From b79ff2ede04b8328dfa6ac23402a18a643eba20a Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 22 Oct 2024 12:52:51 +0200 Subject: [PATCH] fix https://github.com/microsoft/vscode-copilot/issues/9509 (#231926) --- src/vs/workbench/api/common/extHostTypes.ts | 24 +++++++++++-------- .../api/test/browser/extHostTypes.test.ts | 16 +++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 1b955c27e5c..a2b695914ef 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -4608,30 +4608,34 @@ export class LanguageModelChatMessage implements vscode.LanguageModelChatMessage role: vscode.LanguageModelChatMessageRole; - // Temp to avoid breaking changes - content2: (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined; + content: (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[]; - private _content: (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[]; - get content(): (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[] { - // Temp for back-compat - if (this.content2) { - return this.content2.map(part => { + // Temp to avoid breaking changes + set content2(value: (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined) { + if (value) { + this.content = value.map(part => { if (typeof part === 'string') { return new LanguageModelTextPart(part); } - return part; }); } + } - return this._content; + get content2(): (string | LanguageModelToolResultPart | LanguageModelToolCallPart)[] | undefined { + return this.content.map(part => { + if (part instanceof LanguageModelTextPart) { + return part.value; + } + return part; + }); } name: string | undefined; constructor(role: vscode.LanguageModelChatMessageRole, content: string | (LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart)[], name?: string) { this.role = role; - this._content = typeof content === 'string' ? [new LanguageModelTextPart(content)] : content; + this.content = typeof content === 'string' ? [new LanguageModelTextPart(content)] : content; this.name = name; } } diff --git a/src/vs/workbench/api/test/browser/extHostTypes.test.ts b/src/vs/workbench/api/test/browser/extHostTypes.test.ts index 0ed70be8207..bf197e70184 100644 --- a/src/vs/workbench/api/test/browser/extHostTypes.test.ts +++ b/src/vs/workbench/api/test/browser/extHostTypes.test.ts @@ -775,4 +775,20 @@ suite('ExtHostTypes', function () { assert.throws(() => types.FileDecoration.validate({ badge: 'புன்சிரிப்போடு' })); assert.throws(() => types.FileDecoration.validate({ badge: 'ããã' })); }); + + test('No longer possible to set content on LanguageModelChatMessage', function () { + const m = types.LanguageModelChatMessage.Assistant(''); + m.content = [new types.LanguageModelToolCallPart('toolCall.tool.name', 'toolCall.call.callId', 'toolCall.call.parameters')]; + + assert.equal(m.content.length, 1); + assert.equal(m.content2?.length, 1); + + + m.content2 = ['foo']; + assert.equal(m.content.length, 1); + assert.ok(m.content[0] instanceof types.LanguageModelTextPart); + + assert.equal(m.content2?.length, 1); + assert.ok(typeof m.content2[0] === 'string'); + }); });