Skip to content

Commit 04eae95

Browse files
committed
fix: hide non-user-generated messages when reloading history
1 parent def522d commit 04eae95

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ export class AgenticChatController implements ChatHandlers {
524524
let currentRequestInput = { ...initialRequestInput }
525525
let finalResult: Result<AgenticChatResultWithMetadata, string> | null = null
526526
let iterationCount = 0
527+
let shouldDisplayMessage = true
527528
metric.recordStart()
528529

529530
while (iterationCount < maxAgentLoopIterations) {
@@ -574,8 +575,10 @@ export class AgenticChatController implements ChatHandlers {
574575
userIntent: currentMessage.userInputMessage?.userIntent,
575576
origin: currentMessage.userInputMessage?.origin,
576577
userInputMessageContext: currentMessage.userInputMessage?.userInputMessageContext,
578+
shouldDisplayMessage: shouldDisplayMessage,
577579
})
578580
}
581+
shouldDisplayMessage = true
579582

580583
// Phase 4: Response Processing
581584
const result = await this.#processGenerateAssistantResponseResponseWithTimeout(
@@ -620,6 +623,7 @@ export class AgenticChatController implements ChatHandlers {
620623
name: result.data!.toolUses[k].name,
621624
input: result.data!.toolUses[k].input,
622625
})),
626+
shouldDisplayMessage: shouldDisplayMessage,
623627
})
624628
} else {
625629
this.#features.logging.warn('No ChatResult body in response, skipping adding to history')
@@ -642,6 +646,7 @@ export class AgenticChatController implements ChatHandlers {
642646
if (toolResults.some(toolResult => this.#shouldSendBackErrorContent(toolResult))) {
643647
content = 'There was an error processing one or more tool uses. Try again, do not apologize.'
644648
}
649+
shouldDisplayMessage = false
645650
metric.setDimension('cwsprChatConversationType', 'AgenticChatWithToolUse')
646651
} else {
647652
// Send an error card to UI?
@@ -653,6 +658,7 @@ export class AgenticChatController implements ChatHandlers {
653658
if (result.error.startsWith('ToolUse input is invalid JSON:')) {
654659
content =
655660
'Your toolUse input is incomplete because it is too large. Break this task down into multiple tool uses with smaller input. Do not apologize.'
661+
shouldDisplayMessage = false
656662
}
657663
}
658664
currentRequestInput = this.#updateRequestInputWithToolResults(currentRequestInput, toolResults, content)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class TabBarController {
218218
async restoreTab(selectedTab?: Tab | null) {
219219
if (selectedTab) {
220220
const messages = selectedTab.conversations.flatMap((conv: Conversation) =>
221-
conv.messages.flatMap(msg => messageToChatMessage(msg))
221+
conv.messages.filter(msg => msg.shouldDisplayMessage != false).flatMap(msg => messageToChatMessage(msg))
222222
)
223223

224224
const { tabId } = await this.#features.chat.openTab({ newTabOptions: { data: { messages } } })

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ export class ChatDatabase {
313313

314314
const tabData = historyId ? tabCollection.findOne({ historyId }) : undefined
315315
const tabTitle =
316-
(message.type === 'prompt' && message.body.trim().length > 0 ? message.body : tabData?.title) ||
317-
'Amazon Q Chat'
316+
(message.type === 'prompt' && message.shouldDisplayMessage !== false && message.body.trim().length > 0
317+
? message.body
318+
: tabData?.title) || 'Amazon Q Chat'
318319
message = this.formatChatHistoryMessage(message)
319320
if (tabData) {
320321
this.#features.logging.log(`Updating existing tab with historyId=${historyId}`)

0 commit comments

Comments
 (0)