Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2import { type ModelSelection, ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
3
4import { resolveProviderCatalog, type ModelManifestData } from "./ModelManifest.ts";
5import {
6 BUNDLED_CLAUDE_MODEL_CATALOG,
7 capClaudeCatalogEffort,
8 type ClaudeModelCatalog,
9 formatClaudeVersionUpgradeMessage,
10 getClaudeCatalogModelCapabilities,
11 normalizeClaudeCatalogEffort,
12 resolveClaudeCatalogApiModelId,
13 resolveClaudeCatalogContextWindowTokens,
14 resolveClaudeCatalogEffort,
15 resolveClaudeModelCatalog,
16 resolveClaudeModelsForVersion,
17 resolveClaudeModelSlug,
18 resolveClaudeUpdateRequiredModels,
19 scopeClaudeModelCatalog,
20 scopeClaudeUpgradeMessageToChannel,
21 withClaudeCodeModelRoutes,
22} from "./ClaudeModelCatalog.ts";
23
24const manifest = (): ModelManifestData => ({
25 version: 1,
26 currentModels: {},
27 providers: {
28 claudeAgent: {
29 profiles: {
30 synthetic: {
31 capabilities: {
32 optionDescriptors: [
33 {
34 id: "effort",
35 label: "Reasoning",
36 type: "select",
37 options: [{ id: "extreme", label: "Extreme", isDefault: true }],
38 },
39 {
40 id: "contextWindow",
41 label: "Context Window",
42 type: "select",
43 options: [
44 { id: "large", label: "Large", isDefault: true },
45 { id: "small", label: "Small" },
46 ],
47 },
48 ],
49 },
50 adapter: {
51 claudeCode: {
52 effortMap: { extreme: "high" },
53 modelSuffixes: { contextWindow: { large: "[large]" } },
54 },
55 },
56 },
57 },
58 models: [
59 {
60 slug: "claude-synthetic-next",
61 name: "Claude Synthetic Next",
62 aliases: ["synthetic"],
63 status: "current",
64 profile: "synthetic",
65 adapter: { claudeCode: { minVersion: "3.2.0" } },
66 },
67 ],
68 },
69 },
70});
71
72const CLAUDE = ProviderDriverKind.make("claudeAgent");
73
74const catalogFromManifest = (data: ModelManifestData) =>
75 resolveClaudeModelCatalog(resolveProviderCatalog(data, CLAUDE) ?? undefined);
76
77describe("Claude model catalog", () => {
78 it("resolves capacity from selected options and fixed catalog windows without guessing custom models", () => {
79 const source = manifest();
80 const profile = source.providers!.claudeAgent!.profiles.synthetic!;
81 const catalog = catalogFromManifest({
82 ...source,
83 providers: {
84 claudeAgent: {
85 ...source.providers!.claudeAgent!,
86 profiles: {
87 fixed: {
88 capabilities: { optionDescriptors: [] },
89 adapter: { claudeCode: { fixedContextWindowTokens: 64_000 } },
90 },
91 synthetic: {
92 ...profile,
93 adapter: { claudeCode: { contextWindowTokens: { large: 1_000_000, small: 32_000 } } },
94 },
95 },
96 models: [
97 ...source.providers!.claudeAgent!.models,
98 {
99 slug: "fixed",
100 name: "Fixed",
101 status: "current",
102 profile: "fixed",
103 },
104 ],
105 },
106 },
107 });
108 const selection = { instanceId: ProviderInstanceId.make("claudeAgent"), model: "synthetic" };
109 assert.equal(resolveClaudeCatalogContextWindowTokens(catalog, selection), 1_000_000);
110 assert.equal(
111 resolveClaudeCatalogContextWindowTokens(catalog, {
112 ...selection,
113 options: [{ id: "contextWindow", value: "small" }],
114 }),
115 32_000,
116 );
117 assert.equal(
118 resolveClaudeCatalogContextWindowTokens(catalog, { ...selection, model: "fixed" }),
119 64_000,
120 );
121 assert.isUndefined(
122 resolveClaudeCatalogContextWindowTokens(catalog, { ...selection, model: "custom" }),
123 );
124 });
125
126 it("filters models at runtime-version boundaries and derives the upgrade message", () => {
127 const catalog = catalogFromManifest(manifest());
128 assert.deepStrictEqual(resolveClaudeModelsForVersion(catalog, "3.1.9"), []);
129 assert.deepStrictEqual(
130 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
131 ["claude-synthetic-next"],
132 );
133 assert.deepStrictEqual(resolveClaudeUpdateRequiredModels(catalog, "3.1.9"), [
134 { slug: "claude-synthetic-next", name: "Claude Synthetic Next", minVersion: "3.2.0" },
135 ]);
136 assert.deepStrictEqual(resolveClaudeUpdateRequiredModels(catalog, "3.2.0"), []);
137 assert.strictEqual(
138 formatClaudeVersionUpgradeMessage(catalog, "3.1.9"),
139 "Claude Code v3.1.9 is too old for Claude Synthetic Next. Upgrade to v3.2.0 or newer to access it.",
140 );
141 // A Homebrew cask that still ships 3.1.9 cannot deliver the upgrade the check asked for.
142 const probed = {
143 version: "3.1.9",
144 message: formatClaudeVersionUpgradeMessage(catalog, "3.1.9"),
145 versionAdvisory: { latestVersion: "3.1.9", updateCommand: "brew upgrade --cask claude-code" },
146 };
147 assert.strictEqual(
148 scopeClaudeUpgradeMessageToChannel(catalog, probed).message,
149 "Claude Code v3.1.9 is too old for Claude Synthetic Next, which needs v3.2.0 or newer, but the claude-code Homebrew cask only has v3.1.9. Switch to the claude-code@latest cask: brew uninstall --cask claude-code && brew install --cask claude-code@latest",
150 );
151 assert.strictEqual(
152 scopeClaudeUpgradeMessageToChannel(catalog, {
153 ...probed,
154 versionAdvisory: { latestVersion: "3.1.9", updateCommand: null },
155 }).message,
156 "Claude Code v3.1.9 is too old for Claude Synthetic Next, which needs v3.2.0 or newer, but the newest version this install can update to is v3.1.9. Install Claude Code another way or wait for a newer release.",
157 );
158 assert.strictEqual(
159 scopeClaudeUpgradeMessageToChannel(catalog, {
160 ...probed,
161 versionAdvisory: { ...probed.versionAdvisory, latestVersion: "3.2.0" },
162 }).message,
163 probed.message,
164 );
165 // Claude Code before 2.1.321 does not know claude-fable-5-2 and runs it with a 200K window.
166 assert.notInclude(
167 resolveClaudeModelsForVersion(BUNDLED_CLAUDE_MODEL_CATALOG, "2.1.320").map(
168 (model) => model.slug,
169 ),
170 "claude-fable-5-2",
171 );
172 });
173
174 it("resolves aliases and declarative adapter mappings", () => {
175 const base = manifest();
176 const input: ModelManifestData = {
177 ...base,
178 providers: {
179 ...base.providers,
180 claudeAgent: {
181 ...base.providers!.claudeAgent!,
182 models: [
183 {
184 slug: "claude-synthetic-collision",
185 name: "Claude Synthetic Collision",
186 aliases: ["claude-synthetic-next"],
187 status: "current",
188 },
189 ...base.providers!.claudeAgent!.models,
190 ],
191 },
192 },
193 };
194 const catalog = catalogFromManifest(input);
195 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "claude-synthetic-next");
196 assert.strictEqual(
197 resolveClaudeModelSlug(catalog, "claude-synthetic-next"),
198 "claude-synthetic-next",
199 );
200 assert.strictEqual(normalizeClaudeCatalogEffort(catalog, "extreme", "synthetic"), "high");
201 assert.strictEqual(
202 resolveClaudeCatalogApiModelId(catalog, {
203 instanceId: ProviderInstanceId.make("claudeAgent"),
204 model: "synthetic",
205 }),
206 "claude-synthetic-next[large]",
207 );
208 });
209
210 it("appends custom models with their own descriptors and keeps bare slugs opaque", () => {
211 const catalog = scopeClaudeModelCatalog(catalogFromManifest(manifest()), [
212 "synthetic",
213 {
214 slug: "claude-custom-tuned",
215 name: "Tuned",
216 capabilities: {
217 optionDescriptors: [
218 {
219 id: "effort",
220 label: "Reasoning",
221 type: "select",
222 options: [
223 { id: "gentle", label: "Gentle", isDefault: true },
224 { id: "brutal", label: "Brutal" },
225 { id: "ultracode", label: "Ultracode" },
226 ],
227 },
228 ],
229 },
230 },
231 ]);
232
233 assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "synthetic");
234 assert.isUndefined(resolveClaudeCatalogEffort(catalog, "synthetic", "extreme"));
235 assert.strictEqual(resolveClaudeCatalogEffort(catalog, "synthetic", "max"), "max");
236 assert.strictEqual(normalizeClaudeCatalogEffort(catalog, "max", "synthetic"), "max");
237
238 assert.strictEqual(
239 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "brutal"),
240 "brutal",
241 );
242 assert.strictEqual(
243 resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "bogus"),
244 "gentle",
245 );
246 assert.deepStrictEqual(
247 getClaudeCatalogModelCapabilities(catalog, "claude-custom-tuned").optionDescriptors?.map(
248 ({ id, type }) => `${id}:${type}`,
249 ),
250 ["effort:select", "ultracode:boolean"],
251 );
252 assert.strictEqual(
253 normalizeClaudeCatalogEffort(catalog, "brutal", "claude-custom-tuned"),
254 "brutal",
255 );
256 assert.strictEqual(
257 resolveClaudeCatalogApiModelId(catalog, {
258 instanceId: ProviderInstanceId.make("claudeAgent"),
259 model: "claude-custom-tuned",
260 options: [{ id: "effort", value: "brutal" }],
261 }),
262 "claude-custom-tuned",
263 );
264 assert.deepStrictEqual(
265 resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
266 ["claude-synthetic-next", "claude-custom-tuned"],
267 );
268 });
269
270 // Rows Claude Code 2.1.310 reports from initialization for each configuration.
271 it("sends the model id Claude Code reports when it serves a catalog model under another id", () => {
272 const apiModel = (
273 catalog: ClaudeModelCatalog,
274 model: string,
275 options?: ModelSelection["options"],
276 ) =>
277 resolveClaudeCatalogApiModelId(catalog, {
278 instanceId: ProviderInstanceId.make("claudeAgent"),
279 model,
280 ...(options ? { options } : {}),
281 });
282
283 // Bedrock with ANTHROPIC_DEFAULT_*_MODEL and an availableModels allowlist of their ids.
284 const configuredBedrock = withClaudeCodeModelRoutes(BUNDLED_CLAUDE_MODEL_CATALOG, [
285 { value: "default", resolvedModel: "global.anthropic.claude-opus-5-5" },
286 { value: "sonnet", resolvedModel: "global.anthropic.claude-sonnet-5-5[1m]" },
287 { value: "opus", resolvedModel: "global.anthropic.claude-opus-5-5" },
288 { value: "haiku", resolvedModel: "global.anthropic.claude-haiku-5-5" },
289 ]);
290 assert.strictEqual(apiModel(configuredBedrock, "claude-haiku-5-5"), "haiku");
291 assert.strictEqual(apiModel(configuredBedrock, "haiku-5.5"), "haiku");
292 assert.strictEqual(apiModel(configuredBedrock, "claude-sonnet-5-5"), "sonnet");
293 assert.strictEqual(apiModel(configuredBedrock, "claude-opus-5-5"), "opus");
294 assert.strictEqual(apiModel(configuredBedrock, "claude-opus-5"), "claude-opus-5");
295
296 // Bedrock with no model settings: Claude Code's `haiku` is Haiku 4.5 there.
297 const defaultBedrock = withClaudeCodeModelRoutes(BUNDLED_CLAUDE_MODEL_CATALOG, [
298 {
299 value: "us.anthropic.claude-opus-4-6-v1",
300 resolvedModel: "us.anthropic.claude-opus-4-6-v1",
301 },
302 {
303 value: "us.anthropic.claude-opus-4-6-v1[1m]",
304 resolvedModel: "us.anthropic.claude-opus-4-6-v1[1m]",
305 },
306 { value: "haiku", resolvedModel: "us.anthropic.claude-haiku-4-5-20251001-v1:0" },
307 ]);
308 assert.strictEqual(
309 apiModel(defaultBedrock, "claude-opus-4-6", [{ id: "contextWindow", value: "1m" }]),
310 "us.anthropic.claude-opus-4-6-v1[1m]",
311 );
312 assert.strictEqual(
313 apiModel(defaultBedrock, "claude-opus-4-6", [{ id: "contextWindow", value: "200k" }]),
314 "us.anthropic.claude-opus-4-6-v1",
315 );
316 assert.strictEqual(apiModel(defaultBedrock, "claude-haiku-4-5"), "haiku");
317 assert.strictEqual(apiModel(defaultBedrock, "claude-haiku-5-5"), "claude-haiku-5-5");
318
319 // First-party ids already are what Claude Code runs, even when an alias points elsewhere.
320 const firstParty = withClaudeCodeModelRoutes(BUNDLED_CLAUDE_MODEL_CATALOG, [
321 { value: "default", resolvedModel: "claude-opus-5-5" },
322 { value: "opus", resolvedModel: "claude-opus-5-5" },
323 { value: "claude-fable-5-1[1m]", resolvedModel: "claude-fable-5-1[1m]" },
324 { value: "haiku", resolvedModel: "claude-haiku-4-5-20251001" },
325 ]);
326 assert.strictEqual(firstParty, BUNDLED_CLAUDE_MODEL_CATALOG);
327 });
328
329 it("marks effort options that would run above the cap without changing ids or defaults", () => {
330 const effortModel = (slug: string) => ({
331 slug,
332 name: slug,
333 isCustom: false,
334 capabilities: {
335 optionDescriptors: [
336 {
337 id: "effort",
338 label: "Reasoning",
339 type: "select" as const,
340 options: [
341 { id: "medium", label: "Medium" },
342 { id: "high", label: "High", isDefault: true },
343 { id: "xhigh", label: "Extra High" },
344 { id: "max", label: "Max" },
345 { id: "ultracode", label: "Ultracode" },
346 { id: "ultrathink", label: "Ultrathink" },
347 ],
348 },
349 ],
350 },
351 });
352 const models = [effortModel("claude-plain"), effortModel("claude-remapped")];
353 const catalog: ClaudeModelCatalog = {
354 models: [
355 {
356 model: models[0]!,
357 runtime: { effortMap: { ultracode: "xhigh", ultrathink: null } },
358 compatibility: {},
359 },
360 {
361 model: models[1]!,
362 runtime: { effortMap: { max: "high", xhigh: "max", ultrathink: null } },
363 compatibility: {},
364 },
365 ],
366 };
367 const options = (cap: "high" | "xhigh") =>
368 capClaudeCatalogEffort(catalog, models, [{ maxEffortLevel: cap }]).map((model) => {
369 const effort = model.capabilities?.optionDescriptors?.[0];
370 return effort?.type === "select" ? effort.options : undefined;
371 });
372
373 assert.deepStrictEqual(options("high"), [
374 [
375 { id: "medium", label: "Medium" },
376 { id: "high", label: "High", isDefault: true },
377 { id: "xhigh", label: "Extra High (capped to High)" },
378 { id: "max", label: "Max (capped to High)" },
379 { id: "ultracode", label: "Ultracode (capped to High)" },
380 { id: "ultrathink", label: "Ultrathink" },
381 ],
382 [
383 { id: "medium", label: "Medium" },
384 { id: "high", label: "High", isDefault: true },
385 { id: "xhigh", label: "Extra High (capped to High)" },
386 { id: "max", label: "Max" },
387 { id: "ultracode", label: "Ultracode" },
388 { id: "ultrathink", label: "Ultrathink" },
389 ],
390 ]);
391 // An effortMap that sends Extra High as max stays unmarked under an xhigh cap: the CLI runs
392 // it at xhigh, which is what the label says.
393 assert.deepStrictEqual(
394 options("xhigh").map((model) => model?.map((option) => option.label)),
395 [
396 ["Medium", "High", "Extra High", "Max (capped to Extra High)", "Ultracode", "Ultrathink"],
397 ["Medium", "High", "Extra High", "Max", "Ultracode", "Ultrathink"],
398 ],
399 );
400
401 // A per-model cap applies without a top-level one and leaves other models uncapped.
402 assert.deepStrictEqual(
403 capClaudeCatalogEffort(catalog, models, [
404 { modelMaxEffortLevels: new Map([["claude-plain", "high"]]) },
405 ]).map((model) => {
406 const effort = model.capabilities?.optionDescriptors?.[0];
407 return effort?.type === "select" ? effort.options.map((option) => option.label) : [];
408 }),
409 [
410 [
411 "Medium",
412 "High",
413 "Extra High (capped to High)",
414 "Max (capped to High)",
415 "Ultracode (capped to High)",
416 "Ultrathink",
417 ],
418 ["Medium", "High", "Extra High", "Max", "Ultracode", "Ultrathink"],
419 ],
420 );
421
422 // Without an Extra High option (Opus 4.6), the CLI clamps an xhigh cap down to High.
423 const noXhigh = {
424 slug: "claude-no-xhigh",
425 name: "claude-no-xhigh",
426 isCustom: false,
427 capabilities: {
428 optionDescriptors: [
429 {
430 id: "effort",
431 label: "Reasoning",
432 type: "select" as const,
433 options: [
434 { id: "low", label: "Low" },
435 { id: "medium", label: "Medium" },
436 { id: "high", label: "High", isDefault: true },
437 { id: "max", label: "Max" },
438 ],
439 },
440 ],
441 },
442 };
443 const [capped] = capClaudeCatalogEffort(
444 { models: [] },
445 [noXhigh],
446 [{ maxEffortLevel: "xhigh" }],
447 );
448 const cappedEffort = capped?.capabilities?.optionDescriptors?.[0];
449 assert.deepStrictEqual(
450 cappedEffort?.type === "select" ? cappedEffort.options.map((option) => option.label) : [],
451 ["Low", "Medium", "High", "Max (capped to High)"],
452 );
453 });
454
455 it("leaves custom model effort labels alone under a cap", () => {
456 const custom = {
457 slug: "claude-custom-copy",
458 name: "Copy",
459 isCustom: true,
460 capabilities: {
461 optionDescriptors: [
462 {
463 id: "effort",
464 label: "Reasoning",
465 type: "select" as const,
466 options: [
467 { id: "high", label: "High", isDefault: true },
468 { id: "max", label: "Max (capped to High)" },
469 ],
470 },
471 ],
472 },
473 };
474
475 assert.deepStrictEqual(
476 capClaudeCatalogEffort({ models: [] }, [custom], [{ maxEffortLevel: "high" }]),
477 [custom],
478 );
479 });
480
481 it("resolves maxEffortLevel per settings source and per model key like Claude Code", () => {
482 const opus = {
483 slug: "claude-opus-5-5",
484 name: "Opus 5.5",
485 isCustom: false,
486 aliases: ["opus", "opus-5.5", "claude-opus-5.5"],
487 capabilities: {
488 optionDescriptors: [
489 {
490 id: "effort",
491 label: "Reasoning",
492 type: "select" as const,
493 options: [
494 { id: "low", label: "Low" },
495 { id: "medium", label: "Medium" },
496 { id: "high", label: "High", isDefault: true },
497 { id: "max", label: "Max" },
498 ],
499 },
500 ],
501 },
502 };
503 const catalog: ClaudeModelCatalog = {
504 models: [
505 { model: opus, runtime: {}, compatibility: {} },
506 {
507 model: {
508 slug: "claude-opus-5",
509 name: "Opus 5",
510 isCustom: false,
511 capabilities: { optionDescriptors: [] },
512 },
513 runtime: {},
514 compatibility: {},
515 },
516 ],
517 };
518 const maxLabel = (sources: Parameters<typeof capClaudeCatalogEffort>[2]) => {
519 const effort = capClaudeCatalogEffort(catalog, [opus], sources)[0]?.capabilities
520 ?.optionDescriptors?.[0];
521 return effort?.type === "select" ? effort.options.at(-1)?.label : undefined;
522 };
523 const perModel = (entries: Record<string, "low" | "medium" | "high" | "max">) => ({
524 modelMaxEffortLevels: new Map(Object.entries(entries)),
525 });
526
527 // Claude Code matches family aliases and [1m] spellings case-insensitively.
528 assert.strictEqual(maxLabel([perModel({ Opus: "medium" })]), "Max (capped to Medium)");
529 assert.strictEqual(
530 maxLabel([perModel({ "claude-opus-5-5[1M]": "medium" })]),
531 "Max (capped to Medium)",
532 );
533 assert.strictEqual(maxLabel([perModel({ " OPUS[1m] ": "medium" })]), "Max (capped to Medium)");
534 // Other keys name the most specific model id they contain, so dated and provider-prefixed ids
535 // match while the catalog's dotted aliases and a less specific model id do not.
536 for (const key of [
537 "claude-opus-5-5-20260101",
538 "CLAUDE-OPUS-5-5-20260101[1m]",
539 "us.anthropic.claude-opus-5-5-v1:0",
540 "claude-opus-5-5-latest",
541 ]) {
542 assert.strictEqual(maxLabel([perModel({ [key]: "medium" })]), "Max (capped to Medium)", key);
543 }
544 for (const key of ["claude-opus-5.5", "opus-5.5", "opus-5-5", "opus [1m]", "claude-opus-5"]) {
545 assert.strictEqual(maxLabel([perModel({ [key]: "medium" })]), "Max", key);
546 }
547 // Keys naming the same model keep the lowest cap, and a `max` key does not exempt it.
548 assert.strictEqual(
549 maxLabel([perModel({ opus: "max", "claude-opus-5-5": "low" })]),
550 "Max (capped to Low)",
551 );
552 // A per-model `max` only exempts the model from its own source's top-level cap.
553 assert.strictEqual(
554 maxLabel([{ maxEffortLevel: "medium", ...perModel({ opus: "max" }) }]),
555 "Max",
556 );
557 assert.strictEqual(
558 maxLabel([perModel({ opus: "max" }), { maxEffortLevel: "high" }]),
559 "Max (capped to High)",
560 );
561 assert.strictEqual(
562 maxLabel([{ maxEffortLevel: "medium" }, perModel({ opus: "high" })]),
563 "Max (capped to Medium)",
564 );
565 });
566});