src/vs/platform/agentHost/node/claude/claudeElicitationBridge.ts

77 LOC · 77 covered · 0 uncovered · 12 ranges · 394 concepts · 9 introducers · 213 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- claudeElicitation.ts ×7
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( claudeElicitationBridge.ts ×3
38 > deps: IClaudeElicitationDeps,
39 > sessionId: string,
40 > request: ElicitationRequest,
41 > options: { readonly signal: AbortSignal },
42 > ): Promise<ElicitationResult> {
43 > const session = deps.getSession(sessionId);
44 > if (!session) {
45 > return cancelledElicitationResult(); claudeElicitationBridge.ts ×1
46 > }
48 > const requestId = generateUuid();
49 >
50 > if (options.signal.aborted) {
51 > return cancelledElicitationResult(); claudeElicitationBridge.ts ×1
52 > }
54 > // A request with neither a URL nor any questions can't be meaningfully
55 > // presented: a `url`-mode request missing its URL, or a `form` whose schema
56 > // yielded no representable fields. The workbench would inject a required
57 > // generic text question whose answer this translator then discards — falsely
58 > // reporting the elicitation as accepted. Cancel instead of surfacing it.
59 > const chatRequest = buildElicitationRequest(requestId, request);
60 > if (!chatRequest.url && !chatRequest.questions?.length) { claudeElicitationBridge.ts ×3
61 > return cancelledElicitationResult(); claudeElicitationBridge.ts ×1
62 > }
64 > // Observe the SDK's per-request abort signal so a host parked on
65 > // `requestUserInput` unwinds promptly when the SDK cancels the elicitation
66 > // (subprocess teardown, upstream abort). Mirrors `claudeCanUseTool.ts`.
67 > const abortHandler = () => {
68 > session.respondToUserInputRequest(requestId, ChatInputResponseKind.Cancel); claudeElicitationBridge.ts ×1
69 > };
70 > options.signal.addEventListener('abort', abortHandler); claudeElicitationBridge.ts ×2
71 > try {
72 > const { response, answers } = await session.requestUserInput(chatRequest);
73 > return elicitationResultFromAnswers(request, response, answers);
74 > } finally {
75 > options.signal.removeEventListener('abort', abortHandler);
76 > }