Skip to content

Commit f930297

Browse files
authored
fix: Render timeout error, JSON parse error, cancellation to the in progress fs.write UI (#1382)
* fix: Render timeout error, JSON parse error, cancellation to the in progress fs.write UI
1 parent 56f9bee commit f930297

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,11 @@ export class AgenticChatController implements ChatHandlers {
410410
// depends on it
411411
session.conversationId = uuid()
412412
}
413-
413+
const chatResultStream = this.#getChatResultStream(params.partialResultToken)
414414
token.onCancellationRequested(async () => {
415415
this.#log('cancellation requested')
416416
await this.#showUndoAllIfRequired(chatResultStream, session)
417+
await chatResultStream.updateOngoingProgressResult('Canceled')
417418
await this.#getChatResultStream(params.partialResultToken).writeResultBlock({
418419
type: 'directive',
419420
messageId: 'stopped' + uuid(),
@@ -431,8 +432,6 @@ export class AgenticChatController implements ChatHandlers {
431432
})
432433
session.setConversationType('AgenticChat')
433434

434-
const chatResultStream = this.#getChatResultStream(params.partialResultToken)
435-
436435
const additionalContext = await this.#additionalContextProvider.getAdditionalContext(
437436
triggerContext,
438437
params.context
@@ -655,6 +654,8 @@ export class AgenticChatController implements ChatHandlers {
655654
}
656655
currentRequestInput = this.#updateRequestInputWithToolResults(currentRequestInput, [], content)
657656
shouldDisplayMessage = false
657+
// set the in progress tool use UI status to Error
658+
await chatResultStream.updateOngoingProgressResult('Error')
658659
continue
659660
}
660661

@@ -756,6 +757,8 @@ export class AgenticChatController implements ChatHandlers {
756757
'Your toolUse input is incomplete, try again. If the error happens consistently, break this task down into multiple tool uses with smaller input. Do not apologize.'
757758
shouldDisplayMessage = false
758759
}
760+
// set the in progress tool use UI status to Error
761+
await chatResultStream.updateOngoingProgressResult('Error')
759762
}
760763
if (result.success && this.#toolUseLatencies.length > 0) {
761764
// Clear latencies for the next LLM call

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ export class AgenticChatResultStream {
203203
this.#state.chatResultBlocks = this.#state.chatResultBlocks.filter(block => block.messageId !== messageId)
204204
}
205205

206+
/**
207+
* Removes a specific messageId and renders the result on UI
208+
* @param messageId
209+
*/
206210
async removeResultBlockAndUpdateUI(messageId: string) {
207211
if (this.hasMessage(messageId)) {
208212
const blockId = this.getMessageBlockId(messageId)
@@ -213,6 +217,22 @@ export class AgenticChatResultStream {
213217
}
214218
}
215219

220+
async updateOngoingProgressResult(errorMessage: string) {
221+
for (const block of this.#state.chatResultBlocks) {
222+
if (block.messageId?.startsWith(progressPrefix) && block.header?.status?.icon === 'progress') {
223+
await this.removeResultBlockAndUpdateUI(block.messageId)
224+
block.header.status = {
225+
status: 'error',
226+
icon: 'error',
227+
text: errorMessage,
228+
}
229+
block.messageId = block.messageId.substring(progressPrefix.length)
230+
await this.writeResultBlock(block)
231+
break
232+
}
233+
}
234+
}
235+
216236
hasMessage(messageId: string): boolean {
217237
return this.#state.chatResultBlocks.some(block => block.messageId === messageId)
218238
}

0 commit comments

Comments
 (0)