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
@@ -1,7 +1,9 @@
1
1
  import { appendClientResponseChunk, markClientResponseStreamStart, emitClientResponse, } from '../observability/http-exchange.js';
2
+ import { bodyLimitFor, payloadTooLarge, requestBodyTimeout, writeRefusalAnswer } from './body-admission.js';
3
+ import { REQUEST_BODY_IDLE_TIMEOUT_MS } from '../config/defaults.js';
2
4
  import { createClientLegWatchdog, writeWithBackpressure } from './transport-backpressure.js';
3
5
  /**
4
- * Raw node:http transport (the MITM forward-proxy leg) — the second
6
+ * Raw node:http transport (the MITM ingress-proxy leg) — the second
5
7
  * implementation of the frozen TransportContext terminal-send discipline
6
8
  * (contract §1.5). The interceptor reads the body, hands this transport to
7
9
  * dispatchSurface, and the SAME chat pipelines then run byte-comparable on
@@ -17,27 +19,79 @@ import { createClientLegWatchdog, writeWithBackpressure } from './transport-back
17
19
  * "fix" this by inventing key headers the caller cannot send.
18
20
  * (Authoritative text — interceptor.ts keeps only a pointer here.)
19
21
  */
20
- const MAX_BODY_BYTES = 32 * 1024 * 1024;
21
22
  /**
22
- * Read the request body with a hard 32 MB cap (migrated verbatim from the
23
- * pre-refactor interceptor). Oversized bodies reject with 'Request body
24
- * too large' → the caller maps that to 413 via surface.errorBody.
23
+ * Read the request body with the gateway's hard cap (`bodyLimitFor('gateway')` —
24
+ * the SAME number the native Fastify routes pass as bodyLimit, so one admission
25
+ * ceiling covers both legs; `client.bodyLimits.maxBytes` moves it for both at the
26
+ * next boot). Oversized bodies reject with a BodyAdmissionError
27
+ * that already carries the 413 status, the `payload_too_large` code and the
28
+ * client-facing sentence; the caller only has to answer with it.
29
+ *
30
+ * The cap is measured on the WIRE here (this leg buffers before decoding), and
31
+ * `model-gateway.ts` re-checks after `decompressBody`, so a compressed body
32
+ * cannot slip past the ceiling that the native leg applies to its inflated
33
+ * stream.
34
+ *
35
+ * A STALLED body is refused too, with 408 (see `requestBodyTimeout`). The
36
+ * server-level `requestTimeout` cannot express it: that clock covers the whole
37
+ * request, so one byte per minute never trips it — and on Bun no such clock is
38
+ * armed at all. This timer is re-armed on every chunk, so liveness is measured on
39
+ * the axis that actually fails in practice: progress, not elapsed time.
40
+ *
41
+ * `idleMs` is a seam (a test cannot wait a minute, and a later config knob needs
42
+ * one call site); production callers pass nothing and get the single-source default.
25
43
  */
26
- export function readRequestBody(req) {
44
+ export function readRequestBody(req, idleMs = REQUEST_BODY_IDLE_TIMEOUT_MS) {
27
45
  return new Promise((resolve, reject) => {
28
46
  const chunks = [];
47
+ const capBytes = bodyLimitFor('gateway');
29
48
  let total = 0;
49
+ let idle;
50
+ const clearIdle = () => {
51
+ if (idle)
52
+ clearTimeout(idle);
53
+ idle = undefined;
54
+ };
55
+ const armIdle = () => {
56
+ clearIdle();
57
+ idle = setTimeout(() => {
58
+ idle = undefined;
59
+ // Same shape as the size overflow: stop consuming, let the caller answer,
60
+ // and let `sendPreDispatchError` close the connection.
61
+ req.pause();
62
+ reject(requestBodyTimeout());
63
+ }, idleMs);
64
+ // Never hold the event loop open for a client that has stopped talking.
65
+ idle.unref?.();
66
+ };
30
67
  req.on('data', (d) => {
68
+ armIdle();
31
69
  total += d.length;
32
- if (total > MAX_BODY_BYTES) {
33
- reject(new Error('Request body too large'));
34
- req.destroy();
70
+ if (total > capBytes) {
71
+ clearIdle();
72
+ // RFC 9110 15.5.14: an oversized payload is refused with a 413 — an
73
+ // ANSWER, not a reset. Destroying the request here tore the socket down
74
+ // before the caller could write the status, so the client saw a bare
75
+ // ECONNRESET with no code at all (verified on bun and node). Pause
76
+ // instead — the ceiling is already crossed, so stop consuming and let
77
+ // `sendPreDispatchError` answer, flush and close.
78
+ req.pause();
79
+ reject(payloadTooLarge(capBytes));
35
80
  return;
36
81
  }
37
82
  chunks.push(d);
38
83
  });
39
- req.on('end', () => resolve(Buffer.concat(chunks)));
40
- req.on('error', reject);
84
+ req.on('end', () => {
85
+ clearIdle();
86
+ resolve(Buffer.concat(chunks));
87
+ });
88
+ // A client that hangs up mid-body is not a stalled body: no 408 answer to send,
89
+ // just stop the clock.
90
+ req.on('close', clearIdle);
91
+ req.on('error', (err) => {
92
+ clearIdle();
93
+ reject(err);
94
+ });
41
95
  });
42
96
  }
43
97
  /**
@@ -46,18 +100,24 @@ export function readRequestBody(req) {
46
100
  * capture events exist on this path on either leg (contract §4: 400/403
47
101
  * precede process). Adapters never throw — write failures are logged loud.
48
102
  */
49
- export function sendPreDispatchError(res, surface, status, message) {
103
+ export function sendPreDispatchError(res, surface, status, message, code,
104
+ /** The rejection's negotiation headers (`Accept-Encoding` for a refused coding,
105
+ * `Accept` for a refused media type). Carried through so the MITM leg advertises
106
+ * exactly what the native leg does — a client that only reads the headers learns
107
+ * the fix on neither leg if they are dropped here. */
108
+ headers) {
50
109
  let serialized;
51
110
  try {
52
- serialized = JSON.stringify(surface.errorBody(status, message));
111
+ serialized = JSON.stringify(surface.errorBody(status, message, code));
53
112
  }
54
113
  catch (err) {
55
114
  logWriteError(err, 'node-http pre-dispatch error body serialization failed');
56
115
  return;
57
116
  }
58
117
  try {
59
- res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
60
- res.end(serialized);
118
+ // ONE writer for every refusal (see `writeRefusalAnswer`): answer first,
119
+ // declare `content-length`, then drain the refused body (bounded) and close.
120
+ writeRefusalAnswer(res, status, serialized, { headers });
61
121
  }
62
122
  catch (err) {
63
123
  logWriteError(err, 'node-http pre-dispatch error write failed');
@@ -67,7 +127,7 @@ function logWriteError(err, message) {
67
127
  // R-3: loud-not-silent. Bun's socket layer can surface write errors as
68
128
  // 'ERR_STREAM_DESTROYED'-style throws on dead peers; they must reach the
69
129
  // operator log, never an empty catch.
70
- console.error(`[forward-proxy] ${message}`, err);
130
+ console.error(`[ingress-proxy] ${message}`, err);
71
131
  }
72
132
  /**
73
133
  * Build the MITM-leg transport. `captureEnabled` is the SURFACE capture
@@ -16,7 +16,7 @@ import type { ExecutionResult } from '../types/router.js';
16
16
  * makeModelAccessGuard(registry)(req, reply, model); a denial
17
17
  * has ALREADY been written as a 403 by the guard, callers only
18
18
  * check the boolean and must NOT send another response.
19
- * - 'exempt' — POLICY EXEMPTION (MITM forward-proxy leg): the tunnel peer is
19
+ * - 'exempt' — POLICY EXEMPTION (MITM ingress-proxy leg): the tunnel peer is
20
20
  * authenticated by the CONNECT/TLS layer, not an API key, so
21
21
  * every model passes and the capture's inbound request headers
22
22
  * carry no key identity. `keyName`/`policy` pin the empty view
@@ -80,12 +80,20 @@ export interface TransportContext {
80
80
  endSse(): void;
81
81
  /**
82
82
  * Client-abort detection. Bun never fires req 'res''close'/'aborted'
83
- * reliably after the body is read (forward-proxy.test.ts:360 documents the
83
+ * reliably after the body is read (ingress-proxy.test.ts:360 documents the
84
84
  * verified runtime behavior) — adapters combine their own close-flag with
85
85
  * the socket's destroyed state; the pipeline uses this only as a fallback
86
86
  * signal, the terminal send itself is what finalizes capture.
87
87
  */
88
88
  isClientGone(): boolean;
89
+ /**
90
+ * STICKY "did the client leave during this turn" (ADR-0040). Unlike
91
+ * `isClientGone` — which reports the CURRENT socket state and is read at the
92
+ * terminal send — this must still answer YES after the upstream drained into a
93
+ * socket the peer abandoned, so an interrupted turn is recorded as `aborted`
94
+ * rather than `completed`. Optional: a transport with no such signal omits it.
95
+ */
96
+ didClientLeave?(): boolean;
89
97
  logError(err: unknown, message: string): void;
90
98
  }
91
99
  /**
@@ -203,7 +211,7 @@ export interface ChatSurface {
203
211
  * conversion call, per the model's resolved wire — ADR-0008 §7;
204
212
  * no purpose tag — unambiguous within its own turn). FinOps/trace stay
205
213
  * excluded; the default-off path is
206
- * pinned zero-event by forward-proxy-systemone.test.ts.
214
+ * pinned zero-event by ingress-proxy-systemone.test.ts.
207
215
  */
208
216
  export interface DecisionSurface {
209
217
  readonly wire: 'systemone';
@@ -52,7 +52,17 @@ function normalizeReplayedTrace(raw) {
52
52
  delete fin.cachedPromptTokens;
53
53
  }
54
54
  delete fin.savedCostUsd;
55
- fin.costUsd = Number(fin.costUsd) || 0;
55
+ // `costUsd` is OPTIONAL — absent means the price was unknown at request
56
+ // time, and every aggregate counts it as an unpriced turn. Coerce only a
57
+ // value that IS present: `Number(undefined) || 0` laundered an unpriced
58
+ // turn into a confident $0 the next time the process booted.
59
+ if (fin.costUsd !== undefined) {
60
+ const cost = Number(fin.costUsd);
61
+ if (Number.isFinite(cost))
62
+ fin.costUsd = cost;
63
+ else
64
+ delete fin.costUsd;
65
+ }
56
66
  }
57
67
  const req = record.request;
58
68
  if (req && typeof req === 'object') {
@@ -86,6 +96,13 @@ async function tryOpenTraceStore(dir) {
86
96
  // stores (each with its own handle), so contend politely and keep the
87
97
  // schema switch atomic.
88
98
  db.run('PRAGMA busy_timeout = 5000;');
99
+ // The write-through path fires once per completed request, so the default
100
+ // FULL (an fsync per commit) sits on the inference hot path. WAL + NORMAL
101
+ // keeps the file crash-consistent and only risks losing the most recent
102
+ // commits on power loss — acceptable for observability, which fails open
103
+ // by contract. `synchronous` is per-connection: every hot-path handle sets
104
+ // its own (see openFinOpsStore).
105
+ db.run('PRAGMA synchronous = NORMAL;');
89
106
  const version = Number(db.query('PRAGMA user_version').get()?.user_version ?? 0);
90
107
  // `user_version` is FILE-wide (SQLite has no per-table version): this store
91
108
  // is its sole owner — every other store on the file only runs
@@ -307,6 +324,9 @@ export async function openFinOpsStore(dir) {
307
324
  fs.mkdirSync(dir, { recursive: true });
308
325
  db = new Database(path.join(dir, 'traces.db'), { create: true });
309
326
  db.run('PRAGMA journal_mode = WAL;');
327
+ // Same hot-path rationale as tryOpenTraceStore: one counter transaction per
328
+ // completed request must not pay an fsync.
329
+ db.run('PRAGMA synchronous = NORMAL;');
310
330
  db.run(`CREATE TABLE IF NOT EXISTS finops_totals (
311
331
  key TEXT PRIMARY KEY,
312
332
  value REAL NOT NULL
@@ -98,6 +98,14 @@ export interface ExecutionTrace {
98
98
  userAgent?: string;
99
99
  acceptLanguage?: string;
100
100
  clientRequestId?: string;
101
+ /**
102
+ * Self-declared client id from `x-ocr-client`, e.g.
103
+ * `OmniCellRouter-Playground/0.8.5`. PREFERRED over `userAgent` when the
104
+ * console classifies this trace's client family, because a browser
105
+ * webview strips a script-set `User-Agent` on `fetch` (it sends its own
106
+ * instead). Display-only, never an identity or routing input (ADR-0002).
107
+ */
108
+ clientHint?: string;
101
109
  };
102
110
  /**
103
111
  * Client-minted conversation id this turn carried (Cursor's agent-wire
@@ -217,9 +225,11 @@ export interface ExecutionTrace {
217
225
  outputTokens: number;
218
226
  cachedTokens: number;
219
227
  /**
220
- * Actual USD cost of this request, computed at request time with the
221
- * catalog pricing that was current then. The only cost figure stored —
222
- * derived comparisons (baseline/savings) are intentionally not recorded.
228
+ * Actual USD cost of this request, booked at request time: the
229
+ * vendor-reported committed cost when the wire reports one (plugin wires
230
+ * whose upstream bills itself, e.g. qoder credits), otherwise the catalog
231
+ * pricing that was current then. The only cost figure stored — derived
232
+ * comparisons (baseline/savings) are intentionally not recorded.
223
233
  *
224
234
  * Absent when the serving model had NO known price: an unpriced model must
225
235
  * stay unpriceable all the way to the console, because writing 0 here would
@@ -286,6 +296,22 @@ export interface UsageStatsSummary {
286
296
  };
287
297
  keys: KeyUsageRow[];
288
298
  }
299
+ /**
300
+ * Per-model slice of one session's recorded spend, as a trace-derived view —
301
+ * never routing state. Emitted only when a session was served by MORE THAN ONE
302
+ * model: a single-model session's total already says everything, and the
303
+ * sessions list is polled, so the common case must not grow the payload.
304
+ */
305
+ export interface SessionModelCostRow {
306
+ /** Registered id exactly as served (`provider/model`, or a bare id for a hand-configured model). */
307
+ model: string;
308
+ /** Exchanges served by this model. */
309
+ requests: number;
310
+ /** Cost of this model's requests that could be priced; see {@link unpricedRequests}. */
311
+ costUsd: number;
312
+ /** Requests on this model whose price was unknown — excluded from `costUsd`. */
313
+ unpricedRequests: number;
314
+ }
289
315
  export declare class TraceTracker {
290
316
  private traces;
291
317
  /** sessionId -> requestId[] — one entry per RECORD. */
@@ -405,6 +431,12 @@ export declare class TraceTracker {
405
431
  * Non-zero means the total is a floor, not the session's real spend.
406
432
  */
407
433
  unpricedTurns: number;
434
+ /**
435
+ * Per-model split of `requests` / `costUsd`, priced cost descending.
436
+ * Present ONLY when the session served more than one model — a
437
+ * single-model session omits it so the polled sessions list stays lean.
438
+ */
439
+ byModel?: SessionModelCostRow[];
408
440
  totalLatencyMs: number;
409
441
  genOutputTokens: number;
410
442
  genMsSum: number;
@@ -339,6 +339,7 @@ export class TraceTracker {
339
339
  let stalledMsSum = 0;
340
340
  let stallWindowMs = 0;
341
341
  const ttftSamples = [];
342
+ const byModelRows = new Map();
342
343
  let prevModel = null;
343
344
  for (const t of traces) {
344
345
  if (prevModel !== null && t.execution.modelUsed !== prevModel)
@@ -351,6 +352,19 @@ export class TraceTracker {
351
352
  costUsd += t.finops.costUsd;
352
353
  else
353
354
  unpricedTurns++;
355
+ let modelRow = byModelRows.get(t.execution.modelUsed);
356
+ if (!modelRow) {
357
+ modelRow = { model: t.execution.modelUsed, requests: 0, costUsd: 0, unpricedRequests: 0 };
358
+ byModelRows.set(t.execution.modelUsed, modelRow);
359
+ }
360
+ modelRow.requests++;
361
+ // Same skip-and-count semantics as the session total: an unpriced
362
+ // request is excluded from the model's sum and counted, so neither
363
+ // figure silently reads as confident.
364
+ if (t.finops.costUsd !== undefined)
365
+ modelRow.costUsd += t.finops.costUsd;
366
+ else
367
+ modelRow.unpricedRequests++;
354
368
  totalLatencyMs += t.execution.latencyMs;
355
369
  if (typeof t.execution.genMs === 'number') {
356
370
  genOutputTokens += t.finops.outputTokens;
@@ -364,6 +378,14 @@ export class TraceTracker {
364
378
  }
365
379
  }
366
380
  const last = traces[traces.length - 1];
381
+ const byModel = byModelRows.size > 1
382
+ ? [...byModelRows.values()]
383
+ .map((r) => ({ ...r, costUsd: Number(r.costUsd.toFixed(6)) }))
384
+ // Priced cost descending — "who ate the bill" order. Unpriced
385
+ // models carry cost 0 and land last; ties break on the model id
386
+ // by code unit (localeCompare collation varies by ICU build).
387
+ .sort((a, b) => b.costUsd - a.costUsd || (a.model < b.model ? -1 : a.model > b.model ? 1 : 0))
388
+ : undefined;
367
389
  return {
368
390
  traceCount: traces.length,
369
391
  switchCount,
@@ -372,6 +394,7 @@ export class TraceTracker {
372
394
  cachedTokens,
373
395
  costUsd: Number(costUsd.toFixed(6)),
374
396
  unpricedTurns,
397
+ byModel,
375
398
  totalLatencyMs,
376
399
  genOutputTokens,
377
400
  genMsSum,
@@ -167,6 +167,14 @@ export interface Usage {
167
167
  accepted_prediction_tokens?: number;
168
168
  rejected_prediction_tokens?: number;
169
169
  };
170
+ /**
171
+ * Vendor-reported committed cost of THIS exchange in USD (gateway extension,
172
+ * stamped by the model-service plugin from the upstream's own billing — e.g.
173
+ * qoder reports `credits`, converted at the operator's USD/credit rate).
174
+ * `usageToIR` maps it to `vendorCostUsd`, where it wins over catalog
175
+ * pricing for every booking; it is NEVER re-emitted on a client-facing wire.
176
+ */
177
+ cost_usd?: number;
170
178
  }
171
179
  export interface ChatCompletionChoice {
172
180
  index: number;
@@ -22,11 +22,21 @@ export type TierLevel = 'lite' | 'plus' | 'pro' | 'ultra';
22
22
  export type PoolMembership = TierLevel | 'unclassified';
23
23
  export declare const TIER_RANK: Record<TierLevel, number>;
24
24
  /**
25
- * Thinking-effort vocabulary, aligned with OpenCode's 6-level ladder
25
+ * Cost mode means "the cheapest tier that still WORKS", so a lite-lead
26
+ * request may escalate after a failure but never above this ceiling. One
27
+ * constant shared by every escalation site keeps a cost pin from silently
28
+ * spending pro/ultra money (ADR-0001 §1).
29
+ */
30
+ export declare const COST_MODE_TIER_CEILING: TierLevel;
31
+ /** The lower of `tier` and `cap` by TIER_RANK — a ceiling applied to a tier. */
32
+ export declare function clampTierToCeiling(tier: TierLevel, cap: TierLevel): TierLevel;
33
+ /**
34
+ * Thinking-effort vocabulary, aligned with OpenCode's 7-level ladder
26
35
  * (lowest → highest). `EFFORT_LADDER.indexOf(effort)` IS the rank —
27
36
  * weaker levels have smaller index.
28
37
  * none — no reasoning (the lowest tier; client sends this
29
38
  * explicitly to mean "do not think", not as a default)
39
+ * minimal — the lightest active reasoning level (above none)
30
40
  * low / medium / high — shared by every wire (OpenAI, Anthropic,
31
41
  * Google, OpenAI Responses)
32
42
  * xhigh — OpenAI / OpenAI-compatible top tier (GPT-5+)
@@ -40,7 +50,7 @@ export declare const TIER_RANK: Record<TierLevel, number>;
40
50
  * served.
41
51
  *
42
52
  * Default `supportedReasoningEfforts` for a thinking-capable model is
43
- * the full 6-level ladder — there is no 5-level "thinking subset".
53
+ * the full 7-level ladder — there is no reduced "thinking" subset.
44
54
  */
45
55
  export declare const EFFORT_LADDER: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
46
56
  export type ReasoningEffort = (typeof EFFORT_LADDER)[number];
@@ -153,9 +163,10 @@ export type SessionLookupType = 'explicit_header' | 'embedded_user_id' | 'reques
153
163
  /**
154
164
  * Machine-readable routing-reason vocabulary carried alongside the English
155
165
  * `reason` on every decision and trace. Producers emit a code from the locked
156
- * set ('forced', 'default', 'combo', 'l2.*', 'session.*') plus the params
157
- * needed to render it; the console localizes from code+params and falls back
158
- * to the raw `reason` for unknown or legacy values.
166
+ * set ('forced', 'mode', 'default', 'combo', 'l2.*', 'session.*') plus the
167
+ * params needed to render it; the console localizes from code+params and falls
168
+ * back to the raw `reason` for unknown or legacy values. `mode` marks a tier
169
+ * pinned by the global `routing.mode` lever; `forced` stays client-authored.
159
170
  */
160
171
  export type ReasonParams = Record<string, string | number | boolean>;
161
172
  export interface RoutingDecision {
@@ -272,7 +283,7 @@ export interface ExecutionResult {
272
283
  * client sent (or undefined if the client omitted the field).
273
284
  * `actualEffort` is what the gateway actually served (may be lower
274
285
  * after registry-level downgrade); `reasoningDegraded` flags the
275
- * discrepancy. Both are full 6-level `ReasoningEffort` values.
286
+ * discrepancy. Both are full 7-level `ReasoningEffort` values.
276
287
  */
277
288
  requestedEffort?: ReasoningEffort;
278
289
  actualEffort?: ReasoningEffort;
@@ -5,11 +5,23 @@ export const TIER_RANK = {
5
5
  ultra: 4,
6
6
  };
7
7
  /**
8
- * Thinking-effort vocabulary, aligned with OpenCode's 6-level ladder
8
+ * Cost mode means "the cheapest tier that still WORKS", so a lite-lead
9
+ * request may escalate after a failure but never above this ceiling. One
10
+ * constant shared by every escalation site keeps a cost pin from silently
11
+ * spending pro/ultra money (ADR-0001 §1).
12
+ */
13
+ export const COST_MODE_TIER_CEILING = 'plus';
14
+ /** The lower of `tier` and `cap` by TIER_RANK — a ceiling applied to a tier. */
15
+ export function clampTierToCeiling(tier, cap) {
16
+ return TIER_RANK[tier] <= TIER_RANK[cap] ? tier : cap;
17
+ }
18
+ /**
19
+ * Thinking-effort vocabulary, aligned with OpenCode's 7-level ladder
9
20
  * (lowest → highest). `EFFORT_LADDER.indexOf(effort)` IS the rank —
10
21
  * weaker levels have smaller index.
11
22
  * none — no reasoning (the lowest tier; client sends this
12
23
  * explicitly to mean "do not think", not as a default)
24
+ * minimal — the lightest active reasoning level (above none)
13
25
  * low / medium / high — shared by every wire (OpenAI, Anthropic,
14
26
  * Google, OpenAI Responses)
15
27
  * xhigh — OpenAI / OpenAI-compatible top tier (GPT-5+)
@@ -23,7 +35,7 @@ export const TIER_RANK = {
23
35
  * served.
24
36
  *
25
37
  * Default `supportedReasoningEfforts` for a thinking-capable model is
26
- * the full 6-level ladder — there is no 5-level "thinking subset".
38
+ * the full 7-level ladder — there is no reduced "thinking" subset.
27
39
  */
28
40
  export const EFFORT_LADDER = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
29
41
  /** Shared thinking-token budget estimates for protocols that express effort as a token budget. */
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Client-family classification — the ONE mapping from a client fingerprint (a
3
+ * self-declared `x-ocr-client` hint, else the HTTP User-Agent) to a stable
4
+ * client family for the console.
5
+ *
6
+ * Display-only: both inputs are client-forgeable and are deliberately never
7
+ * identity/routing inputs (ADR-0002 resolves session identity zero-header,
8
+ * anchored on the API-key application). The hint exists because a browser
9
+ * webview strips a script-set `User-Agent` on `fetch` — see
10
+ * `CLIENT_HINT_HEADER`. The family id is the machine key the sessions filter
11
+ * and the console query string use; `label` is an English fallback shown when
12
+ * the console has no localized name for the id. Product names (OpenCode,
13
+ * Cursor, …) are proper nouns and are never translated.
14
+ */
15
+ export interface ClientFamily {
16
+ /** Stable machine id (`opencode`, `claude-code`, `pi`, …). Never localized. */
17
+ id: string;
18
+ /** English display label / fallback for unknown UAs. */
19
+ label: string;
20
+ }
21
+ /** Family id for a User-Agent the table does not recognize. */
22
+ export declare const UNKNOWN_CLIENT_FAMILY_ID = "unknown";
23
+ /**
24
+ * Inbound header a client uses to declare its own identity, e.g.
25
+ * `OmniCellRouter-Playground/<version>`.
26
+ *
27
+ * A browser webview strips a script-set `User-Agent` on `fetch` (the browser
28
+ * sends its own instead — verified empirically), so the UA alone cannot carry
29
+ * a self-declared id from a console page. A custom header survives, and it is
30
+ * PREFERRED over the UA for family classification. Display-only, exactly like
31
+ * the UA: forgeable, never an identity or routing input (ADR-0002).
32
+ */
33
+ export declare const CLIENT_HINT_HEADER = "x-ocr-client";
34
+ /**
35
+ * The identification material ONE request carried: a self-declared hint
36
+ * (`x-ocr-client`) and/or the raw inbound User-Agent. Either may be absent.
37
+ */
38
+ export interface ClientFingerprint {
39
+ /** Self-declared client id (`x-ocr-client`), e.g. `playground/0.8.5`. */
40
+ hint?: string;
41
+ /** Raw inbound `User-Agent` string. */
42
+ userAgent?: string;
43
+ }
44
+ /**
45
+ * Classify one User-Agent into a client family. Unknown UAs keep their leading
46
+ * whitespace token (capped) as the label so the console never invents a client
47
+ * that isn't there; the full raw UA stays in the chip tooltip.
48
+ */
49
+ export declare function clientFamilyOf(ua: string): ClientFamily;
50
+ /**
51
+ * One family as a session reports it: the family plus the raw fingerprints
52
+ * that produced it (write order). The fingerprint list exists only so the
53
+ * console chip can keep showing the exact value in its tooltip — it is never
54
+ * an identity or a filter key (the family id is).
55
+ */
56
+ export interface SessionClientFamily extends ClientFamily {
57
+ /** The identifying strings: a self-declared hint or the raw UA, whichever
58
+ * classified the request (see `clientFamiliesOf`). */
59
+ fingerprints: string[];
60
+ }
61
+ /**
62
+ * Distinct families across a session's per-request fingerprints, in write
63
+ * order (first element = display anchor). Fingerprints of the same family
64
+ * collapse to one entry that keeps every contributing value.
65
+ */
66
+ export declare function clientFamiliesOf(fingerprints: readonly ClientFingerprint[]): SessionClientFamily[];
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Ordered first-match table. ORDER MATTERS: `pi` is ANCHORED and must be
3
+ * tested before the generic `/anthropic/i` entry — a pi User-Agent embeds no
4
+ * vendor name, but an unanchored `/pi/i` would match "Anthropic/…".
5
+ */
6
+ const CLIENT_PATTERNS = [
7
+ // The console's own playground page (frontend/src/pages/PlaygroundPage.tsx
8
+ // sends `OmniCellRouter-Playground/<version>`). Before `pi` so the product
9
+ // prefix can never be mistaken for a vendor SDK.
10
+ [/omnicellrouter-playground/i, 'playground', 'Playground'],
11
+ // pi agent — `pi/<version> (<platform>; <runtime>/<ver>; <arch>)` or `pi`.
12
+ [/^pi(\/|\s|$)/i, 'pi', 'pi'],
13
+ // Coding agents / CLIs
14
+ [/opencode/i, 'opencode', 'OpenCode'],
15
+ [/claude-cli|claude-code/i, 'claude-code', 'Claude Code'],
16
+ [/chatgpt/i, 'chatgpt', 'ChatGPT'],
17
+ [/codex/i, 'codex', 'Codex / ChatGPT'],
18
+ [/cline/i, 'cline', 'Cline'],
19
+ [/roo-?code/i, 'roo-code', 'Roo Code'],
20
+ [/kilo-?code/i, 'kilo-code', 'Kilo Code'],
21
+ // Cursor was renamed Grok Build (2026-11-30); the family id stays `cursor`
22
+ // because it is the machine key historical sessions already carry.
23
+ [/cursor/i, 'cursor', 'Grok Build (Cursor)'],
24
+ [/windsurf/i, 'windsurf', 'Windsurf'],
25
+ // Chat frontends
26
+ [/cherrystudio/i, 'cherry-studio', 'Cherry Studio'],
27
+ [/chatbox/i, 'chatbox', 'ChatBox'],
28
+ [/lobe-?chat|lobehub/i, 'lobechat', 'LobeChat'],
29
+ [/nextchat|chatgpt-?next-?web/i, 'nextchat', 'NextChat'],
30
+ [/open-?webui/i, 'open-webui', 'Open WebUI'],
31
+ [/librechat/i, 'librechat', 'LibreChat'],
32
+ [/dify/i, 'dify', 'Dify'],
33
+ [/fastgpt/i, 'fastgpt', 'FastGPT'],
34
+ // IDE / editor integrations
35
+ [/visual-?studio-?code|vscode/i, 'vscode', 'VS Code'],
36
+ [/jetbrains/i, 'jetbrains', 'JetBrains'],
37
+ // Official SDKs
38
+ [/openai\/node/i, 'openai-node', 'OpenAI SDK (Node)'],
39
+ [/openai\/python/i, 'openai-python', 'OpenAI SDK (Python)'],
40
+ [/anthropic/i, 'anthropic-sdk', 'Anthropic SDK'],
41
+ [/google-?genai|generativelanguage/i, 'google-genai', 'Google GenAI SDK'],
42
+ // HTTP libraries (generic fallbacks for home-grown callers)
43
+ [/python-?httpx/i, 'python-httpx', 'Python httpx'],
44
+ [/python-?requests/i, 'python-requests', 'Python requests'],
45
+ [/python-?urllib/i, 'python-urllib', 'Python urllib'],
46
+ [/aiohttp/i, 'python-aiohttp', 'Python aiohttp'],
47
+ [/okhttp/i, 'okhttp', 'OkHttp'],
48
+ [/go-http-client/i, 'go-http', 'Go HTTP'],
49
+ [/guzzle/i, 'guzzle', 'Guzzle'],
50
+ [/\bdart\//i, 'dart', 'Dart'],
51
+ [/axios/i, 'axios', 'Axios'],
52
+ [/undici/i, 'undici', 'Node fetch (undici)'],
53
+ // API tools
54
+ [/postmanruntime/i, 'postman', 'Postman'],
55
+ [/insomnia/i, 'insomnia', 'Insomnia'],
56
+ [/\bcurl\/|libcurl/i, 'curl', 'curl'],
57
+ [/wget/i, 'wget', 'Wget'],
58
+ ];
59
+ /** Max length of an unrecognized UA token shown as the label. */
60
+ const UNKNOWN_LABEL_CAP = 32;
61
+ /** Family id for a User-Agent the table does not recognize. */
62
+ export const UNKNOWN_CLIENT_FAMILY_ID = 'unknown';
63
+ /**
64
+ * Inbound header a client uses to declare its own identity, e.g.
65
+ * `OmniCellRouter-Playground/<version>`.
66
+ *
67
+ * A browser webview strips a script-set `User-Agent` on `fetch` (the browser
68
+ * sends its own instead — verified empirically), so the UA alone cannot carry
69
+ * a self-declared id from a console page. A custom header survives, and it is
70
+ * PREFERRED over the UA for family classification. Display-only, exactly like
71
+ * the UA: forgeable, never an identity or routing input (ADR-0002).
72
+ */
73
+ export const CLIENT_HINT_HEADER = 'x-ocr-client';
74
+ /**
75
+ * Classify one User-Agent into a client family. Unknown UAs keep their leading
76
+ * whitespace token (capped) as the label so the console never invents a client
77
+ * that isn't there; the full raw UA stays in the chip tooltip.
78
+ */
79
+ export function clientFamilyOf(ua) {
80
+ for (const [pattern, id, label] of CLIENT_PATTERNS) {
81
+ if (pattern.test(ua))
82
+ return { id, label };
83
+ }
84
+ const token = ua.trim().split(/\s+/)[0] ?? '';
85
+ const label = token.length > UNKNOWN_LABEL_CAP ? `${token.slice(0, UNKNOWN_LABEL_CAP)}…` : token || '—';
86
+ return { id: UNKNOWN_CLIENT_FAMILY_ID, label };
87
+ }
88
+ /**
89
+ * Resolve ONE request's family. A self-declared hint wins when it names a
90
+ * known family; otherwise the UA classifies, and an unrecognized hint is the
91
+ * last resort. Returns the raw string that actually classified so the console
92
+ * tooltip shows the value the family came from.
93
+ */
94
+ function familyOfFingerprint(fp) {
95
+ const hint = fp.hint?.trim();
96
+ const ua = fp.userAgent?.trim();
97
+ if (hint) {
98
+ const declared = clientFamilyOf(hint);
99
+ if (declared.id !== UNKNOWN_CLIENT_FAMILY_ID)
100
+ return { family: declared, raw: hint };
101
+ }
102
+ if (ua)
103
+ return { family: clientFamilyOf(ua), raw: ua };
104
+ if (hint)
105
+ return { family: clientFamilyOf(hint), raw: hint };
106
+ return undefined;
107
+ }
108
+ /**
109
+ * Distinct families across a session's per-request fingerprints, in write
110
+ * order (first element = display anchor). Fingerprints of the same family
111
+ * collapse to one entry that keeps every contributing value.
112
+ */
113
+ export function clientFamiliesOf(fingerprints) {
114
+ const byId = new Map();
115
+ for (const fp of fingerprints) {
116
+ const resolved = familyOfFingerprint(fp);
117
+ if (!resolved)
118
+ continue;
119
+ const existing = byId.get(resolved.family.id);
120
+ if (existing) {
121
+ existing.fingerprints.push(resolved.raw);
122
+ continue;
123
+ }
124
+ byId.set(resolved.family.id, { ...resolved.family, fingerprints: [resolved.raw] });
125
+ }
126
+ return [...byId.values()];
127
+ }
@@ -8,7 +8,7 @@
8
8
  /** Ring capacity (and, mirrored, the durable row budget). */
9
9
  export declare const EVENT_RING_CAPACITY = 500;
10
10
  /**
11
- * Forward-proxy access-log ring capacity — body-bearing rows are heavy, so
11
+ * Ingress-proxy access-log ring capacity — body-bearing rows are heavy, so
12
12
  * the fourth ledger carries a smaller ring than the other three (pass to the
13
13
  * EventRing constructor; never re-declare per module).
14
14
  */
@@ -8,7 +8,7 @@
8
8
  /** Ring capacity (and, mirrored, the durable row budget). */
9
9
  export const EVENT_RING_CAPACITY = 500;
10
10
  /**
11
- * Forward-proxy access-log ring capacity — body-bearing rows are heavy, so
11
+ * Ingress-proxy access-log ring capacity — body-bearing rows are heavy, so
12
12
  * the fourth ledger carries a smaller ring than the other three (pass to the
13
13
  * EventRing constructor; never re-declare per module).
14
14
  */