Skip to content

Commit 67a3b4b

Browse files
authored
fix(amazonq): Restore toolUse explanations when restoring tabs (aws#7110)
## Problem When tabs are restored, directive messages stored in the explanation field of toolUses are not being displayed. ## Solution Restore toolUse explanations when restoring tabs ## Testing Tested manually Uploading Screen Recording 2025-04-18 at 4.15.40 PM.mov… --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 6f0dc14 commit 67a3b4b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/core/src/codewhispererChat/controllers/chat/tabBarController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class TabBarController {
9090
selectedTab.conversations.flatMap((conv: Conversation) =>
9191
conv.messages
9292
.filter((message) => message.shouldDisplayMessage !== false)
93-
.map((message) => messageToChatItem(message))
93+
.flatMap((message) => messageToChatItem(message))
9494
),
9595
exportTab
9696
)

packages/core/src/shared/db/chatDb/util.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,31 @@ export function messageToChatMessage(msg: Message): ChatMessage {
8484
/**
8585
* Converts Message to MynahUI Chat Item
8686
*/
87-
export function messageToChatItem(msg: Message): ChatItem {
88-
return {
89-
body: msg.body,
90-
type: msg.type as ChatItemType,
91-
codeReference: msg.codeReference,
92-
relatedContent: msg.relatedContent && msg.relatedContent?.content.length > 0 ? msg.relatedContent : undefined,
87+
export function messageToChatItem(msg: Message): ChatItem[] {
88+
const chatItems: ChatItem[] = [
89+
{
90+
body: msg.body,
91+
type: msg.type as ChatItemType,
92+
codeReference: msg.codeReference,
93+
relatedContent:
94+
msg.relatedContent && msg.relatedContent?.content.length > 0 ? msg.relatedContent : undefined,
95+
},
96+
]
97+
// Check if there are any toolUses with explanations that should be displayed as directive messages
98+
if (msg.toolUses && msg.toolUses.length > 0) {
99+
for (const toolUse of msg.toolUses) {
100+
if (toolUse.input && typeof toolUse.input === 'object') {
101+
const input = toolUse.input as any
102+
if (input.explanation) {
103+
chatItems.push({
104+
body: input.explanation,
105+
type: 'directive' as ChatItemType,
106+
})
107+
}
108+
}
109+
}
93110
}
111+
return chatItems
94112
}
95113

96114
/**

0 commit comments

Comments
 (0)