@@ -354,6 +354,7 @@ export function useChat(
354354 streamingFileRef . current = streamingFile
355355 const filePreviewSessionsRef = useRef < Map < string , StreamingFilePreview > > ( new Map ( ) )
356356 const activeFilePreviewToolCallIdRef = useRef < string | null > ( null )
357+ const editContentParentToolCallIdRef = useRef < Map < string , string > > ( new Map ( ) )
357358
358359 const [ messageQueue , setMessageQueue ] = useState < QueuedMessage [ ] > ( [ ] )
359360 const messageQueueRef = useRef < QueuedMessage [ ] > ( [ ] )
@@ -527,6 +528,7 @@ export function useChat(
527528 streamingFileRef . current = null
528529 filePreviewSessionsRef . current . clear ( )
529530 activeFilePreviewToolCallIdRef . current = null
531+ editContentParentToolCallIdRef . current . clear ( )
530532 setMessageQueue ( [ ] )
531533 } , [ initialChatId , queryClient ] )
532534
@@ -550,6 +552,7 @@ export function useChat(
550552 streamingFileRef . current = null
551553 filePreviewSessionsRef . current . clear ( )
552554 activeFilePreviewToolCallIdRef . current = null
555+ editContentParentToolCallIdRef . current . clear ( )
553556 setMessageQueue ( [ ] )
554557 } , [ isHomePage ] )
555558
@@ -1024,6 +1027,10 @@ export function useChat(
10241027 sessions . set ( id , nextSession )
10251028 activeFilePreviewToolCallIdRef . current = id
10261029 streamingFileRef . current = nextSession
1030+ const previewToolIdx = toolMap . get ( id )
1031+ if ( previewToolIdx !== undefined && blocks [ previewToolIdx ] . toolCall ) {
1032+ blocks [ previewToolIdx ] . toolCall ! . status = 'executing'
1033+ }
10271034 setStreamingFile ( nextSession )
10281035 break
10291036 }
@@ -1233,6 +1240,7 @@ export function useChat(
12331240 setResources ( ( rs ) => rs . filter ( ( r ) => r . id !== 'streaming-file' ) )
12341241 }
12351242 }
1243+ editContentParentToolCallIdRef . current . delete ( id )
12361244 break
12371245 }
12381246
@@ -1280,6 +1288,25 @@ export function useChat(
12801288 }
12811289 }
12821290
1291+ if ( name === 'edit_content' ) {
1292+ const parentToolCallId =
1293+ activeFilePreviewToolCallIdRef . current ?? streamingFileRef . current ?. toolCallId
1294+ const parentIdx =
1295+ parentToolCallId !== null && parentToolCallId !== undefined
1296+ ? toolMap . get ( parentToolCallId )
1297+ : undefined
1298+ if ( parentIdx !== undefined && blocks [ parentIdx ] . toolCall ) {
1299+ toolMap . set ( id , parentIdx )
1300+ editContentParentToolCallIdRef . current . set ( id , parentToolCallId ! )
1301+ const tc = blocks [ parentIdx ] . toolCall !
1302+ tc . status = 'executing'
1303+ tc . result = undefined
1304+ tc . error = undefined
1305+ flush ( )
1306+ break
1307+ }
1308+ }
1309+
12831310 if ( ! toolMap . has ( id ) ) {
12841311 toolMap . set ( id , blocks . length )
12851312 blocks . push ( {
@@ -2098,6 +2125,7 @@ export function useChat(
20982125 streamingFileRef . current = null
20992126 filePreviewSessionsRef . current . clear ( )
21002127 activeFilePreviewToolCallIdRef . current = null
2128+ editContentParentToolCallIdRef . current . clear ( )
21012129 setResources ( ( rs ) => rs . filter ( ( resource ) => resource . id !== 'streaming-file' ) )
21022130
21032131 const execState = useExecutionStore . getState ( )
0 commit comments