vscode icon indicating copy to clipboard operation
vscode copied to clipboard

LanguageModelTextPart constructor never assigns audience (audience = audience)

Open mant-raj opened this issue 1 week ago • 0 comments

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: main at commit 1d20abca144f85864e4f9a467f29e7b0bcd86489 (package version 1.148.0)
  • OS Version: Ubuntu 24.04.5 LTS, Node v22.23.5

Description

In src/vs/workbench/api/common/extHostTypes.ts, the LanguageModelTextPart constructor assigns the audience parameter to itself, so this.audience is never set:

constructor(value: string, audience?: vscode.LanguageModelPartAudience[]) {
    this.value = value;
    audience = audience;   // self-assignment: this.audience stays undefined
}

The sibling class LanguageModelDataPart does this correctly (this.audience = audience;). All the type converters in extHostTypeConverters.ts pass audience into new LanguageModelTextPart(value, audience), so it is lost on every conversion, and also in toJSON().

Steps to Reproduce

  1. Bundle the real classes with esbuild (--external:@vscode/windows-registry --external:@vscode/windows-process-tree) and run:
import { LanguageModelTextPart, LanguageModelDataPart } from './src/vs/workbench/api/common/extHostTypes';
const audience = [1, 2] as any;
const text = new LanguageModelTextPart('hello', audience);
const data = new LanguageModelDataPart(new Uint8Array(1), 'image/png', audience);
console.log(JSON.stringify(text.audience));    // undefined
console.log(JSON.stringify(data.audience));    // [1,2]
console.log(JSON.stringify(text.toJSON()));    // {"$mid":21,"value":"hello"}  (no audience)

Actual: LanguageModelTextPart.audience is always undefined. Expected: [1,2], the same as LanguageModelDataPart.

Suggested fix

this.audience = audience;

mant-raj avatar Nov 18 '26 17:11 mant-raj