Skip to content

Commit d0289c0

Browse files
committed
fix: further improvements for thinking/loading
1 parent 6e813fd commit d0289c0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ export const createMynahUi = (
433433
const chatItems = store.chatItems || []
434434
const updatedItems = chatItems.map(item => ({
435435
...item,
436-
type: item.type === ChatItemType.ANSWER_STREAM ? ChatItemType.ANSWER : item.type,
436+
type: item.type === ChatItemType.ANSWER_STREAM && !item.body ? ChatItemType.ANSWER : item.type,
437437
}))
438438
mynahUi.updateStore(tabId, { loadingChat: false, cancelButtonWhenLoading: true, chatItems: updatedItems })
439439
messager.onStopChatResponse(tabId)

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 ?? '', {
@@ -509,6 +513,13 @@ export class AgenticChatController implements ChatHandlers {
509513
break
510514
}
511515

516+
// remove the temp loading message when we are going to process toolUse
517+
if (loadingMessageId) {
518+
await chatResultStream.removeResultBlock(loadingMessageId)
519+
this.#features.chat.sendChatUpdate({ tabId, state: { inProgress: false } })
520+
loadingMessageId = undefined
521+
}
522+
512523
// Process tool uses and update the request input for the next iteration
513524
const toolResults = await this.#processToolUses(pendingToolUses, chatResultStream, session, tabId, token)
514525
currentRequestInput = this.#updateRequestInputWithToolResults(currentRequestInput, toolResults)
@@ -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)