omnicell-router 0.8.4 → 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/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- 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 +8 -0
- package/backend/dist/cli/clients/codex.js +5 -0
- 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/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 +5 -0
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -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 +92 -16
- package/backend/dist/config/comments-en.js +31 -26
- package/backend/dist/config/comments-zh.js +29 -24
- package/backend/dist/config/defaults.d.ts +194 -33
- package/backend/dist/config/defaults.js +193 -32
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +7 -0
- package/backend/dist/config/index.js +184 -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/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 +14 -4
- package/backend/dist/config/types.d.ts +167 -38
- 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 +50 -17
- package/backend/dist/forward-proxy/h2-forward.js +36 -10
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +22 -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 +0 -16
- package/backend/dist/forward-proxy/server.js +124 -156
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +53 -18
- 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 +45 -3
- 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 +82 -24
- package/backend/dist/ir/adapters/openai-responses.js +146 -37
- 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/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 +276 -70
- package/backend/dist/opencode/catalog/ocr-store.js +3 -1
- package/backend/dist/opencode/catalog/overrides-store.d.ts +10 -1
- package/backend/dist/opencode/catalog/overrides-store.js +6 -0
- 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 +25 -2
- package/backend/dist/opencode/catalog/sources/models-dev.js +13 -3
- package/backend/dist/opencode/catalog/types.d.ts +35 -3
- package/backend/dist/opencode/catalog/types.js +38 -1
- 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/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- 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 +497 -165
- 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 +98 -14
- package/backend/dist/plugins/host.js +622 -87
- 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 +252 -36
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- 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/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +84 -25
- package/backend/dist/providers/registry.js +209 -114
- 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 +35 -5
- 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 +928 -310
- 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 +318 -13
- 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/body-admission.d.ts +67 -2
- package/backend/dist/surfaces/body-admission.js +218 -13
- 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 +9 -3
- package/backend/dist/surfaces/transport-node-http.js +6 -19
- 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 +3 -2
- package/backend/dist/utils/server-liveness.js +3 -2
- 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-KI1OW5x6.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-Dk76uc7e.js +0 -1522
|
@@ -4,7 +4,7 @@ import { AnthropicMessagesProvider } from './executors/anthropic-messages.js';
|
|
|
4
4
|
import { OpenAIResponsesProvider } from './executors/openai-responses.js';
|
|
5
5
|
import { GoogleGeminiProvider } from './executors/google-gemini.js';
|
|
6
6
|
import { getModelServicePlugin } from '../plugins/host.js';
|
|
7
|
-
import { EFFORT_LADDER, downgradeReasoning, modelSupportsEfforts } from '../types/router.js';
|
|
7
|
+
import { TIER_RANK, COST_MODE_TIER_CEILING, EFFORT_LADDER, downgradeReasoning, modelSupportsEfforts } from '../types/router.js';
|
|
8
8
|
import { IrUnsupportedError } from '../ir/errors.js';
|
|
9
9
|
import { withDialContext } from '../ir/validate.js';
|
|
10
10
|
import { createEventAccumulator } from '../ir/stream.js';
|
|
@@ -17,8 +17,10 @@ import { canonicalProtocol } from './protocol.js';
|
|
|
17
17
|
import { CircuitBreakerManager, UpstreamError } from '../resilience/index.js';
|
|
18
18
|
import { globMatchAny } from '../utils/glob.js';
|
|
19
19
|
import { loadConfig } from '../config/index.js';
|
|
20
|
-
import {
|
|
21
|
-
import { resolveTierMembers, claimModel, claimInTier, matchingTiers, applyEffortMap, MEMBER_TIER_ORDER, TIER_DESCENDING_ORDER, comboMemberRefsOf, expandComboRefs, RESERVED_IDS } from './member-match.js';
|
|
20
|
+
import { resolveEgress } from '../utils/proxy.js';
|
|
21
|
+
import { resolveTierMembers, claimModel, claimInTier, matchingTiers, applyEffortMap, markExactFullIds, MEMBER_TIER_ORDER, TIER_DESCENDING_ORDER, comboMemberRefsOf, expandComboRefs, RESERVED_IDS } from './member-match.js';
|
|
22
|
+
import { WeightedRoundRobin, normalizeSelectionStrategy, normalizeMemberWeight } from './selection.js';
|
|
23
|
+
import { comparePriceBucket, comparePriceThenId, samePriceBucket } from './price-order.js';
|
|
22
24
|
/**
|
|
23
25
|
* Normalize a client-supplied upstream host for provider matching: lowercase,
|
|
24
26
|
* strip IPv6 brackets and a trailing :port. Returns undefined for empty or
|
|
@@ -84,9 +86,11 @@ export class ProviderRegistry {
|
|
|
84
86
|
* so what routing sees is always exactly what was last committed.
|
|
85
87
|
*/
|
|
86
88
|
committedMembers = { lite: [], plus: [], pro: [], ultra: [] };
|
|
87
|
-
|
|
89
|
+
/** Smooth weighted round-robin cursors — one per tier pool. */
|
|
90
|
+
tierRr = new WeightedRoundRobin();
|
|
88
91
|
combos = new Map();
|
|
89
|
-
|
|
92
|
+
/** Smooth weighted round-robin cursors — one per combo pool. */
|
|
93
|
+
comboRr = new WeightedRoundRobin();
|
|
90
94
|
/** Fingerprint of the combo section last applied by applyCombos — lets the
|
|
91
95
|
* lazy hand-edit safety net skip no-op replays instead of resetting
|
|
92
96
|
* round-robin cursors and re-logging skip warnings every TTL window. */
|
|
@@ -400,7 +404,7 @@ export class ProviderRegistry {
|
|
|
400
404
|
* containing `/` are rejected (those are full-id lookups, not bare names).
|
|
401
405
|
*
|
|
402
406
|
* `upstreamHost` (the proxy-interception target host, when the request
|
|
403
|
-
* arrived through the MITM
|
|
407
|
+
* arrived through the MITM ingress proxy) disambiguates same-name models:
|
|
404
408
|
* candidates whose provider baseUrl hostname matches the host win; when
|
|
405
409
|
* nothing matches (hooked clients hit the gateway itself, unknown hosts)
|
|
406
410
|
* the full hit list applies. Empty result = no registered model carries
|
|
@@ -417,15 +421,13 @@ export class ProviderRegistry {
|
|
|
417
421
|
// Locale-independent tiebreak: strict code-unit order, not localeCompare.
|
|
418
422
|
// Unpriced models sort last: an unknown price cannot claim to be the
|
|
419
423
|
// cheapest, and `Infinity` keeps that ordering without inventing a number.
|
|
420
|
-
const byPrice = (a, b) => (a.pricing?.input ?? Infinity) - (b.pricing?.input ?? Infinity) ||
|
|
421
|
-
(a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
422
424
|
const host = normalizeHostHeader(upstreamHost);
|
|
423
425
|
if (host) {
|
|
424
426
|
const scoped = hits.filter((m) => this.providerHosts.get(m.provider) === host);
|
|
425
427
|
if (scoped.length > 0)
|
|
426
|
-
return scoped.sort(
|
|
428
|
+
return scoped.sort(comparePriceThenId);
|
|
427
429
|
}
|
|
428
|
-
return hits.sort(
|
|
430
|
+
return hits.sort(comparePriceThenId);
|
|
429
431
|
}
|
|
430
432
|
/** Raw provider config (any type) — used for provider baseUrl/apiKey
|
|
431
433
|
* lookup (e.g. boot-time provider registration). */
|
|
@@ -465,54 +467,74 @@ export class ProviderRegistry {
|
|
|
465
467
|
* a weight per pool), default 1. */
|
|
466
468
|
weightFor(tier, modelId) {
|
|
467
469
|
const claim = claimInTier(tier, modelId, this.committedMembers);
|
|
468
|
-
return claim ?
|
|
470
|
+
return claim ? normalizeMemberWeight(claim.rule.weight) : 1;
|
|
469
471
|
}
|
|
470
|
-
/** Effective selection strategy: explicit config wins
|
|
472
|
+
/** Effective selection strategy: explicit config wins, default priority. */
|
|
471
473
|
selectionStrategy(tier) {
|
|
472
|
-
return this.tierPolicies?.[tier]?.selection
|
|
473
|
-
}
|
|
474
|
-
/** Weighted round-robin: each model occupies `weight` consecutive slots per cycle. */
|
|
475
|
-
pickRoundRobin(models, tier) {
|
|
476
|
-
const slots = [];
|
|
477
|
-
for (const m of models) {
|
|
478
|
-
const w = this.weightFor(tier, m.id);
|
|
479
|
-
for (let i = 0; i < w; i++)
|
|
480
|
-
slots.push(m);
|
|
481
|
-
}
|
|
482
|
-
if (slots.length === 0)
|
|
483
|
-
return models[0];
|
|
484
|
-
const prev = this.rrCursor.get(tier) ?? 0;
|
|
485
|
-
this.rrCursor.set(tier, prev + 1);
|
|
486
|
-
return slots[prev % slots.length];
|
|
474
|
+
return normalizeSelectionStrategy(this.tierPolicies?.[tier]?.selection);
|
|
487
475
|
}
|
|
488
476
|
/**
|
|
489
477
|
* Primary pick inside a tier, driven by the tier's selection strategy:
|
|
490
478
|
* - priority (default): first healthy candidate in chain order (= member
|
|
491
479
|
* list order)
|
|
492
|
-
* -
|
|
493
|
-
* rule's weight
|
|
494
|
-
*
|
|
480
|
+
* - weighted_round_robin: smooth WEIGHTED round-robin — weight = the
|
|
481
|
+
* claiming member rule's weight (default 1), served in proportion, evenly
|
|
482
|
+
* interleaved
|
|
483
|
+
* - round_robin: plain sequential round-robin — equal turns, weights ignored
|
|
484
|
+
* `weighted_round_robin` and `round_robin` share ONE smooth round-robin core
|
|
485
|
+
* (combos use it too); only the weight policy differs.
|
|
495
486
|
* The failover chain order is strategy-independent (buildTierPoolEntries:
|
|
496
487
|
* rule weight desc, then rule list order).
|
|
497
488
|
*/
|
|
498
|
-
pickPrimary(models, tier) {
|
|
499
|
-
if (models.length <= 1)
|
|
500
|
-
return models[0];
|
|
489
|
+
pickPrimary(models, tier, costOrder = false) {
|
|
501
490
|
const strategy = this.selectionStrategy(tier);
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
491
|
+
// Cost mode (ADR-0001 §2): restrict the pool to the CHEAPEST price bucket
|
|
492
|
+
// BEFORE the strategy runs, so a pricier member is never selected ahead of
|
|
493
|
+
// a cheaper one — under `priority` too. `priority` returns a head, and a
|
|
494
|
+
// caller list (widened access pool, model-access expansion) is not
|
|
495
|
+
// guaranteed to be price-sorted, so the bucket anchor is the
|
|
496
|
+
// lexicographically CHEAPEST member rather than `models[0]`. Equal-priced
|
|
497
|
+
// members keep sharing turns (rotation draws inside the bucket).
|
|
498
|
+
let pool = models;
|
|
499
|
+
if (costOrder && models.length > 1) {
|
|
500
|
+
const cheapest = models.reduce((best, m) => (comparePriceBucket(m, best) < 0 ? m : best), models[0]);
|
|
501
|
+
const bucket = models.filter((m) => samePriceBucket(m, cheapest));
|
|
502
|
+
if (bucket.length > 0)
|
|
503
|
+
pool = bucket;
|
|
514
504
|
}
|
|
515
|
-
|
|
505
|
+
// `priority` never touches a cursor. The rotation strategies ALWAYS go
|
|
506
|
+
// through the core — including a single-member pool, whose identity check
|
|
507
|
+
// resets a stale vector after a shrink (a short-circuit here would strand
|
|
508
|
+
// credit accumulated before it).
|
|
509
|
+
if (strategy === 'priority')
|
|
510
|
+
return pool[0];
|
|
511
|
+
const weightOf = strategy === 'weighted_round_robin' ? (m) => this.weightFor(tier, m.id) : () => 1;
|
|
512
|
+
// The price projection keeps its OWN cursor: `routing.mode` is hot-reloaded
|
|
513
|
+
// (config/runtime.ts `syncRuntimeAuthView`), so a cost bucket draw and a
|
|
514
|
+
// full-pool draw of this tier can alternate inside one process. A shared
|
|
515
|
+
// key would reset the other projection's credit vector on every toggle.
|
|
516
|
+
return this.tierRr.pick(`${tier}:${strategy}${costOrder ? ':cost' : ''}`, pool, (m) => m.id, weightOf);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Strategy-aware leader over an ALREADY-FILTERED candidate list. `getModelForTier`
|
|
520
|
+
* assembles the pool (health, denylist, cross-tier fallback) and then picks;
|
|
521
|
+
* this is the pure pick for a chain whose pool was filtered elsewhere
|
|
522
|
+
* (model access, widening) — the serving chain must lead with this model.
|
|
523
|
+
*/
|
|
524
|
+
pickLeader(tier, candidates, costOrder = false) {
|
|
525
|
+
return this.pickPrimary(candidates, tier, costOrder);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Chain order for a ready candidate list: the strategy-selected leader first,
|
|
529
|
+
* then the remaining members in their existing order. `priority` leaves the
|
|
530
|
+
* list untouched (its head already leads); only the rotation strategies
|
|
531
|
+
* reorder, and the failover walk after the head is unchanged.
|
|
532
|
+
*/
|
|
533
|
+
orderChain(tier, candidates, costOrder = false) {
|
|
534
|
+
if (candidates.length === 0)
|
|
535
|
+
return candidates;
|
|
536
|
+
const leader = this.pickPrimary(candidates, tier, costOrder);
|
|
537
|
+
return [leader, ...candidates.filter((m) => m.id !== leader.id)];
|
|
516
538
|
}
|
|
517
539
|
/**
|
|
518
540
|
* Per-tier pool construction — the ONE membership read for a single tier.
|
|
@@ -527,7 +549,7 @@ export class ProviderRegistry {
|
|
|
527
549
|
* weight and effortMap — the translation that applies when the model
|
|
528
550
|
* serves from THIS pool.
|
|
529
551
|
*/
|
|
530
|
-
buildTierPoolEntries(tier, members) {
|
|
552
|
+
buildTierPoolEntries(tier, members, order = 'declared') {
|
|
531
553
|
const entries = [];
|
|
532
554
|
for (const m of this.models.values()) {
|
|
533
555
|
if (!m.autoTier) {
|
|
@@ -537,7 +559,7 @@ export class ProviderRegistry {
|
|
|
537
559
|
const claim = claimInTier(tier, m.id, members);
|
|
538
560
|
entries.push({
|
|
539
561
|
model: m,
|
|
540
|
-
weight: claim ?
|
|
562
|
+
weight: claim ? normalizeMemberWeight(claim.rule.weight) : 1,
|
|
541
563
|
effortMap: m.effortMap,
|
|
542
564
|
rank: m.isDefaultInTier ? 0 : m.priority ?? 10,
|
|
543
565
|
});
|
|
@@ -548,12 +570,17 @@ export class ProviderRegistry {
|
|
|
548
570
|
continue;
|
|
549
571
|
entries.push({
|
|
550
572
|
model: m,
|
|
551
|
-
weight:
|
|
573
|
+
weight: normalizeMemberWeight(claim.rule.weight),
|
|
552
574
|
effortMap: claim.rule.effortMap,
|
|
553
575
|
rank: claim.index,
|
|
554
576
|
});
|
|
555
577
|
}
|
|
556
|
-
|
|
578
|
+
// `declared` = weight desc then rule-list order (the operator's own chain).
|
|
579
|
+
// `cheapest` = price first, then the declared order INSIDE a price bucket
|
|
580
|
+
// (cost mode only, ADR-0001 §2; see providers/price-order.ts).
|
|
581
|
+
entries.sort((a, b) => (order === 'cheapest' ? comparePriceBucket(a.model, b.model) : 0) ||
|
|
582
|
+
b.weight - a.weight ||
|
|
583
|
+
a.rank - b.rank);
|
|
557
584
|
return entries;
|
|
558
585
|
}
|
|
559
586
|
/**
|
|
@@ -623,22 +650,40 @@ export class ProviderRegistry {
|
|
|
623
650
|
this.autoRefreshMembers = on;
|
|
624
651
|
}
|
|
625
652
|
/** Registered member refs of one combo (config order, deduped, unregistered
|
|
626
|
-
dropped) — null when the ref is dead:
|
|
627
|
-
shadowed by a registered model. */
|
|
653
|
+
dropped), each carrying its OWN effortMap — null when the ref is dead:
|
|
654
|
+
unknown id, operator-disabled, or shadowed by a registered model. */
|
|
628
655
|
comboMemberRefs(comboId) {
|
|
629
656
|
const combo = this.combos.get(comboId);
|
|
630
657
|
if (!combo || combo.disabled === true || this.models.has(comboId))
|
|
631
658
|
return null;
|
|
632
|
-
return comboMemberRefsOf(combo, (id) => this.models.has(id));
|
|
659
|
+
return { members: comboMemberRefsOf(combo, (id) => this.models.has(id)) };
|
|
660
|
+
}
|
|
661
|
+
/** Per-member thinking-level translations of one combo, keyed by member id
|
|
662
|
+
(ADR-0003). Consumed by the directly-addressed combo path, which has no
|
|
663
|
+
pool context to re-derive from. Empty when the combo is unknown/dead or
|
|
664
|
+
declares no member tables. */
|
|
665
|
+
comboEffortMaps(comboId) {
|
|
666
|
+
const out = new Map();
|
|
667
|
+
for (const member of this.comboMemberRefs(comboId)?.members ?? []) {
|
|
668
|
+
if (member.effortMap)
|
|
669
|
+
out.set(member.id, member.effortMap);
|
|
670
|
+
}
|
|
671
|
+
return out;
|
|
633
672
|
}
|
|
634
673
|
/**
|
|
635
674
|
* The ONE member-rule read view: `tiers.<t>.members` with `combo:<id>` refs
|
|
636
|
-
* expanded in place
|
|
637
|
-
* boot, save checks) must read through this
|
|
638
|
-
* lists while config keeps the operator's
|
|
675
|
+
* expanded in place and hand-written FULL ids pinned exact. Every membership
|
|
676
|
+
* consumer (claims, weights, pools, boot, save checks) must read through this
|
|
677
|
+
* so pools stay physical-model lists while config keeps the operator's
|
|
678
|
+
* declared references. Exact pinning is a PROJECTION concern, not a config
|
|
679
|
+
* write: the stored `tiers` keeps the operator's plain pattern.
|
|
639
680
|
*/
|
|
640
681
|
expandedMemberRules(policies) {
|
|
641
|
-
|
|
682
|
+
const expanded = expandComboRefs(resolveTierMembers(policies).tiers, (id) => this.comboMemberRefs(id));
|
|
683
|
+
const registered = new Set();
|
|
684
|
+
for (const id of this.models.keys())
|
|
685
|
+
registered.add(id.toLowerCase());
|
|
686
|
+
return { dead: expanded.dead, tiers: markExactFullIds(expanded.tiers, (id) => registered.has(id.toLowerCase())) };
|
|
642
687
|
}
|
|
643
688
|
/**
|
|
644
689
|
* COMMIT path — the only one that rewrites live pool membership. Called on
|
|
@@ -728,37 +773,66 @@ export class ProviderRegistry {
|
|
|
728
773
|
* pool (one whose supported set sits above the requested level) is
|
|
729
774
|
* NOT a valid match — we'd rather let the orchestrator pick a
|
|
730
775
|
* different route than silently drop to `none`.
|
|
776
|
+
*
|
|
777
|
+
* `maxTier` bounds Pass 2 (the cross-tier search): no tier ranked above it
|
|
778
|
+
* may serve. Cost mode passes COST_MODE_TIER_CEILING so an effort the lite
|
|
779
|
+
* pool cannot satisfy can never spend a pro/ultra model (ADR-0001 §28).
|
|
780
|
+
* Defaulting to undefined keeps the unrestricted cross-tier search for
|
|
781
|
+
* smart/quality and for direct registry callers.
|
|
782
|
+
*
|
|
783
|
+
* `sameTierOnly` disables Pass 2 entirely: the request is served from THIS
|
|
784
|
+
* tier or not at all. A `same_tier_only` failover policy and a client-forced
|
|
785
|
+
* tier both demand it — a forced lite must never be widened onto a plus/pro
|
|
786
|
+
* model by an effort-aware pick (ADR-0014).
|
|
731
787
|
*/
|
|
732
|
-
pickModelForEffort(tier, requested, healthyOnly = true) {
|
|
788
|
+
pickModelForEffort(tier, requested, healthyOnly = true, costOrder = false, maxTier, sameTierOnly = false) {
|
|
733
789
|
if (requested === 'none') {
|
|
734
790
|
// No thinking requested. Legacy pass-through (any model) UNLESS a
|
|
735
791
|
// member rule maps `none` to a real level (e.g. none→high):
|
|
736
792
|
// then the mapped candidates compete and the mapped level is served.
|
|
737
|
-
const entries = this.tierPoolEntries(tier, healthyOnly);
|
|
793
|
+
const entries = this.tierPoolEntries(tier, healthyOnly, { costOrder });
|
|
738
794
|
if (entries.some((e) => applyEffortMap(e.effortMap, 'none') !== 'none')) {
|
|
739
795
|
const mapped = this.bestEffortMatch(entries, requested);
|
|
740
796
|
if (mapped)
|
|
741
797
|
return mapped;
|
|
742
798
|
}
|
|
743
|
-
|
|
799
|
+
// Pass-through head is NOT a selection: the caller's per-request chain
|
|
800
|
+
// head is the one real pick, so reading the rotation cursor here would
|
|
801
|
+
// advance it twice per request and serve every second draw. The pool
|
|
802
|
+
// head (all health levels, never drawn) is the same model the chain
|
|
803
|
+
// would lead with.
|
|
804
|
+
const head = entries[0]?.model ?? this.getCandidateModelsForTier(tier, false, { costOrder })[0];
|
|
805
|
+
if (head)
|
|
806
|
+
return { model: head, actualEffort: 'none', degraded: false };
|
|
807
|
+
// Pool empty at every health level: keep the getter's cross-tier /
|
|
808
|
+
// throw contract. No rotation draw can happen here — a pool with no
|
|
809
|
+
// candidate has nothing for pickPrimary to advance.
|
|
810
|
+
const m = this.getModelForTier(tier, healthyOnly, costOrder);
|
|
744
811
|
if (m)
|
|
745
812
|
return { model: m, actualEffort: 'none', degraded: false };
|
|
746
813
|
return null;
|
|
747
814
|
}
|
|
748
815
|
// Pass 1: pick from the requested tier (each candidate is first translated
|
|
749
816
|
// by ITS pool's effortMap, then capability-clamped — see bestEffortMatch).
|
|
750
|
-
const tierPick = this.bestEffortMatch(this.tierPoolEntries(tier, healthyOnly), requested);
|
|
817
|
+
const tierPick = this.bestEffortMatch(this.tierPoolEntries(tier, healthyOnly, { costOrder }), requested);
|
|
751
818
|
if (tierPick)
|
|
752
819
|
return tierPick;
|
|
753
820
|
// Pass 2: cross-tier fallback — search all tiers in tier-rank order
|
|
754
821
|
// (highest first) for any healthy thinking-capable model. Per design
|
|
755
822
|
// decision 2026-10: cross-tier mixing is allowed; the actual model is
|
|
756
|
-
// still reported in the response so the caller sees the truth.
|
|
823
|
+
// still reported in the response so the caller sees the truth. `maxTier`
|
|
824
|
+
// caps that walk (cost mode must never spend above its ceiling).
|
|
825
|
+
// `sameTierOnly` refuses the walk outright — the tier is a hard bound, not
|
|
826
|
+
// a preference (same_tier_only policy / a client-forced tier).
|
|
827
|
+
if (sameTierOnly)
|
|
828
|
+
return null;
|
|
757
829
|
const tierOrder = TIER_DESCENDING_ORDER;
|
|
758
830
|
for (const t of tierOrder) {
|
|
759
831
|
if (t === tier)
|
|
760
832
|
continue;
|
|
761
|
-
|
|
833
|
+
if (maxTier !== undefined && TIER_RANK[t] > TIER_RANK[maxTier])
|
|
834
|
+
continue;
|
|
835
|
+
const pick = this.bestEffortMatch(this.tierPoolEntries(t, healthyOnly, { costOrder }), requested);
|
|
762
836
|
if (pick)
|
|
763
837
|
return pick;
|
|
764
838
|
}
|
|
@@ -773,7 +847,7 @@ export class ProviderRegistry {
|
|
|
773
847
|
* upstream for the gateway's own wire mismatch; the decision surface
|
|
774
848
|
* passes `decisionSurface: true` to see them. */
|
|
775
849
|
tierPoolEntries(tier, healthyOnly, opts) {
|
|
776
|
-
return this.buildTierPoolEntries(tier, this.committedMembers)
|
|
850
|
+
return this.buildTierPoolEntries(tier, this.committedMembers, opts?.costOrder ? 'cheapest' : 'declared')
|
|
777
851
|
.filter(({ model }) => opts?.decisionSurface === true || model.wire !== 'systemone')
|
|
778
852
|
.filter(({ model }) => !this.policyRejectionReason(this.tierPolicies, model))
|
|
779
853
|
.filter(({ model }) => !healthyOnly || this.modelAvailable(model).available);
|
|
@@ -821,33 +895,53 @@ export class ProviderRegistry {
|
|
|
821
895
|
return null;
|
|
822
896
|
return { model: best.model, actualEffort: best.actualEffort, degraded: best.gap > 0 };
|
|
823
897
|
}
|
|
824
|
-
getModelForTier(tier, healthyOnly = true) {
|
|
825
|
-
const candidates = this.getCandidateModelsForTier(tier, healthyOnly);
|
|
898
|
+
getModelForTier(tier, healthyOnly = true, costOrder = false) {
|
|
899
|
+
const candidates = this.getCandidateModelsForTier(tier, healthyOnly, { costOrder });
|
|
826
900
|
if (candidates.length > 0) {
|
|
827
|
-
return this.pickPrimary(candidates, tier);
|
|
901
|
+
return this.pickPrimary(candidates, tier, costOrder);
|
|
828
902
|
}
|
|
829
903
|
// If healthyOnly was true and no healthy models found, fallback to any model in tier
|
|
830
904
|
if (healthyOnly) {
|
|
831
|
-
const anyCandidate = this.getCandidateModelsForTier(tier, false);
|
|
905
|
+
const anyCandidate = this.getCandidateModelsForTier(tier, false, { costOrder });
|
|
832
906
|
if (anyCandidate.length > 0) {
|
|
833
|
-
return this.pickPrimary(anyCandidate, tier);
|
|
907
|
+
return this.pickPrimary(anyCandidate, tier, costOrder);
|
|
834
908
|
}
|
|
835
909
|
}
|
|
836
910
|
// the requested tier is EMPTY (a real possibility now that there
|
|
837
911
|
// is no residual catch-all). Degradation is still possible — routing must
|
|
838
912
|
// not hard-fail on a config the user can legitimately write — but it is
|
|
839
913
|
// NEVER silent: the cross-tier step is logged with the reason.
|
|
840
|
-
|
|
914
|
+
//
|
|
915
|
+
// COST MODE (ADR-0001 §2) bounds the walk: `costOrder` clamps every
|
|
916
|
+
// landing to COST_MODE_TIER_CEILING, and a 'never' costEscalation policy
|
|
917
|
+
// pins the walk to tiers at or below the requested one — a cost pin must
|
|
918
|
+
// never be repaired onto pro/ultra money just because lite is empty.
|
|
919
|
+
const cfg = this.tierPolicies ? loadConfig() : undefined;
|
|
920
|
+
const escalate = cfg?.fallback?.escalateTier ?? 'plus';
|
|
921
|
+
const hardPin = costOrder && cfg?.routing?.costEscalation === 'never';
|
|
922
|
+
const maxRank = !costOrder
|
|
923
|
+
? Number.POSITIVE_INFINITY
|
|
924
|
+
: hardPin
|
|
925
|
+
? TIER_RANK[tier]
|
|
926
|
+
: TIER_RANK[COST_MODE_TIER_CEILING];
|
|
841
927
|
const order = [escalate, 'plus', 'lite', 'pro', 'ultra'];
|
|
842
|
-
const chain = order.filter((t, i, all) => t !== tier && all.indexOf(t) === i);
|
|
928
|
+
const chain = order.filter((t, i, all) => t !== tier && all.indexOf(t) === i && TIER_RANK[t] <= maxRank);
|
|
843
929
|
for (const step of chain) {
|
|
844
|
-
|
|
930
|
+
// Cost mode prefers the step's CHEAPEST pool head (a peek — never a
|
|
931
|
+
// rotation draw) over the declared-order representative, so the degraded
|
|
932
|
+
// landing honours the price axis the rest of the cost-mode primitives
|
|
933
|
+
// sort by (the tierDefaults table is built in declared order).
|
|
934
|
+
const rep = costOrder
|
|
935
|
+
? this.getCandidateModelsForTier(step, true, { costOrder })[0] ?? this.tierDefaults.get(step)
|
|
936
|
+
: this.tierDefaults.get(step);
|
|
845
937
|
if (rep && rep.tier !== undefined) {
|
|
846
938
|
console.warn(`[Registry] Tier '${tier}' has no candidate model — falling back to '${step}' (${rep.id}), reason=empty-pool`);
|
|
847
939
|
return rep;
|
|
848
940
|
}
|
|
849
941
|
}
|
|
850
|
-
|
|
942
|
+
// Last resort: prefer an in-budget model before a model that would breach
|
|
943
|
+
// the cost ceiling / a hard pin.
|
|
944
|
+
const any = Array.from(this.models.values()).find((m) => m.tier !== undefined && TIER_RANK[m.tier] <= maxRank) ?? Array.from(this.models.values()).find((m) => m.tier !== undefined);
|
|
851
945
|
if (!any) {
|
|
852
946
|
throw new Error(`No routable models registered (no model's tier membership is claimed by any pool).`);
|
|
853
947
|
}
|
|
@@ -942,7 +1036,7 @@ export class ProviderRegistry {
|
|
|
942
1036
|
return;
|
|
943
1037
|
this.combosFingerprint = fingerprint;
|
|
944
1038
|
this.combos.clear();
|
|
945
|
-
this.
|
|
1039
|
+
this.comboRr.reset();
|
|
946
1040
|
for (const combo of combos || []) {
|
|
947
1041
|
if (!combo?.id || !Array.isArray(combo.models) || combo.models.length === 0)
|
|
948
1042
|
continue;
|
|
@@ -977,7 +1071,7 @@ export class ProviderRegistry {
|
|
|
977
1071
|
comboMemberRef(entry) {
|
|
978
1072
|
if (typeof entry === 'string')
|
|
979
1073
|
return { id: entry, weight: 1 };
|
|
980
|
-
return { id: entry.id, weight:
|
|
1074
|
+
return { id: entry.id, weight: normalizeMemberWeight(entry.weight) };
|
|
981
1075
|
}
|
|
982
1076
|
/**
|
|
983
1077
|
* Resolve a combo to its registered member models in config order.
|
|
@@ -1003,16 +1097,27 @@ export class ProviderRegistry {
|
|
|
1003
1097
|
return members;
|
|
1004
1098
|
}
|
|
1005
1099
|
/**
|
|
1006
|
-
* Combo primary pick, mirroring the tier selection strategies:
|
|
1100
|
+
* Combo primary pick, mirroring the tier selection strategies exactly:
|
|
1007
1101
|
* - priority (default): first healthy member in config order
|
|
1008
|
-
* -
|
|
1009
|
-
*
|
|
1102
|
+
* - weighted_round_robin: smooth WEIGHTED round-robin — weight = the member
|
|
1103
|
+
* entry's weight (default 1)
|
|
1104
|
+
* - round_robin: plain sequential round-robin — equal turns, weights ignored
|
|
1105
|
+
* The same smooth round-robin core serves the tier pools; cursors are
|
|
1106
|
+
* combo-scoped (and strategy-scoped).
|
|
1010
1107
|
* Falls back to the full member list when every member is tripped.
|
|
1108
|
+
*
|
|
1109
|
+
* An EMPTY member list is a caller bug (the combo either does not exist or
|
|
1110
|
+
* has no registered member) and throws — the same contract as the rotation
|
|
1111
|
+
* core. Callers check `resolveCombo(...)` first; `undefined` from the old
|
|
1112
|
+
* `members[0]` return was never part of this signature.
|
|
1011
1113
|
*/
|
|
1012
1114
|
pickComboLeader(comboId, members) {
|
|
1013
|
-
if (members.length
|
|
1014
|
-
|
|
1015
|
-
|
|
1115
|
+
if (members.length === 0) {
|
|
1116
|
+
throw new Error(`pickComboLeader: combo '${comboId}' has no resolved members`);
|
|
1117
|
+
}
|
|
1118
|
+
// Single-member combos still go through the rotation core on rotation
|
|
1119
|
+
// strategies so a shrunk pool resets its cursor (same rule as the tiers).
|
|
1120
|
+
const strategy = normalizeSelectionStrategy(this.combos.get(comboId)?.selection);
|
|
1016
1121
|
// Decision 6 aggregate (same rule as the tier pools): a member whose every
|
|
1017
1122
|
// credential is out must not lead a combo.
|
|
1018
1123
|
const healthy = members.filter((m) => this.modelAvailable(m).available);
|
|
@@ -1023,31 +1128,10 @@ export class ProviderRegistry {
|
|
|
1023
1128
|
if (!weights.has(ref.id))
|
|
1024
1129
|
weights.set(ref.id, ref.weight);
|
|
1025
1130
|
}
|
|
1026
|
-
if (strategy === '
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
for (let i = 0; i < w; i++)
|
|
1031
|
-
slots.push(m);
|
|
1032
|
-
}
|
|
1033
|
-
if (slots.length === 0)
|
|
1034
|
-
return pool[0];
|
|
1035
|
-
const prev = this.comboRrCursor.get(comboId) ?? 0;
|
|
1036
|
-
this.comboRrCursor.set(comboId, prev + 1);
|
|
1037
|
-
return slots[prev % slots.length];
|
|
1038
|
-
}
|
|
1039
|
-
if (strategy === 'weighted') {
|
|
1040
|
-
const ws = pool.map(m => weights.get(m.id) ?? 1);
|
|
1041
|
-
const total = ws.reduce((a, b) => a + b, 0);
|
|
1042
|
-
let r = Math.random() * total;
|
|
1043
|
-
for (let i = 0; i < pool.length; i++) {
|
|
1044
|
-
r -= ws[i];
|
|
1045
|
-
if (r < 0)
|
|
1046
|
-
return pool[i];
|
|
1047
|
-
}
|
|
1048
|
-
return pool[pool.length - 1];
|
|
1049
|
-
}
|
|
1050
|
-
return pool[0];
|
|
1131
|
+
if (strategy === 'priority')
|
|
1132
|
+
return pool[0];
|
|
1133
|
+
const weightOf = strategy === 'weighted_round_robin' ? (m) => weights.get(m.id) ?? 1 : () => 1;
|
|
1134
|
+
return this.comboRr.pick(`${comboId}:${strategy}`, pool, (m) => m.id, weightOf);
|
|
1051
1135
|
}
|
|
1052
1136
|
/**
|
|
1053
1137
|
* Introspection for the console resolve a tier's effective
|
|
@@ -1093,13 +1177,19 @@ export class ProviderRegistry {
|
|
|
1093
1177
|
}
|
|
1094
1178
|
/**
|
|
1095
1179
|
* Outbound egress the CORE transport will take for `model`, resolved from
|
|
1096
|
-
* the same `
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1180
|
+
* the same `resolveEgress` the executors dial with (ADR-0018 / ADR-0022).
|
|
1181
|
+
* Call this IMMEDIATELY before `execute()` and keep the value with the
|
|
1182
|
+
* attempt: the proxy config hot-applies, so a read after a long stream can
|
|
1183
|
+
* describe a different dial.
|
|
1100
1184
|
*
|
|
1101
|
-
* `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode)
|
|
1102
|
-
*
|
|
1185
|
+
* `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode), the
|
|
1186
|
+
* transport does not report its dial base (plugin-owned executors), OR the
|
|
1187
|
+
* operator demanded the proxy and there was no endpoint to dial
|
|
1188
|
+
* (`no-endpoint`). That last case `proxiedFetch` REFUSES — no socket is
|
|
1189
|
+
* opened — so claiming `direct` would put a "goes direct" stamp on a request
|
|
1190
|
+
* that never left the machine. The connectivity probe reports UNKNOWN for it
|
|
1191
|
+
* for the same reason; this keeps the two honest about one verdict. The
|
|
1192
|
+
* verdict's `origin` is already redacted, so no credential can ride a trace.
|
|
1103
1193
|
*/
|
|
1104
1194
|
egressFor(model) {
|
|
1105
1195
|
if (this.mockMode)
|
|
@@ -1107,8 +1197,13 @@ export class ProviderRegistry {
|
|
|
1107
1197
|
const base = this.providers.get(model.provider)?.dialBaseFor?.(model);
|
|
1108
1198
|
if (!base)
|
|
1109
1199
|
return undefined;
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1200
|
+
const verdict = resolveEgress(base, { provider: model.provider, model: model.id });
|
|
1201
|
+
if (verdict.mode === 'proxy')
|
|
1202
|
+
return { mode: 'proxy', origin: verdict.origin };
|
|
1203
|
+
// A refused dial (no-endpoint) took NO leg — stamp UNKNOWN, not direct.
|
|
1204
|
+
if (verdict.reason === 'no-endpoint')
|
|
1205
|
+
return undefined;
|
|
1206
|
+
return { mode: 'direct', reason: verdict.reason };
|
|
1112
1207
|
}
|
|
1113
1208
|
/**
|
|
1114
1209
|
* Execute one completion. `credentialKeyHashPrefix`
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primary-pick selection for tier pools and combos — ONE algorithm family, ONE
|
|
3
|
+
* vocabulary shared by both surfaces.
|
|
4
|
+
*
|
|
5
|
+
* Strategies (the industry-standard trio):
|
|
6
|
+
* - `priority` — the chain head (config/rule order, weight desc)
|
|
7
|
+
* serves; failover walks the rest of the chain.
|
|
8
|
+
* This is the failover axis, not a load-balancing
|
|
9
|
+
* algorithm.
|
|
10
|
+
* - `weighted_round_robin` — smooth WEIGHTED round-robin (SWRR): every member
|
|
11
|
+
* is served in proportion to its weight, with the
|
|
12
|
+
* turns spread evenly (this replaced the retired
|
|
13
|
+
* weighted-RANDOM draw).
|
|
14
|
+
* - `round_robin` — plain (sequential) round-robin: members take
|
|
15
|
+
* turns equally; weights are ignored.
|
|
16
|
+
*
|
|
17
|
+
* `weighted_round_robin` and `round_robin` run through the SAME smooth
|
|
18
|
+
* round-robin core; they differ only in the weight policy (declared share vs
|
|
19
|
+
* uniform 1). There is NO legacy spelling: a value that names none of the
|
|
20
|
+
* three strategies resolves to the default (`priority`).
|
|
21
|
+
*/
|
|
22
|
+
export type SelectionStrategy = 'priority' | 'weighted_round_robin' | 'round_robin';
|
|
23
|
+
/**
|
|
24
|
+
* Hard ceiling for a member weight. The smooth core accumulates credit in a JS
|
|
25
|
+
* number, so an unbounded value (`Infinity` from YAML `.inf` / `1e309`, or a
|
|
26
|
+
* float near the maximum added twice) overflows the accumulator to `Infinity`
|
|
27
|
+
* and then poisons the cursor with `NaN`. Clamping here keeps every weight
|
|
28
|
+
* finite while leaving realistic rotation shares untouched.
|
|
29
|
+
*/
|
|
30
|
+
export declare const MAX_MEMBER_WEIGHT = 1000000;
|
|
31
|
+
/** Resolve a member weight: NaN and sub-1 values mean 1; a non-finite
|
|
32
|
+
* (Infinity from YAML `.inf` / `1e309`) or overflowing value is clamped to
|
|
33
|
+
* `MAX_MEMBER_WEIGHT` — the intent `as heavy as possible` stays honoured and
|
|
34
|
+
* the accumulator stays finite. */
|
|
35
|
+
export declare function normalizeMemberWeight(value: unknown): number;
|
|
36
|
+
/**
|
|
37
|
+
* Normalize a stored strategy value. The three known strategies pass through;
|
|
38
|
+
* everything else — absent, unknown, or the retired `weighted` spelling of the
|
|
39
|
+
* old weighted-RANDOM draw — falls back to the default `priority`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizeSelectionStrategy(value: unknown): SelectionStrategy;
|
|
42
|
+
/**
|
|
43
|
+
* Canonicalize every PRESENT `selection` value in a config-shaped container:
|
|
44
|
+
* `tiers.<tier>.selection` and `combos[].selection` (the runtime flat shape and
|
|
45
|
+
* the disk `routing.*` shape share this layout, so one walker serves both).
|
|
46
|
+
*
|
|
47
|
+
* Called at every config boundary — the runtime read (loadConfig), the visual
|
|
48
|
+
* save (saveConfig) and the raw-YAML save (saveRawConfig) — so runtime consumers
|
|
49
|
+
* only ever see one of the three strategies and no write path can persist an
|
|
50
|
+
* unknown or retired spelling.
|
|
51
|
+
*
|
|
52
|
+
* An ABSENT `selection` is left absent (it already means the default); only a
|
|
53
|
+
* present value is rewritten. `normalizeSelectionStrategy` owns the mapping —
|
|
54
|
+
* unknown / retired spellings become `priority`.
|
|
55
|
+
*
|
|
56
|
+
* @returns true when at least one value changed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function canonicalizeSelectionValues(container: unknown): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Smooth round-robin core (the nginx SWRR algorithm), shared by tier pools and
|
|
61
|
+
* combos so both surfaces rotate identically.
|
|
62
|
+
*
|
|
63
|
+
* Each pick adds every member's weight to its running credit, serves the
|
|
64
|
+
* highest credit and debits the pool's total weight from it. With weighted
|
|
65
|
+
* members each is served exactly `weight` times per cycle, interleaved as
|
|
66
|
+
* evenly as the weights allow (weights 5:1:1 → a, a, b, a, c, a, a — a
|
|
67
|
+
* burst-free rotation); with uniform weights it degenerates to plain
|
|
68
|
+
* round-robin (a, b, c, a, …).
|
|
69
|
+
*
|
|
70
|
+
* O(n) time and O(n) state per pool: unlike the retired "expand each member
|
|
71
|
+
* into `weight` consecutive slots" table, a six-digit weight costs nothing and
|
|
72
|
+
* every pool read stays linear in the member count.
|
|
73
|
+
*
|
|
74
|
+
* State is scoped by a caller-chosen key (tier + strategy / combo id +
|
|
75
|
+
* strategy). A pool whose member sequence OR declared weights change starts a
|
|
76
|
+
* fresh vector on the next pick, so a stale credit vector can never steer a
|
|
77
|
+
* new composition — and a pool shrunk to one member resets here too (the
|
|
78
|
+
* recovered pool must not resume credit accumulated before the shrink).
|
|
79
|
+
*/
|
|
80
|
+
export declare class WeightedRoundRobin {
|
|
81
|
+
private state;
|
|
82
|
+
/**
|
|
83
|
+
* One draw over `entries`. `idOf` identifies a member (pool identity) and
|
|
84
|
+
* `weightOf` returns its rotation weight (values below 1 / non-numeric
|
|
85
|
+
* degrade to 1, a non-finite value clamps to MAX_MEMBER_WEIGHT — matching
|
|
86
|
+
* the config contract); pass `() => 1` for plain round-robin.
|
|
87
|
+
*/
|
|
88
|
+
pick<T>(key: string, entries: readonly T[], idOf: (entry: T) => string, weightOf: (entry: T) => number): T;
|
|
89
|
+
/** Drop one pool's cursor (membership/order changed) or every cursor. */
|
|
90
|
+
reset(key?: string): void;
|
|
91
|
+
}
|