@@ -427,7 +427,7 @@ export class AgenticChatController implements ChatHandlers {
427
427
const conversationId = conversationIdentifier ?? ''
428
428
429
429
// show loading message while we process request
430
- loadingMessageId = `loading-${ conversationId } -${ iterationCount } `
430
+ loadingMessageId = `loading-${ uuid ( ) } -${ iterationCount } `
431
431
await chatResultStream . writeResultBlock ( { messageId : loadingMessageId , type : 'answer' } )
432
432
433
433
if ( ! currentMessage || ! conversationId ) {
@@ -481,6 +481,10 @@ export class AgenticChatController implements ChatHandlers {
481
481
documentReference
482
482
)
483
483
484
+ // show loading message after we render text response and before processing toolUse
485
+ loadingMessageId = `loading-${ uuid ( ) } -${ iterationCount } `
486
+ await chatResultStream . writeResultBlock ( { messageId : loadingMessageId , type : 'answer' } )
487
+
484
488
// Add the current assistantResponse message to the history DB
485
489
if ( result . data ?. chatResult . body !== undefined ) {
486
490
this . #chatHistoryDb. addMessage ( tabId , 'cwc' , conversationIdentifier ?? '' , {
@@ -509,6 +513,13 @@ export class AgenticChatController implements ChatHandlers {
509
513
break
510
514
}
511
515
516
+ // remove the temp loading message when we are going to process toolUse
517
+ if ( loadingMessageId ) {
518
+ await chatResultStream . removeResultBlock ( loadingMessageId )
519
+ this . #features. chat . sendChatUpdate ( { tabId, state : { inProgress : false } } )
520
+ loadingMessageId = undefined
521
+ }
522
+
512
523
// Process tool uses and update the request input for the next iteration
513
524
const toolResults = await this . #processToolUses( pendingToolUses , chatResultStream , session , tabId , token )
514
525
currentRequestInput = this . #updateRequestInputWithToolResults( currentRequestInput , toolResults )
@@ -629,12 +640,7 @@ export class AgenticChatController implements ChatHandlers {
629
640
await chatResultStream . writeResultBlock ( { messageId : loadingMessageId , type : 'answer' } )
630
641
this . #features. chat . sendChatUpdate ( { tabId, state : { inProgress : true } } )
631
642
632
- if ( [ 'fsRead' , 'listDirectory' , 'fileSearch' ] . includes ( toolUse . name ) ) {
633
- const initialListDirResult = this . #processReadOrListOrSearch( toolUse , chatResultStream )
634
- if ( initialListDirResult ) {
635
- await chatResultStream . writeResultBlock ( initialListDirResult )
636
- }
637
- } else if ( toolUse . name === 'fsWrite' ) {
643
+ if ( toolUse . name === 'fsWrite' ) {
638
644
const input = toolUse . input as unknown as FsWriteParams
639
645
const document = await this . #triggerContext. getTextDocument ( input . path )
640
646
this . #triggerContext
@@ -673,6 +679,11 @@ export class AgenticChatController implements ChatHandlers {
673
679
case 'fsRead' :
674
680
case 'listDirectory' :
675
681
case 'fileSearch' :
682
+ const initialListDirResult = this . #processReadOrListOrSearch( toolUse , chatResultStream )
683
+ if ( initialListDirResult ) {
684
+ await chatResultStream . writeResultBlock ( initialListDirResult )
685
+ }
686
+ break
676
687
// no need to write tool result for listDir,fsRead,fileSearch into chat stream
677
688
case 'executeBash' :
678
689
// no need to write tool result for listDir and fsRead into chat stream
0 commit comments