Skip to content

Commit 7cefc1f

Browse files
authored
fix: ux polish for list directory tool messages. (#1075)
## Problem - Existing UX shows multiple context list chatItem cards for list directory tool messages. ## Solution - Use a `messageIdToUpdateListDir` state to store the messageId and update this for next list directory tool messages. ![image](https://github.com/user-attachments/assets/08fff204-0bbc-4467-b05b-7f90be062fc1) ## TODO: - Need to combine both read and list directory tool messages into one context list. - This code change is equivalent to this PR: aws/aws-toolkit-vscode#7006 in `feature/agentic-chat` branch.
1 parent ca1a01d commit 7cefc1f

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
@@ -837,34 +837,33 @@ export class AgenticChatController implements ChatHandlers {
837837
}
838838

839839
#processReadOrList(toolUse: ToolUse, chatResultStream: AgenticChatResultStream): ChatMessage | undefined {
840-
if (toolUse.name !== 'fsRead') {
841-
//TODO: Implement list directory UX in next PR.
842-
return {}
843-
}
844-
let messageId = toolUse.toolUseId || ''
845-
if (chatResultStream.getMessageIdToUpdate()) {
846-
messageId = chatResultStream.getMessageIdToUpdate()!
847-
} else if (messageId) {
848-
chatResultStream.setMessageIdToUpdate(messageId)
840+
let messageIdToUpdate = toolUse.toolUseId!
841+
const currentId = chatResultStream.getMessageIdToUpdateForTool(toolUse.name!)
842+
843+
if (currentId) {
844+
messageIdToUpdate = currentId
845+
} else {
846+
chatResultStream.setMessageIdToUpdateForTool(toolUse.name!, messageIdToUpdate)
849847
}
848+
850849
const currentPath = (toolUse.input as unknown as FsReadParams | ListDirectoryParams)?.path
851850
if (!currentPath) return
852-
const existingPaths = chatResultStream.getMessageOperation(messageId)?.filePaths || []
851+
const existingPaths = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths || []
853852
// Check if path already exists in the list
854853
const isPathAlreadyProcessed = existingPaths.some(path => path.relativeFilePath === currentPath)
855854
if (!isPathAlreadyProcessed) {
856855
const currentFileDetail = {
857856
relativeFilePath: currentPath,
858857
lineRanges: [{ first: -1, second: -1 }],
859858
}
860-
const operationType = toolUse.name === 'fsRead' ? 'read' : 'listDir'
861-
if (operationType === 'read') {
862-
chatResultStream.addMessageOperation(messageId, operationType, [...existingPaths, currentFileDetail])
863-
}
859+
chatResultStream.addMessageOperation(messageIdToUpdate, toolUse.name!, [
860+
...existingPaths,
861+
currentFileDetail,
862+
])
864863
}
865864
let title: string
866-
const itemCount = chatResultStream.getMessageOperation(messageId)?.filePaths.length
867-
const filePathsPushed = chatResultStream.getMessageOperation(messageId)?.filePaths ?? []
865+
const itemCount = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths.length
866+
const filePathsPushed = chatResultStream.getMessageOperation(messageIdToUpdate)?.filePaths ?? []
868867
if (!itemCount) {
869868
title = 'Gathering context'
870869
} else {
@@ -888,7 +887,7 @@ export class AgenticChatController implements ChatHandlers {
888887
return {
889888
type: 'tool',
890889
contextList,
891-
messageId,
890+
messageId: messageIdToUpdate,
892891
body: '',
893892
}
894893
}

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)