From 4235561f6a9e724f204ff5c6f66b8e98060a4e42 Mon Sep 17 00:00:00 2001 From: Lei Gao <97199248+leigaol@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:42:31 -0800 Subject: [PATCH] feat(amazonq): Enable implicit `@workspace` context for Amzn users #5856 ## Problem The chat workspace context requires user to manually input `@workspace` in the chat window, but when user do not have such prompt, workspace context can still be useful, we want to always send the relevant document and let service decide when to utilize it. ## Solution Enable implicit `@workspace` context for Amzn users. For these users, if they do not have `@workspace` in the chat prompt, the relevantTextDocument is still added to the chat API. This will be AB tested Also remove the outdated data collection experiment. --- ...-93485fee-05c0-4dc9-abde-9072590cbd45.json | 4 ++++ .../controllers/chat/controller.ts | 22 ++++++++++++------- packages/core/src/shared/featureConfig.ts | 14 +++--------- 3 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 packages/amazonq/.changes/next-release/Feature-93485fee-05c0-4dc9-abde-9072590cbd45.json diff --git a/packages/amazonq/.changes/next-release/Feature-93485fee-05c0-4dc9-abde-9072590cbd45.json b/packages/amazonq/.changes/next-release/Feature-93485fee-05c0-4dc9-abde-9072590cbd45.json new file mode 100644 index 00000000000..914121a15d4 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Feature-93485fee-05c0-4dc9-abde-9072590cbd45.json @@ -0,0 +1,4 @@ +{ + "type": "Feature", + "description": "Enable default `@workspace` context of Amazon Q chat for certain users" +} diff --git a/packages/core/src/codewhispererChat/controllers/chat/controller.ts b/packages/core/src/codewhispererChat/controllers/chat/controller.ts index b605ce8698b..cc4a61b680f 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/controller.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/controller.ts @@ -47,11 +47,11 @@ import { randomUUID } from '../../../shared/crypto' import { LspController } from '../../../amazonq/lsp/lspController' import { CodeWhispererSettings } from '../../../codewhisperer/util/codewhispererSettings' import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil' -import { FeatureConfigProvider } from '../../../shared/featureConfig' import { getHttpStatusCode, AwsClientResponseError } from '../../../shared/errors' import { uiEventRecorder } from '../../../amazonq/util/eventRecorder' -import { globals } from '../../../shared' +import { globals, waitUntil } from '../../../shared' import { telemetry } from '../../../shared/telemetry' +import { Auth } from '../../../auth' import { isSsoConnection } from '../../../auth/connection' export interface ChatControllerMessagePublishers { @@ -633,17 +633,23 @@ export class ChatController { return } } - // if user does not have @workspace in the prompt, but user is in the data collection group - // If the user is in the data collection group but turned off local index to opt-out, do not collect data. - // TODO: Remove this entire block of code in one month as requested + // if user does not have @workspace in the prompt, but user is Amazon internal + // add project context by default else if ( - FeatureConfigProvider.instance.isAmznDataCollectionGroup() && + Auth.instance.isInternalAmazonUser() && !LspController.instance.isIndexingInProgress() && CodeWhispererSettings.instance.isLocalIndexEnabled() ) { - getLogger().info(`amazonq: User is in data collection group`) const start = performance.now() - triggerPayload.relevantTextDocuments = await LspController.instance.query(triggerPayload.message) + triggerPayload.relevantTextDocuments = await waitUntil( + async function () { + if (triggerPayload.message) { + return await LspController.instance.query(triggerPayload.message) + } + return [] + }, + { timeout: 500, interval: 200, truthy: false } + ) triggerPayload.projectContextQueryLatencyMs = performance.now() - start } } diff --git a/packages/core/src/shared/featureConfig.ts b/packages/core/src/shared/featureConfig.ts index a94fc25a7b8..d6962ada86e 100644 --- a/packages/core/src/shared/featureConfig.ts +++ b/packages/core/src/shared/featureConfig.ts @@ -18,6 +18,7 @@ import globals from './extensionGlobals' import { getClientId, getOperatingSystem } from './telemetry/util' import { extensionVersion } from './vscode/env' import { telemetry } from './telemetry' +import { Auth } from '../auth' export class FeatureContext { constructor( @@ -51,8 +52,6 @@ export class FeatureConfigProvider { static #instance: FeatureConfigProvider - private _isDataCollectionGroup = false - constructor() { this.fetchFeatureConfigs().catch((e) => { getLogger().error('fetchFeatureConfigs failed: %s', (e as Error).message) @@ -65,10 +64,6 @@ export class FeatureConfigProvider { return (this.#instance ??= new this()) } - isAmznDataCollectionGroup(): boolean { - return this._isDataCollectionGroup - } - isNewProjectContextGroup(): boolean { return this.featureConfigs.get(Features.projectContextFeature)?.variation === 'TREATMENT' } @@ -145,11 +140,8 @@ export class FeatureConfigProvider { } } } - - const dataCollectionValue = this.featureConfigs.get(Features.dataCollectionFeature)?.value.stringValue - if (dataCollectionValue === 'data-collection') { - this._isDataCollectionGroup = true - // Enable local workspace index by default, for Amzn users. + if (Auth.instance.isInternalAmazonUser()) { + // Enable local workspace index by default only once, for Amzn users. const isSet = globals.globalState.get('aws.amazonq.workspaceIndexToggleOn') || false if (!isSet) { await CodeWhispererSettings.instance.enableLocalIndex()