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

config(chat): optin @workspace context if a user is in treatment group #5201

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
Expand Up @@ -17,14 +17,17 @@ import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
import software.aws.toolkits.jetbrains.core.credentials.sono.isInternalUser
import software.aws.toolkits.jetbrains.core.gettingstarted.emitUserState
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService
import software.aws.toolkits.jetbrains.services.amazonq.project.ProjectContextController
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindow
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory
import software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererShowSettingsAction
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
import software.aws.toolkits.jetbrains.services.cwc.inline.InlineChatController
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
import software.aws.toolkits.jetbrains.utils.notifyInfo
import software.aws.toolkits.resources.AmazonQBundle.message
import java.lang.management.ManagementFactory
import java.time.Duration
import java.util.concurrent.atomic.AtomicBoolean
Expand All @@ -35,9 +38,22 @@ class AmazonQStartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
if (ApplicationManager.getApplication().isUnitTestMode) return

// Turn on project context if a user is in treatment group and prompt UI to notify them
ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance())?.let {
if (it is AwsBearerTokenConnection && isInternalUser(it.startUrl)) {
if (it is AwsBearerTokenConnection &&
CodeWhispererFeatureConfigService.getInstance().getWorkspaceContext() &&
!CodeWhispererSettings.getInstance().isProjectContextEnabled()
) {
CodeWhispererSettings.getInstance().toggleProjectContextEnabled(value = true, passive = true)

// TODO: finalize strings
runInEdt {
notifyInfo(
title = message("amazonq.brand.title"),
content = message("amazonq.chat.workspacecontext.enable.message"),
notificationActions = listOf(CodeWhispererShowSettingsAction())
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
action.q.hello.description=Hello description
amazonq.brand.title=Amazon Q
amazonq.chat.workspacecontext.enable.message=Workspace index is now enabled. You can disable it in the Amazon Q settings.
amazonqInlineChat.hint.edit = Edit
amazonqInlineChat.popup.accept=Accept \u23CE
amazonqInlineChat.popup.cancel=Cancel \u238B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class CodeWhispererFeatureConfigService {

fun getInlineCompletion(): Boolean = getFeatureValueForKey(INLINE_COMPLETION).stringValue() == "TREATMENT"

fun getWorkspaceContext(): Boolean = getFeatureValueForKey(WORKSPACE_CONTEXT_FEATURE).stringValue() == "TREATMENT"

// Get the feature value for the given key.
// In case of a misconfiguration, it will return a default feature value of Boolean false.
private fun getFeatureValueForKey(name: String): FeatureValue =
Expand All @@ -133,6 +135,7 @@ class CodeWhispererFeatureConfigService {
private const val INLINE_COMPLETION = "ProjectContextV2"
const val CUSTOMIZATION_ARN_OVERRIDE_NAME = "customizationArnOverride"
private const val NEW_AUTO_TRIGGER_UX = "newAutoTriggerUX"
private const val WORKSPACE_CONTEXT_FEATURE = "WorkspaceContext"
private val LOG = getLogger<CodeWhispererFeatureConfigService>()

// TODO: add real feature later
Expand All @@ -158,6 +161,11 @@ class CodeWhispererFeatureConfigService {
INLINE_COMPLETION,
"CONTROL",
FeatureValue.builder().stringValue("CONTROL").build()
),
WORKSPACE_CONTEXT_FEATURE to FeatureContext(
WORKSPACE_CONTEXT_FEATURE,
"CONTROL",
FeatureValue.builder().stringValue("CONTROL").build()
)
)
}
Expand Down
Loading