Skip to content

Commit

Permalink
feat(amazonq): Enable implicit @workspace context for Amzn users #5856
Browse files Browse the repository at this point in the history


## 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.
  • Loading branch information
leigaol authored Nov 13, 2024
1 parent 886ab29 commit 4235561
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Enable default `@workspace` context of Amazon Q chat for certain users"
}
22 changes: 14 additions & 8 deletions packages/core/src/codewhispererChat/controllers/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
14 changes: 3 additions & 11 deletions packages/core/src/shared/featureConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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'
}
Expand Down Expand Up @@ -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<boolean>('aws.amazonq.workspaceIndexToggleOn') || false
if (!isSet) {
await CodeWhispererSettings.instance.enableLocalIndex()
Expand Down

0 comments on commit 4235561

Please sign in to comment.