1
>
/*---------------------------------------------------------------------------------------------
claudeModelId.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
>
/**
7
>
* Mirror of `extensions/copilot/src/extension/chatSessions/claude/{common,node}/claudeModelId.ts`.
8
>
*
9
>
* The Claude Agent SDK speaks Anthropic-canonical hyphenated model IDs
10
>
* (e.g. `claude-opus-4-6-20251101`). CAPI speaks dotted endpoint IDs
11
>
* (`claude-opus-4.6`). The Phase 2 proxy needs bidirectional translation
12
>
* at three points: inbound `requestBody.model` (SDK→CAPI), outbound
13
>
* `model` fields on streaming events / non-streaming responses (CAPI→SDK),
14
>
* and `GET /v1/models` response IDs (CAPI→SDK).
15
>
*
16
>
* **Keep in sync with the extension copy.** When the model-ID grammar
17
>
* changes (new family name, new modifier suffix), update both files.
18
>
*/
19
>
20
>
export interface ParsedClaudeModelId {
21
>
readonly name: string;
22
>
readonly version: string;
23
>
readonly modifiers: string;
24
>
toSdkModelId(): string;
25
>
toEndpointModelId(): string;
26
>
}
27
>
28
>
/**
29
>
* Known model suffixes that are meaningful variants and should be preserved
30
>
* in SDK/endpoint model IDs. Mapped per model family. Date-based suffixes
31
>
* (e.g. 20251101) are intentionally excluded — they are build identifiers
32
>
* that should not appear in the normalized output.
33
>
*/
34
>
const VALID_SUFFIXES: ReadonlyMap<string, ReadonlySet<string>> = new Map([
35
>
['opus', new Set(['1m'])],
36
>
]);
37
>
38
>
const cache = new Map<string, ParsedClaudeModelId | undefined>();
39
>
40
>
/**
41
>
* Parses a Claude model ID string (SDK or endpoint format) into its components.
42
>
* Throws if the model ID is unparseable or not a Claude ID.
43
>
*
44
>
* Use {@link tryParseClaudeModelId} when the input may not be a valid Claude model ID
45
>
* (e.g. model IDs from disk or external sources).
46
>
*/
47
>
export function parseClaudeModelId(modelId: string): ParsedClaudeModelId {
48
const result = tryParseClaudeModelId(modelId);
49
if (!result) {