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.
This commit is contained in:
merfanian
2026-06-09 10:57:00 -05:00
parent 9c5387b348
commit d7bf2fa1b2
3 changed files with 17 additions and 1 deletions
@@ -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();
@@ -3841,6 +3841,8 @@ export class ChatReferenceBinaryData implements vscode.ChatReferenceBinaryData {
mimeType: string;
data: () => Thenable<Uint8Array>;
reference?: vscode.Uri;
isPasted?: boolean;
isURL?: boolean;
constructor(mimeType: string, data: () => Thenable<Uint8Array>, reference?: vscode.Uri) {
this.mimeType = mimeType;
this.data = data;
@@ -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.