Skip to content

Commit 8da4b06

Browse files
committed
fix: incorrect history when user aborts in-progress toolUse
1 parent e8927a8 commit 8da4b06

File tree

1 file changed

+13
-3
lines changed
  • server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb

1 file changed

+13
-3
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ export class ChatDatabase {
375375

376376
formatChatHistoryMessage(message: Message): Message {
377377
if (message.type === ('prompt' as ChatItemType)) {
378-
const hasToolResults = message.userInputMessageContext?.toolResults
378+
let hasToolResults = false
379+
if (message.userInputMessageContext?.toolResults) {
380+
hasToolResults = message.userInputMessageContext?.toolResults.length > 0
381+
}
379382
return {
380383
...message,
381384
userInputMessageContext: {
@@ -589,6 +592,13 @@ export class ChatDatabase {
589592

590593
// Make sure the last stored message is from the assistant (type === 'answer'), else drop
591594
if (messages.length > 0 && messages[messages.length - 1].type === ('prompt' as ChatItemType)) {
595+
// When user aborts some in-progress tooluse event, we should still send the previous toolResult back
596+
if (messages[messages.length - 1].userInputMessageContext?.toolResults) {
597+
if (newUserMessage.userInputMessage?.userInputMessageContext) {
598+
newUserMessage.userInputMessage.userInputMessageContext.toolResults =
599+
messages[messages.length - 1].userInputMessageContext?.toolResults
600+
}
601+
}
592602
messages.pop()
593603
this.#features.logging.debug('Dropped trailing user message')
594604
}
@@ -686,10 +696,10 @@ export class ChatDatabase {
686696

687697
getModelId(): string | undefined {
688698
const settings = this.getSettings()
689-
return settings?.modelId
699+
return settings?.modelId === '' ? undefined : settings?.modelId
690700
}
691701

692702
setModelId(modelId: string | undefined): void {
693-
this.updateSettings({ modelId })
703+
this.updateSettings({ modelId: modelId === '' ? undefined : modelId })
694704
}
695705
}

0 commit comments

Comments
 (0)