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.
Files changed (400) hide show
  1. package/README.md +26 -7
  2. package/README.zh-CN.md +18 -5
  3. package/backend/dist/auth/api-keys.js +11 -0
  4. package/backend/dist/auth/key-models.d.ts +36 -0
  5. package/backend/dist/auth/key-models.js +99 -0
  6. package/backend/dist/capture/recorder.d.ts +4 -10
  7. package/backend/dist/capture/recorder.js +6 -58
  8. package/backend/dist/cli/clients/activity.js +2 -0
  9. package/backend/dist/cli/clients/base.d.ts +36 -11
  10. package/backend/dist/cli/clients/base.js +31 -15
  11. package/backend/dist/cli/clients/claude.d.ts +9 -0
  12. package/backend/dist/cli/clients/claude.js +6 -0
  13. package/backend/dist/cli/clients/codex.d.ts +78 -0
  14. package/backend/dist/cli/clients/codex.js +475 -57
  15. package/backend/dist/cli/clients/core-adapters.d.ts +1 -1
  16. package/backend/dist/cli/clients/core-adapters.js +1 -1
  17. package/backend/dist/cli/clients/dsh.d.ts +8 -0
  18. package/backend/dist/cli/clients/dsh.js +5 -0
  19. package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
  20. package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
  21. package/backend/dist/cli/clients/grok.d.ts +15 -1
  22. package/backend/dist/cli/clients/grok.js +16 -2
  23. package/backend/dist/cli/clients/index.d.ts +13 -1
  24. package/backend/dist/cli/clients/index.js +97 -19
  25. package/backend/dist/cli/clients/kimi.d.ts +6 -0
  26. package/backend/dist/cli/clients/kimi.js +3 -0
  27. package/backend/dist/cli/clients/launcher.d.ts +1 -1
  28. package/backend/dist/cli/clients/model-meta.js +6 -3
  29. package/backend/dist/cli/clients/omp.d.ts +6 -0
  30. package/backend/dist/cli/clients/omp.js +3 -0
  31. package/backend/dist/cli/clients/openclaw.d.ts +6 -0
  32. package/backend/dist/cli/clients/openclaw.js +3 -0
  33. package/backend/dist/cli/clients/opencode.d.ts +8 -0
  34. package/backend/dist/cli/clients/opencode.js +8 -2
  35. package/backend/dist/cli/clients/pi.d.ts +6 -0
  36. package/backend/dist/cli/clients/pi.js +3 -0
  37. package/backend/dist/cli/clients/reserved.js +2 -0
  38. package/backend/dist/cli/clients/update-check.d.ts +37 -0
  39. package/backend/dist/cli/clients/update-check.js +309 -0
  40. package/backend/dist/cli/clients/workbuddy.d.ts +19 -0
  41. package/backend/dist/cli/clients/workbuddy.js +66 -0
  42. package/backend/dist/cli/index.js +5 -4
  43. package/backend/dist/cli/paths.js +8 -0
  44. package/backend/dist/cli/types.d.ts +101 -16
  45. package/backend/dist/config/comments-en.js +34 -25
  46. package/backend/dist/config/comments-zh.js +33 -24
  47. package/backend/dist/config/defaults.d.ts +280 -22
  48. package/backend/dist/config/defaults.js +279 -21
  49. package/backend/dist/config/env.d.ts +10 -0
  50. package/backend/dist/config/env.js +3 -2
  51. package/backend/dist/config/index.d.ts +22 -1
  52. package/backend/dist/config/index.js +218 -43
  53. package/backend/dist/config/migrations/v0-to-v1.d.ts +2 -2
  54. package/backend/dist/config/migrations/v10-to-v11.d.ts +38 -0
  55. package/backend/dist/config/migrations/v10-to-v11.js +43 -0
  56. package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
  57. package/backend/dist/config/migrations/v4-to-v5.js +42 -0
  58. package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
  59. package/backend/dist/config/migrations/v5-to-v6.js +29 -0
  60. package/backend/dist/config/migrations/v6-to-v7.d.ts +45 -0
  61. package/backend/dist/config/migrations/v6-to-v7.js +97 -0
  62. package/backend/dist/config/migrations/v7-to-v8.d.ts +36 -0
  63. package/backend/dist/config/migrations/v7-to-v8.js +43 -0
  64. package/backend/dist/config/migrations/v8-to-v9.d.ts +38 -0
  65. package/backend/dist/config/migrations/v8-to-v9.js +43 -0
  66. package/backend/dist/config/migrations/v9-to-v10.d.ts +51 -0
  67. package/backend/dist/config/migrations/v9-to-v10.js +71 -0
  68. package/backend/dist/config/runtime.js +1 -1
  69. package/backend/dist/config/schema.d.ts +3 -3
  70. package/backend/dist/config/schema.js +18 -4
  71. package/backend/dist/config/types.d.ts +221 -41
  72. package/backend/dist/egress-proxy/asset-download.d.ts +54 -0
  73. package/backend/dist/egress-proxy/asset-download.js +420 -0
  74. package/backend/dist/egress-proxy/manual-node-spec.d.ts +92 -0
  75. package/backend/dist/egress-proxy/manual-node-spec.js +408 -0
  76. package/backend/dist/egress-proxy/mihomo-binary.d.ts +54 -0
  77. package/backend/dist/egress-proxy/mihomo-binary.js +278 -0
  78. package/backend/dist/egress-proxy/mihomo-client.d.ts +94 -0
  79. package/backend/dist/egress-proxy/mihomo-client.js +308 -0
  80. package/backend/dist/egress-proxy/mihomo-config.d.ts +40 -0
  81. package/backend/dist/egress-proxy/mihomo-config.js +161 -0
  82. package/backend/dist/egress-proxy/mihomo-geo.d.ts +87 -0
  83. package/backend/dist/egress-proxy/mihomo-geo.js +213 -0
  84. package/backend/dist/egress-proxy/mihomo-logs.d.ts +43 -0
  85. package/backend/dist/egress-proxy/mihomo-logs.js +84 -0
  86. package/backend/dist/egress-proxy/mihomo-pac.d.ts +37 -0
  87. package/backend/dist/egress-proxy/mihomo-pac.js +75 -0
  88. package/backend/dist/egress-proxy/mihomo-rules-import.d.ts +43 -0
  89. package/backend/dist/egress-proxy/mihomo-rules-import.js +193 -0
  90. package/backend/dist/egress-proxy/mihomo-sidecar.d.ts +81 -0
  91. package/backend/dist/egress-proxy/mihomo-sidecar.js +637 -0
  92. package/backend/dist/forward-proxy/egress.d.ts +50 -11
  93. package/backend/dist/forward-proxy/egress.js +63 -17
  94. package/backend/dist/forward-proxy/h2-forward.js +42 -15
  95. package/backend/dist/forward-proxy/index.d.ts +11 -8
  96. package/backend/dist/forward-proxy/index.js +27 -60
  97. package/backend/dist/forward-proxy/interceptor.d.ts +3 -2
  98. package/backend/dist/forward-proxy/interceptor.js +4 -4
  99. package/backend/dist/forward-proxy/relay.js +3 -3
  100. package/backend/dist/forward-proxy/rules.d.ts +4 -4
  101. package/backend/dist/forward-proxy/rules.js +25 -4
  102. package/backend/dist/forward-proxy/server.d.ts +12 -16
  103. package/backend/dist/forward-proxy/server.js +237 -171
  104. package/backend/dist/harness/host/hosts.js +3 -2
  105. package/backend/dist/index.js +59 -19
  106. package/backend/dist/ingress-proxy/access-log.d.ts +176 -0
  107. package/backend/dist/ingress-proxy/access-log.js +774 -0
  108. package/backend/dist/ingress-proxy/ca-inventory.d.ts +106 -0
  109. package/backend/dist/ingress-proxy/ca-inventory.js +525 -0
  110. package/backend/dist/ingress-proxy/ca-trust.d.ts +96 -0
  111. package/backend/dist/ingress-proxy/ca-trust.js +315 -0
  112. package/backend/dist/ingress-proxy/ca.d.ts +104 -0
  113. package/backend/dist/ingress-proxy/ca.js +273 -0
  114. package/backend/dist/ingress-proxy/data-dir.d.ts +28 -0
  115. package/backend/dist/ingress-proxy/data-dir.js +45 -0
  116. package/backend/dist/ingress-proxy/egress.d.ts +151 -0
  117. package/backend/dist/ingress-proxy/egress.js +364 -0
  118. package/backend/dist/ingress-proxy/h2-forward.d.ts +66 -0
  119. package/backend/dist/ingress-proxy/h2-forward.js +561 -0
  120. package/backend/dist/ingress-proxy/index.d.ts +24 -0
  121. package/backend/dist/ingress-proxy/index.js +144 -0
  122. package/backend/dist/ingress-proxy/interceptor.d.ts +25 -0
  123. package/backend/dist/ingress-proxy/interceptor.js +52 -0
  124. package/backend/dist/ingress-proxy/ordered-relay.d.ts +29 -0
  125. package/backend/dist/ingress-proxy/ordered-relay.js +46 -0
  126. package/backend/dist/ingress-proxy/relay.d.ts +54 -0
  127. package/backend/dist/ingress-proxy/relay.js +188 -0
  128. package/backend/dist/ingress-proxy/rules.d.ts +195 -0
  129. package/backend/dist/ingress-proxy/rules.js +348 -0
  130. package/backend/dist/ingress-proxy/server.d.ts +153 -0
  131. package/backend/dist/ingress-proxy/server.js +2065 -0
  132. package/backend/dist/ingress-proxy/sni.d.ts +35 -0
  133. package/backend/dist/ingress-proxy/sni.js +124 -0
  134. package/backend/dist/ingress-proxy/status.d.ts +32 -0
  135. package/backend/dist/ingress-proxy/status.js +15 -0
  136. package/backend/dist/ingress-proxy/system-proxy.d.ts +112 -0
  137. package/backend/dist/ingress-proxy/system-proxy.js +481 -0
  138. package/backend/dist/ingress-proxy/traffic-delete.d.ts +21 -0
  139. package/backend/dist/ingress-proxy/traffic-delete.js +64 -0
  140. package/backend/dist/ingress-proxy/traffic-delete.worker.d.ts +44 -0
  141. package/backend/dist/ingress-proxy/traffic-delete.worker.js +228 -0
  142. package/backend/dist/ingress-proxy/traffic-files.d.ts +10 -0
  143. package/backend/dist/ingress-proxy/traffic-files.js +10 -0
  144. package/backend/dist/ingress-proxy/upstream-tls.d.ts +46 -0
  145. package/backend/dist/ingress-proxy/upstream-tls.js +105 -0
  146. package/backend/dist/ingress-proxy/ws-frames.d.ts +45 -0
  147. package/backend/dist/ingress-proxy/ws-frames.js +153 -0
  148. package/backend/dist/ir/adapters/anthropic-messages-stream.js +6 -1
  149. package/backend/dist/ir/adapters/anthropic-messages.js +12 -5
  150. package/backend/dist/ir/adapters/google-gemini-stream.js +7 -2
  151. package/backend/dist/ir/adapters/google-gemini.js +5 -2
  152. package/backend/dist/ir/adapters/openai-chat-stream.js +5 -1
  153. package/backend/dist/ir/adapters/openai-chat.d.ts +25 -0
  154. package/backend/dist/ir/adapters/openai-chat.js +50 -6
  155. package/backend/dist/ir/adapters/openai-responses-output.d.ts +1 -0
  156. package/backend/dist/ir/adapters/openai-responses-output.js +67 -21
  157. package/backend/dist/ir/adapters/openai-responses-stream.d.ts +13 -0
  158. package/backend/dist/ir/adapters/openai-responses-stream.js +34 -1
  159. package/backend/dist/ir/adapters/openai-responses.d.ts +92 -1
  160. package/backend/dist/ir/adapters/openai-responses.js +163 -12
  161. package/backend/dist/ir/capabilities.js +4 -0
  162. package/backend/dist/ir/media.d.ts +20 -0
  163. package/backend/dist/ir/media.js +41 -0
  164. package/backend/dist/ir/tool-identity.d.ts +35 -0
  165. package/backend/dist/ir/tool-identity.js +40 -0
  166. package/backend/dist/ir/types.d.ts +9 -1
  167. package/backend/dist/ir/validate.d.ts +24 -0
  168. package/backend/dist/ir/validate.js +113 -63
  169. package/backend/dist/local/build-jobs.d.ts +66 -0
  170. package/backend/dist/local/build-jobs.js +243 -0
  171. package/backend/dist/local/detect.d.ts +32 -0
  172. package/backend/dist/local/detect.js +145 -0
  173. package/backend/dist/local/draft-match.d.ts +58 -0
  174. package/backend/dist/local/draft-match.js +124 -0
  175. package/backend/dist/local/engine-runtime.d.ts +522 -0
  176. package/backend/dist/local/engine-runtime.js +1 -0
  177. package/backend/dist/local/engines.d.ts +241 -0
  178. package/backend/dist/local/engines.js +651 -0
  179. package/backend/dist/local/gguf.d.ts +35 -0
  180. package/backend/dist/local/gguf.js +314 -0
  181. package/backend/dist/local/hf.d.ts +120 -0
  182. package/backend/dist/local/hf.js +304 -0
  183. package/backend/dist/local/install.d.ts +90 -0
  184. package/backend/dist/local/install.js +421 -0
  185. package/backend/dist/local/llamacpp.d.ts +55 -0
  186. package/backend/dist/local/llamacpp.js +177 -0
  187. package/backend/dist/local/local-provider.d.ts +81 -0
  188. package/backend/dist/local/local-provider.js +301 -0
  189. package/backend/dist/local/machine-stats.d.ts +87 -0
  190. package/backend/dist/local/machine-stats.js +332 -0
  191. package/backend/dist/local/model-store.d.ts +347 -0
  192. package/backend/dist/local/model-store.js +1215 -0
  193. package/backend/dist/local/part-sweep.d.ts +32 -0
  194. package/backend/dist/local/part-sweep.js +156 -0
  195. package/backend/dist/local/plan.d.ts +65 -0
  196. package/backend/dist/local/plan.js +146 -0
  197. package/backend/dist/local/resources.d.ts +49 -0
  198. package/backend/dist/local/resources.js +64 -0
  199. package/backend/dist/local/run-stats.d.ts +95 -0
  200. package/backend/dist/local/run-stats.js +195 -0
  201. package/backend/dist/local/runner.d.ts +235 -0
  202. package/backend/dist/local/runner.js +1392 -0
  203. package/backend/dist/local/settings.d.ts +79 -0
  204. package/backend/dist/local/settings.js +180 -0
  205. package/backend/dist/local/strata-catalog.d.ts +30 -0
  206. package/backend/dist/local/strata-catalog.js +511 -0
  207. package/backend/dist/local/strata-drafting.d.ts +46 -0
  208. package/backend/dist/local/strata-drafting.js +265 -0
  209. package/backend/dist/local/strata.d.ts +278 -0
  210. package/backend/dist/local/strata.js +1392 -0
  211. package/backend/dist/local/tar.d.ts +20 -0
  212. package/backend/dist/local/tar.js +367 -0
  213. package/backend/dist/local/transport.d.ts +35 -0
  214. package/backend/dist/local/transport.js +89 -0
  215. package/backend/dist/local/tune.d.ts +58 -0
  216. package/backend/dist/local/tune.js +324 -0
  217. package/backend/dist/observability/http-exchange.d.ts +2 -2
  218. package/backend/dist/opencode/catalog/auto-pull.d.ts +14 -3
  219. package/backend/dist/opencode/catalog/auto-pull.js +284 -77
  220. package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
  221. package/backend/dist/opencode/catalog/ocr-store.js +4 -2
  222. package/backend/dist/opencode/catalog/overrides-store.d.ts +15 -4
  223. package/backend/dist/opencode/catalog/overrides-store.js +28 -19
  224. package/backend/dist/opencode/catalog/reasoning-declaration.d.ts +35 -0
  225. package/backend/dist/opencode/catalog/reasoning-declaration.js +66 -0
  226. package/backend/dist/opencode/catalog/repository.js +28 -5
  227. package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
  228. package/backend/dist/opencode/catalog/sources/models-dev.js +42 -14
  229. package/backend/dist/opencode/catalog/types.d.ts +42 -12
  230. package/backend/dist/opencode/catalog/types.js +38 -1
  231. package/backend/dist/opencode/credentials/def-materialize.js +27 -21
  232. package/backend/dist/opencode/credentials/ocr-store.js +11 -2
  233. package/backend/dist/opencode/credentials/sync.js +12 -3
  234. package/backend/dist/opencode/credentials/types.d.ts +31 -4
  235. package/backend/dist/opencode/credentials/types.js +25 -0
  236. package/backend/dist/opencode/migrate/engine.d.ts +20 -0
  237. package/backend/dist/opencode/migrate/engine.js +71 -0
  238. package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
  239. package/backend/dist/opencode/migrate/migrator.js +6 -0
  240. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
  241. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
  242. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
  243. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
  244. package/backend/dist/opencode/probe.d.ts +21 -4
  245. package/backend/dist/opencode/probe.js +34 -10
  246. package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
  247. package/backend/dist/opencode/provider-def-adapters.js +43 -27
  248. package/backend/dist/opencode/provider-defs.d.ts +10 -16
  249. package/backend/dist/opencode/provider-defs.js +45 -45
  250. package/backend/dist/opencode/user-config.d.ts +23 -26
  251. package/backend/dist/opencode/user-config.js +95 -77
  252. package/backend/dist/pipeline/directives.d.ts +9 -4
  253. package/backend/dist/pipeline/directives.js +14 -10
  254. package/backend/dist/pipeline/orchestrator.d.ts +42 -13
  255. package/backend/dist/pipeline/orchestrator.js +514 -172
  256. package/backend/dist/plugins/builtin/model-gateway.js +38 -12
  257. package/backend/dist/plugins/environment-ack.d.ts +51 -0
  258. package/backend/dist/plugins/environment-ack.js +81 -0
  259. package/backend/dist/plugins/gateways.d.ts +6 -6
  260. package/backend/dist/plugins/gateways.js +2 -2
  261. package/backend/dist/plugins/host.d.ts +100 -16
  262. package/backend/dist/plugins/host.js +637 -99
  263. package/backend/dist/plugins/install-run.d.ts +27 -0
  264. package/backend/dist/plugins/install-run.js +99 -0
  265. package/backend/dist/plugins/manifest.d.ts +84 -32
  266. package/backend/dist/plugins/manifest.js +149 -45
  267. package/backend/dist/plugins/market-install.d.ts +18 -0
  268. package/backend/dist/plugins/market-install.js +111 -0
  269. package/backend/dist/plugins/market-source.d.ts +100 -0
  270. package/backend/dist/plugins/market-source.js +449 -0
  271. package/backend/dist/plugins/market-updates.d.ts +70 -0
  272. package/backend/dist/plugins/market-updates.js +97 -0
  273. package/backend/dist/plugins/market.d.ts +677 -0
  274. package/backend/dist/plugins/market.js +2113 -0
  275. package/backend/dist/plugins/source-index.d.ts +155 -0
  276. package/backend/dist/plugins/source-index.js +217 -0
  277. package/backend/dist/plugins/types.d.ts +402 -37
  278. package/backend/dist/projects/worktrees.d.ts +88 -0
  279. package/backend/dist/projects/worktrees.js +220 -0
  280. package/backend/dist/providers/boot-direct.d.ts +41 -7
  281. package/backend/dist/providers/boot-direct.js +284 -44
  282. package/backend/dist/providers/compat/tool-markup-recovery.js +31 -6
  283. package/backend/dist/providers/dial-wire.d.ts +17 -0
  284. package/backend/dist/providers/dial-wire.js +49 -0
  285. package/backend/dist/providers/executors/dispatch.d.ts +17 -7
  286. package/backend/dist/providers/executors/dispatch.js +28 -9
  287. package/backend/dist/providers/executors/openai-chat.js +14 -2
  288. package/backend/dist/providers/executors/plugin-adapter.d.ts +23 -1
  289. package/backend/dist/providers/executors/plugin-adapter.js +59 -3
  290. package/backend/dist/providers/member-match.d.ts +32 -9
  291. package/backend/dist/providers/member-match.js +65 -21
  292. package/backend/dist/providers/model-resolution.d.ts +62 -0
  293. package/backend/dist/providers/model-resolution.js +62 -0
  294. package/backend/dist/providers/price-order.d.ts +51 -0
  295. package/backend/dist/providers/price-order.js +54 -0
  296. package/backend/dist/providers/protocols-field.d.ts +24 -0
  297. package/backend/dist/providers/protocols-field.js +66 -0
  298. package/backend/dist/providers/provider-takedown.d.ts +5 -2
  299. package/backend/dist/providers/registry.d.ts +87 -26
  300. package/backend/dist/providers/registry.js +232 -121
  301. package/backend/dist/providers/selection.d.ts +91 -0
  302. package/backend/dist/providers/selection.js +158 -0
  303. package/backend/dist/providers/virtual-meta.d.ts +33 -2
  304. package/backend/dist/providers/virtual-meta.js +74 -18
  305. package/backend/dist/quota/cli-login.d.ts +25 -4
  306. package/backend/dist/quota/cli-login.js +38 -6
  307. package/backend/dist/quota/coverage-generation.d.ts +24 -0
  308. package/backend/dist/quota/coverage-generation.js +29 -0
  309. package/backend/dist/quota/declarations.js +8 -4
  310. package/backend/dist/quota/engine.js +2 -2
  311. package/backend/dist/quota/prober.d.ts +43 -2
  312. package/backend/dist/quota/prober.js +97 -22
  313. package/backend/dist/ratelimit/rate-limiter.d.ts +1 -1
  314. package/backend/dist/resilience/error-classifier.js +29 -0
  315. package/backend/dist/router/index.d.ts +1 -1
  316. package/backend/dist/router/index.js +17 -1
  317. package/backend/dist/router/layer2-decision.d.ts +1 -1
  318. package/backend/dist/router/layer2-decision.js +2 -2
  319. package/backend/dist/routes/console.js +1043 -405
  320. package/backend/dist/routes/environments.js +1 -1
  321. package/backend/dist/routes/local-models.d.ts +2 -0
  322. package/backend/dist/routes/local-models.js +1414 -0
  323. package/backend/dist/routes/mihomo.d.ts +2 -2
  324. package/backend/dist/routes/mihomo.js +20 -11
  325. package/backend/dist/routes/projects.js +121 -0
  326. package/backend/dist/server.js +409 -15
  327. package/backend/dist/session/session-manager.d.ts +42 -5
  328. package/backend/dist/session/session-manager.js +64 -11
  329. package/backend/dist/session/session-row.d.ts +29 -8
  330. package/backend/dist/session/session-row.js +18 -13
  331. package/backend/dist/snapshot/bundle.d.ts +40 -0
  332. package/backend/dist/snapshot/bundle.js +177 -0
  333. package/backend/dist/snapshot/handoff/compress.d.ts +46 -0
  334. package/backend/dist/snapshot/handoff/compress.js +77 -0
  335. package/backend/dist/snapshot/handoff/index.d.ts +119 -0
  336. package/backend/dist/snapshot/handoff/index.js +160 -0
  337. package/backend/dist/snapshot/handoff/jsonl-writer.d.ts +78 -0
  338. package/backend/dist/snapshot/handoff/jsonl-writer.js +175 -0
  339. package/backend/dist/snapshot/handoff/opencode-writer.d.ts +51 -0
  340. package/backend/dist/snapshot/handoff/opencode-writer.js +214 -0
  341. package/backend/dist/snapshot/handoff/summarize.d.ts +39 -0
  342. package/backend/dist/snapshot/handoff/summarize.js +118 -0
  343. package/backend/dist/snapshot/handoff/transcript.d.ts +71 -0
  344. package/backend/dist/snapshot/handoff/transcript.js +167 -0
  345. package/backend/dist/snapshot/media-fs.d.ts +10 -0
  346. package/backend/dist/snapshot/media-fs.js +50 -0
  347. package/backend/dist/snapshot/media.d.ts +32 -0
  348. package/backend/dist/snapshot/media.js +87 -0
  349. package/backend/dist/snapshot/store.d.ts +226 -0
  350. package/backend/dist/snapshot/store.js +887 -0
  351. package/backend/dist/snapshot/tree.d.ts +112 -0
  352. package/backend/dist/snapshot/tree.js +207 -0
  353. package/backend/dist/snapshot/types.d.ts +212 -0
  354. package/backend/dist/snapshot/types.js +14 -0
  355. package/backend/dist/snapshot/view.d.ts +19 -0
  356. package/backend/dist/snapshot/view.js +57 -0
  357. package/backend/dist/snapshot/write-worker.d.ts +67 -0
  358. package/backend/dist/snapshot/write-worker.js +129 -0
  359. package/backend/dist/surfaces/anthropic.js +4 -1
  360. package/backend/dist/surfaces/body-admission.d.ts +344 -0
  361. package/backend/dist/surfaces/body-admission.js +818 -0
  362. package/backend/dist/surfaces/chat-pipeline.js +8 -0
  363. package/backend/dist/surfaces/decision-pipeline.js +10 -7
  364. package/backend/dist/surfaces/gateway-catalog.d.ts +26 -0
  365. package/backend/dist/surfaces/gateway-catalog.js +202 -0
  366. package/backend/dist/surfaces/gateway-chat.d.ts +7 -11
  367. package/backend/dist/surfaces/gateway-chat.js +50 -12
  368. package/backend/dist/surfaces/ocr-headers.d.ts +6 -4
  369. package/backend/dist/surfaces/ocr-headers.js +11 -7
  370. package/backend/dist/surfaces/systemone.js +1 -1
  371. package/backend/dist/surfaces/transport-fastify.js +32 -5
  372. package/backend/dist/surfaces/transport-node-http.d.ts +51 -6
  373. package/backend/dist/surfaces/transport-node-http.js +76 -16
  374. package/backend/dist/surfaces/types.d.ts +11 -3
  375. package/backend/dist/trace/persist.js +21 -1
  376. package/backend/dist/trace/tracker.d.ts +35 -3
  377. package/backend/dist/trace/tracker.js +23 -0
  378. package/backend/dist/types/openai.d.ts +8 -0
  379. package/backend/dist/types/router.d.ts +17 -6
  380. package/backend/dist/types/router.js +14 -2
  381. package/backend/dist/utils/client-families.d.ts +66 -0
  382. package/backend/dist/utils/client-families.js +127 -0
  383. package/backend/dist/utils/event-ring.d.ts +1 -1
  384. package/backend/dist/utils/event-ring.js +1 -1
  385. package/backend/dist/utils/proxy-node.js +1 -1
  386. package/backend/dist/utils/proxy.d.ts +135 -11
  387. package/backend/dist/utils/proxy.js +144 -29
  388. package/backend/dist/utils/run-command.d.ts +21 -1
  389. package/backend/dist/utils/run-command.js +64 -4
  390. package/backend/dist/utils/server-liveness.d.ts +28 -0
  391. package/backend/dist/utils/server-liveness.js +32 -0
  392. package/backend/dist/utils/session-file.d.ts +28 -0
  393. package/backend/dist/utils/session-file.js +34 -0
  394. package/frontend/dist/assets/antigravity.color-DXFfVr6X.svg +39 -0
  395. package/frontend/dist/assets/gemini-cli.color-BfquLd1p.svg +1 -0
  396. package/frontend/dist/assets/index-CTZNvn1d.js +1707 -0
  397. package/frontend/dist/assets/{index-DxZ9MHKB.css → index-CqDSOPQ0.css} +1 -1
  398. package/frontend/dist/index.html +2 -2
  399. package/package.json +3 -1
  400. package/frontend/dist/assets/index-55VVwfFQ.js +0 -1521
@@ -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
+ }