@@ -691,34 +691,34 @@ export class AgenticChatController implements ChatHandlers {
691691 }
692692
693693 #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+ const currentId = chatResultStream . getMessageIdToUpdateForTool ( operationType )
697+
698+ if ( currentId ) {
699+ messageIdToUpdate = currentId
700+ } else {
701+ chatResultStream . setMessageIdToUpdateForTool ( operationType , messageIdToUpdate )
703702 }
703+
704704 const currentPath = ( toolUse . input as unknown as FsReadParams | ListDirectoryParams ) ?. path
705705 if ( ! currentPath ) return
706- const existingPaths = chatResultStream . getMessageOperation ( messageId ) ?. filePaths || [ ]
706+ const existingPaths = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths || [ ]
707707 // Check if path already exists in the list
708708 const isPathAlreadyProcessed = existingPaths . some ( path => path . relativeFilePath === currentPath )
709709 if ( ! isPathAlreadyProcessed ) {
710710 const currentFileDetail = {
711711 relativeFilePath : currentPath ,
712712 lineRanges : [ { first : - 1 , second : - 1 } ] ,
713713 }
714- const operationType = toolUse . name === 'fsRead' ? 'read' : 'listDir'
715- if ( operationType === 'read' ) {
716- chatResultStream . addMessageOperation ( messageId , operationType , [ ... existingPaths , currentFileDetail ] )
717- }
714+ chatResultStream . addMessageOperation ( messageIdToUpdate , operationType , [
715+ ... existingPaths ,
716+ currentFileDetail ,
717+ ] )
718718 }
719719 let title : string
720- const itemCount = chatResultStream . getMessageOperation ( messageId ) ?. filePaths . length
721- const filePathsPushed = chatResultStream . getMessageOperation ( messageId ) ?. filePaths ?? [ ]
720+ const itemCount = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths . length
721+ const filePathsPushed = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths ?? [ ]
722722 if ( ! itemCount ) {
723723 title = 'Gathering context'
724724 } else {
@@ -742,7 +742,7 @@ export class AgenticChatController implements ChatHandlers {
742742 return {
743743 type : 'tool' ,
744744 contextList,
745- messageId,
745+ messageId : messageIdToUpdate ,
746746 body : '' ,
747747 }
748748 }
0 commit comments