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,144 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { CA_CERT_FILENAME, resolveCaDir } from './ca.js';
|
|
3
|
+
import { DEFAULT_INGRESS_PROXY_MAX_CONNECTIONS, DEFAULT_INGRESS_PROXY_PORT, DEFAULT_INGRESS_PROXY_HOST, DEFAULT_INGRESS_PROXY_INTERCEPT, DEFAULT_PROXY_ACCESS_LOG_PERSIST_DAYS, } from '../config/defaults.js';
|
|
4
|
+
import { getRuntimeConfigRef, loadConfig } from '../config/index.js';
|
|
5
|
+
import { createIngressProxyServer, openOriginLegCount } from './server.js';
|
|
6
|
+
import { createProxyInterceptor } from './interceptor.js';
|
|
7
|
+
import { setIngressProxyLiveCounters } from './status.js';
|
|
8
|
+
import { setGatewayChatServices, buildGatewayChatServices } from '../surfaces/gateway-chat.js';
|
|
9
|
+
import { detectSurface } from '../surfaces/table.js';
|
|
10
|
+
import { setProxyAccessLogSettingsReader, setProxyAccessLogPersistDir, initProxyAccessLogPersistence } from './access-log.js';
|
|
11
|
+
import { listGatewayHosts, WILDCARD_HOST_CLAIM } from '../plugins/gateways.js';
|
|
12
|
+
import { setUpstreamTlsReader } from './upstream-tls.js';
|
|
13
|
+
import { migrateIngressProxyDataDir } from './data-dir.js';
|
|
14
|
+
/** Literal loopback bind/listen address — 0.0.0.0/:: count as exposed. */
|
|
15
|
+
function isLiteralLoopbackHost(host) {
|
|
16
|
+
const h = (host || '').trim().toLowerCase().replace(/^\[|\]$/g, '');
|
|
17
|
+
return !h || h === 'localhost' || h.endsWith('.localhost') || h === '::1' || /^127\.\d+\.\d+\.\d+$/.test(h);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Refuse any bind that is not a literal loopback address.
|
|
21
|
+
*
|
|
22
|
+
* The inbound proxy authenticates NOBODY (ADR-0008 §3) and decrypts + records
|
|
23
|
+
* whatever its clients send, so a listener reachable from another machine would
|
|
24
|
+
* be an unauthenticated full-capture MITM proxy on the LAN. There is exactly one
|
|
25
|
+
* admissible bind, and refusing loudly is the honest failure: silently folding
|
|
26
|
+
* the address to 127.0.0.1 would leave the operator's remote client failing to
|
|
27
|
+
* connect with no explanation anywhere.
|
|
28
|
+
*
|
|
29
|
+
* A remote client is served with a tunnel (SSH port-forward / socat), never a
|
|
30
|
+
* wide bind.
|
|
31
|
+
*/
|
|
32
|
+
export function assertIngressProxyBindSafety(host) {
|
|
33
|
+
// Deliberately NOT `isLoopbackHost`: that helper counts 0.0.0.0 as "loopback"
|
|
34
|
+
// for MITM cycle-safety (an unspecified target is never decrypted), which is
|
|
35
|
+
// the exact opposite of what a BIND gate needs — 0.0.0.0 means every
|
|
36
|
+
// interface.
|
|
37
|
+
const loopback = isLiteralLoopbackHost(host);
|
|
38
|
+
if (loopback)
|
|
39
|
+
return;
|
|
40
|
+
throw new Error(`ingressProxy.host is "${host}" (not loopback). The inbound proxy carries no credential, so it may only listen on ` +
|
|
41
|
+
'127.0.0.1 / ::1 / localhost. Reach a remote client through a tunnel (SSH port-forward or socat) instead of a wide bind.');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Start the inbound ingress proxy (HTTP_PROXY / HTTPS_PROXY server).
|
|
45
|
+
* Enabled via config.yaml `ingressProxy.enabled`; defaults: port 4555,
|
|
46
|
+
* loopback-only. The MITM CA lives in the machine-wide shared dir (see
|
|
47
|
+
* `resolveCaDir`); the access log stays under this book-set's home.
|
|
48
|
+
*/
|
|
49
|
+
export async function startIngressProxy(cfg, orchestrator) {
|
|
50
|
+
const host = cfg.host?.trim() || DEFAULT_INGRESS_PROXY_HOST;
|
|
51
|
+
// Bind gate BEFORE anything listens: the inbound proxy has no credential
|
|
52
|
+
// (ADR-0008 §3), so only a literal loopback address is admissible.
|
|
53
|
+
assertIngressProxyBindSafety(host);
|
|
54
|
+
// Move the pre-rename state directory before ANY reader touches it. A failed
|
|
55
|
+
// move keeps the legacy path serving (see data-dir.ts), so this is safe to
|
|
56
|
+
// call unconditionally on every boot.
|
|
57
|
+
const dataDir = migrateIngressProxyDataDir();
|
|
58
|
+
const caDir = resolveCaDir(cfg.caDir);
|
|
59
|
+
const intercept = createProxyInterceptor(orchestrator);
|
|
60
|
+
// Gateway-plugin chat seam (ADR-0017): the services ride the same
|
|
61
|
+
// orchestrator the interceptor uses, so plugins dispatch through the
|
|
62
|
+
// identical routing pipeline as the native legs.
|
|
63
|
+
// Key binding: resolve the plugin's `accountKeyId` against the LIVE config
|
|
64
|
+
// snapshot so console edits apply without a restart. This is the ONLY
|
|
65
|
+
// identity a proxy-borne completion has — admission carries none.
|
|
66
|
+
const liveKey = (id) => (getRuntimeConfigRef() ?? loadConfig()).apiKeys?.find((k) => k.id === id);
|
|
67
|
+
setGatewayChatServices(buildGatewayChatServices(orchestrator, liveKey));
|
|
68
|
+
// Hot-apply seam: the access-log flags re-read the live runtime ref per
|
|
69
|
+
// request, so console saves need no restart.
|
|
70
|
+
setProxyAccessLogPersistDir(path.join(dataDir.dir, 'access-log'));
|
|
71
|
+
initProxyAccessLogPersistence();
|
|
72
|
+
setProxyAccessLogSettingsReader(() => {
|
|
73
|
+
const fp = getRuntimeConfigRef()?.ingressProxy;
|
|
74
|
+
return {
|
|
75
|
+
enabled: fp?.accessLog?.enabled !== false,
|
|
76
|
+
bodyBytes: fp?.accessLog?.bodyBytes,
|
|
77
|
+
persist: fp?.accessLog?.persist !== false,
|
|
78
|
+
persistDays: fp?.accessLog?.persistDays ?? DEFAULT_PROXY_ACCESS_LOG_PERSIST_DAYS,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
// Upstream TLS trust (ADR-0019): resolved per origin leg off the live config,
|
|
82
|
+
// so a console save hot-applies. A `caFile` is re-stat'ed on a short TTL, so a
|
|
83
|
+
// rotated bundle is picked up too.
|
|
84
|
+
setUpstreamTlsReader(() => getRuntimeConfigRef()?.ingressProxy?.upstreamTls);
|
|
85
|
+
if (cfg.upstreamTls?.insecure === true) {
|
|
86
|
+
console.warn('[IngressProxy] ingressProxy.upstreamTls.insecure is TRUE — upstream certificates are NOT verified. ' +
|
|
87
|
+
'Any origin (including a MITM on the path) is accepted; use it only to get past a broken chain, never as a resting state.');
|
|
88
|
+
}
|
|
89
|
+
// Interception posture (ADR-0018 Revision 4): the default decrypts only
|
|
90
|
+
// plugin-claimed hosts and explicit `ingress: intercept` rows. `all` is the
|
|
91
|
+
// audit posture — a standing machine-wide decryption the operator must be
|
|
92
|
+
// told about in the log, not just in a YAML value.
|
|
93
|
+
if (cfg.intercept === 'all') {
|
|
94
|
+
console.warn('[IngressProxy] ingressProxy.intercept is "all" — EVERY host proxied here is decrypted (machine-wide TLS interception, audit mode). ' +
|
|
95
|
+
'Every client trust store must carry this CA; set `intercept: claims` to decrypt only plugin-claimed hosts.');
|
|
96
|
+
}
|
|
97
|
+
const handle = await createIngressProxyServer({
|
|
98
|
+
port: cfg.port ?? DEFAULT_INGRESS_PROXY_PORT,
|
|
99
|
+
host,
|
|
100
|
+
caDir,
|
|
101
|
+
maxConnections: cfg.maxConnections,
|
|
102
|
+
rules: cfg.rules,
|
|
103
|
+
interceptPosture: cfg.intercept,
|
|
104
|
+
// Hot-apply seam: rules / intercept re-read the runtime ref per
|
|
105
|
+
// request, so console saves need no restart.
|
|
106
|
+
liveIngressProxy: () => getRuntimeConfigRef()?.ingressProxy,
|
|
107
|
+
// The MITM Expect: 100-continue guard answers in the served surface's own
|
|
108
|
+
// envelope, so it needs the registry — passed in, not imported by server.ts
|
|
109
|
+
// (that import closes a load-time cycle; see IngressProxyDeps.detectSurface).
|
|
110
|
+
detectSurface,
|
|
111
|
+
intercept,
|
|
112
|
+
log: (m) => console.log(`[IngressProxy] ${m}`),
|
|
113
|
+
});
|
|
114
|
+
setIngressProxyLiveCounters(() => ({
|
|
115
|
+
connections: handle.activeConnections(),
|
|
116
|
+
originLegs: openOriginLegCount(),
|
|
117
|
+
maxConnections: loadConfig().ingressProxy?.maxConnections ?? DEFAULT_INGRESS_PROXY_MAX_CONNECTIONS,
|
|
118
|
+
}));
|
|
119
|
+
console.log(`[IngressProxy] ready on http://${host}:${handle.port} — MITM CA: ${path.join(caDir, CA_CERT_FILENAME)}`);
|
|
120
|
+
// One line that answers "who gets decrypted on this machine?" — the posture
|
|
121
|
+
// and the claim count are the whole answer under the default (ADR-0018
|
|
122
|
+
// Revision 4), so they belong in the boot log next to the table summary.
|
|
123
|
+
const rules = cfg.rules || [];
|
|
124
|
+
const posture = cfg.intercept ?? DEFAULT_INGRESS_PROXY_INTERCEPT;
|
|
125
|
+
// A wildcard gateway claims every host through `match()`; it is reported as a
|
|
126
|
+
// posture of its own rather than counted as one host name.
|
|
127
|
+
const claimedHosts = listGatewayHosts();
|
|
128
|
+
const wildcard = claimedHosts.has(WILDCARD_HOST_CLAIM);
|
|
129
|
+
const claimedCount = wildcard ? claimedHosts.size - 1 : claimedHosts.size;
|
|
130
|
+
const catchAll = rules.find((r) => r.match === '*');
|
|
131
|
+
console.log(`[IngressProxy] rules: ${rules.length} rule(s) (${rules.filter((r) => r.ingress === 'passthrough').length} blind-tunnel), ` +
|
|
132
|
+
`${catchAll ? 'catch-all present' : 'NO catch-all → unmatched hosts go DIRECT'}, ` +
|
|
133
|
+
`intercept: ${posture} (${posture === 'all'
|
|
134
|
+
? 'EVERY host decrypted'
|
|
135
|
+
: `${claimedCount} claimed host(s)${wildcard ? ' + a wildcard gateway' : ''} + explicit intercept rows decrypted`})`);
|
|
136
|
+
if (catchAll?.ingress === 'intercept' && posture !== 'all') {
|
|
137
|
+
console.warn('[IngressProxy] the catch-all row says `ingress: intercept` but intercept is "claims" — it only decrypts hosts a gateway plugin claims. ' +
|
|
138
|
+
'Write `intercept: all` for machine-wide decryption, or `ingress: passthrough` on the catch-all to say what actually happens.');
|
|
139
|
+
}
|
|
140
|
+
if (rules.some((r) => r.egress === 'proxy') && getRuntimeConfigRef()?.proxy?.enabled !== true) {
|
|
141
|
+
console.warn('[IngressProxy] the rule table has "proxy" rules but proxy.enabled is not true — requests for those hosts are REFUSED (502) until an outbound proxy is configured.');
|
|
142
|
+
}
|
|
143
|
+
return handle;
|
|
144
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type { PipelineOrchestrator } from '../pipeline/orchestrator.js';
|
|
3
|
+
/**
|
|
4
|
+
* Decrypted-request dispatch for the ingress proxy, in exactly TWO outcomes
|
|
5
|
+
* (ADR-0026 revision 2):
|
|
6
|
+
*
|
|
7
|
+
* 1. a GATEWAY accepts this request — an exact SNI host claim, an installed
|
|
8
|
+
* wildcard claim, or last of all the built-in universal gateway — and
|
|
9
|
+
* owns it from there;
|
|
10
|
+
* 2. nothing accepted it: this is not model traffic, return false and let
|
|
11
|
+
* the caller forward it transparently, byte-for-byte.
|
|
12
|
+
*
|
|
13
|
+
* There is deliberately no third branch any more. Model service is not
|
|
14
|
+
* something this file does; it is something a gateway does, and the built-in
|
|
15
|
+
* row (`plugins/builtin/model-gateway.ts`) is merely the default occupant of
|
|
16
|
+
* that slot. Installing a package that claims the wildcard takes over with no
|
|
17
|
+
* core change; disabling it hands the traffic straight back.
|
|
18
|
+
*
|
|
19
|
+
* POLICY: intercepted traffic carries NO gateway key — the authoritative note
|
|
20
|
+
* lives in `surfaces/transport-node-http.ts` (the node-http transport); do NOT
|
|
21
|
+
* invent key headers here. Proxy admission carries no identity either (ADR-0008
|
|
22
|
+
* §3): a gateway-plugin completion reads its key from the plugin's own settings
|
|
23
|
+
* (`accountKeyId`) at dispatch, and nothing about the connection can override it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createProxyInterceptor(orchestrator: PipelineOrchestrator): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<boolean>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createBuiltinModelGateway } from '../plugins/builtin/model-gateway.js';
|
|
2
|
+
import { findGateway } from '../plugins/gateways.js';
|
|
3
|
+
/**
|
|
4
|
+
* Decrypted-request dispatch for the ingress proxy, in exactly TWO outcomes
|
|
5
|
+
* (ADR-0026 revision 2):
|
|
6
|
+
*
|
|
7
|
+
* 1. a GATEWAY accepts this request — an exact SNI host claim, an installed
|
|
8
|
+
* wildcard claim, or last of all the built-in universal gateway — and
|
|
9
|
+
* owns it from there;
|
|
10
|
+
* 2. nothing accepted it: this is not model traffic, return false and let
|
|
11
|
+
* the caller forward it transparently, byte-for-byte.
|
|
12
|
+
*
|
|
13
|
+
* There is deliberately no third branch any more. Model service is not
|
|
14
|
+
* something this file does; it is something a gateway does, and the built-in
|
|
15
|
+
* row (`plugins/builtin/model-gateway.ts`) is merely the default occupant of
|
|
16
|
+
* that slot. Installing a package that claims the wildcard takes over with no
|
|
17
|
+
* core change; disabling it hands the traffic straight back.
|
|
18
|
+
*
|
|
19
|
+
* POLICY: intercepted traffic carries NO gateway key — the authoritative note
|
|
20
|
+
* lives in `surfaces/transport-node-http.ts` (the node-http transport); do NOT
|
|
21
|
+
* invent key headers here. Proxy admission carries no identity either (ADR-0008
|
|
22
|
+
* §3): a gateway-plugin completion reads its key from the plugin's own settings
|
|
23
|
+
* (`accountKeyId`) at dispatch, and nothing about the connection can override it.
|
|
24
|
+
*/
|
|
25
|
+
export function createProxyInterceptor(orchestrator) {
|
|
26
|
+
// The built-in row needs the live orchestrator, and this factory is the one
|
|
27
|
+
// place that has it. It is captured HERE rather than stored in the gateway
|
|
28
|
+
// registry: two interceptors can exist in one process, and a shared slot
|
|
29
|
+
// would let the later factory re-point the earlier server's model traffic.
|
|
30
|
+
const builtin = createBuiltinModelGateway(orchestrator);
|
|
31
|
+
return async function intercept(req, res) {
|
|
32
|
+
const gateway = findGateway(req, builtin);
|
|
33
|
+
if (!gateway)
|
|
34
|
+
return false;
|
|
35
|
+
try {
|
|
36
|
+
await gateway.handle(req, res);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// The built-in row answers its own failures in the surface envelope; a
|
|
40
|
+
// plugin that throws past its own error handling gets the proxy's
|
|
41
|
+
// generic refusal rather than a hung socket.
|
|
42
|
+
if (!res.headersSent) {
|
|
43
|
+
try {
|
|
44
|
+
res.writeHead(502, { 'content-type': 'application/json; charset=utf-8' });
|
|
45
|
+
res.end(JSON.stringify({ error: { message: 'Gateway handler failed' } }));
|
|
46
|
+
}
|
|
47
|
+
catch { }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orders what a decrypted client stream produced ahead of an asynchronous hop.
|
|
3
|
+
*
|
|
4
|
+
* The MITM leg reads the client's plaintext (a `tls.Socket`) and forwards it to
|
|
5
|
+
* a loopback socket that feeds the inner HTTP server. Those two halves do not
|
|
6
|
+
* become ready at the same moment: `net.connect()` returns a socket immediately
|
|
7
|
+
* but connects on a later tick, while decrypted chunks keep arriving. Writing a
|
|
8
|
+
* chunk to the (unconnected) socket queues it, so a later flush of the buffered
|
|
9
|
+
* head lands AFTER it — the parser then reads a body fragment where it expects a
|
|
10
|
+
* request line and answers `400` to a request it never saw. One small request
|
|
11
|
+
* hides this (single chunk); a large prompt does not.
|
|
12
|
+
*
|
|
13
|
+
* So: everything pushed before `attach` is held, and `attach` hands the sink the
|
|
14
|
+
* held bytes first, in order. After that, chunks go straight through.
|
|
15
|
+
*/
|
|
16
|
+
export declare class OrderedRelay {
|
|
17
|
+
#private;
|
|
18
|
+
/** Hold a chunk, or hand it to the sink once one is attached. */
|
|
19
|
+
push(chunk: Buffer): void;
|
|
20
|
+
/**
|
|
21
|
+
* Install the sink and flush what was held. `onAttach` runs after the flush,
|
|
22
|
+
* so a caller can flip its own "connected" state knowing the backlog landed.
|
|
23
|
+
*/
|
|
24
|
+
attach(sink: (chunk: Buffer) => void, onAttach?: () => void): void;
|
|
25
|
+
/** Chunks held while no sink was attached (diagnostics / tests). */
|
|
26
|
+
get held(): number;
|
|
27
|
+
/** The held bytes in arrival order, joined — what a sniffer looks at. */
|
|
28
|
+
snapshot(): Buffer;
|
|
29
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orders what a decrypted client stream produced ahead of an asynchronous hop.
|
|
3
|
+
*
|
|
4
|
+
* The MITM leg reads the client's plaintext (a `tls.Socket`) and forwards it to
|
|
5
|
+
* a loopback socket that feeds the inner HTTP server. Those two halves do not
|
|
6
|
+
* become ready at the same moment: `net.connect()` returns a socket immediately
|
|
7
|
+
* but connects on a later tick, while decrypted chunks keep arriving. Writing a
|
|
8
|
+
* chunk to the (unconnected) socket queues it, so a later flush of the buffered
|
|
9
|
+
* head lands AFTER it — the parser then reads a body fragment where it expects a
|
|
10
|
+
* request line and answers `400` to a request it never saw. One small request
|
|
11
|
+
* hides this (single chunk); a large prompt does not.
|
|
12
|
+
*
|
|
13
|
+
* So: everything pushed before `attach` is held, and `attach` hands the sink the
|
|
14
|
+
* held bytes first, in order. After that, chunks go straight through.
|
|
15
|
+
*/
|
|
16
|
+
export class OrderedRelay {
|
|
17
|
+
#pending = [];
|
|
18
|
+
#sink;
|
|
19
|
+
/** Hold a chunk, or hand it to the sink once one is attached. */
|
|
20
|
+
push(chunk) {
|
|
21
|
+
if (this.#sink) {
|
|
22
|
+
this.#sink(chunk);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.#pending.push(chunk);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Install the sink and flush what was held. `onAttach` runs after the flush,
|
|
29
|
+
* so a caller can flip its own "connected" state knowing the backlog landed.
|
|
30
|
+
*/
|
|
31
|
+
attach(sink, onAttach) {
|
|
32
|
+
this.#sink = sink;
|
|
33
|
+
for (const chunk of this.#pending)
|
|
34
|
+
sink(chunk);
|
|
35
|
+
this.#pending.length = 0;
|
|
36
|
+
onAttach?.();
|
|
37
|
+
}
|
|
38
|
+
/** Chunks held while no sink was attached (diagnostics / tests). */
|
|
39
|
+
get held() {
|
|
40
|
+
return this.#pending.length;
|
|
41
|
+
}
|
|
42
|
+
/** The held bytes in arrival order, joined — what a sniffer looks at. */
|
|
43
|
+
snapshot() {
|
|
44
|
+
return Buffer.concat(this.#pending);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type net from 'node:net';
|
|
2
|
+
/**
|
|
3
|
+
* Which way a relayed chunk travelled: `a2b` = first argument → second.
|
|
4
|
+
*/
|
|
5
|
+
export type SpliceDirection = 'a2b' | 'b2a';
|
|
6
|
+
/** Options for one relay. */
|
|
7
|
+
export interface SpliceOptions {
|
|
8
|
+
/** Observe every relayed chunk (never consumes bytes). */
|
|
9
|
+
tap?: (dir: SpliceDirection, chunk: Buffer) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Liveness stamp for the caller's own ledger (the ingress proxy's admission
|
|
12
|
+
* cap orders eviction by it). Called on every relayed chunk, either direction.
|
|
13
|
+
*/
|
|
14
|
+
onActivity?: () => void;
|
|
15
|
+
/** Override for tests; default INGRESS_PROXY_ABANDONED_TUNNEL_MS. */
|
|
16
|
+
abandonedTunnelMs?: number;
|
|
17
|
+
/** Override for tests; default INGRESS_PROXY_STALE_TUNNEL_MS. */
|
|
18
|
+
halfCloseReapMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Bidirectional byte relay between two sockets with backpressure.
|
|
22
|
+
*
|
|
23
|
+
* Two Bun node:net/tls quirks are load-bearing here (verified on 1.3.14):
|
|
24
|
+
* - `socket.pipe()` FROM a TLSSocket does not flush already-buffered data —
|
|
25
|
+
* an explicit 'data' relay is used instead;
|
|
26
|
+
* - a previously `pause()`d stream does NOT auto-flow when a 'data' listener
|
|
27
|
+
* attaches — `resume()` must be called explicitly.
|
|
28
|
+
*
|
|
29
|
+
* `tap` observes every relayed chunk WITHOUT owning the stream: it runs inside
|
|
30
|
+
* the relay's own 'data' handler, so it can never consume bytes that the relay
|
|
31
|
+
* has not forwarded yet. (Attaching a separate 'data' listener before the relay
|
|
32
|
+
* starts — the obvious way to "peek" a tunnel — silently eats everything that
|
|
33
|
+
* arrives during the async dial.)
|
|
34
|
+
*
|
|
35
|
+
* TCP keepalive is armed on BOTH sockets. A relayed connection has no
|
|
36
|
+
* application-level idle timeout on purpose (a tunnel may carry a legitimately
|
|
37
|
+
* silent protocol — IMAP IDLE keeps quiet for ~29 minutes), so the only way a
|
|
38
|
+
* peer that vanished without FIN/RST gets reaped is the kernel probe. The
|
|
39
|
+
* default OS idle (2 hours) is longer than a crashed client's socket lives, so
|
|
40
|
+
* a half-dead tunnel would hold two descriptors for hours; probing after
|
|
41
|
+
* `INGRESS_PROXY_KEEPALIVE_MS` reclaims them without ever touching a live but
|
|
42
|
+
* quiet stream. `setKeepAlive` is chainable on Bun 1.3.14 (verified: it neither
|
|
43
|
+
* throws nor disturbs the byte flow).
|
|
44
|
+
*
|
|
45
|
+
* Keepalive alone is NOT enough for a tunnel that is abandoned before it ever
|
|
46
|
+
* speaks: probing a LOOPBACK peer (the MITM hop) never fails, so a client that
|
|
47
|
+
* opened a tunnel and vanished leaves both halves ESTABLISHED for the life of the
|
|
48
|
+
* process — measured on a live install as ~200 dead pairs, ~87% of the process's
|
|
49
|
+
* descriptors. `INGRESS_PROXY_ABANDONED_TUNNEL_MS` closes exactly that case and
|
|
50
|
+
* nothing else: it fires only when NOT ONE byte crossed in either direction,
|
|
51
|
+
* which a working tunnel never looks like (a TLS ClientHello or an HTTP request
|
|
52
|
+
* arrives with the first flight).
|
|
53
|
+
*/
|
|
54
|
+
export declare function splice(a: net.Socket, b: net.Socket, opts?: SpliceOptions): void;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { INGRESS_PROXY_ABANDONED_TUNNEL_MS, INGRESS_PROXY_KEEPALIVE_MS, INGRESS_PROXY_STALE_TUNNEL_MS, } from '../config/defaults.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bidirectional byte relay between two sockets with backpressure.
|
|
4
|
+
*
|
|
5
|
+
* Two Bun node:net/tls quirks are load-bearing here (verified on 1.3.14):
|
|
6
|
+
* - `socket.pipe()` FROM a TLSSocket does not flush already-buffered data —
|
|
7
|
+
* an explicit 'data' relay is used instead;
|
|
8
|
+
* - a previously `pause()`d stream does NOT auto-flow when a 'data' listener
|
|
9
|
+
* attaches — `resume()` must be called explicitly.
|
|
10
|
+
*
|
|
11
|
+
* `tap` observes every relayed chunk WITHOUT owning the stream: it runs inside
|
|
12
|
+
* the relay's own 'data' handler, so it can never consume bytes that the relay
|
|
13
|
+
* has not forwarded yet. (Attaching a separate 'data' listener before the relay
|
|
14
|
+
* starts — the obvious way to "peek" a tunnel — silently eats everything that
|
|
15
|
+
* arrives during the async dial.)
|
|
16
|
+
*
|
|
17
|
+
* TCP keepalive is armed on BOTH sockets. A relayed connection has no
|
|
18
|
+
* application-level idle timeout on purpose (a tunnel may carry a legitimately
|
|
19
|
+
* silent protocol — IMAP IDLE keeps quiet for ~29 minutes), so the only way a
|
|
20
|
+
* peer that vanished without FIN/RST gets reaped is the kernel probe. The
|
|
21
|
+
* default OS idle (2 hours) is longer than a crashed client's socket lives, so
|
|
22
|
+
* a half-dead tunnel would hold two descriptors for hours; probing after
|
|
23
|
+
* `INGRESS_PROXY_KEEPALIVE_MS` reclaims them without ever touching a live but
|
|
24
|
+
* quiet stream. `setKeepAlive` is chainable on Bun 1.3.14 (verified: it neither
|
|
25
|
+
* throws nor disturbs the byte flow).
|
|
26
|
+
*
|
|
27
|
+
* Keepalive alone is NOT enough for a tunnel that is abandoned before it ever
|
|
28
|
+
* speaks: probing a LOOPBACK peer (the MITM hop) never fails, so a client that
|
|
29
|
+
* opened a tunnel and vanished leaves both halves ESTABLISHED for the life of the
|
|
30
|
+
* process — measured on a live install as ~200 dead pairs, ~87% of the process's
|
|
31
|
+
* descriptors. `INGRESS_PROXY_ABANDONED_TUNNEL_MS` closes exactly that case and
|
|
32
|
+
* nothing else: it fires only when NOT ONE byte crossed in either direction,
|
|
33
|
+
* which a working tunnel never looks like (a TLS ClientHello or an HTTP request
|
|
34
|
+
* arrives with the first flight).
|
|
35
|
+
*/
|
|
36
|
+
export function splice(a, b, opts = {}) {
|
|
37
|
+
const { tap, onActivity } = opts;
|
|
38
|
+
/** Set by the first relayed chunk; disarms the abandoned-tunnel watchdog. */
|
|
39
|
+
let spoke = false;
|
|
40
|
+
/** Armed by the first half-close; finishes a teardown `close` never starts. */
|
|
41
|
+
let halfCloseReap;
|
|
42
|
+
const abandoned = setTimeout(() => {
|
|
43
|
+
if (spoke)
|
|
44
|
+
return;
|
|
45
|
+
// The client opened this tunnel and never sent a byte, and nothing came
|
|
46
|
+
// back: both halves are dead weight. destroy() the pair so the descriptors
|
|
47
|
+
// return to the OS now rather than at process exit.
|
|
48
|
+
for (const s of [a, b]) {
|
|
49
|
+
try {
|
|
50
|
+
s.destroy();
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
}
|
|
54
|
+
}, opts.abandonedTunnelMs ?? INGRESS_PROXY_ABANDONED_TUNNEL_MS);
|
|
55
|
+
abandoned.unref?.();
|
|
56
|
+
const disarm = () => {
|
|
57
|
+
if (spoke)
|
|
58
|
+
return;
|
|
59
|
+
spoke = true;
|
|
60
|
+
clearTimeout(abandoned);
|
|
61
|
+
};
|
|
62
|
+
/** A write into a socket the runtime already closed means the peer is gone. */
|
|
63
|
+
const peerGone = (target) => target.destroyed === true || target.readyState === 'closed';
|
|
64
|
+
a.on('data', (d) => {
|
|
65
|
+
disarm();
|
|
66
|
+
onActivity?.();
|
|
67
|
+
tap?.('a2b', d);
|
|
68
|
+
if (peerGone(b)) {
|
|
69
|
+
try {
|
|
70
|
+
a.destroy();
|
|
71
|
+
}
|
|
72
|
+
catch { }
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!b.write(d)) {
|
|
76
|
+
a.pause();
|
|
77
|
+
b.once('drain', () => a.resume());
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
b.on('data', (d) => {
|
|
81
|
+
disarm();
|
|
82
|
+
onActivity?.();
|
|
83
|
+
tap?.('b2a', d);
|
|
84
|
+
if (peerGone(a)) {
|
|
85
|
+
try {
|
|
86
|
+
b.destroy();
|
|
87
|
+
}
|
|
88
|
+
catch { }
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!a.write(d)) {
|
|
92
|
+
b.pause();
|
|
93
|
+
a.once('drain', () => b.resume());
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
a.on('close', () => {
|
|
97
|
+
clearTimeout(abandoned);
|
|
98
|
+
clearTimeout(halfCloseReap);
|
|
99
|
+
});
|
|
100
|
+
b.on('close', () => {
|
|
101
|
+
clearTimeout(abandoned);
|
|
102
|
+
clearTimeout(halfCloseReap);
|
|
103
|
+
});
|
|
104
|
+
a.on('end', () => {
|
|
105
|
+
try {
|
|
106
|
+
b.end();
|
|
107
|
+
}
|
|
108
|
+
catch { }
|
|
109
|
+
armHalfCloseReap();
|
|
110
|
+
});
|
|
111
|
+
b.on('end', () => {
|
|
112
|
+
try {
|
|
113
|
+
a.end();
|
|
114
|
+
}
|
|
115
|
+
catch { }
|
|
116
|
+
armHalfCloseReap();
|
|
117
|
+
});
|
|
118
|
+
a.on('error', () => {
|
|
119
|
+
try {
|
|
120
|
+
b.destroy();
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
});
|
|
124
|
+
b.on('error', () => {
|
|
125
|
+
try {
|
|
126
|
+
a.destroy();
|
|
127
|
+
}
|
|
128
|
+
catch { }
|
|
129
|
+
});
|
|
130
|
+
// `destroy()` on one side emits `close` WITHOUT `error`, so the error
|
|
131
|
+
// handlers above miss it. An abrupt local close would otherwise leave the
|
|
132
|
+
// upstream half — and, for a MITM tunnel, the decrypted loopback socket —
|
|
133
|
+
// open until the OS reaps it.
|
|
134
|
+
// The socket is already fully closed here, so destroying the peer cannot cut
|
|
135
|
+
// a live half-close short.
|
|
136
|
+
a.on('close', () => {
|
|
137
|
+
if (b.destroyed)
|
|
138
|
+
return;
|
|
139
|
+
try {
|
|
140
|
+
b.destroy();
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
143
|
+
});
|
|
144
|
+
b.on('close', () => {
|
|
145
|
+
if (a.destroyed)
|
|
146
|
+
return;
|
|
147
|
+
try {
|
|
148
|
+
a.destroy();
|
|
149
|
+
}
|
|
150
|
+
catch { }
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* A half-close that never completes is a dead pair.
|
|
154
|
+
*
|
|
155
|
+
* `a.on('end')` + `b.end()` is the graceful path, but the `close` handlers
|
|
156
|
+
* above are what actually destroy the peer, and Bun does not deliver `close`
|
|
157
|
+
* for a CONNECT socket whose client process died — it delivers `end` only.
|
|
158
|
+
* The peer therefore sits half-closed forever: measured on Windows/Bun 1.3.14
|
|
159
|
+
* as one ESTABLISHED loopback PAIR per killed client, still there 12 s later
|
|
160
|
+
* AND after the proxy handle was closed (a loopback origin never probes dead,
|
|
161
|
+
* so keepalive cannot reap it). The bound is the same order as the admission
|
|
162
|
+
* ledger's stale window: it exists to finish a teardown that has already
|
|
163
|
+
* started, never to time out a live idle tunnel.
|
|
164
|
+
*/
|
|
165
|
+
const armHalfCloseReap = () => {
|
|
166
|
+
if (halfCloseReap)
|
|
167
|
+
return;
|
|
168
|
+
halfCloseReap = setTimeout(() => {
|
|
169
|
+
for (const s of [a, b]) {
|
|
170
|
+
if (s.destroyed)
|
|
171
|
+
continue;
|
|
172
|
+
try {
|
|
173
|
+
s.destroy();
|
|
174
|
+
}
|
|
175
|
+
catch { }
|
|
176
|
+
}
|
|
177
|
+
}, opts.halfCloseReapMs ?? INGRESS_PROXY_STALE_TUNNEL_MS);
|
|
178
|
+
halfCloseReap.unref?.();
|
|
179
|
+
};
|
|
180
|
+
a.resume();
|
|
181
|
+
b.resume();
|
|
182
|
+
for (const s of [a, b]) {
|
|
183
|
+
try {
|
|
184
|
+
s.setKeepAlive(true, INGRESS_PROXY_KEEPALIVE_MS);
|
|
185
|
+
}
|
|
186
|
+
catch { }
|
|
187
|
+
}
|
|
188
|
+
}
|