Skip to content

Commit 78c275a

Browse files
committed
fix: ux polish for list directory tool messages
1 parent 61da81e commit 78c275a

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatResultStream.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AgenticChatResultStream {
2929
isLocked: false,
3030
uuid: randomUUID(),
3131
messageId: undefined as string | undefined,
32-
messageIdToUpdate: undefined as string | undefined,
32+
messageIdToUpdateForTool: new Map<OperationType, string>(),
3333
messageOperations: new Map<string, FileOperation>(),
3434
}
3535
readonly #sendProgress: (newChatResult: ChatResult | string) => Promise<void>
@@ -41,12 +41,13 @@ export class AgenticChatResultStream {
4141
getResult(only?: string): ChatResult {
4242
return this.#joinResults(this.#state.chatResultBlocks, only)
4343
}
44-
getMessageIdToUpdate(): string | undefined {
45-
return this.#state.messageIdToUpdate
44+
45+
setMessageIdToUpdateForTool(toolName: OperationType, messageId: string) {
46+
this.#state.messageIdToUpdateForTool.set(toolName, messageId)
4647
}
4748

48-
setMessageIdToUpdate(messageId: string) {
49-
this.#state.messageIdToUpdate = messageId
49+
getMessageIdToUpdateForTool(toolName: OperationType): string | undefined {
50+
return this.#state.messageIdToUpdateForTool.get(toolName)
5051
}
5152

5253
/**

0 commit comments

Comments
 (0)