@bastani/atomic 0.9.20-alpha.6 → 0.9.20-alpha.8
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/CHANGELOG.md +46 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +18 -8
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +27 -0
- package/dist/builtin/workflows/README.md +5 -19
- package/dist/builtin/workflows/builtin/{chunk-deq63d9p.js → chunk-7bzcersz.js} +30 -19
- package/dist/builtin/workflows/builtin/goal.js +1 -1
- package/dist/builtin/workflows/builtin/index.js +1 -1
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +10 -9
- package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +4 -4
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +96 -23
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +75 -27
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +72 -26
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +58 -22
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +118 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +70 -29
- package/dist/builtin/workflows/skills/prompt-engineer/references/core_prompting.md +1 -1
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +95 -32
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +79 -30
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +139 -0
- package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -4
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +389 -719
- package/dist/builtin/workflows/src/index.js +17 -7
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +3 -1
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +4 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +6 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts +9 -0
- package/dist/core/agent-session-tasks.d.ts.map +1 -1
- package/dist/core/agent-session-tasks.js +68 -16
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +9 -21
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +5 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/execution-model-router.d.ts +14 -0
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +67 -21
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/fast-model-variants.d.ts +26 -0
- package/dist/core/fast-model-variants.d.ts.map +1 -1
- package/dist/core/fast-model-variants.js +40 -1
- package/dist/core/fast-model-variants.js.map +1 -1
- package/dist/core/model-runtime.d.ts +13 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +16 -1
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/sdk-types.d.ts +5 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +4 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/skill-catalog.d.ts.map +1 -1
- package/dist/core/skill-catalog.js +18 -6
- package/dist/core/skill-catalog.js.map +1 -1
- package/dist/core/structured-output/index.d.ts +1 -0
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +34 -26
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/jev-client.d.ts +9 -0
- package/dist/core/structured-output/jev-client.d.ts.map +1 -1
- package/dist/core/structured-output/jev-client.js +57 -3
- package/dist/core/structured-output/jev-client.js.map +1 -1
- package/dist/core/structured-output/jev.d.ts.map +1 -1
- package/dist/core/structured-output/jev.js +35 -53
- package/dist/core/structured-output/jev.js.map +1 -1
- package/dist/core/structured-output/resolver.d.ts +32 -24
- package/dist/core/structured-output/resolver.d.ts.map +1 -1
- package/dist/core/structured-output/resolver.js +57 -9
- package/dist/core/structured-output/resolver.js.map +1 -1
- package/dist/core/structured-output/types.d.ts +8 -4
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/tasks/child-command-owner.d.ts +34 -0
- package/dist/core/tasks/child-command-owner.d.ts.map +1 -0
- package/dist/core/tasks/child-command-owner.js +70 -0
- package/dist/core/tasks/child-command-owner.js.map +1 -0
- package/dist/core/tools/bash-pty-native.d.ts +5 -1
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +15 -7
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +15 -13
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/kill.d.ts +2 -2
- package/dist/core/tools/kill.d.ts.map +1 -1
- package/dist/core/tools/kill.js +3 -4
- package/dist/core/tools/kill.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.d.ts.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.js +3 -2
- package/dist/modes/interactive/components/atomic-banner.js.map +1 -1
- package/dist/modes/interactive/components/startup-identity.d.ts +3 -0
- package/dist/modes/interactive/components/startup-identity.d.ts.map +1 -1
- package/dist/modes/interactive/components/startup-identity.js +11 -2
- package/dist/modes/interactive/components/startup-identity.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +2 -4
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-tui.js +2 -0
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive/overlay-line-composite.d.ts +7 -0
- package/dist/modes/interactive/overlay-line-composite.d.ts.map +1 -0
- package/dist/modes/interactive/overlay-line-composite.js +24 -0
- package/dist/modes/interactive/overlay-line-composite.js.map +1 -0
- package/dist/modes/interactive-engine/isolated-auth.d.ts +16 -0
- package/dist/modes/interactive-engine/isolated-auth.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js +27 -0
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +4 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -1
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js +7 -2
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +3 -1
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +2 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js +2 -2
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/child-process.d.ts +1 -0
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +7 -8
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +18 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/background-tasks.md +11 -2
- package/docs/environment-variables.md +1 -1
- package/docs/getting-started/first-session.md +2 -2
- package/docs/llama-cpp.md +2 -2
- package/docs/models/evals.md +47 -43
- package/docs/models/reference.md +1 -1
- package/docs/providers.md +14 -4
- package/docs/reference/cli.md +2 -2
- package/docs/rpc/examples.md +2 -0
- package/docs/sdk/reference.md +1 -1
- package/docs/sdk/structured-decisions.md +20 -14
- package/docs/settings.md +8 -8
- package/docs/skills.md +5 -1
- package/docs/subagents/reference.md +2 -2
- package/docs/subagents.md +1 -1
- package/docs/workflows/api-reference.md +5 -34
- package/docs/workflows/builtins.md +1 -1
- package/docs/workflows/operations.md +11 -77
- package/docs/workflows/reliable-design.md +14 -29
- package/docs/workflows.md +8 -7
- package/examples/rpc-client.ts +38 -0
- package/examples/rpc-extension-ui.ts +19 -5
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +65 -65
- package/package.json +7 -7
- package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_astra.md +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-model-router.js","sourceRoot":"","sources":["../../src/core/execution-model-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,M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":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { type Api, containsKnownEnvCredential, getSupportedThinkingLevels, type Model } from \"@bastani/pi-ai\";\nimport { Type } from \"typebox\";\nimport { getDocsPath } from \"../config.js\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport {\n\teligiblePair,\n\ttype ModelConstraints,\n\ttype ModelRouterOutput,\n\tparseModelConstraints,\n} from \"./model-routing-constraints.js\";\nimport { modelRoutingTask } from \"./model-routing-task.js\";\nimport { inferRouterDecision, resolveRouterModel } from \"./structured-output/index.js\";\n\nexport interface ModelRoutingContext {\n\treadonly modelRegistry: Pick<\n\t\tModelRegistry,\n\t\t\"getAll\" | \"getAvailable\" | \"streamSimple\" | \"containsConfiguredCredential\"\n\t> &\n\t\tPartial<Pick<ModelRegistry, \"getProviderAuthStatus\" | \"getProviderAuth\">>;\n\treadonly model?: Model<Api>;\n\tgetRouterModel(): string;\n}\nexport interface ModelRoute {\n\treadonly routerSelection: ModelRouterOutput;\n\treadonly modelOverride: string;\n\treadonly fallbackModels?: readonly string[];\n\tassertCurrent(): void;\n\tallowsModel(model: Model<Api>, effort?: string): boolean;\n}\nconst instructions =\n\t\"Select one eligible model/effort pair for `task` and `agent` from the supplied Choice criteria, using `evals` as evidence and `model_selection_guide` as policy. Match the agent role to the guide's model cost tier and thinking level first, then consider task fit, measured effort, dates, caveats and cost. Evals cannot add candidates or bypass constraints. Return exactly model and effort; null means no configurable reasoning.\";\n\n/** Static selection policy sent with every auto-routing request alongside the dated `evals` evidence. */\nexport const MODEL_SELECTION_GUIDE = `## Benchmarks are evidence, not policy\n\nBenchmark results are measurements under named harnesses, dates, models, efforts, agents, tools, prompts, prices, and scoring rules. Treat a bracketed effort level as the measurement configuration for that row, not a command to run every task at that effort. Compare only records whose measured setup resembles the decision at hand, and keep unmeasured work under ordinary validation rather than inheriting a score.\n\nMissing evidence is unknown, not zero. A rounded lead is not proof of significance. A result for one provider, model version, effort, agent, fallback setting, or benchmark harness does not transfer to another identity.\n\n## Role-based thinking effort\n\nUse these starting defaults unless the user requests a level. Higher effort can improve hard reasoning, but it also costs more and can be slower. \\`max\\` is an exception, not a default.\n\nPrice is per task. Candidate cost is USD per million tokens, and roles differ in token volume and in what a mistake costs. High-volume, tool-checked roles such as exploration and routine implementation default to cheaper, faster models; roles where a missed defect is expensive, such as review, verification, and final approval, justify frontier models at high effort. Pick the tier first, then the effort within it; do not compensate for a cheap model with \\`max\\` or for an expensive one with \\`minimal\\`.\n\n| Stage role | Default thinking level | Model cost tier | Why |\n| --- | --- | --- | --- |\n| Codebase exploration: locating files, reading code, tracing call sites | \\`minimal\\` or \\`low\\` | Cheap, fast | Tool-driven lookups need speed, not deliberation; escalate to mapping or analysis only when the question becomes a design judgement. |\n| Coding, implementation, routine fixes | \\`low\\` or \\`medium\\` | Cheap or mid-priced | Runs many times per task and is validated by tools and review afterwards. |\n| Code review, test design, failure analysis, security, identity, adversarial challenge, final approval | \\`high\\` or \\`xhigh\\` | Frontier | A missed defect is the expensive outcome; spend the strongest model and reasoning here. |\n| Codebase mapping, lifecycle analysis, compatibility, planning, synthesis, triage | \\`high\\` | Frontier or mid-priced | Resolve ambiguity before downstream work depends on it. |\n| Orchestration, delegation, and multi-stage coordination | \\`medium\\` or \\`high\\` | Mid-priced | Judge scope, sequence work, and integrate results without re-deriving what delegated stages already verified. |\n| User-impact review and final reporting | \\`medium\\` | Mid-priced | Preserve evidence and communicate clearly without unnecessary reasoning. |\n| Deterministic checks | No model call | — | Run tests, typechecks, probes, and scripts directly. |\n\nAn explicit user request wins over these defaults, but the requested level must exist for the selected catalog entry. Do not invent unsupported suffixes. If \\`xhigh\\` is unavailable, use \\`high\\` rather than automatically promoting to \\`max\\`; choose another catalog model or leave the stage unpinned if neither fits.\n`;\n\n// Jev 1.13 allows 32k tokens for state plus the longest question. Routing charges\n// one byte per token and stays under 30_000. This is what remains for the full\n// evals snapshot after the model-selection guide, a 9_000-byte task, and a\n// nine-candidate question.\nexport const MODEL_SELECTION_EVALS_JSON_BYTES = 14_200;\nconst EVALS_BUDGET_ERROR = `Auto routing requires a nonempty evals.md document within ${MODEL_SELECTION_EVALS_JSON_BYTES.toLocaleString(\"en-US\")} JSON-encoded bytes. Repair the Atomic installation or select a concrete execution model.`;\nfunction jsonBytes(value: string): number {\n\treturn Buffer.byteLength(JSON.stringify(value), \"utf8\");\n}\n\nasync function readModelSelectionEvals(signal?: AbortSignal): Promise<string> {\n\ttry {\n\t\tconst evals = await readFile(join(getDocsPath(), \"models\", \"evals.md\"), { encoding: \"utf8\", signal });\n\t\tif (!evals.trim() || jsonBytes(evals) > MODEL_SELECTION_EVALS_JSON_BYTES) throw new Error(EVALS_BUDGET_ERROR);\n\t\treturn evals;\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\tif (error instanceof Error && error.message === EVALS_BUDGET_ERROR) throw error;\n\t\tthrow new Error(EVALS_BUDGET_ERROR);\n\t}\n}\n\nexport async function routeExecutionModel(input: {\n\tctx: ModelRoutingContext;\n\ttask: string;\n\tagent: { name: string; description: string };\n\tconstraints?: readonly ModelConstraints[];\n\tsignal?: AbortSignal;\n\t/** Restore a recorded decision without another inference call. */\n\tselection?: ModelRouterOutput;\n}): Promise<ModelRoute> {\n\tconst { ctx, signal } = input;\n\tsignal?.throwIfAborted();\n\tconst constraints = structuredClone((input.constraints ?? []).map((c) => parseModelConstraints(c)!));\n\tconst catalog = () =>\n\t\tctx.modelRegistry\n\t\t\t.getAvailable()\n\t\t\t.filter((model) => model.provider !== \"typesafe-ai\")\n\t\t\t.map((model) => ({\n\t\t\t\tmodel,\n\t\t\t\tpairs: (model.reasoning ? getSupportedThinkingLevels(model) : [null])\n\t\t\t\t\t.map((effort) => ({ model: `${model.provider}/${model.id}`, effort }))\n\t\t\t\t\t.filter((pair) => eligiblePair(model, pair, constraints)),\n\t\t\t}))\n\t\t\t.filter((entry) => entry.pairs.length > 0);\n\tconst available = catalog();\n\tconst pairs = available.flatMap((entry) => entry.pairs);\n\tif (!pairs.length)\n\t\tthrow new Error(\n\t\t\t\"Auto routing has no eligible model/effort pairs. Check configured providers and modelConstraints.\",\n\t\t);\n\tlet selection = input.selection;\n\tif (selection === undefined) {\n\t\tconst settings = { getRouterModel: () => ctx.getRouterModel() };\n\t\tresolveRouterModel({ settings, currentModel: ctx.model, modelRegistry: ctx.modelRegistry });\n\t\tconst candidates = available.flatMap(({ model, pairs }) =>\n\t\t\tpairs.map((pair) => ({\n\t\t\t\t...pair,\n\t\t\t\tinput: model.input,\n\t\t\t\tcontextWindow: model.contextWindow,\n\t\t\t\tcost: { ...model.cost, tiers: (model.cost.tiers ?? []).map((tier) => ({ ...tier })) },\n\t\t\t})),\n\t\t);\n\t\tconst allCriteria = Object.fromEntries(\n\t\t\tcandidates.map((candidate, index) => [`pair_${index}`, JSON.stringify(candidate)]),\n\t\t);\n\t\tconst state = {\n\t\t\ttask: input.task,\n\t\t\tagent: { name: input.agent.name, description: input.agent.description },\n\t\t\tevals: await readModelSelectionEvals(signal),\n\t\t\tmodel_selection_guide: MODEL_SELECTION_GUIDE,\n\t\t};\n\t\tif (!state.task.trim()) throw new Error(\"Auto routing requires task instructions.\");\n\t\tconst serialized = JSON.stringify({ state, criteria: allCriteria, constraints });\n\t\tlet configuredCredential: boolean;\n\t\ttry {\n\t\t\tconfiguredCredential = await ctx.modelRegistry.containsConfiguredCredential(serialized);\n\t\t} catch {\n\t\t\tthrow new Error(\"Auto routing could not screen configured credentials. No inference was performed.\");\n\t\t}\n\t\tif (\n\t\t\tcontainsKnownEnvCredential(serialized) ||\n\t\t\tconfiguredCredential ||\n\t\t\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\\b(?:sk|ghp|github_pat)[-_][A-Za-z0-9_-]{16,}/i.test(\n\t\t\t\tserialized,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(\"Auto routing context contains credential material. Remove secrets before retrying.\");\n\t\t// Screen the full task first, even credentials in text the router will omit.\n\t\t// Shortening only affects the routing request, never the execution prompt,\n\t\t// so it is not surfaced to the user.\n\t\tstate.task = modelRoutingTask(state.task);\n\t\tconst ranked: ModelRouterOutput[] = [];\n\t\t// Rank by repeated bounded choices, excluding all efforts of earlier models.\n\t\t// Probabilities from separate tournament batches are not comparable.\n\t\twhile (ranked.length < Math.min(3, available.length)) {\n\t\t\tconst remaining = pairs.filter((pair) => !ranked.some((selected) => selected.model === pair.model));\n\t\t\tif (!remaining.length) break;\n\t\t\tconst criteria = Object.fromEntries(\n\t\t\t\tremaining.map((pair) => {\n\t\t\t\t\tconst key = `pair_${pairs.indexOf(pair)}`;\n\t\t\t\t\treturn [key, allCriteria[key]];\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// Strict Responses providers reject object unions. Enumerate scalar values\n\t\t\t// on the wire, then verify the exact model/effort relation before admission.\n\t\t\tconst schema = Type.Unsafe<ModelRouterOutput>({\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tmodel: Type.String({ enum: [...new Set(remaining.map((pair) => pair.model))] }),\n\t\t\t\t\teffort: { type: [\"string\", \"null\"], enum: [...new Set(remaining.map((pair) => pair.effort))] },\n\t\t\t\t},\n\t\t\t\trequired: [\"model\", \"effort\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t});\n\t\t\tconst result = await inferRouterDecision(\n\t\t\t\t{\n\t\t\t\t\tsettings,\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\tstate,\n\t\t\t\t\tinstructions,\n\t\t\t\t\tschema,\n\t\t\t\t\tjev: {\n\t\t\t\t\t\tquestions: {\n\t\t\t\t\t\t\tpair: {\n\t\t\t\t\t\t\t\tinstructions:\n\t\t\t\t\t\t\t\t\t\"Which eligible model and reasoning effort best suit this task and agent role, considering the model_selection_guide role tiers, evals, and candidate capabilities and prices? Prefer cheaper candidates for exploration and routine implementation and stronger ones for review and verification. Candidate cost is USD per million tokens, not benchmark task cost.\",\n\t\t\t\t\t\t\t\tcriteria,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdecode: (choices) => {\n\t\t\t\t\t\t\tconst pair = pairs[Number(choices.pair?.replace(/^pair_/, \"\"))];\n\t\t\t\t\t\t\tif (!pair || choices.pair !== `pair_${pairs.indexOf(pair)}`)\n\t\t\t\t\t\t\t\tthrow new Error(\"Invalid execution model Choice.\");\n\t\t\t\t\t\t\treturn { ...pair };\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tsignal,\n\t\t\t\t},\n\t\t\t\t(value) => remaining.some((pair) => pair.model === value.model && pair.effort === value.effort),\n\t\t\t);\n\t\t\tranked.push(result.value);\n\t\t}\n\t\tselection = { ...ranked[0]!, ...(ranked.length > 1 ? { fallbacks: ranked.slice(1) } : {}) };\n\t}\n\tconst fallbacks = selection.fallbacks?.map((pair) => Object.freeze({ model: pair.model, effort: pair.effort }));\n\tif (\n\t\tfallbacks &&\n\t\t(fallbacks.length > 2 ||\n\t\t\tnew Set([selection.model, ...fallbacks.map((pair) => pair.model)]).size !== fallbacks.length + 1)\n\t)\n\t\tthrow new Error(\"Invalid ranked auto selection: expected up to three distinct models.\");\n\tconst routerSelection = Object.freeze({\n\t\tmodel: selection.model,\n\t\teffort: selection.effort,\n\t\t...(fallbacks?.length ? { fallbacks: Object.freeze(fallbacks) } : {}),\n\t});\n\tconst hasPair = (pair: ModelRouterOutput) =>\n\t\tcatalog().some((entry) => entry.pairs.some((p) => p.model === pair.model && p.effort === pair.effort));\n\tconst allowsModel = (model: Model<Api>, effort?: string): boolean => {\n\t\tconst levels = model.reasoning ? getSupportedThinkingLevels(model) : [null];\n\t\treturn levels.some((level) => {\n\t\t\tif (model.reasoning && effort !== undefined && level !== effort) return false;\n\t\t\tconst pair = { model: `${model.provider}/${model.id}`, effort: level };\n\t\t\treturn eligiblePair(model, pair, constraints) && hasPair(pair);\n\t\t});\n\t};\n\tconst assertCurrent = () => {\n\t\tsignal?.throwIfAborted();\n\t\tif (![routerSelection, ...(routerSelection.fallbacks ?? [])].every(hasPair))\n\t\t\tthrow new Error(\"Auto selection is no longer eligible. Retry explicitly with the current catalog.\");\n\t};\n\tassertCurrent();\n\treturn {\n\t\trouterSelection,\n\t\tmodelOverride: routerSelection.model + (routerSelection.effort === null ? \"\" : `:${routerSelection.effort}`),\n\t\tfallbackModels: Object.freeze(\n\t\t\t(routerSelection.fallbacks ?? []).map((pair) => pair.model + (pair.effort === null ? \"\" : `:${pair.effort}`)),\n\t\t),\n\t\tassertCurrent,\n\t\tallowsModel,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"execution-model-router.js","sourceRoot":"","sources":["../../src/core/execution-model-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAY,0BAA0B,EAAE,0BAA0B,EAAc,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EACN,YAAY,EAGZ,qBAAqB,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAmBvF;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAQnD,YAAY,OAAe,EAAE,iBAA8B;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,iBAAiB,KAAK,SAAS;YAAE,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IACjF,CAAC;CACD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AI,KAAK,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACvE,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,aAAa,GAAG,GAAG,EAAE;QAC1B,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;YAC1E,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;IACtG,CAAC,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,OAAO;QACN,eAAe;QACf,aAAa,EAAE,eAAe,CAAC,KAAK,GAAG,CAAC,eAAe,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC5G,cAAc,EAAE,MAAM,CAAC,MAAM,CAC5B,CAAC,eAAe,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAC7G;QACD,aAAa;QACb,WAAW;KACX,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { type Api, containsKnownEnvCredential, getSupportedThinkingLevels, type Model } from \"@bastani/pi-ai\";\nimport { Type } from \"typebox\";\nimport { getDocsPath } from \"../config.js\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport {\n\teligiblePair,\n\ttype ModelConstraints,\n\ttype ModelRouterOutput,\n\tparseModelConstraints,\n} from \"./model-routing-constraints.js\";\nimport { modelRoutingTask } from \"./model-routing-task.js\";\nimport { inferRouterDecision, resolveRouterModel } from \"./structured-output/index.js\";\n\nexport interface ModelRoutingContext {\n\treadonly modelRegistry: Pick<\n\t\tModelRegistry,\n\t\t\"getAll\" | \"getAvailable\" | \"streamSimple\" | \"containsConfiguredCredential\"\n\t> &\n\t\tPartial<Pick<ModelRegistry, \"getProviderAuthStatus\" | \"getProviderAuth\">>;\n\treadonly model?: Model<Api>;\n\tgetRouterModel(): string;\n}\nexport interface ModelRoute {\n\treadonly routerSelection: ModelRouterOutput;\n\treadonly modelOverride: string;\n\treadonly fallbackModels?: readonly string[];\n\tassertCurrent(): void;\n\tallowsModel(model: Model<Api>, effort?: string): boolean;\n}\n\n/**\n * Total auto-routing inference failure: Jev and the chat structured-output\n * fallback both failed before any model was selected (#3206). Validation,\n * eligibility, and credential-screening errors are never marked.\n */\nexport class AutoRoutingInferenceError extends Error {\n\t/**\n\t * Route pinned to the current chat model, present only when that model is\n\t * available and satisfies every routing constraint. Consumers may degrade\n\t * to it; when it is absent the failure stays fatal.\n\t */\n\treadonly currentModelRoute?: ModelRoute;\n\n\tconstructor(message: string, currentModelRoute?: ModelRoute) {\n\t\tsuper(message);\n\t\tthis.name = \"AutoRoutingInferenceError\";\n\t\tif (currentModelRoute !== undefined) this.currentModelRoute = currentModelRoute;\n\t}\n}\n\n/** Degraded routes keep a balanced effort when the constraints leave a choice. */\nconst CURRENT_MODEL_EFFORT_PREFERENCE: readonly (string | null)[] = [\n\tnull,\n\t\"medium\",\n\t\"high\",\n\t\"low\",\n\t\"xhigh\",\n\t\"minimal\",\n\t\"max\",\n\t\"off\",\n];\nconst instructions =\n\t\"Select one eligible model/effort pair for `task` and `agent` from the supplied Choice criteria, using `evals` as evidence and `model_selection_guide` as policy. Match the agent role to the guide's model cost tier and thinking level first, then consider task fit, measured effort, dates, caveats and cost. Evals cannot add candidates or bypass constraints. Return exactly model and effort; null means no configurable reasoning.\";\n\n/** Static selection policy sent with every auto-routing request alongside the dated `evals` evidence. */\nexport const MODEL_SELECTION_GUIDE = `## Benchmarks are evidence, not policy\n\nBenchmark results are measurements under named harnesses, dates, models, efforts, agents, tools, prompts, prices, and scoring rules. Treat a bracketed effort level as the measurement configuration for that row, not a command to run every task at that effort. Compare only records whose measured setup resembles the decision at hand, and keep unmeasured work under ordinary validation rather than inheriting a score.\n\nMissing evidence is unknown, not zero. A rounded lead is not proof of significance. A result for one provider, model version, effort, agent, fallback setting, or benchmark harness does not transfer to another identity.\n\n## Role-based thinking effort\n\nUse these starting defaults unless the user requests a level. Higher effort can improve hard reasoning, but it also costs more and can be slower. \\`max\\` is an exception, not a default.\n\nPrice is per task. Candidate cost is USD per million tokens, and roles differ in token volume and in what a mistake costs. High-volume, tool-checked roles such as exploration and routine implementation default to cheaper, faster models; roles where a missed defect is expensive, such as review, verification, and final approval, justify frontier models at high effort. Pick the tier first, then the effort within it; do not compensate for a cheap model with \\`max\\` or for an expensive one with \\`minimal\\`.\n\n| Stage role | Default thinking level | Model cost tier | Why |\n| --- | --- | --- | --- |\n| Codebase exploration: locating files, reading code, tracing call sites | \\`minimal\\` or \\`low\\` | Cheap, fast | Tool-driven lookups need speed, not deliberation; escalate to mapping or analysis only when the question becomes a design judgement. |\n| Coding, implementation, routine fixes | \\`low\\` or \\`medium\\` | Cheap or mid-priced | Runs many times per task and is validated by tools and review afterwards. |\n| Code review, test design, failure analysis, security, identity, adversarial challenge, final approval | \\`high\\` or \\`xhigh\\` | Frontier | A missed defect is the expensive outcome; spend the strongest model and reasoning here. |\n| Codebase mapping, lifecycle analysis, compatibility, planning, synthesis, triage | \\`high\\` | Frontier or mid-priced | Resolve ambiguity before downstream work depends on it. |\n| Orchestration, delegation, and multi-stage coordination | \\`medium\\` or \\`high\\` | Mid-priced | Judge scope, sequence work, and integrate results without re-deriving what delegated stages already verified. |\n| User-impact review and final reporting | \\`medium\\` | Mid-priced | Preserve evidence and communicate clearly without unnecessary reasoning. |\n| Deterministic checks | No model call | — | Run tests, typechecks, probes, and scripts directly. |\n\nAn explicit user request wins over these defaults, but the requested level must exist for the selected catalog entry. Do not invent unsupported suffixes. If \\`xhigh\\` is unavailable, use \\`high\\` rather than automatically promoting to \\`max\\`; choose another catalog model or leave the stage unpinned if neither fits.\n`;\n\n// Jev 1.13 allows 32k tokens for state plus the longest question. Routing charges\n// one byte per token and stays under 30_000. This is what remains for the full\n// evals snapshot after the model-selection guide, a 9_000-byte task, and a\n// nine-candidate question.\nexport const MODEL_SELECTION_EVALS_JSON_BYTES = 14_200;\nconst EVALS_BUDGET_ERROR = `Auto routing requires a nonempty evals.md document within ${MODEL_SELECTION_EVALS_JSON_BYTES.toLocaleString(\"en-US\")} JSON-encoded bytes. Repair the Atomic installation or select a concrete execution model.`;\nfunction jsonBytes(value: string): number {\n\treturn Buffer.byteLength(JSON.stringify(value), \"utf8\");\n}\n\nasync function readModelSelectionEvals(signal?: AbortSignal): Promise<string> {\n\ttry {\n\t\tconst evals = await readFile(join(getDocsPath(), \"models\", \"evals.md\"), { encoding: \"utf8\", signal });\n\t\tif (!evals.trim() || jsonBytes(evals) > MODEL_SELECTION_EVALS_JSON_BYTES) throw new Error(EVALS_BUDGET_ERROR);\n\t\treturn evals;\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\tif (error instanceof Error && error.message === EVALS_BUDGET_ERROR) throw error;\n\t\tthrow new Error(EVALS_BUDGET_ERROR);\n\t}\n}\n\nexport async function routeExecutionModel(input: {\n\tctx: ModelRoutingContext;\n\ttask: string;\n\tagent: { name: string; description: string };\n\tconstraints?: readonly ModelConstraints[];\n\tsignal?: AbortSignal;\n\t/** Restore a recorded decision without another inference call. */\n\tselection?: ModelRouterOutput;\n}): Promise<ModelRoute> {\n\tconst { ctx, signal } = input;\n\tsignal?.throwIfAborted();\n\tconst constraints = structuredClone((input.constraints ?? []).map((c) => parseModelConstraints(c)!));\n\tconst catalog = () =>\n\t\tctx.modelRegistry\n\t\t\t.getAvailable()\n\t\t\t.filter((model) => model.provider !== \"typesafe-ai\")\n\t\t\t.map((model) => ({\n\t\t\t\tmodel,\n\t\t\t\tpairs: (model.reasoning ? getSupportedThinkingLevels(model) : [null])\n\t\t\t\t\t.map((effort) => ({ model: `${model.provider}/${model.id}`, effort }))\n\t\t\t\t\t.filter((pair) => eligiblePair(model, pair, constraints)),\n\t\t\t}))\n\t\t\t.filter((entry) => entry.pairs.length > 0);\n\tconst available = catalog();\n\tconst pairs = available.flatMap((entry) => entry.pairs);\n\tif (!pairs.length)\n\t\tthrow new Error(\n\t\t\t\"Auto routing has no eligible model/effort pairs. Check configured providers and modelConstraints.\",\n\t\t);\n\tlet selection = input.selection;\n\tif (selection === undefined) {\n\t\tconst settings = { getRouterModel: () => ctx.getRouterModel() };\n\t\tresolveRouterModel({ settings, currentModel: ctx.model, modelRegistry: ctx.modelRegistry });\n\t\tconst candidates = available.flatMap(({ model, pairs }) =>\n\t\t\tpairs.map((pair) => ({\n\t\t\t\t...pair,\n\t\t\t\tinput: model.input,\n\t\t\t\tcontextWindow: model.contextWindow,\n\t\t\t\tcost: { ...model.cost, tiers: (model.cost.tiers ?? []).map((tier) => ({ ...tier })) },\n\t\t\t})),\n\t\t);\n\t\tconst allCriteria = Object.fromEntries(\n\t\t\tcandidates.map((candidate, index) => [`pair_${index}`, JSON.stringify(candidate)]),\n\t\t);\n\t\tconst state = {\n\t\t\ttask: input.task,\n\t\t\tagent: { name: input.agent.name, description: input.agent.description },\n\t\t\tevals: await readModelSelectionEvals(signal),\n\t\t\tmodel_selection_guide: MODEL_SELECTION_GUIDE,\n\t\t};\n\t\tif (!state.task.trim()) throw new Error(\"Auto routing requires task instructions.\");\n\t\tconst serialized = JSON.stringify({ state, criteria: allCriteria, constraints });\n\t\tlet configuredCredential: boolean;\n\t\ttry {\n\t\t\tconfiguredCredential = await ctx.modelRegistry.containsConfiguredCredential(serialized);\n\t\t} catch {\n\t\t\tthrow new Error(\"Auto routing could not screen configured credentials. No inference was performed.\");\n\t\t}\n\t\tif (\n\t\t\tcontainsKnownEnvCredential(serialized) ||\n\t\t\tconfiguredCredential ||\n\t\t\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\\b(?:sk|ghp|github_pat)[-_][A-Za-z0-9_-]{16,}/i.test(\n\t\t\t\tserialized,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(\"Auto routing context contains credential material. Remove secrets before retrying.\");\n\t\t// Screen the full task first, even credentials in text the router will omit.\n\t\t// Shortening only affects the routing request, never the execution prompt,\n\t\t// so it is not surfaced to the user.\n\t\tstate.task = modelRoutingTask(state.task);\n\t\tconst ranked: ModelRouterOutput[] = [];\n\t\t// Degrade only to a current chat model that is available and eligible under\n\t\t// the same constraints, restored through the normal selection path (#3206).\n\t\tconst currentModelRoute = async (): Promise<ModelRoute | undefined> => {\n\t\t\tconst current = ctx.model;\n\t\t\tconst entry = available.find(\n\t\t\t\t(candidate) => candidate.model.provider === current?.provider && candidate.model.id === current?.id,\n\t\t\t);\n\t\t\tconst pair = CURRENT_MODEL_EFFORT_PREFERENCE.map((effort) =>\n\t\t\t\tentry?.pairs.find((candidate) => candidate.effort === effort),\n\t\t\t).find((candidate) => candidate !== undefined);\n\t\t\tif (pair === undefined) return undefined;\n\t\t\treturn routeExecutionModel({ ...input, selection: { model: pair.model, effort: pair.effort } });\n\t\t};\n\t\t// Rank by repeated bounded choices, excluding all efforts of earlier models.\n\t\t// Probabilities from separate tournament batches are not comparable.\n\t\t// Only a failure before the primary is chosen is a total inference failure:\n\t\t// Jev and its chat structured-output fallback both failed (#3206). A failed\n\t\t// optional fallback-ranking pass keeps the models already ranked.\n\t\twhile (ranked.length < Math.min(3, available.length)) {\n\t\t\tconst remaining = pairs.filter((pair) => !ranked.some((selected) => selected.model === pair.model));\n\t\t\tif (!remaining.length) break;\n\t\t\tconst criteria = Object.fromEntries(\n\t\t\t\tremaining.map((pair) => {\n\t\t\t\t\tconst key = `pair_${pairs.indexOf(pair)}`;\n\t\t\t\t\treturn [key, allCriteria[key]];\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// Strict Responses providers reject object unions. Enumerate scalar values\n\t\t\t// on the wire, then verify the exact model/effort relation before admission.\n\t\t\tconst schema = Type.Unsafe<ModelRouterOutput>({\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tmodel: Type.String({ enum: [...new Set(remaining.map((pair) => pair.model))] }),\n\t\t\t\t\teffort: { type: [\"string\", \"null\"], enum: [...new Set(remaining.map((pair) => pair.effort))] },\n\t\t\t\t},\n\t\t\t\trequired: [\"model\", \"effort\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t});\n\t\t\tlet result: Awaited<ReturnType<typeof inferRouterDecision<typeof schema>>>;\n\t\t\ttry {\n\t\t\t\tresult = await inferRouterDecision(\n\t\t\t\t\t{\n\t\t\t\t\t\tsettings,\n\t\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tinstructions,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tjev: {\n\t\t\t\t\t\t\tquestions: {\n\t\t\t\t\t\t\t\tpair: {\n\t\t\t\t\t\t\t\t\tinstructions:\n\t\t\t\t\t\t\t\t\t\t\"Which eligible model and reasoning effort best suit this task and agent role, considering the model_selection_guide role tiers, evals, and candidate capabilities and prices? Prefer cheaper candidates for exploration and routine implementation and stronger ones for review and verification. Candidate cost is USD per million tokens, not benchmark task cost.\",\n\t\t\t\t\t\t\t\t\tcriteria,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdecode: (choices) => {\n\t\t\t\t\t\t\t\tconst pair = pairs[Number(choices.pair?.replace(/^pair_/, \"\"))];\n\t\t\t\t\t\t\t\tif (!pair || choices.pair !== `pair_${pairs.indexOf(pair)}`)\n\t\t\t\t\t\t\t\t\tthrow new Error(\"Invalid execution model Choice.\");\n\t\t\t\t\t\t\t\treturn { ...pair };\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t\t(value) => remaining.some((pair) => pair.model === value.model && pair.effort === value.effort),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tif (ranked.length > 0) break;\n\t\t\t\tthrow new AutoRoutingInferenceError(\n\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\tawait currentModelRoute().catch(() => undefined),\n\t\t\t\t);\n\t\t\t}\n\t\t\tranked.push(result.value);\n\t\t}\n\t\tselection = { ...ranked[0]!, ...(ranked.length > 1 ? { fallbacks: ranked.slice(1) } : {}) };\n\t}\n\tconst fallbacks = selection.fallbacks?.map((pair) => Object.freeze({ model: pair.model, effort: pair.effort }));\n\tif (\n\t\tfallbacks &&\n\t\t(fallbacks.length > 2 ||\n\t\t\tnew Set([selection.model, ...fallbacks.map((pair) => pair.model)]).size !== fallbacks.length + 1)\n\t)\n\t\tthrow new Error(\"Invalid ranked auto selection: expected up to three distinct models.\");\n\tconst routerSelection = Object.freeze({\n\t\tmodel: selection.model,\n\t\teffort: selection.effort,\n\t\t...(fallbacks?.length ? { fallbacks: Object.freeze(fallbacks) } : {}),\n\t});\n\tconst hasPair = (pair: ModelRouterOutput) =>\n\t\tcatalog().some((entry) => entry.pairs.some((p) => p.model === pair.model && p.effort === pair.effort));\n\tconst allowsModel = (model: Model<Api>, effort?: string): boolean => {\n\t\tconst levels = model.reasoning ? getSupportedThinkingLevels(model) : [null];\n\t\treturn levels.some((level) => {\n\t\t\tif (model.reasoning && effort !== undefined && level !== effort) return false;\n\t\t\tconst pair = { model: `${model.provider}/${model.id}`, effort: level };\n\t\t\treturn eligiblePair(model, pair, constraints) && hasPair(pair);\n\t\t});\n\t};\n\tconst assertCurrent = () => {\n\t\tsignal?.throwIfAborted();\n\t\tif (![routerSelection, ...(routerSelection.fallbacks ?? [])].every(hasPair))\n\t\t\tthrow new Error(\"Auto selection is no longer eligible. Retry explicitly with the current catalog.\");\n\t};\n\tassertCurrent();\n\treturn {\n\t\trouterSelection,\n\t\tmodelOverride: routerSelection.model + (routerSelection.effort === null ? \"\" : `:${routerSelection.effort}`),\n\t\tfallbackModels: Object.freeze(\n\t\t\t(routerSelection.fallbacks ?? []).map((pair) => pair.model + (pair.effort === null ? \"\" : `:${pair.effort}`)),\n\t\t),\n\t\tassertCurrent,\n\t\tallowsModel,\n\t};\n}\n"]}
|
|
@@ -4,6 +4,14 @@ import type { ModelsJsonModelOverride } from "./model-config.ts";
|
|
|
4
4
|
export declare const FAST_MODEL_ID_SUFFIX = "-fast";
|
|
5
5
|
/** Service tier OpenAI-style providers use to route fast traffic. */
|
|
6
6
|
export declare const FAST_MODEL_SERVICE_TIER: "priority";
|
|
7
|
+
/** Inference speed Anthropic's Messages API uses to route fast traffic. */
|
|
8
|
+
export declare const FAST_MODEL_SPEED: "fast";
|
|
9
|
+
/**
|
|
10
|
+
* Claude models Anthropic's fast mode accepts. Requesting `speed: "fast"` on any other model is an
|
|
11
|
+
* error, so the list is explicit rather than a family-name pattern.
|
|
12
|
+
* https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models
|
|
13
|
+
*/
|
|
14
|
+
export declare const ANTHROPIC_FAST_MODE_MODEL_IDS: ReadonlySet<string>;
|
|
7
15
|
/** A derived fast variant that was suppressed because something already owns its exact model ID. */
|
|
8
16
|
export interface FastModelVariantDiagnostic {
|
|
9
17
|
provider: string;
|
|
@@ -61,8 +69,26 @@ export declare function isNativeFastRouteApi(api: Api): api is "openai-responses
|
|
|
61
69
|
* because selecting it would send an ordinary request under a name that promises otherwise.
|
|
62
70
|
*/
|
|
63
71
|
export declare function usesOpenAIFastServiceTier(model: Pick<Model<Api>, "api" | "provider">): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* xAI Priority Processing keeps the base upstream Grok model ID and adds the same
|
|
74
|
+
* `service_tier: "priority"` field on the Responses API. xAI has no `-fast` model slugs for current
|
|
75
|
+
* Grok models; priority is billed at twice the standard token rates, and only when the response
|
|
76
|
+
* confirms the tier. https://docs.x.ai/developers/advanced-api-usage/priority-processing
|
|
77
|
+
*
|
|
78
|
+
* Eligibility requires the first-party `xai` provider on `openai-responses`. OpenRouter, Vercel AI
|
|
79
|
+
* Gateway, and renamed or proxied xAI-compatible providers do not qualify.
|
|
80
|
+
*/
|
|
81
|
+
export declare function usesXaiFastServiceTier(model: Pick<Model<Api>, "api" | "provider">): boolean;
|
|
64
82
|
/** GitHub Copilot advertises real fast sibling model IDs per account; it never uses a service tier. */
|
|
65
83
|
export declare function isGitHubCopilotModel(model: Pick<Model<Api>, "provider">): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Anthropic fast mode keeps the base upstream model ID and adds `speed: "fast"` with the fast-mode beta.
|
|
86
|
+
*
|
|
87
|
+
* Eligibility requires the first-party `anthropic` provider on the Messages API and a supported model.
|
|
88
|
+
* Fast mode is not offered through Amazon Bedrock, Google Vertex, GitHub Copilot, OpenRouter, or a
|
|
89
|
+
* renamed or proxied Anthropic-compatible provider.
|
|
90
|
+
*/
|
|
91
|
+
export declare function usesAnthropicFastMode(model: Pick<Model<Api>, "api" | "id" | "provider">): boolean;
|
|
66
92
|
/** Read the exact fast model IDs a stored GitHub Copilot OAuth credential advertises. */
|
|
67
93
|
export declare function copilotAdvertisedFastModelIds(credential: Credential | undefined): readonly string[] | undefined;
|
|
68
94
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fast-model-variants.d.ts","sourceRoot":"","sources":["../../src/core/fast-model-variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAkB,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,KAAK,EAAE,u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A6B,GAAG,QAAQ,CAgB1G"}
|
|
@@ -3,6 +3,18 @@ import { applyModelOverride } from "./provider-composer-internal.js";
|
|
|
3
3
|
export const FAST_MODEL_ID_SUFFIX = "-fast";
|
|
4
4
|
/** Service tier OpenAI-style providers use to route fast traffic. */
|
|
5
5
|
export const FAST_MODEL_SERVICE_TIER = "priority";
|
|
6
|
+
/** Inference speed Anthropic's Messages API uses to route fast traffic. */
|
|
7
|
+
export const FAST_MODEL_SPEED = "fast";
|
|
8
|
+
/**
|
|
9
|
+
* Claude models Anthropic's fast mode accepts. Requesting `speed: "fast"` on any other model is an
|
|
10
|
+
* error, so the list is explicit rather than a family-name pattern.
|
|
11
|
+
* https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models
|
|
12
|
+
*/
|
|
13
|
+
export const ANTHROPIC_FAST_MODE_MODEL_IDS = new Set([
|
|
14
|
+
"claude-opus-5-5",
|
|
15
|
+
"claude-opus-5",
|
|
16
|
+
"claude-opus-4-8",
|
|
17
|
+
]);
|
|
6
18
|
/** Canonical selectable ID of the fast variant of `baseModelId`. */
|
|
7
19
|
export function fastModelId(baseModelId) {
|
|
8
20
|
return `${baseModelId}${FAST_MODEL_ID_SUFFIX}`;
|
|
@@ -27,10 +39,34 @@ export function isNativeFastRouteApi(api) {
|
|
|
27
39
|
export function usesOpenAIFastServiceTier(model) {
|
|
28
40
|
return isNativeFastRouteApi(model.api) && (model.provider === "openai" || model.provider === "openai-codex");
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* xAI Priority Processing keeps the base upstream Grok model ID and adds the same
|
|
44
|
+
* `service_tier: "priority"` field on the Responses API. xAI has no `-fast` model slugs for current
|
|
45
|
+
* Grok models; priority is billed at twice the standard token rates, and only when the response
|
|
46
|
+
* confirms the tier. https://docs.x.ai/developers/advanced-api-usage/priority-processing
|
|
47
|
+
*
|
|
48
|
+
* Eligibility requires the first-party `xai` provider on `openai-responses`. OpenRouter, Vercel AI
|
|
49
|
+
* Gateway, and renamed or proxied xAI-compatible providers do not qualify.
|
|
50
|
+
*/
|
|
51
|
+
export function usesXaiFastServiceTier(model) {
|
|
52
|
+
return model.api === "openai-responses" && model.provider === "xai";
|
|
53
|
+
}
|
|
30
54
|
/** GitHub Copilot advertises real fast sibling model IDs per account; it never uses a service tier. */
|
|
31
55
|
export function isGitHubCopilotModel(model) {
|
|
32
56
|
return model.provider === "github-copilot";
|
|
33
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Anthropic fast mode keeps the base upstream model ID and adds `speed: "fast"` with the fast-mode beta.
|
|
60
|
+
*
|
|
61
|
+
* Eligibility requires the first-party `anthropic` provider on the Messages API and a supported model.
|
|
62
|
+
* Fast mode is not offered through Amazon Bedrock, Google Vertex, GitHub Copilot, OpenRouter, or a
|
|
63
|
+
* renamed or proxied Anthropic-compatible provider.
|
|
64
|
+
*/
|
|
65
|
+
export function usesAnthropicFastMode(model) {
|
|
66
|
+
return (model.api === "anthropic-messages" &&
|
|
67
|
+
model.provider === "anthropic" &&
|
|
68
|
+
ANTHROPIC_FAST_MODE_MODEL_IDS.has(model.id));
|
|
69
|
+
}
|
|
34
70
|
function advertisedModelIds(value) {
|
|
35
71
|
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string"))
|
|
36
72
|
return undefined;
|
|
@@ -57,9 +93,12 @@ export function copilotAdvertisesModelId(credential, modelId) {
|
|
|
57
93
|
advertisedModelIds(credential.fastModelIds)?.includes(modelId) === true);
|
|
58
94
|
}
|
|
59
95
|
function fastRouteForBaseModel(model, entitledCopilotFastModelIds) {
|
|
60
|
-
if (usesOpenAIFastServiceTier(model)) {
|
|
96
|
+
if (usesOpenAIFastServiceTier(model) || usesXaiFastServiceTier(model)) {
|
|
61
97
|
return { baseModelId: model.id, upstreamModelId: model.id, serviceTier: FAST_MODEL_SERVICE_TIER };
|
|
62
98
|
}
|
|
99
|
+
if (usesAnthropicFastMode(model)) {
|
|
100
|
+
return { baseModelId: model.id, upstreamModelId: model.id, speed: FAST_MODEL_SPEED };
|
|
101
|
+
}
|
|
63
102
|
if (isGitHubCopilotModel(model)) {
|
|
64
103
|
const advertisedId = fastModelId(model.id);
|
|
65
104
|
return entitledCopilotFastModelIds.has(advertisedId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fast-model-variants.js","sourceRoot":"","sources":["../../src/core/fast-model-variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAE5C,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAmB,CAAC;AA6C3D,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC9C,OAAO,GAAG,WAAW,GAAG,oBAAoB,EAAE,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAQ;IAC5C,OAAO,GAAG,KAAK,kBAAkB,IAAI,GAAG,KAAK,wBAAwB,CAAC;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAA2C;IACpF,OAAO,oBAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,KAAK,cAAc,CAAC,CAAC;AAC9G,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,oBAAoB,CAAC,KAAmC;IACvE,OAAO,KAAK,CAAC,QAAQ,KAAK,gBAAgB,CAAC;AAC5C,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAC;IAClG,OAA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AE,EAAE,WAAW,CAAC,CAAC;YAClD,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { Api, Credential, Model, ModelFastRoute, Provider } from \"@bastani/pi-ai\";\nimport type { ModelsJsonModelOverride } from \"./model-config.ts\";\nimport { applyModelOverride } from \"./provider-composer-internal.ts\";\n\n/** Canonical suffix every selectable fast model variant carries. */\nexport const FAST_MODEL_ID_SUFFIX = \"-fast\";\n\n/** Service tier OpenAI-style providers use to route fast traffic. */\nexport const FAST_MODEL_SERVICE_TIER = \"priority\" as const;\n\n/** A derived fast variant that was suppressed because something already owns its exact model ID. */\nexport interface FastModelVariantDiagnostic {\n\tprovider: string;\n\t/** The exact selectable model ID that collided. */\n\tmodelId: string;\n\tmessage: string;\n}\n\nexport interface FastModelVariantDerivation {\n\tmodels: readonly Model<Api>[];\n\tdiagnostics: readonly FastModelVariantDiagnostic[];\n}\n\nexport interface DeriveFastModelVariantsOptions {\n\t/** Exact fast model IDs the stored GitHub Copilot credential advertises for this account. */\n\tcopilotFastModelIds?: readonly string[];\n\t/** `models.json` `modelOverrides` for this provider, applied to derived entries by their exact `-fast` ID. */\n\tmodelOverrides?: Readonly<Record<string, ModelsJsonModelOverride>>;\n\t/** APIs whose transport a registered extension owns for this provider. No variant is derived for them. */\n\textensionOwnedApis?: ReadonlySet<Api>;\n\t/** IDs explicitly declared in this provider's models.json models array. Never derive siblings for them. */\n\tcustomModelIds?: ReadonlySet<string>;\n}\n\nexport interface FastModelVariantsOptions {\n\t/**\n\t * Synchronous read of the exact fast model IDs the stored GitHub Copilot credential advertises.\n\t * Read per call so a credential that lands after provider composition still takes effect.\n\t */\n\tgetCopilotFastModelIds?: () => readonly string[] | undefined;\n\t/** Synchronous read of this provider's `models.json` `modelOverrides`, so a reload takes effect. */\n\tgetModelOverrides?: () => Readonly<Record<string, ModelsJsonModelOverride>> | undefined;\n\t/** Read current custom model IDs per pass so models.json reloads update eligibility. */\n\tgetCustomModelIds?: () => ReadonlySet<string>;\n\t/**\n\t * Synchronous read of the APIs a registered extension supplies a stream function for. Read per call\n\t * because extensions register after initial composition on some paths.\n\t */\n\tgetExtensionOwnedApis?: () => ReadonlySet<Api> | undefined;\n\t/** Called after every derivation pass with the complete diagnostic list for this provider. */\n\tonDiagnostics?: (providerId: string, diagnostics: readonly FastModelVariantDiagnostic[]) => void;\n}\n\n/** Canonical selectable ID of the fast variant of `baseModelId`. */\nexport function fastModelId(baseModelId: string): string {\n\treturn `${baseModelId}${FAST_MODEL_ID_SUFFIX}`;\n}\n\n/**\n * The two pi-ai adapters that serialize `service_tier`. `azure-openai-responses` and\n * `openai-completions` have no such option, and `streamSimple` drops it, so a service-tier route on\n * any other API would silently degrade to an ordinary request.\n */\nexport function isNativeFastRouteApi(api: Api): api is \"openai-responses\" | \"openai-codex-responses\" {\n\treturn api === \"openai-responses\" || api === \"openai-codex-responses\";\n}\n\n/**\n * OpenAI-style fast routing keeps the base upstream model ID and adds a priority service tier.\n *\n * Eligibility requires both a first-party provider ID and an adapter that serializes\n * `service_tier`. A renamed provider, proxy, Azure OpenAI (`azure-openai-responses`), OpenRouter\n * (`openai-completions`), and generic OpenAI-compatible providers do not qualify. An `openai` or\n * `openai-codex` model on an adapter that cannot carry `service_tier` must not offer a fast variant,\n * because selecting it would send an ordinary request under a name that promises otherwise.\n */\nexport function usesOpenAIFastServiceTier(model: Pick<Model<Api>, \"api\" | \"provider\">): boolean {\n\treturn isNativeFastRouteApi(model.api) && (model.provider === \"openai\" || model.provider === \"openai-codex\");\n}\n\n/** GitHub Copilot advertises real fast sibling model IDs per account; it never uses a service tier. */\nexport function isGitHubCopilotModel(model: Pick<Model<Api>, \"provider\">): boolean {\n\treturn model.provider === \"github-copilot\";\n}\n\nfunction advertisedModelIds(value: unknown): readonly string[] | undefined {\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) return undefined;\n\treturn value;\n}\n\n/** Read the exact fast model IDs a stored GitHub Copilot OAuth credential advertises. */\nexport function copilotAdvertisedFastModelIds(credential: Credential | undefined): readonly string[] | undefined {\n\tif (credential?.type !== \"oauth\") return undefined;\n\treturn advertisedModelIds(credential.fastModelIds);\n}\n\n/**\n * Whether a stored GitHub Copilot OAuth credential advertises this exact model ID at all — as a\n * selectable picker/policy model or as a fast sibling.\n *\n * Copilot's per-account advertisement is the authority the provider's own `filterModels` uses, so\n * restoration consults the same lists. An ID the account advertises as an ordinary model is ordinary,\n * whatever its name ends in.\n */\nexport function copilotAdvertisesModelId(credential: Credential | undefined, modelId: string): boolean {\n\tif (credential?.type !== \"oauth\") return false;\n\treturn (\n\t\tadvertisedModelIds(credential.availableModelIds)?.includes(modelId) === true ||\n\t\tadvertisedModelIds(credential.fastModelIds)?.includes(modelId) === true\n\t);\n}\n\nfunction fastRouteForBaseModel(\n\tmodel: Model<Api>,\n\tentitledCopilotFastModelIds: ReadonlySet<string>,\n): ModelFastRoute | undefined {\n\tif (usesOpenAIFastServiceTier(model)) {\n\t\treturn { baseModelId: model.id, upstreamModelId: model.id, serviceTier: FAST_MODEL_SERVICE_TIER };\n\t}\n\tif (isGitHubCopilotModel(model)) {\n\t\tconst advertisedId = fastModelId(model.id);\n\t\treturn entitledCopilotFastModelIds.has(advertisedId)\n\t\t\t? { baseModelId: model.id, upstreamModelId: advertisedId }\n\t\t\t: undefined;\n\t}\n\treturn undefined;\n}\n\n/**\n * Add a selectable `<base-model-id>-fast` entry for every eligible model, carrying the explicit\n * {@link ModelFastRoute} metadata that gives it fast semantics. The input list is preserved verbatim\n * and in order; each derived entry is appended directly after the model it derives from.\n *\n * A model whose exact `-fast` ID is already owned by the provider, a `models.json` custom model, or an\n * extension wins: derivation is suppressed for it and a diagnostic is recorded. The owning model keeps\n * whatever semantics it declares, because fast behavior comes only from `fastRoute`, never from the\n * `-fast` suffix. For the same reason a base model whose ID already ends in `-fast` is never used to\n * derive a `-fast-fast` variant: that is not a canonical ID this scheme defines.\n *\n * A derived entry is a real catalog model, so a `modelOverrides` entry keyed on its exact `-fast` ID\n * applies to it after derivation. Without that pass the derived entry would inherit the *base* model's\n * overrides and its own would be silently inert.\n *\n * No variant is derived for an API whose transport a registered extension owns, because Atomic cannot\n * enforce the route through a transport it does not serialize.\n */\nexport function deriveFastModelVariants(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\toptions: DeriveFastModelVariantsOptions = {},\n): FastModelVariantDerivation {\n\tconst ownedModelIds = new Set(models.map((model) => model.id));\n\tconst entitledCopilotFastModelIds = new Set(options.copilotFastModelIds ?? []);\n\tconst derived: Model<Api>[] = [];\n\tconst diagnostics: FastModelVariantDiagnostic[] = [];\n\tlet changed = false;\n\tfor (const model of models) {\n\t\tderived.push(model);\n\t\tif (model.fastRoute !== undefined || model.id.endsWith(FAST_MODEL_ID_SUFFIX)) continue;\n\t\tif (options.customModelIds?.has(model.id)) continue;\n\t\t// An extension that supplies this API's stream function owns its serialization, so Atomic cannot\n\t\t// guarantee the route reaches the wire. Publishing a `-fast` choice it may not honor is the same\n\t\t// hazard as publishing one for an adapter that cannot carry the tier.\n\t\tif (options.extensionOwnedApis?.has(model.api) === true) continue;\n\t\tconst fastRoute = fastRouteForBaseModel(model, entitledCopilotFastModelIds);\n\t\tif (!fastRoute) continue;\n\t\tconst variantId = fastModelId(model.id);\n\t\tif (ownedModelIds.has(variantId)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tprovider: providerId,\n\t\t\t\tmodelId: variantId,\n\t\t\t\tmessage:\n\t\t\t\t\t`Model \"${providerId}/${variantId}\" is already defined by the provider, models.json, or an extension, ` +\n\t\t\t\t\t`so Atomic did not derive a fast variant of \"${providerId}/${model.id}\". ` +\n\t\t\t\t\t`That model routes exactly as declared. Rename or remove it to get the derived fast variant instead.`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst override = options.modelOverrides?.[variantId];\n\t\tconst variant: Model<Api> = { ...model, id: variantId, name: `${model.name} (fast)`, fastRoute };\n\t\tderived.push(override ? applyModelOverride(variant, override) : variant);\n\t\tchanged = true;\n\t}\n\tif (!changed && diagnostics.length === 0) return { models, diagnostics };\n\treturn { models: derived, diagnostics };\n}\n\n/**\n * Overlay derived fast model variants onto a composed provider. Apply this after built-in,\n * `models.json`, extension, and `modelOverrides` composition so exact user-owned `-fast` IDs are\n * already present and win the collision.\n */\nexport function withFastModelVariants(provider: Provider, options: FastModelVariantsOptions = {}): Provider {\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => {\n\t\t\tconst { models, diagnostics } = deriveFastModelVariants(provider.id, provider.getModels(), {\n\t\t\t\tcopilotFastModelIds: isGitHubCopilotModel({ provider: provider.id })\n\t\t\t\t\t? options.getCopilotFastModelIds?.()\n\t\t\t\t\t: undefined,\n\t\t\t\tmodelOverrides: options.getModelOverrides?.(),\n\t\t\t\textensionOwnedApis: options.getExtensionOwnedApis?.(),\n\t\t\t\tcustomModelIds: options.getCustomModelIds?.(),\n\t\t\t});\n\t\t\toptions.onDiagnostics?.(provider.id, diagnostics);\n\t\t\treturn models;\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fast-model-variants.js","sourceRoot":"","sources":["../../src/core/fast-model-variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAE5C,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAmB,CAAC;AAE3D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAe,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAwB,IAAI,GAAG,CAAC;IACzE,iBAAiB;IACjB,eAAe;IACf,iBAAiB;CACjB,CAAC,CAAC;AA6CH,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC9C,OAAO,GAAG,WAAW,GAAG,oBAAoB,EAAE,CAAC;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C,CAAC;YACH,OAAO,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;YAClD,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { Api, Credential, Model, ModelFastRoute, Provider } from \"@bastani/pi-ai\";\nimport type { ModelsJsonModelOverride } from \"./model-config.ts\";\nimport { applyModelOverride } from \"./provider-composer-internal.ts\";\n\n/** Canonical suffix every selectable fast model variant carries. */\nexport const FAST_MODEL_ID_SUFFIX = \"-fast\";\n\n/** Service tier OpenAI-style providers use to route fast traffic. */\nexport const FAST_MODEL_SERVICE_TIER = \"priority\" as const;\n\n/** Inference speed Anthropic's Messages API uses to route fast traffic. */\nexport const FAST_MODEL_SPEED = \"fast\" as const;\n\n/**\n * Claude models Anthropic's fast mode accepts. Requesting `speed: \"fast\"` on any other model is an\n * error, so the list is explicit rather than a family-name pattern.\n * https://platform.claude.com/docs/en/build-with-claude/fast-mode#supported-models\n */\nexport const ANTHROPIC_FAST_MODE_MODEL_IDS: ReadonlySet<string> = new Set([\n\t\"claude-opus-5-5\",\n\t\"claude-opus-5\",\n\t\"claude-opus-4-8\",\n]);\n\n/** A derived fast variant that was suppressed because something already owns its exact model ID. */\nexport interface FastModelVariantDiagnostic {\n\tprovider: string;\n\t/** The exact selectable model ID that collided. */\n\tmodelId: string;\n\tmessage: string;\n}\n\nexport interface FastModelVariantDerivation {\n\tmodels: readonly Model<Api>[];\n\tdiagnostics: readonly FastModelVariantDiagnostic[];\n}\n\nexport interface DeriveFastModelVariantsOptions {\n\t/** Exact fast model IDs the stored GitHub Copilot credential advertises for this account. */\n\tcopilotFastModelIds?: readonly string[];\n\t/** `models.json` `modelOverrides` for this provider, applied to derived entries by their exact `-fast` ID. */\n\tmodelOverrides?: Readonly<Record<string, ModelsJsonModelOverride>>;\n\t/** APIs whose transport a registered extension owns for this provider. No variant is derived for them. */\n\textensionOwnedApis?: ReadonlySet<Api>;\n\t/** IDs explicitly declared in this provider's models.json models array. Never derive siblings for them. */\n\tcustomModelIds?: ReadonlySet<string>;\n}\n\nexport interface FastModelVariantsOptions {\n\t/**\n\t * Synchronous read of the exact fast model IDs the stored GitHub Copilot credential advertises.\n\t * Read per call so a credential that lands after provider composition still takes effect.\n\t */\n\tgetCopilotFastModelIds?: () => readonly string[] | undefined;\n\t/** Synchronous read of this provider's `models.json` `modelOverrides`, so a reload takes effect. */\n\tgetModelOverrides?: () => Readonly<Record<string, ModelsJsonModelOverride>> | undefined;\n\t/** Read current custom model IDs per pass so models.json reloads update eligibility. */\n\tgetCustomModelIds?: () => ReadonlySet<string>;\n\t/**\n\t * Synchronous read of the APIs a registered extension supplies a stream function for. Read per call\n\t * because extensions register after initial composition on some paths.\n\t */\n\tgetExtensionOwnedApis?: () => ReadonlySet<Api> | undefined;\n\t/** Called after every derivation pass with the complete diagnostic list for this provider. */\n\tonDiagnostics?: (providerId: string, diagnostics: readonly FastModelVariantDiagnostic[]) => void;\n}\n\n/** Canonical selectable ID of the fast variant of `baseModelId`. */\nexport function fastModelId(baseModelId: string): string {\n\treturn `${baseModelId}${FAST_MODEL_ID_SUFFIX}`;\n}\n\n/**\n * The two pi-ai adapters that serialize `service_tier`. `azure-openai-responses` and\n * `openai-completions` have no such option, and `streamSimple` drops it, so a service-tier route on\n * any other API would silently degrade to an ordinary request.\n */\nexport function isNativeFastRouteApi(api: Api): api is \"openai-responses\" | \"openai-codex-responses\" {\n\treturn api === \"openai-responses\" || api === \"openai-codex-responses\";\n}\n\n/**\n * OpenAI-style fast routing keeps the base upstream model ID and adds a priority service tier.\n *\n * Eligibility requires both a first-party provider ID and an adapter that serializes\n * `service_tier`. A renamed provider, proxy, Azure OpenAI (`azure-openai-responses`), OpenRouter\n * (`openai-completions`), and generic OpenAI-compatible providers do not qualify. An `openai` or\n * `openai-codex` model on an adapter that cannot carry `service_tier` must not offer a fast variant,\n * because selecting it would send an ordinary request under a name that promises otherwise.\n */\nexport function usesOpenAIFastServiceTier(model: Pick<Model<Api>, \"api\" | \"provider\">): boolean {\n\treturn isNativeFastRouteApi(model.api) && (model.provider === \"openai\" || model.provider === \"openai-codex\");\n}\n\n/**\n * xAI Priority Processing keeps the base upstream Grok model ID and adds the same\n * `service_tier: \"priority\"` field on the Responses API. xAI has no `-fast` model slugs for current\n * Grok models; priority is billed at twice the standard token rates, and only when the response\n * confirms the tier. https://docs.x.ai/developers/advanced-api-usage/priority-processing\n *\n * Eligibility requires the first-party `xai` provider on `openai-responses`. OpenRouter, Vercel AI\n * Gateway, and renamed or proxied xAI-compatible providers do not qualify.\n */\nexport function usesXaiFastServiceTier(model: Pick<Model<Api>, \"api\" | \"provider\">): boolean {\n\treturn model.api === \"openai-responses\" && model.provider === \"xai\";\n}\n\n/** GitHub Copilot advertises real fast sibling model IDs per account; it never uses a service tier. */\nexport function isGitHubCopilotModel(model: Pick<Model<Api>, \"provider\">): boolean {\n\treturn model.provider === \"github-copilot\";\n}\n\n/**\n * Anthropic fast mode keeps the base upstream model ID and adds `speed: \"fast\"` with the fast-mode beta.\n *\n * Eligibility requires the first-party `anthropic` provider on the Messages API and a supported model.\n * Fast mode is not offered through Amazon Bedrock, Google Vertex, GitHub Copilot, OpenRouter, or a\n * renamed or proxied Anthropic-compatible provider.\n */\nexport function usesAnthropicFastMode(model: Pick<Model<Api>, \"api\" | \"id\" | \"provider\">): boolean {\n\treturn (\n\t\tmodel.api === \"anthropic-messages\" &&\n\t\tmodel.provider === \"anthropic\" &&\n\t\tANTHROPIC_FAST_MODE_MODEL_IDS.has(model.id)\n\t);\n}\n\nfunction advertisedModelIds(value: unknown): readonly string[] | undefined {\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) return undefined;\n\treturn value;\n}\n\n/** Read the exact fast model IDs a stored GitHub Copilot OAuth credential advertises. */\nexport function copilotAdvertisedFastModelIds(credential: Credential | undefined): readonly string[] | undefined {\n\tif (credential?.type !== \"oauth\") return undefined;\n\treturn advertisedModelIds(credential.fastModelIds);\n}\n\n/**\n * Whether a stored GitHub Copilot OAuth credential advertises this exact model ID at all — as a\n * selectable picker/policy model or as a fast sibling.\n *\n * Copilot's per-account advertisement is the authority the provider's own `filterModels` uses, so\n * restoration consults the same lists. An ID the account advertises as an ordinary model is ordinary,\n * whatever its name ends in.\n */\nexport function copilotAdvertisesModelId(credential: Credential | undefined, modelId: string): boolean {\n\tif (credential?.type !== \"oauth\") return false;\n\treturn (\n\t\tadvertisedModelIds(credential.availableModelIds)?.includes(modelId) === true ||\n\t\tadvertisedModelIds(credential.fastModelIds)?.includes(modelId) === true\n\t);\n}\n\nfunction fastRouteForBaseModel(\n\tmodel: Model<Api>,\n\tentitledCopilotFastModelIds: ReadonlySet<string>,\n): ModelFastRoute | undefined {\n\tif (usesOpenAIFastServiceTier(model) || usesXaiFastServiceTier(model)) {\n\t\treturn { baseModelId: model.id, upstreamModelId: model.id, serviceTier: FAST_MODEL_SERVICE_TIER };\n\t}\n\tif (usesAnthropicFastMode(model)) {\n\t\treturn { baseModelId: model.id, upstreamModelId: model.id, speed: FAST_MODEL_SPEED };\n\t}\n\tif (isGitHubCopilotModel(model)) {\n\t\tconst advertisedId = fastModelId(model.id);\n\t\treturn entitledCopilotFastModelIds.has(advertisedId)\n\t\t\t? { baseModelId: model.id, upstreamModelId: advertisedId }\n\t\t\t: undefined;\n\t}\n\treturn undefined;\n}\n\n/**\n * Add a selectable `<base-model-id>-fast` entry for every eligible model, carrying the explicit\n * {@link ModelFastRoute} metadata that gives it fast semantics. The input list is preserved verbatim\n * and in order; each derived entry is appended directly after the model it derives from.\n *\n * A model whose exact `-fast` ID is already owned by the provider, a `models.json` custom model, or an\n * extension wins: derivation is suppressed for it and a diagnostic is recorded. The owning model keeps\n * whatever semantics it declares, because fast behavior comes only from `fastRoute`, never from the\n * `-fast` suffix. For the same reason a base model whose ID already ends in `-fast` is never used to\n * derive a `-fast-fast` variant: that is not a canonical ID this scheme defines.\n *\n * A derived entry is a real catalog model, so a `modelOverrides` entry keyed on its exact `-fast` ID\n * applies to it after derivation. Without that pass the derived entry would inherit the *base* model's\n * overrides and its own would be silently inert.\n *\n * No variant is derived for an API whose transport a registered extension owns, because Atomic cannot\n * enforce the route through a transport it does not serialize.\n */\nexport function deriveFastModelVariants(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\toptions: DeriveFastModelVariantsOptions = {},\n): FastModelVariantDerivation {\n\tconst ownedModelIds = new Set(models.map((model) => model.id));\n\tconst entitledCopilotFastModelIds = new Set(options.copilotFastModelIds ?? []);\n\tconst derived: Model<Api>[] = [];\n\tconst diagnostics: FastModelVariantDiagnostic[] = [];\n\tlet changed = false;\n\tfor (const model of models) {\n\t\tderived.push(model);\n\t\tif (model.fastRoute !== undefined || model.id.endsWith(FAST_MODEL_ID_SUFFIX)) continue;\n\t\tif (options.customModelIds?.has(model.id)) continue;\n\t\t// An extension that supplies this API's stream function owns its serialization, so Atomic cannot\n\t\t// guarantee the route reaches the wire. Publishing a `-fast` choice it may not honor is the same\n\t\t// hazard as publishing one for an adapter that cannot carry the tier.\n\t\tif (options.extensionOwnedApis?.has(model.api) === true) continue;\n\t\tconst fastRoute = fastRouteForBaseModel(model, entitledCopilotFastModelIds);\n\t\tif (!fastRoute) continue;\n\t\tconst variantId = fastModelId(model.id);\n\t\tif (ownedModelIds.has(variantId)) {\n\t\t\tdiagnostics.push({\n\t\t\t\tprovider: providerId,\n\t\t\t\tmodelId: variantId,\n\t\t\t\tmessage:\n\t\t\t\t\t`Model \"${providerId}/${variantId}\" is already defined by the provider, models.json, or an extension, ` +\n\t\t\t\t\t`so Atomic did not derive a fast variant of \"${providerId}/${model.id}\". ` +\n\t\t\t\t\t`That model routes exactly as declared. Rename or remove it to get the derived fast variant instead.`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst override = options.modelOverrides?.[variantId];\n\t\tconst variant: Model<Api> = { ...model, id: variantId, name: `${model.name} (fast)`, fastRoute };\n\t\tderived.push(override ? applyModelOverride(variant, override) : variant);\n\t\tchanged = true;\n\t}\n\tif (!changed && diagnostics.length === 0) return { models, diagnostics };\n\treturn { models: derived, diagnostics };\n}\n\n/**\n * Overlay derived fast model variants onto a composed provider. Apply this after built-in,\n * `models.json`, extension, and `modelOverrides` composition so exact user-owned `-fast` IDs are\n * already present and win the collision.\n */\nexport function withFastModelVariants(provider: Provider, options: FastModelVariantsOptions = {}): Provider {\n\treturn {\n\t\t...provider,\n\t\tgetModels: () => {\n\t\t\tconst { models, diagnostics } = deriveFastModelVariants(provider.id, provider.getModels(), {\n\t\t\t\tcopilotFastModelIds: isGitHubCopilotModel({ provider: provider.id })\n\t\t\t\t\t? options.getCopilotFastModelIds?.()\n\t\t\t\t\t: undefined,\n\t\t\t\tmodelOverrides: options.getModelOverrides?.(),\n\t\t\t\textensionOwnedApis: options.getExtensionOwnedApis?.(),\n\t\t\t\tcustomModelIds: options.getCustomModelIds?.(),\n\t\t\t});\n\t\t\toptions.onDiagnostics?.(provider.id, diagnostics);\n\t\t\treturn models;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -19,6 +19,10 @@ export interface ExtensionProviderTransaction {
|
|
|
19
19
|
hasConfiguredAuth(providerId: string): boolean;
|
|
20
20
|
commit(): Promise<void>;
|
|
21
21
|
}
|
|
22
|
+
export interface SaveCredentialOptions {
|
|
23
|
+
/** Fetch the remote catalog before publishing the credential. Defaults to true. */
|
|
24
|
+
refreshCatalog?: boolean;
|
|
25
|
+
}
|
|
22
26
|
/** Configured pi-ai Models collection used by coding-agent and SDK consumers. */
|
|
23
27
|
export declare class ModelRuntime implements Models {
|
|
24
28
|
private readonly models;
|
|
@@ -168,7 +172,15 @@ export declare class ModelRuntime implements Models {
|
|
|
168
172
|
private enqueueCredentialOperation;
|
|
169
173
|
private synchronizeCredentialState;
|
|
170
174
|
private refreshRemainingAuthAfterLogout;
|
|
171
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Persist a credential acquired elsewhere.
|
|
177
|
+
*
|
|
178
|
+
* `refreshCatalog` defaults to true so the saved credential is published against
|
|
179
|
+
* a freshly fetched catalog. Callers that acquired the key through a login dialog
|
|
180
|
+
* pass false: that transaction ends at persistence, and a remote catalog fetch
|
|
181
|
+
* would make an offline save fail after the credential was already committed.
|
|
182
|
+
*/
|
|
183
|
+
saveCredential(providerId: string, credential: Credential, options?: SaveCredentialOptions): Promise<void>;
|
|
172
184
|
/**
|
|
173
185
|
* Apply a process-scoped API key override. This publishes the provider against
|
|
174
186
|
* the current snapshot and deliberately does not refresh the model catalog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-runtime.d.ts","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EAEnB,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAGxB,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAIN,KAAK,0BAA0B,EAG/B,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EACN,KAAK,UAAU,EACf,KAAK,0BAA0B,EAG/B,KAAK,mBAAmB,EAGxB,MAAM,wBAAwB,CAAC;AAIhC,YAAY,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAKrG,OAAO,EAAE,KAAK,+BAA+B,EAAyB,MAAM,8BAA8B,CAAC;AAC3G,OAAO,KAAK,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErG,MAAM,M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AC,gBAAgB,CAAC,CAE3B;IAED,aAAa,CACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,0BAA0B,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAE3B;IAED,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9G;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAgBjG;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBlF;IAED;;;;;;OAMG;IACH,uBAAuB,IAAI,OAAO,CAEjC;IACK,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAE9E;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;YAMrB,UAAU;IAwCxB,kCAAkC,CAAC,mBAAmB,GAAE,QAAQ,CAAC,MAAM,CAAM,GAAG,4BAA4B,CA+E3G;IAED,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAO/C;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,IAAI,CA2CtE;IAED,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAM3C;CACD"}
|
|
@@ -577,12 +577,27 @@ export class ModelRuntime {
|
|
|
577
577
|
clearTimeout(timeout);
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
|
-
|
|
580
|
+
/**
|
|
581
|
+
* Persist a credential acquired elsewhere.
|
|
582
|
+
*
|
|
583
|
+
* `refreshCatalog` defaults to true so the saved credential is published against
|
|
584
|
+
* a freshly fetched catalog. Callers that acquired the key through a login dialog
|
|
585
|
+
* pass false: that transaction ends at persistence, and a remote catalog fetch
|
|
586
|
+
* would make an offline save fail after the credential was already committed.
|
|
587
|
+
*/
|
|
588
|
+
async saveCredential(providerId, credential, options = {}) {
|
|
589
|
+
const refreshCatalog = options.refreshCatalog ?? true;
|
|
581
590
|
const signal = operationSignal(undefined);
|
|
582
591
|
await this.enqueueCredentialOperation(providerId, signal, async () => {
|
|
583
592
|
await this.credentials.modify(providerId, async () => credential);
|
|
584
593
|
this.markCatalogInputsChanged();
|
|
585
594
|
await this.synchronizeCredentialState(providerId, "saveCredential", credential, async () => {
|
|
595
|
+
if (!refreshCatalog) {
|
|
596
|
+
this.updateModelSnapshot();
|
|
597
|
+
this.externalProviderAuthStatuses.delete(providerId);
|
|
598
|
+
this.snapshot = addStoredCredentialProvider(this.snapshot, providerId, credential.type);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
586
601
|
const result = await this.refresh({ providers: [providerId] });
|
|
587
602
|
this.assertCredentialRefreshSucceeded(providerId, result);
|
|
588
603
|
// A concurrent catalog refresh can supersede this provider's availability
|