activeClientState.ts ×17

Frontier kind: Code frontier

unlabeled · c_95d3a47d043e

693 tests · 4669 LOC · 25 files · introduces 0 tests · 120 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges120 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
654 ranges4669 lines · 25 files · Browse complete extent
All tests (intent)
693 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.

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.

1 file ranked by introduced lines: 120 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/activeClientState.ts 120 introduced LOC · 17 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- activeClientState.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 { equals } from '../../../base/common/objects.js';
7 > import type { ToolDefinition } from '../common/state/protocol/state.js';
8 >
9 > /**
10 > * Structural view of the active client's contributions that, when changed,
11 > * requires the underlying SDK session to be restarted / rebound. The
12 > * `clientId` is deliberately excluded — a window reload that produces a new
13 > * `clientId` with an identical tool list does NOT require a restart.
14 > */
15 > export interface IActiveClientStructuralSnapshot {
16 > readonly tools: readonly ToolDefinition[];
17 > }
18 >
19 > /**
20 > * Deep-equal two client-tool snapshots on `name + description + inputSchema`.
21 > * `undefined` and `[]` compare equal. Order-insensitive.
22 > *
23 > * Single shared implementation for the agent-host providers — previously
24 > * duplicated as `snapshotsEqual` (Claude client-tools model) and an inline
25 > * loop in the Copilot `ActiveClient` staleness check.
26 > */
27 > export function structuralToolsEqual(
28 a: readonly ToolDefinition[] | undefined,
29 b: readonly ToolDefinition[] | undefined,
52 return true;
53 }
55 > /**
56 > * A per-session registry of the tools contributed by each active client,
57 > * keyed by `clientId` and kept in insertion order. Backs the multi-active-client
58 > * tool model shared by the agent-host providers (Copilot, Claude, Codex):
59 > * each provider stores one of these per session and exposes the
60 > * {@link merged} view to its SDK while routing tool calls back to the
61 > * {@link ownerOf | owning client}.
62 > *
63 > * Deduplication of {@link merged} is by tool `name`, first-inserted-client
64 > * wins, so the merged order and the owner of any given tool name are
65 > * deterministic regardless of how many clients contribute it.
66 > */
67 > export class ActiveClientToolSet {
68 private readonly _byClient = new Map<string, readonly ToolDefinition[]>();
70 > /** Number of clients currently contributing tools. */
71 > get size(): number {
72 return this._byClient.size;
73 }
75 > /** Whether `clientId` currently contributes tools. */
76 > has(clientId: string): boolean {
77 return this._byClient.has(clientId);
78 }
80 > /** The client ids currently contributing tools, in insertion order. */
81 > clientIds(): IterableIterator<string> {
82 return this._byClient.keys();
83 }
85 > /** This client's contributed tools, or an empty array when absent. */
86 > get(clientId: string): readonly ToolDefinition[] {
87 return this._byClient.get(clientId) ?? [];
88 }
90 > /**
91 > * Replace `clientId`'s contributed tools (full replacement). A new
92 > * `clientId` is appended after existing ones; re-setting an existing
93 > * `clientId` keeps its insertion position so merged ordering and tool
94 > * ownership stay stable across updates.
95 > */
96 > set(clientId: string, tools: readonly ToolDefinition[]): void {
97 this._byClient.set(clientId, tools);
98 }
100 > /** Remove `clientId`'s contribution. Returns whether anything was removed. */
101 > delete(clientId: string): boolean {
102 return this._byClient.delete(clientId);
103 }
105 > /**
106 > * The union of every client's tools, deduplicated by `name` with the
107 > * first-inserted contributor winning. Order follows client insertion
108 > * order, then per-client tool order.
109 > */
110 > merged(): readonly ToolDefinition[] {
111 const seen = new Set<string>();
112 const result: ToolDefinition[] = [];
122 return result;
123 }
125 > /**
126 > * The `clientId` that owns the tool named `toolName`, or `undefined` when
127 > * no active client provides it. When `preferredClientId` currently provides
128 > * the tool it wins; otherwise the first-inserted contributor wins.
129 > */
130 > ownerOf(toolName: string, preferredClientId?: string): string | undefined {
131 if (preferredClientId && this.get(preferredClientId).some(tool => tool.name === toolName)) {
132 return preferredClientId;
139 return undefined;
140 }
142 > /**
143 > * Structural comparison of the current {@link merged} tools against a
144 > * previously-applied snapshot (`name + description + inputSchema`,
145 > * order-insensitive). Returns `true` when no SDK restart is required.
146 > */
147 > structuralEquals(applied: readonly ToolDefinition[] | undefined): boolean {
148 return structuralToolsEqual(this.merged(), applied);
149 }
151 >
152 > /**
153 > * Live, mutable holder for the active client's identity (`clientId`) and the
154 > * structural tool snapshot it contributes. Shared between the Copilot and
155 > * Claude providers so a single long-lived instance per session URI survives
156 > * SDK-session dispose / resume cycles.
157 > *
158 > * The `clientId` is read at tool-call **stamp time** (not cached per turn) so
159 > * that a window reload — which connects with a new `clientId` and re-pushes an
160 > * identical tool list — stamps subsequent client tool calls with the new,
161 > * live `clientId` instead of a frozen one baked in at session creation.
162 > */
163 > export class ActiveClientState {
164 private _clientId: string | undefined = undefined;
165 private _tools: readonly ToolDefinition[] = [];
167 > /** Live owning client id, or `undefined` when no client is currently connected. */
168 > get clientId(): string | undefined {
169 return this._clientId;
170 }
172 > /** Structural state (tool definitions). Changing these requires an SDK restart/rebind. */
173 > get tools(): readonly ToolDefinition[] {
174 return this._tools;
175 }
177 > /**
178 > * Replace the owning `clientId` (`undefined` when no client is connected)
179 > * and the contributed tool list. A `clientId`-only change does NOT mark
180 > * structural dirt (see {@link structuralEquals}).
181 > */
182 > update(clientId: string | undefined, tools: readonly ToolDefinition[]): void {
183 this._clientId = clientId;
184 this._tools = tools;
185 }
187 > /**
188 > * Structural comparison of the live tools against a previously-applied
189 > * snapshot (`name + description + inputSchema`, order-insensitive).
190 > * Returns `true` when no SDK restart is required.
191 > */
192 > structuralEquals(applied: IActiveClientStructuralSnapshot): boolean {
193 return structuralToolsEqual(this._tools, applied.tools);
194 }