Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ClaudeModelCatalog.ts

609 lines22.6 KB

1import {
2 type CustomModelSetting,
3 type ModelCapabilities,
4 type ModelSelection,
5 ProviderDriverKind,
6 type ServerProviderModel,
7 type ServerProviderUpdateRequiredModel,
8} from "@t3tools/contracts";
9import type { ModelInfo as ClaudeModelInfo } from "@anthropic-ai/claude-agent-sdk";
10import * as Option from "effect/Option";
11import {
12 getModelSelectionStringOptionValue,
13 getProviderOptionCurrentValue,
14 getProviderOptionDescriptors,
15 readCustomModelEntries,
16} from "@t3tools/shared/model";
17import { compareSemverVersions } from "@t3tools/shared/semver";
18​
19import {
20 type ClaudeCodeCompatibility,
21 type ClaudeCodeProfile,
22 decodeClaudeModelAdapter,
23 decodeClaudeProfileAdapter,
24} from "./ClaudeModelManifest.ts";
25import * as ModelCatalog from "@t3tools/provider-core/server/ModelCatalog";
26import { BUNDLED_MODEL_MANIFEST, resolveProviderCatalog } from "./ModelManifest.ts";
27​
28const CLAUDE = ProviderDriverKind.make("claudeAgent");
29const EMPTY_CAPABILITIES: ModelCapabilities = { optionDescriptors: [] };
30​
31export interface ClaudeCatalogModel {
32 readonly model: ServerProviderModel;
33 readonly runtime: ClaudeCodeProfile;
34 readonly compatibility: ClaudeCodeCompatibility;
35 /** What to send Claude Code instead of the slug, from its own model list. */
36 readonly apiModel?: string;
38​
39export interface ClaudeModelCatalog {
40 readonly models: ReadonlyArray<ClaudeCatalogModel>;
42​
43function tryResolveClaudeModelCatalog(
44 resolved: ModelCatalog.ProviderCatalog | undefined,
45): ClaudeModelCatalog | null {
46 if (!resolved) return null;
47​
48 const models: Array<ClaudeCatalogModel> = [];
49 for (const entry of resolved.models) {
50 const profile = decodeClaudeProfileAdapter(entry.profileAdapter ?? {});
51 const adapter = decodeClaudeModelAdapter(entry.adapter ?? {});
52 if (Option.isNone(profile) || Option.isNone(adapter)) return null;
53 const model = ModelCatalog.catalogServerModel(resolved, entry);
54 models.push({
55 model: { ...model, capabilities: withUltracodeToggle(model.capabilities) },
56 runtime: profile.value.claudeCode ?? {},
57 compatibility: adapter.value.claudeCode ?? {},
58 });
59 }
60​
61 return {
62 models,
63 };
65​
66// The manifest keeps Ultracode as an effort level because released servers read it from main.
67export function withUltracodeToggle(
68 capabilities: ModelCapabilities | null,
69): ModelCapabilities | null {
70 const descriptors = capabilities?.optionDescriptors ?? [];
71 const effortIndex = descriptors.findIndex(
72 (descriptor) =>
73 descriptor.id === "effort" &&
74 descriptor.type === "select" &&
75 descriptor.options.some((option) => option.id === "ultracode"),
76 );
77 const effort = descriptors[effortIndex];
78 if (effort?.type !== "select") return capabilities;
79 const ultracodeByDefault =
80 (effort.currentValue ?? effort.options.find((option) => option.isDefault)?.id) === "ultracode";
81 const hasXhigh = effort.options.some((option) => option.id === "xhigh");
82 // Ultracode ran at xhigh, so a model that offered it keeps xhigh, and its default moves there.
83 const options = effort.options.flatMap(({ isDefault, ...option }) => {
84 if (option.id === "ultracode") {
85 return hasXhigh
86 ? []
87 : [{ id: "xhigh", label: "Extra High", ...(isDefault ? { isDefault } : {}) }];
88 }
89 if (ultracodeByDefault && option.id === "xhigh") return [{ ...option, isDefault: true }];
90 return [isDefault && !ultracodeByDefault ? { ...option, isDefault } : option];
91 });
92 return {
93 optionDescriptors: descriptors.toSpliced(
94 effortIndex,
95 1,
96 {
97 ...effort,
98 ...(effort.currentValue === "ultracode" ? { currentValue: "xhigh" } : {}),
99 options,
100 },
101 {
102 id: "ultracode",
103 label: "Ultracode",
104 type: "boolean",
105 ...(ultracodeByDefault ? { currentValue: true } : {}),
106 },
107 ),
108 };
110​
111/** Resolve the fallback on each read so its new-model badges can expire. */
112export function resolveClaudeModelCatalog(
113 catalog: ModelCatalog.ProviderCatalog | undefined,
114): ClaudeModelCatalog {
115 return (
116 tryResolveClaudeModelCatalog(catalog) ??
117 tryResolveClaudeModelCatalog(
118 resolveProviderCatalog(BUNDLED_MODEL_MANIFEST, CLAUDE) ?? undefined,
119 ) ?? {
120 models: [],
121 }
122 );
124​
125export const BUNDLED_CLAUDE_MODEL_CATALOG = resolveClaudeModelCatalog(undefined);
126​
127export function scopeClaudeModelCatalog(
128 catalog: ClaudeModelCatalog,
129 customModels: ReadonlyArray<CustomModelSetting>,
130): ClaudeModelCatalog {
131 const customEntries = readCustomModelEntries(customModels);
132 if (customEntries.length === 0) return catalog;
133 const customAliases = new Set(customEntries.map((entry) => entry.slug.toLowerCase()));
134​
135 const builtInModels = catalog.models.map((entry) => {
136 if (!entry.model.aliases?.some((alias) => customAliases.has(alias.toLowerCase()))) {
137 return entry;
138 }
139 return {
140 ...entry,
141 model: {
142 ...entry.model,
143 aliases: entry.model.aliases.filter((alias) => !customAliases.has(alias.toLowerCase())),
144 },
145 };
146 });
147 const builtInSlugs = new Set(builtInModels.map((entry) => entry.model.slug));
148 const customCatalogModels: Array<ClaudeCatalogModel> = [];
149 for (const entry of customEntries) {
150 if (!entry.capabilities || builtInSlugs.has(entry.slug)) continue;
151 customCatalogModels.push({
152 model: {
153 slug: entry.slug,
154 name: entry.name,
155 isCustom: true,
156 capabilities: withUltracodeToggle(entry.capabilities),
157 },
158 runtime: {},
159 compatibility: {},
160 });
161 }
162​
163 return { models: [...builtInModels, ...customCatalogModels] };
165​
166const CLAUDE_EFFORT_LABELS: Readonly<Record<string, string>> = {
167 low: "Low",
168 medium: "Medium",
169 high: "High",
170 xhigh: "Extra High",
171 max: "Max",
172};
173​
174function stripClaudeContextWindowSuffix(value: string): string {
175 return value.replace(/\[[^\]]*\]$/, "").trim();
177​
178export function claudeReportedModels(
179 catalog: ClaudeModelCatalog,
180 customModels: ReadonlyArray<CustomModelSetting>,
181 reported: ReadonlyArray<ClaudeModelInfo> | undefined,
182): ReadonlyArray<ServerProviderModel> {
183 if (!reported?.length) return [];
184 const known = new Set(
185 [
186 ...catalog.models.flatMap(({ model }) => [model.slug, ...(model.aliases ?? [])]),
187 ...readCustomModelEntries(customModels).map((entry) => entry.slug),
188 ].map((id) => stripClaudeContextWindowSuffix(id).toLowerCase()),
189 );
190 const models: Array<ServerProviderModel> = [];
191 for (const info of reported) {
192 const slug = info.value.trim();
193 // `default` is Claude Code's pointer at its own default model, not a model.
194 if (!slug || slug === "default") continue;
195 const ids = [slug, info.resolvedModel ?? ""]
196 .map((id) => stripClaudeContextWindowSuffix(id).toLowerCase())
197 .filter((id) => id.length > 0);
198 if (ids.some((id) => known.has(id))) continue;
199 for (const id of ids) known.add(id);
200 const efforts = info.supportsEffort ? (info.supportedEffortLevels ?? []) : [];
201 models.push({
202 slug,
203 name: info.displayName.trim() || slug,
204 isCustom: false,
205 capabilities: {
206 optionDescriptors: efforts.length
207 ? [
208 {
209 id: "effort",
210 label: "Reasoning",
211 type: "select",
212 // `default` is not an effort, so choosing it sends none and Claude Code picks.
213 options: [
214 { id: "default", label: "Default", isDefault: true },
215 ...efforts.map((id) => ({ id, label: CLAUDE_EFFORT_LABELS[id] ?? id })),
216 ],
217 },
218 ]
219 : [],
220 },
221 });
222 }
223 return models;
225​
226export function resolveClaudeCatalogModel(
227 catalog: ClaudeModelCatalog,
228 slugOrAlias: string | null | undefined,
229): ClaudeCatalogModel | undefined {
230 const value = slugOrAlias?.trim();
231 if (!value) return undefined;
232 return (
233 catalog.models.find((entry) => entry.model.slug === value) ??
234 catalog.models.find((entry) =>
235 entry.model.aliases?.some((alias) => alias.toLowerCase() === value.toLowerCase()),
236 )
237 );
239​
240// Cloud backends decorate first-party ids: Bedrock adds a region prefix and a
241// version ("us.anthropic.claude-opus-4-6-v1"), Vertex adds "@<date>".
242function stripClaudeBackendDecoration(wireModel: string): string {
243 return wireModel
244 .replace(/^(?:[a-z-]+\.)?anthropic\./, "")
245 .replace(/-v\d+(?::\d+)?$/, "")
246 .replace(/@[^@]*$/, "");
248​
249/**
250 * On Bedrock, Vertex and similar backends Claude Code does not accept the first-party slug: it
251 * either sends it verbatim or, when `availableModels` excludes it, silently runs the default
252 * model instead. Its model list names the id that does work, often a family alias that
253 * `ANTHROPIC_DEFAULT_*_MODEL` points at a backend id.
254 */
255export function withClaudeCodeModelRoutes(
256 catalog: ClaudeModelCatalog,
257 reportedModels: ReadonlyArray<Pick<ClaudeModelInfo, "value" | "resolvedModel">>,
258): ClaudeModelCatalog {
259 const apiModels = new Map<string, string>();
260 for (const reported of reportedModels) {
261 if (reported.value === "default") continue;
262 const wireModel = stripClaudeContextWindowSuffix(reported.resolvedModel ?? reported.value);
263 const firstPartyModel = stripClaudeBackendDecoration(wireModel);
264 if (firstPartyModel === wireModel) continue;
265 const entry = resolveClaudeCatalogModel(catalog, firstPartyModel);
266 if (!entry || apiModels.has(entry.model.slug)) continue;
267 apiModels.set(entry.model.slug, stripClaudeContextWindowSuffix(reported.value));
268 }
269 if (apiModels.size === 0) return catalog;
270 return {
271 models: catalog.models.map((entry) => {
272 const apiModel = apiModels.get(entry.model.slug);
273 return apiModel ? { ...entry, apiModel } : entry;
274 }),
275 };
277​
278export function resolveClaudeModelSlug(catalog: ClaudeModelCatalog, slugOrAlias: string): string {
279 return resolveClaudeCatalogModel(catalog, slugOrAlias)?.model.slug ?? slugOrAlias;
281​
282/** Claude reports dated IDs, such as `claude-opus-4-5-20251101`, that the catalog may not list. */
283export function resolveClaudeReportedModelSlug(
284 catalog: ClaudeModelCatalog,
285 reported: string,
286): string {
287 return (
288 (
289 resolveClaudeCatalogModel(catalog, reported) ??
290 resolveClaudeCatalogModel(catalog, reported.replace(/-\d{8}$/, ""))
291 )?.model.slug ?? reported
292 );
294​
295export function getClaudeCatalogModelCapabilities(
296 catalog: ClaudeModelCatalog,
297 slugOrAlias: string | null | undefined,
298): ModelCapabilities {
299 return resolveClaudeCatalogModel(catalog, slugOrAlias)?.model.capabilities ?? EMPTY_CAPABILITIES;
301​
302function isVersionSupported(
303 compatibility: ClaudeCodeCompatibility,
304 version: string | null | undefined,
305): boolean {
306 if (!compatibility.minVersion && !compatibility.maxVersionExclusive) return true;
307 if (!version) return false;
308 if (compatibility.minVersion && compareSemverVersions(version, compatibility.minVersion) < 0) {
309 return false;
310 }
311 return !(
312 compatibility.maxVersionExclusive &&
313 compareSemverVersions(version, compatibility.maxVersionExclusive) >= 0
314 );
316​
317export function resolveClaudeModelsForVersion(
318 catalog: ClaudeModelCatalog,
319 version: string | null | undefined,
320): ReadonlyArray<ClaudeCatalogModel["model"]> {
321 return catalog.models
322 .filter((entry) => isVersionSupported(entry.compatibility, version))
323 .map((entry) => entry.model);
325​
326export function resolveClaudeUpdateRequiredModels(
327 catalog: ClaudeModelCatalog,
328 version: string | null | undefined,
329): ReadonlyArray<ServerProviderUpdateRequiredModel> {
330 if (!version) return [];
331 return catalog.models.flatMap(({ model, compatibility }) => {
332 const minVersion = compatibility.minVersion;
333 if (model.isLegacy || !minVersion || compareSemverVersions(version, minVersion) >= 0) {
334 return [];
335 }
336 return [
337 {
338 slug: model.slug,
339 name: model.name,
340 ...(model.badge ? { badge: model.badge } : {}),
341 minVersion,
342 },
343 ];
344 });
346​
347// The two casks conflict, so moving to the faster channel means replacing the install.
348const HOMEBREW_STABLE_CASK_UPDATE_COMMAND = "brew upgrade --cask claude-code";
349const HOMEBREW_LATEST_CASK_SWITCH_COMMAND =
350 "brew uninstall --cask claude-code && brew install --cask claude-code@latest";
351​
352export function formatClaudeVersionUpgradeMessage(
353 catalog: ClaudeModelCatalog,
354 version: string | null,
355 channel?: { readonly latestVersion: string | null; readonly updateCommand: string | null },
356): string | undefined {
357 const unavailable = catalog.models
358 .filter(
359 (entry) =>
360 entry.compatibility.minVersion &&
361 (!version || compareSemverVersions(version, entry.compatibility.minVersion) < 0),
362 )
363 .toSorted((left, right) =>
364 compareSemverVersions(left.compatibility.minVersion!, right.compatibility.minVersion!),
365 )[0];
366 if (!unavailable?.compatibility.minVersion) return undefined;
367 const versionLabel = version ? `v${version}` : "the installed version";
368 const minVersion = unavailable.compatibility.minVersion;
369 const latestVersion = channel?.latestVersion;
370 if (latestVersion && compareSemverVersions(latestVersion, minVersion) < 0) {
371 const tooOld = `Claude Code ${versionLabel} is too old for ${unavailable.model.name}, which needs v${minVersion} or newer`;
372 if (channel?.updateCommand === HOMEBREW_STABLE_CASK_UPDATE_COMMAND) {
373 return `${tooOld}, but the claude-code Homebrew cask only has v${latestVersion}. Switch to the claude-code@latest cask: ${HOMEBREW_LATEST_CASK_SWITCH_COMMAND}`;
374 }
375 return `${tooOld}, but the newest version this install can update to is v${latestVersion}. Install Claude Code another way or wait for a newer release.`;
376 }
377 return `Claude Code ${versionLabel} is too old for ${unavailable.model.name}. Upgrade to v${minVersion} or newer to access it.`;
379​
380/** The status check words the upgrade before the install channel reports its newest version. */
381export function scopeClaudeUpgradeMessageToChannel<
382 P extends {
383 readonly message?: string | undefined;
384 readonly version: string | null;
385 readonly versionAdvisory?:
386 | { readonly latestVersion: string | null; readonly updateCommand: string | null }
387 | undefined;
388 },
389>(catalog: ClaudeModelCatalog, provider: P): P {
390 const channel = provider.versionAdvisory;
391 if (
392 !channel?.latestVersion ||
393 provider.message === undefined ||
394 provider.message !== formatClaudeVersionUpgradeMessage(catalog, provider.version)
395 ) {
396 return provider;
397 }
398 const message = formatClaudeVersionUpgradeMessage(catalog, provider.version, channel);
399 return message === undefined ? provider : { ...provider, message };
401​
402/** Claude Code's effort levels, lowest first. */
403export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
404export type ClaudeEffortLevel = (typeof CLAUDE_EFFORT_LEVELS)[number];
405​
406function claudeEffortRank(level: string | undefined): number {
407 return CLAUDE_EFFORT_LEVELS.indexOf(level as ClaudeEffortLevel);
409​
410/** One settings source's effort caps, with `modelSettings` keys as the user wrote them. */
411export interface ClaudeEffortCapSource {
412 readonly maxEffortLevel?: ClaudeEffortLevel;
413 readonly modelMaxEffortLevels?: ReadonlyMap<string, ClaudeEffortLevel>;
415​
416const CLAUDE_1M_SUFFIX = "[1m]";
417const CLAUDE_CODE_FAMILY_ALIASES: ReadonlySet<string> = new Set([
418 "opus",
419 "sonnet",
420 "haiku",
421 "fable",
422]);
423​
424/**
425 * Names the model a `modelSettings` key caps the way Claude Code does, which is narrower than the
426 * catalog's aliases: only a family alias (optionally `[1m]`) resolves as an alias, and any other key
427 * names the most specific model id it contains, so `claude-opus-5-5-20260101` and Bedrock ids match
428 * while `claude-opus-5.5` matches nothing.
429 */
430function resolveClaudeModelSettingsKey(
431 catalog: ClaudeModelCatalog,
432 key: string,
433): string | undefined {
434 const lowered = key.trim().toLowerCase();
435 const unsuffixed = lowered.endsWith(CLAUDE_1M_SUFFIX)
436 ? lowered.slice(0, -CLAUDE_1M_SUFFIX.length)
437 : lowered;
438 if (CLAUDE_CODE_FAMILY_ALIASES.has(unsuffixed)) {
439 return catalog.models.find(
440 (entry) => !entry.model.isCustom && entry.model.aliases?.includes(unsuffixed),
441 )?.model.slug;
442 }
443 let match: string | undefined;
444 for (const { model } of catalog.models) {
445 if (!model.isCustom && lowered.includes(model.slug) && model.slug.length > (match?.length ?? 0))
446 match = model.slug;
447 }
448 return match;
450​
451/** Keys `modelSettings` caps by canonical slug, keeping the lowest cap when several keys name one model. */
452function resolveClaudeModelMaxEffortLevels(
453 catalog: ClaudeModelCatalog,
454 levels: ReadonlyMap<string, ClaudeEffortLevel> | undefined,
455): ReadonlyMap<string, ClaudeEffortLevel> {
456 const resolved = new Map<string, ClaudeEffortLevel>();
457 for (const [key, level] of levels ?? []) {
458 const slug = resolveClaudeModelSettingsKey(catalog, key);
459 if (!slug) continue;
460 const current = resolved.get(slug);
461 if (!current || claudeEffortRank(level) < claudeEffortRank(current)) resolved.set(slug, level);
462 }
463 return resolved;
465​
466/**
467 * Claude Code clamps efforts above `maxEffortLevel` to the model's highest level under it, so
468 * such options are relabelled, not removed, keeping stored selections valid. Per-model caps
469 * replace their own source's top-level cap and `max` means none; across sources the lowest wins.
470 */
471export function capClaudeCatalogEffort(
472 catalog: ClaudeModelCatalog,
473 models: ReadonlyArray<ServerProviderModel>,
474 sources: ReadonlyArray<ClaudeEffortCapSource>,
475): ReadonlyArray<ServerProviderModel> {
476 if (sources.length === 0) return models;
477 const resolvedSources = sources.map((source) => ({
478 maxEffortLevel: source.maxEffortLevel,
479 modelMaxEffortLevels: resolveClaudeModelMaxEffortLevels(catalog, source.modelMaxEffortLevels),
480 }));
481 return models.map((model) => {
482 // Custom model labels are user-authored, so they are left alone.
483 if (model.isCustom || !model.capabilities?.optionDescriptors) return model;
484 const modelMaxEffortLevel = resolvedSources.reduce<ClaudeEffortLevel | undefined>(
485 (lowest, source) => {
486 const level = source.modelMaxEffortLevels.get(model.slug) ?? source.maxEffortLevel;
487 return level &&
488 level !== "max" &&
489 (!lowest || claudeEffortRank(level) < claudeEffortRank(lowest))
490 ? level
491 : lowest;
492 },
493 undefined,
494 );
495 if (!modelMaxEffortLevel) return model;
496 const capRank = claudeEffortRank(modelMaxEffortLevel);
497 return {
498 ...model,
499 capabilities: {
500 ...model.capabilities,
501 optionDescriptors: model.capabilities.optionDescriptors.map((descriptor) => {
502 if (descriptor.id !== "effort" || descriptor.type !== "select") return descriptor;
503 const cap = descriptor.options.reduce<{ rank: number; label: string } | undefined>(
504 (best, option) => {
505 const rank = claudeEffortRank(option.id);
506 return rank >= 0 && rank <= capRank && rank > (best?.rank ?? -1)
507 ? { rank, label: option.label }
508 : best;
509 },
510 undefined,
511 );
512 if (!cap) return descriptor;
513 return {
514 ...descriptor,
515 options: descriptor.options.map((option) => {
516 const idRank = claudeEffortRank(option.id);
517 const sentRank = claudeEffortRank(
518 normalizeClaudeCatalogEffort(catalog, option.id, model.slug),
519 );
520 const displayedRank = idRank >= 0 ? idRank : sentRank;
521 const runsRank = sentRank >= 0 ? sentRank : idRank;
522 return displayedRank > cap.rank && runsRank > cap.rank
523 ? { ...option, label: `${option.label} (capped to ${cap.label})` }
524 : option;
525 }),
526 };
527 }),
528 },
529 };
530 });
532​
533export function resolveClaudeCatalogEffort(
534 catalog: ClaudeModelCatalog,
535 model: string | null | undefined,
536 raw: string | null | undefined,
537): string | undefined {
538 if (!resolveClaudeCatalogModel(catalog, model)) {
539 const effort = raw?.trim();
540 return effort && (CLAUDE_EFFORT_LEVELS as ReadonlyArray<string>).includes(effort)
541 ? effort
542 : undefined;
543 }
544​
545 const caps = getClaudeCatalogModelCapabilities(catalog, model);
546 const descriptors = getProviderOptionDescriptors({
547 caps,
548 ...(raw ? { selections: [{ id: "effort", value: raw }] } : {}),
549 });
550 const descriptor = descriptors.find((candidate) => candidate.id === "effort");
551 const value = getProviderOptionCurrentValue(descriptor);
552 return typeof value === "string" ? value : undefined;
554​
555export function normalizeClaudeCatalogEffort(
556 catalog: ClaudeModelCatalog,
557 effort: string | null | undefined,
558 model: string | null | undefined,
559): string | undefined {
560 if (!effort) return undefined;
561 const effortMap = resolveClaudeCatalogModel(catalog, model)?.runtime.effortMap;
562 if (!effortMap || !Object.prototype.hasOwnProperty.call(effortMap, effort)) return effort;
563 return effortMap[effort] ?? undefined;
565​
566function resolveClaudeCatalogContextWindow(
567 catalog: ClaudeModelCatalog,
568 modelSelection: ModelSelection | undefined,
569): string | undefined {
570 const caps = getClaudeCatalogModelCapabilities(catalog, modelSelection?.model);
571 const raw = getModelSelectionStringOptionValue(modelSelection, "contextWindow");
572 const descriptors = getProviderOptionDescriptors({
573 caps,
574 ...(raw ? { selections: [{ id: "contextWindow", value: raw }] } : {}),
575 });
576 const descriptor = descriptors.find((candidate) => candidate.id === "contextWindow");
577 const value = getProviderOptionCurrentValue(descriptor);
578 return typeof value === "string" ? value : undefined;
580​
581export function resolveClaudeCatalogApiModelId(
582 catalog: ClaudeModelCatalog,
583 modelSelection: ModelSelection,
584): string {
585 const entry = resolveClaudeCatalogModel(catalog, modelSelection.model);
586 const slug = entry?.apiModel ?? entry?.model.slug ?? modelSelection.model;
587 const descriptors = getProviderOptionDescriptors({
588 caps: entry?.model.capabilities ?? EMPTY_CAPABILITIES,
589 selections: modelSelection.options,
590 });
591 for (const [optionId, suffixes] of Object.entries(entry?.runtime.modelSuffixes ?? {})) {
592 const value = getProviderOptionCurrentValue(
593 descriptors.find((descriptor) => descriptor.id === optionId),
594 );
595 if (typeof value === "string" && suffixes[value]) return `${slug}${suffixes[value]}`;
596 }
597 return slug;
599​
600export function resolveClaudeCatalogContextWindowTokens(
601 catalog: ClaudeModelCatalog,
602 modelSelection: ModelSelection | undefined,
603): number | undefined {
604 const entry = resolveClaudeCatalogModel(catalog, modelSelection?.model);
605 if (!entry) return undefined;
606 if (entry.runtime.fixedContextWindowTokens) return entry.runtime.fixedContextWindowTokens;
607 const contextWindow = resolveClaudeCatalogContextWindow(catalog, modelSelection);
608 return contextWindow ? entry.runtime.contextWindowTokens?.[contextWindow] : undefined;