1- import type { SessionNotification , SessionUpdate } from "@agentclientprotocol/sdk" ;
1+ import type {
2+ SessionNotification ,
3+ SessionUpdate ,
4+ } from "@agentclientprotocol/sdk" ;
25import { useChatStore } from "@/features/chat/stores/chatStore" ;
36import { useChatSessionStore } from "@/features/chat/stores/chatSessionStore" ;
47import {
58 ensureReplayBuffer ,
69 getBufferedMessage ,
710 findLatestUnpairedToolRequest ,
811} from "@/features/chat/hooks/replayBuffer" ;
9- import type { ToolRequestContent , ToolResponseContent } from "@/shared/types/messages" ;
12+ import type {
13+ ToolRequestContent ,
14+ ToolResponseContent ,
15+ } from "@/shared/types/messages" ;
1016import type { AcpNotificationHandler } from "./acpConnection" ;
1117import { getLocalSessionId } from "./acpSessionTracker" ;
1218
1319// Pre-set message ID for the next live stream per goose session
1420const presetMessageIds = new Map < string , string > ( ) ;
1521
16- export function setActiveMessageId ( gooseSessionId : string , messageId : string ) : void {
22+ export function setActiveMessageId (
23+ gooseSessionId : string ,
24+ messageId : string ,
25+ ) : void {
1726 presetMessageIds . set ( gooseSessionId , messageId ) ;
1827}
1928
@@ -70,15 +79,23 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
7079 const messageId = update . messageId ?? crypto . randomUUID ( ) ;
7180 const buffer = ensureReplayBuffer ( sessionId ) ;
7281 const existing = getBufferedMessage ( sessionId , messageId ) ;
73- if ( ! existing && update . content . type === "text" && "text" in update . content ) {
82+ if (
83+ ! existing &&
84+ update . content . type === "text" &&
85+ "text" in update . content
86+ ) {
7487 buffer . push ( {
7588 id : messageId ,
7689 role : "user" ,
7790 created : Date . now ( ) ,
7891 content : [ { type : "text" , text : update . content . text } ] ,
7992 metadata : { userVisible : true , agentVisible : true } ,
8093 } ) ;
81- } else if ( existing && update . content . type === "text" && "text" in update . content ) {
94+ } else if (
95+ existing &&
96+ update . content . type === "text" &&
97+ "text" in update . content
98+ ) {
8299 const last = existing . content [ existing . content . length - 1 ] ;
83100 if ( last ?. type === "text" ) {
84101 ( last as { type : "text" ; text : string } ) . text += update . content . text ;
@@ -122,7 +139,10 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
122139 if ( tc && tc . type === "toolRequest" ) {
123140 const idx = msg . content . indexOf ( tc ) ;
124141 if ( idx >= 0 ) {
125- msg . content [ idx ] = { ...tc , status : "completed" } as ToolRequestContent ;
142+ msg . content [ idx ] = {
143+ ...tc ,
144+ status : "completed" ,
145+ } as ToolRequestContent ;
126146 }
127147 }
128148 const resultText = extractToolResultText ( update ) ;
@@ -149,13 +169,22 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
149169 }
150170}
151171
152- function handleLive ( sessionId : string , gooseSessionId : string , update : SessionUpdate ) : void {
172+ function handleLive (
173+ sessionId : string ,
174+ gooseSessionId : string ,
175+ update : SessionUpdate ,
176+ ) : void {
153177 const store = useChatStore . getState ( ) ;
154178
155179 switch ( update . sessionUpdate ) {
156180 case "agent_message_chunk" : {
157- const messageId = update . messageId ?? presetMessageIds . get ( gooseSessionId ) ?? crypto . randomUUID ( ) ;
158- const existing = store . messagesBySession [ sessionId ] ?. find ( m => m . id === messageId ) ;
181+ const messageId =
182+ update . messageId ??
183+ presetMessageIds . get ( gooseSessionId ) ??
184+ crypto . randomUUID ( ) ;
185+ const existing = store . messagesBySession [ sessionId ] ?. find (
186+ ( m ) => m . id === messageId ,
187+ ) ;
159188
160189 if ( ! existing ) {
161190 store . addMessage ( sessionId , {
@@ -257,22 +286,28 @@ function handleLive(sessionId: string, gooseSessionId: string, update: SessionUp
257286function handleShared ( sessionId : string , update : SessionUpdate ) : void {
258287 switch ( update . sessionUpdate ) {
259288 case "session_info_update" : {
260- const info = update as SessionUpdate & { sessionUpdate : "session_info_update" } ;
289+ const info = update as SessionUpdate & {
290+ sessionUpdate : "session_info_update" ;
291+ } ;
261292 if ( "title" in info && info . title ) {
262293 const session = useChatSessionStore . getState ( ) . getSession ( sessionId ) ;
263294 if ( session && ! session . userSetName ) {
264- useChatSessionStore . getState ( ) . updateSession (
265- sessionId ,
266- { title : info . title as string } ,
267- { persistOverlay : false } ,
268- ) ;
295+ useChatSessionStore
296+ . getState ( )
297+ . updateSession (
298+ sessionId ,
299+ { title : info . title as string } ,
300+ { persistOverlay : false } ,
301+ ) ;
269302 }
270303 }
271304 break ;
272305 }
273306
274307 case "config_option_update" : {
275- const configUpdate = update as SessionUpdate & { sessionUpdate : "config_option_update" } ;
308+ const configUpdate = update as SessionUpdate & {
309+ sessionUpdate : "config_option_update" ;
310+ } ;
276311 if ( "options" in configUpdate && Array . isArray ( configUpdate . options ) ) {
277312 const modelOption = configUpdate . options . find (
278313 ( opt : any ) => opt . category === "model" ,
@@ -295,7 +330,8 @@ function handleShared(sessionId: string, update: SessionUpdate): void {
295330 }
296331
297332 const currentModelName =
298- availableModels . find ( ( m ) => m . id === currentModelId ) ?. name ?? currentModelId ;
333+ availableModels . find ( ( m ) => m . id === currentModelId ) ?. name ??
334+ currentModelId ;
299335
300336 const sessionStore = useChatSessionStore . getState ( ) ;
301337 sessionStore . setSessionModels ( sessionId , availableModels ) ;
@@ -326,26 +362,38 @@ function handleShared(sessionId: string, update: SessionUpdate): void {
326362// Helpers
327363
328364function findStreamingMessageId ( sessionId : string ) : string | null {
329- return useChatStore . getState ( ) . getSessionRuntime ( sessionId ) . streamingMessageId ;
365+ return useChatStore . getState ( ) . getSessionRuntime ( sessionId )
366+ . streamingMessageId ;
330367}
331368
332- function findMessageInBuffer ( sessionId : string , _toolCallId : string ) : ReturnType < typeof getBufferedMessage > {
369+ function findMessageInBuffer (
370+ sessionId : string ,
371+ _toolCallId : string ,
372+ ) : ReturnType < typeof getBufferedMessage > {
333373 const buffer = ensureReplayBuffer ( sessionId ) ;
334374 return buffer [ buffer . length - 1 ] ;
335375}
336376
337- function findMessageWithToolCall ( sessionId : string , toolCallId : string ) : ReturnType < typeof getBufferedMessage > {
377+ function findMessageWithToolCall (
378+ sessionId : string ,
379+ toolCallId : string ,
380+ ) : ReturnType < typeof getBufferedMessage > {
338381 const buffer = ensureReplayBuffer ( sessionId ) ;
339382 for ( let i = buffer . length - 1 ; i >= 0 ; i -- ) {
340383 const msg = buffer [ i ] ;
341- if ( msg . content . some ( ( c ) => c . type === "toolRequest" && c . id === toolCallId ) ) {
384+ if (
385+ msg . content . some ( ( c ) => c . type === "toolRequest" && c . id === toolCallId )
386+ ) {
342387 return msg ;
343388 }
344389 }
345390 return buffer [ buffer . length - 1 ] ;
346391}
347392
348- function extractToolResultText ( update : { content ?: Array < any > | null ; rawOutput ?: unknown } ) : string {
393+ function extractToolResultText ( update : {
394+ content ?: Array < any > | null ;
395+ rawOutput ?: unknown ;
396+ } ) : string {
349397 if ( update . content && update . content . length > 0 ) {
350398 for ( const item of update . content ) {
351399 if ( item . type === "content" && item . content ?. type === "text" ) {
0 commit comments