omnicell-router 0.8.2 → 0.10.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/README.md +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/auth/api-keys.js +11 -0
- package/backend/dist/auth/key-models.d.ts +36 -0
- package/backend/dist/auth/key-models.js +99 -0
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/activity.js +2 -0
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +78 -0
- package/backend/dist/cli/clients/codex.js +475 -57
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
- package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +8 -2
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +101 -16
- package/backend/dist/config/comments-en.js +34 -25
- package/backend/dist/config/comments-zh.js +33 -24
- package/backend/dist/config/defaults.d.ts +280 -22
- package/backend/dist/config/defaults.js +279 -21
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +22 -1
- package/backend/dist/config/index.js +218 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
- package/backend/dist/config/migrations/v4-to-v5.js +42 -0
- package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
- package/backend/dist/config/migrations/v5-to-v6.js +29 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +18 -4
- package/backend/dist/config/types.d.ts +221 -41
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +63 -17
- package/backend/dist/forward-proxy/h2-forward.js +42 -15
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +27 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +12 -16
- package/backend/dist/forward-proxy/server.js +237 -171
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +59 -19
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +50 -6
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +92 -1
- package/backend/dist/ir/adapters/openai-responses.js +163 -12
- package/backend/dist/ir/capabilities.js +4 -0
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/ir/validate.d.ts +24 -0
- package/backend/dist/ir/validate.js +113 -63
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +284 -77
- package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
- package/backend/dist/opencode/catalog/ocr-store.js +4 -2
- package/backend/dist/opencode/catalog/overrides-store.d.ts +15 -4
- package/backend/dist/opencode/catalog/overrides-store.js +28 -19
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +28 -5
- package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
- package/backend/dist/opencode/catalog/sources/models-dev.js +42 -14
- package/backend/dist/opencode/catalog/types.d.ts +42 -12
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/def-materialize.js +27 -21
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/migrate/engine.d.ts +20 -0
- package/backend/dist/opencode/migrate/engine.js +71 -0
- package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
- package/backend/dist/opencode/migrate/migrator.js +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
- package/backend/dist/opencode/provider-def-adapters.js +43 -27
- package/backend/dist/opencode/provider-defs.d.ts +10 -16
- package/backend/dist/opencode/provider-defs.js +45 -45
- package/backend/dist/opencode/user-config.d.ts +23 -26
- package/backend/dist/opencode/user-config.js +95 -77
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +514 -172
- package/backend/dist/plugins/builtin/model-gateway.js +38 -12
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +100 -16
- package/backend/dist/plugins/host.js +637 -99
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +284 -44
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/dial-wire.d.ts +17 -0
- package/backend/dist/providers/dial-wire.js +49 -0
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/protocols-field.d.ts +24 -0
- package/backend/dist/providers/protocols-field.js +66 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +87 -26
- package/backend/dist/providers/registry.js +232 -121
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +38 -6
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +1043 -405
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +409 -15
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/anthropic.js +4 -1
- package/backend/dist/surfaces/body-admission.d.ts +344 -0
- package/backend/dist/surfaces/body-admission.js +818 -0
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +51 -6
- package/backend/dist/surfaces/transport-node-http.js +76 -16
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +28 -0
- package/backend/dist/utils/server-liveness.js +32 -0
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-DxZ9MHKB.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-55VVwfFQ.js +0 -1521
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { EFFORT_LADDER, TIER_RANK, downgradeReasoning, effortFromThinkingBudget, modelSupportsEfforts } from '../types/router.js';
|
|
2
|
+
import { EFFORT_LADDER, TIER_RANK, COST_MODE_TIER_CEILING, clampTierToCeiling, downgradeReasoning, effortFromThinkingBudget, modelSupportsEfforts } from '../types/router.js';
|
|
3
3
|
import { PromptOptimizer } from './prompt-optimizer.js';
|
|
4
4
|
import { repairToolCallPairing } from './tool-pairing.js';
|
|
5
5
|
import { applyCompression } from '../compression/index.js';
|
|
@@ -13,7 +13,10 @@ import { DEFAULT_LAYER2_EFFORT_FLOOR } from '../config/defaults.js';
|
|
|
13
13
|
import { appendRoutingLedger } from '../router/routing-ledger.js';
|
|
14
14
|
import { SchemaAssertion } from '../validator/schema-assertion.js';
|
|
15
15
|
import { FallbackContextBuilder } from '../validator/parser.js';
|
|
16
|
+
import { resolveModel } from '../providers/model-resolution.js';
|
|
17
|
+
import { pickDialWire } from '../providers/dial-wire.js';
|
|
16
18
|
import { applyEffortMap } from '../providers/member-match.js';
|
|
19
|
+
import { comparePriceBucket } from '../providers/price-order.js';
|
|
17
20
|
import { protocolForWire } from '../providers/vocabulary.js';
|
|
18
21
|
import { capabilitiesFor } from '../ir/capabilities.js';
|
|
19
22
|
import { IrUnsupportedError } from '../ir/errors.js';
|
|
@@ -21,10 +24,13 @@ import { computeRequestCost } from '../metrics/request-cost.js';
|
|
|
21
24
|
import { getRateLimiter, credentialSubject, apiKeySubject, UPSTREAM_429_DEFAULT_COOLDOWN_MS, } from '../ratelimit/rate-limiter.js';
|
|
22
25
|
import { recordRateLimitEvent } from '../ratelimit/event-log.js';
|
|
23
26
|
import { NO_TURN } from '../capture/turn-boundary.js';
|
|
27
|
+
import { CLIENT_HINT_HEADER } from '../utils/client-families.js';
|
|
24
28
|
import { SessionManager } from '../session/session-manager.js';
|
|
25
29
|
import { getEnvPaths } from '../config/env.js';
|
|
26
30
|
import { TraceTracker } from '../trace/tracker.js';
|
|
27
31
|
import { CaptureRecorder } from '../capture/recorder.js';
|
|
32
|
+
import { SessionSnapshotStore } from '../snapshot/store.js';
|
|
33
|
+
import { snapshotRequestViewOf } from '../snapshot/view.js';
|
|
28
34
|
import { UpstreamEventContext } from '../observability/upstream-events.js';
|
|
29
35
|
import { emitClientRequest, captureKeyIdentity, setClientExchangeContext } from '../observability/http-exchange.js';
|
|
30
36
|
import { resolveClientRequestId, mintRequestId } from '../observability/request-identity.js';
|
|
@@ -34,7 +40,7 @@ import { redactUpstreamBody } from '../observability/upstream-body-redaction.js'
|
|
|
34
40
|
import { displayPromptText, firstDisplayText } from '../utils/client-envelope.js';
|
|
35
41
|
import { harnessProfileOf } from '../utils/harness-profiles.js';
|
|
36
42
|
import { ActiveHealthProber, ErrorClassifier } from '../resilience/index.js';
|
|
37
|
-
import { isModelAllowed, isModelAllowedInTiers
|
|
43
|
+
import { isModelAllowed, isModelAllowedInTiers } from '../auth/model-access.js';
|
|
38
44
|
import { DEFAULT_CREDENTIAL_AFFINITY_CACHE_TTL_MS, selectCredential, } from './credential-selection.js';
|
|
39
45
|
/** Key attribution: the in-process binding wins, else the request's authInfo. */
|
|
40
46
|
const keyIdentityOf = (ctx) => ctx?.clientKey ?? captureKeyIdentity(ctx?.fastifyRequest ?? ctx?.clientRequest);
|
|
@@ -143,6 +149,32 @@ const effortOf = (request) => request.reasoning?.effort;
|
|
|
143
149
|
function setEffort(request, effort) {
|
|
144
150
|
request.reasoning = { ...request.reasoning, effort };
|
|
145
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Has the model's registration EXPLICITLY declared "no level control"? That is
|
|
154
|
+
* `supportedReasoningEfforts: []` — the shape `effortLadderFor` emits for a
|
|
155
|
+
* catalog toggle / always-on row. It is deliberately distinct from `undefined`
|
|
156
|
+
* (nothing declared — the legacy "model handles effort internally" case, which
|
|
157
|
+
* still clamps to `none`). A level the model cannot honour is never sent for a
|
|
158
|
+
* declared-empty model, so writing `'none'` back would put a positive
|
|
159
|
+
* thinking-off on the wire that no client asked for.
|
|
160
|
+
*/
|
|
161
|
+
function isDeclaredNoControl(supported) {
|
|
162
|
+
return Array.isArray(supported) && supported.length === 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The model DECLARES a level table that does not include `none`. Thinking-off
|
|
166
|
+
* is then INEXPRESSIBLE for it: the official APIs answer HTTP 400 to
|
|
167
|
+
* `reasoning_effort: 'none'` / `thinkingBudget: 0` on such models (OpenAI
|
|
168
|
+
* documents this for `gpt-5` / `gpt-6-astra`; Gemini forbids disabling
|
|
169
|
+
* thinking on 3.x+), and the vendor's own default governs instead. So `none`
|
|
170
|
+
* must never reach the wire — the honest move is to OMIT the field.
|
|
171
|
+
*
|
|
172
|
+
* Distinct from the other two shapes: `[]` = no level control at all;
|
|
173
|
+
* `undefined` = nothing declared (the legacy clamp to `none` still applies).
|
|
174
|
+
*/
|
|
175
|
+
function declaresLadderWithoutNone(supported) {
|
|
176
|
+
return Array.isArray(supported) && supported.length > 0 && !supported.includes('none');
|
|
177
|
+
}
|
|
146
178
|
/**
|
|
147
179
|
* Pull a non-sensitive subset of inbound headers for the trace's
|
|
148
180
|
* `clientHeaders` field. Three categories:
|
|
@@ -158,7 +190,7 @@ function setEffort(request, effort) {
|
|
|
158
190
|
*/
|
|
159
191
|
/**
|
|
160
192
|
* Pull the upstream target host from an inbound header map. On the MITM
|
|
161
|
-
*
|
|
193
|
+
* ingress-proxy path this is the ORIGINAL destination (the API host the
|
|
162
194
|
* client dialed — `clientRequest.headers.host` survives TLS termination),
|
|
163
195
|
* which pins bare-name model resolution to the right provider. The native
|
|
164
196
|
* /v1 leg is deliberately excluded from this call: there `headers.host` is
|
|
@@ -214,6 +246,13 @@ function envelopeHintsOf(headers) {
|
|
|
214
246
|
declaredPrompt: declared ? clipDisplayText(declared.replace(/\s+/g, ' ').trim()) || undefined : undefined,
|
|
215
247
|
};
|
|
216
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Non-sensitive client-identification subset of the inbound headers. The
|
|
251
|
+
* self-declared `x-ocr-client` hint is read because a browser webview strips
|
|
252
|
+
* a script-set `User-Agent` on `fetch` — the hint is what identifies the
|
|
253
|
+
* console playground (see `utils/client-families.ts`). Display-only: the
|
|
254
|
+
* family it produces is never an identity or routing input (ADR-0002).
|
|
255
|
+
*/
|
|
217
256
|
function extractClientHeaders(headers) {
|
|
218
257
|
if (!headers)
|
|
219
258
|
return undefined;
|
|
@@ -228,12 +267,14 @@ function extractClientHeaders(headers) {
|
|
|
228
267
|
const ua = pick('user-agent');
|
|
229
268
|
const al = pick('accept-language');
|
|
230
269
|
const rid = resolveClientRequestId({ headers }).clientRequestId;
|
|
231
|
-
|
|
270
|
+
const hint = pick(CLIENT_HINT_HEADER);
|
|
271
|
+
if (ua === undefined && al === undefined && rid === undefined && hint === undefined)
|
|
232
272
|
return undefined;
|
|
233
273
|
return {
|
|
234
274
|
...(ua !== undefined ? { userAgent: ua } : {}),
|
|
235
275
|
...(al !== undefined ? { acceptLanguage: al } : {}),
|
|
236
276
|
...(rid !== undefined ? { clientRequestId: rid } : {}),
|
|
277
|
+
...(hint !== undefined ? { clientHint: hint } : {}),
|
|
237
278
|
};
|
|
238
279
|
}
|
|
239
280
|
export class PipelineOrchestrator {
|
|
@@ -243,6 +284,7 @@ export class PipelineOrchestrator {
|
|
|
243
284
|
sessionManager;
|
|
244
285
|
traceTracker;
|
|
245
286
|
captureRecorder;
|
|
287
|
+
snapshotStore;
|
|
246
288
|
healthProber;
|
|
247
289
|
constructor(config, registry, tracker, sessionManager) {
|
|
248
290
|
this.config = config;
|
|
@@ -256,6 +298,10 @@ export class PipelineOrchestrator {
|
|
|
256
298
|
new SessionManager(config.session, path.join(getEnvPaths().dataDir, 'sessions.json'));
|
|
257
299
|
this.traceTracker = new TraceTracker(5000, config.tracePersist);
|
|
258
300
|
this.captureRecorder = new CaptureRecorder(config.requestCapture);
|
|
301
|
+
// Session-snapshot handoff plane (ADR-0038) — separate from capture: an
|
|
302
|
+
// incremental, semantic transcript written for conversation MOVES, not a
|
|
303
|
+
// byte-faithful debug log.
|
|
304
|
+
this.snapshotStore = new SessionSnapshotStore(config.sessionSnapshots);
|
|
259
305
|
if (config.circuitBreaker?.activeProbing?.enabled) {
|
|
260
306
|
this.healthProber = new ActiveHealthProber(this.registry.getCircuitBreakerManager(), this.registry, config.circuitBreaker.activeProbing.intervalMs);
|
|
261
307
|
}
|
|
@@ -272,6 +318,9 @@ export class PipelineOrchestrator {
|
|
|
272
318
|
getCaptureRecorder() {
|
|
273
319
|
return this.captureRecorder;
|
|
274
320
|
}
|
|
321
|
+
getSnapshotStore() {
|
|
322
|
+
return this.snapshotStore;
|
|
323
|
+
}
|
|
275
324
|
getRegistry() {
|
|
276
325
|
return this.registry;
|
|
277
326
|
}
|
|
@@ -292,14 +341,14 @@ export class PipelineOrchestrator {
|
|
|
292
341
|
/**
|
|
293
342
|
* Auto-request routing with the experience table in front of the decision layer
|
|
294
343
|
* (ADR-0011): an entry hit short-circuits L2 entirely — the table IS a
|
|
295
|
-
* prior judgment. Explicit request tiers (`forceTier
|
|
296
|
-
* mode
|
|
297
|
-
*
|
|
298
|
-
*
|
|
344
|
+
* prior judgment. Explicit request tiers (`forceTier`) and the global
|
|
345
|
+
* routing mode's tier pin (`modeTier`) skip the table: both are layer0
|
|
346
|
+
* decisions by definition. On an L2 judgment the router behaves exactly as
|
|
347
|
+
* before (decision layer → plus baseline).
|
|
299
348
|
*/
|
|
300
|
-
async routeAutoDecision(request, decisionCapture, sessionId, promptHash) {
|
|
349
|
+
async routeAutoDecision(request, decisionCapture, sessionId, promptHash, modeTier) {
|
|
301
350
|
const gate = routeEntriesGate();
|
|
302
|
-
if (gate.enabled !== false && promptHash && !request.routerOptions?.forceTier) {
|
|
351
|
+
if (gate.enabled !== false && promptHash && !request.routerOptions?.forceTier && !modeTier) {
|
|
303
352
|
const entry = getRouteEntryStore().hit(promptHash, sessionId);
|
|
304
353
|
if (entry) {
|
|
305
354
|
// The entry's effort is part of the experience; a client-explicit
|
|
@@ -331,7 +380,7 @@ export class PipelineOrchestrator {
|
|
|
331
380
|
decisionCapture,
|
|
332
381
|
// Failure attribution: decision layer wire failures land in the failure_events
|
|
333
382
|
// ledger tagged with THIS conversation, whatever the capture switch.
|
|
334
|
-
sessionId);
|
|
383
|
+
sessionId, modeTier);
|
|
335
384
|
}
|
|
336
385
|
startProber() {
|
|
337
386
|
if (this.healthProber)
|
|
@@ -474,7 +523,67 @@ export class PipelineOrchestrator {
|
|
|
474
523
|
// response. The sink never writes a byte, so `committed` stays
|
|
475
524
|
// false and retries/failover remain legal;
|
|
476
525
|
// follow → the client's own relay (or none) — historical behavior.
|
|
477
|
-
|
|
526
|
+
const upstreamRelay = this.resolveUpstreamRelay(relay);
|
|
527
|
+
try {
|
|
528
|
+
return await this.processInternal(snapshotRequest, snapshotScan, addressed, context, preResolvedSession, upstreamEventContext, turnIdentity, upstreamRelay);
|
|
529
|
+
}
|
|
530
|
+
catch (err) {
|
|
531
|
+
// ABORT SEAM (ADR-0040): the request threw before the success path could
|
|
532
|
+
// record it. Record it as terminated with its reason so the transcript does
|
|
533
|
+
// not silently lose where a conversation was interrupted. `processInternal`
|
|
534
|
+
// records on the success path itself, so this only fires on a throw.
|
|
535
|
+
if (this.snapshotStore.isEnabled()) {
|
|
536
|
+
const committed = upstreamRelay?.committed === true;
|
|
537
|
+
const clientGone = this.isClientAborted(context);
|
|
538
|
+
const outcome = committed ? 'aborted' : 'failed';
|
|
539
|
+
const reason = clientGone
|
|
540
|
+
? 'client-abort'
|
|
541
|
+
: statusCodeOf(err) !== undefined && statusCodeOf(err) < 500 && statusCodeOf(err) >= 400
|
|
542
|
+
? 'client-native-error'
|
|
543
|
+
: 'upstream-error';
|
|
544
|
+
this.snapshotStore.recordTurn({
|
|
545
|
+
sessionId: admissionSessionId,
|
|
546
|
+
turnIndex: turnIdentity.turn.turnIndex,
|
|
547
|
+
requestId: turnIdentity.requestId,
|
|
548
|
+
ts: Date.now(),
|
|
549
|
+
servedModel: '',
|
|
550
|
+
outcome,
|
|
551
|
+
abortReason: reason,
|
|
552
|
+
request: snapshotRequestViewOf(snapshotRequest),
|
|
553
|
+
response: {
|
|
554
|
+
status: outcome === 'aborted' ? 'incomplete' : 'failed',
|
|
555
|
+
reason,
|
|
556
|
+
// A committed abort already streamed a fragment to the client; that
|
|
557
|
+
// fragment is NOT this turn's output (the pipeline never got it back
|
|
558
|
+
// on this path), so the stored output is empty and `partialChars`
|
|
559
|
+
// stays 0 — the console says "interrupted" from `outcome`, not from
|
|
560
|
+
// a fabricated fragment.
|
|
561
|
+
output: [],
|
|
562
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
563
|
+
partialChars: committed ? undefined : 0,
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
throw err;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Did the CLIENT disconnect for this request? Best-effort, from the transport's
|
|
572
|
+
* socket state: `destroyed` on the raw request with the readable side not
|
|
573
|
+
* ended is the signature of a peer that hung up mid-response. Absent transport
|
|
574
|
+
* (in-process callers / tests) always reads as "not gone" — the turn is then
|
|
575
|
+
* attributed to the upstream, which is the honest default when we cannot tell.
|
|
576
|
+
*/
|
|
577
|
+
isClientAborted(context) {
|
|
578
|
+
try {
|
|
579
|
+
if (context?.isClientGone?.() === true)
|
|
580
|
+
return true;
|
|
581
|
+
const raw = context?.fastifyRequest?.raw;
|
|
582
|
+
return raw !== undefined && raw.destroyed === true && raw.readableEnded === false;
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
478
587
|
}
|
|
479
588
|
/**
|
|
480
589
|
* Apply `streaming.upstream.mode` to the surface-supplied relay. The sink
|
|
@@ -491,111 +600,53 @@ export class PipelineOrchestrator {
|
|
|
491
600
|
return mode === 'stream' ? UPSTREAM_SINK_RELAY : undefined;
|
|
492
601
|
}
|
|
493
602
|
/**
|
|
494
|
-
* Names the model the client addressed
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
* Does not resolve a session.
|
|
603
|
+
* Names the model the client addressed — the execution-side consumer of
|
|
604
|
+
* `resolveModel` (the pure, draw-free ladder lives there, shared with
|
|
605
|
+
* every other reader). Applies the mutations the name implies (forceTier,
|
|
606
|
+
* variant rewrite + effort pin) and enforces the key's model policy for an
|
|
607
|
+
* explicitly named model. Does not resolve a session.
|
|
499
608
|
*/
|
|
500
609
|
resolveAddressedModel(request, context) {
|
|
501
610
|
let explicitModel;
|
|
502
611
|
let variantUsed;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
else if (modelName && modelName !== 'auto') {
|
|
514
|
-
const specific = this.registry.getModel(modelName);
|
|
515
|
-
if (specific) {
|
|
516
|
-
// Exact-model pass-through: the client named a REGISTERED model id
|
|
517
|
-
// (e.g. pinned via the Client Hub model slots). Route to exactly
|
|
518
|
-
// this model — not merely its tier. Resilience is preserved: in-place
|
|
519
|
-
// same-model retry and credential re-spread still apply; the model
|
|
520
|
-
// itself is never substituted (ADR-0014).
|
|
521
|
-
explicitModel = specific;
|
|
522
|
-
request.routerOptions = { ...request.routerOptions, forceTier: specific.tier };
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
const variantRef = this.registry.resolveVariantRef(modelName);
|
|
526
|
-
if (variantRef) {
|
|
527
|
-
// Variant request (sibling id `base-variant` or `base#variant`):
|
|
528
|
-
// route to the BASE model exactly and pin the variant's effort as
|
|
529
|
-
// if the client had asked for that level. The variant choice is
|
|
530
|
-
// the more explicit signal, so it wins over any client-sent
|
|
531
|
-
// `reasoning_effort`; the effort-matching block below still
|
|
532
|
-
// applies its downgrade/honesty contract.
|
|
533
|
-
explicitModel = variantRef.base;
|
|
534
|
-
variantUsed = variantRef.variant.id;
|
|
535
|
-
setEffort(request, variantRef.variant.reasoningEffort);
|
|
536
|
-
request.model = variantRef.base.id;
|
|
537
|
-
request.routerOptions = { ...request.routerOptions, forceTier: variantRef.base.tier };
|
|
538
|
-
}
|
|
539
|
-
else if (modelName.includes('#')) {
|
|
540
|
-
// `#variant` is explicit syntax — a typo must fail loud instead of
|
|
541
|
-
// silently classifier-routing (invisible model drift is exactly
|
|
542
|
-
// the failure mode variant ids exist to prevent).
|
|
543
|
-
const hash = modelName.indexOf('#');
|
|
544
|
-
throw Object.assign(new Error(`Variant '${modelName.slice(hash + 1)}' not found for model '${modelName.slice(0, hash)}'`), { statusCode: 404 });
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
// Bare upstream name (no provider prefix — clients that address a
|
|
548
|
-
// model the way its own catalog names it, e.g. `qwen3.8-flash`).
|
|
549
|
-
// The full-id lookup above missed, but a registered model may still
|
|
550
|
-
// carry this exact name as its upstreamModel: resolve to it so the
|
|
551
|
-
// client's explicit choice is honored instead of silently
|
|
552
|
-
// classifier-routing. Provider pinning reads ONLY the MITM leg's
|
|
553
|
-
// clientRequest headers — after TLS termination its `host` is the
|
|
554
|
-
// ORIGINAL host the client dialed (the design intent of the pin).
|
|
555
|
-
// The native /v1 leg never pins: its `headers.host` is client-
|
|
556
|
-
// controlled (a forged Host could steer resolution to a same-named
|
|
557
|
-
// sibling provider) and the gateway's own host matches no provider
|
|
558
|
-
// baseUrl anyway. Cheapest-hit-first ordering picks the primary
|
|
559
|
-
// otherwise. Same-name siblings stay reachable via the tier's
|
|
560
|
-
// failover pool. A full miss falls through to the classifier —
|
|
561
|
-
// ADR-0026 deleted the unresolved-model policy outright, so every
|
|
562
|
-
// leg resolves a name the same way.
|
|
563
|
-
const bareHits = this.registry.getModelsByUpstreamName(modelName, pickHeaderHost(context?.clientRequest?.headers));
|
|
564
|
-
// A live combo id claims this name for the gateway: the combo fork
|
|
565
|
-
// below is the advertised meaning (/v1/models lists the id as a
|
|
566
|
-
// virtual model), and resolving the same name to one physical
|
|
567
|
-
// same-named member would be the single-model billing/model drift
|
|
568
|
-
// the combo fail-fast contract exists to forbid. The physical
|
|
569
|
-
// models stay addressable by their full provider-prefixed id.
|
|
570
|
-
if (bareHits.length > 0 && !this.registry.isCombo(modelName)) {
|
|
571
|
-
explicitModel = bareHits[0];
|
|
572
|
-
request.routerOptions = {
|
|
573
|
-
...request.routerOptions,
|
|
574
|
-
forceTier: explicitModel.tier,
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
// Nothing matched: no policy, no mapping, no fallback. The name
|
|
578
|
-
// falls through to the classifier exactly like a native /v1 caller's
|
|
579
|
-
// would — ADR-0026 deleted the unresolved-model mechanism outright,
|
|
580
|
-
// so the MITM leg has no special posture of its own. A gateway
|
|
581
|
-
// plugin that wants "this name means that model" maps it BEFORE
|
|
582
|
-
// dispatch (it owns the decrypted wire); the pipeline never guesses.
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
// Custom model combo: the client named a configured combo id — the
|
|
587
|
-
// combo's member list IS the candidate pool. Tier-pool routing,
|
|
588
|
-
// session ratchet and schema-assertion escalation are all bypassed
|
|
589
|
-
// (explicit user composition wins, mirroring the exact-model
|
|
590
|
-
// pass-through above).
|
|
591
|
-
const comboByName = !explicitModel && modelName && this.registry.isCombo(modelName) ? modelName : undefined;
|
|
592
|
-
if (comboByName && this.registry.isComboDisabled(comboByName)) {
|
|
593
|
-
throw Object.assign(new Error(`Combo '${comboByName}' is disabled — re-enable it in the console or choose another model.`), { statusCode: 404 });
|
|
612
|
+
const resolved = resolveModel(request.model, this.registry, {
|
|
613
|
+
// Provider pinning reads ONLY the MITM leg's clientRequest headers:
|
|
614
|
+
// after TLS termination its `host` is the ORIGINAL host the client
|
|
615
|
+
// dialed. The native /v1 leg passes nothing because its `Host` header
|
|
616
|
+
// is client-controlled.
|
|
617
|
+
upstreamHost: pickHeaderHost(context?.clientRequest?.headers),
|
|
618
|
+
});
|
|
619
|
+
if (resolved.kind === 'error') {
|
|
620
|
+
throw Object.assign(new Error(resolved.message), { statusCode: resolved.statusCode });
|
|
594
621
|
}
|
|
595
|
-
|
|
596
|
-
|
|
622
|
+
switch (resolved.kind) {
|
|
623
|
+
case 'tier':
|
|
624
|
+
request.routerOptions = { ...request.routerOptions, forceTier: resolved.tier };
|
|
625
|
+
break;
|
|
626
|
+
case 'registered':
|
|
627
|
+
case 'legacy':
|
|
628
|
+
// Exact-model pass-through: route to exactly this model — not merely
|
|
629
|
+
// its tier. Resilience is preserved (same-model retry + credential
|
|
630
|
+
// re-spread); the model itself is never substituted (ADR-0014).
|
|
631
|
+
explicitModel = resolved.model;
|
|
632
|
+
request.routerOptions = { ...request.routerOptions, forceTier: resolved.model.tier };
|
|
633
|
+
break;
|
|
634
|
+
case 'variant':
|
|
635
|
+
// Variant request: route to the BASE model exactly and pin the
|
|
636
|
+
// variant's effort as if the client had asked for that level. The
|
|
637
|
+
// variant choice outranks any client-sent `reasoning_effort`.
|
|
638
|
+
explicitModel = resolved.model;
|
|
639
|
+
variantUsed = resolved.variantId;
|
|
640
|
+
setEffort(request, resolved.effort);
|
|
641
|
+
request.model = resolved.model.id;
|
|
642
|
+
request.routerOptions = { ...request.routerOptions, forceTier: resolved.model.tier };
|
|
643
|
+
break;
|
|
644
|
+
case 'combo':
|
|
645
|
+
case 'auto':
|
|
646
|
+
case 'unresolved':
|
|
647
|
+
break;
|
|
597
648
|
}
|
|
598
|
-
const comboId =
|
|
649
|
+
const comboId = resolved.kind === 'combo' ? resolved.comboId : undefined;
|
|
599
650
|
// An explicitly named model outside the key's model policy fails loud
|
|
600
651
|
// here (HTTP routes entry-check this too; direct orchestrator callers
|
|
601
652
|
// might not). The model's FULL membership set is passed so TIER-level
|
|
@@ -620,12 +671,26 @@ export class PipelineOrchestrator {
|
|
|
620
671
|
const normalizedRequest = request;
|
|
621
672
|
const directivePrefix = directivesGate().prefix;
|
|
622
673
|
const { explicitModel, variantUsed, comboId } = addressed;
|
|
623
|
-
// 1B. Global routing mode (config.routing.mode) — cost/quality
|
|
624
|
-
// for auto/tier-alias requests; explicit client choices always win.
|
|
674
|
+
// 1B. Global routing mode (config.routing.mode) — cost/quality pin the tier
|
|
675
|
+
// for auto/tier-alias requests; explicit client choices always win. The pin
|
|
676
|
+
// rides as a dedicated routing input, NOT `routerOptions.forceTier`:
|
|
677
|
+
// `forceTier` is the CLIENT-authored contract (never cascaded, never
|
|
678
|
+
// escaped), while a mode pin is server policy and still gains the
|
|
679
|
+
// structured-output quality floor (ADR-0001 §1–§2).
|
|
625
680
|
const modeTier = routingModeForceTier(normalizedRequest.model, normalizedRequest.routerOptions, this.config.routing?.mode);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
681
|
+
// cost mode's failure policy: 'to_fallback_tier' (default) lets a failing
|
|
682
|
+
// lite leg escalate, but every escalation target is clamped to the shared
|
|
683
|
+
// COST_MODE_TIER_CEILING (plus); 'never' is a hard lite pin. Read per
|
|
684
|
+
// request so the knob hot-applies like the rest of `routing`.
|
|
685
|
+
const costEscalation = this.config.routing?.costEscalation === 'never' ? 'never' : 'to_fallback_tier';
|
|
686
|
+
// Cost mode's tier-INTERIOR policy (ADR-0001 §2): inside every pool this
|
|
687
|
+
// request touches, the cheapest priced member leads and the failover chain
|
|
688
|
+
// walks ascending price. Smart/quality keep the operator's declared order
|
|
689
|
+
// (weights ARE the quality statement; price-sorting pro would turn quality
|
|
690
|
+
// mode into "cheapest pro"). Server policy only: explicit models, client
|
|
691
|
+
// forceTier and tier aliases resolve modeTier undefined, so a client's
|
|
692
|
+
// choice is never price-redirected.
|
|
693
|
+
const costOrder = modeTier === 'lite';
|
|
629
694
|
// 2. The admission gate resolved this conversation and allocated its turn.
|
|
630
695
|
// clientRef is read again only so the trace row names the ref that was bound.
|
|
631
696
|
const clientRef = SessionManager.clientRefOf(normalizedRequest);
|
|
@@ -644,6 +709,21 @@ export class PipelineOrchestrator {
|
|
|
644
709
|
`${pairing.orphans} orphan repl${pairing.orphans === 1 ? 'y' : 'ies'}`);
|
|
645
710
|
normalizedRequest.input = pairing.input;
|
|
646
711
|
}
|
|
712
|
+
// 2B'. Freeze the PRE-compression request for the snapshot handoff plane
|
|
713
|
+
// (ADR-0038). After tool-pair repair (the history is now forwardable) and
|
|
714
|
+
// before compression (which rewrites tool outputs in place for this
|
|
715
|
+
// upstream). A private clone the snapshot store owns — null when the plane
|
|
716
|
+
// is off, so a disabled feature costs nothing on the hot path.
|
|
717
|
+
const snapshotRequest = this.snapshotStore.isEnabled()
|
|
718
|
+
? snapshotRequestViewOf(normalizedRequest)
|
|
719
|
+
: undefined;
|
|
720
|
+
// Guards the ONE snapshot write for this request: the success path (§8B) and
|
|
721
|
+
// the abort seam in `process()` are mutually exclusive. `process()` records an
|
|
722
|
+
// `aborted`/`failed` record when this function THROWS (ADR-0040); the success
|
|
723
|
+
// path records `completed` here. `snapshotRecorded` is set only by the success
|
|
724
|
+
// path, which is why the abort seam can safely assume "a throw means nothing
|
|
725
|
+
// was recorded yet".
|
|
726
|
+
let snapshotRecorded = false;
|
|
647
727
|
await applyCompression(normalizedRequest, this.config.compression, sessionId);
|
|
648
728
|
// 2C. Route-entry experience (ADR-0011). One normalized prompt hash feeds
|
|
649
729
|
// the experience-table lookup and write. Directives were scrubbed above, so
|
|
@@ -694,10 +774,12 @@ export class PipelineOrchestrator {
|
|
|
694
774
|
layerUsed: 'layer0',
|
|
695
775
|
needsSchemaValidation: false,
|
|
696
776
|
}
|
|
697
|
-
: await this.routeAutoDecision(normalizedRequest, upstreamEventContext, sessionId, promptHash);
|
|
777
|
+
: await this.routeAutoDecision(normalizedRequest, upstreamEventContext, sessionId, promptHash, modeTier);
|
|
698
778
|
// Explicit-model honesty: the engine's 'forced' code here reflects the
|
|
699
|
-
// forceTier
|
|
779
|
+
// forceTier address resolution INJECTED from the named model's registration
|
|
700
780
|
// (full id / variant / bare name) — the client named a model, not a tier.
|
|
781
|
+
// The global mode pin never writes `forceTier` (it rides `modeTier` and
|
|
782
|
+
// emits reasonCode 'mode'), so this rename stays client-authored only.
|
|
701
783
|
// A dedicated code keeps the trace truthful: `tier` stays in params for
|
|
702
784
|
// tooltips, but the console template carries no {tier} slot, so no tier
|
|
703
785
|
// badge is ever inferred from a registration-table lookup.
|
|
@@ -757,9 +839,9 @@ export class PipelineOrchestrator {
|
|
|
757
839
|
// resolved once here (the unified policy seam for all entry modes):
|
|
758
840
|
// - 'ratchet' : auto routing — full monotonic ratchet (upgrade allowed,
|
|
759
841
|
// downgrade intercepted, pin honored)
|
|
760
|
-
// - 'explicit' : a client-authored choice — a named model
|
|
761
|
-
//
|
|
762
|
-
//
|
|
842
|
+
// - 'explicit' : a client-authored choice — a named model, a forced tier
|
|
843
|
+
// (tier aliases / `router_options.forceTier`), or the global
|
|
844
|
+
// mode's tier pin (`modeTier`). Turn recorded, a higher
|
|
763
845
|
// proposal still escalates the ceiling, but the session
|
|
764
846
|
// NEVER rewrites the proposal and the pin is neither
|
|
765
847
|
// read nor followed — a forced lite must serve lite even
|
|
@@ -768,7 +850,7 @@ export class PipelineOrchestrator {
|
|
|
768
850
|
// composition IS the decision
|
|
769
851
|
const sessionMode = comboId
|
|
770
852
|
? 'bypass'
|
|
771
|
-
: explicitModel || normalizedRequest.routerOptions?.forceTier
|
|
853
|
+
: explicitModel || normalizedRequest.routerOptions?.forceTier || modeTier
|
|
772
854
|
? 'explicit'
|
|
773
855
|
: 'ratchet';
|
|
774
856
|
let decision;
|
|
@@ -783,6 +865,12 @@ export class PipelineOrchestrator {
|
|
|
783
865
|
sessionRequestCount = this.sessionManager.recordBypassTurn(sessionId);
|
|
784
866
|
}
|
|
785
867
|
else {
|
|
868
|
+
// The birth pin IS served: ratchet turns serve it, and a forced-tier
|
|
869
|
+
// turn follows a same-tier pin for KV affinity (below), so its pick is
|
|
870
|
+
// real and may advance the strategy cursor. Only the stateless /
|
|
871
|
+
// disabled branch throws its representative away — it must not consume
|
|
872
|
+
// a pick, because the per-request chain head takes the one pick then.
|
|
873
|
+
const ratchetConsumesPick = this.sessionManager.pinsModels();
|
|
786
874
|
const ratchetResult = this.sessionManager.applyRatchet(sessionId, initialDecision,
|
|
787
875
|
// Tier representative for session bookkeeping (pin birth). An
|
|
788
876
|
// explicitly named model IS the representative of its own turn —
|
|
@@ -791,7 +879,22 @@ export class PipelineOrchestrator {
|
|
|
791
879
|
// though the request itself is directly callable by design. Bare
|
|
792
880
|
// `auto` keeps resolving through the pool (its empty-pool throw is
|
|
793
881
|
// the honest "add tier members" answer).
|
|
794
|
-
|
|
882
|
+
// The representative also honours the request's `costOrder`: a cost-mode
|
|
883
|
+
// session must be BORN on its cheapest member, since the birth pin is
|
|
884
|
+
// what every later turn follows by KV affinity (ADR-0001 §2).
|
|
885
|
+
(tier) => {
|
|
886
|
+
if (explicitModel)
|
|
887
|
+
return explicitModel;
|
|
888
|
+
if (!ratchetConsumesPick) {
|
|
889
|
+
const pool = this.registry.getCandidateModelsForTier(tier, true, { costOrder });
|
|
890
|
+
if (pool.length > 0)
|
|
891
|
+
return pool[0];
|
|
892
|
+
const anyPool = this.registry.getCandidateModelsForTier(tier, false, { costOrder });
|
|
893
|
+
if (anyPool.length > 0)
|
|
894
|
+
return anyPool[0];
|
|
895
|
+
}
|
|
896
|
+
return this.registry.getModelForTier(tier, true, costOrder);
|
|
897
|
+
}, { allowIntercept: sessionMode === 'ratchet' });
|
|
795
898
|
decision = ratchetResult.finalDecision;
|
|
796
899
|
decision.sessionId = sessionId;
|
|
797
900
|
decision.sessionRatchetApplied = ratchetResult.ratchetApplied;
|
|
@@ -864,7 +967,18 @@ export class PipelineOrchestrator {
|
|
|
864
967
|
// scope). It is also the ONLY legal automatic-path downgrade. Explicit
|
|
865
968
|
// client choices (named model / forced tier / combo) outrank a directive —
|
|
866
969
|
// the client already decided — and say so in the ledger.
|
|
867
|
-
|
|
970
|
+
// A directive is a per-turn USER override. It outranks SERVER policy (the
|
|
971
|
+
// global mode tier pin) but never a client-authored choice (named model /
|
|
972
|
+
// forced tier / combo). A mode-pin turn stays classified `explicit` for
|
|
973
|
+
// ratchet/pin purposes (a cost pin must not be dragged up by the session
|
|
974
|
+
// high-water mark, ADR-0014), yet its directive axes still apply —
|
|
975
|
+
// otherwise cost/quality mode silently swallows the user's tier/effort
|
|
976
|
+
// directives (ADR-0011).
|
|
977
|
+
const modePinnedTurn = modeTier !== undefined &&
|
|
978
|
+
!explicitModel &&
|
|
979
|
+
!comboId &&
|
|
980
|
+
normalizedRequest.routerOptions?.forceTier === undefined;
|
|
981
|
+
const directivesApplicable = sessionMode === 'ratchet' || modePinnedTurn;
|
|
868
982
|
if (!directivesApplicable && directiveScan.effective.length > 0) {
|
|
869
983
|
appendRoutingLedger({
|
|
870
984
|
kind: 'directive_ignored',
|
|
@@ -886,6 +1000,7 @@ export class PipelineOrchestrator {
|
|
|
886
1000
|
});
|
|
887
1001
|
}
|
|
888
1002
|
let tierDirectiveChanged = false;
|
|
1003
|
+
let effortDirectiveChanged = false;
|
|
889
1004
|
if (directivesApplicable) {
|
|
890
1005
|
const tierDirective = applyTierDirectives(directiveActions, decision.targetTier);
|
|
891
1006
|
if (tierDirective.applied) {
|
|
@@ -989,7 +1104,7 @@ export class PipelineOrchestrator {
|
|
|
989
1104
|
!this.poolOfHomedModel(preferredModel).some((m) => m.id === pinnedId));
|
|
990
1105
|
const healthEvicted = preferredModel !== null && this.registry.modelHealthView(preferredModel) === 'unavailable';
|
|
991
1106
|
if (pinnedId && (configEvicted || healthEvicted)) {
|
|
992
|
-
const healthyReplacement = this.registry.getModelForTier(actualTier, true);
|
|
1107
|
+
const healthyReplacement = this.registry.getModelForTier(actualTier, true, costOrder);
|
|
993
1108
|
// Guard: getModelForTier degrades across tiers when the whole tier is
|
|
994
1109
|
// down — a cross-tier landing is legitimate (the registry logs it with
|
|
995
1110
|
// reason=empty-pool) and repinModel moves the model pin only, never
|
|
@@ -1023,7 +1138,7 @@ export class PipelineOrchestrator {
|
|
|
1023
1138
|
}
|
|
1024
1139
|
}
|
|
1025
1140
|
}
|
|
1026
|
-
else if (sessionMode === 'explicit' && !explicitModel && normalizedRequest.routerOptions?.forceTier) {
|
|
1141
|
+
else if (sessionMode === 'explicit' && !explicitModel && (normalizedRequest.routerOptions?.forceTier || modeTier)) {
|
|
1027
1142
|
// Forced-tier turn (ADR-0014): the session pin is followed ONLY when it
|
|
1028
1143
|
// lives in the forced tier — then following is pure KV affinity (the
|
|
1029
1144
|
// pin IS a model of the tier the client forced, so serving it cannot
|
|
@@ -1044,7 +1159,7 @@ export class PipelineOrchestrator {
|
|
|
1044
1159
|
const tierPool = this.registry.getCandidateModelsForTier(actualTier, false);
|
|
1045
1160
|
const degradeLanding = preferredModel !== null &&
|
|
1046
1161
|
tierPool.length === 0 &&
|
|
1047
|
-
this.registry.getModelForTier(actualTier).id === preferredModel.id;
|
|
1162
|
+
this.registry.getModelForTier(actualTier, true, costOrder).id === preferredModel.id;
|
|
1048
1163
|
const unhomed = preferredModel !== null && preferredModel.tier === undefined;
|
|
1049
1164
|
if (pinnedId &&
|
|
1050
1165
|
(preferredModel === null ||
|
|
@@ -1055,7 +1170,7 @@ export class PipelineOrchestrator {
|
|
|
1055
1170
|
!this.poolOfHomedModel(preferredModel).some((m) => m.id === pinnedId);
|
|
1056
1171
|
const healthEvicted = preferredModel !== null && this.registry.modelHealthView(preferredModel) === 'unavailable';
|
|
1057
1172
|
if (configEvicted || healthEvicted) {
|
|
1058
|
-
const healthyReplacement = this.registry.getModelForTier(actualTier, true);
|
|
1173
|
+
const healthyReplacement = this.registry.getModelForTier(actualTier, true, costOrder);
|
|
1059
1174
|
if (healthyReplacement &&
|
|
1060
1175
|
healthyReplacement.id !== pinnedId &&
|
|
1061
1176
|
this.registry.modelAvailable(healthyReplacement).available) {
|
|
@@ -1086,10 +1201,48 @@ export class PipelineOrchestrator {
|
|
|
1086
1201
|
// the zero-member case fails fast above, so index 0 exists whenever
|
|
1087
1202
|
// comboId is set. Bare `auto` still resolves through the pool — its
|
|
1088
1203
|
// empty-pool throw is the honest "add members on the /tiers page" answer.
|
|
1204
|
+
// One strategy pick for the no-pin auto path (stateless / disabled
|
|
1205
|
+
// sessions): the same model leads the serving chain below (the direct
|
|
1206
|
+
// path reuses `autoLeader`), so the cursor advances exactly once per
|
|
1207
|
+
// request and effort prep sees the model that will actually serve. A
|
|
1208
|
+
// session pin (preferredModel) and combos resolve without touching this
|
|
1209
|
+
// cursor.
|
|
1210
|
+
//
|
|
1211
|
+
// The lite-lead cascade below picks its OWN leader per tier, so this
|
|
1212
|
+
// pre-execution draw must be skipped when the cascade will decide the
|
|
1213
|
+
// route: a round here would advance the cursor for a model the request
|
|
1214
|
+
// never serves, and the placeholder is discarded anyway. Hoisting the
|
|
1215
|
+
// cascade predicate keeps the two sites from ever disagreeing.
|
|
1216
|
+
const cascadeEligible = decision.needsSchemaValidation &&
|
|
1217
|
+
this.config.fallback.enabled &&
|
|
1218
|
+
!request.routerOptions?.disableFallback &&
|
|
1219
|
+
!explicitModel &&
|
|
1220
|
+
!comboId &&
|
|
1221
|
+
!normalizedRequest.routerOptions?.forceTier &&
|
|
1222
|
+
// A mode pin may gain the structured-output floor only from the lite
|
|
1223
|
+
// lead: quality mode is pinned to pro, and a lite-first cascade would
|
|
1224
|
+
// downgrade it. Smart (no modeTier) keeps the original behaviour. A
|
|
1225
|
+
// 'never' cost-escalation policy refuses the escalation outright.
|
|
1226
|
+
(modeTier === undefined || (modeTier === 'lite' && costEscalation !== 'never'));
|
|
1227
|
+
const autoLeader = preferredModel || comboId || explicitModel || cascadeEligible
|
|
1228
|
+
? null
|
|
1229
|
+
: this.registry.getModelForTier(actualTier, true, costOrder);
|
|
1089
1230
|
let actualModel = preferredModel ||
|
|
1090
1231
|
(comboId ? this.registry.resolveCombo(comboId)[0] : undefined) ||
|
|
1091
1232
|
explicitModel ||
|
|
1092
|
-
|
|
1233
|
+
autoLeader ||
|
|
1234
|
+
// Cascade-eligible placeholder: the cascade executes its own leaders, so
|
|
1235
|
+
// this only feeds the pre-execution effort preview and the directive
|
|
1236
|
+
// ledger — take a pool head WITHOUT a rotation draw. Healthy head first,
|
|
1237
|
+
// then the all-health head: `getModelForTier` is only reached when the
|
|
1238
|
+
// tier pool is empty at every health level, where it resolves a cross-tier
|
|
1239
|
+
// representative without touching a cursor. Reaching a `pickPrimary` draw
|
|
1240
|
+
// here would advance the same projection cursor (`${tier}:${strategy}`,
|
|
1241
|
+
// `:cost`-suffixed under a price projection) the cascade then draws on
|
|
1242
|
+
// (double advance for one request).
|
|
1243
|
+
this.registry.getCandidateModelsForTier(actualTier, true, { costOrder })[0] ||
|
|
1244
|
+
this.registry.getCandidateModelsForTier(actualTier, false, { costOrder })[0] ||
|
|
1245
|
+
this.registry.getModelForTier(actualTier, true, costOrder);
|
|
1093
1246
|
// Reasoning-effort matching. `requestedEffort` is the
|
|
1094
1247
|
// literal value the client sent (undefined if the field was omitted —
|
|
1095
1248
|
// distinct from `'none'`, which is the client EXPLICITLY asking for no
|
|
@@ -1112,7 +1265,10 @@ export class PipelineOrchestrator {
|
|
|
1112
1265
|
// the default pin / effort matching below, so capability clamps and the
|
|
1113
1266
|
// X-OCR-Thinking-* headers see it; the budget itself stays on the request
|
|
1114
1267
|
// for wires that consume it natively.
|
|
1115
|
-
|
|
1268
|
+
// Prefer-native dial (same pickDialWire registry.execute uses) — effort
|
|
1269
|
+
// prep and X-OCR-Protocol must name the wire THIS attempt will dial, not
|
|
1270
|
+
// protocols[0] / the boot primary alone.
|
|
1271
|
+
const servedWire = pickDialWire(actualModel.protocols ?? (actualModel.wire ? [actualModel.wire] : undefined), context?.wire, normalizedRequest);
|
|
1116
1272
|
const budgetTokens = normalizedRequest.reasoning?.budgetTokens;
|
|
1117
1273
|
if (effortOf(normalizedRequest) === undefined &&
|
|
1118
1274
|
typeof budgetTokens === 'number' &&
|
|
@@ -1131,8 +1287,12 @@ export class PipelineOrchestrator {
|
|
|
1131
1287
|
// Baseline = the effective ask already in play (client value, else the
|
|
1132
1288
|
// entry/L2 injection, else the model default pinned just above), so the
|
|
1133
1289
|
// step is relative to what this turn WOULD have served — symmetric with the
|
|
1134
|
-
// tier axis, which steps from the post-ratchet decision. Capability
|
|
1135
|
-
//
|
|
1290
|
+
// tier axis, which steps from the post-ratchet decision. Capability handling
|
|
1291
|
+
// belongs to the SERVING model, exactly like a client field: a STEP is
|
|
1292
|
+
// range-clamped against the pre-pick model's declared ladder, while a PIN
|
|
1293
|
+
// is written here as the raw ask and translated (effortMap) + clamped by
|
|
1294
|
+
// the pipeline below — clamping a pin here would bypass a `high->xhigh`
|
|
1295
|
+
// map and read an arbitrary pool head. Runs BEFORE the effort matching so a
|
|
1136
1296
|
// model pick can honour a raised level. Per-turn: it writes the request
|
|
1137
1297
|
// for this call only and never records session state.
|
|
1138
1298
|
if (directivesApplicable) {
|
|
@@ -1148,6 +1308,7 @@ export class PipelineOrchestrator {
|
|
|
1148
1308
|
: modelSupportsEfforts(declared, actualModel.supportsReasoningEffort, actualModel.reasoningDisableable);
|
|
1149
1309
|
const before = effortOf(normalizedRequest);
|
|
1150
1310
|
const effortDirective = applyEffortDirectives(directiveActions, before, supportedEfforts, actualModel.reasoningDisableable === false);
|
|
1311
|
+
effortDirectiveChanged = effortDirective.changed;
|
|
1151
1312
|
if (effortDirective.applied) {
|
|
1152
1313
|
const suffix = effortDirective.suffix ?? (effortDirective.delta > 0 ? 'effort-up' : 'effort-down');
|
|
1153
1314
|
const token = `${directivePrefix}${suffix}`;
|
|
@@ -1203,6 +1364,13 @@ export class PipelineOrchestrator {
|
|
|
1203
1364
|
const requestedEffort = effortOf(normalizedRequest);
|
|
1204
1365
|
let actualEffort;
|
|
1205
1366
|
let reasoningDegraded = false;
|
|
1367
|
+
// Tier-cross policy, resolved here (before the effort pick) so a
|
|
1368
|
+
// `same_tier_only` deployment OR a client-forced tier forbids the
|
|
1369
|
+
// effort-aware pick from leaving its tier. Reused verbatim below for the
|
|
1370
|
+
// cross-tier escalation tail.
|
|
1371
|
+
const tierCrossPolicy = this.config.retry?.failover?.tierCrossPolicy ?? 'allow_escalate';
|
|
1372
|
+
const sameTierEffortPick = tierCrossPolicy !== 'allow_escalate' ||
|
|
1373
|
+
normalizedRequest.routerOptions?.forceTier !== undefined;
|
|
1206
1374
|
const effortPick = (() => {
|
|
1207
1375
|
// Skip effort-based pick when the request is an explicit model choice
|
|
1208
1376
|
// OR a combo — both are pinned by the caller and must not be re-routed
|
|
@@ -1217,10 +1385,10 @@ export class PipelineOrchestrator {
|
|
|
1217
1385
|
// No explicit level asked — still engage when a member rule
|
|
1218
1386
|
// maps `none` to a real level (e.g. none→high) — the pick becomes
|
|
1219
1387
|
// effort-aware. Otherwise leave the default tier pick alone.
|
|
1220
|
-
const mapped = this.registry.pickModelForEffort(actualTier, 'none', true);
|
|
1388
|
+
const mapped = this.registry.pickModelForEffort(actualTier, 'none', true, costOrder, modeTier === 'lite' ? COST_MODE_TIER_CEILING : undefined, sameTierEffortPick);
|
|
1221
1389
|
return mapped && mapped.actualEffort !== 'none' ? mapped : null;
|
|
1222
1390
|
}
|
|
1223
|
-
return this.registry.pickModelForEffort(actualTier, requestedEffort, true);
|
|
1391
|
+
return this.registry.pickModelForEffort(actualTier, requestedEffort, true, costOrder, modeTier === 'lite' ? COST_MODE_TIER_CEILING : undefined, sameTierEffortPick);
|
|
1224
1392
|
})();
|
|
1225
1393
|
if (effortPick) {
|
|
1226
1394
|
actualModel = effortPick.model;
|
|
@@ -1246,6 +1414,26 @@ export class PipelineOrchestrator {
|
|
|
1246
1414
|
if (target === 'none' && !forbidsNone) {
|
|
1247
1415
|
actualEffort = requestedEffort; // nothing in play — mirror exactly
|
|
1248
1416
|
}
|
|
1417
|
+
else if (
|
|
1418
|
+
// The always-think clamp (below) owns a disableable:false model whose
|
|
1419
|
+
// ladder has no `none`: its declared rung is the honest floor, never an
|
|
1420
|
+
// omission. Only the two NO-RUNG-TO-CLAMP-TO shapes route here.
|
|
1421
|
+
!(preferredModel.reasoningDisableable === false && supported.length > 0) &&
|
|
1422
|
+
((isDeclaredNoControl(preferredModel.supportedReasoningEfforts) && target !== 'none') ||
|
|
1423
|
+
(target === 'none' && requestedEffort !== undefined && declaresLadderWithoutNone(preferredModel.supportedReasoningEfforts)))) {
|
|
1424
|
+
// Two shapes where the ask is NOT a level the model can honour, and the
|
|
1425
|
+
// honest serve is "send nothing, let the vendor decide" rather than a
|
|
1426
|
+
// rewritten `none` (which is a positive thinking-off on the chat wire,
|
|
1427
|
+
// or an HTTP 400 on models whose table omits `none`):
|
|
1428
|
+
// - EXPLICITLY declared no level control (`supportedReasoningEfforts: []`
|
|
1429
|
+
// — a toggle / always-on catalog row);
|
|
1430
|
+
// - a declared table WITHOUT `none` (OpenAI `gpt-5`/`gpt-6-astra`,
|
|
1431
|
+
// Gemini 3.x — `none` is inexpressible, `400` otherwise).
|
|
1432
|
+
// (An UNDECLARED support set — `undefined` — is the legacy "model
|
|
1433
|
+
// handles effort internally" case and still clamps to `none` below.)
|
|
1434
|
+
actualEffort = target === 'none' ? undefined : requestedEffort;
|
|
1435
|
+
reasoningDegraded = requestedEffort !== undefined && requestedEffort !== 'none';
|
|
1436
|
+
}
|
|
1249
1437
|
else {
|
|
1250
1438
|
let recomputed = downgradeReasoning(target, supported, alwaysThink);
|
|
1251
1439
|
// Same contradictory-data rule as resolveServedEffort: an empty resolved
|
|
@@ -1292,25 +1480,35 @@ export class PipelineOrchestrator {
|
|
|
1292
1480
|
let servedEgress = undefined;
|
|
1293
1481
|
// 5. Execution with Cascading Fallback & Schema Assertion
|
|
1294
1482
|
// (lite-lead cascade is skipped for explicit model choices, combos AND
|
|
1295
|
-
// forced tiers — the client named exactly what to run. A forced
|
|
1296
|
-
// a contract in BOTH directions: no lite-lead downgrade of a
|
|
1297
|
-
// plus/pro/ultra, no plus escape of a forced lite.
|
|
1483
|
+
// client-forced tiers — the client named exactly what to run. A forced
|
|
1484
|
+
// tier is a contract in BOTH directions: no lite-lead downgrade of a
|
|
1485
|
+
// forced plus/pro/ultra, no plus escape of a forced lite. A MODE pin is
|
|
1486
|
+
// server policy, not a client contract: cost mode (lite) still earns the
|
|
1487
|
+
// structured-output floor, while quality mode (pro) never takes a lite
|
|
1488
|
+
// lead. A session pin does NOT skip the cascade: the structured-output
|
|
1489
|
+
// probe is a cost decision and each leg it serves draws its own leader.
|
|
1490
|
+
// ADR-0014.)
|
|
1298
1491
|
const retryConfig = this.config.retry;
|
|
1299
1492
|
const failoverEnabled = retryConfig?.enabled !== false && retryConfig?.failover?.enabled !== false;
|
|
1300
1493
|
const maxFailoverCandidates = failoverEnabled ? (retryConfig?.failover?.maxAttempts ?? 2) : 1;
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1494
|
+
// `tierCrossPolicy` was resolved above (the effort pick needs it).
|
|
1495
|
+
// Where a failing lite leg escalates to: the operator's configured target
|
|
1496
|
+
// in smart/quality, clamped to the shared ceiling in cost mode. ONE value
|
|
1497
|
+
// feeds the 5A lite-lead tail, the 5B escalation and the direct path's
|
|
1498
|
+
// cross-tier tail, so none of them invents its own 'plus' (S3 drift twin).
|
|
1499
|
+
const configuredEscalateTier = this.config.fallback?.escalateTier || 'plus';
|
|
1500
|
+
const escalateTier = modeTier === 'lite'
|
|
1501
|
+
? clampTierToCeiling(configuredEscalateTier, COST_MODE_TIER_CEILING)
|
|
1502
|
+
: configuredEscalateTier;
|
|
1503
|
+
if (cascadeEligible) {
|
|
1308
1504
|
// 5A: Lite Tier lead - Deploy Lite Tier first with resilience
|
|
1309
|
-
const litePool = this.registry.getCandidateModelsForTier('lite', true);
|
|
1505
|
+
const litePool = this.registry.getCandidateModelsForTier('lite', true, { costOrder });
|
|
1506
|
+
const liteCandidates = litePool.length > 0 ? litePool : this.registry.getCandidateModelsForTier('lite', false, { costOrder });
|
|
1310
1507
|
const liteResult = await this.executeCandidatePool(normalizedRequest, {
|
|
1311
|
-
chain:
|
|
1508
|
+
chain: this.registry.orderChain('lite', liteCandidates, costOrder),
|
|
1312
1509
|
tier: 'lite',
|
|
1313
1510
|
allowEscalate: tierCrossPolicy === 'allow_escalate',
|
|
1511
|
+
escalateTier,
|
|
1314
1512
|
attemptCap: maxFailoverCandidates,
|
|
1315
1513
|
modelAccess: context?.modelAccess,
|
|
1316
1514
|
requestedEffort,
|
|
@@ -1356,11 +1554,13 @@ export class PipelineOrchestrator {
|
|
|
1356
1554
|
if (!assertionPassed) {
|
|
1357
1555
|
fallbackOccurred = true;
|
|
1358
1556
|
fallbackReason = assertionError;
|
|
1359
|
-
|
|
1557
|
+
// Cost mode never spends above its ceiling; other modes honor the
|
|
1558
|
+
// operator's configured target unchanged. `escalateTier` was resolved
|
|
1559
|
+
// above from `fallback.escalateTier` (ceiling-clamped in cost mode).
|
|
1360
1560
|
const failedContent = responseMessageText(liteRes);
|
|
1361
1561
|
const fallbackReq = FallbackContextBuilder.buildEscalationRequest(normalizedRequest, failedContent, assertionError, escalateTier);
|
|
1362
1562
|
const plusResult = await this.executeCandidatePool(fallbackReq, {
|
|
1363
|
-
chain: this.registry.getCandidateModelsForTier(escalateTier, true),
|
|
1563
|
+
chain: this.registry.orderChain(escalateTier, this.registry.getCandidateModelsForTier(escalateTier, true, { costOrder }), costOrder),
|
|
1364
1564
|
tier: escalateTier,
|
|
1365
1565
|
allowEscalate: false,
|
|
1366
1566
|
attemptCap: maxFailoverCandidates,
|
|
@@ -1379,6 +1579,7 @@ export class PipelineOrchestrator {
|
|
|
1379
1579
|
requestedEffort,
|
|
1380
1580
|
variantUsed,
|
|
1381
1581
|
},
|
|
1582
|
+
inboundWire: context?.wire,
|
|
1382
1583
|
}, upstreamEventContext);
|
|
1383
1584
|
if (!plusResult.success || !plusResult.response) {
|
|
1384
1585
|
if (plusResult.policyDenied) {
|
|
@@ -1389,7 +1590,7 @@ export class PipelineOrchestrator {
|
|
|
1389
1590
|
throw escErr;
|
|
1390
1591
|
const accessPolicy = context?.modelAccess;
|
|
1391
1592
|
const escRemaining = this.registry
|
|
1392
|
-
.getCandidateModelsForTier(escalateTier, true)
|
|
1593
|
+
.getCandidateModelsForTier(escalateTier, true, { costOrder })
|
|
1393
1594
|
.filter((m) => !plusResult.failoverPath.includes(m.id) &&
|
|
1394
1595
|
(!accessPolicy || isModelAllowedInTiers(m.id, accessPolicy, this.registry.tiersOf(m))));
|
|
1395
1596
|
throw routeExhaustedError(`escalation tier '${escalateTier}'`, plusResult.failoverPath, escErr, escRemaining);
|
|
@@ -1460,9 +1661,9 @@ export class PipelineOrchestrator {
|
|
|
1460
1661
|
// to the full pool when everything is tripped — the loop force-tries
|
|
1461
1662
|
// the last candidate) follows the head, so KV-cache affinity is
|
|
1462
1663
|
// preserved on the first candidate.
|
|
1463
|
-
let pool = this.registry.getCandidateModelsForTier(actualTier, true);
|
|
1664
|
+
let pool = this.registry.getCandidateModelsForTier(actualTier, true, { costOrder });
|
|
1464
1665
|
if (pool.length === 0)
|
|
1465
|
-
pool = this.registry.getCandidateModelsForTier(actualTier, false);
|
|
1666
|
+
pool = this.registry.getCandidateModelsForTier(actualTier, false, { costOrder });
|
|
1466
1667
|
// Bare-auto under a model-access policy: the classifier may land in a
|
|
1467
1668
|
// tier that holds no admissible model (allow: none whitelisted in that
|
|
1468
1669
|
// tier; deny: every model of that tier tier-denied) — widen the pool
|
|
@@ -1483,12 +1684,44 @@ export class PipelineOrchestrator {
|
|
|
1483
1684
|
const widened = this.registry
|
|
1484
1685
|
.getAllModels()
|
|
1485
1686
|
.filter((m) => isModelAllowedInTiers(m.id, accessPolicy, this.registry.tiersOf(m)))
|
|
1486
|
-
.sort((a, b) =>
|
|
1687
|
+
.sort((a, b) =>
|
|
1688
|
+
// Cost mode: the cheapest allowed model leads regardless of
|
|
1689
|
+
// tier proximity (ADR-0001 §2) — otherwise widening would be
|
|
1690
|
+
// the one cost-mode path that ignores price.
|
|
1691
|
+
(costOrder ? comparePriceBucket(a, b) : 0) ||
|
|
1692
|
+
Math.abs(rankOf(a) - (rank[actualTier] ?? 9)) - Math.abs(rankOf(b) - (rank[actualTier] ?? 9)) ||
|
|
1487
1693
|
rankOf(a) - rankOf(b));
|
|
1488
1694
|
if (widened.length > 0)
|
|
1489
1695
|
pool = widened;
|
|
1490
1696
|
}
|
|
1491
|
-
|
|
1697
|
+
if (head) {
|
|
1698
|
+
chain = [head, ...pool.filter(m => m.id !== head.id)];
|
|
1699
|
+
}
|
|
1700
|
+
else if (pool.length === 0) {
|
|
1701
|
+
chain = pool;
|
|
1702
|
+
}
|
|
1703
|
+
else {
|
|
1704
|
+
// No pin and no explicit model (stateless / disabled sessions):
|
|
1705
|
+
// the early strategy pick IS this request's leader and already
|
|
1706
|
+
// advanced the cursor once. Keep it when the (possibly widened)
|
|
1707
|
+
// pool still holds it; otherwise draw exactly one replacement
|
|
1708
|
+
// from the pool this chain will actually walk.
|
|
1709
|
+
const early = autoLeader;
|
|
1710
|
+
// The effort-aware pick OUTRANKS the tier leader. `pickModelForEffort`
|
|
1711
|
+
// already resolved (and, in cost mode, ceiling-clamped) the model that
|
|
1712
|
+
// can serve the requested level — it may live in another tier than the
|
|
1713
|
+
// one this chain is built for. Leading with the tier leader would send
|
|
1714
|
+
// the request to a model that cannot serve the level at all and throw
|
|
1715
|
+
// the pick away (the pick is metadata until a candidate actually runs).
|
|
1716
|
+
// A pick that matches the early leader adds nothing, so keep the
|
|
1717
|
+
// early leader then (it already advanced the rotation cursor once).
|
|
1718
|
+
const effortHead = effortPick && effortPick.model.id !== early?.id ? effortPick.model : undefined;
|
|
1719
|
+
const leader = effortHead ??
|
|
1720
|
+
(early && pool.some(m => m.id === early.id)
|
|
1721
|
+
? early
|
|
1722
|
+
: this.registry.pickLeader(actualTier, pool, costOrder));
|
|
1723
|
+
chain = [leader, ...pool.filter(m => m.id !== leader.id)];
|
|
1724
|
+
}
|
|
1492
1725
|
// Auto keeps the configured failover budget; an explicit opt-in is
|
|
1493
1726
|
// bounded by its own chain length (failover.maxAttempts governs
|
|
1494
1727
|
// auto routing only). Cross-tier escalation is an AUTO-routing
|
|
@@ -1498,6 +1731,7 @@ export class PipelineOrchestrator {
|
|
|
1498
1731
|
allowEscalate =
|
|
1499
1732
|
!explicitModel &&
|
|
1500
1733
|
!normalizedRequest.routerOptions?.forceTier &&
|
|
1734
|
+
(modeTier === undefined || (modeTier === 'lite' && costEscalation !== 'never')) &&
|
|
1501
1735
|
tierCrossPolicy === 'allow_escalate' &&
|
|
1502
1736
|
actualTier === 'lite';
|
|
1503
1737
|
}
|
|
@@ -1506,7 +1740,10 @@ export class PipelineOrchestrator {
|
|
|
1506
1740
|
chain,
|
|
1507
1741
|
tier: actualTier,
|
|
1508
1742
|
accessTierMode,
|
|
1743
|
+
comboEffortMaps: comboId ? this.registry.comboEffortMaps(comboId) : undefined,
|
|
1509
1744
|
allowEscalate,
|
|
1745
|
+
escalateTier,
|
|
1746
|
+
costOrder,
|
|
1510
1747
|
attemptCap,
|
|
1511
1748
|
label: poolLabel,
|
|
1512
1749
|
modelAccess: context?.modelAccess,
|
|
@@ -1527,6 +1764,7 @@ export class PipelineOrchestrator {
|
|
|
1527
1764
|
requestedEffort,
|
|
1528
1765
|
variantUsed,
|
|
1529
1766
|
},
|
|
1767
|
+
inboundWire: context?.wire,
|
|
1530
1768
|
}, upstreamEventContext);
|
|
1531
1769
|
if (!execResult.success || !execResult.response) {
|
|
1532
1770
|
if (execResult.policyDenied) {
|
|
@@ -1582,10 +1820,14 @@ export class PipelineOrchestrator {
|
|
|
1582
1820
|
// one `pickModelForEffort` originally picked, with a different effort
|
|
1583
1821
|
// translation/ceiling. The header / ExecutionResult must reflect reality.
|
|
1584
1822
|
{
|
|
1585
|
-
const r = this.resolveServedEffort(actualModel, requestedEffort, actualTier, budgetTokens);
|
|
1823
|
+
const r = this.resolveServedEffort(actualModel, requestedEffort, actualTier, budgetTokens, execResult.effortMap);
|
|
1586
1824
|
actualEffort = r.actualEffort;
|
|
1587
1825
|
reasoningDegraded = r.degraded;
|
|
1588
1826
|
}
|
|
1827
|
+
// The pool owns the failover verdict: a leader that was attempted and
|
|
1828
|
+
// rejected shifts the served model, and the direct path must report that
|
|
1829
|
+
// exactly like the cascade legs do (gate-skipped candidates are NOT
|
|
1830
|
+
// failovers — they were never attempted).
|
|
1589
1831
|
failoverOccurred = execResult.failoverOccurred;
|
|
1590
1832
|
failoverAttempts = execResult.failoverAttempts;
|
|
1591
1833
|
failoverPath = execResult.failoverPath;
|
|
@@ -1694,7 +1936,10 @@ export class PipelineOrchestrator {
|
|
|
1694
1936
|
// Cached tokens are included in input; reasoning tokens in output.
|
|
1695
1937
|
const rlUsage = {
|
|
1696
1938
|
tokens: usage.inputTokens + usage.outputTokens,
|
|
1697
|
-
|
|
1939
|
+
// A vendor-reported committed cost (plugin wires whose upstream bills
|
|
1940
|
+
// itself, e.g. qoder credits) is the invoice; the catalog table is only
|
|
1941
|
+
// an estimate and exists as the fallback for wires that report none.
|
|
1942
|
+
costUsd: usage.vendorCostUsd ?? computeRequestCost(usage, actualModel.pricing),
|
|
1698
1943
|
};
|
|
1699
1944
|
let usageCredentialPrefix;
|
|
1700
1945
|
{
|
|
@@ -1718,11 +1963,15 @@ export class PipelineOrchestrator {
|
|
|
1718
1963
|
// schema-cascade turns where the lite lead owns the tier decision.
|
|
1719
1964
|
// Directives deliberately write NOTHING back: a manual override is an
|
|
1720
1965
|
// operator/user decision, not statistical experience to bake into routing.
|
|
1966
|
+
// A NO-OP directive changed nothing, so the ordinary observation stays
|
|
1967
|
+
// learnable; a directive that CHANGED an axis skips the write entirely.
|
|
1721
1968
|
if (routeEntriesOn && promptHash) {
|
|
1722
1969
|
const entryStore = getRouteEntryStore();
|
|
1723
1970
|
if (decision.layerUsed === 'layer2' &&
|
|
1724
1971
|
(decision.confidence ?? 0) >= L2_CONFIDENT_THRESHOLD &&
|
|
1725
|
-
!decision.needsSchemaValidation
|
|
1972
|
+
!decision.needsSchemaValidation &&
|
|
1973
|
+
!tierDirectiveChanged &&
|
|
1974
|
+
!effortDirectiveChanged) {
|
|
1726
1975
|
entryStore.upsert({
|
|
1727
1976
|
promptHash,
|
|
1728
1977
|
tier: actualTier,
|
|
@@ -1848,6 +2097,39 @@ export class PipelineOrchestrator {
|
|
|
1848
2097
|
costUsd: rlUsage.costUsd,
|
|
1849
2098
|
},
|
|
1850
2099
|
});
|
|
2100
|
+
// 8B. Snapshot handoff plane (ADR-0038 / ADR-0040). Same seam as the trace,
|
|
2101
|
+
// so the two observation planes name the same turn identically; the canonical
|
|
2102
|
+
// response is only co-scoped with the ids HERE, which is why the store cannot
|
|
2103
|
+
// be fed from the transport's serialized bytes. Fail-open inside `recordTurn`.
|
|
2104
|
+
if (snapshotRequest && !snapshotRecorded) {
|
|
2105
|
+
snapshotRecorded = true;
|
|
2106
|
+
// A COMPLETED upstream request over a client that had already gone away is
|
|
2107
|
+
// NOT a completed conversation record: the response was drained into a dead
|
|
2108
|
+
// socket. Record it as `aborted` so a later reader (or a handoff) never
|
|
2109
|
+
// believes the model's full answer reached anyone (ADR-0040). The STICKY
|
|
2110
|
+
// probe is preferred — by this point `isClientGone` may read "dead" even
|
|
2111
|
+
// for a clean turn (socket torn down after a full send).
|
|
2112
|
+
const clientGoneBeforeWrite = context?.didClientLeave
|
|
2113
|
+
? context.didClientLeave()
|
|
2114
|
+
: context?.isClientGone?.() === true;
|
|
2115
|
+
this.snapshotStore.recordTurn({
|
|
2116
|
+
sessionId,
|
|
2117
|
+
turnIndex: requestTurn.turnIndex,
|
|
2118
|
+
requestId,
|
|
2119
|
+
ts: startTime,
|
|
2120
|
+
servedModel: actualModel.id,
|
|
2121
|
+
...(clientGoneBeforeWrite
|
|
2122
|
+
? { outcome: 'aborted', abortReason: 'client-abort' }
|
|
2123
|
+
: {}),
|
|
2124
|
+
request: snapshotRequest,
|
|
2125
|
+
response: {
|
|
2126
|
+
status: finalResponse.status,
|
|
2127
|
+
...(finalResponse.reason ? { reason: finalResponse.reason } : {}),
|
|
2128
|
+
output: finalResponse.output ?? [],
|
|
2129
|
+
usage: finalResponse.usage,
|
|
2130
|
+
},
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
1851
2133
|
const breakerState = cbManager.getSnapshot(actualModel.id)?.state ?? 'CLOSED';
|
|
1852
2134
|
// additive keys only — older readers keep reading
|
|
1853
2135
|
// breakerState alone: when the turn ran in pair mode, expose the serving
|
|
@@ -1903,15 +2185,40 @@ export class PipelineOrchestrator {
|
|
|
1903
2185
|
wireConsumesBudgetNatively(wire) {
|
|
1904
2186
|
return wire === 'anthropic-messages' || wire === 'google-gemini' || wire === 'openai-responses';
|
|
1905
2187
|
}
|
|
1906
|
-
resolveServedEffort(model, requestedEffort, servedTier, budgetTokens
|
|
2188
|
+
resolveServedEffort(model, requestedEffort, servedTier, budgetTokens,
|
|
2189
|
+
/** Execution-time translation (e.g. a served member's own table) — when the
|
|
2190
|
+
* serving path already resolved one, it MUST be reused rather than
|
|
2191
|
+
* re-derived from the pool, because a directly-addressed combo has no
|
|
2192
|
+
* pool to re-derive from (ADR-0003). */
|
|
2193
|
+
effortMapOverride) {
|
|
1907
2194
|
const effectiveRequested = requestedEffort ??
|
|
1908
2195
|
(typeof budgetTokens === 'number' && budgetTokens > 0 && !this.wireConsumesBudgetNatively(model.wire)
|
|
1909
2196
|
? effortFromThinkingBudget(budgetTokens)
|
|
1910
2197
|
: undefined);
|
|
1911
2198
|
const ask = effectiveRequested ?? 'none';
|
|
1912
|
-
const target = applyEffortMap(this.registry.effortMapFor(model, servedTier), ask);
|
|
2199
|
+
const target = applyEffortMap(effortMapOverride ?? this.registry.effortMapFor(model, servedTier), ask);
|
|
1913
2200
|
const supported = modelSupportsEfforts(model.supportedReasoningEfforts, model.supportsReasoningEffort, model.reasoningDisableable) ?? [];
|
|
1914
2201
|
const alwaysThink = model.reasoningDisableable === false;
|
|
2202
|
+
// EXPLICITLY declared no level control (`supportedReasoningEfforts: []`) or a
|
|
2203
|
+
// declared table WITHOUT `none`: a level the model cannot honour was never
|
|
2204
|
+
// sent (the wire omits it), so the honest account is "nothing in play", not
|
|
2205
|
+
// a rewritten `none`. Reporting `none` would claim a thinking-off the
|
|
2206
|
+
// gateway never requested — and on a table without `none` that field would
|
|
2207
|
+
// 400 (official: OpenAI `gpt-5`/`gpt-6-astra`, Gemini 3.x). An UNDECLARED
|
|
2208
|
+
// set (`undefined`) keeps the legacy clamp below.
|
|
2209
|
+
if (
|
|
2210
|
+
// A disableable:false model with a declared ladder clamps to its rung
|
|
2211
|
+
// (below) — never an omission. Only the no-rung shapes are handled here.
|
|
2212
|
+
!(alwaysThink && supported.length > 0) &&
|
|
2213
|
+
((isDeclaredNoControl(model.supportedReasoningEfforts) && target !== 'none') ||
|
|
2214
|
+
(target === 'none' && effectiveRequested !== undefined && declaresLadderWithoutNone(model.supportedReasoningEfforts)))) {
|
|
2215
|
+
// A level the model cannot honour was never sent (the wire omits it), so
|
|
2216
|
+
// the honest account is "nothing in play", not a rewritten `none`.
|
|
2217
|
+
// Reporting `none` would claim a thinking-off the gateway never
|
|
2218
|
+
// requested — and on a table without `none` that field would 400.
|
|
2219
|
+
const explicitlyAsked = effectiveRequested !== undefined;
|
|
2220
|
+
return { actualEffort: undefined, degraded: explicitlyAsked };
|
|
2221
|
+
}
|
|
1915
2222
|
// ADR-0035 absolute withholding: an always-think model with a declared
|
|
1916
2223
|
// ladder can NEVER serve `none` — not even for an explicit client none-ask
|
|
1917
2224
|
// or an effortMap that translates to none. It clamps to its lowest rung.
|
|
@@ -1943,9 +2250,9 @@ export class PipelineOrchestrator {
|
|
|
1943
2250
|
*
|
|
1944
2251
|
* Chain contract: chain[0] is the leader (pinned model / explicit model /
|
|
1945
2252
|
* combo leader), the rest follow failover order. When `allowEscalate` is
|
|
1946
|
-
* set (auto lite-tier only),
|
|
1947
|
-
* cross-tier escalation tail — Strict
|
|
1948
|
-
* get lite models appended.
|
|
2253
|
+
* set (auto lite-tier only), the resolved escalation-tier models (see
|
|
2254
|
+
* `escalateTier`) are appended as a cross-tier escalation tail — Strict
|
|
2255
|
+
* Anti-Downgrade: plus chains never get lite models appended.
|
|
1949
2256
|
*
|
|
1950
2257
|
* Two-Tier Cost-Aware Resilience Architecture:
|
|
1951
2258
|
* 1. In-Place Retry (Preserve Upstream KV Prompt Cache, Prevent 10x Cost Invalidation):
|
|
@@ -1997,12 +2304,20 @@ export class PipelineOrchestrator {
|
|
|
1997
2304
|
let candidateList = opts.chain.map((m) => ({
|
|
1998
2305
|
model: m,
|
|
1999
2306
|
accessTier: accessTierOf(m),
|
|
2000
|
-
|
|
2307
|
+
// A directly-addressed combo's PER-MEMBER table wins for its own member;
|
|
2308
|
+
// a member with no table (or a non-combo chain) falls back to its home
|
|
2309
|
+
// tier's translation.
|
|
2310
|
+
effortMap: opts.comboEffortMaps?.get(m.id) ?? this.registry.effortMapFor(m, accessTierOf(m)),
|
|
2001
2311
|
}));
|
|
2002
2312
|
if (allowEscalate) {
|
|
2003
|
-
|
|
2313
|
+
// The escalation target is resolved by the caller (`fallback.escalateTier`
|
|
2314
|
+
// in smart/quality, clamped to COST_MODE_TIER_CEILING in cost mode); the
|
|
2315
|
+
// ceiling is only the default. `accessTier` and the effort translation
|
|
2316
|
+
// follow the tier the model is actually being tried from.
|
|
2317
|
+
const tailTier = opts.escalateTier ?? COST_MODE_TIER_CEILING;
|
|
2318
|
+
for (const m of this.registry.getCandidateModelsForTier(tailTier, true, { costOrder: opts.costOrder === true })) {
|
|
2004
2319
|
if (!candidateList.some(c => c.model.id === m.id))
|
|
2005
|
-
candidateList.push({ model: m, accessTier:
|
|
2320
|
+
candidateList.push({ model: m, accessTier: tailTier, effortMap: this.registry.effortMapFor(m, tailTier) });
|
|
2006
2321
|
}
|
|
2007
2322
|
}
|
|
2008
2323
|
if (opts.modelAccess) {
|
|
@@ -2174,6 +2489,10 @@ export class PipelineOrchestrator {
|
|
|
2174
2489
|
noteCode: forcedPass.noteCode,
|
|
2175
2490
|
});
|
|
2176
2491
|
}
|
|
2492
|
+
// Prefer-native dial for THIS attempt — effort prep, staging headers, and
|
|
2493
|
+
// the returned modelUsed.wire must match what registry.execute dials.
|
|
2494
|
+
const dialWire = pickDialWire(candidate.protocols ?? (candidate.wire ? [candidate.wire] : undefined), opts.inboundWire, request);
|
|
2495
|
+
const dialCandidate = dialWire === candidate.wire ? candidate : { ...candidate, wire: dialWire };
|
|
2177
2496
|
// per-candidate effort translation. Each chain member serves
|
|
2178
2497
|
// through ITS OWN effortMap (`none` included), clamped by its declared
|
|
2179
2498
|
// capability — the request copy carries exactly what gets sent (a
|
|
@@ -2183,7 +2502,7 @@ export class PipelineOrchestrator {
|
|
|
2183
2502
|
const budgetAsk = opts.requestedEffort === undefined &&
|
|
2184
2503
|
typeof request.reasoning?.budgetTokens === 'number' &&
|
|
2185
2504
|
request.reasoning.budgetTokens > 0 &&
|
|
2186
|
-
!this.wireConsumesBudgetNatively(
|
|
2505
|
+
!this.wireConsumesBudgetNatively(dialCandidate.wire)
|
|
2187
2506
|
? effortFromThinkingBudget(request.reasoning.budgetTokens)
|
|
2188
2507
|
: undefined;
|
|
2189
2508
|
const ask = opts.requestedEffort ?? budgetAsk ?? 'none';
|
|
@@ -2194,7 +2513,23 @@ export class PipelineOrchestrator {
|
|
|
2194
2513
|
// `none` — the rewire must run even for an explicit none ask so the
|
|
2195
2514
|
// upstream payload carries the clamped rung, not the forbidden none.
|
|
2196
2515
|
const forbidsNone = candidateAlwaysThink && supported.length > 0;
|
|
2197
|
-
if (
|
|
2516
|
+
if (
|
|
2517
|
+
// The always-think clamp (below) owns a disableable:false model whose
|
|
2518
|
+
// ladder has no `none`: its declared rung is the honest floor, never
|
|
2519
|
+
// an omission. Only the NO-RUNG-TO-CLAMP-TO shapes route here.
|
|
2520
|
+
!(candidateAlwaysThink && supported.length > 0) &&
|
|
2521
|
+
((isDeclaredNoControl(candidate.supportedReasoningEfforts) && target !== 'none') ||
|
|
2522
|
+
(target === 'none' && opts.requestedEffort !== undefined && declaresLadderWithoutNone(candidate.supportedReasoningEfforts)))) {
|
|
2523
|
+
// The level is not one this model can honour — never forward it as a
|
|
2524
|
+
// clamped `none` (a positive "off" on the chat wire, or an HTTP 400 on
|
|
2525
|
+
// a model whose table omits `none`). Send nothing; the vendor's own
|
|
2526
|
+
// default governs. Only rewrite when the request still carries an
|
|
2527
|
+
// effort. An UNDECLARED set (undefined) keeps the legacy clamp below.
|
|
2528
|
+
if (effortOf(request) !== undefined) {
|
|
2529
|
+
candidateReq = { ...request, reasoning: { ...request.reasoning, effort: undefined } };
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
else if (!(target === 'none' && ask === 'none') || forbidsNone) {
|
|
2198
2533
|
let candidateEffort = target === 'none' && !forbidsNone ? 'none' : downgradeReasoning(target, supported, candidateAlwaysThink);
|
|
2199
2534
|
if (candidateEffort === 'none' && candidateAlwaysThink && supported.length === 0) {
|
|
2200
2535
|
candidateEffort = ask;
|
|
@@ -2211,7 +2546,7 @@ export class PipelineOrchestrator {
|
|
|
2211
2546
|
// signatures / encrypted blobs so long multi-turn threads can still fail over
|
|
2212
2547
|
// to Chat-only upstreams instead of failing with 400 on the backup model.
|
|
2213
2548
|
if (failoverAttempts > 1 &&
|
|
2214
|
-
!capabilitiesFor(protocolForWire(
|
|
2549
|
+
!capabilitiesFor(protocolForWire(dialCandidate.wire ?? 'openai-chat')).reasoningSignature &&
|
|
2215
2550
|
candidateReq.input.some((item) => item.type === 'reasoning' && (item.signature !== undefined || item.encrypted !== undefined))) {
|
|
2216
2551
|
const strippedInput = candidateReq.input.flatMap((item) => {
|
|
2217
2552
|
if (item.type !== 'reasoning' || (item.signature === undefined && item.encrypted === undefined))
|
|
@@ -2228,9 +2563,9 @@ export class PipelineOrchestrator {
|
|
|
2228
2563
|
if (opts.relay) {
|
|
2229
2564
|
opts.relay.stageRouting({
|
|
2230
2565
|
...opts.streamRouting,
|
|
2231
|
-
modelUsed:
|
|
2566
|
+
modelUsed: dialCandidate.id,
|
|
2232
2567
|
tierUsed: candidateAccessTier,
|
|
2233
|
-
protocolUsed: protocolForWire(
|
|
2568
|
+
protocolUsed: protocolForWire(dialCandidate.wire ?? 'openai-chat'),
|
|
2234
2569
|
});
|
|
2235
2570
|
}
|
|
2236
2571
|
// In-place retry loop on the SAME candidate model
|
|
@@ -2298,7 +2633,7 @@ export class PipelineOrchestrator {
|
|
|
2298
2633
|
// Resolve egress at the dial: the proxy config hot-applies, so a
|
|
2299
2634
|
// read at trace time could describe a different dial than this one.
|
|
2300
2635
|
attemptEgress = this.registry.egressFor(candidate);
|
|
2301
|
-
candidateResponse = await this.registry.execute(candidateReq,
|
|
2636
|
+
candidateResponse = await this.registry.execute(candidateReq, dialCandidate, upstreamEventContext, credentialPrefix, timingRelay, opts.sessionId, opts.inboundWire);
|
|
2302
2637
|
if (firstChunkAt !== undefined)
|
|
2303
2638
|
streamEndAt = Date.now();
|
|
2304
2639
|
// Scope-aware success: undefined prefix degenerates to the exact
|
|
@@ -2332,7 +2667,12 @@ export class PipelineOrchestrator {
|
|
|
2332
2667
|
// retry decision below — the committed check at the commit point
|
|
2333
2668
|
// returns first, so the two can never disagree.
|
|
2334
2669
|
const willRetryInPlace = diagnosis.isInPlaceRetriable && attempt < maxInplaceAttempts && !opts.relay?.committed;
|
|
2335
|
-
|
|
2670
|
+
// Operator-state errors are not upstream evidence (ADR-0038 §3): a
|
|
2671
|
+
// local run that is stopped on purpose answers `local_run_inactive`,
|
|
2672
|
+
// and recording it would turn a deliberate action into a breaker
|
|
2673
|
+
// cooldown for a model that never failed.
|
|
2674
|
+
const breakerExempt = err?.breakerExempt === true;
|
|
2675
|
+
if (!willRetryInPlace && !breakerExempt) {
|
|
2336
2676
|
cbManager.recordFailureScoped(candidate.id, diagnosis, candidate.provider, credentialPrefix, this.registry.getCredentialChain(candidate.provider)?.map((c) => c.keyHashPrefix));
|
|
2337
2677
|
}
|
|
2338
2678
|
// Upstream-429 feedback into the local shaping window: the provider
|
|
@@ -2428,7 +2768,7 @@ export class PipelineOrchestrator {
|
|
|
2428
2768
|
return {
|
|
2429
2769
|
success: true,
|
|
2430
2770
|
response: candidateResponse,
|
|
2431
|
-
modelUsed:
|
|
2771
|
+
modelUsed: dialCandidate,
|
|
2432
2772
|
tierUsed: candidateAccessTier,
|
|
2433
2773
|
failoverOccurred: failoverAttempts > 1,
|
|
2434
2774
|
failoverAttempts,
|
|
@@ -2443,6 +2783,8 @@ export class PipelineOrchestrator {
|
|
|
2443
2783
|
transport: opts.relay ? transport : 'buffered',
|
|
2444
2784
|
// Served-attempt egress, resolved at the dial by this pool.
|
|
2445
2785
|
egress: attemptEgress,
|
|
2786
|
+
// The translation that actually applied to the served candidate.
|
|
2787
|
+
effortMap: candidateEffortMap,
|
|
2446
2788
|
};
|
|
2447
2789
|
}
|
|
2448
2790
|
}
|