Skip to content

Commit 613bf5f

Browse files
authored
feat(amazonq): capability to send new context commands to AB groups (#6239)
## Problem When working on new features available to AB groups, the new action are not easily discoverable to users ## Solution Add the ability to send a new command that will appear when a user types @ in the chat window --- - 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 d2cde47 commit 613bf5f

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Adds capability to send new context commands to AB groups"
4+
}

packages/amazonq/test/e2e/amazonq/welcome.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import sinon from 'sinon'
99
import { Messenger } from './framework/messenger'
1010
import { MynahUIDataModel } from '@aws/mynah-ui'
1111
import { assertQuickActions } from './assert'
12+
import { FeatureContext } from 'aws-core-vscode/shared'
1213

1314
describe('Amazon Q Welcome page', function () {
1415
let framework: qTestingFramework
@@ -17,8 +18,15 @@ describe('Amazon Q Welcome page', function () {
1718

1819
const availableCommands = ['/dev', '/test', '/review', '/doc', '/transform']
1920

21+
const highlightCommand: FeatureContext = {
22+
name: 'highlightCommand',
23+
value: {
24+
stringValue: '@highlight',
25+
},
26+
variation: 'highlight command desc',
27+
}
2028
beforeEach(() => {
21-
framework = new qTestingFramework('welcome', true, [], 0)
29+
framework = new qTestingFramework('welcome', true, [['highlightCommand', highlightCommand]], 0)
2230
tab = framework.getTabs()[0] // use the default tab that gets created
2331
store = tab.getStore()
2432
})
@@ -33,13 +41,13 @@ describe('Amazon Q Welcome page', function () {
3341
assertQuickActions(tab, availableCommands)
3442
})
3543

36-
it('Shows @workspace', async () => {
44+
it('Shows context commands', async () => {
3745
assert.deepStrictEqual(
3846
store.contextCommands
3947
?.map((x) => x.commands)
4048
.flat()
4149
.map((x) => x.command),
42-
['@workspace']
50+
['@workspace', '@highlight']
4351
)
4452
})
4553

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,18 @@ export const createMynahUI = (
106106

107107
let isDocEnabled = amazonQEnabled
108108

109+
let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)
110+
111+
const highlightCommand = featureConfigs.get('highlightCommand')
112+
109113
let tabDataGenerator = new TabDataGenerator({
110114
isFeatureDevEnabled,
111115
isGumbyEnabled,
112116
isScanEnabled,
113117
isTestEnabled,
114118
isDocEnabled,
115119
disabledCommands,
120+
commandHighlight: highlightCommand,
116121
})
117122

118123
// eslint-disable-next-line prefer-const
@@ -124,9 +129,6 @@ export const createMynahUI = (
124129
// eslint-disable-next-line prefer-const
125130
let messageController: MessageController
126131

127-
// @ts-ignore
128-
let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)
129-
130132
function getCodeBlockActions(messageData: any) {
131133
// Show ViewDiff and AcceptDiff for allowedCommands in CWC
132134
const isEnabled = featureConfigs.get('ViewDiffInChat')?.variation === 'TREATMENT'
@@ -199,6 +201,7 @@ export const createMynahUI = (
199201
isTestEnabled,
200202
isDocEnabled,
201203
disabledCommands,
204+
commandHighlight: highlightCommand,
202205
})
203206

204207
featureConfigs = tryNewMap(featureConfigsSerialized)

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { ChatItemType, MynahUIDataModel } from '@aws/mynah-ui'
6+
import { ChatItemType, MynahUIDataModel, QuickActionCommandGroup } from '@aws/mynah-ui'
77
import { TabType } from '../storages/tabsStorage'
88
import { FollowUpGenerator } from '../followUps/generator'
99
import { QuickActionGenerator } from '../quickActions/generator'
1010
import { TabTypeDataMap } from './constants'
1111
import { agentWalkthroughDataModel } from '../walkthrough/agent'
12+
import { FeatureContext } from '../../../../shared'
1213

1314
export interface TabDataGeneratorProps {
1415
isFeatureDevEnabled: boolean
@@ -17,11 +18,13 @@ export interface TabDataGeneratorProps {
1718
isTestEnabled: boolean
1819
isDocEnabled: boolean
1920
disabledCommands?: string[]
21+
commandHighlight?: FeatureContext
2022
}
2123

2224
export class TabDataGenerator {
2325
private followUpsGenerator: FollowUpGenerator
2426
public quickActionsGenerator: QuickActionGenerator
27+
private highlightCommand?: FeatureContext
2528

2629
constructor(props: TabDataGeneratorProps) {
2730
this.followUpsGenerator = new FollowUpGenerator()
@@ -33,6 +36,7 @@ export class TabDataGenerator {
3336
isDocEnabled: props.isDocEnabled,
3437
disableCommands: props.disabledCommands,
3538
})
39+
this.highlightCommand = props.commandHighlight
3640
}
3741

3842
public getTabData(tabType: TabType, needWelcomeMessages: boolean, taskName?: string): MynahUIDataModel {
@@ -50,7 +54,7 @@ export class TabDataGenerator {
5054
'Amazon Q Developer uses generative AI. You may need to verify responses. See the [AWS Responsible AI Policy](https://aws.amazon.com/machine-learning/responsible-ai/policy/).',
5155
quickActionCommands: this.quickActionsGenerator.generateForTab(tabType),
5256
promptInputPlaceholder: TabTypeDataMap[tabType].placeholder,
53-
contextCommands: TabTypeDataMap[tabType].contextCommands,
57+
contextCommands: this.getContextCommands(tabType),
5458
chatItems: needWelcomeMessages
5559
? [
5660
{
@@ -66,4 +70,32 @@ export class TabDataGenerator {
6670
}
6771
return tabData
6872
}
73+
74+
private getContextCommands(tabType: TabType): QuickActionCommandGroup[] | undefined {
75+
if (tabType === 'agentWalkthrough' || tabType === 'welcome') {
76+
return
77+
}
78+
79+
const commandName = this.highlightCommand?.value.stringValue
80+
if (commandName === undefined || commandName === '') {
81+
return TabTypeDataMap[tabType].contextCommands
82+
} else {
83+
const commandHighlight: QuickActionCommandGroup = {
84+
groupName: 'Additional Commands',
85+
commands: [
86+
{
87+
command: commandName,
88+
description: this.highlightCommand?.variation,
89+
},
90+
],
91+
}
92+
93+
const contextCommands = TabTypeDataMap[tabType].contextCommands
94+
if (contextCommands === undefined) {
95+
return [commandHighlight]
96+
} else {
97+
return [...contextCommands, commandHighlight]
98+
}
99+
}
100+
}
69101
}

0 commit comments

Comments
 (0)