@@ -184,7 +184,10 @@ import { OAUTH_CALLBACK_SERVER } from "@posthog/workspace-server/services/oauth-
184184import { oauthCallbackModule } from "@posthog/workspace-server/services/oauth-callback/oauth-callback.module" ;
185185import { onboardingImportModule } from "@posthog/workspace-server/services/onboarding-import/onboarding-import.module" ;
186186import { osModule } from "@posthog/workspace-server/services/os/os.module" ;
187- import { PI_SESSION_SERVICE } from "@posthog/workspace-server/services/pi-session/identifiers" ;
187+ import {
188+ PI_RUNTIME_FACTORY ,
189+ PI_SESSION_SERVICE ,
190+ } from "@posthog/workspace-server/services/pi-session/identifiers" ;
188191import type { PiSessionService } from "@posthog/workspace-server/services/pi-session/pi-session" ;
189192import { piSessionModule } from "@posthog/workspace-server/services/pi-session/pi-session.module" ;
190193import { POSTHOG_PLUGIN_SERVICE } from "@posthog/workspace-server/services/posthog-plugin/identifiers" ;
@@ -253,6 +256,7 @@ import {
253256 TokenCipherPortAdapter ,
254257} from "../services/auth/port-adapters" ;
255258import { DeepLinkService } from "../services/deep-link/service" ;
259+ import { DesktopPiRuntimeFactory } from "../services/desktop-pi-runtime-factory" ;
256260import { DevActionsService } from "../services/dev-actions/service" ;
257261import { DevFlagsService } from "../services/dev-flags/service" ;
258262import { DevLogsService } from "../services/dev-logs/service" ;
@@ -318,6 +322,17 @@ import {
318322 WORKTREE_REPOSITORY as MAIN_WORKTREE_REPOSITORY ,
319323} from "./tokens" ;
320324
325+ async function cancelTaskSessions (
326+ agentService : AgentService ,
327+ piSessionService : PiSessionService ,
328+ taskId : string ,
329+ ) : Promise < void > {
330+ await Promise . all ( [
331+ agentService . cancelSessionsByTaskId ( taskId ) ,
332+ piSessionService . stop ( taskId ) ,
333+ ] ) ;
334+ }
335+
321336export const container = new TypedContainer < MainBindings > ( {
322337 defaultScope : "Singleton" ,
323338} ) ;
@@ -359,6 +374,7 @@ container
359374 . bind ( MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY )
360375 . toService ( DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY ) ;
361376container . load ( agentModule ) ;
377+ container . bind ( PI_RUNTIME_FACTORY ) . to ( DesktopPiRuntimeFactory ) ;
362378container . load ( piSessionModule ) ;
363379container . bind ( AGENT_SLEEP_COORDINATOR ) . toService ( MAIN_SLEEP_SERVICE ) ;
364380container . bind ( AGENT_MCP_APPS ) . toService ( MCP_APPS_SERVICE ) ;
@@ -395,12 +411,12 @@ container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
395411} ) ;
396412container . load ( archiveModule ) ;
397413container . bind ( ARCHIVE_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
398- cancelSessionsByTaskId : async ( taskId : string ) => {
399- await Promise . all ( [
400- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
401- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
402- ] ) ;
403- } ,
414+ cancelSessionsByTaskId : ( taskId : string ) =>
415+ cancelTaskSessions (
416+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
417+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
418+ taskId ,
419+ ) ,
404420} ) ) ;
405421container . bind ( ARCHIVE_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
406422 stopWatching : async ( worktreePath : string ) => {
@@ -411,12 +427,12 @@ container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
411427} ) ) ;
412428container . load ( suspensionModule ) ;
413429container . bind ( SUSPENSION_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
414- cancelSessionsByTaskId : async ( taskId : string ) => {
415- await Promise . all ( [
416- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
417- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
418- ] ) ;
419- } ,
430+ cancelSessionsByTaskId : ( taskId : string ) =>
431+ cancelTaskSessions (
432+ ctx . get < AgentService > ( AGENT_SERVICE ) ,
433+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
434+ taskId ,
435+ ) ,
420436} ) ) ;
421437container . bind ( SUSPENSION_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
422438 stopWatching : async ( worktreePath : string ) => {
@@ -687,12 +703,12 @@ container.load(workspaceModule);
687703container . bind ( WORKSPACE_AGENT ) . toDynamicValue ( ( ctx ) : WorkspaceAgent => {
688704 const agent = ctx . get < AgentService > ( AGENT_SERVICE ) ;
689705 return {
690- cancelSessionsByTaskId : async ( taskId ) => {
691- await Promise . all ( [
692- agent . cancelSessionsByTaskId ( taskId ) ,
693- ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
694- ] ) ;
695- } ,
706+ cancelSessionsByTaskId : ( taskId ) =>
707+ cancelTaskSessions (
708+ agent ,
709+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) ,
710+ taskId ,
711+ ) ,
696712 onAgentFileActivity : ( handler ) =>
697713 agent . on ( AgentServiceEvent . AgentFileActivity , handler ) ,
698714 } ;
0 commit comments