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
@@ -130,6 +130,14 @@ export async function runChatSurface(t, surface, orchestrator, body) {
130
130
  // Capture keeps the client's protocol envelope; IR belongs to routing
131
131
  // and execution, never to the inbound wire archive.
132
132
  clientBody: body,
133
+ // A client that disconnected mid-stream leaves the upstream draining into
134
+ // a dead socket. This probe lets the snapshot plane record such a turn as
135
+ // `aborted` rather than `completed` (ADR-0040). Transport-owned so a
136
+ // non-Fastify leg may omit it.
137
+ isClientGone: () => t.isClientGone(),
138
+ // Sticky variant for the snapshot plane (ADR-0040): "the client left at
139
+ // some point during this turn" — still true after the upstream drained.
140
+ ...(t.didClientLeave ? { didClientLeave: () => t.didClientLeave() } : {}),
133
141
  ...t.captureProcessContext(),
134
142
  }, relay);
135
143
  if (streamed) {
@@ -75,8 +75,8 @@ export async function runDecisionSurface(t, orchestrator, body) {
75
75
  }
76
76
  // Chain head of the healthy allowed pool (weight/priority order from
77
77
  // buildTierPoolEntries) — deterministic per pool state. The chat pool's
78
- // weighted/round-robin strategies are a chat-surface nicety, not a
79
- // decision-surface one.
78
+ // rotation strategies (`weighted_round_robin` / `round_robin`) are a
79
+ // chat-surface nicety, not a decision-surface one.
80
80
  const healthyAllowed = registry
81
81
  .getCandidateModelsForTier(tier, true, { decisionSurface: true })
82
82
  .filter((m) => isModelAllowed(m.id, policy, tier));
@@ -220,14 +220,17 @@ export async function runDecisionSurface(t, orchestrator, body) {
220
220
  // this decision (the request slot was already consumed; same honesty as
221
221
  // failed chat turns). costUsd approximation: this wire has no cached/
222
222
  // reasoning split, so input bills at FULL input price — a deliberate
223
- // conservative over-count for budgets.
223
+ // conservative over-count for budgets. A plugin that reported the vendor's
224
+ // own committed cost (`vendorCostUsd`, stamped on the IR usage) is the
225
+ // invoice, so it wins over that estimate here exactly as on the chat wire.
224
226
  const rlUsage = decision.response.usage
225
227
  ? {
226
228
  tokens: (decision.response.usage.input_tokens ?? 0) + (decision.response.usage.output_tokens ?? 0),
227
- costUsd: computeRequestCost({
228
- inputTokens: decision.response.usage.input_tokens ?? 0,
229
- outputTokens: decision.response.usage.output_tokens ?? 0,
230
- }, model.pricing),
229
+ costUsd: decision.response.usage.vendorCostUsd ??
230
+ computeRequestCost({
231
+ inputTokens: decision.response.usage.input_tokens ?? 0,
232
+ outputTokens: decision.response.usage.output_tokens ?? 0,
233
+ }, model.pricing),
231
234
  }
232
235
  : undefined;
233
236
  if (rlUsage) {
@@ -0,0 +1,26 @@
1
+ import type { ProviderRegistry } from '../providers/registry.js';
2
+ import type { CatalogProviderRecord } from '../opencode/catalog/types.js';
3
+ import type { GatewayCatalog } from '../plugins/types.js';
4
+ /**
5
+ * Async-refresh snapshot: `catalog()` is a SYNC host seam called on the
6
+ * request path, so a registry change kicks a background rebuild and the
7
+ * previous snapshot keeps serving until it lands. The first call after boot
8
+ * answers with ids only (the pre-existing contract) — never a blocked request.
9
+ */
10
+ export declare class GatewayCatalogProjection {
11
+ private readonly registry;
12
+ private readonly listCatalog;
13
+ private snapshot;
14
+ private names;
15
+ private builtSignature;
16
+ private inFlight;
17
+ constructor(registry: ProviderRegistry, listCatalog: () => Promise<CatalogProviderRecord[]>);
18
+ get(): GatewayCatalog;
19
+ /**
20
+ * Catalog display name for a gateway-visible id, read from the SAME
21
+ * snapshot as `get()`. Ensure-first: a caller that only ever resolves
22
+ * models still kicks the (best-effort) build. Undefined until the first
23
+ * build lands (or when the catalog states none) — never a guess.
24
+ */
25
+ nameOf(id: string): string | undefined;
26
+ }
@@ -0,0 +1,202 @@
1
+ import { comboEnvelope, findMemberCatalogRecords, tierAliasEnvelope, TIER_LADDER, } from '../providers/virtual-meta.js';
2
+ import { EFFORT_LADDER, modelSupportsEfforts } from '../types/router.js';
3
+ /**
4
+ * The capability half of the gateway catalog handed to client-gateway plugins
5
+ * (ADR-0017 `catalog()`).
6
+ *
7
+ * A vendor client draws its model picker, its compaction budget and its
8
+ * thinking-level control from whatever the gateway advertises. The ids alone
9
+ * are not enough: with capabilities absent a client either invents a number
10
+ * (Cursor's 200K constant compacted a 1M-context model early) or offers no
11
+ * level at all. This module projects the REAL facts the routing plane already
12
+ * holds — the resolved effort ladder (post ADR-0035 `none` withholding) and the
13
+ * catalog `limit` / modalities — into ONE map keyed by gateway-visible id.
14
+ *
15
+ * Shape rules (they are what keeps the advertisement honest):
16
+ * - a concrete id reports what its registration will actually serve;
17
+ * - a virtual id (`auto` / tier alias / combo) reports the member-set
18
+ * envelope for LIMITS (declared rung window for tier aliases and `auto`
19
+ * per ADR-0041, safe-min context for combos, intersection vision) and the
20
+ * permissive full ladder for EFFORT — the gateway clamps per request and
21
+ * reports the served level on `X-OCR-Thinking-*`, the same contract
22
+ * `/v1/models` already publishes for virtual refs (see virtual-meta.ts);
23
+ * - an id whose facts are unknown is ABSENT from the map, never defaulted.
24
+ */
25
+ /** Limiting envelope values for a virtual ref, in the gateway vocabulary. */
26
+ function virtualCapabilities(env) {
27
+ return {
28
+ ...(env.contextWindow ? { contextWindow: env.contextWindow } : {}),
29
+ ...(env.maxTokens ? { maxOutputTokens: env.maxTokens } : {}),
30
+ ...(env.imageInput ? { vision: true } : {}),
31
+ // Virtual refs resolve their member per request; the gateway clamps to
32
+ // what the member can serve, so the ladder is advertised permissively —
33
+ // exactly the claim `virtualModelsDevBlock` already makes for
34
+ // `/v1/models` (reasoning: true + the full ladder). Keeping the two
35
+ // surfaces identical matters more than a per-pool intersection the
36
+ // client cannot act on.
37
+ ...(env.memberCount > 0
38
+ ? { thinking: true, supportedEfforts: [...EFFORT_LADDER] }
39
+ : {}),
40
+ };
41
+ }
42
+ function concreteCapabilities(cat, supported, defaultEffort) {
43
+ const vision = cat?.attachment === true ||
44
+ (Array.isArray(cat?.modalities?.input) && cat.modalities.input.includes('image'));
45
+ // Tri-state: a declared `reasoning: false` is the catalog SAYING it does not
46
+ // reason; an absent field is "not stated" and must not be turned into a
47
+ // claim either way. A resolved ladder implies reasoning.
48
+ const reasoningDeclared = cat?.reasoning === false ? false : cat?.reasoning === true ? true : undefined;
49
+ const thinks = reasoningDeclared ?? (supported && supported.length > 0 ? true : undefined);
50
+ // A pin the ladder cannot serve is not a fact this id can state — the
51
+ // pipeline would clamp the ask away, so advertising it would pre-select a
52
+ // level the request never sends. Publish it only where it survives.
53
+ const pinned = defaultEffort && supported?.includes(defaultEffort) ? defaultEffort : undefined;
54
+ return {
55
+ ...(cat?.limit?.context ? { contextWindow: cat.limit.context } : {}),
56
+ ...(cat?.limit?.output ? { maxOutputTokens: cat.limit.output } : {}),
57
+ ...(vision ? { vision: true } : {}),
58
+ ...(thinks !== undefined ? { thinking: thinks } : {}),
59
+ ...(supported && supported.length > 0 ? { supportedEfforts: [...supported] } : {}),
60
+ ...(pinned ? { defaultEffort: pinned } : {}),
61
+ };
62
+ }
63
+ /**
64
+ * Registry identity for the projection: every input that can change the
65
+ * result without a source sync (model ids, home tiers, resolved effort
66
+ * tables, the always-think fact, variant siblings, combo compositions).
67
+ * Catalog-side drift is picked up on the next rebuild regardless — a catalog
68
+ * sync lands far less often than a console save.
69
+ */
70
+ function registrySignature(registry) {
71
+ const parts = [];
72
+ for (const model of registry.getAllModels()) {
73
+ parts.push(`${model.id}\u0001${model.tier ?? ''}\u0001${(model.supportedReasoningEfforts ?? []).join(',')}` +
74
+ `\u0001${model.supportsReasoningEffort === true ? '1' : ''}\u0001${model.reasoningDisableable === false ? '0' : ''}` +
75
+ `\u0001${model.defaultEffort ?? ''}`);
76
+ }
77
+ for (const variant of registry.getVariantExposures())
78
+ parts.push(`v:${variant.id}`);
79
+ for (const combo of registry.getCombos()) {
80
+ parts.push(`c:${combo.id}\u0001${combo.disabled === true ? 'off' : 'on'}\u0001${combo.models
81
+ .map((m) => (typeof m === 'string' ? m : m.id))
82
+ .join(',')}`);
83
+ }
84
+ return parts.join('\u0002');
85
+ }
86
+ /** Ids-only catalog — the pre-capability shape, used while a build is in flight. */
87
+ function baseCatalog(registry) {
88
+ return {
89
+ virtualModels: ['auto', ...TIER_LADDER],
90
+ models: registry.getAllModels().map((m) => ({ id: m.id, label: m.upstreamModel })),
91
+ };
92
+ }
93
+ /** Build the capability map against one catalog snapshot. */
94
+ async function project(registry, listCatalog) {
95
+ const catalog = baseCatalog(registry);
96
+ const capabilities = {};
97
+ // Memoize the catalog list for this build: every envelope / lookup call
98
+ // would otherwise re-fetch the same in-memory aggregate.
99
+ let providers;
100
+ const listOnce = async () => {
101
+ if (!providers) {
102
+ try {
103
+ providers = await listCatalog();
104
+ }
105
+ catch {
106
+ providers = [];
107
+ }
108
+ }
109
+ return providers;
110
+ };
111
+ const models = registry.getAllModels();
112
+ const { byId } = await findMemberCatalogRecords(models.map((m) => m.id), listOnce);
113
+ // The display name rides on the SAME snapshot as the capabilities: a
114
+ // resolution read is synchronous and must never await the catalog. Absent
115
+ // name (no record, or a record that states none) stays absent.
116
+ const names = new Map();
117
+ for (const [id, cat] of byId) {
118
+ const name = typeof cat.name === 'string' ? cat.name.trim() : '';
119
+ if (name)
120
+ names.set(id, name);
121
+ }
122
+ for (const model of models) {
123
+ const supported = modelSupportsEfforts(model.supportedReasoningEfforts, model.supportsReasoningEffort, model.reasoningDisableable);
124
+ const variants = (model.variants ?? []).map((v) => ({
125
+ id: `${model.id}-${v.id}`,
126
+ effort: v.reasoningEffort,
127
+ }));
128
+ capabilities[model.id] = {
129
+ ...concreteCapabilities(byId.get(model.id), supported, model.defaultEffort),
130
+ ...(variants.length > 0 ? { variants } : {}),
131
+ };
132
+ }
133
+ // Virtual refs (auto + tier aliases) and combos: member-set envelope.
134
+ for (const alias of ['auto', ...TIER_LADDER]) {
135
+ const env = await tierAliasEnvelope(registry, listOnce, alias);
136
+ if (env.memberCount === 0)
137
+ continue;
138
+ capabilities[alias] = virtualCapabilities(env);
139
+ }
140
+ for (const combo of registry.getCombos()) {
141
+ if (combo.disabled === true)
142
+ continue;
143
+ const env = await comboEnvelope(registry, listOnce, combo);
144
+ if (env.memberCount === 0)
145
+ continue;
146
+ capabilities[combo.id] = virtualCapabilities(env);
147
+ }
148
+ return { catalog: { ...catalog, capabilities }, names };
149
+ }
150
+ /**
151
+ * Async-refresh snapshot: `catalog()` is a SYNC host seam called on the
152
+ * request path, so a registry change kicks a background rebuild and the
153
+ * previous snapshot keeps serving until it lands. The first call after boot
154
+ * answers with ids only (the pre-existing contract) — never a blocked request.
155
+ */
156
+ export class GatewayCatalogProjection {
157
+ registry;
158
+ listCatalog;
159
+ snapshot;
160
+ names;
161
+ builtSignature = '';
162
+ inFlight;
163
+ constructor(registry, listCatalog) {
164
+ this.registry = registry;
165
+ this.listCatalog = listCatalog;
166
+ }
167
+ get() {
168
+ const signature = registrySignature(this.registry);
169
+ if (this.snapshot && this.builtSignature === signature)
170
+ return this.snapshot;
171
+ if (this.inFlight !== signature) {
172
+ this.inFlight = signature;
173
+ void project(this.registry, this.listCatalog)
174
+ .then((next) => {
175
+ // A rebuild for a stale signature must not overwrite a newer one.
176
+ if (this.inFlight !== signature)
177
+ return;
178
+ this.snapshot = next.catalog;
179
+ this.names = next.names;
180
+ this.builtSignature = signature;
181
+ })
182
+ .catch(() => {
183
+ // best effort — the ids-only shape keeps serving
184
+ })
185
+ .finally(() => {
186
+ if (this.inFlight === signature)
187
+ this.inFlight = undefined;
188
+ });
189
+ }
190
+ return this.snapshot ?? baseCatalog(this.registry);
191
+ }
192
+ /**
193
+ * Catalog display name for a gateway-visible id, read from the SAME
194
+ * snapshot as `get()`. Ensure-first: a caller that only ever resolves
195
+ * models still kicks the (best-effort) build. Undefined until the first
196
+ * build lands (or when the catalog states none) — never a guess.
197
+ */
198
+ nameOf(id) {
199
+ this.get();
200
+ return this.names?.get(id);
201
+ }
202
+ }
@@ -1,10 +1,10 @@
1
1
  import type { PipelineOrchestrator } from '../pipeline/orchestrator.js';
2
- import type { GatewayChatSink } from '../plugins/types.js';
2
+ import type { GatewayCatalog, GatewayChatSink, GatewayModelResolution } from '../plugins/types.js';
3
3
  import type { ApiKeyConfig } from '../config/types.js';
4
4
  /**
5
5
  * In-process chat seam for client-gateway plugins (ADR-0017).
6
6
  *
7
- * `startForwardProxy` wires the services once with the live orchestrator; a
7
+ * `startIngressProxy` wires the services once with the live orchestrator; a
8
8
  * gateway then runs ONE canonical OpenAI-shaped completion through the SAME
9
9
  * `dispatchSurface` pipeline as /v1/chat/completions — model resolution,
10
10
  * tiers, breakers, captures all apply — and receives exactly the SSE frames
@@ -32,16 +32,12 @@ export interface GatewayChatRunOptions {
32
32
  export interface GatewayChatServices {
33
33
  /** One canonical chat completion; terminal discipline via the sink. */
34
34
  run(body: Record<string, unknown>, sink: GatewayChatSink, signal: AbortSignal | undefined, opts?: GatewayChatRunOptions): Promise<void>;
35
- /** Current routing surface for AvailableModels-style fabrication. */
36
- catalog(): {
37
- virtualModels: string[];
38
- models: {
39
- id: string;
40
- label?: string;
41
- }[];
42
- };
35
+ /** Current routing surface (+ capability map) for AvailableModels-style fabrication. */
36
+ catalog(): GatewayCatalog;
37
+ /** Draw-free description of what an id addresses (see resolveModel). */
38
+ resolveModel?(modelId: string): GatewayModelResolution;
43
39
  }
44
- /** Wired once by forward-proxy/index.ts (it holds the orchestrator). */
40
+ /** Wired once by ingress-proxy/index.ts (it holds the orchestrator). */
45
41
  export declare function setGatewayChatServices(s: GatewayChatServices | undefined): void;
46
42
  /** Lookup for the plugin-host SDK (undefined = core not booted yet). */
47
43
  export declare function getGatewayChatServices(): GatewayChatServices | undefined;
@@ -1,13 +1,24 @@
1
1
  import { dispatchSurface } from './dispatch.js';
2
2
  import { chatSurface } from './chat.js';
3
- import { TIER_LADDER } from '../providers/virtual-meta.js';
3
+ import { resolveModel } from '../providers/model-resolution.js';
4
+ import { GatewayCatalogProjection } from './gateway-catalog.js';
4
5
  import { loadConfig } from '../config/index.js';
5
6
  import { checkModelAccess, getModelAccessPolicy } from '../auth/model-access.js';
6
7
  import { isApiKeyUsable } from '../auth/api-keys.js';
7
8
  import { apiKeySubject, getRateLimiter } from '../ratelimit/rate-limiter.js';
8
9
  import { recordRateLimitEvent } from '../ratelimit/event-log.js';
10
+ function explicitResolution(kind, model, rawModelId, factModelName) {
11
+ return {
12
+ kind,
13
+ rawModelId,
14
+ factModelId: model.id,
15
+ provider: model.provider,
16
+ ...(model.wire ? { wire: model.wire } : {}),
17
+ ...(factModelName ? { factModelName } : {}),
18
+ };
19
+ }
9
20
  let services;
10
- /** Wired once by forward-proxy/index.ts (it holds the orchestrator). */
21
+ /** Wired once by ingress-proxy/index.ts (it holds the orchestrator). */
11
22
  export function setGatewayChatServices(s) {
12
23
  services = s;
13
24
  }
@@ -26,15 +37,41 @@ export function resolveGatewayKey(keyId, lookup = lookupConfiguredKey) {
26
37
  }
27
38
  /** Build the services over an orchestrator: dispatch + callback transport. */
28
39
  export function buildGatewayChatServices(orchestrator, resolveKey = lookupConfiguredKey) {
40
+ // ONE projection per boot: the capability map is rebuilt in the background
41
+ // when the registry drifts, so the synchronous `catalog()` seam stays free
42
+ // of per-request aggregation.
43
+ const catalog = new GatewayCatalogProjection(orchestrator.getRegistry(), async () => (await import('../opencode/catalog/repository.js')).catalogRepository.list());
29
44
  return {
30
- catalog: () => ({
31
- // Canonical display order: auto spans the TIER_LADDER escalation rungs.
32
- virtualModels: ['auto', ...TIER_LADDER],
33
- models: orchestrator
34
- .getRegistry()
35
- .getAllModels()
36
- .map((m) => ({ id: m.id, label: m.upstreamModel })),
37
- }),
45
+ catalog: () => catalog.get(),
46
+ // Registry ladder plus the catalog name snapshot — no session, no
47
+ // selection, no cursor advance. This is the same ladder the chat dispatch
48
+ // will walk, so an explicit ref's physical model (and therefore its prompt
49
+ // family) is known up front; the display name is the last family signal
50
+ // when the id and upstream name are both opaque.
51
+ resolveModel: (modelId) => {
52
+ const resolved = resolveModel(modelId, orchestrator.getRegistry());
53
+ switch (resolved.kind) {
54
+ case 'registered':
55
+ return explicitResolution('registered', resolved.model, modelId, catalog.nameOf(resolved.model.id));
56
+ case 'legacy':
57
+ return explicitResolution('legacy', resolved.model, modelId, catalog.nameOf(resolved.model.id));
58
+ case 'variant':
59
+ return {
60
+ ...explicitResolution('variant', resolved.model, modelId, catalog.nameOf(resolved.model.id)),
61
+ variantId: resolved.variantId,
62
+ };
63
+ case 'tier':
64
+ return { kind: 'tier', rawModelId: modelId };
65
+ case 'combo':
66
+ return { kind: 'combo', rawModelId: modelId };
67
+ case 'auto':
68
+ return { kind: 'auto', rawModelId: modelId };
69
+ case 'unresolved':
70
+ return { kind: 'unresolved', rawModelId: modelId };
71
+ case 'error':
72
+ return { kind: 'unknown', rawModelId: modelId, error: resolved.message };
73
+ }
74
+ },
38
75
  run: async (body, sink, signal, opts) => {
39
76
  const boundKeyId = opts?.keyId?.trim() ?? '';
40
77
  const key = resolveGatewayKey(boundKeyId, resolveKey);
@@ -42,12 +79,13 @@ export function buildGatewayChatServices(orchestrator, resolveKey = lookupConfig
42
79
  // No identity = no OCR routing. Vendor-native requests never reach this
43
80
  // seam, so passthrough keeps working without a key; only our own
44
81
  // inference is refused. This is the policy split: proxy admission is
45
- // transport, model usage is keyed.
82
+ // transport (it carries no identity at all, ADR-0008 §3), model usage is
83
+ // keyed.
46
84
  sink.onJson(401, {
47
85
  error: {
48
86
  message: boundKeyId
49
87
  ? `Bound API key '${boundKeyId}' is missing, disabled or expired — pick a valid key in Client Hub`
50
- : 'OCR routing requires an API key: send one as the forward-proxy credential or bind one in Client Hub',
88
+ : 'OCR routing requires an API key: bind one to this plugin in Client Hub (proxy admission carries no credential)',
51
89
  type: 'invalid_request_error',
52
90
  code: 'invalid_api_key',
53
91
  },
@@ -11,7 +11,7 @@ import type { StreamRoutingFacts } from '../utils/stream-relay.js';
11
11
  * wire (staged reply.header loop for non-stream, writeHead spread for SSE).
12
12
  *
13
13
  * NOTE on the `?? / ||` defaults: they are FROZEN contract, not style.
14
- * Test stubs (forward-proxy.test.ts and friends) return partial
14
+ * Test stubs (ingress-proxy.test.ts and friends) return partial
15
15
  * ExecutionResults, and the builder must apply safe defaults instead of
16
16
  * throwing on missing optionals (contract §1.4, risk R-4).
17
17
  */
@@ -28,9 +28,11 @@ import type { StreamRoutingFacts } from '../utils/stream-relay.js';
28
28
  * They expose the gateway-measured TTFT (process start → first forwarded
29
29
  * chunk) and decode window (first chunk → stream end) so a client can
30
30
  * compute the same decode-TPS the console shows. Buffered turns omit both.
31
- * - X-OCR-Thinking-{Requested,Actual,Degraded}: only when the client asked
32
- * for reasoning effort (`requestedEffort` set and not 'none'). Lets the
33
- * caller verify whether they got the level requested or were silently
31
+ * - X-OCR-Thinking-{Requested,Actual,Degraded}: only when there is something
32
+ * to report — the ask is not 'none', OR a 'none' ask was NOT served as
33
+ * 'none' (an always-think floor or a member effortMap raised it), so a
34
+ * served level is never silently hidden behind the ask. Lets the caller
35
+ * verify whether they got the level requested or were silently
34
36
  * downgraded. The same record goes to non-stream and SSE wires, so the
35
37
  * Thinking-* headers reach the stream too (unlike the pre-builder code,
36
38
  * where the SSE spread omitted them).
@@ -10,7 +10,7 @@ import { buildOcrSummaryFrame } from '../utils/chat-sse.js';
10
10
  * wire (staged reply.header loop for non-stream, writeHead spread for SSE).
11
11
  *
12
12
  * NOTE on the `?? / ||` defaults: they are FROZEN contract, not style.
13
- * Test stubs (forward-proxy.test.ts and friends) return partial
13
+ * Test stubs (ingress-proxy.test.ts and friends) return partial
14
14
  * ExecutionResults, and the builder must apply safe defaults instead of
15
15
  * throwing on missing optionals (contract §1.4, risk R-4).
16
16
  */
@@ -27,9 +27,11 @@ import { buildOcrSummaryFrame } from '../utils/chat-sse.js';
27
27
  * They expose the gateway-measured TTFT (process start → first forwarded
28
28
  * chunk) and decode window (first chunk → stream end) so a client can
29
29
  * compute the same decode-TPS the console shows. Buffered turns omit both.
30
- * - X-OCR-Thinking-{Requested,Actual,Degraded}: only when the client asked
31
- * for reasoning effort (`requestedEffort` set and not 'none'). Lets the
32
- * caller verify whether they got the level requested or were silently
30
+ * - X-OCR-Thinking-{Requested,Actual,Degraded}: only when there is something
31
+ * to report — the ask is not 'none', OR a 'none' ask was NOT served as
32
+ * 'none' (an always-think floor or a member effortMap raised it), so a
33
+ * served level is never silently hidden behind the ask. Lets the caller
34
+ * verify whether they got the level requested or were silently
33
35
  * downgraded. The same record goes to non-stream and SSE wires, so the
34
36
  * Thinking-* headers reach the stream too (unlike the pre-builder code,
35
37
  * where the SSE spread omitted them).
@@ -76,9 +78,11 @@ export function buildChatOcrHeaders(result, fallbackModel) {
76
78
  headers['X-OCR-TTFT-MS'] = result.ttftMs.toString();
77
79
  if (result.genMs !== undefined)
78
80
  headers['X-OCR-Gen-MS'] = result.genMs.toString();
79
- if (result.requestedEffort && result.requestedEffort !== 'none') {
80
- headers['X-OCR-Thinking-Requested'] = result.requestedEffort;
81
- headers['X-OCR-Thinking-Actual'] = result.actualEffort ?? result.requestedEffort;
81
+ const requestedEffort = result.requestedEffort;
82
+ const servedEffort = result.actualEffort ?? requestedEffort;
83
+ if (requestedEffort && (requestedEffort !== 'none' || (servedEffort && servedEffort !== 'none'))) {
84
+ headers['X-OCR-Thinking-Requested'] = requestedEffort;
85
+ headers['X-OCR-Thinking-Actual'] = servedEffort ?? requestedEffort;
82
86
  headers['X-OCR-Thinking-Degraded'] = result.reasoningDegraded ? 'true' : 'false';
83
87
  // ADR-0012: WHO authored the ask — 'client' or a gateway decision
84
88
  // (decision layer / entry / @ocr directive / default). Emitted only when known;
@@ -23,7 +23,7 @@ export const systemoneSurface = {
23
23
  routePath: '/v1/systemone',
24
24
  /**
25
25
  * Intentionally WIDER than routePath — by design. The MITM
26
- * forward-proxy leg must also claim System One-shaped decision traffic:
26
+ * ingress-proxy leg must also claim System One-shaped decision traffic:
27
27
  * TypeSafe Jev (api.typesafe.ai/v1/systemone) and the Alibaba Bailian
28
28
  * compatible-mode decision endpoint both terminate in `/systemone`, and
29
29
  * the gateway serves them over the intercepted leg. Detection is the
@@ -27,6 +27,17 @@ export function createFastifyTransport(req, reply, orchestrator) {
27
27
  let sseCtx;
28
28
  // Set by the migrated close listener (see below) — the isClientGone signal.
29
29
  let closed = false;
30
+ /**
31
+ * STICKY disconnect flag (ADR-0040). `closed` is only written when the close
32
+ * lands BEFORE the response finished, which is right for capture. But the
33
+ * snapshot plane asks "did the client ever go away during this turn?" AFTER the
34
+ * upstream drained — by then the socket is a normal closed socket and
35
+ * `destroyed` no longer distinguishes a peer that hung up mid-stream from one
36
+ * that received the whole answer. So latch THAT fact here, on the same event,
37
+ * and expose it separately: a turn whose client left mid-stream is `aborted`
38
+ * even though the upstream finished.
39
+ */
40
+ let clientLeftMidStream = false;
30
41
  // Stall deadline for the SSE leg, armed at beginSse (see
31
42
  // `createClientLegWatchdog`): a peer that stops draining and never reports
32
43
  // close would otherwise park the exchange — and its terminal capture event —
@@ -38,7 +49,7 @@ export function createFastifyTransport(req, reply, orchestrator) {
38
49
  // synthetic 499 (nginx convention for client-closed connection) and every
39
50
  // request event stays paired. NB: Fastify's `onClose` application hook is
40
51
  // server-shutdown, NOT this. On Bun 'close' never fires on premature
41
- // disconnect (forward-proxy.test.ts:360 is the runtime spec), which is why
52
+ // disconnect (ingress-proxy.test.ts:360 is the runtime spec), which is why
42
53
  // the terminal sends ALSO consult isClientGone() below.
43
54
  reply.raw.on('close', () => {
44
55
  sseWatchdog?.stop();
@@ -48,6 +59,10 @@ export function createFastifyTransport(req, reply, orchestrator) {
48
59
  if (reply.raw.writableEnded)
49
60
  return;
50
61
  closed = true;
62
+ // Latch the mid-stream departure for the snapshot plane (ADR-0040). This is
63
+ // the Node-runtime path; on Bun the event does not fire, so the terminal
64
+ // sends also consult `isClientGone()` below — the only cross-runtime probe.
65
+ clientLeftMidStream = true;
51
66
  const ctx = getClientExchangeContext(req);
52
67
  if (ctx && !ctx.pending.responded && ctx.recorder.isEnabled()) {
53
68
  emitClientResponse(ctx, {
@@ -58,8 +73,8 @@ export function createFastifyTransport(req, reply, orchestrator) {
58
73
  }
59
74
  });
60
75
  // Bun fires no reliable 'close'/'aborted' after the response is dead —
61
- // the migrated listener covers Node; the socket-destroyed poll covers
62
- // Bun (forward-proxy.test.ts:360 documents the verified runtime).
76
+ // the migrated listener covers Node; `isClientGone` is the only cross-runtime
77
+ // probe this transport can offer (used by the terminal sends).
63
78
  const isClientGone = () => closed || reply.raw.destroyed || reply.raw.socket?.destroyed === true;
64
79
  // Fastify's per-request pino child — the one error sink for this transport.
65
80
  const logError = (err, message) => {
@@ -186,9 +201,14 @@ export function createFastifyTransport(req, reply, orchestrator) {
186
201
  appendClientResponseChunk(sseCtx, chunk);
187
202
  }
188
203
  sseWatchdog?.progress();
189
- if (isClientGone())
204
+ if (isClientGone()) {
205
+ clientLeftMidStream = true;
190
206
  return;
191
- return writeWithBackpressure(reply.raw, chunk, (err) => logError(err, 'Fastify writeSseChunk failed'));
207
+ }
208
+ return writeWithBackpressure(reply.raw, chunk, (err) => {
209
+ clientLeftMidStream = true;
210
+ logError(err, 'Fastify writeSseChunk failed');
211
+ });
192
212
  },
193
213
  endSse: () => {
194
214
  sseWatchdog?.stop();
@@ -248,6 +268,13 @@ export function createFastifyTransport(req, reply, orchestrator) {
248
268
  });
249
269
  },
250
270
  isClientGone,
271
+ /**
272
+ * STICKY "did the client leave during this turn" (ADR-0040). True only when a
273
+ * runtime signal actually fired (Node `close`); on Bun nothing fires, so this
274
+ * stays false and the snapshot cannot tell an aborted turn from a completed
275
+ * one — a documented runtime limitation, not a silent hole.
276
+ */
277
+ didClientLeave: () => clientLeftMidStream,
251
278
  logError,
252
279
  };
253
280
  return transport;
@@ -1,18 +1,63 @@
1
1
  import type http from 'node:http';
2
- import type { ProtocolSurface, TransportContext } from './types.js';
2
+ import type { TransportContext } from './types.js';
3
3
  /**
4
- * Read the request body with a hard 32 MB cap (migrated verbatim from the
5
- * pre-refactor interceptor). Oversized bodies reject with 'Request body
6
- * too large' → the caller maps that to 413 via surface.errorBody.
4
+ * Raw node:http transport (the MITM ingress-proxy leg) — the second
5
+ * implementation of the frozen TransportContext terminal-send discipline
6
+ * (contract §1.5). The interceptor reads the body, hands this transport to
7
+ * dispatchSurface, and the SAME chat pipelines then run byte-comparable on
8
+ * both legs.
9
+ *
10
+ * POLICY EXEMPTION (deliberate): intercepted traffic carries NO gateway key —
11
+ * the upstream Authorization header belongs to the real upstream API, so
12
+ * per-key model-access policies cannot apply here. This surface is a trusted
13
+ * local-machine convenience (the user explicitly points their tools at the
14
+ * proxy); anyone who can reach the proxy could equally call the native
15
+ * endpoints if they held a key, and inference cost-control for untrusted
16
+ * remote callers is the proxy operator's job (bind it to loopback). Do NOT
17
+ * "fix" this by inventing key headers the caller cannot send.
18
+ * (Authoritative text — interceptor.ts keeps only a pointer here.)
7
19
  */
8
- export declare function readRequestBody(req: http.IncomingMessage): Promise<Buffer>;
20
+ /**
21
+ * Read the request body with the gateway's hard cap (`bodyLimitFor('gateway')` —
22
+ * the SAME number the native Fastify routes pass as bodyLimit, so one admission
23
+ * ceiling covers both legs; `client.bodyLimits.maxBytes` moves it for both at the
24
+ * next boot). Oversized bodies reject with a BodyAdmissionError
25
+ * that already carries the 413 status, the `payload_too_large` code and the
26
+ * client-facing sentence; the caller only has to answer with it.
27
+ *
28
+ * The cap is measured on the WIRE here (this leg buffers before decoding), and
29
+ * `model-gateway.ts` re-checks after `decompressBody`, so a compressed body
30
+ * cannot slip past the ceiling that the native leg applies to its inflated
31
+ * stream.
32
+ *
33
+ * A STALLED body is refused too, with 408 (see `requestBodyTimeout`). The
34
+ * server-level `requestTimeout` cannot express it: that clock covers the whole
35
+ * request, so one byte per minute never trips it — and on Bun no such clock is
36
+ * armed at all. This timer is re-armed on every chunk, so liveness is measured on
37
+ * the axis that actually fails in practice: progress, not elapsed time.
38
+ *
39
+ * `idleMs` is a seam (a test cannot wait a minute, and a later config knob needs
40
+ * one call site); production callers pass nothing and get the single-source default.
41
+ */
42
+ export declare function readRequestBody(req: http.IncomingMessage, idleMs?: number): Promise<Buffer>;
43
+ /** The minimal envelope surface: enough to build a rejection body. Declared
44
+ * structurally so both a `ProtocolSurface` and the admin plane's adapter can
45
+ * be passed without either importing the other. */
46
+ export interface PreDispatchEnvelope {
47
+ errorBody(status: number, message: string, code?: string): unknown;
48
+ }
9
49
  /**
10
50
  * Pre-dispatch error (413 oversized body / 400 invalid JSON): sent through
11
51
  * the surface's own error envelope BEFORE any orchestrator call, so no
12
52
  * capture events exist on this path on either leg (contract §4: 400/403
13
53
  * precede process). Adapters never throw — write failures are logged loud.
14
54
  */
15
- export declare function sendPreDispatchError(res: http.ServerResponse, surface: ProtocolSurface, status: number, message: string): void;
55
+ export declare function sendPreDispatchError(res: http.ServerResponse, surface: PreDispatchEnvelope, status: number, message: string, code?: string,
56
+ /** The rejection's negotiation headers (`Accept-Encoding` for a refused coding,
57
+ * `Accept` for a refused media type). Carried through so the MITM leg advertises
58
+ * exactly what the native leg does — a client that only reads the headers learns
59
+ * the fix on neither leg if they are dropped here. */
60
+ headers?: Record<string, string>): void;
16
61
  /**
17
62
  * Build the MITM-leg transport. `captureEnabled` is the SURFACE capture
18
63
  * policy threaded in by the caller: `true` wires the