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
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { comboEnvelope, findMemberCatalogRecords, tierAliasEnvelope, TIER_LADDER, } from '../providers/virtual-meta.js';
|
|
2
|
+
import { EFFORT_LADDER, modelSupportsEfforts } from '../types/router.js';
|
|
3
|
+
/**
|
|
4
|
+
* The capability half of the gateway catalog handed to client-gateway plugins
|
|
5
|
+
* (ADR-0017 `catalog()`).
|
|
6
|
+
*
|
|
7
|
+
* A vendor client draws its model picker, its compaction budget and its
|
|
8
|
+
* thinking-level control from whatever the gateway advertises. The ids alone
|
|
9
|
+
* are not enough: with capabilities absent a client either invents a number
|
|
10
|
+
* (Cursor's 200K constant compacted a 1M-context model early) or offers no
|
|
11
|
+
* level at all. This module projects the REAL facts the routing plane already
|
|
12
|
+
* holds — the resolved effort ladder (post ADR-0035 `none` withholding) and the
|
|
13
|
+
* catalog `limit` / modalities — into ONE map keyed by gateway-visible id.
|
|
14
|
+
*
|
|
15
|
+
* Shape rules (they are what keeps the advertisement honest):
|
|
16
|
+
* - a concrete id reports what its registration will actually serve;
|
|
17
|
+
* - a virtual id (`auto` / tier alias / combo) reports the member-set
|
|
18
|
+
* envelope for LIMITS (declared rung window for tier aliases and `auto`
|
|
19
|
+
* per ADR-0041, safe-min context for combos, intersection vision) and the
|
|
20
|
+
* permissive full ladder for EFFORT — the gateway clamps per request and
|
|
21
|
+
* reports the served level on `X-OCR-Thinking-*`, the same contract
|
|
22
|
+
* `/v1/models` already publishes for virtual refs (see virtual-meta.ts);
|
|
23
|
+
* - an id whose facts are unknown is ABSENT from the map, never defaulted.
|
|
24
|
+
*/
|
|
25
|
+
/** Limiting envelope values for a virtual ref, in the gateway vocabulary. */
|
|
26
|
+
function virtualCapabilities(env) {
|
|
27
|
+
return {
|
|
28
|
+
...(env.contextWindow ? { contextWindow: env.contextWindow } : {}),
|
|
29
|
+
...(env.maxTokens ? { maxOutputTokens: env.maxTokens } : {}),
|
|
30
|
+
...(env.imageInput ? { vision: true } : {}),
|
|
31
|
+
// Virtual refs resolve their member per request; the gateway clamps to
|
|
32
|
+
// what the member can serve, so the ladder is advertised permissively —
|
|
33
|
+
// exactly the claim `virtualModelsDevBlock` already makes for
|
|
34
|
+
// `/v1/models` (reasoning: true + the full ladder). Keeping the two
|
|
35
|
+
// surfaces identical matters more than a per-pool intersection the
|
|
36
|
+
// client cannot act on.
|
|
37
|
+
...(env.memberCount > 0
|
|
38
|
+
? { thinking: true, supportedEfforts: [...EFFORT_LADDER] }
|
|
39
|
+
: {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function concreteCapabilities(cat, supported, defaultEffort) {
|
|
43
|
+
const vision = cat?.attachment === true ||
|
|
44
|
+
(Array.isArray(cat?.modalities?.input) && cat.modalities.input.includes('image'));
|
|
45
|
+
// Tri-state: a declared `reasoning: false` is the catalog SAYING it does not
|
|
46
|
+
// reason; an absent field is "not stated" and must not be turned into a
|
|
47
|
+
// claim either way. A resolved ladder implies reasoning.
|
|
48
|
+
const reasoningDeclared = cat?.reasoning === false ? false : cat?.reasoning === true ? true : undefined;
|
|
49
|
+
const thinks = reasoningDeclared ?? (supported && supported.length > 0 ? true : undefined);
|
|
50
|
+
// A pin the ladder cannot serve is not a fact this id can state — the
|
|
51
|
+
// pipeline would clamp the ask away, so advertising it would pre-select a
|
|
52
|
+
// level the request never sends. Publish it only where it survives.
|
|
53
|
+
const pinned = defaultEffort && supported?.includes(defaultEffort) ? defaultEffort : undefined;
|
|
54
|
+
return {
|
|
55
|
+
...(cat?.limit?.context ? { contextWindow: cat.limit.context } : {}),
|
|
56
|
+
...(cat?.limit?.output ? { maxOutputTokens: cat.limit.output } : {}),
|
|
57
|
+
...(vision ? { vision: true } : {}),
|
|
58
|
+
...(thinks !== undefined ? { thinking: thinks } : {}),
|
|
59
|
+
...(supported && supported.length > 0 ? { supportedEfforts: [...supported] } : {}),
|
|
60
|
+
...(pinned ? { defaultEffort: pinned } : {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Registry identity for the projection: every input that can change the
|
|
65
|
+
* result without a source sync (model ids, home tiers, resolved effort
|
|
66
|
+
* tables, the always-think fact, variant siblings, combo compositions).
|
|
67
|
+
* Catalog-side drift is picked up on the next rebuild regardless — a catalog
|
|
68
|
+
* sync lands far less often than a console save.
|
|
69
|
+
*/
|
|
70
|
+
function registrySignature(registry) {
|
|
71
|
+
const parts = [];
|
|
72
|
+
for (const model of registry.getAllModels()) {
|
|
73
|
+
parts.push(`${model.id}\u0001${model.tier ?? ''}\u0001${(model.supportedReasoningEfforts ?? []).join(',')}` +
|
|
74
|
+
`\u0001${model.supportsReasoningEffort === true ? '1' : ''}\u0001${model.reasoningDisableable === false ? '0' : ''}` +
|
|
75
|
+
`\u0001${model.defaultEffort ?? ''}`);
|
|
76
|
+
}
|
|
77
|
+
for (const variant of registry.getVariantExposures())
|
|
78
|
+
parts.push(`v:${variant.id}`);
|
|
79
|
+
for (const combo of registry.getCombos()) {
|
|
80
|
+
parts.push(`c:${combo.id}\u0001${combo.disabled === true ? 'off' : 'on'}\u0001${combo.models
|
|
81
|
+
.map((m) => (typeof m === 'string' ? m : m.id))
|
|
82
|
+
.join(',')}`);
|
|
83
|
+
}
|
|
84
|
+
return parts.join('\u0002');
|
|
85
|
+
}
|
|
86
|
+
/** Ids-only catalog — the pre-capability shape, used while a build is in flight. */
|
|
87
|
+
function baseCatalog(registry) {
|
|
88
|
+
return {
|
|
89
|
+
virtualModels: ['auto', ...TIER_LADDER],
|
|
90
|
+
models: registry.getAllModels().map((m) => ({ id: m.id, label: m.upstreamModel })),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Build the capability map against one catalog snapshot. */
|
|
94
|
+
async function project(registry, listCatalog) {
|
|
95
|
+
const catalog = baseCatalog(registry);
|
|
96
|
+
const capabilities = {};
|
|
97
|
+
// Memoize the catalog list for this build: every envelope / lookup call
|
|
98
|
+
// would otherwise re-fetch the same in-memory aggregate.
|
|
99
|
+
let providers;
|
|
100
|
+
const listOnce = async () => {
|
|
101
|
+
if (!providers) {
|
|
102
|
+
try {
|
|
103
|
+
providers = await listCatalog();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
providers = [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return providers;
|
|
110
|
+
};
|
|
111
|
+
const models = registry.getAllModels();
|
|
112
|
+
const { byId } = await findMemberCatalogRecords(models.map((m) => m.id), listOnce);
|
|
113
|
+
// The display name rides on the SAME snapshot as the capabilities: a
|
|
114
|
+
// resolution read is synchronous and must never await the catalog. Absent
|
|
115
|
+
// name (no record, or a record that states none) stays absent.
|
|
116
|
+
const names = new Map();
|
|
117
|
+
for (const [id, cat] of byId) {
|
|
118
|
+
const name = typeof cat.name === 'string' ? cat.name.trim() : '';
|
|
119
|
+
if (name)
|
|
120
|
+
names.set(id, name);
|
|
121
|
+
}
|
|
122
|
+
for (const model of models) {
|
|
123
|
+
const supported = modelSupportsEfforts(model.supportedReasoningEfforts, model.supportsReasoningEffort, model.reasoningDisableable);
|
|
124
|
+
const variants = (model.variants ?? []).map((v) => ({
|
|
125
|
+
id: `${model.id}-${v.id}`,
|
|
126
|
+
effort: v.reasoningEffort,
|
|
127
|
+
}));
|
|
128
|
+
capabilities[model.id] = {
|
|
129
|
+
...concreteCapabilities(byId.get(model.id), supported, model.defaultEffort),
|
|
130
|
+
...(variants.length > 0 ? { variants } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Virtual refs (auto + tier aliases) and combos: member-set envelope.
|
|
134
|
+
for (const alias of ['auto', ...TIER_LADDER]) {
|
|
135
|
+
const env = await tierAliasEnvelope(registry, listOnce, alias);
|
|
136
|
+
if (env.memberCount === 0)
|
|
137
|
+
continue;
|
|
138
|
+
capabilities[alias] = virtualCapabilities(env);
|
|
139
|
+
}
|
|
140
|
+
for (const combo of registry.getCombos()) {
|
|
141
|
+
if (combo.disabled === true)
|
|
142
|
+
continue;
|
|
143
|
+
const env = await comboEnvelope(registry, listOnce, combo);
|
|
144
|
+
if (env.memberCount === 0)
|
|
145
|
+
continue;
|
|
146
|
+
capabilities[combo.id] = virtualCapabilities(env);
|
|
147
|
+
}
|
|
148
|
+
return { catalog: { ...catalog, capabilities }, names };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Async-refresh snapshot: `catalog()` is a SYNC host seam called on the
|
|
152
|
+
* request path, so a registry change kicks a background rebuild and the
|
|
153
|
+
* previous snapshot keeps serving until it lands. The first call after boot
|
|
154
|
+
* answers with ids only (the pre-existing contract) — never a blocked request.
|
|
155
|
+
*/
|
|
156
|
+
export class GatewayCatalogProjection {
|
|
157
|
+
registry;
|
|
158
|
+
listCatalog;
|
|
159
|
+
snapshot;
|
|
160
|
+
names;
|
|
161
|
+
builtSignature = '';
|
|
162
|
+
inFlight;
|
|
163
|
+
constructor(registry, listCatalog) {
|
|
164
|
+
this.registry = registry;
|
|
165
|
+
this.listCatalog = listCatalog;
|
|
166
|
+
}
|
|
167
|
+
get() {
|
|
168
|
+
const signature = registrySignature(this.registry);
|
|
169
|
+
if (this.snapshot && this.builtSignature === signature)
|
|
170
|
+
return this.snapshot;
|
|
171
|
+
if (this.inFlight !== signature) {
|
|
172
|
+
this.inFlight = signature;
|
|
173
|
+
void project(this.registry, this.listCatalog)
|
|
174
|
+
.then((next) => {
|
|
175
|
+
// A rebuild for a stale signature must not overwrite a newer one.
|
|
176
|
+
if (this.inFlight !== signature)
|
|
177
|
+
return;
|
|
178
|
+
this.snapshot = next.catalog;
|
|
179
|
+
this.names = next.names;
|
|
180
|
+
this.builtSignature = signature;
|
|
181
|
+
})
|
|
182
|
+
.catch(() => {
|
|
183
|
+
// best effort — the ids-only shape keeps serving
|
|
184
|
+
})
|
|
185
|
+
.finally(() => {
|
|
186
|
+
if (this.inFlight === signature)
|
|
187
|
+
this.inFlight = undefined;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return this.snapshot ?? baseCatalog(this.registry);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Catalog display name for a gateway-visible id, read from the SAME
|
|
194
|
+
* snapshot as `get()`. Ensure-first: a caller that only ever resolves
|
|
195
|
+
* models still kicks the (best-effort) build. Undefined until the first
|
|
196
|
+
* build lands (or when the catalog states none) — never a guess.
|
|
197
|
+
*/
|
|
198
|
+
nameOf(id) {
|
|
199
|
+
this.get();
|
|
200
|
+
return this.names?.get(id);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PipelineOrchestrator } from '../pipeline/orchestrator.js';
|
|
2
|
-
import type { GatewayChatSink } from '../plugins/types.js';
|
|
2
|
+
import type { GatewayCatalog, GatewayChatSink, GatewayModelResolution } from '../plugins/types.js';
|
|
3
3
|
import type { ApiKeyConfig } from '../config/types.js';
|
|
4
4
|
/**
|
|
5
5
|
* In-process chat seam for client-gateway plugins (ADR-0017).
|
|
6
6
|
*
|
|
7
|
-
* `
|
|
7
|
+
* `startIngressProxy` wires the services once with the live orchestrator; a
|
|
8
8
|
* gateway then runs ONE canonical OpenAI-shaped completion through the SAME
|
|
9
9
|
* `dispatchSurface` pipeline as /v1/chat/completions — model resolution,
|
|
10
10
|
* tiers, breakers, captures all apply — and receives exactly the SSE frames
|
|
@@ -32,16 +32,12 @@ export interface GatewayChatRunOptions {
|
|
|
32
32
|
export interface GatewayChatServices {
|
|
33
33
|
/** One canonical chat completion; terminal discipline via the sink. */
|
|
34
34
|
run(body: Record<string, unknown>, sink: GatewayChatSink, signal: AbortSignal | undefined, opts?: GatewayChatRunOptions): Promise<void>;
|
|
35
|
-
/** Current routing surface for AvailableModels-style fabrication. */
|
|
36
|
-
catalog():
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
id: string;
|
|
40
|
-
label?: string;
|
|
41
|
-
}[];
|
|
42
|
-
};
|
|
35
|
+
/** Current routing surface (+ capability map) for AvailableModels-style fabrication. */
|
|
36
|
+
catalog(): GatewayCatalog;
|
|
37
|
+
/** Draw-free description of what an id addresses (see resolveModel). */
|
|
38
|
+
resolveModel?(modelId: string): GatewayModelResolution;
|
|
43
39
|
}
|
|
44
|
-
/** Wired once by
|
|
40
|
+
/** Wired once by ingress-proxy/index.ts (it holds the orchestrator). */
|
|
45
41
|
export declare function setGatewayChatServices(s: GatewayChatServices | undefined): void;
|
|
46
42
|
/** Lookup for the plugin-host SDK (undefined = core not booted yet). */
|
|
47
43
|
export declare function getGatewayChatServices(): GatewayChatServices | undefined;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { dispatchSurface } from './dispatch.js';
|
|
2
2
|
import { chatSurface } from './chat.js';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveModel } from '../providers/model-resolution.js';
|
|
4
|
+
import { GatewayCatalogProjection } from './gateway-catalog.js';
|
|
4
5
|
import { loadConfig } from '../config/index.js';
|
|
5
6
|
import { checkModelAccess, getModelAccessPolicy } from '../auth/model-access.js';
|
|
6
7
|
import { isApiKeyUsable } from '../auth/api-keys.js';
|
|
7
8
|
import { apiKeySubject, getRateLimiter } from '../ratelimit/rate-limiter.js';
|
|
8
9
|
import { recordRateLimitEvent } from '../ratelimit/event-log.js';
|
|
10
|
+
function explicitResolution(kind, model, rawModelId, factModelName) {
|
|
11
|
+
return {
|
|
12
|
+
kind,
|
|
13
|
+
rawModelId,
|
|
14
|
+
factModelId: model.id,
|
|
15
|
+
provider: model.provider,
|
|
16
|
+
...(model.wire ? { wire: model.wire } : {}),
|
|
17
|
+
...(factModelName ? { factModelName } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
9
20
|
let services;
|
|
10
|
-
/** Wired once by
|
|
21
|
+
/** Wired once by ingress-proxy/index.ts (it holds the orchestrator). */
|
|
11
22
|
export function setGatewayChatServices(s) {
|
|
12
23
|
services = s;
|
|
13
24
|
}
|
|
@@ -26,15 +37,41 @@ export function resolveGatewayKey(keyId, lookup = lookupConfiguredKey) {
|
|
|
26
37
|
}
|
|
27
38
|
/** Build the services over an orchestrator: dispatch + callback transport. */
|
|
28
39
|
export function buildGatewayChatServices(orchestrator, resolveKey = lookupConfiguredKey) {
|
|
40
|
+
// ONE projection per boot: the capability map is rebuilt in the background
|
|
41
|
+
// when the registry drifts, so the synchronous `catalog()` seam stays free
|
|
42
|
+
// of per-request aggregation.
|
|
43
|
+
const catalog = new GatewayCatalogProjection(orchestrator.getRegistry(), async () => (await import('../opencode/catalog/repository.js')).catalogRepository.list());
|
|
29
44
|
return {
|
|
30
|
-
catalog: () => (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
catalog: () => catalog.get(),
|
|
46
|
+
// Registry ladder plus the catalog name snapshot — no session, no
|
|
47
|
+
// selection, no cursor advance. This is the same ladder the chat dispatch
|
|
48
|
+
// will walk, so an explicit ref's physical model (and therefore its prompt
|
|
49
|
+
// family) is known up front; the display name is the last family signal
|
|
50
|
+
// when the id and upstream name are both opaque.
|
|
51
|
+
resolveModel: (modelId) => {
|
|
52
|
+
const resolved = resolveModel(modelId, orchestrator.getRegistry());
|
|
53
|
+
switch (resolved.kind) {
|
|
54
|
+
case 'registered':
|
|
55
|
+
return explicitResolution('registered', resolved.model, modelId, catalog.nameOf(resolved.model.id));
|
|
56
|
+
case 'legacy':
|
|
57
|
+
return explicitResolution('legacy', resolved.model, modelId, catalog.nameOf(resolved.model.id));
|
|
58
|
+
case 'variant':
|
|
59
|
+
return {
|
|
60
|
+
...explicitResolution('variant', resolved.model, modelId, catalog.nameOf(resolved.model.id)),
|
|
61
|
+
variantId: resolved.variantId,
|
|
62
|
+
};
|
|
63
|
+
case 'tier':
|
|
64
|
+
return { kind: 'tier', rawModelId: modelId };
|
|
65
|
+
case 'combo':
|
|
66
|
+
return { kind: 'combo', rawModelId: modelId };
|
|
67
|
+
case 'auto':
|
|
68
|
+
return { kind: 'auto', rawModelId: modelId };
|
|
69
|
+
case 'unresolved':
|
|
70
|
+
return { kind: 'unresolved', rawModelId: modelId };
|
|
71
|
+
case 'error':
|
|
72
|
+
return { kind: 'unknown', rawModelId: modelId, error: resolved.message };
|
|
73
|
+
}
|
|
74
|
+
},
|
|
38
75
|
run: async (body, sink, signal, opts) => {
|
|
39
76
|
const boundKeyId = opts?.keyId?.trim() ?? '';
|
|
40
77
|
const key = resolveGatewayKey(boundKeyId, resolveKey);
|
|
@@ -42,12 +79,13 @@ export function buildGatewayChatServices(orchestrator, resolveKey = lookupConfig
|
|
|
42
79
|
// No identity = no OCR routing. Vendor-native requests never reach this
|
|
43
80
|
// seam, so passthrough keeps working without a key; only our own
|
|
44
81
|
// inference is refused. This is the policy split: proxy admission is
|
|
45
|
-
// transport, model usage is
|
|
82
|
+
// transport (it carries no identity at all, ADR-0008 §3), model usage is
|
|
83
|
+
// keyed.
|
|
46
84
|
sink.onJson(401, {
|
|
47
85
|
error: {
|
|
48
86
|
message: boundKeyId
|
|
49
87
|
? `Bound API key '${boundKeyId}' is missing, disabled or expired — pick a valid key in Client Hub`
|
|
50
|
-
: 'OCR routing requires an API key:
|
|
88
|
+
: 'OCR routing requires an API key: bind one to this plugin in Client Hub (proxy admission carries no credential)',
|
|
51
89
|
type: 'invalid_request_error',
|
|
52
90
|
code: 'invalid_api_key',
|
|
53
91
|
},
|
|
@@ -11,7 +11,7 @@ import type { StreamRoutingFacts } from '../utils/stream-relay.js';
|
|
|
11
11
|
* wire (staged reply.header loop for non-stream, writeHead spread for SSE).
|
|
12
12
|
*
|
|
13
13
|
* NOTE on the `?? / ||` defaults: they are FROZEN contract, not style.
|
|
14
|
-
* Test stubs (
|
|
14
|
+
* Test stubs (ingress-proxy.test.ts and friends) return partial
|
|
15
15
|
* ExecutionResults, and the builder must apply safe defaults instead of
|
|
16
16
|
* throwing on missing optionals (contract §1.4, risk R-4).
|
|
17
17
|
*/
|
|
@@ -28,9 +28,11 @@ import type { StreamRoutingFacts } from '../utils/stream-relay.js';
|
|
|
28
28
|
* They expose the gateway-measured TTFT (process start → first forwarded
|
|
29
29
|
* chunk) and decode window (first chunk → stream end) so a client can
|
|
30
30
|
* compute the same decode-TPS the console shows. Buffered turns omit both.
|
|
31
|
-
* - X-OCR-Thinking-{Requested,Actual,Degraded}: only when
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* - X-OCR-Thinking-{Requested,Actual,Degraded}: only when there is something
|
|
32
|
+
* to report — the ask is not 'none', OR a 'none' ask was NOT served as
|
|
33
|
+
* 'none' (an always-think floor or a member effortMap raised it), so a
|
|
34
|
+
* served level is never silently hidden behind the ask. Lets the caller
|
|
35
|
+
* verify whether they got the level requested or were silently
|
|
34
36
|
* downgraded. The same record goes to non-stream and SSE wires, so the
|
|
35
37
|
* Thinking-* headers reach the stream too (unlike the pre-builder code,
|
|
36
38
|
* where the SSE spread omitted them).
|
|
@@ -10,7 +10,7 @@ import { buildOcrSummaryFrame } from '../utils/chat-sse.js';
|
|
|
10
10
|
* wire (staged reply.header loop for non-stream, writeHead spread for SSE).
|
|
11
11
|
*
|
|
12
12
|
* NOTE on the `?? / ||` defaults: they are FROZEN contract, not style.
|
|
13
|
-
* Test stubs (
|
|
13
|
+
* Test stubs (ingress-proxy.test.ts and friends) return partial
|
|
14
14
|
* ExecutionResults, and the builder must apply safe defaults instead of
|
|
15
15
|
* throwing on missing optionals (contract §1.4, risk R-4).
|
|
16
16
|
*/
|
|
@@ -27,9 +27,11 @@ import { buildOcrSummaryFrame } from '../utils/chat-sse.js';
|
|
|
27
27
|
* They expose the gateway-measured TTFT (process start → first forwarded
|
|
28
28
|
* chunk) and decode window (first chunk → stream end) so a client can
|
|
29
29
|
* compute the same decode-TPS the console shows. Buffered turns omit both.
|
|
30
|
-
* - X-OCR-Thinking-{Requested,Actual,Degraded}: only when
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* - X-OCR-Thinking-{Requested,Actual,Degraded}: only when there is something
|
|
31
|
+
* to report — the ask is not 'none', OR a 'none' ask was NOT served as
|
|
32
|
+
* 'none' (an always-think floor or a member effortMap raised it), so a
|
|
33
|
+
* served level is never silently hidden behind the ask. Lets the caller
|
|
34
|
+
* verify whether they got the level requested or were silently
|
|
33
35
|
* downgraded. The same record goes to non-stream and SSE wires, so the
|
|
34
36
|
* Thinking-* headers reach the stream too (unlike the pre-builder code,
|
|
35
37
|
* where the SSE spread omitted them).
|
|
@@ -76,9 +78,11 @@ export function buildChatOcrHeaders(result, fallbackModel) {
|
|
|
76
78
|
headers['X-OCR-TTFT-MS'] = result.ttftMs.toString();
|
|
77
79
|
if (result.genMs !== undefined)
|
|
78
80
|
headers['X-OCR-Gen-MS'] = result.genMs.toString();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const requestedEffort = result.requestedEffort;
|
|
82
|
+
const servedEffort = result.actualEffort ?? requestedEffort;
|
|
83
|
+
if (requestedEffort && (requestedEffort !== 'none' || (servedEffort && servedEffort !== 'none'))) {
|
|
84
|
+
headers['X-OCR-Thinking-Requested'] = requestedEffort;
|
|
85
|
+
headers['X-OCR-Thinking-Actual'] = servedEffort ?? requestedEffort;
|
|
82
86
|
headers['X-OCR-Thinking-Degraded'] = result.reasoningDegraded ? 'true' : 'false';
|
|
83
87
|
// ADR-0012: WHO authored the ask — 'client' or a gateway decision
|
|
84
88
|
// (decision layer / entry / @ocr directive / default). Emitted only when known;
|
|
@@ -23,7 +23,7 @@ export const systemoneSurface = {
|
|
|
23
23
|
routePath: '/v1/systemone',
|
|
24
24
|
/**
|
|
25
25
|
* Intentionally WIDER than routePath — by design. The MITM
|
|
26
|
-
*
|
|
26
|
+
* ingress-proxy leg must also claim System One-shaped decision traffic:
|
|
27
27
|
* TypeSafe Jev (api.typesafe.ai/v1/systemone) and the Alibaba Bailian
|
|
28
28
|
* compatible-mode decision endpoint both terminate in `/systemone`, and
|
|
29
29
|
* the gateway serves them over the intercepted leg. Detection is the
|
|
@@ -27,6 +27,17 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
27
27
|
let sseCtx;
|
|
28
28
|
// Set by the migrated close listener (see below) — the isClientGone signal.
|
|
29
29
|
let closed = false;
|
|
30
|
+
/**
|
|
31
|
+
* STICKY disconnect flag (ADR-0040). `closed` is only written when the close
|
|
32
|
+
* lands BEFORE the response finished, which is right for capture. But the
|
|
33
|
+
* snapshot plane asks "did the client ever go away during this turn?" AFTER the
|
|
34
|
+
* upstream drained — by then the socket is a normal closed socket and
|
|
35
|
+
* `destroyed` no longer distinguishes a peer that hung up mid-stream from one
|
|
36
|
+
* that received the whole answer. So latch THAT fact here, on the same event,
|
|
37
|
+
* and expose it separately: a turn whose client left mid-stream is `aborted`
|
|
38
|
+
* even though the upstream finished.
|
|
39
|
+
*/
|
|
40
|
+
let clientLeftMidStream = false;
|
|
30
41
|
// Stall deadline for the SSE leg, armed at beginSse (see
|
|
31
42
|
// `createClientLegWatchdog`): a peer that stops draining and never reports
|
|
32
43
|
// close would otherwise park the exchange — and its terminal capture event —
|
|
@@ -38,7 +49,7 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
38
49
|
// synthetic 499 (nginx convention for client-closed connection) and every
|
|
39
50
|
// request event stays paired. NB: Fastify's `onClose` application hook is
|
|
40
51
|
// server-shutdown, NOT this. On Bun 'close' never fires on premature
|
|
41
|
-
// disconnect (
|
|
52
|
+
// disconnect (ingress-proxy.test.ts:360 is the runtime spec), which is why
|
|
42
53
|
// the terminal sends ALSO consult isClientGone() below.
|
|
43
54
|
reply.raw.on('close', () => {
|
|
44
55
|
sseWatchdog?.stop();
|
|
@@ -48,6 +59,10 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
48
59
|
if (reply.raw.writableEnded)
|
|
49
60
|
return;
|
|
50
61
|
closed = true;
|
|
62
|
+
// Latch the mid-stream departure for the snapshot plane (ADR-0040). This is
|
|
63
|
+
// the Node-runtime path; on Bun the event does not fire, so the terminal
|
|
64
|
+
// sends also consult `isClientGone()` below — the only cross-runtime probe.
|
|
65
|
+
clientLeftMidStream = true;
|
|
51
66
|
const ctx = getClientExchangeContext(req);
|
|
52
67
|
if (ctx && !ctx.pending.responded && ctx.recorder.isEnabled()) {
|
|
53
68
|
emitClientResponse(ctx, {
|
|
@@ -58,8 +73,8 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
58
73
|
}
|
|
59
74
|
});
|
|
60
75
|
// Bun fires no reliable 'close'/'aborted' after the response is dead —
|
|
61
|
-
// the migrated listener covers Node; the
|
|
62
|
-
//
|
|
76
|
+
// the migrated listener covers Node; `isClientGone` is the only cross-runtime
|
|
77
|
+
// probe this transport can offer (used by the terminal sends).
|
|
63
78
|
const isClientGone = () => closed || reply.raw.destroyed || reply.raw.socket?.destroyed === true;
|
|
64
79
|
// Fastify's per-request pino child — the one error sink for this transport.
|
|
65
80
|
const logError = (err, message) => {
|
|
@@ -186,9 +201,14 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
186
201
|
appendClientResponseChunk(sseCtx, chunk);
|
|
187
202
|
}
|
|
188
203
|
sseWatchdog?.progress();
|
|
189
|
-
if (isClientGone())
|
|
204
|
+
if (isClientGone()) {
|
|
205
|
+
clientLeftMidStream = true;
|
|
190
206
|
return;
|
|
191
|
-
|
|
207
|
+
}
|
|
208
|
+
return writeWithBackpressure(reply.raw, chunk, (err) => {
|
|
209
|
+
clientLeftMidStream = true;
|
|
210
|
+
logError(err, 'Fastify writeSseChunk failed');
|
|
211
|
+
});
|
|
192
212
|
},
|
|
193
213
|
endSse: () => {
|
|
194
214
|
sseWatchdog?.stop();
|
|
@@ -248,6 +268,13 @@ export function createFastifyTransport(req, reply, orchestrator) {
|
|
|
248
268
|
});
|
|
249
269
|
},
|
|
250
270
|
isClientGone,
|
|
271
|
+
/**
|
|
272
|
+
* STICKY "did the client leave during this turn" (ADR-0040). True only when a
|
|
273
|
+
* runtime signal actually fired (Node `close`); on Bun nothing fires, so this
|
|
274
|
+
* stays false and the snapshot cannot tell an aborted turn from a completed
|
|
275
|
+
* one — a documented runtime limitation, not a silent hole.
|
|
276
|
+
*/
|
|
277
|
+
didClientLeave: () => clientLeftMidStream,
|
|
251
278
|
logError,
|
|
252
279
|
};
|
|
253
280
|
return transport;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type http from 'node:http';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TransportContext } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Raw node:http transport (the MITM
|
|
4
|
+
* Raw node:http transport (the MITM ingress-proxy leg) — the second
|
|
5
5
|
* implementation of the frozen TransportContext terminal-send discipline
|
|
6
6
|
* (contract §1.5). The interceptor reads the body, hands this transport to
|
|
7
7
|
* dispatchSurface, and the SAME chat pipelines then run byte-comparable on
|
|
@@ -40,13 +40,19 @@ import type { ProtocolSurface, TransportContext } from './types.js';
|
|
|
40
40
|
* one call site); production callers pass nothing and get the single-source default.
|
|
41
41
|
*/
|
|
42
42
|
export declare function readRequestBody(req: http.IncomingMessage, idleMs?: number): Promise<Buffer>;
|
|
43
|
+
/** The minimal envelope surface: enough to build a rejection body. Declared
|
|
44
|
+
* structurally so both a `ProtocolSurface` and the admin plane's adapter can
|
|
45
|
+
* be passed without either importing the other. */
|
|
46
|
+
export interface PreDispatchEnvelope {
|
|
47
|
+
errorBody(status: number, message: string, code?: string): unknown;
|
|
48
|
+
}
|
|
43
49
|
/**
|
|
44
50
|
* Pre-dispatch error (413 oversized body / 400 invalid JSON): sent through
|
|
45
51
|
* the surface's own error envelope BEFORE any orchestrator call, so no
|
|
46
52
|
* capture events exist on this path on either leg (contract §4: 400/403
|
|
47
53
|
* precede process). Adapters never throw — write failures are logged loud.
|
|
48
54
|
*/
|
|
49
|
-
export declare function sendPreDispatchError(res: http.ServerResponse, surface:
|
|
55
|
+
export declare function sendPreDispatchError(res: http.ServerResponse, surface: PreDispatchEnvelope, status: number, message: string, code?: string,
|
|
50
56
|
/** The rejection's negotiation headers (`Accept-Encoding` for a refused coding,
|
|
51
57
|
* `Accept` for a refused media type). Carried through so the MITM leg advertises
|
|
52
58
|
* exactly what the native leg does — a client that only reads the headers learns
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { appendClientResponseChunk, markClientResponseStreamStart, emitClientResponse, } from '../observability/http-exchange.js';
|
|
2
|
-
import { bodyLimitFor, payloadTooLarge, requestBodyTimeout } from './body-admission.js';
|
|
2
|
+
import { bodyLimitFor, payloadTooLarge, requestBodyTimeout, writeRefusalAnswer } from './body-admission.js';
|
|
3
3
|
import { REQUEST_BODY_IDLE_TIMEOUT_MS } from '../config/defaults.js';
|
|
4
4
|
import { createClientLegWatchdog, writeWithBackpressure } from './transport-backpressure.js';
|
|
5
5
|
/**
|
|
6
|
-
* Raw node:http transport (the MITM
|
|
6
|
+
* Raw node:http transport (the MITM ingress-proxy leg) — the second
|
|
7
7
|
* implementation of the frozen TransportContext terminal-send discipline
|
|
8
8
|
* (contract §1.5). The interceptor reads the body, hands this transport to
|
|
9
9
|
* dispatchSurface, and the SAME chat pipelines then run byte-comparable on
|
|
@@ -115,22 +115,9 @@ headers) {
|
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
try {
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
// envelope), so `connection: close` is spoken only on the h1 leg.
|
|
122
|
-
const isH2 = res.stream !== undefined;
|
|
123
|
-
res.writeHead(status, {
|
|
124
|
-
'content-type': 'application/json; charset=utf-8',
|
|
125
|
-
...(isH2 ? {} : { connection: 'close' }),
|
|
126
|
-
...(headers ?? {}),
|
|
127
|
-
});
|
|
128
|
-
res.end(serialized);
|
|
129
|
-
// The body was deliberately left unread, so this connection is not reusable.
|
|
130
|
-
// destroySoon() — never destroy() — flushes the answer first and then closes
|
|
131
|
-
// the transport; on the h2 leg it ends the affected stream, not the
|
|
132
|
-
// multiplexed session.
|
|
133
|
-
res.destroySoon?.();
|
|
118
|
+
// ONE writer for every refusal (see `writeRefusalAnswer`): answer first,
|
|
119
|
+
// declare `content-length`, then drain the refused body (bounded) and close.
|
|
120
|
+
writeRefusalAnswer(res, status, serialized, { headers });
|
|
134
121
|
}
|
|
135
122
|
catch (err) {
|
|
136
123
|
logWriteError(err, 'node-http pre-dispatch error write failed');
|
|
@@ -140,7 +127,7 @@ function logWriteError(err, message) {
|
|
|
140
127
|
// R-3: loud-not-silent. Bun's socket layer can surface write errors as
|
|
141
128
|
// 'ERR_STREAM_DESTROYED'-style throws on dead peers; they must reach the
|
|
142
129
|
// operator log, never an empty catch.
|
|
143
|
-
console.error(`[
|
|
130
|
+
console.error(`[ingress-proxy] ${message}`, err);
|
|
144
131
|
}
|
|
145
132
|
/**
|
|
146
133
|
* Build the MITM-leg transport. `captureEnabled` is the SURFACE capture
|
|
@@ -16,7 +16,7 @@ import type { ExecutionResult } from '../types/router.js';
|
|
|
16
16
|
* makeModelAccessGuard(registry)(req, reply, model); a denial
|
|
17
17
|
* has ALREADY been written as a 403 by the guard, callers only
|
|
18
18
|
* check the boolean and must NOT send another response.
|
|
19
|
-
* - 'exempt' — POLICY EXEMPTION (MITM
|
|
19
|
+
* - 'exempt' — POLICY EXEMPTION (MITM ingress-proxy leg): the tunnel peer is
|
|
20
20
|
* authenticated by the CONNECT/TLS layer, not an API key, so
|
|
21
21
|
* every model passes and the capture's inbound request headers
|
|
22
22
|
* carry no key identity. `keyName`/`policy` pin the empty view
|
|
@@ -80,12 +80,20 @@ export interface TransportContext {
|
|
|
80
80
|
endSse(): void;
|
|
81
81
|
/**
|
|
82
82
|
* Client-abort detection. Bun never fires req 'res''close'/'aborted'
|
|
83
|
-
* reliably after the body is read (
|
|
83
|
+
* reliably after the body is read (ingress-proxy.test.ts:360 documents the
|
|
84
84
|
* verified runtime behavior) — adapters combine their own close-flag with
|
|
85
85
|
* the socket's destroyed state; the pipeline uses this only as a fallback
|
|
86
86
|
* signal, the terminal send itself is what finalizes capture.
|
|
87
87
|
*/
|
|
88
88
|
isClientGone(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* STICKY "did the client leave during this turn" (ADR-0040). Unlike
|
|
91
|
+
* `isClientGone` — which reports the CURRENT socket state and is read at the
|
|
92
|
+
* terminal send — this must still answer YES after the upstream drained into a
|
|
93
|
+
* socket the peer abandoned, so an interrupted turn is recorded as `aborted`
|
|
94
|
+
* rather than `completed`. Optional: a transport with no such signal omits it.
|
|
95
|
+
*/
|
|
96
|
+
didClientLeave?(): boolean;
|
|
89
97
|
logError(err: unknown, message: string): void;
|
|
90
98
|
}
|
|
91
99
|
/**
|
|
@@ -203,7 +211,7 @@ export interface ChatSurface {
|
|
|
203
211
|
* conversion call, per the model's resolved wire — ADR-0008 §7;
|
|
204
212
|
* no purpose tag — unambiguous within its own turn). FinOps/trace stay
|
|
205
213
|
* excluded; the default-off path is
|
|
206
|
-
* pinned zero-event by
|
|
214
|
+
* pinned zero-event by ingress-proxy-systemone.test.ts.
|
|
207
215
|
*/
|
|
208
216
|
export interface DecisionSurface {
|
|
209
217
|
readonly wire: 'systemone';
|
|
@@ -52,7 +52,17 @@ function normalizeReplayedTrace(raw) {
|
|
|
52
52
|
delete fin.cachedPromptTokens;
|
|
53
53
|
}
|
|
54
54
|
delete fin.savedCostUsd;
|
|
55
|
-
|
|
55
|
+
// `costUsd` is OPTIONAL — absent means the price was unknown at request
|
|
56
|
+
// time, and every aggregate counts it as an unpriced turn. Coerce only a
|
|
57
|
+
// value that IS present: `Number(undefined) || 0` laundered an unpriced
|
|
58
|
+
// turn into a confident $0 the next time the process booted.
|
|
59
|
+
if (fin.costUsd !== undefined) {
|
|
60
|
+
const cost = Number(fin.costUsd);
|
|
61
|
+
if (Number.isFinite(cost))
|
|
62
|
+
fin.costUsd = cost;
|
|
63
|
+
else
|
|
64
|
+
delete fin.costUsd;
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
const req = record.request;
|
|
58
68
|
if (req && typeof req === 'object') {
|
|
@@ -86,6 +96,13 @@ async function tryOpenTraceStore(dir) {
|
|
|
86
96
|
// stores (each with its own handle), so contend politely and keep the
|
|
87
97
|
// schema switch atomic.
|
|
88
98
|
db.run('PRAGMA busy_timeout = 5000;');
|
|
99
|
+
// The write-through path fires once per completed request, so the default
|
|
100
|
+
// FULL (an fsync per commit) sits on the inference hot path. WAL + NORMAL
|
|
101
|
+
// keeps the file crash-consistent and only risks losing the most recent
|
|
102
|
+
// commits on power loss — acceptable for observability, which fails open
|
|
103
|
+
// by contract. `synchronous` is per-connection: every hot-path handle sets
|
|
104
|
+
// its own (see openFinOpsStore).
|
|
105
|
+
db.run('PRAGMA synchronous = NORMAL;');
|
|
89
106
|
const version = Number(db.query('PRAGMA user_version').get()?.user_version ?? 0);
|
|
90
107
|
// `user_version` is FILE-wide (SQLite has no per-table version): this store
|
|
91
108
|
// is its sole owner — every other store on the file only runs
|
|
@@ -307,6 +324,9 @@ export async function openFinOpsStore(dir) {
|
|
|
307
324
|
fs.mkdirSync(dir, { recursive: true });
|
|
308
325
|
db = new Database(path.join(dir, 'traces.db'), { create: true });
|
|
309
326
|
db.run('PRAGMA journal_mode = WAL;');
|
|
327
|
+
// Same hot-path rationale as tryOpenTraceStore: one counter transaction per
|
|
328
|
+
// completed request must not pay an fsync.
|
|
329
|
+
db.run('PRAGMA synchronous = NORMAL;');
|
|
310
330
|
db.run(`CREATE TABLE IF NOT EXISTS finops_totals (
|
|
311
331
|
key TEXT PRIMARY KEY,
|
|
312
332
|
value REAL NOT NULL
|