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..3c8843fce 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,10 @@ export class Image extends PromptElement { decoded = decodedString; } + if (this.props.url) { + decoded = 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); } } diff --git a/src/util/common/test/shims/chatTypes.ts b/src/util/common/test/shims/chatTypes.ts index 7b82d924d..f5781c986 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 ) { } }