@@ -85,8 +85,6 @@ const STATE_TO_STATUS: Record<string, ToolCallStatus> = {
8585const DEPLOY_TOOL_NAMES = new Set ( [ 'deploy_api' , 'deploy_chat' , 'deploy_mcp' , 'redeploy' ] )
8686const RECONNECT_TAIL_ERROR =
8787 'Live reconnect failed before the stream finished. The latest response may be incomplete.'
88- const CONTINUE_OPTIONS_CONTENT =
89- '<options>{"continue":{"title":"Continue","description":"Pick up where we left off"}}</options>'
9088
9189function mapStoredBlock ( block : TaskStoredContentBlock ) : ContentBlock {
9290 const mapped : ContentBlock = {
@@ -1215,22 +1213,16 @@ export function useChat(
12151213
12161214 if ( storedBlocks . length > 0 ) {
12171215 storedBlocks . push ( { type : 'stopped' } )
1218- storedBlocks . push ( { type : 'text' , content : CONTINUE_OPTIONS_CONTENT } )
12191216 }
12201217
1221- const persistedContent =
1222- content && ! content . includes ( '<options>' )
1223- ? `${ content } \n\n${ CONTINUE_OPTIONS_CONTENT } `
1224- : content
1225-
12261218 try {
12271219 const res = await fetch ( stopPathRef . current , {
12281220 method : 'POST' ,
12291221 headers : { 'Content-Type' : 'application/json' } ,
12301222 body : JSON . stringify ( {
12311223 chatId,
12321224 streamId,
1233- content : persistedContent ,
1225+ content,
12341226 ...( storedBlocks . length > 0 && { contentBlocks : storedBlocks } ) ,
12351227 } ) ,
12361228 } )
@@ -1256,50 +1248,6 @@ export function useChat(
12561248 const messagesRef = useRef ( messages )
12571249 messagesRef . current = messages
12581250
1259- const resolveInterruptedToolCalls = useCallback ( ( ) => {
1260- setMessages ( ( prev ) => {
1261- const hasAnyExecuting = prev . some ( ( m ) =>
1262- m . contentBlocks ?. some ( ( b ) => b . toolCall ?. status === 'executing' )
1263- )
1264- if ( ! hasAnyExecuting ) return prev
1265-
1266- let lastAssistantIdx = - 1
1267- for ( let i = prev . length - 1 ; i >= 0 ; i -- ) {
1268- if ( prev [ i ] . role === 'assistant' ) {
1269- lastAssistantIdx = i
1270- break
1271- }
1272- }
1273- return prev . map ( ( msg , idx ) => {
1274- const hasExecuting = msg . contentBlocks ?. some ( ( b ) => b . toolCall ?. status === 'executing' )
1275- const isLastAssistant = idx === lastAssistantIdx
1276- if ( ! hasExecuting && ! isLastAssistant ) return msg
1277-
1278- const blocks : ContentBlock [ ] = ( msg . contentBlocks ?? [ ] ) . map ( ( block ) => {
1279- if ( block . toolCall ?. status !== 'executing' ) return block
1280- return {
1281- ...block ,
1282- toolCall : {
1283- ...block . toolCall ,
1284- status : 'cancelled' as const ,
1285- displayTitle : 'Stopped' ,
1286- } ,
1287- }
1288- } )
1289- if ( isLastAssistant && ! blocks . some ( ( b ) => b . type === 'stopped' ) ) {
1290- blocks . push ( { type : 'stopped' as const } )
1291- }
1292- if (
1293- isLastAssistant &&
1294- ! blocks . some ( ( b ) => b . type === 'text' && b . content ?. includes ( '<options>' ) )
1295- ) {
1296- blocks . push ( { type : 'text' , content : CONTINUE_OPTIONS_CONTENT } )
1297- }
1298- return { ...msg , contentBlocks : blocks . length > 0 ? blocks : msg . contentBlocks }
1299- } )
1300- } )
1301- } , [ ] )
1302-
13031251 const finalize = useCallback (
13041252 ( options ?: { error ?: boolean } ) => {
13051253 sendingRef . current = false
@@ -1314,8 +1262,6 @@ export function useChat(
13141262 }
13151263 }
13161264
1317- resolveInterruptedToolCalls ( )
1318-
13191265 if ( options ?. error ) {
13201266 setMessageQueue ( [ ] )
13211267 return
@@ -1331,7 +1277,7 @@ export function useChat(
13311277 } )
13321278 }
13331279 } ,
1334- [ invalidateChatQueries , resolveInterruptedToolCalls ]
1280+ [ invalidateChatQueries ]
13351281 )
13361282 finalizeRef . current = finalize
13371283
@@ -1489,7 +1435,24 @@ export function useChat(
14891435 sendingRef . current = false
14901436 setIsSending ( false )
14911437
1492- resolveInterruptedToolCalls ( )
1438+ setMessages ( ( prev ) =>
1439+ prev . map ( ( msg ) => {
1440+ if ( ! msg . contentBlocks ?. some ( ( b ) => b . toolCall ?. status === 'executing' ) ) return msg
1441+ const updated = msg . contentBlocks ! . map ( ( block ) => {
1442+ if ( block . toolCall ?. status !== 'executing' ) return block
1443+ return {
1444+ ...block ,
1445+ toolCall : {
1446+ ...block . toolCall ,
1447+ status : 'cancelled' as const ,
1448+ displayTitle : 'Stopped by user' ,
1449+ } ,
1450+ }
1451+ } )
1452+ updated . push ( { type : 'stopped' as const } )
1453+ return { ...msg , contentBlocks : updated }
1454+ } )
1455+ )
14931456
14941457 if ( sid ) {
14951458 fetch ( '/api/copilot/chat/abort' , {
@@ -1555,7 +1518,7 @@ export function useChat(
15551518
15561519 reportManualRunToolStop ( workflowId , toolCallId ) . catch ( ( ) => { } )
15571520 }
1558- } , [ invalidateChatQueries , persistPartialResponse , executionStream , resolveInterruptedToolCalls ] )
1521+ } , [ invalidateChatQueries , persistPartialResponse , executionStream ] )
15591522
15601523 const removeFromQueue = useCallback ( ( id : string ) => {
15611524 messageQueueRef . current = messageQueueRef . current . filter ( ( m ) => m . id !== id )
0 commit comments