Skip to content

Commit 7a3f7fe

Browse files
authored
feat(amazonq): saved prompts (aws#7)
* feat(amazonq): saved prompts * fix: remove unecessary change
1 parent 435ee79 commit 7a3f7fe

File tree

11 files changed

+314
-10
lines changed

11 files changed

+314
-10
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { ChatItemType, MynahUIDataModel } from '@aws/mynah-ui'
6+
import { ChatItemButton, ChatItemFormItem, ChatItemType, MynahUIDataModel } from '@aws/mynah-ui'
77
import { TabType } from '../storages/tabsStorage'
88
import { CWCChatItem } from '../connector'
99
import { BaseConnector, BaseConnectorProps } from './baseConnector'
1010

1111
export interface ConnectorProps extends BaseConnectorProps {
1212
onCWCContextCommandMessage: (message: CWCChatItem, command?: string) => string | undefined
1313
onContextCommandDataReceived: (data: MynahUIDataModel['contextCommands']) => void
14+
onShowCustomForm: (
15+
tabId: string,
16+
formItems?: ChatItemFormItem[],
17+
buttons?: ChatItemButton[],
18+
title?: string,
19+
description?: string
20+
) => void
1421
}
1522

1623
export class Connector extends BaseConnector {
1724
private readonly onCWCContextCommandMessage
1825
private readonly onContextCommandDataReceived
26+
private readonly onShowCustomForm
1927

2028
override getTabType(): TabType {
2129
return 'cwc'
@@ -25,6 +33,7 @@ export class Connector extends BaseConnector {
2533
super(props)
2634
this.onCWCContextCommandMessage = props.onCWCContextCommandMessage
2735
this.onContextCommandDataReceived = props.onContextCommandDataReceived
36+
this.onShowCustomForm = props.onShowCustomForm
2837
}
2938

3039
onSourceLinkClick = (tabID: string, messageId: string, link: string): void => {
@@ -140,6 +149,16 @@ export class Connector extends BaseConnector {
140149
}
141150
}
142151

152+
private showCustomFormMessage = (messageData: any) => {
153+
this.onShowCustomForm(
154+
messageData.tabID,
155+
messageData.formItems,
156+
messageData.buttons,
157+
messageData.title,
158+
messageData.description
159+
)
160+
}
161+
143162
handleMessageReceive = async (messageData: any): Promise<void> => {
144163
if (messageData.type === 'chatMessage') {
145164
await this.processChatMessage(messageData)
@@ -155,7 +174,45 @@ export class Connector extends BaseConnector {
155174
await this.processContextCommandData(messageData)
156175
return
157176
}
177+
if (messageData.type === 'showCustomFormMessage') {
178+
this.showCustomFormMessage(messageData)
179+
return
180+
}
181+
182+
if (messageData.type === 'customFormActionMessage') {
183+
this.onCustomFormAction(messageData.tabID, messageData.action)
184+
return
185+
}
158186
// For other message types, call the base class handleMessageReceive
159187
await this.baseHandleMessageReceive(messageData)
160188
}
189+
190+
onQuickCommandGroupActionClick = (tabID: string, action: { id: string }) => {
191+
this.sendMessageToExtension({
192+
command: 'quick-command-group-action-click',
193+
actionId: action.id,
194+
tabID,
195+
tabType: this.getTabType(),
196+
})
197+
}
198+
199+
onCustomFormAction(
200+
tabId: string,
201+
action: {
202+
id: string
203+
text?: string | undefined
204+
formItemValues?: Record<string, string> | undefined
205+
}
206+
) {
207+
if (action === undefined) {
208+
return
209+
}
210+
211+
this.sendMessageToExtension({
212+
command: 'form-action-click',
213+
action: action,
214+
tabType: this.getTabType(),
215+
tabID: tabId,
216+
})
217+
}
161218
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ type MessageCommand =
4242
| 'open-link'
4343
| 'send-telemetry'
4444
| 'update-welcome-count'
45+
| 'quick-command-group-action-click'
4546

4647
export type ExtensionMessage = Record<string, any> & { command: MessageCommand }

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
ChatPrompt,
1515
MynahUIDataModel,
1616
QuickActionCommand,
17+
ChatItemFormItem,
18+
ChatItemButton,
1719
} from '@aws/mynah-ui'
1820
import { Connector as CWChatConnector } from './apps/cwChatConnector'
1921
import { Connector as FeatureDevChatConnector } from './apps/featureDevChatConnector'
@@ -91,6 +93,13 @@ export interface ConnectorProps {
9193
handleCommand: (chatPrompt: ChatPrompt, tabId: string) => void
9294
sendStaticMessages: (tabID: string, messages: ChatItem[]) => void
9395
onContextCommandDataReceived: (message: MynahUIDataModel['contextCommands']) => void
96+
onShowCustomForm: (
97+
tabId: string,
98+
formItems?: ChatItemFormItem[],
99+
buttons?: ChatItemButton[],
100+
title?: string,
101+
description?: string
102+
) => void
94103
tabsStorage: TabsStorage
95104
}
96105

@@ -612,6 +621,14 @@ export class Connector {
612621
}
613622
}
614623

624+
onQuickCommandGroupActionClick = (tabId: string, action: { id: string }) => {
625+
switch (this.tabsStorage.getTab(tabId)?.type) {
626+
case 'cwc':
627+
this.cwChatConnector.onQuickCommandGroupActionClick(tabId, action)
628+
break
629+
}
630+
}
631+
615632
onChatItemVoted = (tabId: string, messageId: string, vote: 'upvote' | 'downvote'): void | undefined => {
616633
switch (this.tabsStorage.getTab(tabId)?.type) {
617634
case 'cwc':
@@ -655,6 +672,8 @@ export class Connector {
655672
type: '',
656673
tabType: 'cwc',
657674
})
675+
} else {
676+
this.cwChatConnector.onCustomFormAction(tabId, action)
658677
}
659678
break
660679
case 'agentWalkthrough': {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
NotificationType,
1414
ReferenceTrackerInformation,
1515
ProgressField,
16+
ChatItemButton,
17+
ChatItemFormItem,
1618
} from '@aws/mynah-ui'
1719
import { ChatPrompt } from '@aws/mynah-ui/dist/static'
1820
import { TabsStorage, TabType } from './storages/tabsStorage'
@@ -570,6 +572,15 @@ export const createMynahUI = (
570572
}
571573
}
572574
},
575+
onShowCustomForm(
576+
tabId: string,
577+
formItems?: ChatItemFormItem[],
578+
buttons?: ChatItemButton[],
579+
title?: string,
580+
description?: string
581+
) {
582+
mynahUI.showCustomForm(tabId, formItems, buttons, title, description)
583+
},
573584
})
574585

575586
mynahUI = new MynahUI({
@@ -670,6 +681,7 @@ export const createMynahUI = (
670681
// handler for the cwc panel
671682
textMessageHandler.handle(prompt, tabID, eventId as string)
672683
},
684+
onQuickCommandGroupActionClick: connector.onQuickCommandGroupActionClick,
673685
onVote: connector.onChatItemVoted,
674686
onInBodyButtonClicked: (tabId, messageId, action, eventId) => {
675687
switch (action.id) {

packages/core/src/amazonq/webview/ui/tabs/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type TabTypeData = {
1313
contextCommands?: QuickActionCommandGroup[]
1414
}
1515

16-
const workspaceCommand: QuickActionCommandGroup = {
16+
export const workspaceCommand: QuickActionCommandGroup = {
1717
groupName: 'Mention code',
1818
commands: [
1919
{

packages/core/src/codewhispererChat/app.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import {
2626
TriggerTabIDReceived,
2727
UIFocusMessage,
2828
AcceptDiff,
29+
QuickCommandGroupActionClick,
2930
} from './controllers/chat/model'
3031
import { EditorContextCommand, registerCommands } from './commands/registerCommands'
32+
import { CustomFormActionMessage } from './view/connector/connector'
3133

3234
export function init(appContext: AmazonQAppInitContext) {
3335
const cwChatControllerEventEmitters = {
@@ -49,6 +51,8 @@ export function init(appContext: AmazonQAppInitContext) {
4951
processResponseBodyLinkClick: new EventEmitter<ResponseBodyLinkClickMessage>(),
5052
processFooterInfoLinkClick: new EventEmitter<FooterInfoLinkClick>(),
5153
processContextCommandUpdateMessage: new EventEmitter<any>(),
54+
processQuickCommandGroupActionClicked: new EventEmitter<QuickCommandGroupActionClick>(),
55+
processCustomFormAction: new EventEmitter<CustomFormActionMessage>(),
5256
}
5357

5458
const cwChatControllerMessageListeners = {
@@ -100,6 +104,12 @@ export function init(appContext: AmazonQAppInitContext) {
100104
processContextCommandUpdateMessage: new MessageListener<void>(
101105
cwChatControllerEventEmitters.processContextCommandUpdateMessage
102106
),
107+
processQuickCommandGroupActionClicked: new MessageListener<QuickCommandGroupActionClick>(
108+
cwChatControllerEventEmitters.processQuickCommandGroupActionClicked
109+
),
110+
processCustomFormAction: new MessageListener<CustomFormActionMessage>(
111+
cwChatControllerEventEmitters.processCustomFormAction
112+
),
103113
}
104114

105115
const cwChatControllerMessagePublishers = {
@@ -153,6 +163,12 @@ export function init(appContext: AmazonQAppInitContext) {
153163
processContextCommandUpdateMessage: new MessagePublisher<void>(
154164
cwChatControllerEventEmitters.processContextCommandUpdateMessage
155165
),
166+
processQuickCommandGroupActionClicked: new MessagePublisher<QuickCommandGroupActionClick>(
167+
cwChatControllerEventEmitters.processQuickCommandGroupActionClicked
168+
),
169+
processCustomFormAction: new MessagePublisher<CustomFormActionMessage>(
170+
cwChatControllerEventEmitters.processCustomFormAction
171+
),
156172
}
157173

158174
new CwChatController(

0 commit comments

Comments
 (0)