@agentproto/model-catalog 0.12.6 → 0.13.0
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/access/index.mjs +4 -4
- package/dist/{chunk-KYJLELLO.mjs → chunk-3WNSSJTB.mjs} +3 -3
- package/dist/{chunk-KYJLELLO.mjs.map → chunk-3WNSSJTB.mjs.map} +1 -1
- package/dist/{chunk-VDHRRWLK.mjs → chunk-H2TPFH4A.mjs} +5 -5
- package/dist/{chunk-VDHRRWLK.mjs.map → chunk-H2TPFH4A.mjs.map} +1 -1
- package/dist/{chunk-XMQXJNZO.mjs → chunk-JMEDHOCQ.mjs} +170 -48
- package/dist/chunk-JMEDHOCQ.mjs.map +1 -0
- package/dist/{chunk-DM77NOWF.mjs → chunk-LMY5TLSF.mjs} +4 -4
- package/dist/{chunk-DM77NOWF.mjs.map → chunk-LMY5TLSF.mjs.map} +1 -1
- package/dist/{chunk-SKSUC4MT.mjs → chunk-PITHETND.mjs} +3 -3
- package/dist/{chunk-SKSUC4MT.mjs.map → chunk-PITHETND.mjs.map} +1 -1
- package/dist/{chunk-XZXZXU6H.mjs → chunk-S27LMEYZ.mjs} +160 -127
- package/dist/chunk-S27LMEYZ.mjs.map +1 -0
- package/dist/{chunk-CON7JITC.mjs → chunk-TWTG323Z.mjs} +5 -4
- package/dist/chunk-TWTG323Z.mjs.map +1 -0
- package/dist/{chunk-44OPAHZ7.mjs → chunk-XP2KTH6U.mjs} +4 -4
- package/dist/{chunk-44OPAHZ7.mjs.map → chunk-XP2KTH6U.mjs.map} +1 -1
- package/dist/cost/index.mjs +6 -6
- package/dist/curation/index.mjs +6 -6
- package/dist/defaults-BDkNRPK8.d.ts +50 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +10 -10
- package/dist/index.mjs.map +1 -1
- package/dist/llm/index.d.ts +2 -44
- package/dist/llm/index.mjs +2 -2
- package/dist/route-identity/index.mjs +2 -2
- package/package.json +5 -5
- package/dist/chunk-CON7JITC.mjs.map +0 -1
- package/dist/chunk-XMQXJNZO.mjs.map +0 -1
- package/dist/chunk-XZXZXU6H.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OPENCODE_GO_ROUTES, OPENCODE_ZEN_ROUTES, OPENCODE_GO_ANTHROPIC_MODELS, OPENCODE_ZEN_ANTHROPIC_MODELS } from './chunk-
|
|
1
|
+
import { OPENCODE_GO_ROUTES, OPENCODE_ZEN_ROUTES, OPENCODE_GO_ANTHROPIC_MODELS, OPENCODE_ZEN_ANTHROPIC_MODELS } from './chunk-S27LMEYZ.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @agentproto/model-catalog v0.1.0
|
|
@@ -33,6 +33,7 @@ function formatTokens(n) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// src/llm/defaults.ts
|
|
36
|
+
var DEFAULT_ANTHROPIC_MODEL = "claude-sonnet-5-5";
|
|
36
37
|
var WORKFLOW_FAST_MODEL = "claude-sonnet-4-6";
|
|
37
38
|
var WORKFLOW_PREMIUM_MODEL = "claude-opus-4-6";
|
|
38
39
|
var WORKFLOW_TINY_MODEL = "claude-haiku-4-5-20251001";
|
|
@@ -75,6 +76,6 @@ var LLM_TIERS = {
|
|
|
75
76
|
]
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
export { LLM_TIERS, OPERATOR_AGENT_MODELS, OPERATOR_DEFAULT_GEMINI, OPERATOR_DEFAULT_PREMIUM, OPERATOR_DEFAULT_STANDARD, WORKFLOW_FAST_MODEL, WORKFLOW_PREMIUM_MODEL, WORKFLOW_TINY_MODEL, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs };
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
export { DEFAULT_ANTHROPIC_MODEL, LLM_TIERS, OPERATOR_AGENT_MODELS, OPERATOR_DEFAULT_GEMINI, OPERATOR_DEFAULT_PREMIUM, OPERATOR_DEFAULT_STANDARD, WORKFLOW_FAST_MODEL, WORKFLOW_PREMIUM_MODEL, WORKFLOW_TINY_MODEL, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs };
|
|
80
|
+
//# sourceMappingURL=chunk-TWTG323Z.mjs.map
|
|
81
|
+
//# sourceMappingURL=chunk-TWTG323Z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/llm/opencode.ts","../src/llm/tokens.ts","../src/llm/defaults.ts"],"names":[],"mappings":";;;;;;;;;AAiCO,SAAS,sBAAsB,QAAA,EAAsC;AAC1E,EAAA,MAAM,MAAA,GAAS,QAAA,KAAa,aAAA,GAAgB,kBAAA,GAAqB,mBAAA;AACjE,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAAE,IAAA,EAAK;AAClC;AAkBO,SAAS,+BAA+B,QAAA,EAAsC;AACnF,EAAA,MAAM,OAAA,GACJ,QAAA,KAAa,aAAA,GAAgB,4BAAA,GAA+B,6BAAA;AAC9D,EAAA,OAAO,OAAA,CAAQ,IAAI,CAAA,EAAA,KAAM,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA,CAAE,IAAA,EAAK;AACrD;;;ACjDO,SAAS,aAAa,CAAA,EAAsC;AACjE,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,CAAA,IAAK,GAAG,OAAO,IAAA;AAC5C,EAAA,IAAI,KAAK,GAAA,EAAW;AAClB,IAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,IAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,CAAC,CAAA,GAAI,OAAO,CAAC,CAAA,GAAI,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAA;AAC1D,IAAA,OAAO,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,EAChB;AACA,EAAA,IAAI,KAAK,GAAA,EAAO;AACd,IAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,IAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,CAAC,CAAA,GAAI,OAAO,CAAC,CAAA,GAAI,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAA;AAC1D,IAAA,OAAO,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,EAChB;AACA,EAAA,OAAO,OAAO,CAAC,CAAA;AACjB;;;ACJO,IAAM,uBAAA,GAA0B;AAGhC,IAAM,mBAAA,GAAsB;AAG5B,IAAM,sBAAA,GAAyB;AAG/B,IAAM,mBAAA,GAAsB;AAO5B,IAAM,qBAAA,GAAwB;AAAA,EACnC,iBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF;AAKO,IAAM,wBAAA,GAA+C;AACrD,IAAM,yBAAA,GAAgD;AACtD,IAAM,uBAAA,GACX;AAcK,IAAM,SAAA,GAAY;AAAA;AAAA,EAEvB,IAAA,EAAM,CAAC,+BAA+B,CAAA;AAAA;AAAA,EAEtC,IAAA,EAAM;AAAA,IACJ,cAAA;AAAA,IACA,cAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,IAAA,EAAM;AAAA,IACJ,kBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,IAAA,EAAM;AAAA,IACJ,mBAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,GAAA,EAAK;AAAA,IACH,iBAAA;AAAA,IACA,+BAAA;AAAA,IACA;AAAA;AAEJ","file":"chunk-TWTG323Z.mjs","sourcesContent":["/**\n * OpenCode's two hosted endpoints — the small hand-written surface over their\n * generated route tables.\n *\n * Deliberately its OWN module rather than an addition to `catalog.ts`: that\n * file owns `LLM_PRICING_CATALOG`, and the one invariant these tables have is\n * that they are NEVER spread into it (a bare `claude-sonnet-5` must keep\n * meaning direct Anthropic, not a Zen-priced route — see the OpenCode branch\n * in `route-identity/index.ts`). Keeping the import out of `catalog.ts`\n * keeps that temptation out of reach.\n */\n\nimport {\n OPENCODE_GO_ANTHROPIC_MODELS,\n OPENCODE_GO_ROUTES,\n} from \"./opencode-go-routes.generated.js\"\nimport {\n OPENCODE_ZEN_ANTHROPIC_MODELS,\n OPENCODE_ZEN_ROUTES,\n} from \"./opencode-zen-routes.generated.js\"\n\n/**\n * The two OpenCode hosted endpoints, by catalog provider id.\n * - `\"opencode\"` — OpenCode Zen, pay-as-you-go (`.../zen/v1`).\n * - `\"opencode-go\"` — OpenCode Go, the flat subscription (`.../zen/go/v1`).\n */\nexport type OpencodeEndpoint = \"opencode\" | \"opencode-go\"\n\n/**\n * Every model ref an OpenCode endpoint serves, in the `<provider>/<bare-id>`\n * form the route tables are keyed by — which is also opencode's own config\n * spelling and what a caller passes to `agent_start`.\n */\nexport function listOpencodeModelRefs(endpoint: OpencodeEndpoint): string[] {\n const routes = endpoint === \"opencode-go\" ? OPENCODE_GO_ROUTES : OPENCODE_ZEN_ROUTES\n return Object.keys(routes).sort()\n}\n\n/**\n * The subset of {@link listOpencodeModelRefs} whose wire surface is the\n * Anthropic Messages API — exactly what the matching `opencode` /\n * `opencode-go` gateway preset can serve, and therefore exactly what an\n * Anthropic-native adapter (claude-code / claude-sdk) may offer on that\n * route. Both endpoints also serve OpenAI chat/completions, OpenAI Responses\n * and (Zen only) Gemini models behind the same base URL; those are\n * unreachable from an Anthropic client and are excluded here.\n *\n * Derived from the generated `*_ANTHROPIC_MODELS` lists, which come from the\n * source's own per-model `provider.npm` discriminator — so an adapter menu\n * built on this can never drift into offering an id the endpoint won't answer\n * on `/v1/messages`, and a newly-added Anthropic-surface model becomes\n * offerable on the next catalog-sync run with no code change (the same\n * rationale as `listNativeModelIds`).\n */\nexport function listOpencodeAnthropicModelRefs(endpoint: OpencodeEndpoint): string[] {\n const bareIds =\n endpoint === \"opencode-go\" ? OPENCODE_GO_ANTHROPIC_MODELS : OPENCODE_ZEN_ANTHROPIC_MODELS\n return bareIds.map(id => `${endpoint}/${id}`).sort()\n}\n","/**\n * Shared human-readable token formatting, so the `agentproto models` CLI and\n * the `catalog_models` MCP tool render the same `1M`/`200k` shapes instead of\n * raw integers. Lives next to `resolveContextWindow` (its data source) — one\n * formatter per concept, both output surfaces consume it.\n */\n\n/** Format a token count compactly — `1M`, `500k`, `2k`, `448`. Undefined ⇒\n * null so JSON output omits rather than fabricates a value. */\nexport function formatTokens(n: number | undefined): string | null {\n if (typeof n !== \"number\" || n <= 0) return null\n if (n >= 1_000_000) {\n const m = n / 1_000_000\n const text = Number.isInteger(m) ? String(m) : m.toFixed(1)\n return `${text}M`\n }\n if (n >= 1_000) {\n const k = n / 1_000\n const text = Number.isInteger(k) ? String(k) : k.toFixed(1)\n return `${text}k`\n }\n return String(n)\n}\n","/**\n * Curated, SDK-ready LLM model ids.\n *\n * Centralizes the version-specific provider ids used at runtime so call\n * sites stop carrying string literals. Pricing for each is resolved\n * automatically through `MODEL_ALIASES` in `catalog.ts` (e.g.\n * `claude-sonnet-4-6` → `claude-sonnet-4-5`).\n *\n * Update one constant here when bumping the platform-wide default —\n * every workflow step and operator config picks up the new id with a\n * single rebuild.\n */\n\n/**\n * Canonical Anthropic default used by the adapter manifests (`AIP-45`\n * `models.default`, in `provider/id` form). Single source of truth for the\n * platform-wide Claude default — bump here, not in each manifest.\n */\nexport const DEFAULT_ANTHROPIC_MODEL = \"claude-sonnet-5-5\" as const\n\n/** Fast workhorse for content workflows (outline, post, sections). */\nexport const WORKFLOW_FAST_MODEL = \"claude-sonnet-4-6\" as const\n\n/** Premium tier for high-stakes generation (rarely used in workflows). */\nexport const WORKFLOW_PREMIUM_MODEL = \"claude-opus-4-6\" as const\n\n/** Cheap-and-quick for short outputs like titles. */\nexport const WORKFLOW_TINY_MODEL = \"claude-haiku-4-5-20251001\" as const\n\n/**\n * Models eligible for operator agents (an app). Keep in sync with the\n * agent-framework's model-provider config. The literal tuple drives the\n * `OperatorAgentModel` union type below.\n */\nexport const OPERATOR_AGENT_MODELS = [\n \"claude-opus-4-5\",\n \"claude-sonnet-4-5\",\n \"gemini-3.1-pro-preview\",\n] as const\n\nexport type OperatorAgentModel = (typeof OPERATOR_AGENT_MODELS)[number]\n\n/** Default operator model when no explicit choice is made. */\nexport const OPERATOR_DEFAULT_PREMIUM: OperatorAgentModel = \"claude-opus-4-5\"\nexport const OPERATOR_DEFAULT_STANDARD: OperatorAgentModel = \"claude-sonnet-4-5\"\nexport const OPERATOR_DEFAULT_GEMINI: OperatorAgentModel =\n \"gemini-3.1-pro-preview\"\n\n// ── Plan-tier → model lists ─────────────────────────────────────────────\n//\n// Catalog-canonical equivalent of agent-framework's `MODEL_TIERS`. Used\n// by per-app `AppPlanRegistry` files as the source list when a plan\n// surfaces \"all of the X tier\". Keeping this in the catalog keeps the\n// app registries declarative — they pick from `LLM_TIERS.plus` rather\n// than re-specifying ids.\n//\n// All ids resolve through `resolvePricing` (direct match → alias →\n// partial-prefix). Names are app-vocabulary-neutral; per-app registries\n// re-key as needed (`PaygoTier.nano` → `LLM_TIERS.nano`, etc.).\n\nexport const LLM_TIERS = {\n /** Cheap-and-quick. Single-model fallback. */\n nano: [\"mistral-small-creative-latest\"] as const,\n /** Low-cost, agentic-capable. Direct alt-providers. */\n mini: [\n \"MiniMax-M2.5\",\n \"MiniMax-M2.1\",\n \"MiniMax-M2\",\n \"mistral-large-latest\",\n ] as const,\n /** Medium cost, fast inference + good general perf. OpenRouter-routed. */\n lite: [\n \"x-ai/grok-4-fast\",\n \"xiaomi/mimo-v2-flash\",\n \"google/gemini-3-flash-preview\",\n ] as const,\n /** High quality, premium features. Mix of direct + OpenRouter. */\n plus: [\n \"claude-sonnet-4-5\",\n \"gpt-4o\",\n \"kimi-k2.5\",\n \"deepseek/deepseek-v3.2\",\n ] as const,\n /** Top-tier, best performance. */\n pro: [\n \"claude-opus-4-5\",\n \"google/gemini-3.1-pro-preview\",\n \"kimi-k2-thinking\",\n ] as const,\n} as const\n\nexport type LlmTierName = keyof typeof LLM_TIERS\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getModel } from './chunk-
|
|
2
|
-
import { calculateLLMCreditCost } from './chunk-
|
|
1
|
+
import { getModel } from './chunk-H2TPFH4A.mjs';
|
|
2
|
+
import { calculateLLMCreditCost } from './chunk-S27LMEYZ.mjs';
|
|
3
3
|
import { computeCenticredits, pricingRegistry } from './chunk-QHELXPSL.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -223,5 +223,5 @@ function calculateAudioCost(modelId, usage, opts) {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
export { CostUsageKindMismatchError, UnknownModelError, calculateAudioCost, calculateCost, calculateImageCost, calculateLLMCost, calculateVideoCost };
|
|
226
|
-
//# sourceMappingURL=chunk-
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
226
|
+
//# sourceMappingURL=chunk-XP2KTH6U.mjs.map
|
|
227
|
+
//# sourceMappingURL=chunk-XP2KTH6U.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cost/index.ts"],"names":["resolved","baseCostUsd","credits","calculatedCredits","markup"],"mappings":";;;;;;;;;;;AAiCA,IAAM,4BAAA,GAAuD;AAAA,EAC3D,OAAA,EAAS,yBAAA;AAAA,EACT,UAAA,EAAY;AACd,CAAA;AAkDO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAC3C,YAA4B,OAAA,EAAiB;AAC3C,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,OAAO,CAAA,CAAA,CAAG,CAAA;AADZ,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAE1B,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AAAA,EAH4B,OAAA;AAI9B;AAEO,IAAM,0BAAA,GAAN,cAAyC,KAAA,CAAM;AAAA,EACpD,WAAA,CACkB,OAAA,EACA,QAAA,EACA,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,EACA,IAAA,EACY;AACZ,EAAA,OAAO,aAAA,CAAc,SAAS,EAAE,IAAA,EAAM,SAAS,GAAG,KAAA,IAAS,IAAI,CAAA;AACjE;AAEO,SAAS,kBAAA,CACd,OAAA,EACA,KAAA,EACA,IAAA,EACY;AACZ,EAAA,OAAO,aAAA,CAAc,SAAS,EAAE,IAAA,EAAM,SAAS,GAAG,KAAA,IAAS,IAAI,CAAA;AACjE;AAEO,SAAS,kBAAA,CACd,OAAA,EACA,KAAA,EACA,IAAA,EACY;AACZ,EAAA,OAAO,aAAA,CAAc,SAAS,EAAE,IAAA,EAAM,SAAS,GAAG,KAAA,IAAS,IAAI,CAAA;AACjE","file":"chunk-44OPAHZ7.mjs","sourcesContent":["/**\n * Cost dispatcher — computes credit cost + production USD cost for any\n * model id, regardless of kind. Single entry point used by orchestrator,\n * billing audits, and (eventually) the metered MCP gen layer.\n *\n * Per-kind formulas:\n * - LLM → reuses `calculateLLMCreditCost` (token math + cache + markup)\n * - Image → `creditCost × numOutputs`\n * - Video → `creditCost × multipliers[resolution|duration|mode]`\n * - Audio → `creditCost × (characters or seconds)` per `billingUnit`\n */\n\nimport {\n calculateLLMCreditCost,\n type LLMCreditCostResult,\n} from \"../llm/index.js\"\nimport { getModel } from \"../registry/index.js\"\nimport { computeCenticredits, pricingRegistry } from \"../pricing/index.js\"\n\n/**\n * Voice metadata → default audio model the dispatcher bills through.\n *\n * Voices are render-targets, not priced units. A MiniMax voice can be\n * played through `minimax/speech-02-hd` OR `…-turbo`; an ElevenLabs\n * voice through any of their model tiers. We default to the cheapest\n * model per provider so a drive-by voice-id call doesn't over-bill.\n * Callers wanting HD / premium-tier pricing should pass the audio\n * model id directly with the voice as metadata — see\n * `text-to-speech.tool.ts` for the canonical pattern.\n *\n * Add a new provider here when a new voice catalog lands (e.g.\n * `ELEVENLABS_VOICES` if/when we surface their voice IDs).\n */\nconst VOICE_PROVIDER_DEFAULT_MODEL: Record<string, string> = {\n minimax: \"minimax/speech-02-turbo\",\n elevenlabs: \"elevenlabs/flash-v2.5\",\n}\n\nexport type CostUsage =\n | {\n kind: \"llm\"\n inputTokens: number\n outputTokens: number\n cacheReadInputTokens?: number\n cacheCreationInputTokens?: number\n }\n | { kind: \"image\"; numOutputs?: number }\n | {\n kind: \"video\"\n resolution?: string\n duration?: number\n mode?: string\n }\n | { kind: \"audio\"; characters?: number; seconds?: number }\n\nexport interface CostResult {\n kind: \"llm\" | \"image\" | \"video\" | \"audio\"\n modelId: string\n /** Canonical model id after alias resolution (LLM only; same as modelId for media) */\n canonicalId: string\n /**\n * Total **centicredits** to charge (1 displayed credit = 100 cc).\n * Honors per-model overrides. Feed straight into the ledger — the\n * `credit_transactions.credits` column stores cc, so no `× 100`\n * conversion at the call site. Format for display with\n * `displayCredits(cc) → cr`.\n */\n credits: number\n /**\n * Centicredits the pure formula (provider cost × category markup)\n * would have charged, independent of any per-model override. Equal\n * to `credits` when no override is in play. Surfaced so\n * reconciliation can diff \"what we did\" vs \"what the formula said\"\n * without recomputing — persisted to `usage_events.calculated_credits`.\n */\n calculatedCredits: number\n /** Production cost in USD (provider-side, before markup) */\n baseCostUsd: number\n /** Per-kind breakdown — inputCredits/outputCredits for LLM, etc. All in cc. */\n breakdown: Record<string, number>\n /** True iff fallback pricing was used (currently LLM-only) */\n isFallback: boolean\n /** Markup applied (1.0 = catalog rate as-is) */\n markup: number\n}\n\nexport class UnknownModelError extends Error {\n constructor(public readonly modelId: string) {\n super(`Unknown model id: \"${modelId}\"`)\n this.name = \"UnknownModelError\"\n }\n}\n\nexport class CostUsageKindMismatchError extends Error {\n constructor(\n public readonly modelId: string,\n public readonly expected: string,\n public readonly got: string\n ) {\n super(\n `Model \"${modelId}\" is kind \"${expected}\", but received usage of kind \"${got}\"`\n )\n this.name = \"CostUsageKindMismatchError\"\n }\n}\n\nexport interface CalculateCostOptions {\n /**\n * App that's invoking the model. Routes per-app markup overrides\n * registered via `pricingRegistry.registerApp(appId, ...)`. When\n * omitted, core defaults apply.\n */\n appId?: string\n}\n\n/**\n * Computes credit + USD cost for a model run.\n *\n * Throws `UnknownModelError` for ids not in any catalog (LLM has its own\n * fallback path inside `calculateLLMCreditCost` — this surface preserves\n * that for back-compat).\n *\n * Throws `CostUsageKindMismatchError` if `usage.kind` doesn't match the\n * resolved model's kind (data integrity guard).\n *\n * Image / video / audio credits are derived at call time via the\n * pricing registry (`provider_cost × category-markup`). LLM keeps its\n * own per-model markup table inside `calculateLLMCreditCost` —\n * collapsing that follows in W6b.\n */\nexport function calculateCost(\n modelId: string,\n usage: CostUsage,\n opts: CalculateCostOptions = {}\n): CostResult {\n // LLM has a fallback path that returns valid pricing even for unknown\n // ids (preserves the orchestrator's existing tolerance). Other kinds\n // throw for unknowns.\n if (usage.kind === \"llm\") {\n const llmResult: LLMCreditCostResult = calculateLLMCreditCost(modelId, {\n inputTokens: usage.inputTokens,\n outputTokens: usage.outputTokens,\n cacheReadInputTokens: usage.cacheReadInputTokens,\n cacheCreationInputTokens: usage.cacheCreationInputTokens,\n })\n const resolved = getModel(modelId)\n const canonicalId =\n resolved && resolved.kind === \"llm\" ? resolved.canonicalId : modelId\n return {\n kind: \"llm\",\n modelId,\n canonicalId,\n credits: llmResult.credits,\n calculatedCredits: llmResult.calculatedCredits,\n baseCostUsd: llmResult.productionCost,\n breakdown: {\n inputCredits: llmResult.inputCredits,\n outputCredits: llmResult.outputCredits,\n cacheReadCredits: llmResult.cacheReadCredits,\n cacheWriteCredits: llmResult.cacheWriteCredits,\n },\n isFallback: llmResult.isFallback,\n markup: llmResult.markup,\n }\n }\n\n const resolved = getModel(modelId)\n if (!resolved) throw new UnknownModelError(modelId)\n // `voice` is structurally audio for billing purposes (MiniMax voice\n // metadata billed via per-character output). Accept `audio` usage on\n // voice models so the per-kind branches below can pattern-match.\n const expectedUsageKind: CostUsage[\"kind\"] =\n resolved.kind === \"voice\" ? \"audio\" : resolved.kind\n if (expectedUsageKind !== usage.kind) {\n // Pass `expectedUsageKind` (not `resolved.kind`) so the error message\n // accurately says \"audio\" rather than \"voice\" when a voice model is\n // billed — the caller must supply audio usage, not voice usage.\n throw new CostUsageKindMismatchError(modelId, expectedUsageKind, usage.kind)\n }\n\n if (resolved.kind === \"image\") {\n // `usage.kind` is \"image\" here (guarded above) but TS won't cross-narrow\n // it from `resolved.kind`, so check explicitly before reading numOutputs.\n const numOutputs = Math.max(\n 1,\n usage.kind === \"image\" ? (usage.numOutputs ?? 1) : 1\n )\n const baseCostUsd = resolved.def.pricing.baseCost * numOutputs\n const perOutputCredits = computeCenticredits({\n baseCostUsd: resolved.def.pricing.baseCost,\n category: \"image\",\n overrideCreditCost: resolved.def.pricing.overrideCreditCost,\n appId: opts.appId,\n })\n const credits = perOutputCredits * numOutputs\n // Formula-only (ignores override) — for `usage_events.calculated_credits`.\n const formulaPerOutput = computeCenticredits({\n baseCostUsd: resolved.def.pricing.baseCost,\n category: \"image\",\n appId: opts.appId,\n })\n const calculatedCredits = formulaPerOutput * numOutputs\n const markup = pricingRegistry.getMarkup(\"image\", opts.appId)\n return {\n kind: \"image\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perOutputCredits,\n numOutputs,\n },\n isFallback: false,\n markup,\n }\n }\n\n if (resolved.kind === \"video\") {\n if (usage.kind !== \"video\") {\n throw new CostUsageKindMismatchError(modelId, \"video\", usage.kind)\n }\n const pricing = resolved.def.pricing\n // Provider-side multipliers — re-applied to BOTH the provider cost\n // (what we pay) AND the derived credit cost (so margin holds).\n const mult = pricing.multipliers\n const resMult =\n usage.resolution && mult?.resolution\n ? (mult.resolution[usage.resolution] ?? 1.0)\n : 1.0\n const durMult =\n usage.duration && mult?.duration\n ? (mult.duration[usage.duration] ?? 1.0)\n : 1.0\n const modMult =\n usage.mode && mult?.mode ? (mult.mode[usage.mode] ?? 1.0) : 1.0\n const variantMultiplier = resMult * durMult * modMult\n const baseCostUsd = pricing.baseCost * variantMultiplier\n const perClipCredits = computeCenticredits({\n baseCostUsd: pricing.baseCost,\n category: \"video\",\n overrideCreditCost: pricing.overrideCreditCost,\n appId: opts.appId,\n })\n const credits = Math.ceil(perClipCredits * variantMultiplier)\n const formulaPerClip = computeCenticredits({\n baseCostUsd: pricing.baseCost,\n category: \"video\",\n appId: opts.appId,\n })\n const calculatedCredits = Math.ceil(formulaPerClip * variantMultiplier)\n const markup = pricingRegistry.getMarkup(\"video\", opts.appId)\n return {\n kind: \"video\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perClipCredits,\n resolutionMultiplier: resMult,\n durationMultiplier: durMult,\n modeMultiplier: modMult,\n variantMultiplier,\n },\n isFallback: false,\n markup,\n }\n }\n\n // Audio (and voice, delegated as audio — see expectedUsageKind above).\n if (usage.kind !== \"audio\") {\n throw new CostUsageKindMismatchError(modelId, \"audio\", usage.kind)\n }\n\n if (resolved.kind === \"voice\") {\n // Voice rows are metadata; delegate to the provider's default audio model.\n const provider = resolved.voice.provider\n const delegateModelId = VOICE_PROVIDER_DEFAULT_MODEL[provider]\n if (!delegateModelId) throw new UnknownModelError(modelId)\n const delegateResult = calculateCost(delegateModelId, usage, opts)\n return {\n ...delegateResult,\n modelId,\n canonicalId: delegateModelId,\n }\n }\n\n // Only `audio` remains (llm returned at top; image/video/voice handled\n // above). Narrow explicitly so `.def` is type-safe.\n if (resolved.kind !== \"audio\") throw new UnknownModelError(modelId)\n const audioPricing = resolved.def.pricing\n // Map the provider's billing unit to a quantity of billable units.\n // The catalog DATA uses `per_1k_chars` (chars ÷ 1000) and `per_minute`\n // (whole minutes, rounded UP to match provider invoicing). `per_character`\n // / `per_second` are handled too so a future data migration to those units\n // keeps working. NOTE: do not switch on the zod enum value alone — the\n // audio schema enum is stale (`per_character|per_second`) while the data\n // still ships `per_1k_chars|per_minute`; trusting the enum bills 0.\n const billingUnit = audioPricing.billingUnit as string\n let quantity: number\n switch (billingUnit) {\n case \"per_1k_chars\":\n quantity = Math.max(0, usage.characters ?? 0) / 1000\n break\n case \"per_character\":\n quantity = Math.max(0, usage.characters ?? 0)\n break\n case \"per_minute\":\n quantity = Math.ceil(Math.max(0, usage.seconds ?? 0) / 60)\n break\n case \"per_second\":\n default:\n quantity = Math.max(0, usage.seconds ?? 0)\n break\n }\n const baseCostUsd = audioPricing.baseCost * quantity\n const perUnitCredits = computeCenticredits({\n baseCostUsd: audioPricing.baseCost,\n category: \"audio\",\n overrideCreditCost: audioPricing.overrideCreditCost,\n appId: opts.appId,\n })\n // Per-call floor (1 cc) so a non-empty call never rounds to 0; a genuinely\n // empty call (quantity 0, e.g. empty-string TTS) bills nothing.\n const credits =\n quantity > 0 ? Math.max(1, Math.ceil(perUnitCredits * quantity)) : 0\n const formulaPerUnit = computeCenticredits({\n baseCostUsd: audioPricing.baseCost,\n category: \"audio\",\n appId: opts.appId,\n })\n const calculatedCredits =\n quantity > 0 ? Math.max(1, Math.ceil(formulaPerUnit * quantity)) : 0\n const markup = pricingRegistry.getMarkup(\"audio\", opts.appId)\n return {\n kind: \"audio\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perUnitCredits,\n quantity,\n },\n isFallback: false,\n markup,\n }\n}\n\n// Thin ergonomic wrappers around `calculateCost`. Two reasons they exist:\n// 1. Callers with a known kind don't want to construct the full union.\n// 2. The kind/usage union is a `calculateCost` implementation detail —\n// wrapper types are narrower and easier to read at call sites.\n\nexport function calculateLLMCost(\n modelId: string,\n usage: {\n inputTokens: number\n outputTokens: number\n cacheReadInputTokens?: number\n cacheCreationInputTokens?: number\n },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"llm\", ...usage }, opts)\n}\n\nexport function calculateImageCost(\n modelId: string,\n usage: { numOutputs?: number },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"image\", ...usage }, opts)\n}\n\nexport function calculateVideoCost(\n modelId: string,\n usage: { resolution?: string; duration?: number; mode?: string },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"video\", ...usage }, opts)\n}\n\nexport function calculateAudioCost(\n modelId: string,\n usage: { characters?: number; seconds?: number },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"audio\", ...usage }, opts)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/cost/index.ts"],"names":["resolved","baseCostUsd","credits","calculatedCredits","markup"],"mappings":";;;;;;;;;;;AAiCA,IAAM,4BAAA,GAAuD;AAAA,EAC3D,OAAA,EAAS,yBAAA;AAAA,EACT,UAAA,EAAY;AACd,CAAA;AAkDO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAC3C,YAA4B,OAAA,EAAiB;AAC3C,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,OAAO,CAAA,CAAA,CAAG,CAAA;AADZ,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAE1B,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AAAA,EAH4B,OAAA;AAI9B;AAEO,IAAM,0BAAA,GAAN,cAAyC,KAAA,CAAM;AAAA,EACpD,WAAA,CACkB,OAAA,EACA,QAAA,EACA,GAAA,EAChB;AACA,IAAA,KAAA;AAAA,MACE,CAAA,OAAA,EAAU,OAAO,CAAA,WAAA,EAAc,QAAQ,kCAAkC,GAAG,CAAA,CAAA;AAAA,KAC9E;AANgB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAKhB,IAAA,IAAA,CAAK,IAAA,GAAO,4BAAA;AAAA,EACd;AAAA,EARkB,OAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAOpB;AA0BO,SAAS,aAAA,CACd,OAAA,EACA,KAAA,EACA,IAAA,GAA6B,EAAC,EAClB;AAIZ,EAAA,IAAI,KAAA,CAAM,SAAS,KAAA,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cost for any\n * model id, regardless of kind. Single entry point used by orchestrator,\n * billing audits, and (eventually) the metered MCP gen layer.\n *\n * Per-kind formulas:\n * - LLM → reuses `calculateLLMCreditCost` (token math + cache + markup)\n * - Image → `creditCost × numOutputs`\n * - Video → `creditCost × multipliers[resolution|duration|mode]`\n * - Audio → `creditCost × (characters or seconds)` per `billingUnit`\n */\n\nimport {\n calculateLLMCreditCost,\n type LLMCreditCostResult,\n} from \"../llm/index.js\"\nimport { getModel } from \"../registry/index.js\"\nimport { computeCenticredits, pricingRegistry } from \"../pricing/index.js\"\n\n/**\n * Voice metadata → default audio model the dispatcher bills through.\n *\n * Voices are render-targets, not priced units. A MiniMax voice can be\n * played through `minimax/speech-02-hd` OR `…-turbo`; an ElevenLabs\n * voice through any of their model tiers. We default to the cheapest\n * model per provider so a drive-by voice-id call doesn't over-bill.\n * Callers wanting HD / premium-tier pricing should pass the audio\n * model id directly with the voice as metadata — see\n * `text-to-speech.tool.ts` for the canonical pattern.\n *\n * Add a new provider here when a new voice catalog lands (e.g.\n * `ELEVENLABS_VOICES` if/when we surface their voice IDs).\n */\nconst VOICE_PROVIDER_DEFAULT_MODEL: Record<string, string> = {\n minimax: \"minimax/speech-02-turbo\",\n elevenlabs: \"elevenlabs/flash-v2.5\",\n}\n\nexport type CostUsage =\n | {\n kind: \"llm\"\n inputTokens: number\n outputTokens: number\n cacheReadInputTokens?: number\n cacheCreationInputTokens?: number\n }\n | { kind: \"image\"; numOutputs?: number }\n | {\n kind: \"video\"\n resolution?: string\n duration?: number\n mode?: string\n }\n | { kind: \"audio\"; characters?: number; seconds?: number }\n\nexport interface CostResult {\n kind: \"llm\" | \"image\" | \"video\" | \"audio\"\n modelId: string\n /** Canonical model id after alias resolution (LLM only; same as modelId for media) */\n canonicalId: string\n /**\n * Total **centicredits** to charge (1 displayed credit = 100 cc).\n * Honors per-model overrides. Feed straight into the ledger — the\n * `credit_transactions.credits` column stores cc, so no `× 100`\n * conversion at the call site. Format for display with\n * `displayCredits(cc) → cr`.\n */\n credits: number\n /**\n * Centicredits the pure formula (provider cost × category markup)\n * would have charged, independent of any per-model override. Equal\n * to `credits` when no override is in play. Surfaced so\n * reconciliation can diff \"what we did\" vs \"what the formula said\"\n * without recomputing — persisted to `usage_events.calculated_credits`.\n */\n calculatedCredits: number\n /** Production cost in USD (provider-side, before markup) */\n baseCostUsd: number\n /** Per-kind breakdown — inputCredits/outputCredits for LLM, etc. All in cc. */\n breakdown: Record<string, number>\n /** True iff fallback pricing was used (currently LLM-only) */\n isFallback: boolean\n /** Markup applied (1.0 = catalog rate as-is) */\n markup: number\n}\n\nexport class UnknownModelError extends Error {\n constructor(public readonly modelId: string) {\n super(`Unknown model id: \"${modelId}\"`)\n this.name = \"UnknownModelError\"\n }\n}\n\nexport class CostUsageKindMismatchError extends Error {\n constructor(\n public readonly modelId: string,\n public readonly expected: string,\n public readonly got: string\n ) {\n super(\n `Model \"${modelId}\" is kind \"${expected}\", but received usage of kind \"${got}\"`\n )\n this.name = \"CostUsageKindMismatchError\"\n }\n}\n\nexport interface CalculateCostOptions {\n /**\n * App that's invoking the model. Routes per-app markup overrides\n * registered via `pricingRegistry.registerApp(appId, ...)`. When\n * omitted, core defaults apply.\n */\n appId?: string\n}\n\n/**\n * Computes credit + USD cost for a model run.\n *\n * Throws `UnknownModelError` for ids not in any catalog (LLM has its own\n * fallback path inside `calculateLLMCreditCost` — this surface preserves\n * that for back-compat).\n *\n * Throws `CostUsageKindMismatchError` if `usage.kind` doesn't match the\n * resolved model's kind (data integrity guard).\n *\n * Image / video / audio credits are derived at call time via the\n * pricing registry (`provider_cost × category-markup`). LLM keeps its\n * own per-model markup table inside `calculateLLMCreditCost` —\n * collapsing that follows in W6b.\n */\nexport function calculateCost(\n modelId: string,\n usage: CostUsage,\n opts: CalculateCostOptions = {}\n): CostResult {\n // LLM has a fallback path that returns valid pricing even for unknown\n // ids (preserves the orchestrator's existing tolerance). Other kinds\n // throw for unknowns.\n if (usage.kind === \"llm\") {\n const llmResult: LLMCreditCostResult = calculateLLMCreditCost(modelId, {\n inputTokens: usage.inputTokens,\n outputTokens: usage.outputTokens,\n cacheReadInputTokens: usage.cacheReadInputTokens,\n cacheCreationInputTokens: usage.cacheCreationInputTokens,\n })\n const resolved = getModel(modelId)\n const canonicalId =\n resolved && resolved.kind === \"llm\" ? resolved.canonicalId : modelId\n return {\n kind: \"llm\",\n modelId,\n canonicalId,\n credits: llmResult.credits,\n calculatedCredits: llmResult.calculatedCredits,\n baseCostUsd: llmResult.productionCost,\n breakdown: {\n inputCredits: llmResult.inputCredits,\n outputCredits: llmResult.outputCredits,\n cacheReadCredits: llmResult.cacheReadCredits,\n cacheWriteCredits: llmResult.cacheWriteCredits,\n },\n isFallback: llmResult.isFallback,\n markup: llmResult.markup,\n }\n }\n\n const resolved = getModel(modelId)\n if (!resolved) throw new UnknownModelError(modelId)\n // `voice` is structurally audio for billing purposes (MiniMax voice\n // metadata billed via per-character output). Accept `audio` usage on\n // voice models so the per-kind branches below can pattern-match.\n const expectedUsageKind: CostUsage[\"kind\"] =\n resolved.kind === \"voice\" ? \"audio\" : resolved.kind\n if (expectedUsageKind !== usage.kind) {\n // Pass `expectedUsageKind` (not `resolved.kind`) so the error message\n // accurately says \"audio\" rather than \"voice\" when a voice model is\n // billed — the caller must supply audio usage, not voice usage.\n throw new CostUsageKindMismatchError(modelId, expectedUsageKind, usage.kind)\n }\n\n if (resolved.kind === \"image\") {\n // `usage.kind` is \"image\" here (guarded above) but TS won't cross-narrow\n // it from `resolved.kind`, so check explicitly before reading numOutputs.\n const numOutputs = Math.max(\n 1,\n usage.kind === \"image\" ? (usage.numOutputs ?? 1) : 1\n )\n const baseCostUsd = resolved.def.pricing.baseCost * numOutputs\n const perOutputCredits = computeCenticredits({\n baseCostUsd: resolved.def.pricing.baseCost,\n category: \"image\",\n overrideCreditCost: resolved.def.pricing.overrideCreditCost,\n appId: opts.appId,\n })\n const credits = perOutputCredits * numOutputs\n // Formula-only (ignores override) — for `usage_events.calculated_credits`.\n const formulaPerOutput = computeCenticredits({\n baseCostUsd: resolved.def.pricing.baseCost,\n category: \"image\",\n appId: opts.appId,\n })\n const calculatedCredits = formulaPerOutput * numOutputs\n const markup = pricingRegistry.getMarkup(\"image\", opts.appId)\n return {\n kind: \"image\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perOutputCredits,\n numOutputs,\n },\n isFallback: false,\n markup,\n }\n }\n\n if (resolved.kind === \"video\") {\n if (usage.kind !== \"video\") {\n throw new CostUsageKindMismatchError(modelId, \"video\", usage.kind)\n }\n const pricing = resolved.def.pricing\n // Provider-side multipliers — re-applied to BOTH the provider cost\n // (what we pay) AND the derived credit cost (so margin holds).\n const mult = pricing.multipliers\n const resMult =\n usage.resolution && mult?.resolution\n ? (mult.resolution[usage.resolution] ?? 1.0)\n : 1.0\n const durMult =\n usage.duration && mult?.duration\n ? (mult.duration[usage.duration] ?? 1.0)\n : 1.0\n const modMult =\n usage.mode && mult?.mode ? (mult.mode[usage.mode] ?? 1.0) : 1.0\n const variantMultiplier = resMult * durMult * modMult\n const baseCostUsd = pricing.baseCost * variantMultiplier\n const perClipCredits = computeCenticredits({\n baseCostUsd: pricing.baseCost,\n category: \"video\",\n overrideCreditCost: pricing.overrideCreditCost,\n appId: opts.appId,\n })\n const credits = Math.ceil(perClipCredits * variantMultiplier)\n const formulaPerClip = computeCenticredits({\n baseCostUsd: pricing.baseCost,\n category: \"video\",\n appId: opts.appId,\n })\n const calculatedCredits = Math.ceil(formulaPerClip * variantMultiplier)\n const markup = pricingRegistry.getMarkup(\"video\", opts.appId)\n return {\n kind: \"video\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perClipCredits,\n resolutionMultiplier: resMult,\n durationMultiplier: durMult,\n modeMultiplier: modMult,\n variantMultiplier,\n },\n isFallback: false,\n markup,\n }\n }\n\n // Audio (and voice, delegated as audio — see expectedUsageKind above).\n if (usage.kind !== \"audio\") {\n throw new CostUsageKindMismatchError(modelId, \"audio\", usage.kind)\n }\n\n if (resolved.kind === \"voice\") {\n // Voice rows are metadata; delegate to the provider's default audio model.\n const provider = resolved.voice.provider\n const delegateModelId = VOICE_PROVIDER_DEFAULT_MODEL[provider]\n if (!delegateModelId) throw new UnknownModelError(modelId)\n const delegateResult = calculateCost(delegateModelId, usage, opts)\n return {\n ...delegateResult,\n modelId,\n canonicalId: delegateModelId,\n }\n }\n\n // Only `audio` remains (llm returned at top; image/video/voice handled\n // above). Narrow explicitly so `.def` is type-safe.\n if (resolved.kind !== \"audio\") throw new UnknownModelError(modelId)\n const audioPricing = resolved.def.pricing\n // Map the provider's billing unit to a quantity of billable units.\n // The catalog DATA uses `per_1k_chars` (chars ÷ 1000) and `per_minute`\n // (whole minutes, rounded UP to match provider invoicing). `per_character`\n // / `per_second` are handled too so a future data migration to those units\n // keeps working. NOTE: do not switch on the zod enum value alone — the\n // audio schema enum is stale (`per_character|per_second`) while the data\n // still ships `per_1k_chars|per_minute`; trusting the enum bills 0.\n const billingUnit = audioPricing.billingUnit as string\n let quantity: number\n switch (billingUnit) {\n case \"per_1k_chars\":\n quantity = Math.max(0, usage.characters ?? 0) / 1000\n break\n case \"per_character\":\n quantity = Math.max(0, usage.characters ?? 0)\n break\n case \"per_minute\":\n quantity = Math.ceil(Math.max(0, usage.seconds ?? 0) / 60)\n break\n case \"per_second\":\n default:\n quantity = Math.max(0, usage.seconds ?? 0)\n break\n }\n const baseCostUsd = audioPricing.baseCost * quantity\n const perUnitCredits = computeCenticredits({\n baseCostUsd: audioPricing.baseCost,\n category: \"audio\",\n overrideCreditCost: audioPricing.overrideCreditCost,\n appId: opts.appId,\n })\n // Per-call floor (1 cc) so a non-empty call never rounds to 0; a genuinely\n // empty call (quantity 0, e.g. empty-string TTS) bills nothing.\n const credits =\n quantity > 0 ? Math.max(1, Math.ceil(perUnitCredits * quantity)) : 0\n const formulaPerUnit = computeCenticredits({\n baseCostUsd: audioPricing.baseCost,\n category: \"audio\",\n appId: opts.appId,\n })\n const calculatedCredits =\n quantity > 0 ? Math.max(1, Math.ceil(formulaPerUnit * quantity)) : 0\n const markup = pricingRegistry.getMarkup(\"audio\", opts.appId)\n return {\n kind: \"audio\",\n modelId,\n canonicalId: modelId,\n credits,\n calculatedCredits,\n baseCostUsd,\n breakdown: {\n perUnitCredits,\n quantity,\n },\n isFallback: false,\n markup,\n }\n}\n\n// Thin ergonomic wrappers around `calculateCost`. Two reasons they exist:\n// 1. Callers with a known kind don't want to construct the full union.\n// 2. The kind/usage union is a `calculateCost` implementation detail —\n// wrapper types are narrower and easier to read at call sites.\n\nexport function calculateLLMCost(\n modelId: string,\n usage: {\n inputTokens: number\n outputTokens: number\n cacheReadInputTokens?: number\n cacheCreationInputTokens?: number\n },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"llm\", ...usage }, opts)\n}\n\nexport function calculateImageCost(\n modelId: string,\n usage: { numOutputs?: number },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"image\", ...usage }, opts)\n}\n\nexport function calculateVideoCost(\n modelId: string,\n usage: { resolution?: string; duration?: number; mode?: string },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"video\", ...usage }, opts)\n}\n\nexport function calculateAudioCost(\n modelId: string,\n usage: { characters?: number; seconds?: number },\n opts?: CalculateCostOptions\n): CostResult {\n return calculateCost(modelId, { kind: \"audio\", ...usage }, opts)\n}\n"]}
|
package/dist/cost/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { CostUsageKindMismatchError, UnknownModelError, calculateAudioCost, calculateCost, calculateImageCost, calculateLLMCost, calculateVideoCost } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
1
|
+
export { CostUsageKindMismatchError, UnknownModelError, calculateAudioCost, calculateCost, calculateImageCost, calculateLLMCost, calculateVideoCost } from '../chunk-XP2KTH6U.mjs';
|
|
2
|
+
import '../chunk-H2TPFH4A.mjs';
|
|
3
|
+
import '../chunk-JMEDHOCQ.mjs';
|
|
4
|
+
import '../chunk-3WNSSJTB.mjs';
|
|
5
5
|
import '../chunk-H6JUTF3U.mjs';
|
|
6
6
|
import '../chunk-WG4F6IRS.mjs';
|
|
7
|
-
import '../chunk-
|
|
8
|
-
import '../chunk-
|
|
7
|
+
import '../chunk-TWTG323Z.mjs';
|
|
8
|
+
import '../chunk-S27LMEYZ.mjs';
|
|
9
9
|
import '../chunk-QHELXPSL.mjs';
|
|
10
10
|
import '../chunk-2LWYZOWB.mjs';
|
|
11
11
|
import '../chunk-IJZ4XPO2.mjs';
|
package/dist/curation/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { applyProfile, expandProviders, filterVoicesByProviders, getProviderGroup, getSurfaceProfile, groupForProvider, listProviderGroups, listSurfaceProfiles, listSurfaced, modelMatchesProfile } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
1
|
+
export { applyProfile, expandProviders, filterVoicesByProviders, getProviderGroup, getSurfaceProfile, groupForProvider, listProviderGroups, listSurfaceProfiles, listSurfaced, modelMatchesProfile } from '../chunk-LMY5TLSF.mjs';
|
|
2
|
+
import '../chunk-H2TPFH4A.mjs';
|
|
3
|
+
import '../chunk-JMEDHOCQ.mjs';
|
|
4
|
+
import '../chunk-3WNSSJTB.mjs';
|
|
5
5
|
import '../chunk-H6JUTF3U.mjs';
|
|
6
6
|
import '../chunk-WG4F6IRS.mjs';
|
|
7
|
-
import '../chunk-
|
|
8
|
-
import '../chunk-
|
|
7
|
+
import '../chunk-TWTG323Z.mjs';
|
|
8
|
+
import '../chunk-S27LMEYZ.mjs';
|
|
9
9
|
import '../chunk-QHELXPSL.mjs';
|
|
10
10
|
import '../chunk-2LWYZOWB.mjs';
|
|
11
11
|
import '../chunk-IJZ4XPO2.mjs';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curated, SDK-ready LLM model ids.
|
|
3
|
+
*
|
|
4
|
+
* Centralizes the version-specific provider ids used at runtime so call
|
|
5
|
+
* sites stop carrying string literals. Pricing for each is resolved
|
|
6
|
+
* automatically through `MODEL_ALIASES` in `catalog.ts` (e.g.
|
|
7
|
+
* `claude-sonnet-4-6` → `claude-sonnet-4-5`).
|
|
8
|
+
*
|
|
9
|
+
* Update one constant here when bumping the platform-wide default —
|
|
10
|
+
* every workflow step and operator config picks up the new id with a
|
|
11
|
+
* single rebuild.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Canonical Anthropic default used by the adapter manifests (`AIP-45`
|
|
15
|
+
* `models.default`, in `provider/id` form). Single source of truth for the
|
|
16
|
+
* platform-wide Claude default — bump here, not in each manifest.
|
|
17
|
+
*/
|
|
18
|
+
declare const DEFAULT_ANTHROPIC_MODEL: "claude-sonnet-5-5";
|
|
19
|
+
/** Fast workhorse for content workflows (outline, post, sections). */
|
|
20
|
+
declare const WORKFLOW_FAST_MODEL: "claude-sonnet-4-6";
|
|
21
|
+
/** Premium tier for high-stakes generation (rarely used in workflows). */
|
|
22
|
+
declare const WORKFLOW_PREMIUM_MODEL: "claude-opus-4-6";
|
|
23
|
+
/** Cheap-and-quick for short outputs like titles. */
|
|
24
|
+
declare const WORKFLOW_TINY_MODEL: "claude-haiku-4-5-20251001";
|
|
25
|
+
/**
|
|
26
|
+
* Models eligible for operator agents (an app). Keep in sync with the
|
|
27
|
+
* agent-framework's model-provider config. The literal tuple drives the
|
|
28
|
+
* `OperatorAgentModel` union type below.
|
|
29
|
+
*/
|
|
30
|
+
declare const OPERATOR_AGENT_MODELS: readonly ["claude-opus-4-5", "claude-sonnet-4-5", "gemini-3.1-pro-preview"];
|
|
31
|
+
type OperatorAgentModel = (typeof OPERATOR_AGENT_MODELS)[number];
|
|
32
|
+
/** Default operator model when no explicit choice is made. */
|
|
33
|
+
declare const OPERATOR_DEFAULT_PREMIUM: OperatorAgentModel;
|
|
34
|
+
declare const OPERATOR_DEFAULT_STANDARD: OperatorAgentModel;
|
|
35
|
+
declare const OPERATOR_DEFAULT_GEMINI: OperatorAgentModel;
|
|
36
|
+
declare const LLM_TIERS: {
|
|
37
|
+
/** Cheap-and-quick. Single-model fallback. */
|
|
38
|
+
readonly nano: readonly ["mistral-small-creative-latest"];
|
|
39
|
+
/** Low-cost, agentic-capable. Direct alt-providers. */
|
|
40
|
+
readonly mini: readonly ["MiniMax-M2.5", "MiniMax-M2.1", "MiniMax-M2", "mistral-large-latest"];
|
|
41
|
+
/** Medium cost, fast inference + good general perf. OpenRouter-routed. */
|
|
42
|
+
readonly lite: readonly ["x-ai/grok-4-fast", "xiaomi/mimo-v2-flash", "google/gemini-3-flash-preview"];
|
|
43
|
+
/** High quality, premium features. Mix of direct + OpenRouter. */
|
|
44
|
+
readonly plus: readonly ["claude-sonnet-4-5", "gpt-4o", "kimi-k2.5", "deepseek/deepseek-v3.2"];
|
|
45
|
+
/** Top-tier, best performance. */
|
|
46
|
+
readonly pro: readonly ["claude-opus-4-5", "google/gemini-3.1-pro-preview", "kimi-k2-thinking"];
|
|
47
|
+
};
|
|
48
|
+
type LlmTierName = keyof typeof LLM_TIERS;
|
|
49
|
+
|
|
50
|
+
export { DEFAULT_ANTHROPIC_MODEL as D, LLM_TIERS as L, OPERATOR_AGENT_MODELS as O, WORKFLOW_FAST_MODEL as W, type LlmTierName as a, OPERATOR_DEFAULT_GEMINI as b, OPERATOR_DEFAULT_PREMIUM as c, OPERATOR_DEFAULT_STANDARD as d, type OperatorAgentModel as e, WORKFLOW_PREMIUM_MODEL as f, WORKFLOW_TINY_MODEL as g };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ImageAspectRatio, ImageAspectRatioSchema, ImageCapabilities, ImageCapabilitiesSchema, ImageEntry, ImageEntrySchema, ImagePricing, ImagePricingSchema, ImageReferenceImages, ImageReferenceImagesSchema, LLMEntry, LLMEntrySchema, LlmPricing, LlmPricingSchema, ModelEntry, ModelEntrySchema, VideoCapabilities, VideoCapabilitiesSchema, VideoCostMultipliers, VideoCostMultipliersSchema, VideoEntry, VideoEntrySchema, VideoPricing, VideoPricingSchema, VideoResolution, VideoResolutionSchema } from './schema/index.js';
|
|
2
2
|
export { D as DEFAULT_PRICING, a as LLMCreditCostResult, L as LLMPricing, b as LLMPricingTier, c as LLMUsageBreakdown, d as LLM_PRICING_CATALOG, M as MODEL_ALIASES, e as calculateLLMCreditCost, r as resolvePricing, s as selectPricingTier } from './catalog-DRGEICKV.js';
|
|
3
|
+
export { D as DEFAULT_ANTHROPIC_MODEL } from './defaults-BDkNRPK8.js';
|
|
3
4
|
export { AGENT_EDITABLE_MODEL_IDS, AGENT_GENERATIVE_MODEL_IDS, AGENT_IMAGE_MODEL_IDS, IMAGE_MODEL_CATALOG, IMAGE_MODEL_IDS, ImageModelDefinition, generateImageModelTable } from './image/index.js';
|
|
4
5
|
export { AGENT_VIDEO_MODEL_IDS, VIDEO_MODEL_CATALOG, VIDEO_MODEL_IDS, VideoModelDefinition, generateVideoModelTable } from './video/index.js';
|
|
5
6
|
export { AGENT_AUDIO_MODEL_IDS, AGENT_STT_MODEL_IDS, AGENT_TTS_MODEL_IDS, AUDIO_MODEL_CATALOG, AUDIO_MODEL_IDS, AudioBillingUnit, AudioModality, AudioModelDefinition, AudioProvider, DEFAULT_GEMINI_LIVE_MODEL, GEMINI_LIVE_MODEL_IDS, S2S_MODEL_IDS, generateAudioModelTable, isAcceptedGeminiLiveModel } from './audio/index.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export { applyProfile, expandProviders, filterVoicesByProviders, getProviderGroup, getSurfaceProfile, groupForProvider, listProviderGroups, listSurfaceProfiles, listSurfaced, modelMatchesProfile } from './chunk-
|
|
2
|
-
export { CostUsageKindMismatchError, UnknownModelError, calculateAudioCost, calculateCost, calculateImageCost, calculateLLMCost, calculateVideoCost } from './chunk-
|
|
3
|
-
import { getModel } from './chunk-
|
|
4
|
-
export { getModel, getModelsByProvider, getStaticModelProvider, isAgentVisible, listModels, resolveAlias } from './chunk-
|
|
5
|
-
import './chunk-
|
|
1
|
+
export { applyProfile, expandProviders, filterVoicesByProviders, getProviderGroup, getSurfaceProfile, groupForProvider, listProviderGroups, listSurfaceProfiles, listSurfaced, modelMatchesProfile } from './chunk-LMY5TLSF.mjs';
|
|
2
|
+
export { CostUsageKindMismatchError, UnknownModelError, calculateAudioCost, calculateCost, calculateImageCost, calculateLLMCost, calculateVideoCost } from './chunk-XP2KTH6U.mjs';
|
|
3
|
+
import { getModel } from './chunk-H2TPFH4A.mjs';
|
|
4
|
+
export { getModel, getModelsByProvider, getStaticModelProvider, isAgentVisible, listModels, resolveAlias } from './chunk-H2TPFH4A.mjs';
|
|
5
|
+
import './chunk-JMEDHOCQ.mjs';
|
|
6
6
|
export { shouldDebit } from './chunk-XFDXTFV3.mjs';
|
|
7
|
-
export { evaluateAccess, evaluateCatalogDefaults } from './chunk-
|
|
8
|
-
import { priceTierForModel } from './chunk-
|
|
9
|
-
export { assertReservedPrefixDiscipline, getActions, getEnrichment, isActionTag, modelHasAction, modelHasTag, modelMatchesCatalogPriceTier, modelMatchesKind, modelMatchesPriceTier, priceTierForModel } from './chunk-
|
|
7
|
+
export { evaluateAccess, evaluateCatalogDefaults } from './chunk-PITHETND.mjs';
|
|
8
|
+
import { priceTierForModel } from './chunk-3WNSSJTB.mjs';
|
|
9
|
+
export { assertReservedPrefixDiscipline, getActions, getEnrichment, isActionTag, modelHasAction, modelHasTag, modelMatchesCatalogPriceTier, modelMatchesKind, modelMatchesPriceTier, priceTierForModel } from './chunk-3WNSSJTB.mjs';
|
|
10
10
|
export { clearCatalogOverlays, getMergedOverlay, registerCatalogOverlay } from './chunk-H6JUTF3U.mjs';
|
|
11
11
|
export { AudioCapabilitiesSchema, AudioEntrySchema, AudioPricingSchema, ImageAspectRatioSchema, ImageCapabilitiesSchema, ImageEntrySchema, ImagePricingSchema, ImageReferenceImagesSchema, LLMEntrySchema, LlmPricingSchema, ModelEntrySchema, VideoCapabilitiesSchema, VideoCostMultipliersSchema, VideoEntrySchema, VideoPricingSchema, VideoResolutionSchema } from './chunk-7U7XGVHP.mjs';
|
|
12
12
|
export { CatalogPriceTierSchema, CatalogProviderSchema, LifecycleSchema, ModelKindSchema, NsfwPolicySchema, PROVIDER_KEY_ENV, PROVIDER_KEY_ENV_ALIASES, baseEntryShape } from './chunk-WG4F6IRS.mjs';
|
|
13
|
-
|
|
14
|
-
export { DEFAULT_PRICING, LLM_PRICING_CATALOG, MODEL_ALIASES, calculateLLMCreditCost, resolvePricing, selectPricingTier } from './chunk-
|
|
13
|
+
export { DEFAULT_ANTHROPIC_MODEL } from './chunk-TWTG323Z.mjs';
|
|
14
|
+
export { DEFAULT_PRICING, LLM_PRICING_CATALOG, MODEL_ALIASES, calculateLLMCreditCost, resolvePricing, selectPricingTier } from './chunk-S27LMEYZ.mjs';
|
|
15
15
|
export { CC_USD_RATE, CREDIT_USD_RATE, DEFAULT_PRICING_FLOORS, DEFAULT_PRICING_MARKUP, computeCenticredits, pricingRegistry } from './chunk-QHELXPSL.mjs';
|
|
16
16
|
export { AGENT_EDITABLE_MODEL_IDS, AGENT_GENERATIVE_MODEL_IDS, AGENT_IMAGE_MODEL_IDS, IMAGE_MODEL_CATALOG, IMAGE_MODEL_IDS, generateImageModelTable } from './chunk-2LWYZOWB.mjs';
|
|
17
17
|
export { AGENT_VIDEO_MODEL_IDS, VIDEO_MODEL_CATALOG, VIDEO_MODEL_IDS, generateVideoModelTable } from './chunk-IJZ4XPO2.mjs';
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEO,SAAS,oBAAoB,EAAA,EAAoB;AACtD,EAAA,MAAM,KAAA,GAAQ,SAAS,EAAE,CAAA;AACzB,EAAA,OAAO,KAAA,GAAQ,iBAAA,CAA0B,KAAK,CAAA,GAAI,CAAA;AACpD","file":"index.mjs","sourcesContent":["/**\n * @agentproto/model-catalog — unified model catalog.\n *\n * Single source of truth for LLM, image, video, audio, and voice model\n * entries. Owns cost dispatch, BYOK policy, and access control evaluation.\n * Zod-only OSS core; @agentproto/model-catalog layers billing/access/BYOK\n * policy on top.\n *\n * Subpath imports for tree-shaking:\n * import { LLM_PRICING_CATALOG } from \"@agentproto/model-catalog/llm\"\n * import { calculateCost } from \"@agentproto/model-catalog/cost\"\n * import { shouldDebit } from \"@agentproto/model-catalog/byok\"\n * import { evaluateAccess } from \"@agentproto/model-catalog/access\"\n * import { VOICE_CATALOG } from \"@agentproto/model-catalog/voice\"\n * import { listSurfaced } from \"@agentproto/model-catalog/curation\"\n */\n\nexport * from \"./schema/index.js\"\n// LLM has its own `resolveAlias` (legacy back-compat for the app legacy pricing module).\n// At the top level we prefer the cross-kind `resolveAlias` from the registry.\nexport {\n LLM_PRICING_CATALOG,\n MODEL_ALIASES,\n DEFAULT_PRICING,\n DEFAULT_ANTHROPIC_MODEL,\n resolvePricing,\n calculateLLMCreditCost,\n selectPricingTier,\n} from \"./llm/index.js\"\nexport type {\n LLMPricing,\n LLMPricingTier,\n LLMUsageBreakdown,\n LLMCreditCostResult,\n} from \"./llm/index.js\"\nexport * from \"./image/index.js\"\nexport * from \"./video/index.js\"\nexport * from \"./audio/index.js\"\nexport * from \"./voice/index.js\"\nexport * from \"./curation/index.js\"\nexport * from \"./pricing/index.js\"\nexport * from \"./cost/index.js\"\nexport * from \"./byok/index.js\"\nexport * from \"./access/index.js\"\nexport * from \"./overlay/index.js\"\nexport * from \"./registry/index.js\"\nexport {\n getActions,\n isActionTag,\n assertReservedPrefixDiscipline,\n} from \"./registry/actions.js\"\nexport {\n getEnrichment,\n modelHasTag,\n modelHasAction,\n modelMatchesCatalogPriceTier,\n modelMatchesPriceTier,\n modelMatchesKind,\n priceTierForModel,\n type ModelEnrichment,\n} from \"./enrichment/index.js\"\n\nimport { getModel } from \"./registry/index.js\"\nimport { priceTierForModel as priceTierForModelInternal } from \"./enrichment/index.js\"\n\n/**\n * Display price gauge level (1..5) for a model id — resolves the catalog\n * entry then defers to {@link priceTierForModel}. 0 for an unknown id.\n * The id→level convenience used by the WhatsApp / slash pickers, which carry\n * a model id rather than a resolved model.\n */\nexport function priceTierForModelId(id: string): number {\n const model = getModel(id)\n return model ? priceTierForModelInternal(model) : 0\n}\nexport type {\n AvailableModel,\n AvailableModelCapabilities,\n AvailableConnector,\n AvailableModelsActor,\n AvailableModelsResponse,\n ListAvailableModelsParams,\n} from \"./picker/index.js\"\n"]}
|
package/dist/llm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { C as CacheStats, f as CalculateLLMCreditCostOptions, g as ContextWindowEntry, D as DEFAULT_PRICING, K as KnownLlmId, a as LLMCreditCostResult, L as LLMPricing, b as LLMPricingTier, c as LLMUsageBreakdown, d as LLM_PRICING_CATALOG, h as LlmModelAlias, i as LlmModelId, M as MODEL_ALIASES, j as ModelRoute, e as calculateLLMCreditCost, k as getCacheStats, l as getModelProvider, m as isKnownLlmId, n as listNativeModelIds, o as listUnpricedKnownLlmIds, p as resolveAlias, q as resolveContextWindow, t as resolveModelRoute, r as resolvePricing, u as resolvePricingExact, s as selectPricingTier, v as splitContextWindowHint } from '../catalog-DRGEICKV.js';
|
|
2
|
+
export { D as DEFAULT_ANTHROPIC_MODEL, L as LLM_TIERS, a as LlmTierName, O as OPERATOR_AGENT_MODELS, b as OPERATOR_DEFAULT_GEMINI, c as OPERATOR_DEFAULT_PREMIUM, d as OPERATOR_DEFAULT_STANDARD, e as OperatorAgentModel, W as WORKFLOW_FAST_MODEL, f as WORKFLOW_PREMIUM_MODEL, g as WORKFLOW_TINY_MODEL } from '../defaults-BDkNRPK8.js';
|
|
2
3
|
import '../base-BaiI72Da.js';
|
|
3
4
|
import 'zod';
|
|
4
5
|
|
|
@@ -53,47 +54,4 @@ declare function listOpencodeAnthropicModelRefs(endpoint: OpencodeEndpoint): str
|
|
|
53
54
|
* null so JSON output omits rather than fabricates a value. */
|
|
54
55
|
declare function formatTokens(n: number | undefined): string | null;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
* Curated, SDK-ready LLM model ids.
|
|
58
|
-
*
|
|
59
|
-
* Centralizes the version-specific provider ids used at runtime so call
|
|
60
|
-
* sites stop carrying string literals. Pricing for each is resolved
|
|
61
|
-
* automatically through `MODEL_ALIASES` in `catalog.ts` (e.g.
|
|
62
|
-
* `claude-sonnet-4-6` → `claude-sonnet-4-5`).
|
|
63
|
-
*
|
|
64
|
-
* Update one constant here when bumping the platform-wide default —
|
|
65
|
-
* every workflow step and operator config picks up the new id with a
|
|
66
|
-
* single rebuild.
|
|
67
|
-
*/
|
|
68
|
-
/** Fast workhorse for content workflows (outline, post, sections). */
|
|
69
|
-
declare const WORKFLOW_FAST_MODEL: "claude-sonnet-4-6";
|
|
70
|
-
/** Premium tier for high-stakes generation (rarely used in workflows). */
|
|
71
|
-
declare const WORKFLOW_PREMIUM_MODEL: "claude-opus-4-6";
|
|
72
|
-
/** Cheap-and-quick for short outputs like titles. */
|
|
73
|
-
declare const WORKFLOW_TINY_MODEL: "claude-haiku-4-5-20251001";
|
|
74
|
-
/**
|
|
75
|
-
* Models eligible for operator agents (an app). Keep in sync with the
|
|
76
|
-
* agent-framework's model-provider config. The literal tuple drives the
|
|
77
|
-
* `OperatorAgentModel` union type below.
|
|
78
|
-
*/
|
|
79
|
-
declare const OPERATOR_AGENT_MODELS: readonly ["claude-opus-4-5", "claude-sonnet-4-5", "gemini-3.1-pro-preview"];
|
|
80
|
-
type OperatorAgentModel = (typeof OPERATOR_AGENT_MODELS)[number];
|
|
81
|
-
/** Default operator model when no explicit choice is made. */
|
|
82
|
-
declare const OPERATOR_DEFAULT_PREMIUM: OperatorAgentModel;
|
|
83
|
-
declare const OPERATOR_DEFAULT_STANDARD: OperatorAgentModel;
|
|
84
|
-
declare const OPERATOR_DEFAULT_GEMINI: OperatorAgentModel;
|
|
85
|
-
declare const LLM_TIERS: {
|
|
86
|
-
/** Cheap-and-quick. Single-model fallback. */
|
|
87
|
-
readonly nano: readonly ["mistral-small-creative-latest"];
|
|
88
|
-
/** Low-cost, agentic-capable. Direct alt-providers. */
|
|
89
|
-
readonly mini: readonly ["MiniMax-M2.5", "MiniMax-M2.1", "MiniMax-M2", "mistral-large-latest"];
|
|
90
|
-
/** Medium cost, fast inference + good general perf. OpenRouter-routed. */
|
|
91
|
-
readonly lite: readonly ["x-ai/grok-4-fast", "xiaomi/mimo-v2-flash", "google/gemini-3-flash-preview"];
|
|
92
|
-
/** High quality, premium features. Mix of direct + OpenRouter. */
|
|
93
|
-
readonly plus: readonly ["claude-sonnet-4-5", "gpt-4o", "kimi-k2.5", "deepseek/deepseek-v3.2"];
|
|
94
|
-
/** Top-tier, best performance. */
|
|
95
|
-
readonly pro: readonly ["claude-opus-4-5", "google/gemini-3.1-pro-preview", "kimi-k2-thinking"];
|
|
96
|
-
};
|
|
97
|
-
type LlmTierName = keyof typeof LLM_TIERS;
|
|
98
|
-
|
|
99
|
-
export { LLM_TIERS, type LlmTierName, OPERATOR_AGENT_MODELS, OPERATOR_DEFAULT_GEMINI, OPERATOR_DEFAULT_PREMIUM, OPERATOR_DEFAULT_STANDARD, type OpencodeEndpoint, type OperatorAgentModel, WORKFLOW_FAST_MODEL, WORKFLOW_PREMIUM_MODEL, WORKFLOW_TINY_MODEL, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs };
|
|
57
|
+
export { type OpencodeEndpoint, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs };
|
package/dist/llm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { LLM_TIERS, OPERATOR_AGENT_MODELS, OPERATOR_DEFAULT_GEMINI, OPERATOR_DEFAULT_PREMIUM, OPERATOR_DEFAULT_STANDARD, WORKFLOW_FAST_MODEL, WORKFLOW_PREMIUM_MODEL, WORKFLOW_TINY_MODEL, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs } from '../chunk-
|
|
2
|
-
export { DEFAULT_PRICING, LLM_PRICING_CATALOG, MODEL_ALIASES, calculateLLMCreditCost, getCacheStats, getModelProvider, isKnownLlmId, listNativeModelIds, listUnpricedKnownLlmIds, resolveAlias, resolveContextWindow, resolveModelRoute, resolvePricing, resolvePricingExact, selectPricingTier, splitContextWindowHint } from '../chunk-
|
|
1
|
+
export { DEFAULT_ANTHROPIC_MODEL, LLM_TIERS, OPERATOR_AGENT_MODELS, OPERATOR_DEFAULT_GEMINI, OPERATOR_DEFAULT_PREMIUM, OPERATOR_DEFAULT_STANDARD, WORKFLOW_FAST_MODEL, WORKFLOW_PREMIUM_MODEL, WORKFLOW_TINY_MODEL, formatTokens, listOpencodeAnthropicModelRefs, listOpencodeModelRefs } from '../chunk-TWTG323Z.mjs';
|
|
2
|
+
export { DEFAULT_PRICING, LLM_PRICING_CATALOG, MODEL_ALIASES, calculateLLMCreditCost, getCacheStats, getModelProvider, isKnownLlmId, listNativeModelIds, listUnpricedKnownLlmIds, resolveAlias, resolveContextWindow, resolveModelRoute, resolvePricing, resolvePricingExact, selectPricingTier, splitContextWindowHint } from '../chunk-S27LMEYZ.mjs';
|
|
3
3
|
import '../chunk-QHELXPSL.mjs';
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { InvalidModelRefError, OPENROUTER_VARIANTS, clearCustomRoutes, diagnoseModelRef, formatModelRef, isModelRefString, listRouterLlmRoutes, parseModelRef, registerCustomRoute, resolveCustomRoute, resolveLlmModelRoute, stripAnthropicNativeVendor, stripFixedNativeVendor, stripRouteSuffix, tryParseModelRef } from '../chunk-
|
|
1
|
+
export { InvalidModelRefError, OPENROUTER_VARIANTS, clearCustomRoutes, diagnoseModelRef, formatModelRef, isModelRefString, listRouterLlmRoutes, parseModelRef, registerCustomRoute, resolveCustomRoute, resolveLlmModelRoute, stripAnthropicNativeVendor, stripFixedNativeVendor, stripRouteSuffix, tryParseModelRef } from '../chunk-JMEDHOCQ.mjs';
|
|
2
2
|
import '../chunk-WG4F6IRS.mjs';
|
|
3
|
-
import '../chunk-
|
|
3
|
+
import '../chunk-S27LMEYZ.mjs';
|
|
4
4
|
import '../chunk-QHELXPSL.mjs';
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
6
6
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/model-catalog",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Unified, dependency-light model catalog: LLM, image, video, audio entries + cost dispatcher + picker. Zod-only; the OSS core that @agstudio/model-catalog layers billing/access/BYOK on top of.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -119,15 +119,15 @@
|
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"zod": "^4.6.
|
|
122
|
+
"zod": "^4.6.7"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
|
-
"@types/node": "^25.9.
|
|
125
|
+
"@types/node": "^25.9.9",
|
|
126
126
|
"tsup": "^8.5.1",
|
|
127
127
|
"typescript": "^5.9.3",
|
|
128
128
|
"vitest": "^3.2.7",
|
|
129
|
-
"@agentproto/
|
|
130
|
-
"@agentproto/
|
|
129
|
+
"@agentproto/tooling": "0.1.0",
|
|
130
|
+
"@agentproto/provider-presets": "0.7.1"
|
|
131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O,GAAG,IAAI,CAAA,CAAA,CAAA;AAAA,EAChB;AACA,EAAA,OAAO,OAAO,CAAC,CAAA;AACjB;;;ACRO,IAAM,mBAAA,GAAsB;AAG5B,IAAM,sBAAA,GAAyB;AAG/B,IAAM,mBAAA,GAAsB;AAO5B,IAAM,qBAAA,GAAwB;AAAA,EACnC,iBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF;AAKO,IAAM,wBAAA,GAA+C;AACrD,IAAM,yBAAA,GAAgD;AACtD,IAAM,uBAAA,GACX;AAcK,IAAM,SAAA,GAAY;AAAA;AAAA,EAEvB,IAAA,EAAM,CAAC,+BAA+B,CAAA;AAAA;AAAA,EAEtC,IAAA,EAAM;AAAA,IACJ,cAAA;AAAA,IACA,cAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,IAAA,EAAM;AAAA,IACJ,kBAAA;AAAA,IACA,sBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,IAAA,EAAM;AAAA,IACJ,mBAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAAA;AAAA,EAEA,GAAA,EAAK;AAAA,IACH,iBAAA;AAAA,IACA,+BAAA;AAAA,IACA;AAAA;AAEJ","file":"chunk-CON7JITC.mjs","sourcesContent":["/**\n * OpenCode's two hosted endpoints — the small hand-written surface over their\n * generated route tables.\n *\n * Deliberately its OWN module rather than an addition to `catalog.ts`: that\n * file owns `LLM_PRICING_CATALOG`, and the one invariant these tables have is\n * that they are NEVER spread into it (a bare `claude-sonnet-5` must keep\n * meaning direct Anthropic, not a Zen-priced route — see the OpenCode branch\n * in `route-identity/index.ts`). Keeping the import out of `catalog.ts`\n * keeps that temptation out of reach.\n */\n\nimport {\n OPENCODE_GO_ANTHROPIC_MODELS,\n OPENCODE_GO_ROUTES,\n} from \"./opencode-go-routes.generated.js\"\nimport {\n OPENCODE_ZEN_ANTHROPIC_MODELS,\n OPENCODE_ZEN_ROUTES,\n} from \"./opencode-zen-routes.generated.js\"\n\n/**\n * The two OpenCode hosted endpoints, by catalog provider id.\n * - `\"opencode\"` — OpenCode Zen, pay-as-you-go (`.../zen/v1`).\n * - `\"opencode-go\"` — OpenCode Go, the flat subscription (`.../zen/go/v1`).\n */\nexport type OpencodeEndpoint = \"opencode\" | \"opencode-go\"\n\n/**\n * Every model ref an OpenCode endpoint serves, in the `<provider>/<bare-id>`\n * form the route tables are keyed by — which is also opencode's own config\n * spelling and what a caller passes to `agent_start`.\n */\nexport function listOpencodeModelRefs(endpoint: OpencodeEndpoint): string[] {\n const routes = endpoint === \"opencode-go\" ? OPENCODE_GO_ROUTES : OPENCODE_ZEN_ROUTES\n return Object.keys(routes).sort()\n}\n\n/**\n * The subset of {@link listOpencodeModelRefs} whose wire surface is the\n * Anthropic Messages API — exactly what the matching `opencode` /\n * `opencode-go` gateway preset can serve, and therefore exactly what an\n * Anthropic-native adapter (claude-code / claude-sdk) may offer on that\n * route. Both endpoints also serve OpenAI chat/completions, OpenAI Responses\n * and (Zen only) Gemini models behind the same base URL; those are\n * unreachable from an Anthropic client and are excluded here.\n *\n * Derived from the generated `*_ANTHROPIC_MODELS` lists, which come from the\n * source's own per-model `provider.npm` discriminator — so an adapter menu\n * built on this can never drift into offering an id the endpoint won't answer\n * on `/v1/messages`, and a newly-added Anthropic-surface model becomes\n * offerable on the next catalog-sync run with no code change (the same\n * rationale as `listNativeModelIds`).\n */\nexport function listOpencodeAnthropicModelRefs(endpoint: OpencodeEndpoint): string[] {\n const bareIds =\n endpoint === \"opencode-go\" ? OPENCODE_GO_ANTHROPIC_MODELS : OPENCODE_ZEN_ANTHROPIC_MODELS\n return bareIds.map(id => `${endpoint}/${id}`).sort()\n}\n","/**\n * Shared human-readable token formatting, so the `agentproto models` CLI and\n * the `catalog_models` MCP tool render the same `1M`/`200k` shapes instead of\n * raw integers. Lives next to `resolveContextWindow` (its data source) — one\n * formatter per concept, both output surfaces consume it.\n */\n\n/** Format a token count compactly — `1M`, `500k`, `2k`, `448`. Undefined ⇒\n * null so JSON output omits rather than fabricates a value. */\nexport function formatTokens(n: number | undefined): string | null {\n if (typeof n !== \"number\" || n <= 0) return null\n if (n >= 1_000_000) {\n const m = n / 1_000_000\n const text = Number.isInteger(m) ? String(m) : m.toFixed(1)\n return `${text}M`\n }\n if (n >= 1_000) {\n const k = n / 1_000\n const text = Number.isInteger(k) ? String(k) : k.toFixed(1)\n return `${text}k`\n }\n return String(n)\n}\n","/**\n * Curated, SDK-ready LLM model ids.\n *\n * Centralizes the version-specific provider ids used at runtime so call\n * sites stop carrying string literals. Pricing for each is resolved\n * automatically through `MODEL_ALIASES` in `catalog.ts` (e.g.\n * `claude-sonnet-4-6` → `claude-sonnet-4-5`).\n *\n * Update one constant here when bumping the platform-wide default —\n * every workflow step and operator config picks up the new id with a\n * single rebuild.\n */\n\n/** Fast workhorse for content workflows (outline, post, sections). */\nexport const WORKFLOW_FAST_MODEL = \"claude-sonnet-4-6\" as const\n\n/** Premium tier for high-stakes generation (rarely used in workflows). */\nexport const WORKFLOW_PREMIUM_MODEL = \"claude-opus-4-6\" as const\n\n/** Cheap-and-quick for short outputs like titles. */\nexport const WORKFLOW_TINY_MODEL = \"claude-haiku-4-5-20251001\" as const\n\n/**\n * Models eligible for operator agents (an app). Keep in sync with the\n * agent-framework's model-provider config. The literal tuple drives the\n * `OperatorAgentModel` union type below.\n */\nexport const OPERATOR_AGENT_MODELS = [\n \"claude-opus-4-5\",\n \"claude-sonnet-4-5\",\n \"gemini-3.1-pro-preview\",\n] as const\n\nexport type OperatorAgentModel = (typeof OPERATOR_AGENT_MODELS)[number]\n\n/** Default operator model when no explicit choice is made. */\nexport const OPERATOR_DEFAULT_PREMIUM: OperatorAgentModel = \"claude-opus-4-5\"\nexport const OPERATOR_DEFAULT_STANDARD: OperatorAgentModel = \"claude-sonnet-4-5\"\nexport const OPERATOR_DEFAULT_GEMINI: OperatorAgentModel =\n \"gemini-3.1-pro-preview\"\n\n// ── Plan-tier → model lists ─────────────────────────────────────────────\n//\n// Catalog-canonical equivalent of agent-framework's `MODEL_TIERS`. Used\n// by per-app `AppPlanRegistry` files as the source list when a plan\n// surfaces \"all of the X tier\". Keeping this in the catalog keeps the\n// app registries declarative — they pick from `LLM_TIERS.plus` rather\n// than re-specifying ids.\n//\n// All ids resolve through `resolvePricing` (direct match → alias →\n// partial-prefix). Names are app-vocabulary-neutral; per-app registries\n// re-key as needed (`PaygoTier.nano` → `LLM_TIERS.nano`, etc.).\n\nexport const LLM_TIERS = {\n /** Cheap-and-quick. Single-model fallback. */\n nano: [\"mistral-small-creative-latest\"] as const,\n /** Low-cost, agentic-capable. Direct alt-providers. */\n mini: [\n \"MiniMax-M2.5\",\n \"MiniMax-M2.1\",\n \"MiniMax-M2\",\n \"mistral-large-latest\",\n ] as const,\n /** Medium cost, fast inference + good general perf. OpenRouter-routed. */\n lite: [\n \"x-ai/grok-4-fast\",\n \"xiaomi/mimo-v2-flash\",\n \"google/gemini-3-flash-preview\",\n ] as const,\n /** High quality, premium features. Mix of direct + OpenRouter. */\n plus: [\n \"claude-sonnet-4-5\",\n \"gpt-4o\",\n \"kimi-k2.5\",\n \"deepseek/deepseek-v3.2\",\n ] as const,\n /** Top-tier, best performance. */\n pro: [\n \"claude-opus-4-5\",\n \"google/gemini-3.1-pro-preview\",\n \"kimi-k2-thinking\",\n ] as const,\n} as const\n\nexport type LlmTierName = keyof typeof LLM_TIERS\n"]}
|