Skip to content

Commit acd52cf

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

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -691,34 +691,33 @@ 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+
let messageIdToUpdate = toolUse.toolUseId!
695+
const currentId = chatResultStream.getMessageIdToUpdateForTool(toolUse.name!)
696+
697+
if (currentId) {
698+
messageIdToUpdate = currentId
699+
} else {
700+
chatResultStream.setMessageIdToUpdateForTool(toolUse.name!, messageIdToUpdate)
703701
}
702+
704703
const currentPath = (toolUse.input as unknown as FsReadParams | ListDirectoryParams)?.path
705704
if (!currentPath) return
706-
const existingPaths = chatResultStream.getMessageOperation(messageId)?.filePaths || []
705+
const existingPaths = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths || []
707706
// Check if path already exists in the list
708707
const isPathAlreadyProcessed = existingPaths.some(path => path.relativeFilePath === currentPath)
709708
if (!isPathAlreadyProcessed) {
710709
const currentFileDetail = {
711710
relativeFilePath: currentPath,
712711
lineRanges: [{ first: -1, second: -1 }],
713712
}
714-
const operationType = toolUse.name === 'fsRead' ? 'read' : 'listDir'
715-
if (operationType === 'read') {
716-
chatResultStream.addMessageOperation(messageId, operationType, [...existingPaths, currentFileDetail])
717-
}
713+
chatResultStream.addMessageOperation(messageIdToUpdate, toolUse.name!, [
714+
...existingPaths,
715+
currentFileDetail,
716+
])
718717
}
719718
let title: string
720-
const itemCount = chatResultStream.getMessageOperation(messageId)?.filePaths.length
721-
const filePathsPushed = chatResultStream.getMessageOperation(messageId)?.filePaths ?? []
719+
const itemCount = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths.length
720+
const filePathsPushed = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths ?? []
722721
if (!itemCount) {
723722
title = 'Gathering context'
724723
} else {
@@ -742,7 +741,7 @@ export class AgenticChatController implements ChatHandlers {
742741
return {
743742
type: 'tool',
744743
contextList,
745-
messageId,
744+
messageId: messageIdToUpdate,
746745
body: '',
747746
}
748747
}

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

Lines changed: 9 additions & 8 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,22 +41,23 @@ 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: string, messageId: string) {
46+
this.#state.messageIdToUpdateForTool.set(toolName as OperationType, messageId)
4647
}
4748

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

5253
/**
5354
* Adds a file operation for a specific message
5455
* @param messageId The ID of the message
55-
* @param type The type of operation ('read' or 'listDir' or 'write')
56+
* @param type The type of operation ('fsRead' or 'listDirectory' or 'fsWrite')
5657
* @param filePaths Array of FileDetailsWithPath involved in the operation
5758
*/
58-
addMessageOperation(messageId: string, type: OperationType, filePaths: FileDetailsWithPath[]) {
59-
this.#state.messageOperations.set(messageId, { type, filePaths })
59+
addMessageOperation(messageId: string, type: string, filePaths: FileDetailsWithPath[]) {
60+
this.#state.messageOperations.set(messageId, { type: type as OperationType, filePaths })
6061
}
6162

6263
/**

0 commit comments

Comments
 (0)