Cleanup IChatResponseDataPart

This commit is contained in:
Rob Lourens 2025-08-01 18:33:07 -07:00
parent 28562576c1
commit 92978676c7
No known key found for this signature in database
3 changed files with 16 additions and 15 deletions

View File

@ -5,6 +5,7 @@
import type * as vscode from 'vscode';
import { AsyncIterableObject, AsyncIterableSource, RunOnceScheduler } from '../../../base/common/async.js';
import { VSBuffer } from '../../../base/common/buffer.js';
import { CancellationToken } from '../../../base/common/cancellation.js';
import { SerializedError, transformErrorForSerialization, transformErrorFromSerialization } from '../../../base/common/errors.js';
import { Emitter, Event } from '../../../base/common/event.js';
@ -16,17 +17,16 @@ import { ExtensionIdentifier, ExtensionIdentifierMap, ExtensionIdentifierSet, IE
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
import { ILogService } from '../../../platform/log/common/log.js';
import { Progress } from '../../../platform/progress/common/progress.js';
import { ChatImageMimeType, IChatMessage, IChatResponseFragment, IChatResponsePart, ILanguageModelChatMetadata, ILanguageModelChatMetadataAndIdentifier } from '../../contrib/chat/common/languageModels.js';
import { IChatMessage, IChatResponseFragment, IChatResponsePart, ILanguageModelChatMetadata, ILanguageModelChatMetadataAndIdentifier } from '../../contrib/chat/common/languageModels.js';
import { DEFAULT_MODEL_PICKER_CATEGORY } from '../../contrib/chat/common/modelPicker/modelPickerWidget.js';
import { INTERNAL_AUTH_PROVIDER_PREFIX } from '../../services/authentication/common/authentication.js';
import { checkProposedApiEnabled } from '../../services/extensions/common/extensions.js';
import { SerializableObjectWithBuffers } from '../../services/extensions/common/proxyIdentifier.js';
import { ExtHostLanguageModelsShape, MainContext, MainThreadLanguageModelsShape } from './extHost.protocol.js';
import { IExtHostAuthentication } from './extHostAuthentication.js';
import { IExtHostRpcService } from './extHostRpcService.js';
import * as typeConvert from './extHostTypeConverters.js';
import * as extHostTypes from './extHostTypes.js';
import { SerializableObjectWithBuffers } from '../../services/extensions/common/proxyIdentifier.js';
import { VSBuffer } from '../../../base/common/buffer.js';
import { DEFAULT_MODEL_PICKER_CATEGORY } from '../../contrib/chat/common/modelPicker/modelPickerWidget.js';
export interface IExtHostLanguageModels extends ExtHostLanguageModels { }
@ -103,7 +103,7 @@ class LanguageModelResponse {
if (fragment.part.type === 'text') {
out = new extHostTypes.LanguageModelTextPart(fragment.part.value, fragment.part.audience);
} else if (fragment.part.type === 'data') {
out = new extHostTypes.LanguageModelDataPart(fragment.part.value.data, fragment.part.value.mimeType, fragment.part.audience);
out = new extHostTypes.LanguageModelDataPart(fragment.part.data.buffer, fragment.part.mimeType, fragment.part.audience);
} else {
out = new extHostTypes.LanguageModelToolCallPart(fragment.part.toolCallId, fragment.part.name, fragment.part.parameters);
}
@ -300,7 +300,7 @@ export class ExtHostLanguageModels implements ExtHostLanguageModelsShape {
} else if (fragment.part instanceof extHostTypes.LanguageModelTextPart) {
part = { type: 'text', value: fragment.part.value, audience: fragment.part.audience };
} else if (fragment.part instanceof extHostTypes.LanguageModelDataPart) {
part = { type: 'data', value: { mimeType: fragment.part.mimeType as ChatImageMimeType, data: VSBuffer.wrap(fragment.part.data) }, audience: fragment.part.audience };
part = { type: 'data', mimeType: fragment.part.mimeType, data: VSBuffer.wrap(fragment.part.data), audience: fragment.part.audience };
}
if (!part) {

View File

@ -2318,13 +2318,15 @@ export namespace LanguageModelChatMessage {
if (c.type === 'text') {
return new LanguageModelTextPart(c.value, c.audience);
} else if (c.type === 'tool_result') {
const content: (LanguageModelTextPart | LanguageModelPromptTsxPart)[] = c.value.map(part => {
const content: (LanguageModelTextPart | LanguageModelPromptTsxPart)[] = coalesce(c.value.map(part => {
if (part.type === 'text') {
return new types.LanguageModelTextPart(part.value, part.audience);
} else {
} else if (part.type === 'prompt_tsx') {
return new types.LanguageModelPromptTsxPart(part.value);
} else {
return undefined; // Strip unknown parts
}
});
}));
return new types.LanguageModelToolResultPart(c.toolCallId, content, c.isError);
} else if (c.type === 'image_url') {
// Non-stable types
@ -2418,7 +2420,7 @@ export namespace LanguageModelChatMessage2 {
if (part.type === 'text') {
return new types.LanguageModelTextPart(part.value, part.audience);
} else if (part.type === 'data') {
return new types.LanguageModelDataPart(part.value.data.buffer, part.value.mimeType);
return new types.LanguageModelDataPart(part.data.buffer, part.mimeType);
} else {
return new types.LanguageModelPromptTsxPart(part.value);
}
@ -2467,10 +2469,8 @@ export namespace LanguageModelChatMessage2 {
} else if (part instanceof types.LanguageModelDataPart) {
return {
type: 'data',
value: {
mimeType: part.mimeType as chatProvider.ChatImageMimeType,
data: VSBuffer.wrap(part.data)
},
mimeType: part.mimeType,
data: VSBuffer.wrap(part.data),
audience: part.audience
} satisfies IChatResponseDataPart;
} else {

View File

@ -110,7 +110,8 @@ export interface IChatResponsePromptTsxPart {
export interface IChatResponseDataPart {
type: 'data';
value: IChatImageURLPart;
mimeType: string;
data: VSBuffer;
audience?: ToolResultAudience[];
}