Skip to content

Commit f2bfc78

Browse files
committed
Merge branch 'feature/agentic-chat' into replace-read-messages
2 parents 9376bd7 + cc41a7f commit f2bfc78

File tree

12 files changed

+319
-61
lines changed

12 files changed

+319
-61
lines changed

packages/core/resources/css/amazonq-webview.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ body.vscode-high-contrast:not(.vscode-high-contrast-light) {
1515
--mynah-color-highlight: rgba(0, 137, 255, 0.2);
1616
--mynah-color-highlight-text: rgba(0, 137, 255, 1);
1717
}
18+
19+
body .mynah-card-body h1 {
20+
--mynah-line-height: 1.5rem;
21+
}

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ChatItemButton,
99
ChatItemFormItem,
1010
ChatItemType,
11+
MynahIconsType,
1112
MynahUIDataModel,
1213
QuickActionCommand,
1314
} from '@aws/mynah-ui'
@@ -33,6 +34,7 @@ export class Connector extends BaseConnector {
3334
private readonly onContextCommandDataReceived
3435
private readonly onShowCustomForm
3536
private readonly onChatAnswerUpdated
37+
private chatItems: Map<string, Map<string, ChatItem>> = new Map() // tabId -> messageId -> ChatItem
3638

3739
override getTabType(): TabType {
3840
return 'cwc'
@@ -109,6 +111,10 @@ export class Connector extends BaseConnector {
109111
title: messageData.title,
110112
buttons: messageData.buttons ?? undefined,
111113
fileList: messageData.fileList ?? undefined,
114+
header: messageData.header ?? undefined,
115+
padding: messageData.padding ?? undefined,
116+
fullWidth: messageData.fullWidth ?? undefined,
117+
codeBlockActions: messageData.codeBlockActions ?? undefined,
112118
}
113119

114120
if (messageData.relatedSuggestions !== undefined) {
@@ -117,6 +123,10 @@ export class Connector extends BaseConnector {
117123
content: messageData.relatedSuggestions,
118124
}
119125
}
126+
127+
if (answer.messageId) {
128+
this.storeChatItem(messageData.tabID, answer.messageId, answer)
129+
}
120130
this.onChatAnswerReceived(messageData.tabID, answer, messageData)
121131

122132
// Exit the function if we received an answer from AI
@@ -147,6 +157,10 @@ export class Connector extends BaseConnector {
147157
: undefined,
148158
buttons: messageData.buttons ?? undefined,
149159
canBeVoted: messageData.canBeVoted ?? false,
160+
header: messageData.header ?? undefined,
161+
padding: messageData.padding ?? undefined,
162+
fullWidth: messageData.fullWidth ?? undefined,
163+
codeBlockActions: messageData.codeBlockActions ?? undefined,
150164
}
151165
this.onChatAnswerReceived(messageData.tabID, answer, messageData)
152166

@@ -171,11 +185,29 @@ export class Connector extends BaseConnector {
171185
title: messageData.title,
172186
buttons: messageData.buttons,
173187
fileList: messageData.fileList,
188+
header: messageData.header ?? undefined,
189+
padding: messageData.padding ?? undefined,
190+
fullWidth: messageData.fullWidth ?? undefined,
191+
codeBlockActions: messageData.codeBlockActions ?? undefined,
192+
}
193+
if (answer.messageId) {
194+
this.storeChatItem(messageData.tabID, answer.messageId, answer)
174195
}
175196
this.onChatAnswerUpdated(messageData.tabID, answer)
176197
return
177198
}
178199

200+
private storeChatItem(tabId: string, messageId: string, item: ChatItem): void {
201+
if (!this.chatItems.has(tabId)) {
202+
this.chatItems.set(tabId, new Map())
203+
}
204+
this.chatItems.get(tabId)?.set(messageId, { ...item })
205+
}
206+
207+
private getCurrentChatItem(tabId: string, messageId: string): ChatItem | undefined {
208+
return this.chatItems.get(tabId)?.get(messageId)
209+
}
210+
179211
processContextCommandData(messageData: any) {
180212
if (messageData.data) {
181213
this.onContextCommandDataReceived(messageData.data)
@@ -297,35 +329,39 @@ export class Connector extends BaseConnector {
297329
) {
298330
return
299331
}
332+
333+
// Can not assign body as "undefined" or "null" because both of these values will be overriden at main.ts in onChatAnswerUpdated
334+
// TODO: Refactor in next PR if necessary.
335+
const currentChatItem = this.getCurrentChatItem(tabId, messageId)
300336
const answer: ChatItem = {
301337
type: ChatItemType.ANSWER,
302338
messageId: messageId,
303339
buttons: [],
340+
body: undefined,
341+
header: currentChatItem?.header ? { ...currentChatItem.header } : {},
304342
}
305343
switch (action.id) {
306344
case 'accept-code-diff':
307-
answer.buttons = [
308-
{
309-
keepCardAfterClick: true,
310-
text: 'Accepted code',
311-
id: 'accepted-code-diff',
345+
if (answer.header) {
346+
answer.header.status = {
347+
icon: 'ok' as MynahIconsType,
348+
text: 'Accepted',
312349
status: 'success',
313-
position: 'outside',
314-
disabled: true,
315-
},
316-
]
350+
}
351+
answer.header.buttons = []
352+
answer.body = ' '
353+
}
317354
break
318355
case 'reject-code-diff':
319-
answer.buttons = [
320-
{
321-
keepCardAfterClick: true,
322-
text: 'Rejected code',
323-
id: 'rejected-code-diff',
356+
if (answer.header) {
357+
answer.header.status = {
358+
icon: 'cancel' as MynahIconsType,
359+
text: 'Rejected',
324360
status: 'error',
325-
position: 'outside',
326-
disabled: true,
327-
},
328-
]
361+
}
362+
answer.header.buttons = []
363+
answer.body = ' '
364+
}
329365
break
330366
case 'confirm-tool-use':
331367
answer.buttons = [
@@ -342,6 +378,12 @@ export class Connector extends BaseConnector {
342378
default:
343379
break
344380
}
381+
382+
if (currentChatItem && answer.messageId) {
383+
const updatedItem = { ...currentChatItem, ...answer }
384+
this.storeChatItem(tabId, answer.messageId, updatedItem)
385+
}
386+
345387
this.onChatAnswerUpdated(tabId, answer)
346388
}
347389

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ export const createMynahUI = (
332332
...(item.footer !== undefined ? { footer: item.footer } : {}),
333333
...(item.canBeVoted !== undefined ? { canBeVoted: item.canBeVoted } : {}),
334334
...(item.fileList !== undefined ? { fileList: item.fileList } : {}),
335+
...(item.header !== undefined ? { header: item.header } : {}),
336+
...(item.buttons !== undefined ? { buttons: item.buttons } : {}),
337+
...(item.fullWidth !== undefined ? { fullWidth: item.fullWidth } : {}),
338+
...(item.padding !== undefined ? { padding: item.padding } : {}),
339+
...(item.codeBlockActions !== undefined ? { codeBlockActions: item.codeBlockActions } : {}),
335340
})
336341
} else {
337342
mynahUI.updateLastChatAnswer(tabID, {
@@ -340,6 +345,11 @@ export const createMynahUI = (
340345
...(item.followUp !== undefined ? { followUp: item.followUp } : {}),
341346
...(item.footer !== undefined ? { footer: item.footer } : {}),
342347
...(item.canBeVoted !== undefined ? { canBeVoted: item.canBeVoted } : {}),
348+
...(item.header !== undefined ? { header: item.header } : {}),
349+
...(item.buttons !== undefined ? { buttons: item.buttons } : {}),
350+
...(item.fullWidth !== undefined ? { fullWidth: item.fullWidth } : {}),
351+
...(item.padding !== undefined ? { padding: item.padding } : {}),
352+
...(item.codeBlockActions !== undefined ? { codeBlockActions: item.codeBlockActions } : {}),
343353
})
344354
}
345355
},
@@ -353,8 +363,11 @@ export const createMynahUI = (
353363
...(item.relatedContent !== undefined ? { relatedContent: item.relatedContent } : {}),
354364
...(item.followUp !== undefined ? { followUp: item.followUp } : {}),
355365
...(item.fileList !== undefined ? { fileList: item.fileList } : {}),
356-
...(item.header !== undefined ? { header: item.header } : { header: undefined }),
357-
...(item.buttons !== undefined ? { buttons: item.buttons } : { buttons: undefined }),
366+
...(item.header !== undefined ? { header: item.header } : {}),
367+
...(item.buttons !== undefined ? { buttons: item.buttons } : {}),
368+
...(item.fullWidth !== undefined ? { fullWidth: item.fullWidth } : {}),
369+
...(item.padding !== undefined ? { padding: item.padding } : {}),
370+
...(item.codeBlockActions !== undefined ? { codeBlockActions: item.codeBlockActions } : {}),
358371
})
359372
if (
360373
item.messageId !== undefined &&

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ import { LspController } from '../../../../amazonq/lsp/lspController'
4040
import { extractCodeBlockLanguage } from '../../../../shared/markdown'
4141
import { extractAuthFollowUp } from '../../../../amazonq/util/authUtils'
4242
import { helpMessage } from '../../../../amazonq/webview/ui/texts/constants'
43-
import { ChatItemButton, ChatItemContent, ChatItemFormItem, MynahUIDataModel } from '@aws/mynah-ui'
43+
import { ChatItemButton, ChatItemContent, ChatItemFormItem, MynahIconsType, MynahUIDataModel } from '@aws/mynah-ui'
4444
import { ChatHistoryManager } from '../../../storages/chatHistory'
4545
import { ToolType, ToolUtils } from '../../../tools/toolUtils'
4646
import { ChatStream } from '../../../tools/chatStream'
47-
import path from 'path'
4847
import { getWorkspaceForFile } from '../../../../shared/utilities/workspaceUtils'
48+
import path from 'path'
4949
import { CommandValidation } from '../../../tools/executeBash'
5050

5151
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
@@ -241,7 +241,7 @@ export class Messenger {
241241
validation,
242242
session.messageIdToUpdate
243243
)
244-
ToolUtils.queueDescription(tool, chatStream)
244+
await ToolUtils.queueDescription(tool, chatStream)
245245

246246
if (
247247
session.messageIdToUpdate === undefined &&
@@ -488,35 +488,44 @@ export class Messenger {
488488
buttons.push({
489489
id: 'confirm-tool-use',
490490
text: 'Confirm',
491-
position: 'outside',
492491
status: 'info',
493492
})
494493

495494
if (validation.warning) {
496495
message = validation.warning + message
497496
}
498497
} else if (toolUse?.name === ToolType.FsWrite) {
499-
// FileList
500498
const absoluteFilePath = (toolUse?.input as any).path
501499
const projectPath = getWorkspaceForFile(absoluteFilePath)
502500
const relativePath = projectPath ? path.relative(projectPath, absoluteFilePath) : absoluteFilePath
501+
// FileList
503502
fileList = {
504-
fileTreeTitle: 'Code suggestions',
505-
rootFolderTitle: path.basename(projectPath ?? 'Default'),
503+
fileTreeTitle: '',
504+
hideFileCount: true,
506505
filePaths: [relativePath],
506+
details: {
507+
[relativePath]: {
508+
// eslint-disable-next-line unicorn/no-null
509+
icon: null,
510+
label: 'Created',
511+
changes: {
512+
added: 36,
513+
deleted: 0,
514+
total: 36,
515+
},
516+
},
517+
},
507518
}
508519
// Buttons
509520
buttons.push({
510521
id: 'reject-code-diff',
511-
text: 'Reject',
512-
position: 'outside',
513-
status: 'error',
522+
status: 'clear',
523+
icon: 'cancel' as MynahIconsType,
514524
})
515525
buttons.push({
516526
id: 'accept-code-diff',
517-
text: 'Accept',
518-
position: 'outside',
519-
status: 'success',
527+
status: 'clear',
528+
icon: 'ok' as MynahIconsType,
520529
})
521530
}
522531

@@ -534,8 +543,16 @@ export class Messenger {
534543
codeBlockLanguage: undefined,
535544
contextList: undefined,
536545
canBeVoted: false,
537-
buttons,
538-
fileList,
546+
buttons: toolUse?.name === ToolType.FsWrite ? undefined : buttons,
547+
fullWidth: toolUse?.name === ToolType.FsWrite,
548+
padding: !(toolUse?.name === ToolType.FsWrite),
549+
header:
550+
toolUse?.name === ToolType.FsWrite
551+
? { icon: 'code-block' as MynahIconsType, buttons: buttons, fileList: fileList }
552+
: undefined,
553+
codeBlockActions:
554+
// eslint-disable-next-line unicorn/no-null, prettier/prettier
555+
toolUse?.name === ToolType.FsWrite ? { 'insert-to-cursor': null, copy: null } : undefined,
539556
},
540557
tabID
541558
)

0 commit comments

Comments
 (0)