@@ -7,6 +7,7 @@ import type { AIService } from "@/services/aiService";
77import type { HistoryService } from "@/services/historyService" ;
88import type { PartialService } from "@/services/partialService" ;
99import type { InitStateManager } from "@/services/initStateManager" ;
10+ import type { NotificationService } from "@/services/NotificationService" ;
1011import type { WorkspaceMetadata } from "@/types/workspace" ;
1112import type { WorkspaceChatMessage , StreamErrorMessage , SendMessageOptions } from "@/types/ipc" ;
1213import type { SendMessageError } from "@/types/errors" ;
@@ -39,6 +40,7 @@ interface AgentSessionOptions {
3940 partialService : PartialService ;
4041 aiService : AIService ;
4142 initStateManager : InitStateManager ;
43+ notificationService : NotificationService ;
4244}
4345
4446export class AgentSession {
@@ -48,6 +50,7 @@ export class AgentSession {
4850 private readonly partialService : PartialService ;
4951 private readonly aiService : AIService ;
5052 private readonly initStateManager : InitStateManager ;
53+ private readonly notificationService : NotificationService ;
5154 private readonly emitter = new EventEmitter ( ) ;
5255 private readonly aiListeners : Array < { event : string ; handler : ( ...args : unknown [ ] ) => void } > =
5356 [ ] ;
@@ -57,8 +60,15 @@ export class AgentSession {
5760
5861 constructor ( options : AgentSessionOptions ) {
5962 assert ( options , "AgentSession requires options" ) ;
60- const { workspaceId, config, historyService, partialService, aiService, initStateManager } =
61- options ;
63+ const {
64+ workspaceId,
65+ config,
66+ historyService,
67+ partialService,
68+ aiService,
69+ initStateManager,
70+ notificationService,
71+ } = options ;
6272
6373 assert ( typeof workspaceId === "string" , "workspaceId must be a string" ) ;
6474 const trimmedWorkspaceId = workspaceId . trim ( ) ;
@@ -70,6 +80,7 @@ export class AgentSession {
7080 this . partialService = partialService ;
7181 this . aiService = aiService ;
7282 this . initStateManager = initStateManager ;
83+ this . notificationService = notificationService ;
7384
7485 this . attachAiListeners ( ) ;
7586 this . attachInitListeners ( ) ;
@@ -393,7 +404,11 @@ export class AgentSession {
393404
394405 forward ( "stream-start" , ( payload ) => this . emitChatEvent ( payload ) ) ;
395406 forward ( "stream-delta" , ( payload ) => this . emitChatEvent ( payload ) ) ;
396- forward ( "stream-end" , ( payload ) => this . emitChatEvent ( payload ) ) ;
407+ forward ( "stream-end" , ( payload ) => {
408+ this . emitChatEvent ( payload ) ;
409+ // Trigger completion notification (server-side so it works when app is closed)
410+ void this . notificationService . sendCompletionNotification ( this . workspaceId , this . workspaceId ) ;
411+ } ) ;
397412 forward ( "tool-call-start" , ( payload ) => this . emitChatEvent ( payload ) ) ;
398413 forward ( "tool-call-delta" , ( payload ) => this . emitChatEvent ( payload ) ) ;
399414 forward ( "tool-call-end" , ( payload ) => this . emitChatEvent ( payload ) ) ;
0 commit comments