Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amazonq): Handle disclaimer acknowledgement #6825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 8 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/amazonq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
"amazonQWorkspaceLspManifestMessage": {
"type": "boolean",
"default": false
},
"amazonQChatDisclaimerAcknowledged": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion packages/amazonq/src/app/inline/sessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes-types/inlineCompletionWithReferences'
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes-types'

// TODO: add more needed data to the session interface
interface CodeWhispererSession {
Expand Down
6 changes: 6 additions & 0 deletions packages/amazonq/src/lsp/chat/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CHAT_OPTIONS,
COPY_TO_CLIPBOARD,
AuthFollowUpType,
DISCLAIMER_ACKNOWLEDGED,
} from '@aws/chat-client-ui-types'
import {
ChatResult,
Expand All @@ -27,6 +28,7 @@ import { Disposable, LanguageClient, Position, State, TextDocumentIdentifier } f
import * as jose from 'jose'
import { AmazonQChatViewProvider } from './webviewProvider'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { AmazonQPromptSettings } from 'aws-core-vscode/shared'

export function registerLanguageServerEventListener(languageClient: LanguageClient, provider: AmazonQChatViewProvider) {
languageClient.onDidChangeState(({ oldState, newState }) => {
Expand Down Expand Up @@ -106,6 +108,10 @@ export function registerMessageListeners(
}
break
}
case DISCLAIMER_ACKNOWLEDGED: {
void AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
break
}
case chatRequestType.method: {
const partialResultToken = uuidv4()
const chatDisposable = languageClient.onProgress(chatRequestType, partialResultToken, (partialResult) =>
Expand Down
16 changes: 11 additions & 5 deletions packages/amazonq/src/lsp/chat/webviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
WebviewViewResolveContext,
Uri,
} from 'vscode'
import { LanguageServerResolver } from 'aws-core-vscode/shared'
import { QuickActionCommandGroup } from '@aws/mynah-ui'
import * as path from 'path'
import { LanguageServerResolver } from 'aws-core-vscode/shared'
import { disclaimer } from 'aws-core-vscode/amazonq'

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

constructor(private readonly mynahUIPath: string) {}

public resolveWebviewView(webviewView: WebviewView, context: WebviewViewResolveContext, _token: CancellationToken) {
public async resolveWebviewView(
webviewView: WebviewView,
context: WebviewViewResolveContext,
_token: CancellationToken
) {
this.webview = webviewView.webview

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

const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
webviewView.webview.html = this.getWebviewContent(uiPath)
webviewView.webview.html = await this.getWebviewContent(uiPath)

this.onDidResolveWebviewEmitter.fire()
}

private getWebviewContent(mynahUIPath: string) {
private async getWebviewContent(mynahUIPath: string) {
const disclaimerAcknowledged = await disclaimer.disclaimerAcknowledged()
return `
<!DOCTYPE html>
<html lang="en">
Expand All @@ -84,7 +90,7 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
<script type="text/javascript">
const init = () => {
amazonQChat.createChat(acquireVsCodeApi(), { disclaimerAcknowledged: false, quickActionCommands: ${JSON.stringify(this.quickActionCommands)}});
amazonQChat.createChat(acquireVsCodeApi(), { disclaimerAcknowledged: ${disclaimerAcknowledged}, quickActionCommands: ${JSON.stringify(this.quickActionCommands)}});
}
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
},
"devDependencies": {
"@aws-sdk/types": "^3.13.1",
"@aws/chat-client-ui-types": "^0.0.8",
"@aws/chat-client-ui-types": "^0.1.12",
"@aws/language-server-runtimes": "^0.2.49",
"@aws/language-server-runtimes-types": "^0.1.10",
"@cspotcode/source-map-support": "^0.8.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/amazonq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from './lsp/config'
export * as WorkspaceLspInstaller from './lsp/workspaceInstaller'
export * as secondaryAuth from '../auth/secondaryAuth'
export * as authConnection from '../auth/connection'
export * as disclaimer from './util/disclaimer'
import { FeatureContext } from '../shared/featureConfig'

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/amazonq/util/disclaimer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import globals from '../../shared/extensionGlobals'
import { AmazonQPromptSettings } from '../../shared/settings'

/**
* If the previous global state was acknowledged, then suppress the prompt and set global state to false
* Otherwise, the new flows will enable amazonQChatDisclaimerAcknowledged directly
*/
export async function disclaimerAcknowledged(): Promise<boolean> {
const acknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)
if (acknowledged) {
await AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
await globals.globalState.update('aws.amazonq.disclaimerAcknowledged', false)
}

return AmazonQPromptSettings.instance.get('amazonQChatDisclaimerAcknowledged', false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
import { FeatureConfigProvider, FeatureContext } from '../../../shared/featureConfig'
import globals from '../../../shared/extensionGlobals'
import { isSageMaker } from '../../../shared/extensionUtilities'
import { disclaimerAcknowledged } from '../../util/disclaimer'

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

const disabledCommandsString = isSageMaker() ? `['/dev', '/transform']` : '[]'
const disclaimerAcknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)

const enableDisclaimer = await disclaimerAcknowledged()
const welcomeLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
const isSMUS = isSageMaker('SMUS')

Expand All @@ -92,7 +92,7 @@ export class WebViewContentGenerator {
const init = () => {
createMynahUI(acquireVsCodeApi(), ${
(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
},${featureConfigsString},${welcomeLoadCount},${disclaimerAcknowledged},${disabledCommandsString},${isSMUS});
},${featureConfigsString},${welcomeLoadCount},${enableDisclaimer},${disabledCommandsString},${isSMUS});
}
</script>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isClickTelemetry, isOpenAgentTelemetry } from '../ui/telemetry/actions'
import globals from '../../../shared/extensionGlobals'
import { openUrl } from '../../../shared/utilities/vsCodeUtils'
import { DefaultAmazonQAppInitContext } from '../../apps/initContext'
import { AmazonQPromptSettings } from '../../../shared/settings'

const qChatModuleName = 'amazonqChat'

Expand Down Expand Up @@ -77,7 +78,7 @@ export function dispatchWebViewMessagesToApps(
return
}
case 'disclaimer-acknowledged': {
globals.globalState.tryUpdate('aws.amazonq.disclaimerAcknowledged', true)
void AmazonQPromptSettings.instance.update('amazonQChatDisclaimerAcknowledged', true)
return
}
case 'update-welcome-count': {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { activate as activateLogger } from './logger/activation'
export { activate as activateTelemetry } from './telemetry/activation'
export { DefaultAwsContext } from './awsContext'
export { DefaultAWSClientBuilder, ServiceOptions } from './awsClientBuilder'
export { Settings, Experiments, DevSettings } from './settings'
export { Settings, Experiments, DevSettings, AmazonQPromptSettings } from './settings'
export * from './extensionUtilities'
export * from './extensionStartup'
export { RegionProvider } from './regions/regionProvider'
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/shared/settings-amazonq.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const amazonqSettings = {
"minIdeVersion": {},
"ssoCacheError": {},
"amazonQLspManifestMessage": {},
"amazonQWorkspaceLspManifestMessage": {}
"amazonQWorkspaceLspManifestMessage": {},
"amazonQChatDisclaimerAcknowledged": {}
},
"amazonQ.showCodeWithReferences": {},
"amazonQ.allowFeatureDevelopmentToRunCodeAndTests": {},
Expand Down
11 changes: 11 additions & 0 deletions packages/webpack.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ module.exports = (env, argv) => {
new webpack.IgnorePlugin({
resourceRegExp: /ps-list/, // matches the path in the require() statement
}),
/**
* HACK: the glob module breaks Web mode if imported, BUT we still dynamically import this module for non web mode
* environments. The following allows compilation to pass by never bundling the module in the final output for web mode.
*/
new webpack.IgnorePlugin({
resourceRegExp: /glob/, // matches the path in the require() statement
}),
],
resolve: {
extensions: ['.ts', '.js'],
Expand All @@ -76,6 +83,10 @@ module.exports = (env, argv) => {
child_process: false, // Reason for error: 'TypeError: The "original" argument must be of type Function'
async_hooks: false,
net: false,

// codewhisperer chat imports jsdom which doesn't run in web mode
vm: false,
tls: false,
},
},
optimization: {
Expand Down
Loading