Skip to content

Commit c124de2

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

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -691,34 +691,37 @@ 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+
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+
}
703705
}
706+
704707
const currentPath = (toolUse.input as unknown as FsReadParams | ListDirectoryParams)?.path
705708
if (!currentPath) return
706-
const existingPaths = chatResultStream.getMessageOperation(messageId)?.filePaths || []
709+
const existingPaths = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths || []
707710
// Check if path already exists in the list
708711
const isPathAlreadyProcessed = existingPaths.some(path => path.relativeFilePath === currentPath)
709712
if (!isPathAlreadyProcessed) {
710713
const currentFileDetail = {
711714
relativeFilePath: currentPath,
712715
lineRanges: [{ first: -1, second: -1 }],
713716
}
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+
])
718721
}
719722
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 ?? []
722725
if (!itemCount) {
723726
title = 'Gathering context'
724727
} else {
@@ -742,7 +745,7 @@ export class AgenticChatController implements ChatHandlers {
742745
return {
743746
type: 'tool',
744747
contextList,
745-
messageId,
748+
messageId: messageIdToUpdate,
746749
body: '',
747750
}
748751
}

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)