Files
plugins/packages/agentcompass/src/catalog.js
T
Akiiwa 157c7deefd agentcompass 0.2.1: a needs_visual task requires image input at every tool_operation level (#1092)
Reviewed at cedd845b3. WSL (Bun 1.4.2, temp HOME): bun test in packages/agentcompass 141 pass, scripts/check.mjs agentcompass ok. Without Boolean(task.needs_visual) the new test fails; restored, 141/141. Generated files change only their Source line.
2026-11-13 19:49:26 +08:00

837 lines
30 KiB
JavaScript

/**
* AgentCompass catalogue: model rows, aliases, family patterns, launch efforts, route scopes, plan windows, the scoring
* policy, and the one model-name resolver (`model_resolution.py`).
*
* The tables between the GENERATED markers are generated from AgentCompass's `references/accounts.json` and
* `plan-templates.json` at a pinned commit (`scripts/sync-catalog.mjs`); do not edit them by hand. The category scores and
* plan capacities are in `src/reference-data.js`, generated the same way.
* Pure ES2022 module with zero external or Node-only dependencies so it runs in both
* Bun (`magpie.hooks` / provider plugin) and Magpie's in-process `moejs` (`magpie.middleware`).
*/
export const INTERACTION_STYLES = ["engineering", "exploration", "text_only", "advisory"];
export const DIFFICULTY_ORDER = ["routine", "hard", "coupled", "frontier"];
/** The efforts a launch can carry, lowest first (`quota_economy.EFFORT_ORDER`). */
export const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max", "ultra"];
// BEGIN GENERATED by scripts/sync-catalog.mjs
// Source: AgentCompass 28443426409fe456a63c2b63633faf18e97ee7b4 skills/agent-compass/references/accounts.json, skills/agent-compass/references/plan-templates.json
export const MODELS = {
"deepseek-v4.1-flash-free": {},
"claude-fable-5-1": {
api_family: "claude",
list_price: { input: 10, cache_write_5m: 12.5, cache_write_1h: 20, cache_read: 0.25, output: 50 },
},
"claude-fable-5-2": {
fast_capable: true,
api_family: "claude",
vendor_fast_mode: {
price_multiplier: 2,
speed_multiplier: 2.5,
fast_price: { input: 16, output: 80, cache_read: 0.4 },
standard_price: { input: 8, output: 40, cache_read: 0.2 },
},
list_price: { input: 8, cache_write_5m: 10, cache_write_1h: 16, cache_read: 0.2, output: 40 },
},
"claude-opus-5-5": {
fast_capable: true,
api_family: "claude",
vendor_fast_mode: {
price_multiplier: 2,
speed_multiplier: 2.5,
fast_price: { input: 8, output: 40, cache_read: 0.4 },
standard_price: { input: 4, output: 20, cache_read: 0.2 },
},
list_price: { input: 4, cache_write_5m: 5, cache_write_1h: 8, cache_read: 0.2, output: 20 },
},
"gpt-6.1-sol": {
fast_capable: true,
api_family: "codex",
list_price: { input: 2, cache_write_5m: 2.5, cache_write_1h: 2.5, cache_read: 0.1, output: 10 },
},
"gpt-6-astra": {
fast_capable: true,
api_family: "codex",
list_price: { input: 10, cache_write_5m: 12.5, cache_write_1h: 12.5, cache_read: 1, output: 50 },
},
"gemini-4-argon-high": {},
"gemini-4-hydrogen-high": {},
"claude-sonnet-5-5": {
api_family: "claude",
list_price: { input: 2, cache_write_5m: 2.5, cache_write_1h: 4, cache_read: 0.1, output: 10 },
},
"grok-4.7": {},
"gemini-3.8-flash-high": {},
"grok-bot": { fixed_effort: "medium", excluded_when: "local_only" },
dot: { excluded_when: "local_only" },
"gpt-6-pro": {
advisor_only: true,
advisor_for: ["direction_reasoning", "complex_build_plan"],
api_family: "codex",
},
"claude-haiku-5-5": {
api_family: "claude",
list_price: { input: 0.1, cache_write_5m: 0.125, cache_write_1h: 0.2, cache_read: 0.01, output: 0.5 },
},
"gpt-6.1-terra": { fast_capable: true, context_window: 500000, api_family: "codex" },
"gpt-6-sol": {
fast_capable: true,
context_window: 272000,
api_family: "codex",
list_price: { input: 2, cache_write_5m: 2.5, cache_write_1h: 2.5, cache_read: 0.2, output: 10 },
},
"gpt-6-luna": {
fast_capable: true,
context_window: 272000,
api_family: "codex",
list_price: { input: 0.1, cache_write_5m: 0.125, cache_write_1h: 0.125, cache_read: 0.01, output: 0.5 },
},
"gpt-5.6-sol": { context_window: 272000, api_family: "codex" },
"gpt-5.6-terra": { context_window: 272000, api_family: "codex" },
"gpt-5.6-luna": { context_window: 272000, api_family: "codex" },
"grok-4.7-build-fast": {},
"deepseek-v4-pro": {},
"glm-5.3": {},
"glm-5.3-flash-free": {},
"qwen3-coder-next": {},
"qwen3.8-max": {},
"kimi-k3.1-pro": {},
"kimi-k3": {},
"minimax-m3": {},
"minimax-m3.1-flash": {},
"doubao-seed-2-1-pro-260628": {},
"mimo-v2.6-pro": {},
"mimo-v2.6-flash-free": {},
"nemotron-3-ultra-free": {},
"nemotron-3.5-super-vl-free": {},
"nemotron-3.5-lightning-free": {},
"mistral-large-4": {},
"muse-wonder-1.0": {},
"beam-free": {},
"flint-40b-free": {},
"claude-haiku-4-5": { api_family: "claude" },
"claude-opus-4-6": { api_family: "claude" },
"claude-sonnet-4-6": { api_family: "claude" },
"glm-5.2": {},
"gpt-oss-120b": { api_family: "codex" },
"gemini-3.1-flash-lite": {},
"kimi-k2.7-code": {},
"qwen3.6-plus": {},
"claude-opus-4-7": { api_family: "claude" },
"claude-opus-4-8": { fast_capable: true, api_family: "claude" },
"grok-4.5": {},
"grok-4.6": {},
"gemini-3.1-pro-preview": {},
"gemini-3.7-flash": {},
"kimi-k2.6": {},
"qwen3-max": {},
"qwen3.7-max": {},
"qwen3-flash-2025-07-28": { context_window: 1000000 },
"gemini-4-carbon": {},
};
export const MODEL_ALIASES = {
"claude-haiku-4-5@20251001": "claude-haiku-4-5",
"claude-opus-5": "claude-opus-5-5",
"claude-sonnet-5": "claude-sonnet-5-5",
"claude-fable-5": "claude-fable-5-2",
fable: "claude-fable-5-2",
"gemini-3.8-flash": "gemini-3.8-flash-high",
"gemini-4-argon": "gemini-4-argon-high",
"gemini-4-hydrogen": "gemini-4-hydrogen-high",
"gemini-4-pro": "gemini-4-argon-high",
"gemini-4-ultra": "gemini-4-argon-high",
argon: "gemini-4-argon-high",
"ChatGPT Pro via chatgpt-pro-consult": "gpt-6-pro",
"grok-4.7-latest": "grok-4.7",
"grok-4": "grok-4.7",
"opencode/deepseek-v4.1-flash-free": "deepseek-v4.1-flash-free",
"deepseek-v4.1-flash": "deepseek-v4.1-flash-free",
deepseek: "deepseek-v4.1-flash-free",
"glm-5.3-flash": "glm-5.3-flash-free",
"opencode/glm-5.3-flash-free": "glm-5.3-flash-free",
"MiniMax-M3": "minimax-m3",
"MiniMax-M3.1-Flash": "minimax-m3.1-flash",
"mimo-v2.6-flash": "mimo-v2.6-flash-free",
"mimo-v2.6-pro-ultraspeed": "mimo-v2.6-pro",
"kimi-k3.1-pro-highspeed": "kimi-k3.1-pro",
"nemotron-3-ultra-550b-a55b": "nemotron-3-ultra-free",
"nemotron-3.5-super-vl-120b-a12b": "nemotron-3.5-super-vl-free",
"nemotron-3.5-lightning-30b-a3b": "nemotron-3.5-lightning-free",
"opencode/mimo-v2.6-flash-free": "mimo-v2.6-flash-free",
"opencode/nemotron-3-ultra-free": "nemotron-3-ultra-free",
"opencode/nemotron-3.5-super-vl-free": "nemotron-3.5-super-vl-free",
"opencode/nemotron-3.5-lightning-free": "nemotron-3.5-lightning-free",
"opencode/beam-free": "beam-free",
"opencode/flint-40b-free": "flint-40b-free",
"zai-org-glm-5-2": "glm-5.2",
"venice-api/zai-org-glm-5-2": "glm-5.2",
"deepseek-flash": "deepseek-v4.1-flash-free",
"deepseek-v4-flash": "deepseek-v4.1-flash-free",
"qwen-flash": "qwen3-flash-2025-07-28",
};
export const FAMILIES = [
{
pattern: "^grok-bot$",
models: [],
},
{
pattern: "^claude-opus",
models: ["claude-opus-5-5"],
},
{
pattern: "^claude-sonnet",
models: ["claude-sonnet-5-5"],
},
{
pattern: "^claude-fable",
models: ["claude-fable-5-2"],
},
{
pattern: "^claude-haiku",
models: ["claude-haiku-5-5"],
},
{
pattern: "^gpt-6.*luna",
models: ["gpt-6-luna"],
},
{
pattern: "^gpt-6.*terra",
models: ["gpt-6.1-terra", "gpt-6-astra"],
},
{
pattern: "^gpt-6.*sol",
models: ["gpt-6.1-sol", "gpt-6-astra"],
},
{
pattern: "^gpt-6.*pro",
models: ["gpt-6-pro", "gpt-6-astra"],
},
{
pattern: "^gpt-6",
models: ["gpt-6-astra"],
},
{
pattern: "^gemini.*hydrogen",
models: ["gemini-4-hydrogen-high", "gemini-3.8-flash-high"],
},
{
pattern: "^gemini.*flash",
models: ["gemini-3.8-flash-high"],
},
{
pattern: "^gemini",
models: ["gemini-4-argon-high"],
},
{
pattern: "^grok.*(?:mini|fast)|^grok-code",
models: ["grok-4.7-build-fast", "grok-4.7"],
},
{
pattern: "^grok",
models: ["grok-4.7"],
},
{
pattern: "^deepseek.*flash",
models: ["deepseek-v4.1-flash-free"],
},
{
pattern: "^deepseek",
models: ["deepseek-v4-pro"],
},
{
pattern: "^qwen.*flash",
models: ["qwen3-flash-2025-07-28"],
},
{
pattern: "^qwen.*coder",
models: ["qwen3-coder-next", "qwen3.8-max"],
},
{
pattern: "^qwen",
models: ["qwen3.8-max"],
},
{
pattern: "^kimi|^moonshot",
models: ["kimi-k3.1-pro"],
},
{
pattern: "^glm.*flash",
models: ["glm-5.3-flash-free"],
},
{
pattern: "^glm",
models: ["glm-5.3"],
},
{
pattern: "^minimax.*flash",
models: ["minimax-m3.1-flash"],
},
{
pattern: "^minimax|^abab",
models: ["minimax-m3"],
},
{
pattern: "^doubao",
models: ["doubao-seed-2-1-pro-260628"],
},
{
pattern: "^mimo.*flash",
models: ["mimo-v2.6-flash-free"],
},
{
pattern: "^mimo",
models: ["mimo-v2.6-pro"],
},
{
pattern: "^nemotron.*lightning",
models: ["nemotron-3.5-lightning-free", "nemotron-3-ultra-free"],
},
{
pattern: "^nemotron.*(?:super|vl)",
models: ["nemotron-3.5-super-vl-free", "nemotron-3-ultra-free"],
},
{
pattern: "^nemotron",
models: ["nemotron-3-ultra-free"],
},
{
pattern: "^muse",
models: ["muse-wonder-1.0"],
},
{
pattern: "^llama",
models: [],
},
{
pattern: "^mistral|^codestral|^devstral",
models: ["mistral-large-4"],
},
];
export const SUPERSEDED_MODELS = {
"claude-opus-4-6": "claude-opus-5-5",
"claude-opus-4-7": "claude-opus-5-5",
"claude-opus-4-8": "claude-opus-5-5",
"claude-sonnet-4-6": "claude-sonnet-5-5",
"claude-haiku-4-5": "claude-haiku-5-5",
"gpt-6-sol": "gpt-6.1-sol",
"gpt-5.6-sol": "gpt-6.1-sol",
"gpt-5.6-terra": "gpt-6.1-terra",
"gpt-5.6-luna": "gpt-6-luna",
"grok-4.5": "grok-4.7",
"grok-4.6": "grok-4.7",
"gemini-3.1-pro-preview": "gemini-4-argon-high",
"gemini-3.7-flash": "gemini-3.8-flash-high",
"glm-5.2": "glm-5.3",
"kimi-k2.6": "kimi-k3",
"qwen3-max": "qwen3.8-max",
"qwen3.7-max": "qwen3.8-max",
"deepseek-v4-flash": "deepseek-v4.1-flash-free",
"claude-fable-5-1": "claude-fable-5-2",
};
export const SAME_MODEL_CAPACITY_RULES = {
"grok-bot": {
model: "claude-opus-5-5",
capacity_rule: {
target_family: "grok",
target_window: "credits",
reference_family: "claude",
reference_window: "seven_day",
},
},
};
export const DISPATCH_EFFORTS = {
grok: {
"grok-4.7": ["low", "high", "xhigh"],
"grok-4.7-build-fast": ["high"],
},
claude: {
"claude-opus-4-6": ["high"],
"claude-sonnet-4-6": ["high"],
"claude-haiku-4-5": ["high"],
"claude-opus-5-5": ["low", "medium", "high", "xhigh", "max"],
"claude-sonnet-5-5": ["low", "medium", "high", "xhigh", "max"],
"claude-fable-5-1": ["low", "medium", "high", "xhigh", "max"],
"claude-fable-5-2": ["low", "medium", "high", "xhigh", "max"],
"claude-haiku-5-5": ["high"],
},
codex: {
"gpt-6-pro": ["high"],
"gpt-6-astra": ["low", "medium", "high", "xhigh", "max", "ultra"],
"gpt-6.1-sol": ["low", "medium", "high", "xhigh", "max", "ultra"],
"gpt-6.1-terra": ["high"],
"gpt-6-sol": ["high"],
"gpt-6-luna": ["high"],
"gpt-5.6-sol": ["high"],
"gpt-5.6-terra": ["high"],
"gpt-5.6-luna": ["high"],
},
opencode: {
"deepseek-v4.1-flash-free": ["default", "low", "high", "max"],
},
"antigravity-resilient": {
"claude-opus-5-5": ["low", "medium", "high"],
"claude-sonnet-5-5": ["low", "medium", "high"],
},
omp: {
"glm-5.2": ["high", "max"],
},
pi: {
"gpt-6-pro": ["high"],
"gpt-6-astra": ["low", "medium", "high", "xhigh", "max"],
"gpt-6.1-sol": ["low", "medium", "high", "xhigh", "max"],
"gpt-6.1-terra": ["high"],
"gpt-6-sol": ["high"],
"gpt-6-luna": ["high"],
"gpt-5.6-sol": ["high"],
"gpt-5.6-terra": ["high"],
"gpt-5.6-luna": ["high"],
},
};
export const ROUTES = {
dot_execution: {
scope: "A bounded assignment the user's own OpenAI Dot can finish end to end and return as a completed text deliverable.",
implies: { local_only: false },
},
web_research: {
scope: "Gather, check and organize information from the open web or other public sources on Dot's own computer, and return a written, sourced result: surveys of options or vendors, current prices, specs or versions, documentation and changelog lookups, fact-checks, news and background roundups, comparison tables.",
harness_order: ["pi", "codex"],
},
text_in_text_out: {
scope: "Self-contained work whose whole input fits in the packet and whose deliverable is text returned to the parent: drafting, rewriting, translating, summarizing, critiquing, comparing, explaining, and reviewing the logic of a document given in full (mark that `hard`).",
harness_order: ["pi", "codex"],
},
exploration_analysis: {
scope: "Explore and analyze material on this machine and return findings as text, with light or no code: map how a codebase or system works, trace where and why something happens, read logs, configs, data files or documents, run read-only commands and throwaway scripts to measure something, audit or compare options against the local evidence, and check a document against the code, configuration or data it describes.",
implies: { local_only: true },
harness_order: ["pi", "codex"],
},
research_packet: {
scope: "Run a defined quantitative experiment, evaluation benchmark, simulation, backtest or data analysis pipeline on this machine's data. Use existing tooling or bounded experiment scripts, compare named variants against a baseline, verify statistical results and report metrics, uncertainty and reproducible artifacts.",
implies: { local_only: true },
harness_order: ["pi", "codex"],
},
self_contained_code: {
scope: "Self-contained code and validation work whose whole input fits in the packet (the spec, interfaces and any existing source it must match; keep it to about 40,000 characters) and whose deliverable is new files with their unit tests, or a report of numbers, returned as text: a module and its tests, a script, a data-processing, backtest or validation routine.",
},
visual_analysis: {
scope: "Interpret screenshots, charts, diagrams, spatial layouts, image evidence or visual discrepancies; distinct from writing frontend code.",
implies: { visual: true },
},
direction_reasoning: {
scope: "Deep reasoning and discussion of solution direction, competing architectures, assumptions, causal explanations, or which problem to solve.",
},
complex_build_plan: {
scope: "Turn an agreed direction into a repository-grounded multi-system build plan: dependencies, interfaces, staged migrations, sequencing, validation and rollback.",
},
general_implementation: {
scope: "Implement an agreed plan, maintain production features, refactor bounded code or deliver ordinary repository changes.",
},
debug_review: {
scope: "Subtle bug diagnosis, regression analysis, review of code and diffs, invariants, test-driven repairs and checking existing behavior.",
harness_order: ["codex", "pi"],
},
frontend_implementation: {
scope: "Write UI components, interactions, animations and styling from the accepted design; visual evidence inspection is a separate visual_analysis task when material.",
},
bounded_bulk_work: {
scope: "Homogeneous small changes, independent extraction or inventory, boilerplate and fixed transformations with explicit acceptance.",
},
tool_execution: {
scope: "A bounded outcome primarily requiring file, shell, browser, API or other tool calls, with direction and authorized actions already established.",
},
computer_use: {
scope: "Operate a graphical computer or app through screenshots, mouse and keyboard (computer use): GUI-only applications, desktop or browser flows with no API, clicking through settings.",
implies: { visual: true },
harness_order: ["codex", "pi"],
},
other_or_mixed: { scope: "Unmatched or mixed work." },
};
export const QUOTA_SOURCES = { "grok-bot": "grok" };
export const SCORING_POLICY = {
small_short_capacity_usd: 50,
small_short_window_floor_pct: 25,
small_short_safety_margin_pct: 12,
safety_margin_pct: 5,
short_window_floor_pct: 10,
short_window_hours: 24,
defer_if_reset_within_hours: 6,
rotate_after_carried_tokens: 2000000,
context_burn_extra_at_250k: 0.5,
needs_judgment_margin: 0.02,
harness_order: ["codex", "pi"],
profile: {
difficulty_by_depth: { "1": "routine", "2": "hard", "3": "coupled", "4": "frontier" },
harness_by_style: {
engineering: ["codex", "pi"],
exploration: ["pi", "codex"],
},
kind_by_style: {
engineering: "general_implementation",
exploration: "exploration_analysis",
text_only: "text_in_text_out",
advisory: "direction_reasoning",
},
},
};
export const PLAN_TEMPLATES = {
claude: {
pro: {
price_usd_per_month: 20,
windows: {
five_hour: { hours: 5, launch_min_remaining_pct: 25 },
seven_day: { hours: 168 },
},
price_source: { kind: "vendor", url: "https://claude.com/pricing" },
},
max5: {
price_usd_per_month: 100,
windows: {
five_hour: { hours: 5 },
seven_day: { hours: 168 },
weekly_fable: {
hours: 168,
models: ["fable"],
},
},
price_source: { kind: "vendor", url: "https://claude.com/pricing" },
},
max20: {
price_usd_per_month: 200,
windows: {
five_hour: { hours: 5 },
seven_day: { hours: 168 },
weekly_fable: {
hours: 168,
models: ["fable"],
},
},
price_source: { kind: "vendor", url: "https://claude.com/pricing" },
},
max: { alias: "max5" },
},
codex: {
plus: {
price_usd_per_month: 20,
windows: {
usage: { hours: 168 },
five_hour: { hours: 5, launch_min_remaining_pct: 25 },
},
},
team: { alias: "plus" },
pro100: {
price_usd_per_month: 100,
windows: {
usage: { hours: 168 },
},
},
pro: {
price_usd_per_month: 200,
windows: {
usage: { hours: 168 },
},
},
},
antigravity: {
ultra20: {
price_usd_per_month: 199.99,
tiers: ["g1-ultra-tier", "Google AI Ultra 20x", "Google AI Ultra (20x)", "ultra 20x", "ultra x20"],
windows: {
"gemini-5h": {
hours: 5,
models: ["gemini"],
},
"gemini-weekly": {
hours: 168,
models: ["gemini"],
},
"3p-5h": {
hours: 5,
models_except: ["gemini"],
},
"3p-weekly": {
hours: 168,
models_except: ["gemini"],
},
},
price_source: { kind: "vendor", url: "https://one.google.com/intl/ALL_us/about/feeds/pricing_2026_07_28.json" },
},
ultra5: {
price_usd_per_month: 99.99,
tiers: ["g1-ultra-lite-tier", "Google AI Ultra 5x", "Google AI Ultra (5x)", "ultra 5x", "ultra x5"],
windows: {
"gemini-5h": {
hours: 5,
models: ["gemini"],
},
"gemini-weekly": {
hours: 168,
models: ["gemini"],
},
"3p-5h": {
hours: 5,
models_except: ["gemini"],
},
"3p-weekly": {
hours: 168,
models_except: ["gemini"],
},
},
price_source: { kind: "vendor", url: "https://one.google.com/intl/ALL_us/about/feeds/pricing_2026_07_28.json" },
},
pro: {
price_usd_per_month: 19.99,
tiers: ["g1-pro-tier", "Google AI Pro"],
windows: {
"gemini-5h": {
hours: 5,
models: ["gemini"],
},
"gemini-weekly": {
hours: 168,
models: ["gemini"],
},
"3p-5h": {
hours: 5,
models_except: ["gemini"],
},
"3p-weekly": {
hours: 168,
models_except: ["gemini"],
},
},
price_source: { kind: "vendor", url: "https://one.google.com/intl/ALL_us/about/feeds/pricing_2026_07_28.json" },
},
},
"chatgpt-web": {
pro: {
price_usd_per_month: 200,
windows: {},
cadence: { window_seconds: 43200, limit: 5 },
unmetered: true,
},
},
grok: {
free: {
price_usd_per_month: 0,
tiers: ["Free", "Free Tier", "FreeTier"],
windows: {},
price_source: { kind: "vendor", url: "https://docs.x.ai/x-subscription/pricing" },
},
plus: {
price_usd_per_month: 8,
tiers: ["Plus", "X Subscription Plus", "The X Subscription Plus"],
windows: {},
price_source: { kind: "vendor", url: "https://docs.x.ai/x-subscription/pricing" },
},
premium: {
price_usd_per_month: 30,
tiers: ["Premium", "X Subscription Premium", "The X Subscription Premium", "SuperGrok", "GrokPro", "Grok Pro"],
windows: {},
price_source: { kind: "vendor", url: "https://docs.x.ai/x-subscription/pricing" },
},
super: {
price_usd_per_month: 100,
tiers: ["Super", "X Subscription Super", "The X Subscription Super"],
windows: {},
price_source: { kind: "vendor", url: "https://docs.x.ai/x-subscription/pricing" },
},
ultra: {
price_usd_per_month: 200,
tiers: ["Ultra", "X Subscription Ultra", "The X Subscription Ultra"],
windows: {},
price_source: { kind: "vendor", url: "https://docs.x.ai/x-subscription/pricing" },
},
},
};
// END GENERATED by scripts/sync-catalog.mjs
// ---------------------------------------------------------------------------- the one model-name resolver
/** A `:effort` suffix names an effort, not a vendor tag: `claude-opus-5-5:medium` asks for Medium. */
export const EFFORT_SUFFIXES = ["none", "minimal", "default", "low", "medium", "high", "xhigh", "max", "ultra"];
const COLON_EFFORT_RE = new RegExp(`^(.+):(${EFFORT_SUFFIXES.join("|")})$`, "i");
const DASH_EFFORT_RE = new RegExp(`^(.+)-(${EFFORT_SUFFIXES.join("|")})$`);
const VENDOR_TAG_RE = /(?:@\d{8}|-\d{8}|-\d{4}-\d{2}-\d{2}|:\w+|\[\w+\]|-(?:latest|preview))$/;
/** How a name reached its row: `family` and `unknown` carry no scores of their own. */
export const DIRECT_SOURCES = ["exact", "alias"];
/** `("claude-opus-5-5", "medium")` for `claude-opus-5-5:medium`; `(raw, null)` without an effort suffix. */
export function splitEffortSuffix(rawModel) {
const name = String(rawModel ?? "").trim();
const match = COLON_EFFORT_RE.exec(name);
return match ? { name: match[1], effort: match[2].toLowerCase() } : { name, effort: null };
}
const isRow = (value) => value && typeof value === "object" && !Array.isArray(value);
const knownNames = (models) => new Set(Object.keys(models || {}).filter((key) => isRow(models[key])));
const regexes = new Map();
function familyRegex(pattern) {
// The patterns are Python's `re.search`; every one the catalogue ships is valid for both engines.
if (!regexes.has(pattern)) regexes.set(pattern, new RegExp(pattern));
return regexes.get(pattern);
}
/**
* The one model-name resolver (`model_resolution.resolve_model`): `{ key, source, effort, bare }`.
* `source`: `exact` (the catalogue has this name), `alias` (another spelling of a row: provider prefix, case, date, `-latest`,
* `-preview`, a vendor tag, an effort suffix or a listed alias), `family` (a different model of a known family, scored as an
* estimate of its target), `unknown` (`key: null`, no scores). `effort` is what the name itself asked for.
*/
export function resolveModel(rawModel, models = MODELS, aliases = MODEL_ALIASES, families = FAMILIES) {
const known = knownNames(models);
const table = aliases || {};
const exact = (candidate) => {
const seen = new Set();
let name = candidate;
while (Object.prototype.hasOwnProperty.call(table, name) && !seen.has(name)) {
seen.add(name);
name = table[name];
}
return known.has(name) ? name : null;
};
const { name: raw, effort } = splitEffortSuffix(rawModel);
let name = raw.split("/").pop().toLowerCase();
const found = (key, source, namedEffort = null) => ({ key, source, effort: effort || namedEffort, bare: name });
let match = exact(raw);
if (match) return found(match, match === raw ? "exact" : "alias");
for (const candidate of [raw.split("/").pop(), raw.toLowerCase(), name]) {
match = exact(candidate);
if (match) return found(match, "alias");
}
for (;;) {
const stripped = name.replace(VENDOR_TAG_RE, "");
if (stripped === name) break;
name = stripped;
match = exact(name);
if (match) return found(match, "alias");
}
const dashed = DASH_EFFORT_RE.exec(name);
if (dashed) {
match = exact(dashed[1]);
if (match) return found(match, "alias", dashed[2]);
}
const row = (families || []).find((f) => familyRegex(f.pattern).test(name));
if (row) {
const target = row.models.find((t) => known.has(t));
return found(target || null, target ? "family" : "unknown");
}
for (const prefix of [...known].sort((a, b) => b.length - a.length || (a < b ? -1 : 1))) {
// A delimiter keeps gpt-6.10 from matching gpt-6.1.
if (name.startsWith(`${prefix}-`) || name.startsWith(`${prefix}:`)) {
match = exact(prefix);
if (match) return found(match, "family");
}
}
return found(null, "unknown");
}
/** The key of `rawModel` when it is a model (`exact`, `alias`); the name as given for a family guess or an unknown name, which is its own model. */
export function canonicalModel(rawModel, aliases = MODEL_ALIASES, models = MODELS, families = FAMILIES) {
if (!rawModel || typeof rawModel !== "string") return "";
const resolved = resolveModel(rawModel, models, aliases, families);
return (DIRECT_SOURCES.includes(resolved.source) && resolved.key) || rawModel;
}
/** The leaf of a model name, without provider prefix or effort suffix. */
export function modelLeaf(rawModel) {
return splitEffortSuffix(rawModel).name.split("/").pop();
}
/**
* Which model a row runs: the resolved key for a row's own name or another spelling of it, its own leaf for a family guess or
* an unknown name. A family guess folds to its target only for its estimated score; two rows are one model only when this
* says so (`account_fleet.row_key`).
*/
export function rowKey(rawModel, models = MODELS, aliases = MODEL_ALIASES, families = FAMILIES) {
const resolved = resolveModel(rawModel, models, aliases, families);
return DIRECT_SOURCES.includes(resolved.source) ? resolved.key : modelLeaf(rawModel).toLowerCase();
}
/** The model's row for a name that is one (`exact`, `alias`); `{}` for a family guess or an unknown name: no scores, no price. */
export function modelSpec(rawModel, models = MODELS, aliases = MODEL_ALIASES, families = FAMILIES) {
const resolved = resolveModel(rawModel, models, aliases, families);
const row = DIRECT_SOURCES.includes(resolved.source) ? models[resolved.key] : null;
return isRow(row) ? row : {};
}
/**
* What a failure counts against. An `exact` or `alias` name is its row. A `family` or `unknown` name is only itself: a family
* row is an estimate of its target, so a preview that fails says nothing about the flagship it was placed on.
*/
export function healthKey(rawModel, models = MODELS, aliases = MODEL_ALIASES, families = FAMILIES) {
if (!rawModel || typeof rawModel !== "string") return "";
const { key, source } = resolveModel(rawModel, models, aliases, families);
if (DIRECT_SOURCES.includes(source)) return key;
return modelLeaf(rawModel).toLowerCase();
}
/**
* Whether a launch id runs at one effort only (`candidate_eval.has_fixed_effort`): `model:effort`, or `model-effort` where the
* base is a calibrated row (`gemini-4-argon-high`). `-max` is also a size name (`qwen3-max`), so it splits only on a base the
* catalogue knows.
*/
export function nameFixesEffort(rawModel, models = MODELS, aliases = MODEL_ALIASES) {
const { name, effort } = splitEffortSuffix(rawModel);
if (effort) return true;
const match = /^(.+?)-(minimal|low|medium|high|xhigh|max)$/.exec(name);
if (!match) return false;
return match[2] !== "max" || match[1] in (models || {}) || match[1] in (aliases || {});
}
const MAX_NAME_IN_TEXT = 128;
/** Control characters as text, so a name can start no line of its own in a log. */
export function escapeControls(text) {
return String(text).replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
}
/** A model name fit to put in a log or an error: under `routeAllModels` and in a pin, the request wrote it. */
export function safeName(name) {
const text = String(name);
return escapeControls(text.length > MAX_NAME_IN_TEXT ? `${text.slice(0, MAX_NAME_IN_TEXT)}...` : text);
}
/** Starts every `catalogNameWarning`, so a host can log each once rather than on every request. */
export const CATALOG_NAME_WARNING = "candidate name ";
/** Why a pool name is not routed on a row of its own, or `null` when it has one. */
export function catalogNameWarning(rawModel, models = MODELS, aliases = MODEL_ALIASES, families = FAMILIES) {
const { key, source } = resolveModel(rawModel, models, aliases, families);
if (DIRECT_SOURCES.includes(source)) return null;
const { name } = splitEffortSuffix(rawModel);
const scored =
source === "family"
? `scored as an estimate of ${key} (its same-series row)`
: "no scores: a demanded category is a data error, so it leaves automatic routing (name it to dispatch it)";
return `${CATALOG_NAME_WARNING}${safeName(name)} is not in the catalog: ${scored}`;
}
/**
* `round(value, digits)` as Python does it: the double's exact value decides, and an exact tie goes to the even digit.
* `Math.round(x * 1000)` rounds the product instead, and 0.7625 lands on the other side of it.
*/
export function pyRound(value, digits) {
const number = Number(value);
const scaled = Math.abs(number) * 10 ** digits;
if (Math.abs(scaled - Math.floor(scaled) - 0.5) > 1e-6) return Number(number.toFixed(digits)) + 0;
const exact = number.toFixed(digits + 60);
const cut = exact.indexOf(".") + 1 + digits;
if (!/^50*$/.test(exact.slice(cut)) || Number(exact[cut - 1]) % 2 === 1) return Number(number.toFixed(digits)) + 0;
return Number(exact.slice(0, cut)) + 0;
}