From 1fea61ffb61be6b74964a5a1ec2f2909c8669971 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 1 Aug 2025 17:10:14 -0700 Subject: [PATCH 1/3] image upload url --- src/extension/prompts/node/panel/chatVariables.tsx | 2 +- src/extension/prompts/node/panel/image.tsx | 9 ++++++++- src/extension/prompts/node/panel/toolCalling.tsx | 10 ++++++++-- .../vscode.proposed.chatBinaryReferenceData.d.ts | 12 ++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/extension/prompts/node/panel/chatVariables.tsx b/src/extension/prompts/node/panel/chatVariables.tsx index cb7a79b6f..f0b34c979 100644 --- a/src/extension/prompts/node/panel/chatVariables.tsx +++ b/src/extension/prompts/node/panel/chatVariables.tsx @@ -187,7 +187,7 @@ export async function renderChatVariables(chatVariables: ChatVariablesCollection ); } else if (variableValue instanceof ChatReferenceBinaryData) { - elements.push(); + elements.push(); } else if (typeof ChatReferenceDiagnostic !== 'undefined' && variableValue instanceof ChatReferenceDiagnostic) { // check undefined to avoid breaking old Insiders versions elements.push(); } diff --git a/src/extension/prompts/node/panel/image.tsx b/src/extension/prompts/node/panel/image.tsx index 137ad58a3..6f2d87c15 100644 --- a/src/extension/prompts/node/panel/image.tsx +++ b/src/extension/prompts/node/panel/image.tsx @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as l10n from '@vscode/l10n'; -import { BasePromptElementProps, ChatResponseReferencePartStatusKind, PromptElement, PromptReference, PromptSizing, UserMessage, Image as BaseImage } from '@vscode/prompt-tsx'; +import { Image as BaseImage, BasePromptElementProps, ChatResponseReferencePartStatusKind, PromptElement, PromptReference, PromptSizing, UserMessage } from '@vscode/prompt-tsx'; import { Uri } from '../../../../vscodeTypes'; import { IPromptEndpoint } from '../base/promptRenderer'; @@ -12,6 +12,7 @@ export interface ImageProps extends BasePromptElementProps { variableName: string; variableValue: Uint8Array | Promise; omitReferences?: boolean; + url?: string; reference?: Uri; } @@ -48,6 +49,12 @@ export class Image extends PromptElement { decoded = decodedString; } + if (this.props.url) { + decoded = this.props.url; + console.log(this.props.url); + + } + return ( diff --git a/src/extension/prompts/node/panel/toolCalling.tsx b/src/extension/prompts/node/panel/toolCalling.tsx index 8e990c01a..49a022f73 100644 --- a/src/extension/prompts/node/panel/toolCalling.tsx +++ b/src/extension/prompts/node/panel/toolCalling.tsx @@ -13,7 +13,7 @@ import { ITokenizer } from '../../../../util/common/tokenizer'; import { CancellationToken } from '../../../../util/vs/base/common/cancellation'; import { toErrorMessage } from '../../../../util/vs/base/common/errorMessage'; import { isCancellationError } from '../../../../util/vs/base/common/errors'; -import { LanguageModelDataPart, LanguageModelPromptTsxPart, ToolResultAudience, LanguageModelTextPart, LanguageModelToolResult, LanguageModelTextPart2, LanguageModelDataPart2 } from '../../../../vscodeTypes'; +import { LanguageModelDataPart, LanguageModelDataPart2, LanguageModelPromptTsxPart, LanguageModelTextPart, LanguageModelTextPart2, LanguageModelToolResult, ToolResultAudience } from '../../../../vscodeTypes'; import { isImageDataPart } from '../../../conversation/common/languageModelChatMessageHelpers'; import { IResultMetadata } from '../../../prompt/common/conversation'; import { IBuildPromptContext, IToolCall, IToolCallRound } from '../../../prompt/common/intents'; @@ -295,7 +295,13 @@ enum ToolInvocationOutcome { export function imageDataPartToTSX(part: LanguageModelDataPart) { if (isImageDataPart(part)) { const base64 = Buffer.from(part.data).toString('base64'); - return ; + const decodedString = new TextDecoder().decode(part.data); + + // Check if the decoded data is a URL + const isUrl = /^https?:\/\/.+/.test(decodedString); + const src = isUrl ? decodedString : `data:${part.mimeType};base64,${base64}`; + + return ; } } diff --git a/src/extension/vscode.proposed.chatBinaryReferenceData.d.ts b/src/extension/vscode.proposed.chatBinaryReferenceData.d.ts index 50789bde8..197cef56a 100644 --- a/src/extension/vscode.proposed.chatBinaryReferenceData.d.ts +++ b/src/extension/vscode.proposed.chatBinaryReferenceData.d.ts @@ -5,9 +5,6 @@ declare module 'vscode' { - /** - * A reference to a value that the user added to their chat request. - */ export interface ChatPromptReference { /** * The value of this reference. The `string | Uri | Location` types are used today, but this could expand in the future. @@ -23,10 +20,17 @@ declare module 'vscode' { /** * Retrieves the binary data of the reference. This is primarily used to receive image attachments from the chat. + * Note: base64 will only be used as a fallback if upload fails. * @returns A promise that resolves to the binary data as a Uint8Array. */ data(): Thenable; + /** + * URL of image that was uploaded to GitHub + */ + url: string; + + /** * Retrieves a URI reference to the binary data, if available. */ @@ -36,6 +40,6 @@ declare module 'vscode' { * @param mimeType The MIME type of the binary data. * @param data The binary data of the reference. */ - constructor(mimeType: string, data: () => Thenable); + constructor(mimeType: string, data: () => Thenable, url: string, reference?: Uri); } } From 74afd0202d201b64ce4a2395102f2b4b003a0595 Mon Sep 17 00:00:00 2001 From: justschen Date: Mon, 4 Aug 2025 13:25:01 -0700 Subject: [PATCH 2/3] fix internal type --- src/util/common/test/shims/chatTypes.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/common/test/shims/chatTypes.ts b/src/util/common/test/shims/chatTypes.ts index c0b70c9bf..c5a56323a 100644 --- a/src/util/common/test/shims/chatTypes.ts +++ b/src/util/common/test/shims/chatTypes.ts @@ -242,7 +242,8 @@ export class ChatReferenceDiagnostic { export class ChatReferenceBinaryData { constructor( readonly mimeType: string, - readonly data: () => Thenable + readonly data: () => Thenable, + readonly url: string ) { } } From 8ce54af0a7180835efba3a51f799df065448e6ec Mon Sep 17 00:00:00 2001 From: justschen Date: Tue, 5 Aug 2025 00:05:49 -0700 Subject: [PATCH 3/3] remove console log --- src/extension/prompts/node/panel/image.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/extension/prompts/node/panel/image.tsx b/src/extension/prompts/node/panel/image.tsx index 6f2d87c15..3c8843fce 100644 --- a/src/extension/prompts/node/panel/image.tsx +++ b/src/extension/prompts/node/panel/image.tsx @@ -51,8 +51,6 @@ export class Image extends PromptElement { if (this.props.url) { decoded = this.props.url; - console.log(this.props.url); - } return (