@@ -189,6 +189,7 @@ import { onboardingImportModule } from "@posthog/workspace-server/services/onboa
189189import { osModule } from "@posthog/workspace-server/services/os/os.module" ;
190190import {
191191 PI_RPC_CLIENT_FACTORY ,
192+ PI_RUNTIME_FACTORY ,
192193 PI_SESSION_SERVICE ,
193194} from "@posthog/workspace-server/services/pi-session/identifiers" ;
194195import type { PiSessionService } from "@posthog/workspace-server/services/pi-session/pi-session" ;
@@ -230,6 +231,7 @@ import { workspaceMetadataModule } from "@posthog/workspace-server/services/work
230231import ExternalAppsStoreImpl from "electron-store" ;
231232import type { FileWatcherBridge } from "../index" ;
232233import { DesktopPiRpcClientFactory } from "../platform-adapters/desktop-pi-rpc-client-factory" ;
234+ import { DesktopPiRuntimeFactory } from "../platform-adapters/desktop-pi-runtime-factory" ;
233235import { ElectronAppLifecycle } from "../platform-adapters/electron-app-lifecycle" ;
234236import { ElectronAppMeta } from "../platform-adapters/electron-app-meta" ;
235237import { ElectronAppMetrics } from "../platform-adapters/electron-app-metrics" ;
@@ -325,6 +327,17 @@ import {
325327 WORKTREE_REPOSITORY as MAIN_WORKTREE_REPOSITORY ,
326328} from "./tokens" ;
327329
330+ async function cancelTaskSessions (
331+ agentService : AgentService ,
332+ piSessionService : PiSessionService ,
333+ taskId : string ,
334+ ) : Promise < void > {
335+ await Promise . all ( [
336+ agentService . cancelSessionsByTaskId ( taskId ) ,
337+ piSessionService . stop ( taskId ) ,
338+ ] ) ;
339+ }
340+
328341export const container = new TypedContainer < MainBindings > ( {
329342 defaultScope : "Singleton" ,
330343} ) ;
@@ -366,6 +379,7 @@ container
366379 . bind ( MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY )
367380 . toService ( DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY ) ;
368381container . load ( agentModule ) ;
382+ container . bind ( PI_RUNTIME_FACTORY ) . to ( DesktopPiRuntimeFactory ) ;
369383container . load ( piSessionModule ) ;
370384container . bind ( AGENT_SLEEP_COORDINATOR ) . toService ( MAIN_SLEEP_SERVICE ) ;
371385container . bind ( AGENT_MCP_APPS ) . toService ( MCP_APPS_SERVICE ) ;
@@ -406,12 +420,12 @@ container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
406420} ) ;
407421container . load ( archiveModule ) ;
408422container . bind ( ARCHIVE_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
409- cancelSessionsByTaskId : async ( taskId : string ) => {
410- await Promise . all ( [
411- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
412- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
413- ] ) ;
414- } ,
423+ cancelSessionsByTaskId : ( taskId : string ) =>
424+ cancelTaskSessions (
425+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
426+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
427+ taskId ,
428+ ) ,
415429} ) ) ;
416430container . bind ( ARCHIVE_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
417431 stopWatching : async ( worktreePath : string ) => {
@@ -422,12 +436,12 @@ container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
422436} ) ) ;
423437container . load ( suspensionModule ) ;
424438container . bind ( SUSPENSION_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
425- cancelSessionsByTaskId : async ( taskId : string ) => {
426- await Promise . all ( [
427- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
428- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
429- ] ) ;
430- } ,
439+ cancelSessionsByTaskId : ( taskId : string ) =>
440+ cancelTaskSessions (
441+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
442+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
443+ taskId ,
444+ ) ,
431445} ) ) ;
432446container . bind ( SUSPENSION_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
433447 stopWatching : async ( worktreePath : string ) => {
@@ -705,12 +719,12 @@ container.load(workspaceModule);
705719container . bind ( WORKSPACE_AGENT ) . toDynamicValue ( ( ctx ) : WorkspaceAgent => {
706720 const agent = ctx . get < AgentService > ( AGENT_SERVICE ) ;
707721 return {
708- cancelSessionsByTaskId : async ( taskId ) => {
709- await Promise . all ( [
710- agent . cancelSessionsByTaskId ( taskId ) ,
711- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
712- ] ) ;
713- } ,
722+ cancelSessionsByTaskId : ( taskId ) =>
723+ cancelTaskSessions (
724+ agent ,
725+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
726+ taskId ,
727+ ) ,
714728 onAgentFileActivity : ( handler ) =>
715729 agent . on ( AgentServiceEvent . AgentFileActivity , handler ) ,
716730 } ;
0 commit comments