From d7bf2fa1b2f3025a464fc293abe52ccbf884edd7 Mon Sep 17 00:00:00 2001 From: merfanian Date: Tue, 9 Jun 2026 10:57:00 -0500 Subject: [PATCH] Preserve image source provenance across chat reference API boundary Image attachments lost their source provenance (clipboard, screenshot, file, url) when converted to the ChatPromptReference API type, because ChatReferenceBinaryData did not carry the isPasted/isURL flags. This caused image-source telemetry to collapse to only 'url' and 'unknown'. Add optional isPasted/isURL to ChatReferenceBinaryData and populate them in the ChatPromptReference.to converter so consumers can recover the original image source. --- src/vs/workbench/api/common/extHostTypeConverters.ts | 5 ++++- src/vs/workbench/api/common/extHostTypes.ts | 2 ++ .../vscode.proposed.chatReferenceBinaryData.d.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index f62a5a7e66c..8f9d3a5612e 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -3555,11 +3555,14 @@ export namespace ChatPromptReference { value = Location.to(revive(value)); } else if (isImageVariableEntry(variable)) { const ref = variable.references?.[0]?.reference; - value = new types.ChatReferenceBinaryData( + const binaryData = new types.ChatReferenceBinaryData( variable.mimeType ?? 'image/png', () => Promise.resolve(new Uint8Array(Object.values(variable.value as number[]))), ref && URI.isUri(ref) ? ref : undefined ); + binaryData.isPasted = variable.isPasted; + binaryData.isURL = variable.isURL; + value = binaryData; } else if (variable.kind === 'diagnostic') { const filterSeverity = variable.filterSeverity && DiagnosticSeverity.to(variable.filterSeverity); const filterUri = variable.filterUri && URI.revive(variable.filterUri).toString(); diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index e7ea45cb0bd..2649f68b4a1 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -3841,6 +3841,8 @@ export class ChatReferenceBinaryData implements vscode.ChatReferenceBinaryData { mimeType: string; data: () => Thenable; reference?: vscode.Uri; + isPasted?: boolean; + isURL?: boolean; constructor(mimeType: string, data: () => Thenable, reference?: vscode.Uri) { this.mimeType = mimeType; this.data = data; diff --git a/src/vscode-dts/vscode.proposed.chatReferenceBinaryData.d.ts b/src/vscode-dts/vscode.proposed.chatReferenceBinaryData.d.ts index 081c24ad8c3..df5095314e2 100644 --- a/src/vscode-dts/vscode.proposed.chatReferenceBinaryData.d.ts +++ b/src/vscode-dts/vscode.proposed.chatReferenceBinaryData.d.ts @@ -29,6 +29,17 @@ declare module 'vscode' { */ readonly reference?: Uri; + /** + * Whether this image was pasted from the clipboard. + */ + readonly isPasted?: boolean; + + /** + * Whether this image originated from a URL. `true` when it was attached from a URL, + * `false` when it came from a local file, and `undefined` when the origin is unknown. + */ + readonly isURL?: boolean; + /** * @param mimeType The MIME type of the binary data. * @param data The binary data of the reference.