Skip to content

Commit 5e091d7

Browse files
authored
fix: further improvements for thinking/loading (#1125)
## Problem - thinking don't show up in second round of messages because the ID used wasn't unique - sometimes it takes a while from us rendering text response to processing toolUse - listDir/read/search shows result before running the tool ## Solution - switch to use `uuid` instead in iterations - add additional loading message between text response to toolUse processing - move list/read/search result to after tool run
1 parent 7c5e5a8 commit 5e091d7

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export const createMynahUi = (
456456
const chatItems = store.chatItems || []
457457
const updatedItems = chatItems.map(item => ({
458458
...item,
459-
type: item.type === ChatItemType.ANSWER_STREAM ? ChatItemType.ANSWER : item.type,
459+
type: item.type === ChatItemType.ANSWER_STREAM && !item.body ? ChatItemType.ANSWER : item.type,
460460
}))
461461
mynahUi.updateStore(tabId, { loadingChat: false, cancelButtonWhenLoading: true, chatItems: updatedItems })
462462
messager.onStopChatResponse(tabId)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ describe('AgenticChatController', () => {
894894

895895
const chatResult = await chatResultPromise
896896

897-
sinon.assert.callCount(testFeatures.lsp.sendProgress, mockChatResponseList.length + 1) // response length + loading message
897+
sinon.assert.callCount(testFeatures.lsp.sendProgress, mockChatResponseList.length + 2) // response length + 2 loading messages
898898
assert.deepStrictEqual(chatResult, {
899899
additionalMessages: [],
900900
body: '\n\nHello World!',
@@ -911,7 +911,7 @@ describe('AgenticChatController', () => {
911911

912912
const chatResult = await chatResultPromise
913913

914-
sinon.assert.callCount(testFeatures.lsp.sendProgress, mockChatResponseList.length + 1) // response length + loading message
914+
sinon.assert.callCount(testFeatures.lsp.sendProgress, mockChatResponseList.length + 2) // response length + 2 loading message
915915
assert.deepStrictEqual(chatResult, {
916916
additionalMessages: [],
917917
body: '\n\nHello World!',

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export class AgenticChatController implements ChatHandlers {
427427
const conversationId = conversationIdentifier ?? ''
428428

429429
// show loading message while we process request
430-
loadingMessageId = `loading-${conversationId}-${iterationCount}`
430+
loadingMessageId = `loading-${uuid()}-${iterationCount}`
431431
await chatResultStream.writeResultBlock({ messageId: loadingMessageId, type: 'answer' })
432432

433433
if (!currentMessage || !conversationId) {
@@ -481,6 +481,10 @@ export class AgenticChatController implements ChatHandlers {
481481
documentReference
482482
)
483483

484+
// show loading message after we render text response and before processing toolUse
485+
loadingMessageId = `loading-${uuid()}-${iterationCount}`
486+
await chatResultStream.writeResultBlock({ messageId: loadingMessageId, type: 'answer' })
487+
484488
// Add the current assistantResponse message to the history DB
485489
if (result.data?.chatResult.body !== undefined) {
486490
this.#chatHistoryDb.addMessage(tabId, 'cwc', conversationIdentifier ?? '', {
@@ -503,6 +507,13 @@ export class AgenticChatController implements ChatHandlers {
503507
// Check if we have any tool uses that need to be processed
504508
const pendingToolUses = this.#getPendingToolUses(result.data?.toolUses || {})
505509

510+
// remove the temp loading message when we are going to process toolUse
511+
if (loadingMessageId) {
512+
await chatResultStream.removeResultBlock(loadingMessageId)
513+
this.#features.chat.sendChatUpdate({ tabId, state: { inProgress: false } })
514+
loadingMessageId = undefined
515+
}
516+
506517
if (pendingToolUses.length === 0) {
507518
// No more tool uses, we're done
508519
finalResult = result
@@ -629,12 +640,7 @@ export class AgenticChatController implements ChatHandlers {
629640
await chatResultStream.writeResultBlock({ messageId: loadingMessageId, type: 'answer' })
630641
this.#features.chat.sendChatUpdate({ tabId, state: { inProgress: true } })
631642

632-
if (['fsRead', 'listDirectory', 'fileSearch'].includes(toolUse.name)) {
633-
const initialListDirResult = this.#processReadOrListOrSearch(toolUse, chatResultStream)
634-
if (initialListDirResult) {
635-
await chatResultStream.writeResultBlock(initialListDirResult)
636-
}
637-
} else if (toolUse.name === 'fsWrite') {
643+
if (toolUse.name === 'fsWrite') {
638644
const input = toolUse.input as unknown as FsWriteParams
639645
const document = await this.#triggerContext.getTextDocument(input.path)
640646
this.#triggerContext
@@ -673,6 +679,11 @@ export class AgenticChatController implements ChatHandlers {
673679
case 'fsRead':
674680
case 'listDirectory':
675681
case 'fileSearch':
682+
const initialListDirResult = this.#processReadOrListOrSearch(toolUse, chatResultStream)
683+
if (initialListDirResult) {
684+
await chatResultStream.writeResultBlock(initialListDirResult)
685+
}
686+
break
676687
// no need to write tool result for listDir,fsRead,fileSearch into chat stream
677688
case 'executeBash':
678689
// no need to write tool result for listDir and fsRead into chat stream

0 commit comments

Comments
 (0)