omnicell-router 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -7
- package/README.zh-CN.md +18 -5
- package/backend/dist/auth/api-keys.js +11 -0
- package/backend/dist/auth/key-models.d.ts +36 -0
- package/backend/dist/auth/key-models.js +99 -0
- package/backend/dist/capture/recorder.d.ts +4 -10
- package/backend/dist/capture/recorder.js +6 -58
- package/backend/dist/cli/clients/activity.js +2 -0
- package/backend/dist/cli/clients/base.d.ts +36 -11
- package/backend/dist/cli/clients/base.js +31 -15
- package/backend/dist/cli/clients/claude.d.ts +9 -0
- package/backend/dist/cli/clients/claude.js +6 -0
- package/backend/dist/cli/clients/codex.d.ts +78 -0
- package/backend/dist/cli/clients/codex.js +475 -57
- package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
- package/backend/dist/cli/clients/core-adapters.js +1 -1
- package/backend/dist/cli/clients/dsh.d.ts +8 -0
- package/backend/dist/cli/clients/dsh.js +5 -0
- package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
- package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
- package/backend/dist/cli/clients/grok.d.ts +15 -1
- package/backend/dist/cli/clients/grok.js +16 -2
- package/backend/dist/cli/clients/index.d.ts +13 -1
- package/backend/dist/cli/clients/index.js +97 -19
- package/backend/dist/cli/clients/kimi.d.ts +6 -0
- package/backend/dist/cli/clients/kimi.js +3 -0
- package/backend/dist/cli/clients/launcher.d.ts +1 -1
- package/backend/dist/cli/clients/model-meta.js +6 -3
- package/backend/dist/cli/clients/omp.d.ts +6 -0
- package/backend/dist/cli/clients/omp.js +3 -0
- package/backend/dist/cli/clients/openclaw.d.ts +6 -0
- package/backend/dist/cli/clients/openclaw.js +3 -0
- package/backend/dist/cli/clients/opencode.d.ts +8 -0
- package/backend/dist/cli/clients/opencode.js +8 -2
- package/backend/dist/cli/clients/pi.d.ts +6 -0
- package/backend/dist/cli/clients/pi.js +3 -0
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/update-check.d.ts +37 -0
- package/backend/dist/cli/clients/update-check.js +309 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
- package/backend/dist/cli/clients/workbuddy.js +66 -0
- package/backend/dist/cli/index.js +5 -4
- package/backend/dist/cli/paths.js +8 -0
- package/backend/dist/cli/types.d.ts +101 -16
- package/backend/dist/config/comments-en.js +34 -25
- package/backend/dist/config/comments-zh.js +33 -24
- package/backend/dist/config/defaults.d.ts +280 -22
- package/backend/dist/config/defaults.js +279 -21
- package/backend/dist/config/env.d.ts +10 -0
- package/backend/dist/config/env.js +3 -2
- package/backend/dist/config/index.d.ts +22 -1
- package/backend/dist/config/index.js +218 -43
- package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
- package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
- package/backend/dist/config/migrations/v10-to-v11.js +43 -0
- package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
- package/backend/dist/config/migrations/v4-to-v5.js +42 -0
- package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
- package/backend/dist/config/migrations/v5-to-v6.js +29 -0
- package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
- package/backend/dist/config/migrations/v6-to-v7.js +97 -0
- package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
- package/backend/dist/config/migrations/v7-to-v8.js +43 -0
- package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
- package/backend/dist/config/migrations/v8-to-v9.js +43 -0
- package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
- package/backend/dist/config/migrations/v9-to-v10.js +71 -0
- package/backend/dist/config/runtime.js +1 -1
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +18 -4
- package/backend/dist/config/types.d.ts +221 -41
- package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
- package/backend/dist/egress-proxy/asset-download.js +420 -0
- package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
- package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
- package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
- package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
- package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
- package/backend/dist/egress-proxy/mihomo-client.js +308 -0
- package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
- package/backend/dist/egress-proxy/mihomo-config.js +161 -0
- package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
- package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
- package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
- package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
- package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
- package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
- package/backend/dist/forward-proxy/egress.d.ts +50 -11
- package/backend/dist/forward-proxy/egress.js +63 -17
- package/backend/dist/forward-proxy/h2-forward.js +42 -15
- package/backend/dist/forward-proxy/index.d.ts +11 -8
- package/backend/dist/forward-proxy/index.js +27 -60
- package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
- package/backend/dist/forward-proxy/interceptor.js +4 -4
- package/backend/dist/forward-proxy/relay.js +3 -3
- package/backend/dist/forward-proxy/rules.d.ts +4 -4
- package/backend/dist/forward-proxy/rules.js +25 -4
- package/backend/dist/forward-proxy/server.d.ts +12 -16
- package/backend/dist/forward-proxy/server.js +237 -171
- package/backend/dist/harness/host/hosts.js +3 -2
- package/backend/dist/index.js +59 -19
- package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
- package/backend/dist/ingress-proxy/access-log.js +774 -0
- package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
- package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
- package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
- package/backend/dist/ingress-proxy/ca-trust.js +315 -0
- package/backend/dist/ingress-proxy/ca.d.ts +104 -0
- package/backend/dist/ingress-proxy/ca.js +273 -0
- package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
- package/backend/dist/ingress-proxy/data-dir.js +45 -0
- package/backend/dist/ingress-proxy/egress.d.ts +151 -0
- package/backend/dist/ingress-proxy/egress.js +364 -0
- package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
- package/backend/dist/ingress-proxy/h2-forward.js +561 -0
- package/backend/dist/ingress-proxy/index.d.ts +24 -0
- package/backend/dist/ingress-proxy/index.js +144 -0
- package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
- package/backend/dist/ingress-proxy/interceptor.js +52 -0
- package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
- package/backend/dist/ingress-proxy/relay.d.ts +54 -0
- package/backend/dist/ingress-proxy/relay.js +188 -0
- package/backend/dist/ingress-proxy/rules.d.ts +195 -0
- package/backend/dist/ingress-proxy/rules.js +348 -0
- package/backend/dist/ingress-proxy/server.d.ts +153 -0
- package/backend/dist/ingress-proxy/server.js +2065 -0
- package/backend/dist/ingress-proxy/sni.d.ts +35 -0
- package/backend/dist/ingress-proxy/sni.js +124 -0
- package/backend/dist/ingress-proxy/status.d.ts +32 -0
- package/backend/dist/ingress-proxy/status.js +15 -0
- package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
- package/backend/dist/ingress-proxy/system-proxy.js +481 -0
- package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
- package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
- package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
- package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
- package/backend/dist/ingress-proxy/traffic-files.js +10 -0
- package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
- package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
- package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
- package/backend/dist/ingress-proxy/ws-frames.js +153 -0
- package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
- package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
- package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
- package/backend/dist/ir/adapters/google-gemini.js +5 -2
- package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
- package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
- package/backend/dist/ir/adapters/openai-chat.js +50 -6
- package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
- package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
- package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
- package/backend/dist/ir/adapters/openai-responses.d.ts +92 -1
- package/backend/dist/ir/adapters/openai-responses.js +163 -12
- package/backend/dist/ir/capabilities.js +4 -0
- package/backend/dist/ir/media.d.ts +20 -0
- package/backend/dist/ir/media.js +41 -0
- package/backend/dist/ir/tool-identity.d.ts +35 -0
- package/backend/dist/ir/tool-identity.js +40 -0
- package/backend/dist/ir/types.d.ts +9 -1
- package/backend/dist/ir/validate.d.ts +24 -0
- package/backend/dist/ir/validate.js +113 -63
- package/backend/dist/local/build-jobs.d.ts +66 -0
- package/backend/dist/local/build-jobs.js +243 -0
- package/backend/dist/local/detect.d.ts +32 -0
- package/backend/dist/local/detect.js +145 -0
- package/backend/dist/local/draft-match.d.ts +58 -0
- package/backend/dist/local/draft-match.js +124 -0
- package/backend/dist/local/engine-runtime.d.ts +522 -0
- package/backend/dist/local/engine-runtime.js +1 -0
- package/backend/dist/local/engines.d.ts +241 -0
- package/backend/dist/local/engines.js +651 -0
- package/backend/dist/local/gguf.d.ts +35 -0
- package/backend/dist/local/gguf.js +314 -0
- package/backend/dist/local/hf.d.ts +120 -0
- package/backend/dist/local/hf.js +304 -0
- package/backend/dist/local/install.d.ts +90 -0
- package/backend/dist/local/install.js +421 -0
- package/backend/dist/local/llamacpp.d.ts +55 -0
- package/backend/dist/local/llamacpp.js +177 -0
- package/backend/dist/local/local-provider.d.ts +81 -0
- package/backend/dist/local/local-provider.js +301 -0
- package/backend/dist/local/machine-stats.d.ts +87 -0
- package/backend/dist/local/machine-stats.js +332 -0
- package/backend/dist/local/model-store.d.ts +347 -0
- package/backend/dist/local/model-store.js +1215 -0
- package/backend/dist/local/part-sweep.d.ts +32 -0
- package/backend/dist/local/part-sweep.js +156 -0
- package/backend/dist/local/plan.d.ts +65 -0
- package/backend/dist/local/plan.js +146 -0
- package/backend/dist/local/resources.d.ts +49 -0
- package/backend/dist/local/resources.js +64 -0
- package/backend/dist/local/run-stats.d.ts +95 -0
- package/backend/dist/local/run-stats.js +195 -0
- package/backend/dist/local/runner.d.ts +235 -0
- package/backend/dist/local/runner.js +1392 -0
- package/backend/dist/local/settings.d.ts +79 -0
- package/backend/dist/local/settings.js +180 -0
- package/backend/dist/local/strata-catalog.d.ts +30 -0
- package/backend/dist/local/strata-catalog.js +511 -0
- package/backend/dist/local/strata-drafting.d.ts +46 -0
- package/backend/dist/local/strata-drafting.js +265 -0
- package/backend/dist/local/strata.d.ts +278 -0
- package/backend/dist/local/strata.js +1392 -0
- package/backend/dist/local/tar.d.ts +20 -0
- package/backend/dist/local/tar.js +367 -0
- package/backend/dist/local/transport.d.ts +35 -0
- package/backend/dist/local/transport.js +89 -0
- package/backend/dist/local/tune.d.ts +58 -0
- package/backend/dist/local/tune.js +324 -0
- package/backend/dist/observability/http-exchange.d.ts +2 -2
- package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
- package/backend/dist/opencode/catalog/auto-pull.js +284 -77
- package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
- package/backend/dist/opencode/catalog/ocr-store.js +4 -2
- package/backend/dist/opencode/catalog/overrides-store.d.ts +15 -4
- package/backend/dist/opencode/catalog/overrides-store.js +28 -19
- package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
- package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
- package/backend/dist/opencode/catalog/repository.js +28 -5
- package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
- package/backend/dist/opencode/catalog/sources/models-dev.js +42 -14
- package/backend/dist/opencode/catalog/types.d.ts +42 -12
- package/backend/dist/opencode/catalog/types.js +38 -1
- package/backend/dist/opencode/credentials/def-materialize.js +27 -21
- package/backend/dist/opencode/credentials/ocr-store.js +11 -2
- package/backend/dist/opencode/credentials/sync.js +12 -3
- package/backend/dist/opencode/credentials/types.d.ts +31 -4
- package/backend/dist/opencode/credentials/types.js +25 -0
- package/backend/dist/opencode/migrate/engine.d.ts +20 -0
- package/backend/dist/opencode/migrate/engine.js +71 -0
- package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
- package/backend/dist/opencode/migrate/migrator.js +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
- package/backend/dist/opencode/probe.d.ts +21 -4
- package/backend/dist/opencode/probe.js +34 -10
- package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
- package/backend/dist/opencode/provider-def-adapters.js +43 -27
- package/backend/dist/opencode/provider-defs.d.ts +10 -16
- package/backend/dist/opencode/provider-defs.js +45 -45
- package/backend/dist/opencode/user-config.d.ts +23 -26
- package/backend/dist/opencode/user-config.js +95 -77
- package/backend/dist/pipeline/directives.d.ts +9 -4
- package/backend/dist/pipeline/directives.js +14 -10
- package/backend/dist/pipeline/orchestrator.d.ts +42 -13
- package/backend/dist/pipeline/orchestrator.js +514 -172
- package/backend/dist/plugins/builtin/model-gateway.js +38 -12
- package/backend/dist/plugins/environment-ack.d.ts +51 -0
- package/backend/dist/plugins/environment-ack.js +81 -0
- package/backend/dist/plugins/gateways.d.ts +6 -6
- package/backend/dist/plugins/gateways.js +2 -2
- package/backend/dist/plugins/host.d.ts +100 -16
- package/backend/dist/plugins/host.js +637 -99
- package/backend/dist/plugins/install-run.d.ts +27 -0
- package/backend/dist/plugins/install-run.js +99 -0
- package/backend/dist/plugins/manifest.d.ts +84 -32
- package/backend/dist/plugins/manifest.js +149 -45
- package/backend/dist/plugins/market-install.d.ts +18 -0
- package/backend/dist/plugins/market-install.js +111 -0
- package/backend/dist/plugins/market-source.d.ts +100 -0
- package/backend/dist/plugins/market-source.js +449 -0
- package/backend/dist/plugins/market-updates.d.ts +70 -0
- package/backend/dist/plugins/market-updates.js +97 -0
- package/backend/dist/plugins/market.d.ts +677 -0
- package/backend/dist/plugins/market.js +2113 -0
- package/backend/dist/plugins/source-index.d.ts +155 -0
- package/backend/dist/plugins/source-index.js +217 -0
- package/backend/dist/plugins/types.d.ts +402 -37
- package/backend/dist/projects/worktrees.d.ts +88 -0
- package/backend/dist/projects/worktrees.js +220 -0
- package/backend/dist/providers/boot-direct.d.ts +41 -7
- package/backend/dist/providers/boot-direct.js +284 -44
- package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
- package/backend/dist/providers/dial-wire.d.ts +17 -0
- package/backend/dist/providers/dial-wire.js +49 -0
- package/backend/dist/providers/executors/dispatch.d.ts +17 -7
- package/backend/dist/providers/executors/dispatch.js +28 -9
- package/backend/dist/providers/executors/openai-chat.js +14 -2
- package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
- package/backend/dist/providers/executors/plugin-adapter.js +59 -3
- package/backend/dist/providers/member-match.d.ts +32 -9
- package/backend/dist/providers/member-match.js +65 -21
- package/backend/dist/providers/model-resolution.d.ts +62 -0
- package/backend/dist/providers/model-resolution.js +62 -0
- package/backend/dist/providers/price-order.d.ts +51 -0
- package/backend/dist/providers/price-order.js +54 -0
- package/backend/dist/providers/protocols-field.d.ts +24 -0
- package/backend/dist/providers/protocols-field.js +66 -0
- package/backend/dist/providers/provider-takedown.d.ts +5 -2
- package/backend/dist/providers/registry.d.ts +87 -26
- package/backend/dist/providers/registry.js +232 -121
- package/backend/dist/providers/selection.d.ts +91 -0
- package/backend/dist/providers/selection.js +158 -0
- package/backend/dist/providers/virtual-meta.d.ts +33 -2
- package/backend/dist/providers/virtual-meta.js +74 -18
- package/backend/dist/quota/cli-login.d.ts +25 -4
- package/backend/dist/quota/cli-login.js +38 -6
- package/backend/dist/quota/coverage-generation.d.ts +24 -0
- package/backend/dist/quota/coverage-generation.js +29 -0
- package/backend/dist/quota/declarations.js +8 -4
- package/backend/dist/quota/engine.js +2 -2
- package/backend/dist/quota/prober.d.ts +43 -2
- package/backend/dist/quota/prober.js +97 -22
- package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
- package/backend/dist/resilience/error-classifier.js +29 -0
- package/backend/dist/router/index.d.ts +1 -1
- package/backend/dist/router/index.js +17 -1
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +2 -2
- package/backend/dist/routes/console.js +1043 -405
- package/backend/dist/routes/environments.js +1 -1
- package/backend/dist/routes/local-models.d.ts +2 -0
- package/backend/dist/routes/local-models.js +1414 -0
- package/backend/dist/routes/mihomo.d.ts +2 -2
- package/backend/dist/routes/mihomo.js +20 -11
- package/backend/dist/routes/projects.js +121 -0
- package/backend/dist/server.js +409 -15
- package/backend/dist/session/session-manager.d.ts +42 -5
- package/backend/dist/session/session-manager.js +64 -11
- package/backend/dist/session/session-row.d.ts +29 -8
- package/backend/dist/session/session-row.js +18 -13
- package/backend/dist/snapshot/bundle.d.ts +40 -0
- package/backend/dist/snapshot/bundle.js +177 -0
- package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
- package/backend/dist/snapshot/handoff/compress.js +77 -0
- package/backend/dist/snapshot/handoff/index.d.ts +119 -0
- package/backend/dist/snapshot/handoff/index.js +160 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
- package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
- package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
- package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
- package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
- package/backend/dist/snapshot/handoff/summarize.js +118 -0
- package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
- package/backend/dist/snapshot/handoff/transcript.js +167 -0
- package/backend/dist/snapshot/media-fs.d.ts +10 -0
- package/backend/dist/snapshot/media-fs.js +50 -0
- package/backend/dist/snapshot/media.d.ts +32 -0
- package/backend/dist/snapshot/media.js +87 -0
- package/backend/dist/snapshot/store.d.ts +226 -0
- package/backend/dist/snapshot/store.js +887 -0
- package/backend/dist/snapshot/tree.d.ts +112 -0
- package/backend/dist/snapshot/tree.js +207 -0
- package/backend/dist/snapshot/types.d.ts +212 -0
- package/backend/dist/snapshot/types.js +14 -0
- package/backend/dist/snapshot/view.d.ts +19 -0
- package/backend/dist/snapshot/view.js +57 -0
- package/backend/dist/snapshot/write-worker.d.ts +67 -0
- package/backend/dist/snapshot/write-worker.js +129 -0
- package/backend/dist/surfaces/anthropic.js +4 -1
- package/backend/dist/surfaces/body-admission.d.ts +344 -0
- package/backend/dist/surfaces/body-admission.js +818 -0
- package/backend/dist/surfaces/chat-pipeline.js +8 -0
- package/backend/dist/surfaces/decision-pipeline.js +10 -7
- package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
- package/backend/dist/surfaces/gateway-catalog.js +202 -0
- package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
- package/backend/dist/surfaces/gateway-chat.js +50 -12
- package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
- package/backend/dist/surfaces/ocr-headers.js +11 -7
- package/backend/dist/surfaces/systemone.js +1 -1
- package/backend/dist/surfaces/transport-fastify.js +32 -5
- package/backend/dist/surfaces/transport-node-http.d.ts +51 -6
- package/backend/dist/surfaces/transport-node-http.js +76 -16
- package/backend/dist/surfaces/types.d.ts +11 -3
- package/backend/dist/trace/persist.js +21 -1
- package/backend/dist/trace/tracker.d.ts +35 -3
- package/backend/dist/trace/tracker.js +23 -0
- package/backend/dist/types/openai.d.ts +8 -0
- package/backend/dist/types/router.d.ts +17 -6
- package/backend/dist/types/router.js +14 -2
- package/backend/dist/utils/client-families.d.ts +66 -0
- package/backend/dist/utils/client-families.js +127 -0
- package/backend/dist/utils/event-ring.d.ts +1 -1
- package/backend/dist/utils/event-ring.js +1 -1
- package/backend/dist/utils/proxy-node.js +1 -1
- package/backend/dist/utils/proxy.d.ts +135 -11
- package/backend/dist/utils/proxy.js +144 -29
- package/backend/dist/utils/run-command.d.ts +21 -1
- package/backend/dist/utils/run-command.js +64 -4
- package/backend/dist/utils/server-liveness.d.ts +28 -0
- package/backend/dist/utils/server-liveness.js +32 -0
- package/backend/dist/utils/session-file.d.ts +28 -0
- package/backend/dist/utils/session-file.js +34 -0
- package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
- package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
- package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
- package/frontend/dist/assets/{index-DxZ9MHKB.css → index-CqDSOPQ0.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +3 -1
- package/frontend/dist/assets/index-55VVwfFQ.js +0 -1521
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type SnapshotTurn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Snapshot write WORKER — the per-request assembly that used to run on the
|
|
4
|
+
* gateway's main thread now runs here.
|
|
5
|
+
*
|
|
6
|
+
* What it takes off the loop: base64 decode + sha256 for every inline image,
|
|
7
|
+
* the content-addressed media write (`writeFileSync` + `renameWithRetry`,
|
|
8
|
+
* which busy-waits through Windows AV contention), `JSON.stringify` of the
|
|
9
|
+
* whole turn, and `Buffer.byteLength`. For a 4 MB agent transcript those were
|
|
10
|
+
* 4–30 ms of event-loop time per completed request — paid AFTER the client's
|
|
11
|
+
* last chunk, so it stalled every other in-flight stream instead of that one.
|
|
12
|
+
*
|
|
13
|
+
* Ordering: the worker writes the media payloads BEFORE the transcript line
|
|
14
|
+
* lands (a line must never reference a payload that is not durable yet), and
|
|
15
|
+
* asks the main thread to register the digests first — `pendingMedia` lives
|
|
16
|
+
* there because it guards the hourly sweep, which also lives there. Turns and
|
|
17
|
+
* flush calls are processed strictly in arrival order, so `flush()` observing
|
|
18
|
+
* a `flushed` reply means every turn posted before it is on disk.
|
|
19
|
+
*/
|
|
20
|
+
export interface SnapshotWorkerConfig {
|
|
21
|
+
type: 'config';
|
|
22
|
+
rootDir: string;
|
|
23
|
+
maxTurnBytes: number;
|
|
24
|
+
}
|
|
25
|
+
export interface SnapshotWorkerTurn {
|
|
26
|
+
type: 'turn';
|
|
27
|
+
id: number;
|
|
28
|
+
sessionId: string;
|
|
29
|
+
file: string;
|
|
30
|
+
turn: SnapshotTurn;
|
|
31
|
+
}
|
|
32
|
+
export interface SnapshotWorkerFlush {
|
|
33
|
+
type: 'flush';
|
|
34
|
+
id: number;
|
|
35
|
+
}
|
|
36
|
+
/** Main -> worker: the digests are registered, the payloads may be referenced. */
|
|
37
|
+
export interface SnapshotWorkerMediaAck {
|
|
38
|
+
type: 'media-ack';
|
|
39
|
+
id: number;
|
|
40
|
+
}
|
|
41
|
+
export type SnapshotWorkerRequest = SnapshotWorkerConfig | SnapshotWorkerTurn | SnapshotWorkerFlush | SnapshotWorkerMediaAck;
|
|
42
|
+
export interface SnapshotWorkerMedia {
|
|
43
|
+
type: 'media';
|
|
44
|
+
id: number;
|
|
45
|
+
keys: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface SnapshotWorkerWritten {
|
|
48
|
+
type: 'written';
|
|
49
|
+
id: number;
|
|
50
|
+
}
|
|
51
|
+
export interface SnapshotWorkerHalt {
|
|
52
|
+
type: 'halt';
|
|
53
|
+
id: number;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
refusedBytes: number;
|
|
56
|
+
limitBytes: number;
|
|
57
|
+
}
|
|
58
|
+
export interface SnapshotWorkerFailed {
|
|
59
|
+
type: 'failed';
|
|
60
|
+
id: number;
|
|
61
|
+
message: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SnapshotWorkerFlushed {
|
|
64
|
+
type: 'flushed';
|
|
65
|
+
id: number;
|
|
66
|
+
}
|
|
67
|
+
export type SnapshotWorkerResponse = SnapshotWorkerMedia | SnapshotWorkerWritten | SnapshotWorkerHalt | SnapshotWorkerFailed | SnapshotWorkerFlushed;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isMainThread, parentPort } from 'node:worker_threads';
|
|
4
|
+
import { ensureDirSync, storeMediaPayload } from './media-fs.js';
|
|
5
|
+
import { offloadInputMedia, offloadOutputMedia } from './media.js';
|
|
6
|
+
import { SNAPSHOT_SCHEMA } from './types.js';
|
|
7
|
+
let rootDir = '';
|
|
8
|
+
let maxTurnBytes = Number.POSITIVE_INFINITY;
|
|
9
|
+
const halted = new Set();
|
|
10
|
+
const mediaAcks = new Map();
|
|
11
|
+
function post(message) {
|
|
12
|
+
parentPort?.postMessage(message);
|
|
13
|
+
}
|
|
14
|
+
function appendMarker(file, turn, refusedBytes) {
|
|
15
|
+
const marker = {
|
|
16
|
+
schema: SNAPSHOT_SCHEMA,
|
|
17
|
+
kind: 'incomplete',
|
|
18
|
+
reason: 'turn-cap',
|
|
19
|
+
turnIndex: turn.turnIndex,
|
|
20
|
+
requestId: turn.requestId,
|
|
21
|
+
ts: turn.ts,
|
|
22
|
+
refusedBytes,
|
|
23
|
+
limitBytes: maxTurnBytes,
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
ensureDirSync(path.dirname(file));
|
|
27
|
+
fs.appendFileSync(file, JSON.stringify(marker) + '\n', 'utf8');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Already halted in memory; the marker is best-effort.
|
|
31
|
+
}
|
|
32
|
+
console.warn(`[snapshot] session ${turn.sessionId} halted (turn-cap): ` +
|
|
33
|
+
`turn ${turn.turnIndex ?? 'none'} needs ${refusedBytes} bytes, limit ${maxTurnBytes} — export will refuse`);
|
|
34
|
+
}
|
|
35
|
+
async function handleTurn(message) {
|
|
36
|
+
const { id, file, turn } = message;
|
|
37
|
+
if (halted.has(message.sessionId)) {
|
|
38
|
+
post({ type: 'written', id });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Pass 1 — PROBE: a sink that returns false keeps `media.ts` from rewriting
|
|
42
|
+
// the payload in place, so this pass only discovers digests. They are
|
|
43
|
+
// registered on the main thread BEFORE any payload file exists, which is
|
|
44
|
+
// what makes the sweep guard airtight for the whole media-write window.
|
|
45
|
+
const probed = new Set();
|
|
46
|
+
const probe = (_raw, sha, ext) => {
|
|
47
|
+
probed.add(`${sha}.${ext}`);
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
offloadInputMedia(turn.request.input, probe);
|
|
51
|
+
offloadOutputMedia(turn.response.output, probe);
|
|
52
|
+
if (probed.size) {
|
|
53
|
+
post({ type: 'media', id, keys: [...probed] });
|
|
54
|
+
await new Promise((resolve) => mediaAcks.set(id, resolve));
|
|
55
|
+
}
|
|
56
|
+
// Pass 2 — OFFLOAD: writes the payloads and rewrites the sources in place,
|
|
57
|
+
// exactly as the inline path does (a failed write keeps the inline bytes).
|
|
58
|
+
const media = {
|
|
59
|
+
...offloadInputMedia(turn.request.input, (raw, sha, ext) => storeMediaPayload(rootDir, raw, sha, ext)).entries,
|
|
60
|
+
...offloadOutputMedia(turn.response.output, (raw, sha, ext) => storeMediaPayload(rootDir, raw, sha, ext)).entries,
|
|
61
|
+
};
|
|
62
|
+
if (Object.keys(media).length)
|
|
63
|
+
turn.media = media;
|
|
64
|
+
let line;
|
|
65
|
+
let bytes;
|
|
66
|
+
try {
|
|
67
|
+
line = JSON.stringify(turn) + '\n';
|
|
68
|
+
bytes = Buffer.byteLength(line, 'utf8');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
post({ type: 'failed', id, message: err.message });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (bytes > maxTurnBytes) {
|
|
75
|
+
// Too big to hand over faithfully; halt the session instead of storing a
|
|
76
|
+
// giant line (ADR-0038 §4).
|
|
77
|
+
halted.add(message.sessionId);
|
|
78
|
+
appendMarker(file, turn, bytes);
|
|
79
|
+
post({ type: 'halt', id, sessionId: message.sessionId, refusedBytes: bytes, limitBytes: maxTurnBytes });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
ensureDirSync(path.dirname(file));
|
|
84
|
+
fs.appendFileSync(file, line, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
post({ type: 'failed', id, message: err.message });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
post({ type: 'written', id });
|
|
91
|
+
}
|
|
92
|
+
const queue = [];
|
|
93
|
+
let pumping = false;
|
|
94
|
+
async function pump() {
|
|
95
|
+
if (pumping)
|
|
96
|
+
return;
|
|
97
|
+
pumping = true;
|
|
98
|
+
while (queue.length) {
|
|
99
|
+
const message = queue.shift();
|
|
100
|
+
if (message.type === 'media-ack') {
|
|
101
|
+
// Answered inline, never queued; kept here for exhaustiveness.
|
|
102
|
+
mediaAcks.get(message.id)?.();
|
|
103
|
+
mediaAcks.delete(message.id);
|
|
104
|
+
}
|
|
105
|
+
else if (message.type === 'config') {
|
|
106
|
+
rootDir = message.rootDir;
|
|
107
|
+
maxTurnBytes = message.maxTurnBytes;
|
|
108
|
+
}
|
|
109
|
+
else if (message.type === 'flush') {
|
|
110
|
+
post({ type: 'flushed', id: message.id });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
await handleTurn(message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
pumping = false;
|
|
117
|
+
}
|
|
118
|
+
if (!isMainThread && parentPort) {
|
|
119
|
+
parentPort.on('message', (message) => {
|
|
120
|
+
if (message.type === 'media-ack') {
|
|
121
|
+
// Resolve outside the queue: the queue is parked awaiting this exact ack.
|
|
122
|
+
mediaAcks.get(message.id)?.();
|
|
123
|
+
mediaAcks.delete(message.id);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
queue.push(message);
|
|
127
|
+
void pump();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
@@ -84,7 +84,10 @@ function anthropicErrorBody(status, message, code) {
|
|
|
84
84
|
return {
|
|
85
85
|
type: 'error',
|
|
86
86
|
error: {
|
|
87
|
-
type
|
|
87
|
+
// Anthropic's own error-type table gives 413 a dedicated type
|
|
88
|
+
// (`request_too_large`); folding it into `invalid_request_error` would
|
|
89
|
+
// tell a Claude Code client to fix its request shape rather than its size.
|
|
90
|
+
type: status >= 500 ? 'api_error' : status === 413 ? 'request_too_large' : 'invalid_request_error',
|
|
88
91
|
message,
|
|
89
92
|
...(code ? { code } : {}),
|
|
90
93
|
},
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type http from 'node:http';
|
|
3
|
+
import type { FastifyError, FastifyReply, FastifyRequest, RouteShorthandOptions } from 'fastify';
|
|
4
|
+
import type { BodyLimitsConfig } from '../config/types.js';
|
|
5
|
+
/** Bytes per MiB — declared once so no consumer writes `1024 * 1024` inline. */
|
|
6
|
+
export declare const BYTES_PER_MIB: number;
|
|
7
|
+
/** Rejection classes this module can produce. `code` is the machine-readable
|
|
8
|
+
* half of the envelope and is stable API; the message text is not. */
|
|
9
|
+
export type BodyAdmissionCode = 'payload_too_large' | 'unsupported_content_encoding' | 'unsupported_media_type' | 'invalid_json_body' | 'request_body_timeout' | 'invalid_content_length';
|
|
10
|
+
/**
|
|
11
|
+
* A body that will not be admitted. It carries its own HTTP status and surface
|
|
12
|
+
* `code` so BOTH legs answer identically: the Fastify route `errorHandler` reads
|
|
13
|
+
* `statusCode`/`code` off the error, the node-http adapter passes the same pair
|
|
14
|
+
* to `sendPreDispatchError`. Neither leg keeps a private message template.
|
|
15
|
+
*
|
|
16
|
+
* `headers` carries the negotiation headers RFC 9110 tells a rejecting server it
|
|
17
|
+
* MAY/CAN send (see ACCEPT_ENCODING_ADVERTISEMENT / ACCEPT_MEDIA_ADVERTISEMENT):
|
|
18
|
+
* they ride on the error, not on the senders, so an admission refusal answers them
|
|
19
|
+
* on both legs and no other 4xx accidentally grows them.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BodyAdmissionError extends Error {
|
|
22
|
+
readonly statusCode: number;
|
|
23
|
+
readonly code: BodyAdmissionCode;
|
|
24
|
+
readonly headers: Readonly<Record<string, string>> | undefined;
|
|
25
|
+
constructor(statusCode: number, code: BodyAdmissionCode, message: string, headers?: Record<string, string>);
|
|
26
|
+
}
|
|
27
|
+
/** 33554432 -> "32 MiB"; 512000 -> "500 KiB". Whole units only: a limit stated
|
|
28
|
+
* as "33554432 bytes" is never actionable for a human reading a 413. */
|
|
29
|
+
export declare function formatByteLimit(bytes: number): string;
|
|
30
|
+
/** The 413 sentence, shared by the native leg, the MITM leg and the h2 preface
|
|
31
|
+
* guard. Names the author (the gateway), the number, and the fix.
|
|
32
|
+
*
|
|
33
|
+
* No `Retry-After` is sent on purpose: RFC 9110 15.5.14 defines that header for
|
|
34
|
+
* when "the request condition is likely to be temporary" (rate limits, maintenance
|
|
35
|
+
* windows). An oversized body is not temporary — it stays oversized until the
|
|
36
|
+
* client changes the request — so a delay would only invite pointless retries of
|
|
37
|
+
* the same refusal. */
|
|
38
|
+
export declare function bodyTooLargeMessage(capBytes: number): string;
|
|
39
|
+
/** Install the configured caps (called once from `createServer`) and return what
|
|
40
|
+
* will actually be enforced, so the caller can log the effective number. Junk
|
|
41
|
+
* (non-finite, <= 0) falls back to the shipped constant: the cleaner in
|
|
42
|
+
* `resolveBodyLimits` already clamps a loaded file, so this is the guard for a
|
|
43
|
+
* hand-built config object, not a second policy. */
|
|
44
|
+
export declare function configureBodyLimits(limits?: BodyLimitsConfig): Required<BodyLimitsConfig>;
|
|
45
|
+
/** The enforced cap of one plane. Read at call time, never captured at module load. */
|
|
46
|
+
export declare function bodyLimitFor(plane: 'gateway' | 'admin'): number;
|
|
47
|
+
export declare function payloadTooLarge(capBytes?: number): BodyAdmissionError;
|
|
48
|
+
/**
|
|
49
|
+
* A body that stopped arriving. 408 (RFC 9110 15.5.9), NOT another 413: nothing is
|
|
50
|
+
* oversized on this path, and the two verdicts ask the client for opposite fixes —
|
|
51
|
+
* shrink the payload versus send the same one again. `connection: close` rides with
|
|
52
|
+
* it because a stalled connection is exactly the thing we are reaping.
|
|
53
|
+
*/
|
|
54
|
+
export declare function requestBodyTimeout(idleMs?: number): BodyAdmissionError;
|
|
55
|
+
/** A body that arrived as text but is not JSON. Lives here so both legs use the
|
|
56
|
+
* same words as Fastify's own parser-failure path. */
|
|
57
|
+
export declare function invalidJsonBody(): BodyAdmissionError;
|
|
58
|
+
/**
|
|
59
|
+
* What we advertise as acceptable request codings, derived from the decode table
|
|
60
|
+
* so the advertisement and the decoder cannot drift. `x-gzip` is the same coding
|
|
61
|
+
* under a legacy name, so it is not advertised; `identity` needs no mention
|
|
62
|
+
* (RFC 9110 8.4.1: a coding token of `identity` is always acceptable).
|
|
63
|
+
*
|
|
64
|
+
* RFC 9110 15.5.16: a 415 response "CAN" list what the server accepts. The coding
|
|
65
|
+
* refusal is the 415 where that list is Content-Encoding, and 8.4.1 is explicit
|
|
66
|
+
* that the media-type 415 MUST NOT carry it — "an incorrectly generated
|
|
67
|
+
* Accept-Encoding header field would be interpreted by the client as an
|
|
68
|
+
* indication that the server supports the listed content codings" — which is why
|
|
69
|
+
* this header rides on the error object instead of on the shared send path.
|
|
70
|
+
*/
|
|
71
|
+
export declare const ACCEPT_ENCODING_ADVERTISEMENT: string;
|
|
72
|
+
/** The media-type 415 gets the other half of the same sentence: the media type
|
|
73
|
+
* whose body we will actually parse. `text/plain` is tolerated in the parser but
|
|
74
|
+
* not advertised, because it is a mis-declaration allowance, not a contract. */
|
|
75
|
+
export declare const ACCEPT_MEDIA_ADVERTISEMENT = "application/json";
|
|
76
|
+
/** The codings a client may declare on the way in — the same table the decoders
|
|
77
|
+
* use, so the 415 message and the Accept-Encoding advertisement cannot drift. */
|
|
78
|
+
export declare const SUPPORTED_REQUEST_CODINGS: readonly string[];
|
|
79
|
+
/**
|
|
80
|
+
* The two headers a rejecting gateway is allowed to advertise, keyed by the code
|
|
81
|
+
* that fired. RFC 9110 15.5.16: a 415 "MUST NOT include a Content-Encoding"-family
|
|
82
|
+
* negotiation field for the rejected payload — it may include `Accept`; 12.5.3
|
|
83
|
+
* gives `Accept-Encoding` to the coding refusal. Attaching the wrong one is not
|
|
84
|
+
* cosmetic: `Accept-Encoding` on a 415 tells the client the media type was fine.
|
|
85
|
+
*
|
|
86
|
+
* Returns undefined for the codes that negotiate nothing (413, 400), so the send
|
|
87
|
+
* sites never have to know which code means what.
|
|
88
|
+
*/
|
|
89
|
+
export declare function admissionNegotiationHeaders(code: BodyAdmissionCode): Record<string, string> | undefined;
|
|
90
|
+
/** True when the client declared `Expect: 100-continue` (token match, so an
|
|
91
|
+
* extension expectation alongside it does not confuse the guard). */
|
|
92
|
+
export declare function expects100Continue(headers: http.IncomingHttpHeaders): boolean;
|
|
93
|
+
/** The body size a client declared, or undefined when it declared none (chunked
|
|
94
|
+
* transfer, or a junk `Content-Length` — both are settled while reading). */
|
|
95
|
+
export declare function declaredBodyBytes(headers: http.IncomingHttpHeaders): number | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Answer an `Expect: 100-continue` request BEFORE its body is transferred.
|
|
98
|
+
*
|
|
99
|
+
* RFC 9110 10.1.1 is not permissive here: a server that has the headers and a
|
|
100
|
+
* 100-continue expectation "MUST send either: an immediate response with a final
|
|
101
|
+
* status code, if that status can be determined by examining just the method,
|
|
102
|
+
* target URI, and header fields, or an immediate 100 (Continue) response". When the
|
|
103
|
+
* declared length is already over the cap the 413 IS that determinable status, so
|
|
104
|
+
* answering now is the required branch -- and it is what the mechanism exists for
|
|
105
|
+
* ("allows the client to wait for an indication that it is worthwhile to send the
|
|
106
|
+
* content ... can improve efficiency when the data is huge"). A body that declares
|
|
107
|
+
* no length (chunked) cannot be judged from headers, so it still gets the streamed
|
|
108
|
+
* guard.
|
|
109
|
+
*
|
|
110
|
+
* INSTALLING A `checkContinue` LISTENER TAKES THE EXCHANGE OVER. Verified on both
|
|
111
|
+
* runtimes this gateway runs on (Bun 1.3.14 and Node 24): once a listener exists,
|
|
112
|
+
* the server fires `checkContinue` INSTEAD of `request` and never delivers the
|
|
113
|
+
* request afterwards -- so a listener that only calls `writeContinue()` hangs the
|
|
114
|
+
* client until timeout, which is worse than the 413 we are trying to avoid.
|
|
115
|
+
* Returning false therefore means "continue, and YOU dispatch it": the caller must
|
|
116
|
+
* hand `req`/`res` to its own request flow (the native leg re-emits `request` on
|
|
117
|
+
* the underlying server; the MITM legs call their inner handler).
|
|
118
|
+
*
|
|
119
|
+
* The same guard answers a header-known 415 (`unsupported_media_type`,
|
|
120
|
+
* `unsupported_content_encoding`) through `preflightBodyAdmission`: the format
|
|
121
|
+
* problem is fully determinable from the headers, it is the first MUST branch above,
|
|
122
|
+
* and RFC 9110 15.5.16 exists precisely so a client can tell a coding problem from a
|
|
123
|
+
* media-type problem from the response fields — so the refusal carries the negotiation
|
|
124
|
+
* header its code owns (`Accept-Encoding` for a coding refusal, `Accept` for a media
|
|
125
|
+
* one; 12.5.3 makes the coding field a MUST NOT when the cause is unrelated to
|
|
126
|
+
* codings, and a 413 gets neither: §15.5.14 names no negotiation field, and a smaller
|
|
127
|
+
* body in an unsupported coding is still unsupported, so advertising codings there
|
|
128
|
+
* would invite a retry that cannot succeed). `Retry-After` is deliberately absent on a
|
|
129
|
+
* 413: 15.5.14 asks for it only "if the condition is temporary", and a standing byte
|
|
130
|
+
* cap is not.
|
|
131
|
+
*
|
|
132
|
+
* The rejection says `connection: close` because 10.1.1 requires a server that
|
|
133
|
+
* answers before reading the content to "SHOULD indicate whether it intends to close
|
|
134
|
+
* the connection ... or continue reading the request content" -- we are not reading
|
|
135
|
+
* the rest, and leaving the pipe open would make the arriving body look like the
|
|
136
|
+
* next pipelined request.
|
|
137
|
+
*
|
|
138
|
+
* `resolveRoute` maps the request target to the cap and envelope that WOULD have
|
|
139
|
+
* handled it; undefined means "not an admission-guarded route, just continue". The
|
|
140
|
+
* cap MUST be the route's own: the two admin upload routes are registered above the
|
|
141
|
+
* inference cap, and a hard-coded guess here would refuse a body the route accepts.
|
|
142
|
+
* Returns true when this guard answered.
|
|
143
|
+
*/
|
|
144
|
+
export interface ContinueAdmissionRoute {
|
|
145
|
+
capBytes: number;
|
|
146
|
+
errorBody: (err: BodyAdmissionError) => unknown;
|
|
147
|
+
/** Which transport refused it (AGENTS.md: leg vocabulary is discipline-bearing). */
|
|
148
|
+
leg?: 'native' | 'mitm';
|
|
149
|
+
log?: {
|
|
150
|
+
warn: (obj: unknown, msg: string) => void;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Close the transport after the refusal. On the MITM leg `res.end()` alone leaves
|
|
154
|
+
* the terminated TLS socket open (Bun), so the ingress proxy passes the terminator
|
|
155
|
+
* abort hook here; the native leg needs nothing extra (`connection: close`).
|
|
156
|
+
*/
|
|
157
|
+
refuse?: () => void;
|
|
158
|
+
}
|
|
159
|
+
export declare function settleContinuationExpectation(req: http.IncomingMessage, res: http.ServerResponse, resolveRoute: (url: string) => ContinueAdmissionRoute | undefined): boolean;
|
|
160
|
+
/** The encoding token of a request, normalised (`GZIP ` -> `gzip`). Missing,
|
|
161
|
+
* empty or `identity` all mean "no transformation" and return undefined. */
|
|
162
|
+
export declare function requestContentEncoding(headers: http.IncomingHttpHeaders): string | undefined;
|
|
163
|
+
export declare function requestMediaType(headers: http.IncomingHttpHeaders): string | undefined;
|
|
164
|
+
/** True when this request's declared media type is one whose body we will parse.
|
|
165
|
+
* An absent header is NOT acceptable — it is the one case where leniency on one
|
|
166
|
+
* leg and a framework gate on the other would disagree silently. */
|
|
167
|
+
export declare function mediaTypeAcceptable(headers: http.IncomingHttpHeaders): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* The MITM leg's media-type gate, thrown (not replied) so answering and logging
|
|
170
|
+
* stay on the single admission path in `model-gateway.ts`. Called BEFORE the body
|
|
171
|
+
* is read, which is the point: reject the type, not the size.
|
|
172
|
+
*/
|
|
173
|
+
export declare function assertJsonMediaType(headers: http.IncomingHttpHeaders): void;
|
|
174
|
+
/**
|
|
175
|
+
* Decide from the HEADERS alone whether this request could ever be admitted:
|
|
176
|
+
* framing first (an ambiguous `Content-Length` is not a message we may forward,
|
|
177
|
+
* RFC 9112 6.3), then media type (cheap, and independent of size), then the
|
|
178
|
+
* content coding, by asking the same decoder table `decompressBody` uses against
|
|
179
|
+
* an empty buffer -- an undecodable coding throws there and here, with the same
|
|
180
|
+
* 415, so the two checks cannot disagree about which codings exist. Also the
|
|
181
|
+
* header-only half of `settleContinuationExpectation`, which is why it returns
|
|
182
|
+
* the error instead of throwing it.
|
|
183
|
+
*
|
|
184
|
+
* Returns the rejection, or undefined when the request may proceed. The MITM legs
|
|
185
|
+
* call it BEFORE the body is drained, so a request we intend to refuse never pays
|
|
186
|
+
* for its own upload (the counterpart of the `Expect: 100-continue` guard, which
|
|
187
|
+
* cannot help a chunked body or a client that ignores the expectation).
|
|
188
|
+
*/
|
|
189
|
+
export declare function preflightBodyAdmission(headers: http.IncomingHttpHeaders, capBytes?: number): BodyAdmissionError | undefined;
|
|
190
|
+
/** A `Content-Length` the server could not frame: duplicated values, a non-numeric
|
|
191
|
+
* value, or bytes that do not match the declaration. 400 because the framing, not
|
|
192
|
+
* the payload, is broken (RFC 9110 8.6 makes a message with conflicting
|
|
193
|
+
* Content-Length values an error, not something to guess at). The declared numbers
|
|
194
|
+
* are deliberately NOT echoed: a mismatch gives the client nothing to fix beyond
|
|
195
|
+
* "reframe the request", and repeating a caller-chosen length into a response and a
|
|
196
|
+
* log line is free noise. */
|
|
197
|
+
export declare function invalidContentLength(): BodyAdmissionError;
|
|
198
|
+
/**
|
|
199
|
+
* Normalize what Fastify handed the handler.
|
|
200
|
+
*
|
|
201
|
+
* A `text/plain` (or any tolerated-but-not-json) declaration makes Fastify's own
|
|
202
|
+
* parser deliver a raw STRING, and passing that to the pipeline produced the
|
|
203
|
+
* misleading `"messages" array is required` 400 for a perfectly valid body. Parse
|
|
204
|
+
* it here so the native leg agrees with the MITM leg, and reject a top-level
|
|
205
|
+
* non-object the same way the MITM leg does.
|
|
206
|
+
*/
|
|
207
|
+
export declare function normalizeNativeBody(body: unknown): unknown;
|
|
208
|
+
/**
|
|
209
|
+
* Streaming decoder for the native leg, returned from a Fastify `preParsing`
|
|
210
|
+
* hook. Returning a stream (instead of buffering) keeps the request on Fastify's
|
|
211
|
+
* normal parse path.
|
|
212
|
+
*
|
|
213
|
+
* The limit is deliberately NOT passed here: Fastify measures the stream this
|
|
214
|
+
* hook returns and enforces `bodyLimit` against its OUTPUT length, so an
|
|
215
|
+
* inflated bomb is refused at the same ceiling as a plain body.
|
|
216
|
+
*
|
|
217
|
+
* `receivedEncodedLength` is defined as a live getter over the COMPRESSED bytes:
|
|
218
|
+
* Fastify compares it against the `Content-Length` header and reads it after each
|
|
219
|
+
* chunk, so a static 0 makes the request fail as a length mismatch.
|
|
220
|
+
*/
|
|
221
|
+
export declare function createBodyDecompressor(headers: http.IncomingHttpHeaders, payload: Readable): Readable;
|
|
222
|
+
/** Buffer decoder for the MITM leg, which already holds the whole body.
|
|
223
|
+
* `maxOutputLength` is the bomb guard: zlib aborts with ERR_BUFFER_TOO_LARGE
|
|
224
|
+
* rather than inflating past the cap, and that is reported as the SAME 413 the
|
|
225
|
+
* native leg produces. */
|
|
226
|
+
export declare function decompressBody(raw: Buffer, headers: http.IncomingHttpHeaders, capBytes?: number): Buffer;
|
|
227
|
+
/** Parse an admitted JSON body, rejecting with the shared 400 rather than a raw
|
|
228
|
+
* SyntaxError whose message leaks byte offsets to the client. */
|
|
229
|
+
export declare function parseJsonBody(body: Buffer | string): unknown;
|
|
230
|
+
/**
|
|
231
|
+
* One operator-facing line per admission rejection. Without it a 413/415 is
|
|
232
|
+
* invisible: capture records nothing on this path (ADR-0008 — 400/413 precede
|
|
233
|
+
* processing) and Fastify request logging is disabled, so an operator debugging
|
|
234
|
+
* "my agent fails on long sessions" has no server-side evidence at all.
|
|
235
|
+
* `log` is the request logger when available; the fallback keeps the line in the
|
|
236
|
+
* process log for the legs that have no pino child.
|
|
237
|
+
*/
|
|
238
|
+
export declare function logBodyRejection(info: {
|
|
239
|
+
leg: 'native' | 'mitm';
|
|
240
|
+
path: string;
|
|
241
|
+
err: BodyAdmissionError;
|
|
242
|
+
capBytes: number;
|
|
243
|
+
receivedBytes?: number;
|
|
244
|
+
encoding?: string;
|
|
245
|
+
}, log?: {
|
|
246
|
+
warn: (obj: unknown, msg: string) => void;
|
|
247
|
+
}): void;
|
|
248
|
+
/** Narrowing helper for the answering layers on both legs. */
|
|
249
|
+
export declare function isBodyAdmissionError(err: unknown): err is BodyAdmissionError;
|
|
250
|
+
/**
|
|
251
|
+
* Read what the client still has in flight BEFORE writing the answer, so the
|
|
252
|
+
* refusal lands in a readable state on a socket the framework will close as soon
|
|
253
|
+
* as the reply finishes. Used by the Fastify (native) legs and the pre-dispatch
|
|
254
|
+
* gate — every place that still has to WRITE an answer.
|
|
255
|
+
*
|
|
256
|
+
* The budget is TWICE the plane's cap: a body just over the limit (the common
|
|
257
|
+
* case, and the one a client can actually fix by reading the answer) is consumed
|
|
258
|
+
* in full, so the sender finishes its write and the answer is read cleanly. A
|
|
259
|
+
* sender far over the limit is cut there — a server is not obliged to download an
|
|
260
|
+
* upload it already refused (RFC 9110 15.5.14), and `Expect: 100-continue`, which
|
|
261
|
+
* this gateway honours, is how a client learns the limit before sending.
|
|
262
|
+
*
|
|
263
|
+
* The drain NEVER destroys the request: expiry only stops reading, so the caller
|
|
264
|
+
* can still write its 413. (Destruction-before-answer is what produced a bare
|
|
265
|
+
* `200 OK` on Bun.)
|
|
266
|
+
*/
|
|
267
|
+
export declare function settleRefusedBody(req: http.IncomingMessage | undefined, capBytes?: number): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Same idea AFTER the answer was already flushed (every refusal path). Returns
|
|
270
|
+
* whether the drain took over the request; when it did not, the caller closes the
|
|
271
|
+
* transport itself. `whenDone` runs once the client finished (or the budget
|
|
272
|
+
* expired), so the close still happens exactly once.
|
|
273
|
+
*
|
|
274
|
+
* The byte budget is the PLANE'S cap doubled, not a fixed number: a body just
|
|
275
|
+
* over the limit is the normal case, and cutting the drain short mid-write makes
|
|
276
|
+
* the client see a reset instead of the answer we already wrote. Measured on the
|
|
277
|
+
* admin plane: an 8 MiB upload reset ~20% of the time while the budget was a flat
|
|
278
|
+
* 4 MiB, and stopped resetting once the drain covered the whole body.
|
|
279
|
+
*/
|
|
280
|
+
export declare function drainRefusedBody(req: http.IncomingMessage | undefined, whenDone?: () => void, capBytes?: number): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Write ONE refusal, then deal with the socket. WHICH order is used depends on
|
|
283
|
+
* the leg, and both orders exist for the same reason — the answer must reach a
|
|
284
|
+
* client that is still uploading:
|
|
285
|
+
*
|
|
286
|
+
* - the RAW leg calls this writer only (answer first, then drain). Answering
|
|
287
|
+
* before reading is what lets a client that ignores the limit still see the
|
|
288
|
+
* 413; the bounded drain only prevents the OS from turning the close into a
|
|
289
|
+
* reset the client never reads past.
|
|
290
|
+
* - the FASTIFY legs drain first (`settleRefusedBody`) and then call this with
|
|
291
|
+
* `drainBody: false`: the framework closes the socket with the reply, so an
|
|
292
|
+
* answer written while the sender is still writing is the reset, and a drain
|
|
293
|
+
* that ran AFTER the answer would only add a second budget on a socket that
|
|
294
|
+
* is already being torn down.
|
|
295
|
+
*
|
|
296
|
+
* Neither path may `destroy()` the request: destroying it before the answer
|
|
297
|
+
* makes Bun reply with a bare `200 OK` and an empty body — a refusal that tells
|
|
298
|
+
* the client the request SUCCEEDED (measured: `+3006 ms`, `HTTP/1.1 200 OK`).
|
|
299
|
+
*
|
|
300
|
+
* `content-length` is declared because Bun 1.4.x otherwise frames the answer as
|
|
301
|
+
* chunked, so a raw-socket client reads hex chunk-size lines instead of JSON.
|
|
302
|
+
* `connection: close` rides only on h1: HTTP/2 forbids connection-specific
|
|
303
|
+
* fields, and on h2 the response completes normally while flow control stops a
|
|
304
|
+
* client that keeps uploading (nothing is buffered).
|
|
305
|
+
*/
|
|
306
|
+
export declare function writeRefusalAnswer(res: http.ServerResponse, status: number, serialized: string, opts?: {
|
|
307
|
+
/** The rejection's own negotiation headers (a 415 names its cause). */
|
|
308
|
+
headers?: Record<string, string>;
|
|
309
|
+
/** The plane's cap, so a post-answer drain knows how much it may read. */
|
|
310
|
+
capBytes?: number;
|
|
311
|
+
/** Drain the refused body after the answer. The raw leg wants it; the
|
|
312
|
+
* Fastify legs already settled the body BEFORE calling this. */
|
|
313
|
+
drainBody?: boolean;
|
|
314
|
+
}): void;
|
|
315
|
+
/** Minimal view of a protocol surface, so this module does not import the table
|
|
316
|
+
* (which would cycle back through the transports). */
|
|
317
|
+
interface EnvelopeOwner {
|
|
318
|
+
routePath: string;
|
|
319
|
+
errorBody(status: number, message: string, code?: string): unknown;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Route options that give the NATIVE leg the same admission policy the MITM leg
|
|
323
|
+
* applies by hand: decode `Content-Encoding` on the way in, cap the DECOMPRESSED
|
|
324
|
+
* body at the configured inference cap (`bodyLimitFor('gateway')`), and answer every
|
|
325
|
+
* rejection in the surface's own envelope with a machine-readable `code`.
|
|
326
|
+
*
|
|
327
|
+
* `preParsing` is registered per route rather than app-wide on purpose — an
|
|
328
|
+
* app-wide hook would also decompress admin/upload bodies it knows nothing about.
|
|
329
|
+
*/
|
|
330
|
+
export declare function surfaceBodyAdmissionOptions(surface: EnvelopeOwner): RouteShorthandOptions;
|
|
331
|
+
/**
|
|
332
|
+
* App-level `errorHandler` for the ADMIN plane (everything that is not a
|
|
333
|
+
* protocol surface). The console reads failures as `{ success: false, message }`;
|
|
334
|
+
* Fastify's default shape is `{ statusCode, code, error, message }` whose
|
|
335
|
+
* `error` is a reason phrase, which the UI renders as the bare
|
|
336
|
+
* `Error: 413 "Payload Too Large"` this whole module exists to kill.
|
|
337
|
+
*
|
|
338
|
+
* Non-admission errors are RE-THROWN, which hands them to Fastify's default
|
|
339
|
+
* handler (fastify/docs/Reference/Errors.md) — this handler must not become a
|
|
340
|
+
* second, worse error serializer for validation and 5xx paths it knows nothing
|
|
341
|
+
* about, and it never echoes a stack or an upstream body.
|
|
342
|
+
*/
|
|
343
|
+
export declare function adminBodyErrorHandler(err: FastifyError, request: FastifyRequest, reply: FastifyReply): Promise<never>;
|
|
344
|
+
export {};
|