Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

zuoyaofu
Copy link
Contributor

@zuoyaofu zuoyaofu commented Jun 21, 2025

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@zuoyaofu zuoyaofu changed the title Image feat(q): add image context support Jun 21, 2025
@zuoyaofu zuoyaofu changed the title feat(q): add image context support feat(amazonq): add image context support Jun 21, 2025
@@ -485,6 +487,17 @@ class BrowserConnector(
)
}
}
OPEN_FILE_DIALOG -> {
handleChat(AmazonQChatServer.showOpenFileDialog, node)
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 walk me through the message flow? does it actually need to transit through flare before requesting the file picker?

Copy link
Contributor Author

@zuoyaofu zuoyaofu Jun 25, 2025

Choose a reason for hiding this comment

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

Flow:

  1. chat-client will send openFileDialog request to flare
  2. Flare will send to extension the params, including canSelectMany (multiple files), filters (what file extension types are allowed)
  3. Extension will then handle file selection logic and send back the list of URIs.
  4. 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)

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this doing?

Copy link
Contributor

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("'", "\\'")
Copy link
Contributor

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

Copy link
Contributor

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

// Set DropTarget on the browser component and its children
browserInstance.component()?.let { component ->
component.dropTarget = dropTarget
// Also try setting on parent if needed
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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"

val maxDimension = 8000

for (file in fileList) {
val fileObj = file as? java.io.File ?: continue
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor

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

Copy link
Contributor

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.

FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()
}

val chosenFiles = FileChooser.chooseFiles(descriptor, project, null)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

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

More arguments provided (1) than placeholders specified (0)
companion object {
private val LOG = getLogger<AmazonQPanel>()

fun getInstance(project: Project) = project.service<AmazonQPanel>()

Check failure

Code scanning / QDJVMC

Incorrect service retrieving Error

The 'software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQPanel' class is not registered as a service
@zuoyaofu zuoyaofu marked this pull request as ready for review June 26, 2025 22:38
@zuoyaofu zuoyaofu requested review from a team as code owners June 26, 2025 22:38
val descriptor = when {
params.canSelectFolders && params.canSelectFiles -> {
if (params.canSelectMany) {
FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor()
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this multiselect

Comment on lines +7 to +11
val canSelectFiles: Boolean = false,
val canSelectFolders: Boolean = false,
val canSelectMany: Boolean = false,
val filters: Map<String, List<String>> = emptyMap(),
val title: String? = null,
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val imageContextEnabled: Boolean = true,
val imageContextEnabled: Boolean,

@@ -3,6 +3,7 @@

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

import com.google.gson.Gson
Copy link
Contributor

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>()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val validImages = mutableListOf<java.io.File>()
val validImages = mutableListOf<File>()

companion object {
private val LOG = getLogger<AmazonQPanel>()

fun getInstance(project: Project) = project.service<AmazonQPanel>()
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants