Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -9,6 +9,8 @@
import com.intellij.openapi.util.Disposer
import com.intellij.ui.jcef.JBCefJSQuery
import org.cef.CefApp
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService
import software.aws.toolkits.jetbrains.services.amazonq.FeatureContext

Check warning on line 13 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AwsServerCapabilitiesProvider
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
Expand Down Expand Up @@ -154,7 +156,7 @@
pairProgrammingAcknowledged: ${!MeetQSettings.getInstance().amazonQChatPairProgramming}
},
hybridChatConnector,
{}
${CodeWhispererFeatureConfigService.getInstance().getFeatureConfigJsonString()}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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

import com.google.gson.Gson
@Service
class CodeWhispererFeatureConfigService {
private val featureConfigs = mutableMapOf<String, FeatureContext>()
Expand Down Expand Up @@ -82,6 +82,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)}]"
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@leigaol leigaol May 7, 2025

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

val jsonString = featureConfigs.entries.map { (key, value) ->
            "[\"$key\",${jacksonObjectMapper().writeValueAsString(value)}]"
        }

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

Copy link
Contributor

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

}
return """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we return jsonstring directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it will fail. I spent 6 hours making it correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 =
Expand Down
Loading