@exla/rudder 5.0.7 → 5.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/models.js CHANGED
@@ -11,22 +11,23 @@ const ANTHROPIC_MODELS_URL = "https://api.anthropic.com/v1/models?limit=100";
11
11
  const ANTHROPIC_VERSION = "2023-06-01";
12
12
  const MODELS_DEV_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
13
13
  const FETCH_TIMEOUT_MS = 2500;
14
- const MODEL_PICKER_LIMIT = 24;
15
14
  let modelCatalogInFlight;
16
- export async function discoverModelOptions(backend, configuredDefault) {
17
- const defaultDetail = configuredDefault || "CLI default";
18
- const picker = backend === "claude" ? "claude" : "codex";
19
- // The catalog (models.dev, the provider APIs, local history, Claude Code's
20
- // list) and the CLI's own list: Claude Code's /model list or Codex's model
21
- // cache. The CLI's list names a model, its effort levels and its display
22
- // name as soon as the CLI learns it.
23
- const [{ data, claudeCode }, codex] = await Promise.all([
24
- readModelsDev(),
25
- picker === "claude" ? [] : readCodexCliModels(),
26
- ]);
27
- const cli = picker === "claude" ? claudeCode : codex;
28
- const catalog = (picker === "claude" ? data.anthropic : data.openai)?.models ?? {};
29
- return [{ label: "Default", value: undefined, detail: defaultDetail }, ...pickerRows(picker, catalog, cli)];
15
+ /**
16
+ * Every harness's models, one section per HARNESSES row, in its order. A
17
+ * section lists exactly what the harness's CLI lists for this account, with
18
+ * the CLI's names and effort levels; the merged catalog (models.dev, the
19
+ * provider APIs, local history, Claude Code's list) adds detail lines and
20
+ * prices. Reading it also refreshes the catalog the dashboard reads.
21
+ */
22
+ export async function discoverHarnesses() {
23
+ const catalog = await readModelsDev();
24
+ return Promise.all(HARNESSES.map(async (harness) => ({
25
+ id: harness.id,
26
+ label: harness.label,
27
+ account: harness.account,
28
+ models: pickerRows(harness, catalog.data[harness.catalog]?.models ?? {}, await harness.listed(catalog)),
29
+ default: await harness.defaultModel(catalog),
30
+ })));
30
31
  }
31
32
  /** Refreshes the models.dev catalog the dashboard's own picker reads. */
32
33
  export async function refreshModelCatalog() {
@@ -51,12 +52,27 @@ async function readCodexCacheModels() {
51
52
  return (parsed.models ?? [])
52
53
  .filter((model) => model.slug && model.slug !== "codex-auto-review" && model.visibility !== "hide");
53
54
  }
54
- async function discoverCodexModelsLocal() {
55
- return (await readCodexCacheModels()).map((model) => ({
56
- label: model.slug || model.display_name || "model",
57
- value: model.slug,
58
- detail: model.display_name || model.description || "local Codex cache",
59
- }));
55
+ /**
56
+ * The model Codex runs when it is given none: the top-level `model` in its
57
+ * config.toml, or null when the file sets none.
58
+ */
59
+ async function readCodexConfiguredModel() {
60
+ const file = path.join(process.env.CODEX_HOME || path.join(os.homedir(), ".codex"), "config.toml");
61
+ const raw = await fsp.readFile(file, "utf8").catch(ignoreMissing);
62
+ if (!raw) {
63
+ return null;
64
+ }
65
+ // Top-level keys come before the first [table].
66
+ for (const line of raw.split("\n")) {
67
+ if (/^\s*\[/.test(line)) {
68
+ break;
69
+ }
70
+ const match = /^\s*model\s*=\s*"([^"]+)"/.exec(line);
71
+ if (match) {
72
+ return match[1];
73
+ }
74
+ }
75
+ return null;
60
76
  }
61
77
  async function readCodexCliModels() {
62
78
  return (await readCodexCacheModels()).map((model) => ({
@@ -65,6 +81,7 @@ async function readCodexCliModels() {
65
81
  description: model.description,
66
82
  efforts: (model.supported_reasoning_levels ?? []).flatMap((level) => (level.effort ? [level.effort] : [])),
67
83
  alias: false,
84
+ resolved: model.slug,
68
85
  }));
69
86
  }
70
87
  async function readModelsDev() {
@@ -105,16 +122,6 @@ function modelsDevCachePath() {
105
122
  // RUDDER_HOME is set — otherwise dynamic model refresh + cached reasoning break.
106
123
  return path.join(rudderHome(), "models-dev.json");
107
124
  }
108
- function isUsableTextModel(id, model) {
109
- if (model.tool_call === false) {
110
- return false;
111
- }
112
- if (isExcludedOpenAiTextModel(id)) {
113
- return false;
114
- }
115
- const output = model.modalities?.output;
116
- return !output || output.includes("text");
117
- }
118
125
  function isClaudePickerModel(id) {
119
126
  // No family-name allowlist: a brand-new model family (fable, and whatever
120
127
  // comes after it) must show up in the picker without a Rudder release. Only
@@ -148,7 +155,7 @@ async function mergeLiveAndLocalModels(data) {
148
155
  for (const model of claudeLocal) {
149
156
  changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
150
157
  }
151
- for (const model of claudeCodeCatalogModels(data, claudeCode)) {
158
+ for (const model of claudeCodeCatalogModels(data, claudeCode.models)) {
152
159
  changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
153
160
  }
154
161
  return { changed, claudeCode };
@@ -164,7 +171,7 @@ function claudeCodeCatalogModels(data, listed) {
164
171
  const efforts = new Map();
165
172
  const names = new Map();
166
173
  for (const model of listed) {
167
- efforts.set(model.id, RUDDER_EFFORTS.claude.filter((level) => model.efforts.includes(level)));
174
+ efforts.set(model.id, CLAUDE.efforts.filter((level) => model.efforts.includes(level)));
168
175
  names.set(model.id, model.name);
169
176
  }
170
177
  for (const model of listed) {
@@ -177,7 +184,7 @@ function claudeCodeCatalogModels(data, listed) {
177
184
  id,
178
185
  meta: known[id]
179
186
  ? { efforts: levels }
180
- : { id, name: names.get(id) || prettyClaudeModel(id), tool_call: true, efforts: levels, modalities: { output: ["text"] }, source: "claude-code" },
187
+ : { id, name: names.get(id) || claudeModelName(id), tool_call: true, efforts: levels, modalities: { output: ["text"] }, source: "claude-code" },
181
188
  }));
182
189
  }
183
190
  async function fetchOpenAIModelCatalog() {
@@ -221,7 +228,7 @@ async function fetchAnthropicModelCatalog() {
221
228
  id: model.id,
222
229
  meta: {
223
230
  id: model.id,
224
- name: model.display_name || prettyClaudeModel(model.id),
231
+ name: model.display_name || claudeModelName(model.id),
225
232
  tool_call: true,
226
233
  reasoning: isLikelyReasoningModel("claude", model.id),
227
234
  release_date: typeof model.created_at === "string" ? model.created_at.slice(0, 10) : undefined,
@@ -233,15 +240,15 @@ async function fetchAnthropicModelCatalog() {
233
240
  return [];
234
241
  }
235
242
  async function readCodexLocalModels() {
236
- return (await discoverCodexModelsLocal())
237
- .filter((model) => model.value && isCodexRelevantModel(model.value) && !isExcludedOpenAiTextModel(model.value))
243
+ return (await readCodexCacheModels())
244
+ .filter((model) => isCodexRelevantModel(model.slug) && !isExcludedOpenAiTextModel(model.slug))
238
245
  .map((model) => ({
239
- id: model.value,
246
+ id: model.slug,
240
247
  meta: {
241
- id: model.value,
242
- name: model.detail || model.label,
248
+ id: model.slug,
249
+ name: model.display_name || model.description || model.slug,
243
250
  tool_call: true,
244
- reasoning: isLikelyReasoningModel("codex", model.value),
251
+ reasoning: isLikelyReasoningModel("codex", model.slug),
245
252
  modalities: { output: ["text"] },
246
253
  source: "codex-local-cache",
247
254
  },
@@ -256,7 +263,7 @@ async function readClaudeLocalModelIds() {
256
263
  id,
257
264
  meta: {
258
265
  id,
259
- name: prettyClaudeModel(id),
266
+ name: claudeModelName(id),
260
267
  tool_call: true,
261
268
  reasoning: isLikelyReasoningModel("claude", id),
262
269
  modalities: { output: ["text"] },
@@ -524,117 +531,137 @@ function collectModelFields(value, counts, depth = 0) {
524
531
  collectModelFields(child, counts, depth + 1);
525
532
  }
526
533
  }
527
- function prettyClaudeModel(model) {
528
- if (model === "opus" || model === "sonnet") {
529
- return `${capitalize(model)} latest`;
530
- }
531
- return model
532
- .replace(/^claude-/, "")
533
- .split("-")
534
- .map((part) => (/^\d+$/.test(part) ? part : capitalize(part)))
535
- .join(" ");
534
+ /** The name a Claude id reads as, the picker's way: "claude-fable-5-2" is "Fable 5.2". */
535
+ function claudeModelName(id) {
536
+ return withContext(parseClaudeId(id).name, id);
536
537
  }
537
538
  function capitalize(value) {
538
539
  return `${value.slice(0, 1).toUpperCase()}${value.slice(1)}`;
539
540
  }
540
- const ALIAS_GROUP = "Always the newest";
541
- const CONTEXT_SUFFIX = /\[(\d+)([km])\]$/i;
542
- // The levels the dashboard passes (native/src/models.rs effort_options_for):
543
- // a model with an effort setting takes low to xhigh, and Claude also max.
544
- const RUDDER_EFFORTS = {
545
- claude: ["low", "medium", "high", "xhigh", "max"],
546
- codex: ["low", "medium", "high", "xhigh"],
541
+ const CLAUDE = {
542
+ id: "claude",
543
+ label: "Claude",
544
+ account: "Claude Code",
545
+ catalog: "anthropic",
546
+ listed: async (catalog) => catalog.claudeCode.models,
547
+ defaultModel: async (catalog) => catalog.claudeCode.default,
548
+ parse: parseClaudeId,
549
+ // Claude Code's names already read "Opus 5.5".
550
+ name: (display) => display,
551
+ tiers: tiersByListOrder,
552
+ efforts: ["low", "medium", "high", "xhigh", "max"],
547
553
  };
548
- function pickerRows(backend, catalog, cli) {
549
- const listed = new Map();
554
+ const CODEX = {
555
+ id: "codex",
556
+ label: "Codex",
557
+ account: "ChatGPT",
558
+ catalog: "openai",
559
+ listed: () => readCodexCliModels(),
560
+ defaultModel: () => readCodexConfiguredModel(),
561
+ parse: parseGptId,
562
+ name: gptName,
563
+ // Codex lists its recommended model first, not its flagship.
564
+ tiers: tiersByPrice,
565
+ efforts: ["low", "medium", "high", "xhigh"],
566
+ };
567
+ const HARNESSES = [CLAUDE, CODEX];
568
+ const CONTEXT_SUFFIX = /\[(\d+)([km])\]$/i;
569
+ function pickerRows(harness, catalog, cli) {
570
+ const models = new Map();
550
571
  const aliases = [];
551
572
  for (const model of cli) {
552
573
  if (model.alias) {
553
574
  aliases.push(model);
554
575
  }
555
- else if (!listed.has(model.id)) {
556
- listed.set(model.id, model);
557
- }
558
- }
559
- const ids = new Set(Object.entries(catalog).filter(([id, model]) => isPickerModel(backend, id, model)).map(([id]) => id));
560
- for (const id of listed.keys()) {
561
- ids.add(id);
562
- }
563
- // A dated snapshot repeats its undated twin, so only the twin is listed
564
- // (the dashboard's picker does the same: models.rs dated_duplicate_base).
565
- for (const id of ids) {
566
- const base = /^(.+)-\d{8}$/.exec(id)?.[1];
567
- if (base && ids.has(base)) {
568
- const twin = listed.get(id);
569
- if (twin && !listed.has(base)) {
570
- listed.set(base, twin);
571
- }
572
- ids.delete(id);
576
+ else if (!models.has(model.id)) {
577
+ models.set(model.id, model);
573
578
  }
574
579
  }
575
- const prices = familyPrices(backend, catalog);
576
- const rows = [...ids]
577
- .map((id) => ({ id, parsed: parseModelId(backend, id) }))
578
- .sort((a, b) => compareModelIds(a.parsed, b.parsed, prices) || a.id.localeCompare(b.id))
579
- // Older catalog models make way; every model the CLI lists stays.
580
- .filter((row, index) => listed.has(row.id) || index < MODEL_PICKER_LIMIT)
581
- .map(({ id, parsed }) => ({
582
- label: modelLabel(backend, id, parsed, listed),
583
- value: id,
584
- detail: listed.get(id)?.description || catalogDetail(catalog[id]),
585
- group: parsed.group,
586
- efforts: modelEfforts(backend, id, catalog[id], listed.get(id)),
580
+ const tiers = harness.tiers(harness.parse, cli, catalog);
581
+ // The levels both the CLI lists and the dashboard passes; the dashboard refuses any other.
582
+ const efforts = (model) => harness.efforts.filter((level) => model.efforts.includes(level));
583
+ const rows = [...models.values()]
584
+ .map((model) => ({ model, parsed: harness.parse(model.id) }))
585
+ .sort((a, b) => compareModelIds(a.parsed, b.parsed, tiers) || a.model.id.localeCompare(b.model.id))
586
+ .map(({ model, parsed }) => ({
587
+ label: modelLabel(harness, model.id, parsed, models),
588
+ value: model.id,
589
+ detail: model.description || catalogDetail(catalog[model.id]),
590
+ efforts: efforts(model),
587
591
  }));
592
+ // "opus" reads "Opus 5.5" and sorts where Opus 5.5 does.
588
593
  const aliasRows = aliases
589
- .map((alias) => ({ alias, family: alias.id.replace(CONTEXT_SUFFIX, "") }))
590
- .sort((a, b) => (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || a.alias.id.localeCompare(b.alias.id))
591
- .map(({ alias }) => ({
592
- label: withContext(capitalize(alias.id.replace(CONTEXT_SUFFIX, "")), alias.id),
594
+ .map((alias) => ({ alias, parsed: harness.parse(alias.resolved) }))
595
+ .sort((a, b) => compareModelIds(a.parsed, b.parsed, tiers) || a.alias.id.localeCompare(b.alias.id))
596
+ .map(({ alias, parsed }) => ({
597
+ label: modelLabel(harness, alias.resolved, parsed, models),
593
598
  value: alias.id,
594
- detail: [alias.name ? `Now ${alias.name}` : "", alias.description ?? ""].filter(Boolean).join(" · "),
595
- group: ALIAS_GROUP,
596
- efforts: modelEfforts(backend, alias.id, catalog[alias.id], alias),
599
+ detail: alias.description ?? "",
600
+ efforts: efforts(alias),
601
+ alias: true,
597
602
  }));
598
603
  return [...rows, ...aliasRows];
599
604
  }
600
- function isPickerModel(backend, id, model) {
601
- if (!isUsableTextModel(id, model)) {
602
- return false;
603
- }
604
- return backend === "claude" ? id.startsWith("claude-") && isClaudePickerModel(id) : isCodexRelevantModel(id);
605
+ /** Families in the order the CLI first lists them: Claude Code lists Opus, Fable, Sonnet, Haiku. */
606
+ function tiersByListOrder(parse, cli) {
607
+ const families = [...new Set(cli.map((model) => parse(model.resolved).family))];
608
+ return new Map(families.map((family, index) => [family, families.length - index]));
605
609
  }
606
- /** "claude-opus-5-5" is Opus of Claude 5.5, "gpt-6.1-sol" Sol of GPT-6.1, "o4-mini" Mini of o4. */
607
- function parseModelId(backend, id) {
608
- const suffix = CONTEXT_SUFFIX.exec(id);
609
- const context = suffix ? `${suffix[1]}${suffix[2].toUpperCase()}` : undefined;
610
- const base = suffix ? id.slice(0, suffix.index) : id;
611
- if (backend === "claude") {
612
- const claude = /^claude-([a-z]+)((?:-\d{1,2})+)(?:-\d{8})?$/.exec(base);
613
- if (claude) {
614
- const version = claude[2].slice(1).split("-").map(Number);
615
- const number = version.join(".");
616
- return { group: `Claude ${number}`, series: 0, version, family: claude[1], name: `${capitalize(claude[1])} ${number}`, context };
617
- }
618
- }
619
- else {
620
- const gpt = /^gpt-(\d+(?:\.\d+)?)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
621
- if (gpt) {
622
- const variant = gpt[2] ?? "";
623
- return { group: `GPT-${gpt[1]}`, series: 0, version: gpt[1].split(".").map(Number), family: variant, name: [`GPT-${gpt[1]}`, ...words(variant)].join(" "), context };
624
- }
625
- const oSeries = /^o(\d+)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
626
- if (oSeries) {
627
- const variant = oSeries[2] ?? "";
628
- return { group: `o${oSeries[1]}`, series: 1, version: [Number(oSeries[1])], family: `o:${variant}`, name: [`o${oSeries[1]}`, ...words(variant)].join(" "), context };
610
+ /** Each family's highest output price in the catalog: Astra before Sol before Terra before Luna. */
611
+ function tiersByPrice(parse, _cli, catalog) {
612
+ const prices = new Map();
613
+ for (const [id, model] of Object.entries(catalog)) {
614
+ const price = model.cost?.output;
615
+ if (typeof price === "number") {
616
+ const { family } = parse(id);
617
+ prices.set(family, Math.max(prices.get(family) ?? 0, price));
629
618
  }
630
619
  }
631
- return { group: "Other", series: 2, version: [], family: base, name: base, context };
632
- }
633
- function words(variant) {
634
- return variant.split("-").filter(Boolean).map(capitalize);
620
+ return prices;
635
621
  }
636
- /** Newest generation first; within one, the family with the highest price first. */
637
- function compareModelIds(a, b, prices) {
622
+ function splitContext(id) {
623
+ const suffix = CONTEXT_SUFFIX.exec(id);
624
+ return suffix ? { base: id.slice(0, suffix.index), context: `${suffix[1]}${suffix[2].toUpperCase()}` } : { base: id };
625
+ }
626
+ /** An id of no known shape reads as its words, without a provider prefix: "anthropic/my-model" is "My Model". */
627
+ function unknownId(base, context) {
628
+ return { series: 2, version: [], family: base, name: words(base.slice(base.lastIndexOf("/") + 1)), context };
629
+ }
630
+ /** "claude-opus-5-5" is Opus 5.5, "claude-haiku-4-5-20251001" Haiku 4.5. */
631
+ function parseClaudeId(id) {
632
+ const { base, context } = splitContext(id);
633
+ const claude = /^claude-([a-z]+)((?:-\d{1,2})+)(?:-\d{8})?$/.exec(base);
634
+ if (!claude) {
635
+ return unknownId(base, context);
636
+ }
637
+ const version = claude[2].slice(1).split("-").map(Number);
638
+ return { series: 0, version, family: claude[1], name: `${capitalize(claude[1])} ${version.join(".")}`, context };
639
+ }
640
+ /** "gpt-6.1-sol" is Sol 6.1, "gpt-5.3-codex-spark" Codex Spark 5.3; "gpt-5.6" has no family word. */
641
+ function parseGptId(id) {
642
+ const { base, context } = splitContext(id);
643
+ const gpt = /^gpt-(\d+(?:\.\d+)?)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
644
+ if (gpt) {
645
+ const family = gpt[2] ?? "";
646
+ return { series: 0, version: gpt[1].split(".").map(Number), family, name: family ? `${words(family)} ${gpt[1]}` : `GPT-${gpt[1]}`, context };
647
+ }
648
+ const oSeries = /^o(\d+)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
649
+ if (oSeries) {
650
+ const family = oSeries[2] ?? "";
651
+ return { series: 1, version: [Number(oSeries[1])], family: `o:${family}`, name: family ? `${words(family)} o${oSeries[1]}` : `o${oSeries[1]}`, context };
652
+ }
653
+ return unknownId(base, context);
654
+ }
655
+ /** Codex's display name, the name and then the version: "GPT-6.2-Sol" and "GPT-6.2 Sol" read "Sol 6.2". */
656
+ function gptName(display) {
657
+ const named = /^GPT-(\d+(?:\.\d+)?)[- ](.+)$/i.exec(display);
658
+ return named ? `${capitalize(named[2].replace(/-/g, " "))} ${named[1]}` : display;
659
+ }
660
+ function words(family) {
661
+ return family.split(/[-_]/).filter(Boolean).map(capitalize).join(" ");
662
+ }
663
+ /** The highest version first; within one, the family of the highest tier first. */
664
+ function compareModelIds(a, b, tiers) {
638
665
  if (a.series !== b.series) {
639
666
  return a.series - b.series;
640
667
  }
@@ -644,74 +671,73 @@ function compareModelIds(a, b, prices) {
644
671
  return diff;
645
672
  }
646
673
  }
647
- return (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || Number(!!a.context) - Number(!!b.context);
648
- }
649
- /** Each family's highest output price in the catalog: Fable before Opus before Sonnet before Haiku. */
650
- function familyPrices(backend, catalog) {
651
- const prices = new Map();
652
- for (const [id, model] of Object.entries(catalog)) {
653
- const price = model.cost?.output;
654
- if (typeof price === "number") {
655
- const { family } = parseModelId(backend, id);
656
- prices.set(family, Math.max(prices.get(family) ?? 0, price));
657
- }
658
- }
659
- return prices;
674
+ return (tiers.get(b.family) ?? 0) - (tiers.get(a.family) ?? 0) || Number(!!a.context) - Number(!!b.context);
660
675
  }
661
- /** The CLI's display name for the model ("GPT-6.2-Sol" reads "GPT-6.2 Sol"), or one read from the id. */
662
- function modelLabel(backend, id, parsed, listed) {
676
+ /** The harness's name for the CLI's display name, or the name read from the id. */
677
+ function modelLabel(harness, id, parsed, listed) {
663
678
  const own = listed.get(id.replace(CONTEXT_SUFFIX, ""))?.name?.trim();
664
- const name = own ? (backend === "codex" ? own.replace(/^(GPT-\d+(?:\.\d+)?)-/i, "$1 ") : own) : parsed.name;
665
- return withContext(name, id);
679
+ return withContext(own ? harness.name(own) : parsed.name, id);
666
680
  }
667
681
  /** "Opus 5.5" of "claude-opus-5-5[1m]" reads "Opus 5.5 · 1M". */
668
682
  function withContext(name, id) {
669
683
  const suffix = CONTEXT_SUFFIX.exec(id);
670
684
  return suffix ? `${name} · ${suffix[1]}${suffix[2].toUpperCase()}` : name;
671
685
  }
672
- /** The levels both the model's CLI lists and the dashboard passes; the dashboard refuses any other. */
673
- function modelEfforts(backend, id, model, listed) {
674
- // Claude Code's levels, kept in the catalog: the dashboard takes exactly these.
675
- if (model?.efforts) {
676
- return model.efforts;
677
- }
678
- if (!hasEffortSetting(backend, id, model)) {
679
- return [];
680
- }
681
- return listed ? RUDDER_EFFORTS[backend].filter((level) => listed.efforts.includes(level)) : RUDDER_EFFORTS[backend];
682
- }
683
- /** native/src/models.rs model_supports_reasoning: the family rule, or the catalog's word. */
684
- function hasEffortSetting(backend, id, model) {
685
- if (model?.reasoning === true) {
686
- return true;
686
+ /**
687
+ * The name the app shows for any model an agent runs on. The home names every
688
+ * model it sends with this (cloud/worker/home.mjs), so the app never names
689
+ * one itself. A model its harness lists reads as its picker row does (an
690
+ * alias like the model it stands for: "opus" is "Opus 5.5"); any other id
691
+ * reads as the rows' rules read it ("claude-opus-4-1" is "Opus 4.1", "gpt-6.1-sol"
692
+ * Sol 6.1, "my-model" My Model). No id is the model the harness runs when
693
+ * given none (HarnessModels.default), and null when it does not say which.
694
+ * `harnesses` is the last discoverHarnesses() answer, empty before the first.
695
+ */
696
+ export function modelName(harnesses, backend, id) {
697
+ const listed = harnesses.find((harness) => harness.id === backend);
698
+ if (!id) {
699
+ return listed?.default ? modelName(harnesses, backend, listed.default) : null;
687
700
  }
688
- if (backend === "claude") {
689
- return /opus|sonnet|fable/.test(id) || (id.startsWith("claude-") && !id.includes("3-"));
701
+ const row = listed?.models.find((model) => model.value === id);
702
+ if (row) {
703
+ return row.label;
690
704
  }
691
- return isGptTextModel(id) || id.includes("codex") || isOSeriesModel(id);
705
+ const harness = HARNESSES.find((entry) => entry.id === backend);
706
+ return withContext(harness ? harness.parse(id).name : unknownId(splitContext(id).base).name, id);
692
707
  }
693
708
  const CLAUDE_CODE_TIMEOUT_MS = 20_000;
694
709
  /**
695
710
  * Claude Code's own /model list for this account, with each alias's current
696
711
  * model, display names and the effort levels each model takes. Each alias
697
712
  * also lists the model it stands for. Empty when Claude Code is not installed.
713
+ * Its "default" row is not a model of its own: it names the model an agent
714
+ * started without one runs.
698
715
  */
699
716
  async function readClaudeCodeModels() {
700
717
  const answer = await claudeCodeModelList();
701
718
  const models = [];
719
+ let runsByDefault = null;
702
720
  for (const row of answer ?? []) {
703
- // Claude Code's "default" is what Rudder's Default row starts.
704
- if (!row.value || row.value === "default") {
721
+ if (row.value === "default") {
722
+ runsByDefault = row.resolvedModel?.startsWith("claude-") ? row.resolvedModel : null;
723
+ continue;
724
+ }
725
+ if (!row.value) {
705
726
  continue;
706
727
  }
707
728
  const efforts = row.supportsEffort ? row.supportedEffortLevels ?? [] : [];
708
- const alias = !row.value.startsWith("claude-");
709
- models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias });
710
- if (alias && row.resolvedModel?.startsWith("claude-")) {
711
- models.push({ id: row.resolvedModel, name: row.displayName, description: row.description, efforts, alias: false });
729
+ if (row.value.startsWith("claude-")) {
730
+ models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias: false, resolved: row.value });
731
+ continue;
732
+ }
733
+ // An alias is named and placed like the model it stands for.
734
+ if (!row.resolvedModel?.startsWith("claude-")) {
735
+ throw new Error(`Claude Code listed the model alias "${row.value}" without the Claude model it stands for`);
712
736
  }
737
+ models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias: true, resolved: row.resolvedModel });
738
+ models.push({ id: row.resolvedModel, name: row.displayName, description: row.description, efforts, alias: false, resolved: row.resolvedModel });
713
739
  }
714
- return models;
740
+ return { models, default: runsByDefault };
715
741
  }
716
742
  /** Claude Code's headless `initialize` answer: its model list, or null when Claude Code is not installed. */
717
743
  function claudeCodeModelList() {