@@ -186,6 +186,7 @@ import { onboardingImportModule } from "@posthog/workspace-server/services/onboa
186186import { osModule } from "@posthog/workspace-server/services/os/os.module" ;
187187import {
188188 PI_RPC_CLIENT_FACTORY ,
189+ PI_RUNTIME_FACTORY ,
189190 PI_SESSION_SERVICE ,
190191} from "@posthog/workspace-server/services/pi-session/identifiers" ;
191192import type { PiSessionService } from "@posthog/workspace-server/services/pi-session/pi-session" ;
@@ -227,6 +228,7 @@ import { workspaceMetadataModule } from "@posthog/workspace-server/services/work
227228import ExternalAppsStoreImpl from "electron-store" ;
228229import type { FileWatcherBridge } from "../index" ;
229230import { DesktopPiRpcClientFactory } from "../platform-adapters/desktop-pi-rpc-client-factory" ;
231+ import { DesktopPiRuntimeFactory } from "../platform-adapters/desktop-pi-runtime-factory" ;
230232import { ElectronAppLifecycle } from "../platform-adapters/electron-app-lifecycle" ;
231233import { ElectronAppMeta } from "../platform-adapters/electron-app-meta" ;
232234import { ElectronAppMetrics } from "../platform-adapters/electron-app-metrics" ;
@@ -322,6 +324,17 @@ import {
322324 WORKTREE_REPOSITORY as MAIN_WORKTREE_REPOSITORY ,
323325} from "./tokens" ;
324326
327+ async function cancelTaskSessions (
328+ agentService : AgentService ,
329+ piSessionService : PiSessionService ,
330+ taskId : string ,
331+ ) : Promise < void > {
332+ await Promise . all ( [
333+ agentService . cancelSessionsByTaskId ( taskId ) ,
334+ piSessionService . stop ( taskId ) ,
335+ ] ) ;
336+ }
337+
325338export const container = new TypedContainer < MainBindings > ( {
326339 defaultScope : "Singleton" ,
327340} ) ;
@@ -363,6 +376,7 @@ container
363376 . bind ( MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY )
364377 . toService ( DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY ) ;
365378container . load ( agentModule ) ;
379+ container . bind ( PI_RUNTIME_FACTORY ) . to ( DesktopPiRuntimeFactory ) ;
366380container . load ( piSessionModule ) ;
367381container . bind ( AGENT_SLEEP_COORDINATOR ) . toService ( MAIN_SLEEP_SERVICE ) ;
368382container . bind ( AGENT_MCP_APPS ) . toService ( MCP_APPS_SERVICE ) ;
@@ -403,12 +417,12 @@ container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
403417} ) ;
404418container . load ( archiveModule ) ;
405419container . bind ( ARCHIVE_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
406- cancelSessionsByTaskId : async ( taskId : string ) => {
407- await Promise . all ( [
408- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
409- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
410- ] ) ;
411- } ,
420+ cancelSessionsByTaskId : ( taskId : string ) =>
421+ cancelTaskSessions (
422+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
423+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
424+ taskId ,
425+ ) ,
412426} ) ) ;
413427container . bind ( ARCHIVE_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
414428 stopWatching : async ( worktreePath : string ) => {
@@ -419,12 +433,12 @@ container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
419433} ) ) ;
420434container . load ( suspensionModule ) ;
421435container . bind ( SUSPENSION_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
422- cancelSessionsByTaskId : async ( taskId : string ) => {
423- await Promise . all ( [
424- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
425- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
426- ] ) ;
427- } ,
436+ cancelSessionsByTaskId : ( taskId : string ) =>
437+ cancelTaskSessions (
438+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
439+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
440+ taskId ,
441+ ) ,
428442} ) ) ;
429443container . bind ( SUSPENSION_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
430444 stopWatching : async ( worktreePath : string ) => {
@@ -695,12 +709,12 @@ container.load(workspaceModule);
695709container . bind ( WORKSPACE_AGENT ) . toDynamicValue ( ( ctx ) : WorkspaceAgent => {
696710 const agent = ctx . get < AgentService > ( AGENT_SERVICE ) ;
697711 return {
698- cancelSessionsByTaskId : async ( taskId ) => {
699- await Promise . all ( [
700- agent . cancelSessionsByTaskId ( taskId ) ,
701- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
702- ] ) ;
703- } ,
712+ cancelSessionsByTaskId : ( taskId ) =>
713+ cancelTaskSessions (
714+ agent ,
715+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
716+ taskId ,
717+ ) ,
704718 onAgentFileActivity : ( handler ) =>
705719 agent . on ( AgentServiceEvent . AgentFileActivity , handler ) ,
706720 } ;
0 commit comments