src/vs/platform/agentHost/common/claudeModelConfig.ts

128 LOC · 128 covered · 0 uncovered · 14 ranges · 385 concepts · 8 introducers · 218 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 > /*--------------------------------------------------------------------------------------------- claudeModelConfig.ts ×4
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 { localize } from '../../../nls.js';
7 > import { getReasoningEffortDescription, getReasoningEffortLabel } from './reasoningEffort.js';
8 > import type { ConfigSchema, ModelSelection } from './state/protocol/state.js';
9 >
10 > /**
11 > * Sub-key in `ModelSelection.config` carrying the user's reasoning-effort
12 > * pick from the model picker. Mirror of CopilotAgent's
13 > * `ThinkingLevelConfigKey` (copilotAgent.ts:83) so a single picker contract
14 > * spans both providers — the picker writes `model.config.thinkingLevel`,
15 > * and each provider narrows that string at materialize.
16 > */
17 > export const CLAUDE_THINKING_LEVEL_KEY = 'thinkingLevel';
18 >
19 > /**
20 > * Reasoning-effort values accepted by the Claude SDK's `Options.effort`
21 > * (startup). Hand-rolled here — not imported from the SDK — to keep `common/`
22 > * SDK-free; structurally identical to the SDK's exported `EffortLevel` so it
23 > * assigns into `Options.effort` without a cast.
24 > */
25 > export type ClaudeEffortLevel = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
26 >
27 > /**
28 > * The effort union the SDK's runtime hot-swap setter
29 > * `Query.applyFlagSettings({ effortLevel })` is *declared* to accept. Note it
30 > * excludes `'max'` — but see {@link toRuntimeEffortLevel}: a `'max'` value can
31 > * still flow through this type at runtime, because the SDK's declared type is
32 > * narrower than what the API actually accepts.
33 > */
34 > export type ClaudeRuntimeEffortLevel = 'low' | 'medium' | 'high' | 'xhigh';
35 >
36 > /**
37 > * Coerce a startup {@link ClaudeEffortLevel} to the {@link ClaudeRuntimeEffortLevel}
38 > * union the SDK's `applyFlagSettings({ effortLevel })` setter is typed to accept.
39 > *
40 > * This used to clamp `'max'` down to `'xhigh'`, because the SDK's
41 > * `Settings.effortLevel` .d.ts type omits `'max'`. That type is wrong: the
42 > * Anthropic API / Copilot CAPI accept `'max'` end-to-end — confirmed with
43 > * Anthropic, and verified by watching a `'max'` turn round-trip successfully
44 > * (the exported `EffortLevel` union and the wire `output_config.effort` field
45 > * both include `'max'`). So `'max'` is now passed straight through.
46 > *
47 > * The cast is deliberate: this returns a value its own return type says it
48 > * cannot — `'max'` is not a member of {@link ClaudeRuntimeEffortLevel}. Keeping
49 > * the narrow return type lets every downstream consumer stay honest against the
50 > * SDK's declared surface while the single lie lives here. Drop the cast (and
51 > * widen the return type, or restore a real clamp) once the SDK's
52 > * `Settings.effortLevel` type is corrected upstream
53 > * (anthropics/claude-agent-sdk-typescript#377).
54 > */
55 > export function toRuntimeEffortLevel(effort: ClaudeEffortLevel | undefined): ClaudeRuntimeEffortLevel | undefined {
56 > return effort as ClaudeRuntimeEffortLevel | undefined; claudeModelConfig.ts ×1
57 > }
59 > /**
60 > * Pull `thinkingLevel` out of `ModelSelection.config` and narrow it to
61 > * {@link ClaudeEffortLevel}. Returns `undefined` when the model selection
62 > * is absent or carries an unrecognized value (the SDK then falls through
63 > * to its own default). Mirror of CopilotAgent's `_getReasoningEffort`
64 > * (copilotAgent.ts:487).
65 > */
66 > export function resolveClaudeEffort(model: ModelSelection | undefined): ClaudeEffortLevel | undefined {
67 > const raw = model?.config?.[CLAUDE_THINKING_LEVEL_KEY]; claudeModelConfig.ts ×3
68 > switch (raw) {
69 > case 'low':
70 > case 'medium':
71 > case 'high':
72 > case 'xhigh':
73 > case 'max':
74 > return raw; claudeModelConfig.ts ×1
75 > default: claudeModelConfig.ts ×3
76 > return undefined; claudeModelConfig.ts ×1
78 > }
80 > /** Canonical ordered list of {@link ClaudeEffortLevel} values; used for sort + guard. */
81 > const CLAUDE_EFFORT_LEVELS: readonly ClaudeEffortLevel[] = ['low', 'medium', 'high', 'xhigh', 'max'];
82 >
83 > /** Type guard narrowing an arbitrary string to {@link ClaudeEffortLevel}. */
84 > export function isClaudeEffortLevel(value: string): value is ClaudeEffortLevel {
85 > return (CLAUDE_EFFORT_LEVELS as readonly string[]).includes(value); claudeModelConfig.ts ×1
86 > }
88 > /**
89 > * Synthesize the per-model `configSchema` advertising the `thinkingLevel`
90 > * picker entry on Claude models that support adaptive thinking. Mirror of
91 > * CopilotAgent's `_createThinkingLevelConfigSchema` (copilotAgent.ts:457).
92 > *
93 > * The `enum` is sourced from each model's own `reasoning_effort` list (a
94 > * runtime field on CAPI's `/models` payload — different Claude models
95 > * support different effort subsets, e.g. `['low','medium','high']`,
96 > * `['high']`, or `[]`). Callers narrow that list to {@link ClaudeEffortLevel}
97 > * via {@link isClaudeEffortLevel} before passing it in.
98 > *
99 > * The `default` is `'high'` when the model supports it, otherwise omitted
100 > * — Claude's own server-side default for adaptive thinking is `'high'`,
101 > * and the extension mirrors the same fallback rule at
102 > * `extensions/copilot/src/extension/chatSessions/claude/node/claudeCodeModels.ts:230`.
103 > * (Anthropic's `CCAModel` rows don't carry a server-supplied default
104 > * field; tracked at microsoft/vscode-capi#85.)
105 > *
106 > * Returns `undefined` for an empty list — the picker then renders no
107 > * thinkingLevel control for that model.
108 > */
109 > export function createClaudeThinkingLevelSchema(supportedEfforts: readonly ClaudeEffortLevel[]): ConfigSchema | undefined {
110 > if (supportedEfforts.length === 0) { claudeModelConfig.ts ×2
111 > return undefined; claudeModelConfig.ts ×1
112 > }
113 > const defaultEffort: ClaudeEffortLevel | undefined = supportedEfforts.includes('high') ? 'high' : undefined; claudeModelConfig.ts ×2
114 > return {
115 > type: 'object',
116 > properties: {
117 > [CLAUDE_THINKING_LEVEL_KEY]: {
118 > type: 'string',
119 > title: localize('claude.modelThinkingLevel.title', "Thinking Level"),
120 > description: localize('claude.modelThinkingLevel.description', "Controls how much reasoning effort Claude uses."),
121 > enum: [...supportedEfforts],
122 > enumLabels: supportedEfforts.map(getReasoningEffortLabel),
123 > enumDescriptions: supportedEfforts.map(effort => getReasoningEffortDescription(effort) ?? ''),
124 > ...(defaultEffort !== undefined ? { default: defaultEffort } : {}),
125 > },
126 > },
127 > };
128 > }