agentHostClientByokLmChannel.ts ×5

Frontier kind: Code frontier

unlabeled · c_08e925d1ef64

6 tests · 9318 LOC · 41 files · introduces 0 tests · 211 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
6 ranges211 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1464 ranges9318 lines · 41 files · Browse complete extent
All tests (intent)
6 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Introduced files, introduced tests, and structurally relevant concept specializationagentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel coalesces a burst of changes so the final snapshot reflects the latest models|occurrence=1 · 0 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×4 · 26 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×1 · 3 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×1 · 1 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×1 · 1 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×3 · 4 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×2 · 2 introduced LOCagentHostClientByokLmCha…agentHostClientByokLmChannel.ts ×1 · 5 introduced LOCagentHostClientByokLmCha…log.ts ×1 · 1 introduced LOClog.ts ×1log.ts ×72 · 446 introduced LOClog.ts ×72contextkey.ts ×1 · 2 introduced LOCcontextkey.ts ×1contextkey.ts ×3 · 7 introduced LOCcontextkey.ts ×3async.ts ×202 · 1247 introduced LOCasync.ts ×202contextkey.ts ×1 · 3 introduced LOCcontextkey.ts ×1contextkey.ts ×1 · 2 introduced LOCcontextkey.ts ×1contextkey.ts ×1 · 3 introduced LOCcontextkey.ts ×1contextkey.ts ×1 · 2 introduced LOCcontextkey.ts ×1contextkey.ts ×2 · 3 introduced LOCcontextkey.ts ×2contextkey.ts ×1 · 2 introduced LOCcontextkey.ts ×1contextkey.ts ×2 · 3 introduced LOCcontextkey.ts ×2contextkey.ts ×2 · 3 introduced LOCcontextkey.ts ×2contextkey.ts ×1 · 2 introduced LOCcontextkey.ts ×1contextkey.ts ×1 · 4 introduced LOCcontextkey.ts ×1contextkey.ts ×201 · 796 introduced LOCcontextkey.ts ×201hash.ts ×17 · 74 introduced LOChash.ts ×17resources.ts ×23 · 253 introduced LOCresources.ts ×23network.ts ×20 · 292 introduced LOCnetwork.ts ×20extpath.ts ×17 · 91 introduced LOCextpath.ts ×17instantiation.ts ×1 · 1 introduced LOCinstantiation.ts ×1strings.ts ×101 · 542 introduced LOCstrings.ts ×101cancellation.ts ×18 · 90 introduced LOCcancellation.ts ×18event.ts ×1 · 1 introduced LOCevent.ts ×1event.ts ×4 · 9 introduced LOCevent.ts ×4event.ts ×2 · 4 introduced LOCevent.ts ×2event.ts ×2 · 6 introduced LOCevent.ts ×2event.ts ×93 · 864 introduced LOCevent.ts ×93buffer.ts ×42 · 483 introduced LOCbuffer.ts ×42scanner.ts ×13 · 13 introduced LOCscanner.ts ×13scanner.ts ×3 · 3 introduced LOCscanner.ts ×3scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×1 · 1 introduced LOCscanner.ts ×1scanner.ts ×36 · 181 introduced LOCscanner.ts ×36utils.ts ×3 · 9 introduced LOCutils.ts ×3instantiation.ts ×4 · 10 introduced LOCinstantiation.ts ×4nls.ts ×1 · 1 introduced LOCnls.ts ×1errorMessage.ts ×6 · 29 introduced LOCerrorMessage.ts ×6linkedList.ts ×13 · 44 introduced LOClinkedList.ts ×13nls.ts ×6 · 13 introduced LOCnls.ts ×6instantiation.ts ×5 · 111 introduced LOCinstantiation.ts ×5lifecycle.ts ×2 · 4 introduced LOClifecycle.ts ×2lifecycle.ts ×4 · 8 introduced LOClifecycle.ts ×4lifecycle.ts ×6 · 16 introduced LOClifecycle.ts ×6lazy.ts ×1 · 2 introduced LOClazy.ts ×1lazy.ts ×3 · 37 introduced LOClazy.ts ×3lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1uint.ts ×2 · 43 introduced LOCuint.ts ×2lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1map.ts ×97 · 3334 introduced LOCmap.ts ×97src/vs/base/common/arrays.ts · 949 LOCcommon/arrays.tssrc/vs/base/common/arraysFind.ts · 226 LOCcommon/arraysFind.tssrc/vs/base/common/assert.ts · 91 LOCcommon/assert.tssrc/vs/base/common/async.ts · 2749 LOCcommon/async.tssrc/vs/base/common/buffer.ts · 499 LOCcommon/buffer.tssrc/vs/base/common/cache.ts · 153 LOCcommon/cache.tssrc/vs/base/common/cancellation.ts · 206 LOCcommon/cancellation.tssrc/vs/base/common/charCode.ts · 450 LOCcommon/charCode.tssrc/vs/base/common/collections.ts · 176 LOCcommon/collections.tssrc/vs/base/common/errorMessage.ts · 113 LOCcommon/errorMessage.tssrc/vs/base/common/errors.ts · 357 LOCcommon/errors.tssrc/vs/base/common/event.ts · 1964 LOCcommon/event.tssrc/vs/base/common/extpath.ts · 433 LOCcommon/extpath.tssrc/vs/base/common/functional.ts · 32 LOCcommon/functional.tssrc/vs/base/common/hash.ts · 324 LOCcommon/hash.tssrc/vs/base/common/iterator.ts · 194 LOCcommon/iterator.tssrc/vs/base/common/lazy.ts · 57 LOCcommon/lazy.tssrc/vs/base/common/lifecycle.ts · 974 LOCcommon/lifecycle.tssrc/vs/base/common/linkedList.ts · 151 LOCcommon/linkedList.tssrc/vs/base/common/map.ts · 1016 LOCcommon/map.tssrc/vs/base/common/marshallingIds.ts · 33 LOCcommon/marshallingIds.tssrc/vs/base/common/network.ts · 440 LOCcommon/network.tssrc/vs/base/common/path.ts · 1589 LOCcommon/path.tssrc/vs/base/common/platform.ts · 281 LOCcommon/platform.tssrc/vs/base/common/process.ts · 76 LOCcommon/process.tssrc/vs/base/common/resources.ts · 444 LOCcommon/resources.tssrc/vs/base/common/stopwatch.ts · 41 LOCcommon/stopwatch.tssrc/vs/base/common/stream.ts · 790 LOCcommon/stream.tssrc/vs/base/common/strings.ts · 1413 LOCcommon/strings.tssrc/vs/base/common/symbols.ts · 9 LOCcommon/symbols.tssrc/vs/base/common/types.ts · 410 LOCcommon/types.tssrc/vs/base/common/uint.ts · 59 LOCcommon/uint.tssrc/vs/base/common/uri.ts · 754 LOCcommon/uri.tssrc/vs/base/test/common/utils.ts · 107 LOCcommon/utils.tssrc/vs/nls.ts · 244 LOCvs/nls.tssrc/vs/platform/agentHost/common/agentHostByokLm.ts · 145 LOCcommon/agentHostByokLm.t…src/vs/platform/agentHost/common/agentHostClientByokLmChannel.ts · 114 LOCcommon/agentHostClientBy…src/vs/platform/contextkey/common/contextkey.ts · 2183 LOCcommon/contextkey.tssrc/vs/platform/contextkey/common/scanner.ts · 384 LOCcommon/scanner.tssrc/vs/platform/instantiation/common/instantiation.ts · 130 LOCcommon/instantiation.tssrc/vs/platform/log/common/log.ts · 926 LOCcommon/log.tsagentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel coalesces a burst of changes so the final snapshot reflects the latest models|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel coalesces a burst of changes so the final snapshot reflects the latest models|occurrence=1agentHostClientByokLmCha…agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel exposes only the models event|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel exposes only the models event|occurrence=1agentHostClientByokLmCha…agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel forwards a bridge error result unchanged|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel forwards a bridge error result unchanged|occurrence=1agentHostClientByokLmCha…agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel pushes the current model snapshot on subscribe and re-pushes on change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel pushes the current model snapshot on subscribe and re-pushes on change|occurrence=1agentHostClientByokLmCha…agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel rejects unknown channel commands|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel rejects unknown channel commands|occurrence=1agentHostClientByokLmCha…agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel round-trips a chat request to the handler and back|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostClientByokLmChannel.test|title=agentHostClientByokLmChannel round-trips a chat request to the handler and back|occurrence=1agentHostClientByokLmCha…Focused concept · agentHostClientByokLmChannel.ts ×5 · 211 introduced LOCagentHostClientByokLmCha…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 211 introduced LOC across 6 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/agentHostByokLm.ts 145 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostByokLm.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 { CancellationToken } from '../../../base/common/cancellation.js';
7 > import { Event } from '../../../base/common/event.js';
8 > import { createDecorator } from '../../instantiation/common/instantiation.js';
9 >
10 > /**
11 > * Serializable bridge contract between the node agent host (where the
12 > * {@link IByokLmProxyService} OpenAI-compatible proxy runs) and the renderer
13 > * (which owns the extension-provided BYOK language models via the LM API).
14 > *
15 > * These shapes are deliberately wire-friendly (plain JSON, no `VSBuffer`,
16 > * `URI`, or `workbench/contrib/chat` types) so they survive both the local
17 > * utility-process IPC channel and the remote JSON-RPC transport without a
18 > * translation step. The node side converts OpenAI Chat Completions wire
19 > * payloads to/from these; the renderer side converts these to/from the VS Code
20 > * LM API (`ILanguageModelsService`).
21 > */
22 >
23 > /** A single tool/function call requested by the assistant. */
24 > export interface IByokLmToolCall {
25 > /** Stable id correlating the call with its later `tool` result message. */
26 > readonly id: string;
27 > /** Tool/function name. */
28 > readonly name: string;
29 > /** JSON-encoded arguments object. */
30 > readonly argumentsJson: string;
31 > }
32 >
33 > /** A tool/function the model may call. */
34 > export interface IByokLmTool {
35 > readonly name: string;
36 > readonly description?: string;
37 > /** JSON schema for the tool parameters. */
38 > readonly parametersSchema?: object;
39 > }
40 >
41 > /** One chat message in a BYOK request. */
42 > export interface IByokLmChatMessage {
43 > readonly role: 'system' | 'user' | 'assistant' | 'tool';
44 > /** Flattened text content. Empty string when the message carries only tool calls/results. */
45 > readonly content: string;
46 > /** Present on `assistant` messages that requested tool calls. */
47 > readonly toolCalls?: IByokLmToolCall[];
48 > /** Present on `tool` messages: the {@link IByokLmToolCall.id} this result answers. */
49 > readonly toolCallId?: string;
50 > }
51 >
52 > /** A chat request forwarded from the proxy to the renderer LM API. */
53 > export interface IByokLmChatRequest {
54 > /** Provider/vendor name (the LM API vendor that registered the model). */
55 > readonly vendor: string;
56 > /** Provider-local model id (the wire id the runtime sent on the OpenAI request). */
57 > readonly modelId: string;
58 > readonly messages: IByokLmChatMessage[];
59 > readonly tools?: IByokLmTool[];
60 > /** Opaque per-request model options forwarded to the LM provider. */
61 > readonly modelOptions?: Record<string, unknown>;
62 > }
63 >
64 > /** The (buffered) completion produced by the renderer LM API. */
65 > export interface IByokLmChatResult {
66 > /** Concatenated assistant text. */
67 > readonly content: string;
68 > /** Tool calls the assistant requested, if any. */
69 > readonly toolCalls?: IByokLmToolCall[];
70 > /** Best-effort token usage, when the provider reports it. */
71 > readonly usage?: {
72 > readonly promptTokens?: number;
73 > readonly completionTokens?: number;
74 > };
75 > /** Set when the LM call failed; `content` is then empty. */
76 > readonly error?: string;
77 > }
78 >
79 > /**
80 > * Metadata for a renderer BYOK model, enumerated over the bridge so the node
81 > * agent host can advertise it to the SDK runtime without any host-side config.
82 > */
83 > export interface IByokLmModelInfo {
84 > /** Provider/vendor name (the LM API vendor that registered the model). */
85 > readonly vendor: string;
86 > /** Provider-local model id. */
87 > readonly id: string;
88 > /** Display name, when the provider supplies one. */
89 > readonly name?: string;
90 > /**
91 > * The identifier the model is registered under in the renderer's LM service —
92 > * i.e. `toModelIdentifier(vendor, group, id)` in `extHostLanguageModels`
93 > * (`<vendor>/<group>/<id>` when the user configured a provider group in
94 > * `chatLanguageModels.json`, else `<vendor>/<id>`).
95 > */
96 > readonly modelIdentifier?: string;
97 > /** Maximum context window tokens (prompt + output), when known. */
98 > readonly maxContextWindowTokens?: number;
99 > /** Whether the model accepts image inputs, when known. */
100 > readonly supportsVision?: boolean;
101 > }
102 >
103 > export const IAgentHostByokLmHandler = createDecorator<IAgentHostByokLmHandler>('agentHostByokLmHandler');
104 >
105 > /**
106 > * Renderer-side handler that services {@link IByokLmChatRequest}s by calling
107 > * the VS Code Language Model API. Implemented in the workbench (where
108 > * `ILanguageModelsService` lives) and reached from the node agent host over
109 > * the reverse bridge.
110 > */
111 > export interface IAgentHostByokLmHandler {
112 > readonly _serviceBrand: undefined;
113 >
114 > /**
115 > * Fires when the renderer's set of BYOK models changes, so the node agent
116 > * host can re-enumerate them for the model picker. Optional: test fakes may
117 > * omit it.
118 > */
119 > readonly onDidChangeModels?: Event<void>;
120 >
121 > /**
122 > * Run a BYOK chat completion against the extension-registered model that
123 > * matches `request.vendor` + `request.modelId`. Rejects (or resolves with
124 > * {@link IByokLmChatResult.error}) when no such model is available.
125 > */
126 > chat(request: IByokLmChatRequest, token: CancellationToken): Promise<IByokLmChatResult>;
127 >
128 > /**
129 > * Enumerate the renderer's BYOK models (vendor `isBYOK`, excluding
130 > * session-scoped agent-host copies) so the node agent host can synthesize
131 > * provider/model config for the SDK runtime.
132 > */
133 > listModels(token: CancellationToken): Promise<IByokLmModelInfo[]>;
134 > }
135 >
136 > /**
137 > * Node-side connection to a single renderer's {@link IAgentHostByokLmHandler}.
138 > * Mirrors `IRemoteFilesystemConnection` for the reverse FS bridge. The renderer
139 > * pushes its models over {@link onDidChangeModels}; `chat` stays a round-trip.
140 > */
141 > export interface IByokLmBridgeConnection {
142 > chat(request: IByokLmChatRequest): Promise<IByokLmChatResult>;
143 > /** Emits the renderer's current BYOK model snapshot on subscribe and on every change. */
144 > readonly onDidChangeModels: Event<IByokLmModelInfo[]>;
145 > }
src/vs/platform/agentHost/common/agentHostClientByokLmChannel.ts 66 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostClientByokLmChannel.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 { CancellationToken } from '../../../base/common/cancellation.js';
7 > import { Throttler } from '../../../base/common/async.js';
8 > import { Emitter, Event } from '../../../base/common/event.js';
9 > import { DisposableStore } from '../../../base/common/lifecycle.js';
10 > import { IChannel, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
11 > import { ILogService } from '../../log/common/log.js';
12 > import {
13 > IAgentHostByokLmHandler,
14 > IByokLmBridgeConnection,
15 > IByokLmChatRequest,
16 > IByokLmChatResult,
17 > IByokLmModelInfo,
18 > } from './agentHostByokLm.js';
19 >
20 > /**
21 > * IPC channel name used for in-process agent-host → renderer reverse BYOK
22 > * language-model RPCs. The renderer registers a server channel under this
23 > * name on its `MessagePortClient`; the agent host reaches it via
24 > * `server.getChannel(name, c => c.ctx === clientId)` on its
25 > * `UtilityProcessServer`.
26 > */
27 > export const AGENT_HOST_CLIENT_BYOK_LM_CHANNEL = 'agentHostClientByokLm';
28 >
29 > /**
30 > * Wraps an {@link IChannel} (obtained from the agent host's
31 > * `UtilityProcessServer.getChannel`) into an {@link IByokLmBridgeConnection}
32 > * suitable for the node-side {@link IByokLmProxyService}. This is the node end
33 > * of the bridge: `chat()` ships the request to the renderer and resolves with
34 > * the buffered completion the renderer produced from the LM API, and
35 > * `onDidChangeModels` is the renderer's pushed model snapshot stream.
36 > */
37 > export function createAgentHostClientByokLmConnection(channel: IChannel): IByokLmBridgeConnection {
38 return {
39 chat: (request) => channel.call('chat', request) as Promise<IByokLmChatResult>,
41 };
42 }
44 > /**
45 > * Server-side channel for in-process reverse BYOK LM RPCs from the local agent
46 > * host. Thin adapter — forwards `chat` calls to the renderer's
47 > * {@link IAgentHostByokLmHandler} (backed by `ILanguageModelsService`) and
48 > * serves the pushed `models` snapshot stream.
49 > */
50 >
51 > export class AgentHostClientByokLmChannel implements IServerChannel {
52 >
53 > constructor(
54 > @IAgentHostByokLmHandler private readonly _handler: IAgentHostByokLmHandler,
55 > @ILogService private readonly _logService: ILogService,
56 > ) { }
57 >
58 > listen<T>(_ctx: unknown, event: string): Event<T> {
59 if (event === 'models') {
60 return this._modelsSnapshotEvent() as Event<T>;
62 throw new Error(`No event '${event}' on AgentHostClientByokLmChannel`);
63 }
65 > /**
66 > * A snapshot stream of the renderer's BYOK models: emits the current models
67 > * when a subscriber attaches, then re-emits whenever the handler reports a
68 > * change. Enumeration is renderer-local, so the node side only ever receives.
69 > *
70 > * A {@link Throttler} serializes overlapping publishes and coalesces bursts,
71 > * so a slow enumeration can't fire a stale snapshot after a newer one.
72 > */
73 > private _modelsSnapshotEvent(): Event<IByokLmModelInfo[]> {
74 const store = new DisposableStore();
75 const throttler = store.add(new Throttler());
102 return emitter.event;
103 }
105 > async call<T>(_ctx: unknown, command: string, arg?: unknown): Promise<T> {
106 switch (command) {
107 case 'chat': {