-
Notifications
You must be signed in to change notification settings - Fork 262
feat(amazonq): add image context support #5846
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
base: main
Are you sure you want to change the base?
Conversation
...tware/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/showOpenFileDialogParams.kt
Outdated
Show resolved
Hide resolved
@@ -485,6 +487,17 @@ class BrowserConnector( | |||
) | |||
} | |||
} | |||
OPEN_FILE_DIALOG -> { | |||
handleChat(AmazonQChatServer.showOpenFileDialog, node) |
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.
can you walk me through the message flow? does it actually need to transit through flare before requesting the file picker?
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.
Flow:
- chat-client will send
openFileDialog
request to flare - Flare will send to extension the params, including
canSelectMany
(multiple files),filters
(what file extension types are allowed) - Extension will then handle file selection logic and send back the list of URIs.
- Flare will then send to chat-client the file uri to display in chat.
- does it actually need to transit through flare before requesting the file picker?
- In @yzhangok's design, yes. Flare is also telling client what type of files are supported in file picker as well(step 2)
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Fixed
Show fixed
Hide fixed
@@ -122,7 +125,7 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project) | |||
<script type="text/javascript" charset="UTF-8" src="$webUri" defer onload="init()"></script> | |||
|
|||
<script type="text/javascript"> | |||
|
|||
let qChat = undefined |
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.
What is this doing?
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.
To use qChat in window.handleNativeDrop
and window.handleNativeNotify
|
||
|
||
|
||
val json = Gson().toJson(validImages).replace("\\", "\\\\").replace("'", "\\'") |
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 it's json why do we need to escape 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.
Let me find a more elegant way to handle this
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Outdated
Show resolved
Hide resolved
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Outdated
Show resolved
Hide resolved
// Set DropTarget on the browser component and its children | ||
browserInstance.component()?.let { component -> | ||
component.dropTarget = dropTarget | ||
// Also try setting on parent if needed |
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.
?
} | ||
} | ||
|
||
// Set DropTarget on the browser component and its children |
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.
how are the children involved
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 want the whole chat window to be "drag & drop zone"
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Show resolved
Hide resolved
val maxDimension = 8000 | ||
|
||
for (file in fileList) { | ||
val fileObj = file as? java.io.File ?: continue |
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.
?
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.
JCEF does not propagate OS-level dragenter, dragOver and drop into DOM. As an alternative, enabling the native drag in JCEF, and let the native handling the drop event, and update the UI through JS bridge.
The same logic of filtering the images are implemented on both language server and JetBrain
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.
no why do we need to do an identity check here
the JDK docs state
To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Outdated
Show resolved
Hide resolved
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor() | ||
} | ||
|
||
val chosenFiles = FileChooser.chooseFiles(descriptor, project, null) |
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.
why aren't images from this flow subject to constraints?
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.
Yes, they are now with the new commit.
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.
what about the file size and dimensional limits?
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Fixed
Show fixed
Hide fixed
...ns-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQPanel.kt
Fixed
Show fixed
Hide fixed
dtde.dropComplete(false) | ||
} | ||
} catch (e: Exception) { | ||
LOG.error("Failed to handle file drop operation", e.message) |
Check warning
Code scanning / QDJVMC
Number of placeholders does not match number of arguments in logging call Warning
companion object { | ||
private val LOG = getLogger<AmazonQPanel>() | ||
|
||
fun getInstance(project: Project) = project.service<AmazonQPanel>() |
Check failure
Code scanning / QDJVMC
Incorrect service retrieving Error
val descriptor = when { | ||
params.canSelectFolders && params.canSelectFiles -> { | ||
if (params.canSelectMany) { | ||
FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor() |
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.
how is this multiselect
val canSelectFiles: Boolean = false, | ||
val canSelectFolders: Boolean = false, | ||
val canSelectMany: Boolean = false, | ||
val filters: Map<String, List<String>> = emptyMap(), | ||
val title: String? = null, |
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.
dont need default values
@@ -25,6 +25,7 @@ data class DeveloperProfiles( | |||
val developerProfiles: Boolean, | |||
val mcp: Boolean, | |||
val pinnedContextEnabled: Boolean, | |||
val imageContextEnabled: Boolean = true, |
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.
val imageContextEnabled: Boolean = true, | |
val imageContextEnabled: Boolean, |
@@ -3,6 +3,7 @@ | |||
|
|||
package software.aws.toolkits.jetbrains.services.amazonq.toolwindow | |||
|
|||
import com.google.gson.Gson |
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 only use Gson in the context of lsp4j
val fileList = transferable.getTransferData(DataFlavor.javaFileListFlavor) as List<*> | ||
|
||
val errorMessages = mutableListOf<String>() | ||
val validImages = mutableListOf<java.io.File>() |
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.
val validImages = mutableListOf<java.io.File>() | |
val validImages = mutableListOf<File>() |
companion object { | ||
private val LOG = getLogger<AmazonQPanel>() | ||
|
||
fun getInstance(project: Project) = project.service<AmazonQPanel>() |
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.
delete
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor() | ||
} | ||
|
||
val chosenFiles = FileChooser.chooseFiles(descriptor, project, null) |
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.
what about the file size and dimensional limits?
val maxDimension = 8000 | ||
|
||
for (file in fileList) { | ||
val fileObj = file as? java.io.File ?: continue |
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.
no why do we need to do an identity check here
the JDK docs state
To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.
Types of changes
Description
Checklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.