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,9 +1,12 @@
1
+ import { pickDialWire } from './dial-wire.js';
1
2
  import { OpenAIChatProvider } from './executors/openai-chat.js';
2
3
  import { AnthropicMessagesProvider } from './executors/anthropic-messages.js';
3
4
  import { OpenAIResponsesProvider } from './executors/openai-responses.js';
4
5
  import { GoogleGeminiProvider } from './executors/google-gemini.js';
5
6
  import { getModelServicePlugin } from '../plugins/host.js';
6
- import { EFFORT_LADDER, downgradeReasoning, modelSupportsEfforts } from '../types/router.js';
7
+ import { TIER_RANK, COST_MODE_TIER_CEILING, EFFORT_LADDER, downgradeReasoning, modelSupportsEfforts } from '../types/router.js';
8
+ import { IrUnsupportedError } from '../ir/errors.js';
9
+ import { withDialContext } from '../ir/validate.js';
7
10
  import { createEventAccumulator } from '../ir/stream.js';
8
11
  import { createToolMarkupScanner, detectToolMarkupLeak } from './compat/tool-markup-leak.js';
9
12
  import { createToolMarkupStreamRecovery, recoverToolMarkupInResponse, toolMarkupRecoveryFor } from './compat/tool-markup-recovery.js';
@@ -14,8 +17,10 @@ import { canonicalProtocol } from './protocol.js';
14
17
  import { CircuitBreakerManager, UpstreamError } from '../resilience/index.js';
15
18
  import { globMatchAny } from '../utils/glob.js';
16
19
  import { loadConfig } from '../config/index.js';
17
- import { redactProxyUrl, resolveProxyUrl } from '../utils/proxy.js';
18
- import { resolveTierMembers, claimModel, claimInTier, matchingTiers, applyEffortMap, MEMBER_TIER_ORDER, TIER_DESCENDING_ORDER, comboMemberRefsOf, expandComboRefs, RESERVED_IDS } from './member-match.js';
20
+ import { resolveEgress } from '../utils/proxy.js';
21
+ import { resolveTierMembers, claimModel, claimInTier, matchingTiers, applyEffortMap, markExactFullIds, MEMBER_TIER_ORDER, TIER_DESCENDING_ORDER, comboMemberRefsOf, expandComboRefs, RESERVED_IDS } from './member-match.js';
22
+ import { WeightedRoundRobin, normalizeSelectionStrategy, normalizeMemberWeight } from './selection.js';
23
+ import { comparePriceBucket, comparePriceThenId, samePriceBucket } from './price-order.js';
19
24
  /**
20
25
  * Normalize a client-supplied upstream host for provider matching: lowercase,
21
26
  * strip IPv6 brackets and a trailing :port. Returns undefined for empty or
@@ -81,9 +86,11 @@ export class ProviderRegistry {
81
86
  * so what routing sees is always exactly what was last committed.
82
87
  */
83
88
  committedMembers = { lite: [], plus: [], pro: [], ultra: [] };
84
- rrCursor = new Map();
89
+ /** Smooth weighted round-robin cursors — one per tier pool. */
90
+ tierRr = new WeightedRoundRobin();
85
91
  combos = new Map();
86
- comboRrCursor = new Map();
92
+ /** Smooth weighted round-robin cursors — one per combo pool. */
93
+ comboRr = new WeightedRoundRobin();
87
94
  /** Fingerprint of the combo section last applied by applyCombos — lets the
88
95
  * lazy hand-edit safety net skip no-op replays instead of resetting
89
96
  * round-robin cursors and re-logging skip warnings every TTL window. */
@@ -397,7 +404,7 @@ export class ProviderRegistry {
397
404
  * containing `/` are rejected (those are full-id lookups, not bare names).
398
405
  *
399
406
  * `upstreamHost` (the proxy-interception target host, when the request
400
- * arrived through the MITM forward proxy) disambiguates same-name models:
407
+ * arrived through the MITM ingress proxy) disambiguates same-name models:
401
408
  * candidates whose provider baseUrl hostname matches the host win; when
402
409
  * nothing matches (hooked clients hit the gateway itself, unknown hosts)
403
410
  * the full hit list applies. Empty result = no registered model carries
@@ -414,15 +421,13 @@ export class ProviderRegistry {
414
421
  // Locale-independent tiebreak: strict code-unit order, not localeCompare.
415
422
  // Unpriced models sort last: an unknown price cannot claim to be the
416
423
  // cheapest, and `Infinity` keeps that ordering without inventing a number.
417
- const byPrice = (a, b) => (a.pricing?.input ?? Infinity) - (b.pricing?.input ?? Infinity) ||
418
- (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
419
424
  const host = normalizeHostHeader(upstreamHost);
420
425
  if (host) {
421
426
  const scoped = hits.filter((m) => this.providerHosts.get(m.provider) === host);
422
427
  if (scoped.length > 0)
423
- return scoped.sort(byPrice);
428
+ return scoped.sort(comparePriceThenId);
424
429
  }
425
- return hits.sort(byPrice);
430
+ return hits.sort(comparePriceThenId);
426
431
  }
427
432
  /** Raw provider config (any type) — used for provider baseUrl/apiKey
428
433
  * lookup (e.g. boot-time provider registration). */
@@ -462,54 +467,74 @@ export class ProviderRegistry {
462
467
  * a weight per pool), default 1. */
463
468
  weightFor(tier, modelId) {
464
469
  const claim = claimInTier(tier, modelId, this.committedMembers);
465
- return claim ? Math.max(1, Number(claim.rule.weight) || 1) : 1;
470
+ return claim ? normalizeMemberWeight(claim.rule.weight) : 1;
466
471
  }
467
- /** Effective selection strategy: explicit config wins; default priority (legacy weights retired). */
472
+ /** Effective selection strategy: explicit config wins, default priority. */
468
473
  selectionStrategy(tier) {
469
- return this.tierPolicies?.[tier]?.selection ?? 'priority';
470
- }
471
- /** Weighted round-robin: each model occupies `weight` consecutive slots per cycle. */
472
- pickRoundRobin(models, tier) {
473
- const slots = [];
474
- for (const m of models) {
475
- const w = this.weightFor(tier, m.id);
476
- for (let i = 0; i < w; i++)
477
- slots.push(m);
478
- }
479
- if (slots.length === 0)
480
- return models[0];
481
- const prev = this.rrCursor.get(tier) ?? 0;
482
- this.rrCursor.set(tier, prev + 1);
483
- return slots[prev % slots.length];
474
+ return normalizeSelectionStrategy(this.tierPolicies?.[tier]?.selection);
484
475
  }
485
476
  /**
486
477
  * Primary pick inside a tier, driven by the tier's selection strategy:
487
478
  * - priority (default): first healthy candidate in chain order (= member
488
479
  * list order)
489
- * - weighted: weighted random draw over the healthy pool (claiming member
490
- * rule's weight, default 1)
491
- * - round_robin: rotating weighted slots for even distribution over time
480
+ * - weighted_round_robin: smooth WEIGHTED round-robin — weight = the
481
+ * claiming member rule's weight (default 1), served in proportion, evenly
482
+ * interleaved
483
+ * - round_robin: plain sequential round-robin — equal turns, weights ignored
484
+ * `weighted_round_robin` and `round_robin` share ONE smooth round-robin core
485
+ * (combos use it too); only the weight policy differs.
492
486
  * The failover chain order is strategy-independent (buildTierPoolEntries:
493
487
  * rule weight desc, then rule list order).
494
488
  */
495
- pickPrimary(models, tier) {
496
- if (models.length <= 1)
497
- return models[0];
489
+ pickPrimary(models, tier, costOrder = false) {
498
490
  const strategy = this.selectionStrategy(tier);
499
- if (strategy === 'round_robin')
500
- return this.pickRoundRobin(models, tier);
501
- if (strategy === 'weighted') {
502
- const weights = models.map((m) => this.weightFor(tier, m.id));
503
- const total = weights.reduce((a, b) => a + b, 0);
504
- let r = Math.random() * total;
505
- for (let i = 0; i < models.length; i++) {
506
- r -= weights[i];
507
- if (r < 0)
508
- return models[i];
509
- }
510
- return models[models.length - 1];
491
+ // Cost mode (ADR-0001 §2): restrict the pool to the CHEAPEST price bucket
492
+ // BEFORE the strategy runs, so a pricier member is never selected ahead of
493
+ // a cheaper one — under `priority` too. `priority` returns a head, and a
494
+ // caller list (widened access pool, model-access expansion) is not
495
+ // guaranteed to be price-sorted, so the bucket anchor is the
496
+ // lexicographically CHEAPEST member rather than `models[0]`. Equal-priced
497
+ // members keep sharing turns (rotation draws inside the bucket).
498
+ let pool = models;
499
+ if (costOrder && models.length > 1) {
500
+ const cheapest = models.reduce((best, m) => (comparePriceBucket(m, best) < 0 ? m : best), models[0]);
501
+ const bucket = models.filter((m) => samePriceBucket(m, cheapest));
502
+ if (bucket.length > 0)
503
+ pool = bucket;
511
504
  }
512
- return models[0];
505
+ // `priority` never touches a cursor. The rotation strategies ALWAYS go
506
+ // through the core — including a single-member pool, whose identity check
507
+ // resets a stale vector after a shrink (a short-circuit here would strand
508
+ // credit accumulated before it).
509
+ if (strategy === 'priority')
510
+ return pool[0];
511
+ const weightOf = strategy === 'weighted_round_robin' ? (m) => this.weightFor(tier, m.id) : () => 1;
512
+ // The price projection keeps its OWN cursor: `routing.mode` is hot-reloaded
513
+ // (config/runtime.ts `syncRuntimeAuthView`), so a cost bucket draw and a
514
+ // full-pool draw of this tier can alternate inside one process. A shared
515
+ // key would reset the other projection's credit vector on every toggle.
516
+ return this.tierRr.pick(`${tier}:${strategy}${costOrder ? ':cost' : ''}`, pool, (m) => m.id, weightOf);
517
+ }
518
+ /**
519
+ * Strategy-aware leader over an ALREADY-FILTERED candidate list. `getModelForTier`
520
+ * assembles the pool (health, denylist, cross-tier fallback) and then picks;
521
+ * this is the pure pick for a chain whose pool was filtered elsewhere
522
+ * (model access, widening) — the serving chain must lead with this model.
523
+ */
524
+ pickLeader(tier, candidates, costOrder = false) {
525
+ return this.pickPrimary(candidates, tier, costOrder);
526
+ }
527
+ /**
528
+ * Chain order for a ready candidate list: the strategy-selected leader first,
529
+ * then the remaining members in their existing order. `priority` leaves the
530
+ * list untouched (its head already leads); only the rotation strategies
531
+ * reorder, and the failover walk after the head is unchanged.
532
+ */
533
+ orderChain(tier, candidates, costOrder = false) {
534
+ if (candidates.length === 0)
535
+ return candidates;
536
+ const leader = this.pickPrimary(candidates, tier, costOrder);
537
+ return [leader, ...candidates.filter((m) => m.id !== leader.id)];
513
538
  }
514
539
  /**
515
540
  * Per-tier pool construction — the ONE membership read for a single tier.
@@ -524,7 +549,7 @@ export class ProviderRegistry {
524
549
  * weight and effortMap — the translation that applies when the model
525
550
  * serves from THIS pool.
526
551
  */
527
- buildTierPoolEntries(tier, members) {
552
+ buildTierPoolEntries(tier, members, order = 'declared') {
528
553
  const entries = [];
529
554
  for (const m of this.models.values()) {
530
555
  if (!m.autoTier) {
@@ -534,7 +559,7 @@ export class ProviderRegistry {
534
559
  const claim = claimInTier(tier, m.id, members);
535
560
  entries.push({
536
561
  model: m,
537
- weight: claim ? Math.max(1, Number(claim.rule.weight) || 1) : 1,
562
+ weight: claim ? normalizeMemberWeight(claim.rule.weight) : 1,
538
563
  effortMap: m.effortMap,
539
564
  rank: m.isDefaultInTier ? 0 : m.priority ?? 10,
540
565
  });
@@ -545,12 +570,17 @@ export class ProviderRegistry {
545
570
  continue;
546
571
  entries.push({
547
572
  model: m,
548
- weight: Math.max(1, Number(claim.rule.weight) || 1),
573
+ weight: normalizeMemberWeight(claim.rule.weight),
549
574
  effortMap: claim.rule.effortMap,
550
575
  rank: claim.index,
551
576
  });
552
577
  }
553
- entries.sort((a, b) => b.weight - a.weight || a.rank - b.rank);
578
+ // `declared` = weight desc then rule-list order (the operator's own chain).
579
+ // `cheapest` = price first, then the declared order INSIDE a price bucket
580
+ // (cost mode only, ADR-0001 §2; see providers/price-order.ts).
581
+ entries.sort((a, b) => (order === 'cheapest' ? comparePriceBucket(a.model, b.model) : 0) ||
582
+ b.weight - a.weight ||
583
+ a.rank - b.rank);
554
584
  return entries;
555
585
  }
556
586
  /**
@@ -620,22 +650,40 @@ export class ProviderRegistry {
620
650
  this.autoRefreshMembers = on;
621
651
  }
622
652
  /** Registered member refs of one combo (config order, deduped, unregistered
623
- dropped) — null when the ref is dead: unknown id, operator-disabled, or
624
- shadowed by a registered model. */
653
+ dropped), each carrying its OWN effortMap — null when the ref is dead:
654
+ unknown id, operator-disabled, or shadowed by a registered model. */
625
655
  comboMemberRefs(comboId) {
626
656
  const combo = this.combos.get(comboId);
627
657
  if (!combo || combo.disabled === true || this.models.has(comboId))
628
658
  return null;
629
- return comboMemberRefsOf(combo, (id) => this.models.has(id));
659
+ return { members: comboMemberRefsOf(combo, (id) => this.models.has(id)) };
660
+ }
661
+ /** Per-member thinking-level translations of one combo, keyed by member id
662
+ (ADR-0003). Consumed by the directly-addressed combo path, which has no
663
+ pool context to re-derive from. Empty when the combo is unknown/dead or
664
+ declares no member tables. */
665
+ comboEffortMaps(comboId) {
666
+ const out = new Map();
667
+ for (const member of this.comboMemberRefs(comboId)?.members ?? []) {
668
+ if (member.effortMap)
669
+ out.set(member.id, member.effortMap);
670
+ }
671
+ return out;
630
672
  }
631
673
  /**
632
674
  * The ONE member-rule read view: `tiers.<t>.members` with `combo:<id>` refs
633
- * expanded in place. Every membership consumer (claims, weights, pools,
634
- * boot, save checks) must read through this so pools stay physical-model
635
- * lists while config keeps the operator's declared references.
675
+ * expanded in place and hand-written FULL ids pinned exact. Every membership
676
+ * consumer (claims, weights, pools, boot, save checks) must read through this
677
+ * so pools stay physical-model lists while config keeps the operator's
678
+ * declared references. Exact pinning is a PROJECTION concern, not a config
679
+ * write: the stored `tiers` keeps the operator's plain pattern.
636
680
  */
637
681
  expandedMemberRules(policies) {
638
- return expandComboRefs(resolveTierMembers(policies).tiers, (id) => this.comboMemberRefs(id));
682
+ const expanded = expandComboRefs(resolveTierMembers(policies).tiers, (id) => this.comboMemberRefs(id));
683
+ const registered = new Set();
684
+ for (const id of this.models.keys())
685
+ registered.add(id.toLowerCase());
686
+ return { dead: expanded.dead, tiers: markExactFullIds(expanded.tiers, (id) => registered.has(id.toLowerCase())) };
639
687
  }
640
688
  /**
641
689
  * COMMIT path — the only one that rewrites live pool membership. Called on
@@ -725,37 +773,66 @@ export class ProviderRegistry {
725
773
  * pool (one whose supported set sits above the requested level) is
726
774
  * NOT a valid match — we'd rather let the orchestrator pick a
727
775
  * different route than silently drop to `none`.
776
+ *
777
+ * `maxTier` bounds Pass 2 (the cross-tier search): no tier ranked above it
778
+ * may serve. Cost mode passes COST_MODE_TIER_CEILING so an effort the lite
779
+ * pool cannot satisfy can never spend a pro/ultra model (ADR-0001 §28).
780
+ * Defaulting to undefined keeps the unrestricted cross-tier search for
781
+ * smart/quality and for direct registry callers.
782
+ *
783
+ * `sameTierOnly` disables Pass 2 entirely: the request is served from THIS
784
+ * tier or not at all. A `same_tier_only` failover policy and a client-forced
785
+ * tier both demand it — a forced lite must never be widened onto a plus/pro
786
+ * model by an effort-aware pick (ADR-0014).
728
787
  */
729
- pickModelForEffort(tier, requested, healthyOnly = true) {
788
+ pickModelForEffort(tier, requested, healthyOnly = true, costOrder = false, maxTier, sameTierOnly = false) {
730
789
  if (requested === 'none') {
731
790
  // No thinking requested. Legacy pass-through (any model) UNLESS a
732
791
  // member rule maps `none` to a real level (e.g. none→high):
733
792
  // then the mapped candidates compete and the mapped level is served.
734
- const entries = this.tierPoolEntries(tier, healthyOnly);
793
+ const entries = this.tierPoolEntries(tier, healthyOnly, { costOrder });
735
794
  if (entries.some((e) => applyEffortMap(e.effortMap, 'none') !== 'none')) {
736
795
  const mapped = this.bestEffortMatch(entries, requested);
737
796
  if (mapped)
738
797
  return mapped;
739
798
  }
740
- const m = this.getModelForTier(tier, healthyOnly);
799
+ // Pass-through head is NOT a selection: the caller's per-request chain
800
+ // head is the one real pick, so reading the rotation cursor here would
801
+ // advance it twice per request and serve every second draw. The pool
802
+ // head (all health levels, never drawn) is the same model the chain
803
+ // would lead with.
804
+ const head = entries[0]?.model ?? this.getCandidateModelsForTier(tier, false, { costOrder })[0];
805
+ if (head)
806
+ return { model: head, actualEffort: 'none', degraded: false };
807
+ // Pool empty at every health level: keep the getter's cross-tier /
808
+ // throw contract. No rotation draw can happen here — a pool with no
809
+ // candidate has nothing for pickPrimary to advance.
810
+ const m = this.getModelForTier(tier, healthyOnly, costOrder);
741
811
  if (m)
742
812
  return { model: m, actualEffort: 'none', degraded: false };
743
813
  return null;
744
814
  }
745
815
  // Pass 1: pick from the requested tier (each candidate is first translated
746
816
  // by ITS pool's effortMap, then capability-clamped — see bestEffortMatch).
747
- const tierPick = this.bestEffortMatch(this.tierPoolEntries(tier, healthyOnly), requested);
817
+ const tierPick = this.bestEffortMatch(this.tierPoolEntries(tier, healthyOnly, { costOrder }), requested);
748
818
  if (tierPick)
749
819
  return tierPick;
750
820
  // Pass 2: cross-tier fallback — search all tiers in tier-rank order
751
821
  // (highest first) for any healthy thinking-capable model. Per design
752
822
  // decision 2026-10: cross-tier mixing is allowed; the actual model is
753
- // still reported in the response so the caller sees the truth.
823
+ // still reported in the response so the caller sees the truth. `maxTier`
824
+ // caps that walk (cost mode must never spend above its ceiling).
825
+ // `sameTierOnly` refuses the walk outright — the tier is a hard bound, not
826
+ // a preference (same_tier_only policy / a client-forced tier).
827
+ if (sameTierOnly)
828
+ return null;
754
829
  const tierOrder = TIER_DESCENDING_ORDER;
755
830
  for (const t of tierOrder) {
756
831
  if (t === tier)
757
832
  continue;
758
- const pick = this.bestEffortMatch(this.tierPoolEntries(t, healthyOnly), requested);
833
+ if (maxTier !== undefined && TIER_RANK[t] > TIER_RANK[maxTier])
834
+ continue;
835
+ const pick = this.bestEffortMatch(this.tierPoolEntries(t, healthyOnly, { costOrder }), requested);
759
836
  if (pick)
760
837
  return pick;
761
838
  }
@@ -770,7 +847,7 @@ export class ProviderRegistry {
770
847
  * upstream for the gateway's own wire mismatch; the decision surface
771
848
  * passes `decisionSurface: true` to see them. */
772
849
  tierPoolEntries(tier, healthyOnly, opts) {
773
- return this.buildTierPoolEntries(tier, this.committedMembers)
850
+ return this.buildTierPoolEntries(tier, this.committedMembers, opts?.costOrder ? 'cheapest' : 'declared')
774
851
  .filter(({ model }) => opts?.decisionSurface === true || model.wire !== 'systemone')
775
852
  .filter(({ model }) => !this.policyRejectionReason(this.tierPolicies, model))
776
853
  .filter(({ model }) => !healthyOnly || this.modelAvailable(model).available);
@@ -818,33 +895,53 @@ export class ProviderRegistry {
818
895
  return null;
819
896
  return { model: best.model, actualEffort: best.actualEffort, degraded: best.gap > 0 };
820
897
  }
821
- getModelForTier(tier, healthyOnly = true) {
822
- const candidates = this.getCandidateModelsForTier(tier, healthyOnly);
898
+ getModelForTier(tier, healthyOnly = true, costOrder = false) {
899
+ const candidates = this.getCandidateModelsForTier(tier, healthyOnly, { costOrder });
823
900
  if (candidates.length > 0) {
824
- return this.pickPrimary(candidates, tier);
901
+ return this.pickPrimary(candidates, tier, costOrder);
825
902
  }
826
903
  // If healthyOnly was true and no healthy models found, fallback to any model in tier
827
904
  if (healthyOnly) {
828
- const anyCandidate = this.getCandidateModelsForTier(tier, false);
905
+ const anyCandidate = this.getCandidateModelsForTier(tier, false, { costOrder });
829
906
  if (anyCandidate.length > 0) {
830
- return this.pickPrimary(anyCandidate, tier);
907
+ return this.pickPrimary(anyCandidate, tier, costOrder);
831
908
  }
832
909
  }
833
910
  // the requested tier is EMPTY (a real possibility now that there
834
911
  // is no residual catch-all). Degradation is still possible — routing must
835
912
  // not hard-fail on a config the user can legitimately write — but it is
836
913
  // NEVER silent: the cross-tier step is logged with the reason.
837
- const escalate = (this.tierPolicies ? loadConfig().fallback?.escalateTier : undefined) ?? 'plus';
914
+ //
915
+ // COST MODE (ADR-0001 §2) bounds the walk: `costOrder` clamps every
916
+ // landing to COST_MODE_TIER_CEILING, and a 'never' costEscalation policy
917
+ // pins the walk to tiers at or below the requested one — a cost pin must
918
+ // never be repaired onto pro/ultra money just because lite is empty.
919
+ const cfg = this.tierPolicies ? loadConfig() : undefined;
920
+ const escalate = cfg?.fallback?.escalateTier ?? 'plus';
921
+ const hardPin = costOrder && cfg?.routing?.costEscalation === 'never';
922
+ const maxRank = !costOrder
923
+ ? Number.POSITIVE_INFINITY
924
+ : hardPin
925
+ ? TIER_RANK[tier]
926
+ : TIER_RANK[COST_MODE_TIER_CEILING];
838
927
  const order = [escalate, 'plus', 'lite', 'pro', 'ultra'];
839
- const chain = order.filter((t, i, all) => t !== tier && all.indexOf(t) === i);
928
+ const chain = order.filter((t, i, all) => t !== tier && all.indexOf(t) === i && TIER_RANK[t] <= maxRank);
840
929
  for (const step of chain) {
841
- const rep = this.tierDefaults.get(step);
930
+ // Cost mode prefers the step's CHEAPEST pool head (a peek — never a
931
+ // rotation draw) over the declared-order representative, so the degraded
932
+ // landing honours the price axis the rest of the cost-mode primitives
933
+ // sort by (the tierDefaults table is built in declared order).
934
+ const rep = costOrder
935
+ ? this.getCandidateModelsForTier(step, true, { costOrder })[0] ?? this.tierDefaults.get(step)
936
+ : this.tierDefaults.get(step);
842
937
  if (rep && rep.tier !== undefined) {
843
938
  console.warn(`[Registry] Tier '${tier}' has no candidate model — falling back to '${step}' (${rep.id}), reason=empty-pool`);
844
939
  return rep;
845
940
  }
846
941
  }
847
- const any = Array.from(this.models.values()).find((m) => m.tier !== undefined);
942
+ // Last resort: prefer an in-budget model before a model that would breach
943
+ // the cost ceiling / a hard pin.
944
+ const any = Array.from(this.models.values()).find((m) => m.tier !== undefined && TIER_RANK[m.tier] <= maxRank) ?? Array.from(this.models.values()).find((m) => m.tier !== undefined);
848
945
  if (!any) {
849
946
  throw new Error(`No routable models registered (no model's tier membership is claimed by any pool).`);
850
947
  }
@@ -939,7 +1036,7 @@ export class ProviderRegistry {
939
1036
  return;
940
1037
  this.combosFingerprint = fingerprint;
941
1038
  this.combos.clear();
942
- this.comboRrCursor.clear();
1039
+ this.comboRr.reset();
943
1040
  for (const combo of combos || []) {
944
1041
  if (!combo?.id || !Array.isArray(combo.models) || combo.models.length === 0)
945
1042
  continue;
@@ -974,7 +1071,7 @@ export class ProviderRegistry {
974
1071
  comboMemberRef(entry) {
975
1072
  if (typeof entry === 'string')
976
1073
  return { id: entry, weight: 1 };
977
- return { id: entry.id, weight: Math.max(1, Number(entry.weight) || 1) };
1074
+ return { id: entry.id, weight: normalizeMemberWeight(entry.weight) };
978
1075
  }
979
1076
  /**
980
1077
  * Resolve a combo to its registered member models in config order.
@@ -1000,16 +1097,27 @@ export class ProviderRegistry {
1000
1097
  return members;
1001
1098
  }
1002
1099
  /**
1003
- * Combo primary pick, mirroring the tier selection strategies:
1100
+ * Combo primary pick, mirroring the tier selection strategies exactly:
1004
1101
  * - priority (default): first healthy member in config order
1005
- * - weighted: weight-random draw over the healthy pool
1006
- * - round_robin: rotating weighted slots (combo-scoped cursor)
1102
+ * - weighted_round_robin: smooth WEIGHTED round-robin — weight = the member
1103
+ * entry's weight (default 1)
1104
+ * - round_robin: plain sequential round-robin — equal turns, weights ignored
1105
+ * The same smooth round-robin core serves the tier pools; cursors are
1106
+ * combo-scoped (and strategy-scoped).
1007
1107
  * Falls back to the full member list when every member is tripped.
1108
+ *
1109
+ * An EMPTY member list is a caller bug (the combo either does not exist or
1110
+ * has no registered member) and throws — the same contract as the rotation
1111
+ * core. Callers check `resolveCombo(...)` first; `undefined` from the old
1112
+ * `members[0]` return was never part of this signature.
1008
1113
  */
1009
1114
  pickComboLeader(comboId, members) {
1010
- if (members.length <= 1)
1011
- return members[0];
1012
- const strategy = this.combos.get(comboId)?.selection ?? 'priority';
1115
+ if (members.length === 0) {
1116
+ throw new Error(`pickComboLeader: combo '${comboId}' has no resolved members`);
1117
+ }
1118
+ // Single-member combos still go through the rotation core on rotation
1119
+ // strategies so a shrunk pool resets its cursor (same rule as the tiers).
1120
+ const strategy = normalizeSelectionStrategy(this.combos.get(comboId)?.selection);
1013
1121
  // Decision 6 aggregate (same rule as the tier pools): a member whose every
1014
1122
  // credential is out must not lead a combo.
1015
1123
  const healthy = members.filter((m) => this.modelAvailable(m).available);
@@ -1020,31 +1128,10 @@ export class ProviderRegistry {
1020
1128
  if (!weights.has(ref.id))
1021
1129
  weights.set(ref.id, ref.weight);
1022
1130
  }
1023
- if (strategy === 'round_robin') {
1024
- const slots = [];
1025
- for (const m of pool) {
1026
- const w = weights.get(m.id) ?? 1;
1027
- for (let i = 0; i < w; i++)
1028
- slots.push(m);
1029
- }
1030
- if (slots.length === 0)
1031
- return pool[0];
1032
- const prev = this.comboRrCursor.get(comboId) ?? 0;
1033
- this.comboRrCursor.set(comboId, prev + 1);
1034
- return slots[prev % slots.length];
1035
- }
1036
- if (strategy === 'weighted') {
1037
- const ws = pool.map(m => weights.get(m.id) ?? 1);
1038
- const total = ws.reduce((a, b) => a + b, 0);
1039
- let r = Math.random() * total;
1040
- for (let i = 0; i < pool.length; i++) {
1041
- r -= ws[i];
1042
- if (r < 0)
1043
- return pool[i];
1044
- }
1045
- return pool[pool.length - 1];
1046
- }
1047
- return pool[0];
1131
+ if (strategy === 'priority')
1132
+ return pool[0];
1133
+ const weightOf = strategy === 'weighted_round_robin' ? (m) => weights.get(m.id) ?? 1 : () => 1;
1134
+ return this.comboRr.pick(`${comboId}:${strategy}`, pool, (m) => m.id, weightOf);
1048
1135
  }
1049
1136
  /**
1050
1137
  * Introspection for the console resolve a tier's effective
@@ -1090,13 +1177,19 @@ export class ProviderRegistry {
1090
1177
  }
1091
1178
  /**
1092
1179
  * Outbound egress the CORE transport will take for `model`, resolved from
1093
- * the same `resolveProxyUrl` the executors call at dial time (ADR-0018 /
1094
- * ADR-0022). Call this IMMEDIATELY before `execute()` and keep the value
1095
- * with the attempt: the proxy config hot-applies, so a read after a long
1096
- * stream can describe a different dial.
1180
+ * the same `resolveEgress` the executors dial with (ADR-0018 / ADR-0022).
1181
+ * Call this IMMEDIATELY before `execute()` and keep the value with the
1182
+ * attempt: the proxy config hot-applies, so a read after a long stream can
1183
+ * describe a different dial.
1097
1184
  *
1098
- * `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode) or
1099
- * the transport does not report its dial base (plugin-owned executors).
1185
+ * `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode), the
1186
+ * transport does not report its dial base (plugin-owned executors), OR the
1187
+ * operator demanded the proxy and there was no endpoint to dial
1188
+ * (`no-endpoint`). That last case `proxiedFetch` REFUSES — no socket is
1189
+ * opened — so claiming `direct` would put a "goes direct" stamp on a request
1190
+ * that never left the machine. The connectivity probe reports UNKNOWN for it
1191
+ * for the same reason; this keeps the two honest about one verdict. The
1192
+ * verdict's `origin` is already redacted, so no credential can ride a trace.
1100
1193
  */
1101
1194
  egressFor(model) {
1102
1195
  if (this.mockMode)
@@ -1104,8 +1197,13 @@ export class ProviderRegistry {
1104
1197
  const base = this.providers.get(model.provider)?.dialBaseFor?.(model);
1105
1198
  if (!base)
1106
1199
  return undefined;
1107
- const proxy = resolveProxyUrl(base, { provider: model.provider, model: model.id });
1108
- return proxy ? { mode: 'proxy', origin: redactProxyUrl(proxy) } : { mode: 'direct' };
1200
+ const verdict = resolveEgress(base, { provider: model.provider, model: model.id });
1201
+ if (verdict.mode === 'proxy')
1202
+ return { mode: 'proxy', origin: verdict.origin };
1203
+ // A refused dial (no-endpoint) took NO leg — stamp UNKNOWN, not direct.
1204
+ if (verdict.reason === 'no-endpoint')
1205
+ return undefined;
1206
+ return { mode: 'direct', reason: verdict.reason };
1109
1207
  }
1110
1208
  /**
1111
1209
  * Execute one completion. `credentialKeyHashPrefix`
@@ -1118,7 +1216,9 @@ export class ProviderRegistry {
1118
1216
  */
1119
1217
  async execute(request, model, upstreamEventContext, credentialKeyHashPrefix, relay,
1120
1218
  /** Resolved OCR conversation id. Not a capture field. */
1121
- sessionId) {
1219
+ sessionId,
1220
+ /** Inbound client surface protocol — prefer-native dial (ADR-0033). */
1221
+ inboundWire) {
1122
1222
  if (this.mockMode) {
1123
1223
  relay?.onTransport?.('buffered');
1124
1224
  return this.mockExecute(request, model);
@@ -1126,6 +1226,8 @@ export class ProviderRegistry {
1126
1226
  const provider = this.providers.get(model.provider);
1127
1227
  if (!provider)
1128
1228
  throw new Error(`Provider '${model.provider}' not found for model '${model.id}'`);
1229
+ const dialWire = pickDialWire(model.protocols ?? (model.wire ? [model.wire] : undefined), inboundWire, request);
1230
+ const dialModel = dialWire === model.wire ? model : { ...model, wire: dialWire };
1129
1231
  const chain = this.credentialChains.get(model.provider);
1130
1232
  let credential;
1131
1233
  if (credentialKeyHashPrefix !== undefined) {
@@ -1135,17 +1237,17 @@ export class ProviderRegistry {
1135
1237
  }
1136
1238
  }
1137
1239
  try {
1138
- const recovery = toolMarkupRecoveryFor(request, model, this.providerConfigs.get(model.provider));
1240
+ const recovery = toolMarkupRecoveryFor(request, dialModel, this.providerConfigs.get(model.provider));
1139
1241
  if (relay) {
1140
1242
  const streams = provider.supportsStreaming
1141
- ? provider.supportsStreaming(model)
1243
+ ? provider.supportsStreaming(dialModel)
1142
1244
  : typeof provider.createStream === 'function';
1143
1245
  if (streams) {
1144
1246
  const accumulate = createEventAccumulator();
1145
1247
  const scanner = recovery ? null : createToolMarkupScanner();
1146
1248
  const rewrite = recovery ? createToolMarkupStreamRecovery(request) : null;
1147
1249
  relay.onTransport?.('sse');
1148
- const stream = await provider.createStream(request, model, upstreamEventContext, credential, sessionId);
1250
+ const stream = await provider.createStream(request, dialModel, upstreamEventContext, credential, sessionId);
1149
1251
  // Drain for terminal usage even if the client disconnected. Relay and
1150
1252
  // accounting consume the same event objects without history copies.
1151
1253
  for await (const event of stream) {
@@ -1163,17 +1265,17 @@ export class ProviderRegistry {
1163
1265
  }
1164
1266
  const accumulated = accumulate.finish();
1165
1267
  const finished = rewrite ? rewrite.finishResponse(accumulated) : accumulated;
1166
- reportToolMarkupLeak(rewrite ? finished.toolMarkupLeak ?? null : scanner.leak(), model);
1268
+ reportToolMarkupLeak(rewrite ? finished.toolMarkupLeak ?? null : scanner.leak(), dialModel);
1167
1269
  return finished;
1168
1270
  }
1169
1271
  relay.onTransport?.('buffered');
1170
1272
  }
1171
- const buffered = await provider.createCompletion(request, model, upstreamEventContext, credential, sessionId);
1273
+ const buffered = await provider.createCompletion(request, dialModel, upstreamEventContext, credential, sessionId);
1172
1274
  const finished = recovery ? recoverToolMarkupInResponse(buffered, request) : buffered;
1173
1275
  const leak = recovery ? finished.toolMarkupLeak ?? null : detectToolMarkupLeak(finished);
1174
1276
  if (!leak)
1175
1277
  return finished;
1176
- reportToolMarkupLeak(leak, model);
1278
+ reportToolMarkupLeak(leak, dialModel);
1177
1279
  return { ...finished, toolMarkupLeak: leak };
1178
1280
  }
1179
1281
  catch (err) {
@@ -1181,6 +1283,15 @@ export class ProviderRegistry {
1181
1283
  if (used && err && (typeof err === 'object' || typeof err === 'function')) {
1182
1284
  err.usedCredentialKeyHashPrefix = used.keyHashPrefix;
1183
1285
  }
1286
+ // Layer model + declared protocols onto IR refusals so the client sees
1287
+ // which dial was incompatible — not only the bare protocol id.
1288
+ if (err instanceof IrUnsupportedError) {
1289
+ throw withDialContext(err, {
1290
+ modelId: dialModel.id,
1291
+ dialWire: dialWire,
1292
+ protocols: dialModel.protocols ?? (dialModel.wire ? [dialModel.wire] : undefined),
1293
+ });
1294
+ }
1184
1295
  throw err;
1185
1296
  }
1186
1297
  }