-
Notifications
You must be signed in to change notification settings - Fork 273
feat(amazonq): enable @sage, pass feature config to mynahUI #5683
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| @file:Suppress("BannedImports") | ||
| package software.aws.toolkits.jetbrains.services.amazonq | ||
|
|
||
| import com.google.gson.Gson | ||
| import com.intellij.openapi.components.Service | ||
| import com.intellij.openapi.components.service | ||
| import com.intellij.openapi.project.Project | ||
|
|
@@ -17,7 +19,6 @@ import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection | |
| import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileManager | ||
| import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererCustomization | ||
| import software.aws.toolkits.jetbrains.utils.isQExpired | ||
|
|
||
| @Service | ||
| class CodeWhispererFeatureConfigService { | ||
| private val featureConfigs = mutableMapOf<String, FeatureContext>() | ||
|
|
@@ -82,6 +83,17 @@ class CodeWhispererFeatureConfigService { | |
|
|
||
| fun getChatWSContext(): Boolean = getFeatureValueForKey(CHAT_WS_CONTEXT).stringValue() == "TREATMENT" | ||
|
|
||
| // convert into mynahUI parsable string | ||
| // format: '[["key1", {"name":"Feature1","variation":"A","value":true}]]' | ||
| fun getFeatureConfigJsonString(): String { | ||
| val jsonString = featureConfigs.entries.map { (key, value) -> | ||
| "[\"$key\",${Gson().toJson(value)}]" | ||
| } | ||
| return """ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we return jsonstring directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it will fail. I spent 6 hours making it correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is trying to deserialize as a typescript MAP on MynahUI end |
||
| '$jsonString' | ||
| """.trimIndent() | ||
| } | ||
|
|
||
| // 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 = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use objectMapper here then this function would be blocked on IO forever and webview will never load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and Gson formatted string happens to match what MynahUI requires.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data in VSC is a JSON.stringfied(JSON.stringfield(Object)). See https://github.com/aws/aws-toolkit-vscode/blob/bb11bd9a4b498b2129085f43217b6b712dbf8c44/packages/amazonq/src/lsp/chat/webviewProvider.ts#L85.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I implement it in this way
then it would stuck at
public native void park(boolean isAbsolute, long time);of Unsafe.java. It may have sometime to do with featureConfigs list being not thread safe but I don't find a easy fix.It can also hang at handleMessage function of StreamMessageProducer.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why the key value pairs are not modelled as json in mynah-ui