Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Adds capability to send new context commands to AB groups"
}
14 changes: 11 additions & 3 deletions packages/amazonq/test/e2e/amazonq/welcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sinon from 'sinon'
import { Messenger } from './framework/messenger'
import { MynahUIDataModel } from '@aws/mynah-ui'
import { assertQuickActions } from './assert'
import { FeatureContext } from 'aws-core-vscode/shared'

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

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

const highlightCommand: FeatureContext = {
name: 'highlightCommand',
value: {
stringValue: '@highlight',
},
variation: 'highlight command desc',
}
beforeEach(() => {
framework = new qTestingFramework('welcome', true, [], 0)
framework = new qTestingFramework('welcome', true, [['highlightCommand', highlightCommand]], 0)
tab = framework.getTabs()[0] // use the default tab that gets created
store = tab.getStore()
})
Expand All @@ -33,13 +41,13 @@ describe('Amazon Q Welcome page', function () {
assertQuickActions(tab, availableCommands)
})

it('Shows @workspace', async () => {
it('Shows context commands', async () => {
assert.deepStrictEqual(
store.contextCommands
?.map((x) => x.commands)
.flat()
.map((x) => x.command),
['@workspace']
['@workspace', '@highlight']
)
})

Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/amazonq/webview/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,18 @@ export const createMynahUI = (

let isDocEnabled = amazonQEnabled

let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)

const highlightCommand = featureConfigs.get('highlightCommand')

let tabDataGenerator = new TabDataGenerator({
isFeatureDevEnabled,
isGumbyEnabled,
isScanEnabled,
isTestEnabled,
isDocEnabled,
disabledCommands,
commandHighlight: highlightCommand,
})

// eslint-disable-next-line prefer-const
Expand All @@ -124,9 +129,6 @@ export const createMynahUI = (
// eslint-disable-next-line prefer-const
let messageController: MessageController

// @ts-ignore
let featureConfigs: Map<string, FeatureContext> = tryNewMap(featureConfigsSerialized)

function getCodeBlockActions(messageData: any) {
// Show ViewDiff and AcceptDiff for allowedCommands in CWC
const isEnabled = featureConfigs.get('ViewDiffInChat')?.variation === 'TREATMENT'
Expand Down Expand Up @@ -199,6 +201,7 @@ export const createMynahUI = (
isTestEnabled,
isDocEnabled,
disabledCommands,
commandHighlight: highlightCommand,
})

featureConfigs = tryNewMap(featureConfigsSerialized)
Expand Down
36 changes: 34 additions & 2 deletions packages/core/src/amazonq/webview/ui/tabs/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatItemType, MynahUIDataModel } from '@aws/mynah-ui'
import { ChatItemType, MynahUIDataModel, QuickActionCommandGroup } from '@aws/mynah-ui'
import { TabType } from '../storages/tabsStorage'
import { FollowUpGenerator } from '../followUps/generator'
import { QuickActionGenerator } from '../quickActions/generator'
import { TabTypeDataMap } from './constants'
import { agentWalkthroughDataModel } from '../walkthrough/agent'
import { FeatureContext } from '../../../../shared'

export interface TabDataGeneratorProps {
isFeatureDevEnabled: boolean
Expand All @@ -17,11 +18,13 @@ export interface TabDataGeneratorProps {
isTestEnabled: boolean
isDocEnabled: boolean
disabledCommands?: string[]
commandHighlight?: FeatureContext
}

export class TabDataGenerator {
private followUpsGenerator: FollowUpGenerator
public quickActionsGenerator: QuickActionGenerator
private highlightCommand?: FeatureContext

constructor(props: TabDataGeneratorProps) {
this.followUpsGenerator = new FollowUpGenerator()
Expand All @@ -33,6 +36,7 @@ export class TabDataGenerator {
isDocEnabled: props.isDocEnabled,
disableCommands: props.disabledCommands,
})
this.highlightCommand = props.commandHighlight
}

public getTabData(tabType: TabType, needWelcomeMessages: boolean, taskName?: string): MynahUIDataModel {
Expand All @@ -50,7 +54,7 @@ export class TabDataGenerator {
'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/).',
quickActionCommands: this.quickActionsGenerator.generateForTab(tabType),
promptInputPlaceholder: TabTypeDataMap[tabType].placeholder,
contextCommands: TabTypeDataMap[tabType].contextCommands,
contextCommands: this.getContextCommands(tabType),
chatItems: needWelcomeMessages
? [
{
Expand All @@ -66,4 +70,32 @@ export class TabDataGenerator {
}
return tabData
}

private getContextCommands(tabType: TabType): QuickActionCommandGroup[] | undefined {
if (tabType === 'agentWalkthrough' || tabType === 'welcome') {
return
}

const commandName = this.highlightCommand?.value.stringValue
if (commandName === undefined || commandName === '') {
return TabTypeDataMap[tabType].contextCommands
} else {
const commandHighlight: QuickActionCommandGroup = {
groupName: 'Additional Commands',
commands: [
{
command: commandName,
description: this.highlightCommand?.variation,
},
],
}

const contextCommands = TabTypeDataMap[tabType].contextCommands
if (contextCommands === undefined) {
return [commandHighlight]
} else {
return [...contextCommands, commandHighlight]
}
}
}
}
Loading