1
>
/*---------------------------------------------------------------------------------------------
chatImageExtraction.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { decodeBase64, VSBuffer } from '../../../../base/common/buffer.js';
7
>
import { IMarkdownString } from '../../../../base/common/htmlContent.js';
8
>
import { getExtensionForMimeType, getMediaMime } from '../../../../base/common/mime.js';
9
>
import { URI } from '../../../../base/common/uri.js';
10
>
import { localize } from '../../../../nls.js';
11
>
import { isLocation } from '../../../../editor/common/languages.js';
12
>
import { IChatResponseViewModel, IChatRequestViewModel, isRequestVM } from './model/chatViewModel.js';
13
>
import { ChatResponseResource } from './model/chatModel.js';
14
>
import { IChatContentInlineReference, IChatToolInvocation, IChatToolInvocationSerialized, IToolResultOutputDetailsSerialized } from './chatService/chatService.js';
15
>
import { isToolResultInputOutputDetails, isToolResultOutputDetails, IToolResultOutputDetails } from './tools/languageModelToolsService.js';
16
>
import { getExplicitFileOrImageAttachmentSummary, type IChatRequestVariableEntry, isImageVariableEntry } from './attachments/chatVariableEntries.js';
17
>
18
>
export interface IChatExtractedImage {
19
>
readonly id: string;
20
>
readonly uri: URI;
21
>
readonly name: string;
22
>
readonly mimeType: string;
23
>
readonly data: VSBuffer;
24
>
readonly source: string;
25
>
readonly caption: string | IMarkdownString | undefined;
26
>
}
27
>
28
>
export interface IChatExtractedImageCollection {
29
>
readonly id: string;
30
>
readonly title: string;
31
>
readonly images: IChatExtractedImage[];
32
>
}
33
>
34
>
/**
35
>
* Extract all images from a chat response's tool invocations and inline references.
36
>
* Tool invocation images are extracted from output details and message URIs.
37
>
* Inline reference images (file URIs) are read via the provided {@link readFile} callback.
38
>
*/
39
export async function extractImagesFromChatResponse(
40
response: IChatResponseViewModel,