Skip to content

Commit 1c741c7

Browse files
committed
Adds capability to send new context commands to AB groups
1 parent c9b4746 commit 1c741c7

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
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/core/src/amazonq/webview/ui/main.ts

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

107107
let isDocEnabled = amazonQEnabled
108108

109+
// @ts-ignore
110+
let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)
111+
112+
const highlightCommand = featureConfigs.get('highlightCommand')
113+
109114
let tabDataGenerator = new TabDataGenerator({
110115
isFeatureDevEnabled,
111116
isGumbyEnabled,
112117
isScanEnabled,
113118
isTestEnabled,
114119
isDocEnabled,
115120
disabledCommands,
121+
highlightCommand,
116122
})
117123

118124
// eslint-disable-next-line prefer-const
@@ -124,9 +130,6 @@ export const createMynahUI = (
124130
// eslint-disable-next-line prefer-const
125131
let messageController: MessageController
126132

127-
// @ts-ignore
128-
let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)
129-
130133
function getCodeBlockActions(messageData: any) {
131134
// Show ViewDiff and AcceptDiff for allowedCommands in CWC
132135
const isEnabled = featureConfigs.get('ViewDiffInChat')?.variation === 'TREATMENT'
@@ -199,6 +202,7 @@ export const createMynahUI = (
199202
isTestEnabled,
200203
isDocEnabled,
201204
disabledCommands,
205+
highlightCommand,
202206
})
203207

204208
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+
highlightCommand?: 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.highlightCommand
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
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import assert from 'assert'
6+
import { QuickActionCommandGroup } from '@aws/mynah-ui'
7+
import { FeatureContext } from '../../shared'
8+
import { TabDataGenerator, TabDataGeneratorProps } from '../../amazonq/webview/ui/tabs/generator'
9+
10+
describe('TabDataGenerator', () => {
11+
let highlightCommand: FeatureContext
12+
let expectedTabCommand: QuickActionCommandGroup
13+
let props: TabDataGeneratorProps
14+
const tabType = 'cwc'
15+
16+
beforeEach(async () => {
17+
highlightCommand = {
18+
name: 'featureCustomizationName',
19+
value: {
20+
stringValue: 'featureCustomizationArn',
21+
},
22+
variation: 'featureCustomizationName',
23+
}
24+
25+
expectedTabCommand = {
26+
groupName: 'Additional Commands',
27+
commands: [
28+
{
29+
command: highlightCommand.value.stringValue!,
30+
description: highlightCommand?.variation,
31+
},
32+
],
33+
}
34+
35+
props = {
36+
isDocEnabled: false,
37+
isFeatureDevEnabled: false,
38+
isGumbyEnabled: false,
39+
isScanEnabled: false,
40+
isTestEnabled: false,
41+
}
42+
})
43+
44+
it('insert code when left hand size has no non empty character', async () => {
45+
props.highlightCommand = highlightCommand
46+
const tabGenerator = new TabDataGenerator(props)
47+
const tabData = tabGenerator.getTabData(tabType, false)
48+
49+
assert.equal(tabData.contextCommands?.includes(expectedTabCommand), true)
50+
})
51+
52+
it('insert code when left hand size has no non empty character2', async () => {
53+
props.highlightCommand = undefined
54+
const tabGenerator = new TabDataGenerator(props)
55+
const tabData = tabGenerator.getTabData(tabType, false)
56+
57+
assert.equal(tabData.contextCommands?.includes(expectedTabCommand), false)
58+
})
59+
})

0 commit comments

Comments
 (0)