Skip to content

Commit

Permalink
Adds event listener for notifying UI that AB feature configurations h…
Browse files Browse the repository at this point in the history
…ave been resolved
  • Loading branch information
spfink committed Jan 29, 2025
1 parent 989a470 commit 8bee84c
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "feature",
"description" : "Adds event listener for notifying UI that AB feature configurations have been resolved"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

package software.aws.toolkits.jetbrains.services.cwc

import com.intellij.openapi.application.ApplicationManager
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.launch
import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigListener
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQApp
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteraction
import software.aws.toolkits.jetbrains.services.amazonq.util.highlightCommand
import software.aws.toolkits.jetbrains.services.cwc.commands.ActionRegistrar
import software.aws.toolkits.jetbrains.services.cwc.commands.CodeScanIssueActionMessage
import software.aws.toolkits.jetbrains.services.cwc.commands.ContextMenuActionMessage
import software.aws.toolkits.jetbrains.services.cwc.controller.ChatController
import software.aws.toolkits.jetbrains.services.cwc.messages.FeatureConfigsAvailableMessage
import software.aws.toolkits.jetbrains.services.cwc.messages.IncomingCwcMessage

class App : AmazonQApp {
Expand Down Expand Up @@ -56,6 +60,21 @@ class App : AmazonQApp {
scope.launch { handleMessage(message, inboundAppMessagesHandler) }
}
}

ApplicationManager.getApplication().messageBus.connect(this).subscribe(
CodeWhispererFeatureConfigListener.TOPIC,
object : CodeWhispererFeatureConfigListener {
override fun publishFeatureConfigsAvailble() {
scope.launch {
context.messagesFromAppToUi.publish(
FeatureConfigsAvailableMessage(
highlightCommand = highlightCommand()
)
)
}
}
}
)
}

private suspend fun handleMessage(message: AmazonQMessage, inboundAppMessagesHandler: InboundAppMessagesHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import software.amazon.awssdk.services.codewhispererstreaming.model.UserIntent
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthFollowUpType
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteractionType
import software.aws.toolkits.jetbrains.services.amazonq.util.HighlightCommand
import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.FollowUpType
import java.time.Instant

Expand Down Expand Up @@ -264,6 +265,14 @@ data class ErrorMessage(
type = "errorMessage",
)

data class FeatureConfigsAvailableMessage(
val highlightCommand: HighlightCommand?,

) : UiMessage(
null,
type = "featureConfigsAvailableMessage",
)

data class QuickActionMessage(
val message: String,
@JsonProperty("triggerID") val triggerId: String,
Expand Down
14 changes: 13 additions & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/cwChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatItemAction, ChatItemType, FeedbackPayload } from '@aws/mynah-ui-chat'
import {ChatItemAction, ChatItemType, FeedbackPayload, QuickActionCommand} from '@aws/mynah-ui-chat'
import { ExtensionMessage } from '../commands'
import { CodeReference } from './amazonqCommonsConnector'
import { TabOpenType, TabsStorage } from '../storages/tabsStorage'
Expand All @@ -23,6 +23,9 @@ export interface ConnectorProps {
onError: (tabID: string, message: string, title: string) => void
onWarning: (tabID: string, message: string, title: string) => void
onOpenSettingsMessage: (tabID: string) => void
onFeatureConfigsAvailable: (
highlightCommand?: QuickActionCommand
) => void
tabsStorage: TabsStorage
}

Expand All @@ -33,6 +36,7 @@ export class Connector {
private readonly onChatAnswerReceived
private readonly onCWCContextCommandMessage
private readonly onOpenSettingsMessage
private readonly onFeatureConfigsAvailable
private readonly followUpGenerator: FollowUpGenerator

constructor(props: ConnectorProps) {
Expand All @@ -42,6 +46,7 @@ export class Connector {
this.onError = props.onError
this.onCWCContextCommandMessage = props.onCWCContextCommandMessage
this.onOpenSettingsMessage = props.onOpenSettingsMessage
this.onFeatureConfigsAvailable = props.onFeatureConfigsAvailable
this.followUpGenerator = new FollowUpGenerator()
}

Expand Down Expand Up @@ -373,5 +378,12 @@ export class Connector {
await this.processOpenSettingsMessage(messageData)
return
}

if (messageData.type === 'featureConfigsAvailableMessage') {
this.onFeatureConfigsAvailable(
messageData.highlightCommand,
)
return
}
}
}
5 changes: 4 additions & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Engagement,
NotificationType,
ProgressField,
ChatPrompt,
ChatPrompt, QuickActionCommand,
} from '@aws/mynah-ui-chat'
import { Connector as CWChatConnector } from './apps/cwChatConnector'
import { Connector as FeatureDevChatConnector } from './apps/featureDevChatConnector'
Expand Down Expand Up @@ -84,6 +84,9 @@ export interface ConnectorProps {
codeTestEnabled: boolean,
authenticatingTabIDs: string[]
) => void
onFeatureConfigsAvailable: (
highlightCommand?: QuickActionCommand
) => void
onNewTab: (tabType: TabType) => void
onStartNewTransform: (tabID: string) => void
onCodeTransformCommandMessageReceived: (message: ChatItem, command?: string) => void
Expand Down
11 changes: 11 additions & 0 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,17 @@ export const createMynahUI = (
tabsStorage.updateTabStatus(tabID, 'free')
}
}
},
onFeatureConfigsAvailable: (
highlightCommand?: QuickActionCommand
): void => {
tabDataGenerator.highlightCommand = highlightCommand

for (const tab of tabsStorage.getTabs()) {
mynahUI.updateStore(tab.id, {
contextCommands: tabDataGenerator.getTabData(tab.type, true).contextCommands
})
}
}
})

Expand Down
2 changes: 1 addition & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/ui/tabs/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TabDataGeneratorProps {
export class TabDataGenerator {
private followUpsGenerator: FollowUpGenerator
public quickActionsGenerator: QuickActionGenerator
private highlightCommand?: QuickActionCommand
public highlightCommand?: QuickActionCommand

private tabTitle: Map<TabType, string> = new Map([
['unknown', 'Chat'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq

import com.intellij.openapi.application.ApplicationManager
import com.intellij.util.messages.Topic

interface CodeWhispererFeatureConfigListener {
fun publishFeatureConfigsAvailble() {}

companion object {
@Topic.AppLevel
val TOPIC = Topic.create("feature configs listener", CodeWhispererFeatureConfigListener::class.java)

fun notifyUiFeatureConfigsAvailable() {
ApplicationManager.getApplication().messageBus.syncPublisher(TOPIC).publishFeatureConfigsAvailble()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CodeWhispererFeatureConfigService {
featureConfigs.remove(CUSTOMIZATION_ARN_OVERRIDE_NAME)
}
}
CodeWhispererFeatureConfigListener.notifyUiFeatureConfigsAvailable()
} catch (e: Exception) {
LOG.debug(e) { "Error when fetching feature configs" }
}
Expand Down

0 comments on commit 8bee84c

Please sign in to comment.