Skip to content

Commit c4110ad

Browse files
authored
feat(amazonq): support select images as context (#7533)
## Problem WebView emit event to open system file dialog to use the VSC api to open file dialog, and the event need to be handled by extension ## Solution 1. Register the request between WebView and language server by adding `case OPEN_FILE_DIALOG` 2. Add handling for event when language server request to open system file dialog, which is defined in `languageClient.onRequest(ShowOpenDialogRequestType.method, async (params: ShowOpenDialogParams)` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d2e5518 commit c4110ad

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

package-lock.json

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Added image support to Amazon Q chat, users can now upload images from their local file system"
4+
}

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ChatPromptOptionAcknowledgedMessage,
1717
STOP_CHAT_RESPONSE,
1818
StopChatResponseMessage,
19+
OPEN_FILE_DIALOG,
1920
} from '@aws/chat-client-ui-types'
2021
import {
2122
ChatResult,
@@ -60,6 +61,10 @@ import {
6061
ruleClickRequestType,
6162
pinnedContextNotificationType,
6263
activeEditorChangedNotificationType,
64+
ShowOpenDialogRequestType,
65+
ShowOpenDialogParams,
66+
openFileDialogRequestType,
67+
OpenFileDialogResult,
6368
} from '@aws/language-server-runtimes/protocol'
6469
import { v4 as uuidv4 } from 'uuid'
6570
import * as vscode from 'vscode'
@@ -316,6 +321,19 @@ export function registerMessageListeners(
316321
}
317322
break
318323
}
324+
case OPEN_FILE_DIALOG: {
325+
// openFileDialog is the event emitted from webView to open
326+
// file system
327+
const result = await languageClient.sendRequest<OpenFileDialogResult>(
328+
openFileDialogRequestType.method,
329+
message.params
330+
)
331+
void provider.webview?.postMessage({
332+
command: openFileDialogRequestType.method,
333+
params: result,
334+
})
335+
break
336+
}
319337
case quickActionRequestType.method: {
320338
const quickActionPartialResultToken = uuidv4()
321339
const quickActionDisposable = languageClient.onProgress(
@@ -461,6 +479,24 @@ export function registerMessageListeners(
461479
}
462480
})
463481

482+
languageClient.onRequest(ShowOpenDialogRequestType.method, async (params: ShowOpenDialogParams) => {
483+
try {
484+
const uris = await vscode.window.showOpenDialog({
485+
canSelectFiles: params.canSelectFiles ?? true,
486+
canSelectFolders: params.canSelectFolders ?? false,
487+
canSelectMany: params.canSelectMany ?? false,
488+
filters: params.filters,
489+
defaultUri: params.defaultUri ? vscode.Uri.parse(params.defaultUri, false) : undefined,
490+
title: params.title,
491+
})
492+
const urisString = uris?.map((uri) => uri.fsPath)
493+
return { uris: urisString || [] }
494+
} catch (err) {
495+
languageClient.error(`[VSCode Client] Failed to open file dialog: ${(err as Error).message}`)
496+
return { uris: [] }
497+
}
498+
})
499+
464500
languageClient.onRequest<ShowDocumentParams, ShowDocumentResult>(
465501
ShowDocumentRequest.method,
466502
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {

packages/amazonq/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export async function startLanguageServer(
163163
q: {
164164
developerProfiles: true,
165165
pinnedContextEnabled: true,
166+
imageContextEnabled: true,
166167
mcp: true,
167168
reroute: true,
168169
modelSelection: true,

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@
470470
"devDependencies": {
471471
"@aws-sdk/types": "^3.13.1",
472472
"@aws/chat-client": "^0.1.4",
473-
"@aws/chat-client-ui-types": "^0.1.24",
474-
"@aws/language-server-runtimes": "^0.2.97",
475-
"@aws/language-server-runtimes-types": "^0.1.39",
473+
"@aws/chat-client-ui-types": "^0.1.47",
474+
"@aws/language-server-runtimes": "^0.2.99",
475+
"@aws/language-server-runtimes-types": "^0.1.41",
476476
"@cspotcode/source-map-support": "^0.8.1",
477477
"@sinonjs/fake-timers": "^10.0.2",
478478
"@types/adm-zip": "^0.4.34",

0 commit comments

Comments
 (0)