Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -69,7 +69,7 @@
}

// TODO: Remove this once chat has been integrated with agents
fun post(message: String) =

Check warning on line 72 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 Community for JVM

Unused symbol

Function "post" is never used
jcefBrowser
.cefBrowser
.executeJavaScript("window.postMessage(JSON.stringify($message))", jcefBrowser.cefBrowser.url, 0)
Expand Down Expand Up @@ -114,13 +114,33 @@
highlightCommand: HighlightCommand?,
activeProfile: QRegionProfile?,
): String {
val quickActionConfig = generateQuickActionConfig()
val postMessageToJavaJsCode = receiveMessageQuery.inject("JSON.stringify(message)")
val connectorAdapterPath = "http://mynah/js/connectorAdapter.js"
generateQuickActionConfig()

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt#L118-L119

Added lines #L118 - L119 were not covered by tests
// language=HTML
val jsScripts = """
<script type="text/javascript" src="$connectorAdapterPath"></script>

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt#L122

Added line #L122 was not covered by tests
<script type="text/javascript" src="$webUri" defer onload="init()"></script>

<script type="text/javascript">

const init = () => {
const hybridChatConnector = connectorAdapter.initiateAdapter(
${MeetQSettings.getInstance().reinvent2024OnboardingCount < MAX_ONBOARDING_PAGE_COUNT},
${MeetQSettings.getInstance().disclaimerAcknowledged},
$isFeatureDevAvailable,
$isCodeTransformAvailable,
$isDocAvailable,
$isCodeScanAvailable,
$isCodeTestAvailable,

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt#L130-L135

Added lines #L130 - L135 were not covered by tests
{
postMessage: message => {
$postMessageToJavaJsCode

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt#L138

Added line #L138 was not covered by tests
}
},

"${activeProfile?.profileName.orEmpty()}")
const commands = [hybridChatConnector.initialQuickActions[0], hybridChatConnector.initialQuickActions[1]]
amazonQChat.createChat(
{
postMessage: message => {
Expand All @@ -129,11 +149,11 @@
},
{
agenticMode: true,
quickActionCommands: $quickActionConfig,
quickActionCommands: commands,
disclaimerAcknowledged: ${MeetQSettings.getInstance().disclaimerAcknowledged},
pairProgrammingAcknowledged: ${!MeetQSettings.getInstance().amazonQChatPairProgramming}
},
null,
hybridChatConnector,
{}

);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
.onEach { json ->
val node = serializer.toNode(json)
when (node.command) {
// this is sent when the named agents UI is ready
"ui-is-ready" -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

lol

Copy link
Contributor Author

@manodnyab manodnyab May 6, 2025

Choose a reason for hiding this comment

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

I know!!

uiReady.complete(true)
RunOnceUtil.runOnceForApp("AmazonQ-UI-Ready") {
MeetQSettings.getInstance().reinvent2024OnboardingCount += 1
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt#L133-L136

Added lines #L133 - L136 were not covered by tests
}
CHAT_DISCLAIMER_ACKNOWLEDGED -> {
MeetQSettings.getInstance().disclaimerAcknowledged = true
}
Expand Down Expand Up @@ -156,13 +163,14 @@
}

val tabType = node.tabType
if (tabType == null) {
if (tabType == null || tabType == "cwc") {
handleFlareChatMessages(browser, node)
}
connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection ->
launch {
val message = serializer.deserialize(node, connection.messageTypeRegistry)
connection.messagesFromUiToApp.publish(message)
} else {
connections.filter { connection -> connection.app.tabTypes.contains(tabType) }.forEach { connection ->
launch {
val message = serializer.deserialize(node, connection.messageTypeRegistry)
connection.messagesFromUiToApp.publish(message)
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt#L169-L173

Added lines #L169 - L173 were not covered by tests
}
}
}
Expand All @@ -182,7 +190,7 @@
// Send inbound messages to the browser
val inboundMessages = connections.map { it.messagesFromAppToUi.flow }.merge()
inboundMessages
.onEach { browser.post(serializer.serialize(it)) }
.onEach { browser.postChat(serializer.serialize(it)) }
.launchIn(this)
}

Expand Down
80 changes: 76 additions & 4 deletions plugins/amazonq/mynah-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugins/amazonq/mynah-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lintfix": "eslint -c .eslintrc.js --fix --ext .ts ."
},
"dependencies": {
"@aws/mynah-ui-chat": "npm:@aws/mynah-ui@4.22.1",
"@aws/mynah-ui-chat": "npm:@aws/mynah-ui@4.30.3",
"@types/node": "^14.18.5",
"fs-extra": "^10.0.1",
"sanitize-html": "^2.12.1",
Expand All @@ -22,6 +22,7 @@
},
"devDependencies": {
"@aws/fully-qualified-names": "^2.1.1",
"@aws/chat-client": "^0.1.4",
"@types/sanitize-html": "^2.8.0",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
Expand Down
118 changes: 118 additions & 0 deletions plugins/amazonq/mynah-ui/src/mynah-ui/connectorAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import {ChatPrompt, MynahUI, QuickActionCommand, QuickActionCommandGroup} from '@aws/mynah-ui-chat'
import { isTabType } from './ui/storages/tabsStorage'
import { WebviewUIHandler } from './ui/main'
import { TabDataGenerator } from './ui/tabs/generator'
import { ChatClientAdapter, ChatEventHandler } from '@aws/chat-client'
import { FqnExtractor } from "./fqn/extractor";

export * from "./ui/main";

declare global {
interface Window { fqnExtractor: FqnExtractor; }
}

window.fqnExtractor = new FqnExtractor();

export const initiateAdapter = (showWelcomePage: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you provide reference to VSC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't have a reference in VSC. The webpack bundles this file and to be able to access its contents need an instance of the class

disclaimerAcknowledged: boolean,
isFeatureDevEnabled: boolean,
isCodeTransformEnabled: boolean,
isDocEnabled: boolean,
isCodeScanEnabled: boolean,
isCodeTestEnabled: boolean,
ideApiPostMessage: (message: any) => void,
profileName?: string) : HybridChatAdapter => {
return new HybridChatAdapter(showWelcomePage, disclaimerAcknowledged, isFeatureDevEnabled, isCodeTransformEnabled, isDocEnabled, isCodeScanEnabled, isCodeTestEnabled, ideApiPostMessage, profileName)
}

export class HybridChatAdapter implements ChatClientAdapter {
private uiHandler?: WebviewUIHandler

private mynahUIRef?: { mynahUI: MynahUI}

constructor(

private showWelcomePage: boolean,
private disclaimerAcknowledged: boolean,
private isFeatureDevEnabled: boolean,
private isCodeTransformEnabled: boolean,
private isDocEnabled: boolean,
private isCodeScanEnabled: boolean,
private isCodeTestEnabled: boolean,
private ideApiPostMessage: (message: any) => void,
private profileName?: string,

) {}

/**
* First we create the ui handler to get the props, then once mynah UI gets created flare will re-inject the
* mynah UI instance on the hybrid chat adapter
*/
createChatEventHandler(mynahUIRef: { mynahUI: MynahUI }): ChatEventHandler {
this.mynahUIRef = mynahUIRef

this.uiHandler = new WebviewUIHandler({
postMessage: this.ideApiPostMessage,
mynahUIRef: this.mynahUIRef,
showWelcomePage: this.showWelcomePage,
disclaimerAcknowledged: this.disclaimerAcknowledged,
isFeatureDevEnabled: this.isFeatureDevEnabled,
isCodeTransformEnabled: this.isCodeTransformEnabled,
isDocEnabled: this.isDocEnabled,
isCodeScanEnabled: this.isCodeScanEnabled,
isCodeTestEnabled: this.isCodeTestEnabled,
profileName: this.profileName,
hybridChat: true,
})

return this.uiHandler.mynahUIProps
}

isSupportedTab(tabId: string): boolean {
const tabType = this.uiHandler?.tabsStorage.getTab(tabId)?.type
if (!tabType) {
return false
}
return isTabType(tabType) && tabType !== 'cwc'
}

async handleMessageReceive(message: MessageEvent): Promise<void> {
if (this.uiHandler) {
return this.uiHandler?.connector?.handleMessageReceive(message)
}

console.error('unknown message: ', message.data)
}

isSupportedQuickAction(command: string): boolean {
return (
command === '/dev' ||
command === '/test' ||
command === '/review' ||
command === '/doc' ||
command === '/transform'
)
}

handleQuickAction(prompt: ChatPrompt, tabId: string, eventId: string | undefined): void {
return this.uiHandler?.quickActionHandler?.handleCommand(prompt, tabId, eventId)
}

get initialQuickActions(): QuickActionCommandGroup[] {
const tabDataGenerator = new TabDataGenerator({
isFeatureDevEnabled: this.isFeatureDevEnabled,
isCodeTransformEnabled: this.isCodeTransformEnabled,
isDocEnabled: this.isDocEnabled,
isCodeScanEnabled: this.isCodeScanEnabled,
isCodeTestEnabled: this.isCodeTestEnabled,
profileName: this.profileName
})
return tabDataGenerator.quickActionsGenerator.generateForTab('cwc') ?? []
}
}


2 changes: 1 addition & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/fqn/extractor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down
2 changes: 1 addition & 1 deletion plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Connector {
private readonly tabsStorage
private readonly amazonqCommonsConnector: AmazonQCommonsConnector

private isUIReady = false
isUIReady = false

constructor(props: ConnectorProps) {
this.sendMessageToExtension = props.sendMessageToExtension
Expand Down
Loading
Loading