-
Notifications
You must be signed in to change notification settings - Fork 251
Add support for Amazon Q chat on remote 242+ #4825
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 21 commits
47706df
7f82602
1c06ff9
a2e4042
9f37025
4f4e3d2
9c49a0a
f46f20d
205251b
6257981
5ac379e
f94e290
f9fa72e
c1b9d17
baa8e8c
b7a8e2c
f5bb9bb
5f1a27a
fa2353e
e164b90
a878739
3a3671b
cc47655
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 |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
import com.intellij.ui.dsl.builder.Align | ||
import com.intellij.ui.dsl.builder.panel | ||
import com.intellij.ui.jcef.JBCefJSQuery | ||
import org.cef.CefApp | ||
import software.aws.toolkits.core.utils.error | ||
import software.aws.toolkits.core.utils.getLogger | ||
import software.aws.toolkits.core.utils.warn | ||
|
@@ -30,8 +29,8 @@ | |
import software.aws.toolkits.jetbrains.core.region.AwsRegionProvider | ||
import software.aws.toolkits.jetbrains.core.webview.BrowserMessage | ||
import software.aws.toolkits.jetbrains.core.webview.BrowserState | ||
import software.aws.toolkits.jetbrains.core.webview.LocalAssetJBCefRequestHandler | ||
import software.aws.toolkits.jetbrains.core.webview.LoginBrowser | ||
import software.aws.toolkits.jetbrains.core.webview.WebviewResourceHandlerFactory | ||
import software.aws.toolkits.jetbrains.isDeveloperMode | ||
import software.aws.toolkits.jetbrains.services.amazonq.util.createBrowser | ||
import software.aws.toolkits.jetbrains.utils.isQConnected | ||
|
@@ -108,25 +107,14 @@ | |
class QWebviewBrowser(val project: Project, private val parentDisposable: Disposable) : | ||
LoginBrowser( | ||
project, | ||
QWebviewBrowser.DOMAIN, | ||
QWebviewBrowser.WEB_SCRIPT_URI | ||
), | ||
Disposable { | ||
// TODO: confirm if we need such configuration or the default is fine | ||
override val jcefBrowser = createBrowser(parentDisposable) | ||
private val query = JBCefJSQuery.create(jcefBrowser) | ||
private val assetHandler = LocalAssetJBCefRequestHandler(jcefBrowser) | ||
Check warning on line 115 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QLoginWebview.kt
|
||
|
||
init { | ||
CefApp.getInstance() | ||
.registerSchemeHandlerFactory( | ||
"http", | ||
domain, | ||
WebviewResourceHandlerFactory( | ||
domain = "http://$domain/", | ||
assetUri = "/webview/assets/" | ||
), | ||
) | ||
|
||
loadWebView(query) | ||
|
||
query.addHandler(jcefHandler) | ||
|
@@ -273,12 +261,15 @@ | |
} | ||
|
||
override fun loadWebView(query: JBCefJSQuery) { | ||
jcefBrowser.loadHTML(getWebviewHTML(webScriptUri, query)) | ||
val webScriptUri = assetHandler.createResource( | ||
"js/getStart.js", | ||
QWebviewBrowser::class.java.getResourceAsStream("/webview/assets/js/getStart.js") | ||
Check warning on line 266 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QLoginWebview.kt
|
||
) | ||
|
||
jcefBrowser.loadURL(assetHandler.createResource("content.html", getWebviewHTML(webScriptUri, query))) | ||
Check warning on line 269 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QLoginWebview.kt
|
||
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. nit: can we assign the file names to consts |
||
} | ||
|
||
companion object { | ||
private val LOG = getLogger<QWebviewBrowser>() | ||
private const val WEB_SCRIPT_URI = "http://webview/js/getStart.js" | ||
private const val DOMAIN = "webview" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,20 @@ | |
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AMAZON_Q_WINDOW_ID | ||
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindow | ||
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.runScanKey | ||
import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend | ||
import software.aws.toolkits.resources.message | ||
import software.aws.toolkits.telemetry.UiTelemetry | ||
|
||
class QOpenPanelAction : AnAction(message("action.q.openchat.text"), null, AwsIcons.Logos.AWS_Q) { | ||
Check warning on line 17 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QOpenPanelAction.kt
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
if (isRunningOnRemoteBackend()) return | ||
val project = e.getRequiredData(CommonDataKeys.PROJECT) | ||
UiTelemetry.click(project, "q_openChat") | ||
ToolWindowManager.getInstance(project).getToolWindow(AMAZON_Q_WINDOW_ID)?.activate(null, true) | ||
if (e.getData(runScanKey) == true) { | ||
AmazonQToolWindow.openScanTab(project) | ||
} | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
e.presentation.isEnabled = e.getData(CommonDataKeys.PROJECT) != null | ||
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. What is the situation when this option is shown and project is null? 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. the action is not available if the project is null |
||
} | ||
Check warning on line 29 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QOpenPanelAction.kt
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.util.Disposer | ||
import com.intellij.ui.jcef.JBCefJSQuery | ||
import org.cef.CefApp | ||
import software.aws.toolkits.jetbrains.core.webview.LocalAssetJBCefRequestHandler | ||
import software.aws.toolkits.jetbrains.services.amazonq.util.HighlightCommand | ||
import software.aws.toolkits.jetbrains.services.amazonq.util.createBrowser | ||
import software.aws.toolkits.jetbrains.settings.MeetQSettings | ||
import java.nio.file.Paths | ||
|
||
/* | ||
Displays the web view for the Amazon Q tool window | ||
|
@@ -21,6 +22,17 @@ | |
|
||
val receiveMessageQuery = JBCefJSQuery.create(jcefBrowser) | ||
|
||
private val assetRequestHandler = LocalAssetJBCefRequestHandler(jcefBrowser) | ||
Check warning on line 25 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt
|
||
|
||
init { | ||
assetRequestHandler.addWildcardHandler("mynah") { path -> | ||
val asset = path.replaceFirst("mynah/", "/mynah-ui/assets/") | ||
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. Should we test this? 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. follow up later |
||
Paths.get(asset).normalize().toString().replace("\\", "/").let { | ||
this::class.java.getResourceAsStream(it) | ||
} | ||
Check warning on line 32 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt
|
||
} | ||
} | ||
Check warning on line 34 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt
|
||
|
||
fun init( | ||
isCodeTransformAvailable: Boolean, | ||
isFeatureDevAvailable: Boolean, | ||
|
@@ -29,14 +41,6 @@ | |
isCodeTestAvailable: Boolean, | ||
highlightCommand: HighlightCommand?, | ||
) { | ||
// register the scheme handler to route http://mynah/ URIs to the resources/assets directory on classpath | ||
CefApp.getInstance() | ||
.registerSchemeHandlerFactory( | ||
"http", | ||
"mynah", | ||
AssetResourceHandler.AssetResourceHandlerFactory(), | ||
) | ||
|
||
loadWebView(isCodeTransformAvailable, isFeatureDevAvailable, isDocAvailable, isCodeScanAvailable, isCodeTestAvailable, highlightCommand) | ||
} | ||
|
||
|
@@ -63,9 +67,13 @@ | |
// setup empty state. The message request handlers use this for storing state | ||
// that's persistent between page loads. | ||
jcefBrowser.setProperty("state", "") | ||
|
||
// load the web app | ||
jcefBrowser.loadHTML( | ||
getWebviewHTML(isCodeTransformAvailable, isFeatureDevAvailable, isDocAvailable, isCodeScanAvailable, isCodeTestAvailable, highlightCommand) | ||
jcefBrowser.loadURL( | ||
assetRequestHandler.createResource( | ||
"webview/chat.html", | ||
getWebviewHTML(isCodeTransformAvailable, isFeatureDevAvailable, isDocAvailable, isCodeScanAvailable, isCodeTestAvailable, highlightCommand) | ||
Check warning on line 75 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt
|
||
) | ||
) | ||
} | ||
|
||
|
@@ -84,7 +92,7 @@ | |
val postMessageToJavaJsCode = receiveMessageQuery.inject("JSON.stringify(message)") | ||
|
||
val jsScripts = """ | ||
<script type="text/javascript" src="$WEB_SCRIPT_URI" defer onload="init()"></script> | ||
<script type="text/javascript" src="http://toolkitasset/mynah/js/mynah-ui.js" defer onload="init()"></script> | ||
<script type="text/javascript"> | ||
const init = () => { | ||
mynahUI.createMynahUI( | ||
|
@@ -120,7 +128,6 @@ | |
} | ||
|
||
companion object { | ||
private const val WEB_SCRIPT_URI = "http://mynah/js/mynah-ui.js" | ||
private const val MAX_ONBOARDING_PAGE_COUNT = 3 | ||
private val OBJECT_MAPPER = jacksonObjectMapper() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ | |
|
||
ApplicationManager.getApplication().invokeAndWait { | ||
selectionRange = ApplicationManager.getApplication().runReadAction<Range?> { | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditorWithRemotes.firstOrNull() | ||
Check warning on line 133 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt
|
||
Check warningCode scanning / QDJVMC Unstable API Usage Warning
'getSelectedTextEditorWithRemotes()' is marked unstable with @ApiStatus.Experimental
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. does this api also work in local ? |
||
editor?.let { | ||
val selectionModel = it.selectionModel | ||
val startOffset = selectionModel.selectionStart | ||
|
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.
Should we revert this?
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.
We can probably revert this for now--this is for differentiating the build, and we may need to re-add it (or something equivalent) whenever we ship a new test build.