claudeElicitation.ts ×7

Frontier kind: Code frontier

unlabeled · c_a4575e5e9d03

213 tests · 10563 LOC · 39 files · introduces 0 tests · 181 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges181 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
690 ranges10563 lines · 39 files · Browse complete extent
All tests (intent)
213 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.

3 files ranked by introduced lines: 181 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/claude/claudeElicitation.ts 141 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- claudeElicitation.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 type { ElicitationRequest, ElicitationResult } from '@anthropic-ai/claude-agent-sdk';
7 > import type { PrimitiveSchemaDefinition } from '@modelcontextprotocol/sdk/types.js';
8 > import { isObject, isString } from '../../../../base/common/types.js';
9 > import { vArray, vNumber, vObj, vOptionalProp, vString, vUnknown, type ValidatorType } from '../../../../base/common/validation.js';
10 > import { ChatInputAnswerState, ChatInputAnswerValueKind, ChatInputQuestionKind, ChatInputResponseKind, type ChatInputAnswer, type ChatInputOption, type ChatInputQuestion, type ChatInputRequest } from '../../common/state/sessionState.js';
11 >
12 > /**
13 > * Pure projections between the Claude SDK's MCP elicitation request/response
14 > * and the agentHost workbench protocol.
15 > *
16 > * When an MCP server calls `elicit/create`, the SDK invokes
17 > * `Options.onElicitation` with an {@link ElicitationRequest}. The agent surfaces
18 > * it as structured user input (a {@link ChatInputRequest}, the same channel
19 > * `AskUserQuestion` uses — NOT the permission gate) and translates the user's
20 > * answer back into the SDK's {@link ElicitationResult}. This module owns those
21 > * projections so they can be unit-tested without standing up an agent.
22 > *
23 > * Unlike the Codex provider — whose `requestedSchema` is a strongly-typed
24 > * generated schema — the Claude SDK delivers `requestedSchema` as an untyped
25 > * `Record<string, unknown>`. Each field is runtime-validated with the base-layer
26 > * {@link vObj} validator ({@link vElicitationField}), which drops malformed
27 > * fields instead of mis-projecting or throwing. The field type is *derived* from
28 > * that validator (not hand-rolled) and cross-checked against the MCP SDK's
29 > * authoritative {@link PrimitiveSchemaDefinition} by
30 > * {@link _assertElicitationFieldCoversSchema} (which catches an incompatible
31 > * reshape of a covered field, though not a purely additive new variant). The
32 > * base-layer validator is used rather than the SDK's own zod schema because this
33 > * module is loaded by the unit-test renderer, where a runtime
34 > * `@modelcontextprotocol/sdk` import does not resolve (all SDK runtime access
35 > * goes through `IClaudeAgentSdkService`).
36 > */
37 >
38 > /** Value the SDK accepts back for a single elicited field. */
39 > type ElicitationFieldValue = NonNullable<ElicitationResult['content']>[string];
40 >
41 > /** A `{ const, title? }` option, shared by `oneOf` and array `items.anyOf`. */
42 > const vTitledOption = vObj({ const: vString(), title: vOptionalProp(vString()) });
43 >
44 > /**
45 > * Lenient runtime validator for a single elicitation schema field. Structure is
46 > * validated (a present `enum` must be a string array, `minimum` a number, …) so
47 > * a malformed field is dropped rather than mis-projected; value-level
48 > * constraints (e.g. `format`, `type`) stay permissive so real-world schema
49 > * variation still renders. {@link IElicitationField} is derived from this, and
50 > * {@link _assertElicitationFieldCoversSchema} pins it to the MCP SDK's
51 > * {@link PrimitiveSchemaDefinition}.
52 > */
53 > const vElicitationField = vObj({
54 > type: vOptionalProp(vString()),
55 > title: vOptionalProp(vString()),
56 > description: vOptionalProp(vString()),
57 > format: vOptionalProp(vString()),
58 > default: vOptionalProp(vUnknown()),
59 > minimum: vOptionalProp(vNumber()),
60 > maximum: vOptionalProp(vNumber()),
61 > minLength: vOptionalProp(vNumber()),
62 > maxLength: vOptionalProp(vNumber()),
63 > minItems: vOptionalProp(vNumber()),
64 > maxItems: vOptionalProp(vNumber()),
65 > enum: vOptionalProp(vArray(vString())),
66 > enumNames: vOptionalProp(vArray(vString())),
67 > oneOf: vOptionalProp(vArray(vTitledOption)),
68 > items: vOptionalProp(vObj({
69 > enum: vOptionalProp(vArray(vString())),
70 > anyOf: vOptionalProp(vArray(vTitledOption)),
71 > })),
72 > });
73 >
74 > type IElicitationField = ValidatorType<typeof vElicitationField>;
75 >
76 > /**
77 > * Compile-time guard: every member of the MCP SDK's authoritative
78 > * {@link PrimitiveSchemaDefinition} union must be assignable to
79 > * {@link IElicitationField}. This catches an *incompatible reshape* of a field
80 > * we already project (e.g. the SDK retyping `enum` from `string[]` to
81 > * `number[]`) by failing to compile. It does NOT catch purely additive changes
82 > * — a brand-new union member or keyword stays structurally assignable to this
83 > * all-optional view and would be silently ignored by the projection until a
84 > * human notices the new shape. It is type-only: never called, erased at runtime.
85 > */
86 function _assertElicitationFieldCoversSchema(field: PrimitiveSchemaDefinition): IElicitationField {
87 return field;
88 }
90 > /**
91 > * Reshaped, validated view of the `form`-mode `requestedSchema`: the schema's
92 > * `properties` record flattened into ordered `[name, field]` tuples, plus its
93 > * `required` list as a set for O(1) per-field lookup during projection.
94 > */
95 > interface IParsedElicitationSchema {
96 > readonly fields: ReadonlyArray<readonly [string, IElicitationField]>;
97 > readonly required: ReadonlySet<string>;
98 > }
99 >
100 > /**
101 > * Narrow the untyped `requestedSchema` into an ordered list of runtime-validated
102 > * fields plus the required set. Fields that fail {@link vElicitationField}
103 > * validation are dropped. Returns `undefined` when the schema is absent or has no
104 > * usable `properties` object, so the caller can fall back to a message-only
105 > * request.
106 > */
107 function parseElicitationSchema(schema: unknown): IParsedElicitationSchema | undefined {
108 if (!isObject(schema)) {
124 return { fields, required };
125 }
127 > /**
128 > * Build the workbench {@link ChatInputRequest} for an MCP elicitation.
129 > *
130 > * - `url` mode surfaces the URL via {@link ChatInputRequest.url} with no
131 > * questions, driving the renderer's "open URL" affordance.
132 > * - `form` mode projects each field of the requested JSON schema into a
133 > * {@link ChatInputQuestion}. A missing/malformed schema falls back to a
134 > * message-only request so the user can still accept or decline.
135 > */
136 > export function buildElicitationRequest(requestId: string, request: ElicitationRequest): ChatInputRequest {
137 if (request.mode === 'url') {
138 const result: ChatInputRequest = { id: requestId, message: request.message };
149 return { id: requestId, message: request.message, questions };
150 }
152 > /**
153 > * Build the SDK {@link ElicitationResult} from the client's answers. A declined
154 > * request maps to `decline`, a cancelled/closed request to `cancel`, and an
155 > * accepted request to `accept` with a `content` object keyed by field name
156 > * (omitting skipped/missing answers). `url`-mode acceptances carry no content.
157 > */
158 > export function elicitationResultFromAnswers(
159 request: ElicitationRequest,
160 response: ChatInputResponseKind,
185 return { action: 'accept', content: Object.fromEntries(entries) };
186 }
188 > /** Cancel result used when there is no session to route the elicitation to. */
189 > export function cancelledElicitationResult(): ElicitationResult {
190 return { action: 'cancel' };
191 }
193 > /**
194 > * Project a single narrowed schema field into a {@link ChatInputQuestion}. The
195 > * schema's property key becomes the stable question id (the key the answer map
196 > * is later read back by). Unknown/missing types fall back to a plain text field.
197 > */
198 function elicitationFieldToQuestion(id: string, field: IElicitationField, required: boolean): ChatInputQuestion {
199 const base = { id, title: field.title ?? id, message: field.description ?? field.title ?? id, required };
256 }
257 }
259 > /**
260 > * Project a single {@link ChatInputAnswer} back into the raw value the SDK
261 > * expects for the given field, coercing to the field's declared type. This is
262 > * schema-aware because the workbench renders number/integer/boolean questions as
263 > * text inputs (no dedicated widget) and returns them as {@link ChatInputAnswer}
264 > * text values, so `"3"` / `"false"` must be coerced back to `3` / `false` to
265 > * satisfy the requested schema. Skipped/missing/uncoercible answers return
266 > * `undefined` so the caller omits them from the content object.
267 > */
268 function elicitationAnswerToValue(field: IElicitationField, answer: ChatInputAnswer | undefined): ElicitationFieldValue | undefined {
269 if (!answer || answer.state === ChatInputAnswerState.Skipped) {
src/vs/platform/agentHost/node/claude/claudeElicitationBridge.ts 36 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- claudeElicitationBridge.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 type { ElicitationRequest, ElicitationResult } from '@anthropic-ai/claude-agent-sdk';
7 > import { generateUuid } from '../../../../base/common/uuid.js';
8 > import { ChatInputResponseKind } from '../../common/state/sessionState.js';
9 > import { ClaudeAgentSession } from './claudeAgentSession.js';
10 > import { buildElicitationRequest, cancelledElicitationResult, elicitationResultFromAnswers } from './claudeElicitation.js';
11 >
12 > /**
13 > * Dependencies for {@link handleElicitation}. Kept narrow (just a session
14 > * lookup) so the agent's `_sessions` map stays private — mirrors
15 > * {@link import('./claudeCanUseTool.js').IClaudeCanUseToolDeps}. There is no
16 > * `configurationService` because elicitation has no unattended auto-cancel:
17 > * Claude always has a UI, and parked requests unwind on teardown.
18 > */
19 > export interface IClaudeElicitationDeps {
20 > readonly getSession: (sessionId: string) => ClaudeAgentSession | undefined;
21 > }
22 >
23 > /**
24 > * SDK `onElicitation` callback bridge. Fires a `ChatInputRequested` action and
25 > * parks on {@link ClaudeAgentSession.requestUserInput} until the
26 > * workbench dispatches a response, then maps it back to an
27 > * {@link ElicitationResult} for the MCP server.
28 > *
29 > * Routing note: elicitation is structured user input, so it flows through the
30 > * `requestUserInput` channel `AskUserQuestion` uses — NOT the
31 > * `pending_confirmation` permission gate.
32 > *
33 > * Result mapping: only an explicit user Decline returns `decline`; a missing
34 > * session, a pre-aborted request, and an SDK-aborted park all return `cancel`
35 > * (see phase 10.6 Decisions).
36 > */
37 export async function handleElicitation(
38 deps: IClaudeElicitationDeps,
src/vs/base/common/validation.ts 4 introduced LOC · 2 ranges

Open complete file

83
84 export function vUnchecked<T>(): ValidatorBase<T> {
85 > return new UncheckedValidator<T>(); validation.ts
86 > }
87
88 class UndefinedValidator extends ValidatorBase<undefined> {
105
106 export function vUnknown(): ValidatorBase<unknown> {
107 > return vUnchecked(); validation.ts
108 > }
109
110 export type ObjectProperties = Record<string, unknown>;