Skip to content

Commit c00d616

Browse files
committed
feat(amazonq): Handle disclaimer acknowledgement
1 parent a97614c commit c00d616

File tree

12 files changed

+71
-37
lines changed

12 files changed

+71
-37
lines changed

package-lock.json

+8-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amazonq/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
"amazonQWorkspaceLspManifestMessage": {
128128
"type": "boolean",
129129
"default": false
130+
},
131+
"amazonQChatDisclaimerAcknowledged": {
132+
"type": "boolean",
133+
"default": false
130134
}
131135
},
132136
"additionalProperties": false

packages/amazonq/src/lsp/chat/messages.ts

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CHAT_OPTIONS,
1111
COPY_TO_CLIPBOARD,
1212
AuthFollowUpType,
13+
DISCLAIMER_ACKNOWLEDGED,
1314
} from '@aws/chat-client-ui-types'
1415
import {
1516
ChatResult,
@@ -27,6 +28,7 @@ import { Disposable, LanguageClient, Position, State, TextDocumentIdentifier } f
2728
import * as jose from 'jose'
2829
import { AmazonQChatViewProvider } from './webviewProvider'
2930
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
31+
import { AmazonQPromptSettings } from 'aws-core-vscode/shared'
3032

3133
export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
3234
languageClient.onDidChangeState(({ oldState, newState }) => {
@@ -106,6 +108,10 @@ export function registerMessageListeners(
106108
}
107109
break
108110
}
111+
case DISCLAIMER_ACKNOWLEDGED: {
112+
void AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
113+
break
114+
}
109115
case chatRequestType.method: {
110116
const partialResultToken = uuidv4()
111117
const chatDisposable = languageClient.onProgress(chatRequestType, partialResultToken, (partialResult) =>

packages/amazonq/src/lsp/chat/webviewProvider.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {
1212
WebviewViewResolveContext,
1313
Uri,
1414
} from 'vscode'
15-
import { LanguageServerResolver } from 'aws-core-vscode/shared'
1615
import { QuickActionCommandGroup } from '@aws/mynah-ui'
1716
import * as path from 'path'
17+
import { LanguageServerResolver } from 'aws-core-vscode/shared'
18+
import { disclaimer } from 'aws-core-vscode/amazonq'
1819

1920
export class AmazonQChatViewProvider implements WebviewViewProvider {
2021
public static readonly viewType = 'aws.amazonq.AmazonQChatView'
@@ -43,7 +44,11 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
4344

4445
constructor(private readonly mynahUIPath: string) {}
4546

46-
public resolveWebviewView(webviewView: WebviewView, context: WebviewViewResolveContext, _token: CancellationToken) {
47+
public async resolveWebviewView(
48+
webviewView: WebviewView,
49+
context: WebviewViewResolveContext,
50+
_token: CancellationToken
51+
) {
4752
this.webview = webviewView.webview
4853

4954
const lspDir = Uri.parse(LanguageServerResolver.defaultDir)
@@ -54,12 +59,13 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
5459
}
5560

5661
const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
57-
webviewView.webview.html = this.getWebviewContent(uiPath)
62+
webviewView.webview.html = await this.getWebviewContent(uiPath)
5863

5964
this.onDidResolveWebviewEmitter.fire()
6065
}
6166

62-
private getWebviewContent(mynahUIPath: string) {
67+
private async getWebviewContent(mynahUIPath: string) {
68+
const disclaimerAcknowledged = await disclaimer.disclaimerAcknowledged()
6369
return `
6470
<!DOCTYPE html>
6571
<html lang="en">
@@ -84,7 +90,7 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
8490
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
8591
<script type="text/javascript">
8692
const init = () => {
87-
amazonQChat.createChat(acquireVsCodeApi(), { disclaimerAcknowledged: false, quickActionCommands: ${JSON.stringify(this.quickActionCommands)}});
93+
amazonQChat.createChat(acquireVsCodeApi(), { disclaimerAcknowledged: ${disclaimerAcknowledged}, quickActionCommands: ${JSON.stringify(this.quickActionCommands)}});
8894
}
8995
</script>
9096
</body>

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
},
441441
"devDependencies": {
442442
"@aws-sdk/types": "^3.13.1",
443-
"@aws/chat-client-ui-types": "^0.0.8",
443+
"@aws/chat-client-ui-types": "^0.1.12",
444444
"@aws/language-server-runtimes": "^0.2.49",
445445
"@aws/language-server-runtimes-types": "^0.1.10",
446446
"@cspotcode/source-map-support": "^0.8.1",

packages/core/src/amazonq/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export * from './lsp/config'
4848
export * as WorkspaceLspInstaller from './lsp/workspaceInstaller'
4949
export * as secondaryAuth from '../auth/secondaryAuth'
5050
export * as authConnection from '../auth/connection'
51+
export * as disclaimer from './util/disclaimer'
5152
import { FeatureContext } from '../shared/featureConfig'
5253

5354
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import globals from '../../shared/extensionGlobals'
7+
import { AmazonQPromptSettings } from '../../shared/settings'
8+
9+
/**
10+
* If the previous global state was acknowledged, then suppress the prompt and set global state to false
11+
* Otherwise, the new flows will enable amazonQChatDisclaimerAcknowledged directly
12+
*/
13+
export async function disclaimerAcknowledged(): Promise<boolean> {
14+
const acknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)
15+
if (acknowledged) {
16+
await AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
17+
await globals.globalState.update('aws.amazonq.disclaimerAcknowledged', false)
18+
}
19+
20+
return AmazonQPromptSettings.instance.get('amazonQChatDisclaimerAcknowledged', false)
21+
}

packages/core/src/amazonq/webview/generators/webViewContent.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
99
import { FeatureConfigProvider, FeatureContext } from '../../../shared/featureConfig'
1010
import globals from '../../../shared/extensionGlobals'
1111
import { isSageMaker } from '../../../shared/extensionUtilities'
12+
import { disclaimerAcknowledged } from '../../util/disclaimer'
1213

1314
export class WebViewContentGenerator {
1415
private async generateFeatureConfigsData(): Promise<string> {
@@ -80,8 +81,7 @@ export class WebViewContentGenerator {
8081
const featureConfigsString = await this.generateFeatureConfigsData()
8182

8283
const disabledCommandsString = isSageMaker() ? `['/dev', '/transform']` : '[]'
83-
const disclaimerAcknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)
84-
84+
const enableDisclaimer = await disclaimerAcknowledged()
8585
const welcomeLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
8686
const isSMUS = isSageMaker('SMUS')
8787

@@ -92,7 +92,7 @@ export class WebViewContentGenerator {
9292
const init = () => {
9393
createMynahUI(acquireVsCodeApi(), ${
9494
(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
95-
},${featureConfigsString},${welcomeLoadCount},${disclaimerAcknowledged},${disabledCommandsString},${isSMUS});
95+
},${featureConfigsString},${welcomeLoadCount},${enableDisclaimer},${disabledCommandsString},${isSMUS});
9696
}
9797
</script>
9898
`

packages/core/src/amazonq/webview/messages/messageDispatcher.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { isClickTelemetry, isOpenAgentTelemetry } from '../ui/telemetry/actions'
1515
import globals from '../../../shared/extensionGlobals'
1616
import { openUrl } from '../../../shared/utilities/vsCodeUtils'
1717
import { DefaultAmazonQAppInitContext } from '../../apps/initContext'
18+
import { AmazonQPromptSettings } from '../../../shared/settings'
1819

1920
const qChatModuleName = 'amazonqChat'
2021

@@ -77,7 +78,7 @@ export function dispatchWebViewMessagesToApps(
7778
return
7879
}
7980
case 'disclaimer-acknowledged': {
80-
globals.globalState.tryUpdate('aws.amazonq.disclaimerAcknowledged', true)
81+
void AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
8182
return
8283
}
8384
case 'update-welcome-count': {

packages/core/src/shared/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export { activate as activateLogger } from './logger/activation'
1313
export { activate as activateTelemetry } from './telemetry/activation'
1414
export { DefaultAwsContext } from './awsContext'
1515
export { DefaultAWSClientBuilder, ServiceOptions } from './awsClientBuilder'
16-
export { Settings, Experiments, DevSettings } from './settings'
16+
export { Settings, Experiments, DevSettings, AmazonQPromptSettings } from './settings'
1717
export * from './extensionUtilities'
1818
export * from './extensionStartup'
1919
export { RegionProvider } from './regions/regionProvider'

packages/core/src/shared/settings-amazonq.gen.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const amazonqSettings = {
2020
"minIdeVersion": {},
2121
"ssoCacheError": {},
2222
"amazonQLspManifestMessage": {},
23-
"amazonQWorkspaceLspManifestMessage": {}
23+
"amazonQWorkspaceLspManifestMessage": {},
24+
"amazonQChatDisclaimerAcknowledged": {}
2425
},
2526
"amazonQ.showCodeWithReferences": {},
2627
"amazonQ.allowFeatureDevelopmentToRunCodeAndTests": {},

packages/webpack.web.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ module.exports = (env, argv) => {
5050
new webpack.IgnorePlugin({
5151
resourceRegExp: /ps-list/, // matches the path in the require() statement
5252
}),
53+
/**
54+
* HACK: the glob module breaks Web mode if imported, BUT we still dynamically import this module for non web mode
55+
* environments. The following allows compilation to pass by never bundling the module in the final output for web mode.
56+
*/
57+
new webpack.IgnorePlugin({
58+
resourceRegExp: /glob/, // matches the path in the require() statement
59+
}),
5360
],
5461
resolve: {
5562
extensions: ['.ts', '.js'],
@@ -76,6 +83,10 @@ module.exports = (env, argv) => {
7683
child_process: false, // Reason for error: 'TypeError: The "original" argument must be of type Function'
7784
async_hooks: false,
7885
net: false,
86+
87+
// codewhisperer chat imports jsdom which doesn't run in web mode
88+
vm: false,
89+
tls: false,
7990
},
8091
},
8192
optimization: {

0 commit comments

Comments
 (0)