@@ -691,34 +691,37 @@ export class AgenticChatController implements ChatHandlers {
691
691
}
692
692
693
693
#processReadOrList( toolUse : ToolUse , chatResultStream : AgenticChatResultStream ) : ChatMessage | undefined {
694
- if ( toolUse . name !== 'fsRead' ) {
695
- //TODO: Implement list directory UX in next PR.
696
- return { }
697
- }
698
- let messageId = toolUse . toolUseId || ''
699
- if ( chatResultStream . getMessageIdToUpdate ( ) ) {
700
- messageId = chatResultStream . getMessageIdToUpdate ( ) !
701
- } else if ( messageId ) {
702
- chatResultStream . setMessageIdToUpdate ( messageId )
694
+ const operationType = toolUse . name === 'fsRead' ? 'read' : 'listDir'
695
+ let messageIdToUpdate = toolUse . toolUseId !
696
+
697
+ if ( operationType === 'read' || operationType === 'listDir' ) {
698
+ const currentId = chatResultStream . getMessageIdToUpdateForTool ( operationType )
699
+
700
+ if ( currentId ) {
701
+ messageIdToUpdate = currentId
702
+ } else {
703
+ chatResultStream . setMessageIdToUpdateForTool ( operationType , messageIdToUpdate )
704
+ }
703
705
}
706
+
704
707
const currentPath = ( toolUse . input as unknown as FsReadParams | ListDirectoryParams ) ?. path
705
708
if ( ! currentPath ) return
706
- const existingPaths = chatResultStream . getMessageOperation ( messageId ) ?. filePaths || [ ]
709
+ const existingPaths = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths || [ ]
707
710
// Check if path already exists in the list
708
711
const isPathAlreadyProcessed = existingPaths . some ( path => path . relativeFilePath === currentPath )
709
712
if ( ! isPathAlreadyProcessed ) {
710
713
const currentFileDetail = {
711
714
relativeFilePath : currentPath ,
712
715
lineRanges : [ { first : - 1 , second : - 1 } ] ,
713
716
}
714
- const operationType = toolUse . name === 'fsRead' ? 'read' : 'listDir'
715
- if ( operationType === 'read' ) {
716
- chatResultStream . addMessageOperation ( messageId , operationType , [ ... existingPaths , currentFileDetail ] )
717
- }
717
+ chatResultStream . addMessageOperation ( messageIdToUpdate , operationType , [
718
+ ... existingPaths ,
719
+ currentFileDetail ,
720
+ ] )
718
721
}
719
722
let title : string
720
- const itemCount = chatResultStream . getMessageOperation ( messageId ) ?. filePaths . length
721
- const filePathsPushed = chatResultStream . getMessageOperation ( messageId ) ?. filePaths ?? [ ]
723
+ const itemCount = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths . length
724
+ const filePathsPushed = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths ?? [ ]
722
725
if ( ! itemCount ) {
723
726
title = 'Gathering context'
724
727
} else {
@@ -742,7 +745,7 @@ export class AgenticChatController implements ChatHandlers {
742
745
return {
743
746
type : 'tool' ,
744
747
contextList,
745
- messageId,
748
+ messageId : messageIdToUpdate ,
746
749
body : '' ,
747
750
}
748
751
}
0 commit comments