omnicell-router 0.2.0 → 0.7.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 (947) hide show
  1. package/README.md +70 -10
  2. package/README.zh-CN.md +57 -8
  3. package/RELEASING.md +6 -0
  4. package/RELEASING.zh-CN.md +5 -0
  5. package/backend/dist/auth/api-keys.d.ts +14 -2
  6. package/backend/dist/auth/api-keys.js +26 -14
  7. package/backend/dist/auth/model-access.d.ts +27 -10
  8. package/backend/dist/auth/model-access.js +34 -17
  9. package/backend/dist/capture/migrate/engine.d.ts +38 -0
  10. package/backend/dist/capture/migrate/engine.js +307 -0
  11. package/backend/dist/capture/migrate/index.d.ts +18 -0
  12. package/backend/dist/capture/migrate/index.js +18 -0
  13. package/backend/dist/capture/migrate/migrator.d.ts +113 -0
  14. package/backend/dist/capture/migrate/migrator.js +16 -0
  15. package/backend/dist/capture/migrate/registry.d.ts +16 -0
  16. package/backend/dist/capture/migrate/registry.js +19 -0
  17. package/backend/dist/capture/migrate/steps/v1-to-v2.d.ts +86 -0
  18. package/backend/dist/capture/migrate/steps/v1-to-v2.js +396 -0
  19. package/backend/dist/capture/recorder.d.ts +422 -272
  20. package/backend/dist/capture/recorder.js +873 -417
  21. package/backend/dist/capture/turn-boundary.d.ts +17 -0
  22. package/backend/dist/capture/turn-boundary.js +31 -0
  23. package/backend/dist/cli/clients/base.d.ts +158 -23
  24. package/backend/dist/cli/clients/base.js +150 -4
  25. package/backend/dist/cli/clients/claude.d.ts +3 -2
  26. package/backend/dist/cli/clients/claude.js +4 -3
  27. package/backend/dist/cli/clients/codex.d.ts +3 -2
  28. package/backend/dist/cli/clients/codex.js +4 -3
  29. package/backend/dist/cli/clients/core-adapters.d.ts +25 -0
  30. package/backend/dist/cli/clients/core-adapters.js +44 -0
  31. package/backend/dist/cli/clients/dsh.d.ts +5 -3
  32. package/backend/dist/cli/clients/dsh.js +29 -18
  33. package/backend/dist/cli/clients/grok.d.ts +53 -0
  34. package/backend/dist/cli/clients/grok.js +249 -0
  35. package/backend/dist/cli/clients/index.d.ts +28 -19
  36. package/backend/dist/cli/clients/index.js +156 -58
  37. package/backend/dist/cli/clients/kimi.d.ts +75 -0
  38. package/backend/dist/cli/clients/kimi.js +316 -0
  39. package/backend/dist/cli/clients/launcher.d.ts +48 -0
  40. package/backend/dist/cli/clients/launcher.js +41 -0
  41. package/backend/dist/cli/clients/omp.d.ts +43 -0
  42. package/backend/dist/cli/clients/omp.js +537 -0
  43. package/backend/dist/cli/clients/openclaw.d.ts +55 -0
  44. package/backend/dist/cli/clients/openclaw.js +525 -0
  45. package/backend/dist/cli/clients/opencode.d.ts +7 -20
  46. package/backend/dist/cli/clients/opencode.js +32 -159
  47. package/backend/dist/cli/clients/pi.d.ts +7 -21
  48. package/backend/dist/cli/clients/pi.js +87 -229
  49. package/backend/dist/cli/clients/plugin-adapters.d.ts +20 -0
  50. package/backend/dist/cli/clients/plugin-adapters.js +88 -0
  51. package/backend/dist/cli/clients/reserved.d.ts +51 -0
  52. package/backend/dist/cli/clients/reserved.js +53 -0
  53. package/backend/dist/cli/clients/workbuddy.d.ts +31 -0
  54. package/backend/dist/cli/clients/workbuddy.js +259 -0
  55. package/backend/dist/cli/daemon.d.ts +105 -27
  56. package/backend/dist/cli/daemon.js +509 -151
  57. package/backend/dist/cli/index.d.ts +6 -1
  58. package/backend/dist/cli/index.js +238 -22
  59. package/backend/dist/cli/paths.d.ts +86 -0
  60. package/backend/dist/cli/paths.js +269 -0
  61. package/backend/dist/cli/shim.d.ts +47 -1
  62. package/backend/dist/cli/shim.js +180 -13
  63. package/backend/dist/cli/types.d.ts +102 -16
  64. package/backend/dist/cli/types.js +5 -4
  65. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  66. package/backend/dist/compression/caveman.d.ts +2 -16
  67. package/backend/dist/compression/caveman.js +25 -37
  68. package/backend/dist/compression/headroom.d.ts +4 -3
  69. package/backend/dist/compression/headroom.js +2 -2
  70. package/backend/dist/compression/index.d.ts +5 -26
  71. package/backend/dist/compression/index.js +79 -17
  72. package/backend/dist/compression/tool-output.d.ts +2 -20
  73. package/backend/dist/compression/tool-output.js +40 -47
  74. package/backend/dist/config/comments-en.d.ts +17 -0
  75. package/backend/dist/config/comments-en.js +232 -0
  76. package/backend/dist/config/comments-zh.d.ts +10 -0
  77. package/backend/dist/config/comments-zh.js +217 -0
  78. package/backend/dist/config/defaults.d.ts +190 -2
  79. package/backend/dist/config/defaults.js +191 -2
  80. package/backend/dist/config/env-archive.js +77 -38
  81. package/backend/dist/config/env.d.ts +4 -0
  82. package/backend/dist/config/env.js +16 -0
  83. package/backend/dist/config/index.d.ts +48 -12
  84. package/backend/dist/config/index.js +794 -368
  85. package/backend/dist/config/layout.d.ts +29 -0
  86. package/backend/dist/config/layout.js +86 -0
  87. package/backend/dist/config/migrations/v0-to-v1.d.ts +105 -0
  88. package/backend/dist/config/migrations/v0-to-v1.js +78 -0
  89. package/backend/dist/config/migrations/v1-to-v2.d.ts +14 -0
  90. package/backend/dist/config/migrations/v1-to-v2.js +41 -0
  91. package/backend/dist/config/migrations/v2-to-v3.d.ts +34 -0
  92. package/backend/dist/config/migrations/v2-to-v3.js +66 -0
  93. package/backend/dist/config/migrations/v3-to-v4.d.ts +34 -0
  94. package/backend/dist/config/migrations/v3-to-v4.js +61 -0
  95. package/backend/dist/config/runtime.d.ts +13 -0
  96. package/backend/dist/config/runtime.js +26 -0
  97. package/backend/dist/config/schema.d.ts +28 -0
  98. package/backend/dist/config/schema.js +98 -0
  99. package/backend/dist/config/types.d.ts +501 -84
  100. package/backend/dist/forward-proxy/access-log.d.ts +173 -0
  101. package/backend/dist/forward-proxy/access-log.js +657 -0
  102. package/backend/dist/forward-proxy/ca-trust.d.ts +42 -0
  103. package/backend/dist/forward-proxy/ca-trust.js +242 -0
  104. package/backend/dist/forward-proxy/ca.d.ts +66 -2
  105. package/backend/dist/forward-proxy/ca.js +146 -11
  106. package/backend/dist/forward-proxy/caller-context.d.ts +18 -0
  107. package/backend/dist/forward-proxy/caller-context.js +20 -0
  108. package/backend/dist/forward-proxy/egress.d.ts +104 -0
  109. package/backend/dist/forward-proxy/egress.js +280 -0
  110. package/backend/dist/forward-proxy/h2-forward.d.ts +66 -0
  111. package/backend/dist/forward-proxy/h2-forward.js +526 -0
  112. package/backend/dist/forward-proxy/index.d.ts +13 -1
  113. package/backend/dist/forward-proxy/index.js +148 -7
  114. package/backend/dist/forward-proxy/interceptor.d.ts +16 -13
  115. package/backend/dist/forward-proxy/interceptor.js +35 -57
  116. package/backend/dist/forward-proxy/relay.d.ts +21 -1
  117. package/backend/dist/forward-proxy/relay.js +48 -1
  118. package/backend/dist/forward-proxy/rules.d.ts +148 -0
  119. package/backend/dist/forward-proxy/rules.js +280 -0
  120. package/backend/dist/forward-proxy/server.d.ts +102 -9
  121. package/backend/dist/forward-proxy/server.js +1310 -305
  122. package/backend/dist/forward-proxy/sni.d.ts +29 -7
  123. package/backend/dist/forward-proxy/sni.js +109 -47
  124. package/backend/dist/forward-proxy/system-proxy.d.ts +72 -0
  125. package/backend/dist/forward-proxy/system-proxy.js +303 -0
  126. package/backend/dist/forward-proxy/upstream-tls.d.ts +46 -0
  127. package/backend/dist/forward-proxy/upstream-tls.js +105 -0
  128. package/backend/dist/forward-proxy/ws-frames.d.ts +45 -0
  129. package/backend/dist/forward-proxy/ws-frames.js +153 -0
  130. package/backend/dist/harness/common/catalog-registry.d.ts +63 -0
  131. package/backend/dist/harness/common/catalog-registry.js +77 -0
  132. package/backend/dist/harness/common/github.d.ts +6 -0
  133. package/backend/dist/harness/common/github.js +13 -0
  134. package/backend/dist/harness/common/market.d.ts +590 -0
  135. package/backend/dist/harness/common/market.js +1079 -0
  136. package/backend/dist/harness/common/marketplace-rescan-scheduler.d.ts +24 -0
  137. package/backend/dist/harness/common/marketplace-rescan-scheduler.js +62 -0
  138. package/backend/dist/harness/{catalog-npm.d.ts → common/npm-catalog.d.ts} +5 -5
  139. package/backend/dist/harness/{catalog-npm.js → common/npm-catalog.js} +7 -7
  140. package/backend/dist/harness/common/npm-source.d.ts +29 -0
  141. package/backend/dist/harness/common/npm-source.js +121 -0
  142. package/backend/dist/harness/common/pypi-source.d.ts +28 -0
  143. package/backend/dist/harness/common/pypi-source.js +71 -0
  144. package/backend/dist/harness/common/source-views.d.ts +22 -0
  145. package/backend/dist/harness/common/source-views.js +25 -0
  146. package/backend/dist/harness/{stars.d.ts → common/stars.d.ts} +1 -1
  147. package/backend/dist/harness/{stars.js → common/stars.js} +2 -2
  148. package/backend/dist/harness/common/text.d.ts +11 -0
  149. package/backend/dist/harness/common/text.js +18 -0
  150. package/backend/dist/harness/config-file.d.ts +14 -1
  151. package/backend/dist/harness/config-file.js +38 -0
  152. package/backend/dist/harness/db-probe.d.ts +29 -0
  153. package/backend/dist/harness/db-probe.js +270 -0
  154. package/backend/dist/harness/detail.d.ts +10 -1
  155. package/backend/dist/harness/detail.js +144 -7
  156. package/backend/dist/harness/host/adapters/amp.d.ts +19 -0
  157. package/backend/dist/harness/host/adapters/amp.js +21 -0
  158. package/backend/dist/harness/host/adapters/antigravity.d.ts +18 -0
  159. package/backend/dist/harness/host/adapters/antigravity.js +21 -0
  160. package/backend/dist/harness/host/adapters/base.d.ts +225 -0
  161. package/backend/dist/harness/host/adapters/base.js +521 -0
  162. package/backend/dist/harness/host/adapters/claude.d.ts +54 -0
  163. package/backend/dist/harness/host/adapters/claude.js +145 -0
  164. package/backend/dist/harness/host/adapters/cline.d.ts +18 -0
  165. package/backend/dist/harness/host/adapters/cline.js +20 -0
  166. package/backend/dist/harness/host/adapters/codex.d.ts +54 -0
  167. package/backend/dist/harness/host/adapters/codex.js +133 -0
  168. package/backend/dist/harness/host/adapters/cursor.d.ts +18 -0
  169. package/backend/dist/harness/host/adapters/cursor.js +24 -0
  170. package/backend/dist/harness/host/adapters/declarative.d.ts +22 -0
  171. package/backend/dist/harness/host/adapters/declarative.js +38 -0
  172. package/backend/dist/harness/host/adapters/dsh.d.ts +76 -0
  173. package/backend/dist/harness/host/adapters/dsh.js +253 -0
  174. package/backend/dist/harness/host/adapters/factory.d.ts +36 -0
  175. package/backend/dist/harness/host/adapters/factory.js +34 -0
  176. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +17 -0
  177. package/backend/dist/harness/host/adapters/gemini-cli.js +19 -0
  178. package/backend/dist/harness/host/adapters/grok.d.ts +66 -0
  179. package/backend/dist/harness/host/adapters/grok.js +136 -0
  180. package/backend/dist/harness/{adapters → host/adapters}/index.d.ts +18 -5
  181. package/backend/dist/harness/{adapters → host/adapters}/index.js +73 -5
  182. package/backend/dist/harness/host/adapters/kimi.d.ts +30 -0
  183. package/backend/dist/harness/host/adapters/kimi.js +59 -0
  184. package/backend/dist/harness/host/adapters/omp.d.ts +55 -0
  185. package/backend/dist/harness/host/adapters/omp.js +90 -0
  186. package/backend/dist/harness/host/adapters/openclaw.d.ts +54 -0
  187. package/backend/dist/harness/host/adapters/openclaw.js +141 -0
  188. package/backend/dist/harness/host/adapters/opencode.d.ts +24 -0
  189. package/backend/dist/harness/host/adapters/opencode.js +48 -0
  190. package/backend/dist/harness/host/adapters/pi.d.ts +27 -0
  191. package/backend/dist/harness/host/adapters/pi.js +58 -0
  192. package/backend/dist/harness/host/adapters/types.d.ts +395 -0
  193. package/backend/dist/harness/host/adapters/types.js +17 -0
  194. package/backend/dist/harness/host/adapters/universal.d.ts +14 -0
  195. package/backend/dist/harness/host/adapters/universal.js +18 -0
  196. package/backend/dist/harness/host/adapters/windsurf.d.ts +20 -0
  197. package/backend/dist/harness/host/adapters/windsurf.js +22 -0
  198. package/backend/dist/harness/host/adapters/zed.d.ts +12 -0
  199. package/backend/dist/harness/host/adapters/zed.js +14 -0
  200. package/backend/dist/harness/host/claude-mcp-runtime.d.ts +6 -0
  201. package/backend/dist/harness/host/claude-mcp-runtime.js +56 -0
  202. package/backend/dist/harness/{discover.d.ts → host/discover.d.ts} +54 -18
  203. package/backend/dist/harness/{discover.js → host/discover.js} +314 -53
  204. package/backend/dist/harness/{drift.d.ts → host/drift.d.ts} +1 -1
  205. package/backend/dist/harness/{drift.js → host/drift.js} +1 -1
  206. package/backend/dist/harness/host/grok-mcp-runtime.d.ts +6 -0
  207. package/backend/dist/harness/host/grok-mcp-runtime.js +56 -0
  208. package/backend/dist/harness/{hosts.d.ts → host/hosts.d.ts} +3 -3
  209. package/backend/dist/harness/{hosts.js → host/hosts.js} +7 -2
  210. package/backend/dist/harness/host/index.d.ts +10 -0
  211. package/backend/dist/harness/host/index.js +12 -0
  212. package/backend/dist/harness/host/install-log.d.ts +22 -0
  213. package/backend/dist/harness/host/install-log.js +106 -0
  214. package/backend/dist/harness/{install.d.ts → host/install.d.ts} +32 -13
  215. package/backend/dist/harness/{install.js → host/install.js} +133 -50
  216. package/backend/dist/harness/host/inventory.d.ts +30 -0
  217. package/backend/dist/harness/{inventory.js → host/inventory.js} +107 -16
  218. package/backend/dist/harness/host/kimi-mcp-runtime.d.ts +6 -0
  219. package/backend/dist/harness/host/kimi-mcp-runtime.js +84 -0
  220. package/backend/dist/harness/{ledger.d.ts → host/ledger.d.ts} +1 -1
  221. package/backend/dist/harness/{ledger.js → host/ledger.js} +3 -3
  222. package/backend/dist/harness/{maintenance.d.ts → host/maintenance.d.ts} +23 -6
  223. package/backend/dist/harness/{maintenance.js → host/maintenance.js} +355 -63
  224. package/backend/dist/harness/{manifest.d.ts → host/manifest.d.ts} +11 -2
  225. package/backend/dist/harness/{manifest.js → host/manifest.js} +76 -15
  226. package/backend/dist/harness/host/marketplace-sync.d.ts +64 -0
  227. package/backend/dist/harness/host/marketplace-sync.js +231 -0
  228. package/backend/dist/harness/host/mcp-cli.d.ts +44 -0
  229. package/backend/dist/harness/host/mcp-cli.js +545 -0
  230. package/backend/dist/harness/host/mcp-edit.d.ts +89 -0
  231. package/backend/dist/harness/host/mcp-edit.js +342 -0
  232. package/backend/dist/harness/host/mcp-entry.d.ts +100 -0
  233. package/backend/dist/harness/host/mcp-entry.js +435 -0
  234. package/backend/dist/harness/host/mcp-inspector.d.ts +125 -0
  235. package/backend/dist/harness/host/mcp-inspector.js +634 -0
  236. package/backend/dist/harness/host/mcp-registry.d.ts +66 -0
  237. package/backend/dist/harness/host/mcp-registry.js +331 -0
  238. package/backend/dist/harness/host/mcp-runtime.d.ts +19 -0
  239. package/backend/dist/harness/host/mcp-runtime.js +22 -0
  240. package/backend/dist/harness/host/opencode-mcp-runtime.d.ts +7 -0
  241. package/backend/dist/harness/host/opencode-mcp-runtime.js +73 -0
  242. package/backend/dist/harness/{probe.d.ts → host/probe.d.ts} +4 -4
  243. package/backend/dist/harness/{probe.js → host/probe.js} +8 -8
  244. package/backend/dist/harness/{registry.d.ts → host/registry.d.ts} +1 -1
  245. package/backend/dist/harness/host/registry.js +28 -0
  246. package/backend/dist/harness/host/request.d.ts +56 -0
  247. package/backend/dist/harness/host/request.js +1 -0
  248. package/backend/dist/harness/{sources → host/resolvers}/clawhub.d.ts +1 -1
  249. package/backend/dist/harness/{sources → host/resolvers}/clawhub.js +1 -1
  250. package/backend/dist/harness/host/resolvers/git-marketplace.d.ts +16 -0
  251. package/backend/dist/harness/host/resolvers/git-marketplace.js +53 -0
  252. package/backend/dist/harness/{sources → host/resolvers}/github.d.ts +1 -1
  253. package/backend/dist/harness/{sources → host/resolvers}/github.js +2 -2
  254. package/backend/dist/harness/host/resolvers/npm.d.ts +2 -0
  255. package/backend/dist/harness/{sources → host/resolvers}/npm.js +16 -10
  256. package/backend/dist/harness/host/resolvers/pypi.d.ts +2 -0
  257. package/backend/dist/harness/host/resolvers/pypi.js +100 -0
  258. package/backend/dist/harness/host/scopes.d.ts +11 -0
  259. package/backend/dist/harness/host/scopes.js +12 -0
  260. package/backend/dist/harness/host/timeouts.d.ts +8 -0
  261. package/backend/dist/harness/host/timeouts.js +8 -0
  262. package/backend/dist/harness/host/writers/kimi-web.d.ts +70 -0
  263. package/backend/dist/harness/host/writers/kimi-web.js +222 -0
  264. package/backend/dist/harness/host/writers/mcp.d.ts +119 -0
  265. package/backend/dist/harness/host/writers/mcp.js +359 -0
  266. package/backend/dist/harness/host/writers/plugin.d.ts +176 -0
  267. package/backend/dist/harness/host/writers/plugin.js +528 -0
  268. package/backend/dist/harness/{writers → host/writers}/skill.d.ts +3 -3
  269. package/backend/dist/harness/{writers → host/writers}/skill.js +6 -3
  270. package/backend/dist/harness/lang.d.ts +14 -0
  271. package/backend/dist/harness/lang.js +33 -0
  272. package/backend/dist/harness/net.d.ts +33 -0
  273. package/backend/dist/harness/net.js +63 -0
  274. package/backend/dist/harness/plugin/adapters/antigravity.d.ts +11 -0
  275. package/backend/dist/harness/plugin/adapters/antigravity.js +14 -0
  276. package/backend/dist/harness/plugin/adapters/base.d.ts +107 -0
  277. package/backend/dist/harness/plugin/adapters/base.js +454 -0
  278. package/backend/dist/harness/plugin/adapters/claude.d.ts +28 -0
  279. package/backend/dist/harness/plugin/adapters/claude.js +63 -0
  280. package/backend/dist/harness/plugin/adapters/codex.d.ts +13 -0
  281. package/backend/dist/harness/plugin/adapters/codex.js +16 -0
  282. package/backend/dist/harness/plugin/adapters/cursor.d.ts +13 -0
  283. package/backend/dist/harness/plugin/adapters/cursor.js +16 -0
  284. package/backend/dist/harness/plugin/adapters/dsh-plugin-net.d.ts +20 -0
  285. package/backend/dist/harness/plugin/adapters/dsh-plugin-net.js +371 -0
  286. package/backend/dist/harness/plugin/adapters/dsh.d.ts +22 -0
  287. package/backend/dist/harness/plugin/adapters/dsh.js +50 -0
  288. package/backend/dist/harness/plugin/adapters/factory.d.ts +11 -0
  289. package/backend/dist/harness/plugin/adapters/factory.js +19 -0
  290. package/backend/dist/harness/plugin/adapters/gemini.d.ts +12 -0
  291. package/backend/dist/harness/plugin/adapters/gemini.js +22 -0
  292. package/backend/dist/harness/plugin/adapters/grok.d.ts +15 -0
  293. package/backend/dist/harness/plugin/adapters/grok.js +23 -0
  294. package/backend/dist/harness/plugin/adapters/index.d.ts +41 -0
  295. package/backend/dist/harness/plugin/adapters/index.js +143 -0
  296. package/backend/dist/harness/plugin/adapters/kimi.d.ts +6 -0
  297. package/backend/dist/harness/plugin/adapters/kimi.js +35 -0
  298. package/backend/dist/harness/plugin/adapters/omp.d.ts +19 -0
  299. package/backend/dist/harness/plugin/adapters/omp.js +26 -0
  300. package/backend/dist/harness/plugin/adapters/openclaw.d.ts +20 -0
  301. package/backend/dist/harness/plugin/adapters/openclaw.js +36 -0
  302. package/backend/dist/harness/plugin/adapters/pi-dev.d.ts +124 -0
  303. package/backend/dist/harness/plugin/adapters/pi-dev.js +420 -0
  304. package/backend/dist/harness/plugin/adapters/pi-github.d.ts +18 -0
  305. package/backend/dist/harness/plugin/adapters/pi-github.js +27 -0
  306. package/backend/dist/harness/plugin/adapters/universal.d.ts +11 -0
  307. package/backend/dist/harness/plugin/adapters/universal.js +18 -0
  308. package/backend/dist/harness/plugin/builtin.d.ts +13 -0
  309. package/backend/dist/harness/plugin/builtin.js +34 -0
  310. package/backend/dist/harness/plugin/catalog.d.ts +30 -0
  311. package/backend/dist/harness/plugin/catalog.js +200 -0
  312. package/backend/dist/harness/plugin/index.d.ts +9 -0
  313. package/backend/dist/harness/plugin/index.js +9 -0
  314. package/backend/dist/harness/plugin/types.d.ts +164 -0
  315. package/backend/dist/harness/plugin/types.js +1 -0
  316. package/backend/dist/harness/{clawhub.d.ts → skill/clawhub.d.ts} +28 -5
  317. package/backend/dist/harness/{clawhub.js → skill/clawhub.js} +170 -5
  318. package/backend/dist/harness/skill/skills-sh.d.ts +47 -0
  319. package/backend/dist/harness/skill/skills-sh.js +270 -0
  320. package/backend/dist/harness/skill/sources.d.ts +41 -0
  321. package/backend/dist/harness/skill/sources.js +131 -0
  322. package/backend/dist/harness/spi.d.ts +11 -7
  323. package/backend/dist/harness/tcp-reach.d.ts +30 -0
  324. package/backend/dist/harness/tcp-reach.js +61 -0
  325. package/backend/dist/harness/translation.d.ts +31 -13
  326. package/backend/dist/harness/translation.js +212 -62
  327. package/backend/dist/harness/types.d.ts +61 -16
  328. package/backend/dist/index.js +170 -16
  329. package/backend/dist/ir/adapters/anthropic-messages-stream.d.ts +18 -0
  330. package/backend/dist/ir/adapters/anthropic-messages-stream.js +266 -0
  331. package/backend/dist/ir/adapters/anthropic-messages.d.ts +30 -0
  332. package/backend/dist/ir/adapters/anthropic-messages.js +870 -0
  333. package/backend/dist/ir/adapters/google-gemini-stream.d.ts +22 -0
  334. package/backend/dist/ir/adapters/google-gemini-stream.js +246 -0
  335. package/backend/dist/ir/adapters/google-gemini.d.ts +9 -0
  336. package/backend/dist/ir/adapters/google-gemini.js +450 -0
  337. package/backend/dist/ir/adapters/openai-chat-stream.d.ts +41 -0
  338. package/backend/dist/ir/adapters/openai-chat-stream.js +369 -0
  339. package/backend/dist/ir/adapters/openai-chat.d.ts +17 -0
  340. package/backend/dist/ir/adapters/openai-chat.js +670 -0
  341. package/backend/dist/ir/adapters/openai-responses-output.d.ts +50 -0
  342. package/backend/dist/ir/adapters/openai-responses-output.js +353 -0
  343. package/backend/dist/ir/adapters/openai-responses-stream.d.ts +12 -0
  344. package/backend/dist/ir/adapters/openai-responses-stream.js +193 -0
  345. package/backend/dist/ir/adapters/openai-responses.d.ts +14 -0
  346. package/backend/dist/ir/adapters/openai-responses.js +670 -0
  347. package/backend/dist/ir/capabilities.d.ts +41 -0
  348. package/backend/dist/ir/capabilities.js +147 -0
  349. package/backend/dist/ir/errors.d.ts +23 -0
  350. package/backend/dist/ir/errors.js +31 -0
  351. package/backend/dist/ir/index.d.ts +5 -0
  352. package/backend/dist/ir/index.js +5 -0
  353. package/backend/dist/ir/media.d.ts +2 -0
  354. package/backend/dist/ir/media.js +2 -0
  355. package/backend/dist/ir/stream.d.ts +17 -0
  356. package/backend/dist/ir/stream.js +250 -0
  357. package/backend/dist/ir/types.d.ts +523 -0
  358. package/backend/dist/ir/types.js +19 -0
  359. package/backend/dist/ir/validate.d.ts +18 -0
  360. package/backend/dist/ir/validate.js +272 -0
  361. package/backend/dist/metrics/request-cost.d.ts +3 -11
  362. package/backend/dist/metrics/request-cost.js +9 -27
  363. package/backend/dist/observability/failure-events.d.ts +20 -4
  364. package/backend/dist/observability/failure-events.js +9 -1
  365. package/backend/dist/observability/http-exchange.d.ts +75 -27
  366. package/backend/dist/observability/http-exchange.js +136 -39
  367. package/backend/dist/observability/request-identity.d.ts +40 -0
  368. package/backend/dist/observability/request-identity.js +102 -0
  369. package/backend/dist/observability/traffic-live-hidden.d.ts +24 -0
  370. package/backend/dist/observability/traffic-live-hidden.js +82 -0
  371. package/backend/dist/observability/upstream-body-redaction.d.ts +23 -0
  372. package/backend/dist/observability/upstream-body-redaction.js +72 -0
  373. package/backend/dist/observability/upstream-events.d.ts +16 -10
  374. package/backend/dist/observability/upstream-events.js +17 -11
  375. package/backend/dist/opencode/agents.d.ts +10 -2
  376. package/backend/dist/opencode/agents.js +22 -3
  377. package/backend/dist/opencode/catalog/auto-pull.d.ts +35 -1
  378. package/backend/dist/opencode/catalog/auto-pull.js +169 -33
  379. package/backend/dist/opencode/catalog/ocr-store.d.ts +6 -6
  380. package/backend/dist/opencode/catalog/ocr-store.js +2 -2
  381. package/backend/dist/opencode/catalog/overrides-store.d.ts +6 -5
  382. package/backend/dist/opencode/catalog/overrides-store.js +28 -3
  383. package/backend/dist/opencode/catalog/repository.d.ts +4 -0
  384. package/backend/dist/opencode/catalog/repository.js +19 -0
  385. package/backend/dist/opencode/catalog/sources/models-dev.d.ts +4 -0
  386. package/backend/dist/opencode/catalog/sources/models-dev.js +15 -4
  387. package/backend/dist/opencode/catalog/types.d.ts +10 -7
  388. package/backend/dist/opencode/connector.d.ts +2 -2
  389. package/backend/dist/opencode/connector.js +2 -2
  390. package/backend/dist/opencode/credentials/def-materialize.d.ts +0 -5
  391. package/backend/dist/opencode/credentials/def-materialize.js +149 -11
  392. package/backend/dist/opencode/credentials/ocr-store.d.ts +18 -0
  393. package/backend/dist/opencode/credentials/ocr-store.js +88 -7
  394. package/backend/dist/opencode/credentials/opencode-v2-store.d.ts +24 -13
  395. package/backend/dist/opencode/credentials/opencode-v2-store.js +70 -29
  396. package/backend/dist/opencode/credentials/paths.d.ts +8 -0
  397. package/backend/dist/opencode/credentials/paths.js +10 -0
  398. package/backend/dist/opencode/credentials/sync.d.ts +1 -1
  399. package/backend/dist/opencode/credentials/sync.js +4 -4
  400. package/backend/dist/opencode/credentials/types.d.ts +40 -4
  401. package/backend/dist/opencode/probe.d.ts +9 -5
  402. package/backend/dist/opencode/probe.js +68 -15
  403. package/backend/dist/opencode/provider-defs.js +59 -2
  404. package/backend/dist/opencode/provider-package.d.ts +31 -0
  405. package/backend/dist/opencode/provider-package.js +70 -0
  406. package/backend/dist/opencode/user-config.d.ts +11 -17
  407. package/backend/dist/opencode/user-config.js +42 -66
  408. package/backend/dist/pipeline/credential-selection.d.ts +13 -0
  409. package/backend/dist/pipeline/credential-selection.js +29 -1
  410. package/backend/dist/pipeline/directives.d.ts +14 -22
  411. package/backend/dist/pipeline/directives.js +122 -68
  412. package/backend/dist/pipeline/orchestrator.d.ts +42 -7
  413. package/backend/dist/pipeline/orchestrator.js +736 -235
  414. package/backend/dist/pipeline/prompt-optimizer.d.ts +6 -13
  415. package/backend/dist/pipeline/prompt-optimizer.js +9 -52
  416. package/backend/dist/pipeline/streaming-posture.d.ts +29 -0
  417. package/backend/dist/pipeline/streaming-posture.js +27 -0
  418. package/backend/dist/pipeline/tool-pairing.d.ts +10 -0
  419. package/backend/dist/pipeline/tool-pairing.js +90 -0
  420. package/backend/dist/plugins/builtin/model-gateway.d.ts +30 -0
  421. package/backend/dist/plugins/builtin/model-gateway.js +98 -0
  422. package/backend/dist/plugins/config.d.ts +41 -0
  423. package/backend/dist/plugins/config.js +113 -0
  424. package/backend/dist/plugins/gateways.d.ts +98 -0
  425. package/backend/dist/plugins/gateways.js +151 -0
  426. package/backend/dist/plugins/host.d.ts +203 -0
  427. package/backend/dist/plugins/host.js +1310 -0
  428. package/backend/dist/plugins/manifest.d.ts +43 -0
  429. package/backend/dist/plugins/manifest.js +462 -0
  430. package/backend/dist/plugins/pack.d.ts +32 -0
  431. package/backend/dist/plugins/pack.js +222 -0
  432. package/backend/dist/plugins/seed.d.ts +53 -0
  433. package/backend/dist/plugins/seed.js +136 -0
  434. package/backend/dist/plugins/types.d.ts +721 -0
  435. package/backend/dist/plugins/types.js +1 -0
  436. package/backend/dist/projects/store.d.ts +56 -0
  437. package/backend/dist/projects/store.js +194 -0
  438. package/backend/dist/projects/types.d.ts +12 -0
  439. package/backend/dist/projects/types.js +1 -0
  440. package/backend/dist/protocols/chat-compat.d.ts +2 -0
  441. package/backend/dist/protocols/chat-compat.js +137 -0
  442. package/backend/dist/protocols/systemone/convert.d.ts +5 -4
  443. package/backend/dist/protocols/systemone/convert.js +72 -26
  444. package/backend/dist/protocols/systemone/decide.js +128 -51
  445. package/backend/dist/protocols/systemone/native.d.ts +1 -1
  446. package/backend/dist/protocols/systemone/native.js +6 -6
  447. package/backend/dist/providers/anthropic.js +6 -6
  448. package/backend/dist/providers/base.d.ts +8 -47
  449. package/backend/dist/providers/boot-direct.d.ts +20 -2
  450. package/backend/dist/providers/boot-direct.js +72 -23
  451. package/backend/dist/providers/compat/tool-markup-leak.d.ts +41 -0
  452. package/backend/dist/providers/compat/tool-markup-leak.js +57 -0
  453. package/backend/dist/providers/compat/tool-markup-recovery.d.ts +27 -0
  454. package/backend/dist/providers/compat/tool-markup-recovery.js +831 -0
  455. package/backend/dist/providers/dispatch.d.ts +5 -8
  456. package/backend/dist/providers/dispatch.js +18 -12
  457. package/backend/dist/providers/executors/anthropic-messages.d.ts +12 -0
  458. package/backend/dist/providers/executors/anthropic-messages.js +56 -0
  459. package/backend/dist/providers/executors/dispatch.d.ts +14 -0
  460. package/backend/dist/providers/executors/dispatch.js +71 -0
  461. package/backend/dist/providers/executors/google-gemini.d.ts +12 -0
  462. package/backend/dist/providers/executors/google-gemini.js +53 -0
  463. package/backend/dist/providers/executors/http-json.d.ts +19 -0
  464. package/backend/dist/providers/executors/http-json.js +125 -0
  465. package/backend/dist/providers/executors/http-stream.d.ts +53 -0
  466. package/backend/dist/providers/executors/http-stream.js +472 -0
  467. package/backend/dist/providers/executors/openai-chat.d.ts +13 -0
  468. package/backend/dist/providers/executors/openai-chat.js +89 -0
  469. package/backend/dist/providers/executors/openai-responses.d.ts +12 -0
  470. package/backend/dist/providers/executors/openai-responses.js +71 -0
  471. package/backend/dist/providers/executors/plugin-adapter.d.ts +9 -0
  472. package/backend/dist/providers/executors/plugin-adapter.js +31 -0
  473. package/backend/dist/providers/google.js +6 -6
  474. package/backend/dist/providers/openai-compatible.js +13 -13
  475. package/backend/dist/providers/opencode-proxy.js +6 -6
  476. package/backend/dist/providers/plugin-wires.d.ts +34 -0
  477. package/backend/dist/providers/plugin-wires.js +82 -0
  478. package/backend/dist/providers/pool-refresh.d.ts +14 -0
  479. package/backend/dist/providers/pool-refresh.js +13 -0
  480. package/backend/dist/providers/protocol.d.ts +4 -0
  481. package/backend/dist/providers/protocol.js +61 -0
  482. package/backend/dist/providers/provider-takedown.d.ts +59 -0
  483. package/backend/dist/providers/provider-takedown.js +135 -0
  484. package/backend/dist/providers/registry.d.ts +37 -21
  485. package/backend/dist/providers/registry.js +204 -109
  486. package/backend/dist/providers/responses.d.ts +4 -2
  487. package/backend/dist/providers/responses.js +12 -9
  488. package/backend/dist/providers/vocabulary.d.ts +24 -6
  489. package/backend/dist/providers/vocabulary.js +75 -33
  490. package/backend/dist/providers/wire.d.ts +12 -17
  491. package/backend/dist/providers/wire.js +43 -91
  492. package/backend/dist/proxy/manual-node-spec.d.ts +92 -0
  493. package/backend/dist/proxy/manual-node-spec.js +408 -0
  494. package/backend/dist/proxy/mihomo-binary.d.ts +39 -0
  495. package/backend/dist/proxy/mihomo-binary.js +267 -0
  496. package/backend/dist/proxy/mihomo-client.d.ts +94 -0
  497. package/backend/dist/proxy/mihomo-client.js +294 -0
  498. package/backend/dist/proxy/mihomo-config.d.ts +40 -0
  499. package/backend/dist/proxy/mihomo-config.js +152 -0
  500. package/backend/dist/proxy/mihomo-pac.d.ts +26 -0
  501. package/backend/dist/proxy/mihomo-pac.js +60 -0
  502. package/backend/dist/proxy/mihomo-rules-import.d.ts +43 -0
  503. package/backend/dist/proxy/mihomo-rules-import.js +193 -0
  504. package/backend/dist/proxy/mihomo-sidecar.d.ts +65 -0
  505. package/backend/dist/proxy/mihomo-sidecar.js +515 -0
  506. package/backend/dist/quota/engine.d.ts +9 -2
  507. package/backend/dist/quota/engine.js +19 -1
  508. package/backend/dist/quota/prober.d.ts +8 -4
  509. package/backend/dist/quota/prober.js +9 -10
  510. package/backend/dist/ratelimit/rate-limiter.d.ts +119 -6
  511. package/backend/dist/ratelimit/rate-limiter.js +358 -20
  512. package/backend/dist/ratelimit/window-store.d.ts +34 -0
  513. package/backend/dist/ratelimit/window-store.js +70 -0
  514. package/backend/dist/resilience/breaker-state.js +8 -1
  515. package/backend/dist/resilience/circuit-breaker-manager.d.ts +229 -132
  516. package/backend/dist/resilience/circuit-breaker-manager.js +566 -297
  517. package/backend/dist/resilience/circuit-breaker.d.ts +11 -0
  518. package/backend/dist/resilience/circuit-breaker.js +39 -7
  519. package/backend/dist/resilience/error-classifier.d.ts +31 -3
  520. package/backend/dist/resilience/error-classifier.js +159 -31
  521. package/backend/dist/resilience/health-prober.d.ts +21 -4
  522. package/backend/dist/resilience/health-prober.js +100 -18
  523. package/backend/dist/resilience/types.d.ts +56 -9
  524. package/backend/dist/resilience/types.js +1 -1
  525. package/backend/dist/router/index.d.ts +6 -29
  526. package/backend/dist/router/index.js +15 -61
  527. package/backend/dist/router/layer2-decision.d.ts +2 -2
  528. package/backend/dist/router/layer2-decision.js +22 -19
  529. package/backend/dist/router/request-traits.d.ts +4 -11
  530. package/backend/dist/router/request-traits.js +5 -13
  531. package/backend/dist/routes/console.js +1948 -253
  532. package/backend/dist/routes/environments.d.ts +3 -2
  533. package/backend/dist/routes/environments.js +8 -4
  534. package/backend/dist/routes/harness.d.ts +3 -1
  535. package/backend/dist/routes/harness.js +1164 -355
  536. package/backend/dist/routes/mihomo.d.ts +5 -0
  537. package/backend/dist/routes/mihomo.js +882 -0
  538. package/backend/dist/routes/projects.d.ts +2 -0
  539. package/backend/dist/routes/projects.js +90 -0
  540. package/backend/dist/routes/responses.d.ts +20 -1
  541. package/backend/dist/routes/responses.js +65 -3
  542. package/backend/dist/routes/translation.d.ts +9 -0
  543. package/backend/dist/routes/translation.js +155 -0
  544. package/backend/dist/server.d.ts +0 -15
  545. package/backend/dist/server.js +388 -105
  546. package/backend/dist/session/resp-store.d.ts +18 -49
  547. package/backend/dist/session/resp-store.js +114 -122
  548. package/backend/dist/session/session-manager.d.ts +237 -81
  549. package/backend/dist/session/session-manager.js +445 -180
  550. package/backend/dist/session/session-row.d.ts +157 -0
  551. package/backend/dist/session/session-row.js +120 -0
  552. package/backend/dist/surfaces/anthropic.d.ts +1 -15
  553. package/backend/dist/surfaces/anthropic.js +63 -44
  554. package/backend/dist/surfaces/chat-pipeline.d.ts +8 -4
  555. package/backend/dist/surfaces/chat-pipeline.js +102 -35
  556. package/backend/dist/surfaces/chat.d.ts +1 -9
  557. package/backend/dist/surfaces/chat.js +52 -29
  558. package/backend/dist/surfaces/decision-pipeline.js +26 -18
  559. package/backend/dist/surfaces/gateway-chat.d.ts +53 -0
  560. package/backend/dist/surfaces/gateway-chat.js +204 -0
  561. package/backend/dist/surfaces/ocr-headers.d.ts +25 -4
  562. package/backend/dist/surfaces/ocr-headers.js +52 -6
  563. package/backend/dist/surfaces/responses.d.ts +9 -1
  564. package/backend/dist/surfaces/responses.js +141 -141
  565. package/backend/dist/surfaces/systemone-probe.js +1 -1
  566. package/backend/dist/surfaces/systemone.d.ts +1 -1
  567. package/backend/dist/surfaces/systemone.js +1 -1
  568. package/backend/dist/surfaces/table.d.ts +15 -0
  569. package/backend/dist/surfaces/table.js +15 -0
  570. package/backend/dist/surfaces/transport-backpressure.d.ts +46 -0
  571. package/backend/dist/surfaces/transport-backpressure.js +122 -0
  572. package/backend/dist/surfaces/transport-fastify.js +92 -21
  573. package/backend/dist/surfaces/transport-node-http.js +92 -18
  574. package/backend/dist/surfaces/types.d.ts +74 -12
  575. package/backend/dist/trace/persist.d.ts +5 -0
  576. package/backend/dist/trace/persist.js +185 -24
  577. package/backend/dist/trace/tracker.d.ts +153 -16
  578. package/backend/dist/trace/tracker.js +77 -27
  579. package/backend/dist/translation/index.d.ts +151 -0
  580. package/backend/dist/translation/index.js +735 -0
  581. package/backend/dist/types/openai.d.ts +82 -1
  582. package/backend/dist/types/router.d.ts +71 -6
  583. package/backend/dist/types/router.js +33 -1
  584. package/backend/dist/update/check.d.ts +43 -0
  585. package/backend/dist/update/check.js +126 -0
  586. package/backend/dist/utils/chat-sse.d.ts +2 -22
  587. package/backend/dist/utils/chat-sse.js +1 -69
  588. package/backend/dist/utils/chat-stream.d.ts +2 -1
  589. package/backend/dist/utils/client-envelope.d.ts +108 -0
  590. package/backend/dist/utils/client-envelope.js +305 -0
  591. package/backend/dist/utils/event-ring.d.ts +8 -1
  592. package/backend/dist/utils/event-ring.js +13 -5
  593. package/backend/dist/utils/harness-profiles.d.ts +51 -0
  594. package/backend/dist/utils/harness-profiles.js +70 -0
  595. package/backend/dist/utils/percentile.d.ts +16 -0
  596. package/backend/dist/utils/percentile.js +29 -0
  597. package/backend/dist/utils/popularity.d.ts +4 -0
  598. package/backend/dist/utils/popularity.js +33 -0
  599. package/backend/dist/utils/probe-interval.d.ts +12 -0
  600. package/backend/dist/utils/probe-interval.js +16 -0
  601. package/backend/dist/utils/proxy-node.d.ts +13 -0
  602. package/backend/dist/utils/proxy-node.js +471 -0
  603. package/backend/dist/utils/proxy.d.ts +12 -0
  604. package/backend/dist/utils/proxy.js +44 -4
  605. package/backend/dist/utils/run-command.d.ts +42 -0
  606. package/backend/dist/utils/run-command.js +93 -0
  607. package/backend/dist/utils/self-url.d.ts +13 -0
  608. package/backend/dist/utils/self-url.js +90 -2
  609. package/backend/dist/utils/semver.d.ts +22 -0
  610. package/backend/dist/utils/semver.js +75 -0
  611. package/backend/dist/utils/stream-relay.d.ts +35 -0
  612. package/backend/dist/utils/stream-relay.js +1 -0
  613. package/backend/dist/utils/upstream-url-guard.d.ts +15 -0
  614. package/backend/dist/utils/upstream-url-guard.js +107 -0
  615. package/backend/dist/validator/parser.d.ts +2 -5
  616. package/backend/dist/validator/parser.js +12 -16
  617. package/backend/dist/validator/schema-assertion.d.ts +3 -2
  618. package/backend/dist/validator/schema-assertion.js +53 -8
  619. package/bin/ocr.js +2 -2
  620. package/frontend/dist/assets/index-CLvxJjp_.js +1476 -0
  621. package/frontend/dist/assets/index-CQSLGFTV.css +1 -0
  622. package/frontend/dist/assets/qoder.color-tVX5GCcD.svg +5 -0
  623. package/frontend/dist/index.html +2 -2
  624. package/frontend/dist/provider-logos/302ai.svg +7 -0
  625. package/frontend/dist/provider-logos/NOTICE.txt +39 -0
  626. package/frontend/dist/provider-logos/abacus.svg +14 -0
  627. package/frontend/dist/provider-logos/abliteration-ai.svg +6 -0
  628. package/frontend/dist/provider-logos/above.svg +3 -0
  629. package/frontend/dist/provider-logos/agentrouter.svg +4 -0
  630. package/frontend/dist/provider-logos/agnes.svg +1 -0
  631. package/frontend/dist/provider-logos/ai-router.svg +5 -0
  632. package/frontend/dist/provider-logos/ai21.svg +3 -0
  633. package/frontend/dist/provider-logos/aiand.svg +4 -0
  634. package/frontend/dist/provider-logos/aihubmix.svg +3 -0
  635. package/frontend/dist/provider-logos/aimlapi.svg +3 -0
  636. package/frontend/dist/provider-logos/ainetcafe.svg +1 -0
  637. package/frontend/dist/provider-logos/aixy.svg +4 -0
  638. package/frontend/dist/provider-logos/aki-io.svg +8 -0
  639. package/frontend/dist/provider-logos/alibaba-cn.svg +3 -0
  640. package/frontend/dist/provider-logos/alibaba-coding-plan-cn.svg +3 -0
  641. package/frontend/dist/provider-logos/alibaba-coding-plan.svg +3 -0
  642. package/frontend/dist/provider-logos/alibaba-token-plan-cn.svg +1 -0
  643. package/frontend/dist/provider-logos/alibaba-token-plan.svg +1 -0
  644. package/frontend/dist/provider-logos/alibaba.svg +3 -0
  645. package/frontend/dist/provider-logos/amazon-bedrock.svg +3 -0
  646. package/frontend/dist/provider-logos/ambient.svg +3 -0
  647. package/frontend/dist/provider-logos/amd.svg +3 -0
  648. package/frontend/dist/provider-logos/anthropic.svg +3 -0
  649. package/frontend/dist/provider-logos/anyapi.svg +3 -0
  650. package/frontend/dist/provider-logos/arcee.svg +3 -0
  651. package/frontend/dist/provider-logos/atomic-chat.svg +1 -0
  652. package/frontend/dist/provider-logos/auriko.svg +6 -0
  653. package/frontend/dist/provider-logos/azure-cognitive-services.svg +3 -0
  654. package/frontend/dist/provider-logos/azure.svg +3 -0
  655. package/frontend/dist/provider-logos/bailing.svg +3 -0
  656. package/frontend/dist/provider-logos/baseten.svg +3 -0
  657. package/frontend/dist/provider-logos/bee.svg +1 -0
  658. package/frontend/dist/provider-logos/berget.svg +3 -0
  659. package/frontend/dist/provider-logos/blueclaw.svg +3 -0
  660. package/frontend/dist/provider-logos/bothub.svg +33 -0
  661. package/frontend/dist/provider-logos/boundless.svg +12 -0
  662. package/frontend/dist/provider-logos/cerebras.svg +4 -0
  663. package/frontend/dist/provider-logos/chutes.svg +24 -0
  664. package/frontend/dist/provider-logos/clarifai.svg +3 -0
  665. package/frontend/dist/provider-logos/claudinio.svg +19 -0
  666. package/frontend/dist/provider-logos/cline-pass.svg +24 -0
  667. package/frontend/dist/provider-logos/cloudferro-sherlock.svg +5 -0
  668. package/frontend/dist/provider-logos/cloudflare-ai-gateway.svg +4 -0
  669. package/frontend/dist/provider-logos/cloudflare-workers-ai.svg +4 -0
  670. package/frontend/dist/provider-logos/cohere.svg +5 -0
  671. package/frontend/dist/provider-logos/commandcode.svg +11 -0
  672. package/frontend/dist/provider-logos/coralbricks.svg +6 -0
  673. package/frontend/dist/provider-logos/cortecs.svg +24 -0
  674. package/frontend/dist/provider-logos/crossmodel.svg +5 -0
  675. package/frontend/dist/provider-logos/crusoe.svg +23 -0
  676. package/frontend/dist/provider-logos/daoxe.svg +3 -0
  677. package/frontend/dist/provider-logos/databricks.svg +3 -0
  678. package/frontend/dist/provider-logos/deepinfra.svg +4 -0
  679. package/frontend/dist/provider-logos/deepseek.svg +3 -0
  680. package/frontend/dist/provider-logos/digitalocean.svg +6 -0
  681. package/frontend/dist/provider-logos/dinference.svg +1 -0
  682. package/frontend/dist/provider-logos/drun.svg +8 -0
  683. package/frontend/dist/provider-logos/ebcloud.svg +8 -0
  684. package/frontend/dist/provider-logos/echo.svg +7 -0
  685. package/frontend/dist/provider-logos/edenai.svg +8 -0
  686. package/frontend/dist/provider-logos/empiriolabs.svg +1 -0
  687. package/frontend/dist/provider-logos/engy.svg +1 -0
  688. package/frontend/dist/provider-logos/evroc.svg +3 -0
  689. package/frontend/dist/provider-logos/fastrouter.svg +3 -0
  690. package/frontend/dist/provider-logos/fireworks-ai.svg +3 -0
  691. package/frontend/dist/provider-logos/freemodel.svg +3 -0
  692. package/frontend/dist/provider-logos/friendli.svg +3 -0
  693. package/frontend/dist/provider-logos/frogbot.svg +36 -0
  694. package/frontend/dist/provider-logos/github-copilot.svg +3 -0
  695. package/frontend/dist/provider-logos/gitlab.svg +3 -0
  696. package/frontend/dist/provider-logos/gmicloud.svg +24 -0
  697. package/frontend/dist/provider-logos/google-vertex-anthropic.svg +10 -0
  698. package/frontend/dist/provider-logos/google-vertex.svg +10 -0
  699. package/frontend/dist/provider-logos/google.svg +3 -0
  700. package/frontend/dist/provider-logos/greenpt.svg +6 -0
  701. package/frontend/dist/provider-logos/groq.svg +3 -0
  702. package/frontend/dist/provider-logos/helicone.svg +6 -0
  703. package/frontend/dist/provider-logos/hetzner.svg +3 -0
  704. package/frontend/dist/provider-logos/hopper.svg +4 -0
  705. package/frontend/dist/provider-logos/hpc-ai.svg +446 -0
  706. package/frontend/dist/provider-logos/huggingface.svg +3 -0
  707. package/frontend/dist/provider-logos/hyper.svg +20 -0
  708. package/frontend/dist/provider-logos/impossibl.svg +3 -0
  709. package/frontend/dist/provider-logos/inception.svg +14 -0
  710. package/frontend/dist/provider-logos/inceptron.svg +14 -0
  711. package/frontend/dist/provider-logos/inco.svg +3 -0
  712. package/frontend/dist/provider-logos/infer.svg +4 -0
  713. package/frontend/dist/provider-logos/inference.svg +3 -0
  714. package/frontend/dist/provider-logos/inferx.svg +5 -0
  715. package/frontend/dist/provider-logos/infomaniak.svg +3 -0
  716. package/frontend/dist/provider-logos/io-net.svg +5 -0
  717. package/frontend/dist/provider-logos/iteracompute.svg +7 -0
  718. package/frontend/dist/provider-logos/jalapeno.svg +8 -0
  719. package/frontend/dist/provider-logos/jiekou.svg +4 -0
  720. package/frontend/dist/provider-logos/kenari.svg +4 -0
  721. package/frontend/dist/provider-logos/kilo.svg +4 -0
  722. package/frontend/dist/provider-logos/kimi-code-plan-cn.svg +3 -0
  723. package/frontend/dist/provider-logos/kimi-code-plan-global.svg +3 -0
  724. package/frontend/dist/provider-logos/klokintegration.svg +11 -0
  725. package/frontend/dist/provider-logos/kosmik.svg +28 -0
  726. package/frontend/dist/provider-logos/kuae-cloud-coding-plan.svg +3 -0
  727. package/frontend/dist/provider-logos/lilac.svg +6 -0
  728. package/frontend/dist/provider-logos/liquid.svg +1 -0
  729. package/frontend/dist/provider-logos/llmgateway-providers.svg +6 -0
  730. package/frontend/dist/provider-logos/llmgateway.svg +6 -0
  731. package/frontend/dist/provider-logos/llmtech.svg +6 -0
  732. package/frontend/dist/provider-logos/llmtr.svg +12 -0
  733. package/frontend/dist/provider-logos/lmstudio.svg +3 -0
  734. package/frontend/dist/provider-logos/longcat.svg +6 -0
  735. package/frontend/dist/provider-logos/lowrouter.svg +8 -0
  736. package/frontend/dist/provider-logos/lucidquery.svg +3 -0
  737. package/frontend/dist/provider-logos/lynkr.svg +1 -0
  738. package/frontend/dist/provider-logos/meganova.svg +3 -0
  739. package/frontend/dist/provider-logos/melious.svg +3 -0
  740. package/frontend/dist/provider-logos/merge-gateway.svg +4 -0
  741. package/frontend/dist/provider-logos/meta.svg +3 -0
  742. package/frontend/dist/provider-logos/minimax-cn-coding-plan.svg +3 -0
  743. package/frontend/dist/provider-logos/minimax-cn.svg +3 -0
  744. package/frontend/dist/provider-logos/minimax-coding-plan.svg +3 -0
  745. package/frontend/dist/provider-logos/minimax.svg +3 -0
  746. package/frontend/dist/provider-logos/mistral.svg +3 -0
  747. package/frontend/dist/provider-logos/mixlayer.svg +9 -0
  748. package/frontend/dist/provider-logos/moark.svg +3 -0
  749. package/frontend/dist/provider-logos/modal.svg +3 -0
  750. package/frontend/dist/provider-logos/model-oracle-ai.svg +11 -0
  751. package/frontend/dist/provider-logos/modelis.svg +1 -0
  752. package/frontend/dist/provider-logos/modelscope.svg +5 -0
  753. package/frontend/dist/provider-logos/modular.svg +3 -0
  754. package/frontend/dist/provider-logos/moonshotai-cn.svg +3 -0
  755. package/frontend/dist/provider-logos/moonshotai.svg +3 -0
  756. package/frontend/dist/provider-logos/morph.svg +24 -0
  757. package/frontend/dist/provider-logos/munito-eu.svg +1 -0
  758. package/frontend/dist/provider-logos/munito.svg +1 -0
  759. package/frontend/dist/provider-logos/nan.svg +1 -0
  760. package/frontend/dist/provider-logos/nano-gpt.svg +3 -0
  761. package/frontend/dist/provider-logos/nearai.svg +1 -0
  762. package/frontend/dist/provider-logos/nebius.svg +4 -0
  763. package/frontend/dist/provider-logos/neon.svg +3 -0
  764. package/frontend/dist/provider-logos/neosmith.svg +6 -0
  765. package/frontend/dist/provider-logos/neuralwatt.svg +27 -0
  766. package/frontend/dist/provider-logos/nova.svg +3 -0
  767. package/frontend/dist/provider-logos/novita-ai.svg +10 -0
  768. package/frontend/dist/provider-logos/nvidia.svg +3 -0
  769. package/frontend/dist/provider-logos/oci.svg +3 -0
  770. package/frontend/dist/provider-logos/ofox.svg +5 -0
  771. package/frontend/dist/provider-logos/ollama-cloud.svg +7 -0
  772. package/frontend/dist/provider-logos/openai.svg +3 -0
  773. package/frontend/dist/provider-logos/opencode-go.svg +4 -0
  774. package/frontend/dist/provider-logos/opencode.svg +4 -0
  775. package/frontend/dist/provider-logos/openreason.svg +8 -0
  776. package/frontend/dist/provider-logos/openrouter.svg +5 -0
  777. package/frontend/dist/provider-logos/opper.svg +3 -0
  778. package/frontend/dist/provider-logos/orcarouter.svg +2 -0
  779. package/frontend/dist/provider-logos/ovhcloud.svg +3 -0
  780. package/frontend/dist/provider-logos/pareto.svg +5 -0
  781. package/frontend/dist/provider-logos/pendra.svg +10 -0
  782. package/frontend/dist/provider-logos/perplexity-agent.svg +3 -0
  783. package/frontend/dist/provider-logos/perplexity.svg +3 -0
  784. package/frontend/dist/provider-logos/pioneer.svg +3 -0
  785. package/frontend/dist/provider-logos/poe.svg +7 -0
  786. package/frontend/dist/provider-logos/poolside.svg +3 -0
  787. package/frontend/dist/provider-logos/prime.svg +7 -0
  788. package/frontend/dist/provider-logos/privatemode-ai.svg +5 -0
  789. package/frontend/dist/provider-logos/qihang-ai.svg +9 -0
  790. package/frontend/dist/provider-logos/qiniu-ai.svg +7 -0
  791. package/frontend/dist/provider-logos/qvac.svg +6 -0
  792. package/frontend/dist/provider-logos/reflection.svg +3 -0
  793. package/frontend/dist/provider-logos/regolo-ai.svg +46 -0
  794. package/frontend/dist/provider-logos/requesty.svg +24 -0
  795. package/frontend/dist/provider-logos/routing-run.svg +4 -0
  796. package/frontend/dist/provider-logos/runinfra.svg +10 -0
  797. package/frontend/dist/provider-logos/sakana.svg +24 -0
  798. package/frontend/dist/provider-logos/salad-cloud.svg +15 -0
  799. package/frontend/dist/provider-logos/sambanova.svg +26 -0
  800. package/frontend/dist/provider-logos/sap-ai-core.svg +24 -0
  801. package/frontend/dist/provider-logos/sarvam.svg +24 -0
  802. package/frontend/dist/provider-logos/scaleway.svg +5 -0
  803. package/frontend/dist/provider-logos/scnet-token-plan.svg +8 -0
  804. package/frontend/dist/provider-logos/scx-ai.svg +1 -0
  805. package/frontend/dist/provider-logos/sensenova.svg +18 -0
  806. package/frontend/dist/provider-logos/siliconflow-cn.svg +3 -0
  807. package/frontend/dist/provider-logos/siliconflow.svg +3 -0
  808. package/frontend/dist/provider-logos/snowflake-cortex.svg +3 -0
  809. package/frontend/dist/provider-logos/stackit.svg +4 -0
  810. package/frontend/dist/provider-logos/standardcompute.svg +5 -0
  811. package/frontend/dist/provider-logos/stepfun-ai-step-plan.svg +16 -0
  812. package/frontend/dist/provider-logos/stepfun-ai.svg +16 -0
  813. package/frontend/dist/provider-logos/stepfun-step-plan.svg +16 -0
  814. package/frontend/dist/provider-logos/stepfun.svg +16 -0
  815. package/frontend/dist/provider-logos/subconscious.svg +3 -0
  816. package/frontend/dist/provider-logos/submodel.svg +3 -0
  817. package/frontend/dist/provider-logos/synthetic.svg +24 -0
  818. package/frontend/dist/provider-logos/tempr.svg +4 -0
  819. package/frontend/dist/provider-logos/tencent-coding-plan.svg +5 -0
  820. package/frontend/dist/provider-logos/tencent-token-plan.svg +3 -0
  821. package/frontend/dist/provider-logos/tencent-tokenhub.svg +3 -0
  822. package/frontend/dist/provider-logos/tensorx.svg +6 -0
  823. package/frontend/dist/provider-logos/the-grid-ai.svg +14 -0
  824. package/frontend/dist/provider-logos/thinkingmachines.svg +3 -0
  825. package/frontend/dist/provider-logos/tinfoil.svg +3 -0
  826. package/frontend/dist/provider-logos/togetherai.svg +4 -0
  827. package/frontend/dist/provider-logos/tokengo.svg +3 -0
  828. package/frontend/dist/provider-logos/tokenrouter.svg +4 -0
  829. package/frontend/dist/provider-logos/trustedrouter.svg +4 -0
  830. package/frontend/dist/provider-logos/umans-ai-coding-plan.svg +29 -0
  831. package/frontend/dist/provider-logos/umans-ai.svg +29 -0
  832. package/frontend/dist/provider-logos/unorouter.svg +7 -0
  833. package/frontend/dist/provider-logos/upstage.svg +24 -0
  834. package/frontend/dist/provider-logos/vancine.svg +6 -0
  835. package/frontend/dist/provider-logos/venice.svg +4 -0
  836. package/frontend/dist/provider-logos/vercel.svg +3 -0
  837. package/frontend/dist/provider-logos/vispark.svg +3 -0
  838. package/frontend/dist/provider-logos/vivgrid.svg +4 -0
  839. package/frontend/dist/provider-logos/volcengine-coding-plan.svg +1 -0
  840. package/frontend/dist/provider-logos/volcengine.svg +1 -0
  841. package/frontend/dist/provider-logos/vultr.svg +6 -0
  842. package/frontend/dist/provider-logos/wafer.ai.svg +3 -0
  843. package/frontend/dist/provider-logos/wallaby.svg +4 -0
  844. package/frontend/dist/provider-logos/wally.svg +1 -0
  845. package/frontend/dist/provider-logos/wandb.svg +6 -0
  846. package/frontend/dist/provider-logos/watsonx.svg +5 -0
  847. package/frontend/dist/provider-logos/xai.svg +3 -0
  848. package/frontend/dist/provider-logos/xiaomi-token-plan-ams.svg +3 -0
  849. package/frontend/dist/provider-logos/xiaomi-token-plan-cn.svg +3 -0
  850. package/frontend/dist/provider-logos/xiaomi-token-plan-sgp.svg +3 -0
  851. package/frontend/dist/provider-logos/xiaomi.svg +3 -0
  852. package/frontend/dist/provider-logos/xpersona.svg +8 -0
  853. package/frontend/dist/provider-logos/zai-coding-plan.svg +3 -0
  854. package/frontend/dist/provider-logos/zai.svg +3 -0
  855. package/frontend/dist/provider-logos/zeldoc.svg +3 -0
  856. package/frontend/dist/provider-logos/zenifra.svg +4 -0
  857. package/frontend/dist/provider-logos/zenmux.svg +4 -0
  858. package/frontend/dist/provider-logos/zhipuai-coding-plan.svg +3 -0
  859. package/frontend/dist/provider-logos/zhipuai.svg +3 -0
  860. package/package.json +13 -5
  861. package/backend/dist/cli/clients/opencode-proxy.d.ts +0 -16
  862. package/backend/dist/cli/clients/opencode-proxy.js +0 -372
  863. package/backend/dist/forward-proxy/bypass.d.ts +0 -20
  864. package/backend/dist/forward-proxy/bypass.js +0 -28
  865. package/backend/dist/harness/adapters/amp.d.ts +0 -2
  866. package/backend/dist/harness/adapters/amp.js +0 -7
  867. package/backend/dist/harness/adapters/claude.d.ts +0 -2
  868. package/backend/dist/harness/adapters/claude.js +0 -7
  869. package/backend/dist/harness/adapters/cline.d.ts +0 -2
  870. package/backend/dist/harness/adapters/cline.js +0 -6
  871. package/backend/dist/harness/adapters/codex.d.ts +0 -2
  872. package/backend/dist/harness/adapters/codex.js +0 -6
  873. package/backend/dist/harness/adapters/cursor.d.ts +0 -5
  874. package/backend/dist/harness/adapters/cursor.js +0 -10
  875. package/backend/dist/harness/adapters/declarative.d.ts +0 -62
  876. package/backend/dist/harness/adapters/declarative.js +0 -202
  877. package/backend/dist/harness/adapters/dsh.d.ts +0 -5
  878. package/backend/dist/harness/adapters/dsh.js +0 -6
  879. package/backend/dist/harness/adapters/gemini-cli.d.ts +0 -2
  880. package/backend/dist/harness/adapters/gemini-cli.js +0 -7
  881. package/backend/dist/harness/adapters/github-copilot.d.ts +0 -5
  882. package/backend/dist/harness/adapters/github-copilot.js +0 -10
  883. package/backend/dist/harness/adapters/opencode.d.ts +0 -2
  884. package/backend/dist/harness/adapters/opencode.js +0 -55
  885. package/backend/dist/harness/adapters/pi.d.ts +0 -1
  886. package/backend/dist/harness/adapters/pi.js +0 -22
  887. package/backend/dist/harness/adapters/types.d.ts +0 -174
  888. package/backend/dist/harness/adapters/types.js +0 -12
  889. package/backend/dist/harness/adapters/universal.d.ts +0 -6
  890. package/backend/dist/harness/adapters/universal.js +0 -10
  891. package/backend/dist/harness/adapters/windsurf.d.ts +0 -2
  892. package/backend/dist/harness/adapters/windsurf.js +0 -10
  893. package/backend/dist/harness/adapters/zed.d.ts +0 -2
  894. package/backend/dist/harness/adapters/zed.js +0 -6
  895. package/backend/dist/harness/awesome-opencode.d.ts +0 -40
  896. package/backend/dist/harness/awesome-opencode.js +0 -75
  897. package/backend/dist/harness/browse.d.ts +0 -202
  898. package/backend/dist/harness/browse.js +0 -1214
  899. package/backend/dist/harness/inventory.d.ts +0 -10
  900. package/backend/dist/harness/opencode-cafe.d.ts +0 -40
  901. package/backend/dist/harness/opencode-cafe.js +0 -85
  902. package/backend/dist/harness/opencode-ecosystem.d.ts +0 -34
  903. package/backend/dist/harness/opencode-ecosystem.js +0 -246
  904. package/backend/dist/harness/pi-dev.d.ts +0 -81
  905. package/backend/dist/harness/pi-dev.js +0 -187
  906. package/backend/dist/harness/registry.js +0 -26
  907. package/backend/dist/harness/scopes.d.ts +0 -21
  908. package/backend/dist/harness/scopes.js +0 -22
  909. package/backend/dist/harness/skills-sh.d.ts +0 -109
  910. package/backend/dist/harness/skills-sh.js +0 -178
  911. package/backend/dist/harness/smithery.d.ts +0 -64
  912. package/backend/dist/harness/smithery.js +0 -146
  913. package/backend/dist/harness/sources/awesome-opencode.d.ts +0 -11
  914. package/backend/dist/harness/sources/awesome-opencode.js +0 -39
  915. package/backend/dist/harness/sources/mcp-official.d.ts +0 -2
  916. package/backend/dist/harness/sources/mcp-official.js +0 -110
  917. package/backend/dist/harness/sources/npm.d.ts +0 -2
  918. package/backend/dist/harness/sources/opencode-cafe.d.ts +0 -11
  919. package/backend/dist/harness/sources/opencode-cafe.js +0 -41
  920. package/backend/dist/harness/sources/smithery.d.ts +0 -2
  921. package/backend/dist/harness/sources/smithery.js +0 -81
  922. package/backend/dist/harness/writers/extension.d.ts +0 -116
  923. package/backend/dist/harness/writers/extension.js +0 -219
  924. package/backend/dist/harness/writers/mcp.d.ts +0 -72
  925. package/backend/dist/harness/writers/mcp.js +0 -195
  926. package/backend/dist/observability/trace-id.d.ts +0 -40
  927. package/backend/dist/observability/trace-id.js +0 -134
  928. package/frontend/dist/assets/index-1o7qI-KJ.css +0 -1
  929. package/frontend/dist/assets/index-DvXKvNxl.js +0 -962
  930. package/frontend/dist/assets/inter-cyrillic-800-normal-C7MGvYyJ.woff2 +0 -0
  931. package/frontend/dist/assets/inter-cyrillic-800-normal-CCHyn08d.woff +0 -0
  932. package/frontend/dist/assets/inter-cyrillic-ext-800-normal-BZOjs1Xv.woff2 +0 -0
  933. package/frontend/dist/assets/inter-cyrillic-ext-800-normal-Ca-gJeZY.woff +0 -0
  934. package/frontend/dist/assets/inter-greek-800-normal-BU00tryP.woff +0 -0
  935. package/frontend/dist/assets/inter-greek-800-normal-CLIouy3y.woff2 +0 -0
  936. package/frontend/dist/assets/inter-greek-ext-800-normal-B--PVpEC.woff2 +0 -0
  937. package/frontend/dist/assets/inter-greek-ext-800-normal-DUe57HfS.woff +0 -0
  938. package/frontend/dist/assets/inter-latin-800-normal-BYj_oED-.woff2 +0 -0
  939. package/frontend/dist/assets/inter-latin-800-normal-D1mf63XC.woff +0 -0
  940. package/frontend/dist/assets/inter-latin-ext-800-normal-BOMpwxm3.woff +0 -0
  941. package/frontend/dist/assets/inter-latin-ext-800-normal-DZJjya6U.woff2 +0 -0
  942. package/frontend/dist/assets/inter-vietnamese-800-normal-Cm7tD1pz.woff2 +0 -0
  943. package/frontend/dist/assets/inter-vietnamese-800-normal-DDlpr_Ee.woff +0 -0
  944. /package/backend/dist/harness/{adapters → host/adapters}/skills-paths.d.ts +0 -0
  945. /package/backend/dist/harness/{adapters → host/adapters}/skills-paths.js +0 -0
  946. /package/backend/dist/harness/{skill-md.d.ts → skill/skill-md.d.ts} +0 -0
  947. /package/backend/dist/harness/{skill-md.js → skill/skill-md.js} +0 -0
@@ -1,14 +1,19 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { isMap, parse, parseDocument, stringify } from 'yaml';
3
+ import { parse, stringify } from 'yaml';
4
+ import { INTERCEPT_POSTURES, lintRules, normalizeRuleTable } from '../forward-proxy/rules.js';
4
5
  import { DEFAULT_RETRIABLE_CAUSES } from '../resilience/types.js';
6
+ import { DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_MAX_RATE_LIMIT_WAIT_MS } from '../resilience/circuit-breaker.js';
5
7
  import { EFFORT_LADDER } from '../types/router.js';
6
8
  import { resolveDirectivePrefix } from '../pipeline/directives.js';
7
- import { DEFAULT_CREDENTIAL_AFFINITY_CACHE_TTL_MS } from '../pipeline/credential-selection.js';
9
+ import { missingNodeCredential, sanitizeTypedNode } from '../proxy/manual-node-spec.js';
8
10
  import { ensureEnvScaffold, getEnvPaths, resolveEnvName } from './env.js';
9
- import { DEFAULT_FORWARD_PROXY_PORT, DEFAULT_HEADROOM_TIMEOUT_MS, DEFAULT_DIRECTIVE_PREFIX, DEFAULT_HEADROOM_URL, DEFAULT_LAYER2_EFFORT_FLOOR, DEFAULT_LAYER2_TIMEOUT_MS, DEFAULT_MAX_BODY_BYTES, DEFAULT_ROUTE_ENTRIES_MAX, } from './defaults.js';
11
+ import { DEFAULT_FORWARD_PROXY_PORT, DEFAULT_FORWARD_PROXY_HOST, DEFAULT_FORWARD_PROXY_MAX_CONNECTIONS, DEFAULT_FORWARD_PROXY_RULES, DEFAULT_FORWARD_PROXY_INTERCEPT, FORWARD_PROXY_MAX_CONNECTIONS_MIN, FORWARD_PROXY_MAX_CONNECTIONS_MAX, DEFAULT_PROXY_ACCESS_LOG_PERSIST_DAYS, PROXY_ACCESS_LOG_PERSIST_DAYS_MIN, PROXY_ACCESS_LOG_PERSIST_DAYS_MAX, DEFAULT_HEADROOM_TIMEOUT_MS, DEFAULT_DIRECTIVE_PREFIX, DEFAULT_HEADROOM_URL, DEFAULT_LAYER2_EFFORT_FLOOR, DEFAULT_LAYER2_TIMEOUT_MS, DEFAULT_MAX_BODY_BYTES, DEFAULT_ROUTE_ENTRIES_MAX, DEFAULT_GATEWAY_PORT, DEFAULT_MIHOMO_CONTROLLER_PORT, DEFAULT_MIHOMO_GROUP, DEFAULT_MIHOMO_MIXED_PORT, DEFAULT_MIHOMO_SUB_INTERVAL_SEC, MIHOMO_SUB_INTERVAL_MAX_SEC, MIHOMO_SUB_INTERVAL_MIN_SEC, MIHOMO_GROUP_INTERVAL_MAX_SEC, MIHOMO_GROUP_INTERVAL_MIN_SEC, DEFAULT_MIHOMO_GROUP_TOLERANCE_MS, MIHOMO_GROUP_TOLERANCE_MAX_MS, DEFAULT_MIHOMO_TEST_URL, } from './defaults.js';
10
12
  import { getRateLimiter } from '../ratelimit/rate-limiter.js';
11
13
  import { getQuotaProber } from '../quota/prober.js';
14
+ import { migrateConfig, toDiskConfig, toRuntimeConfig, SCHEMA_VERSION } from './schema.js';
15
+ import { getRuntimeConfigRef, registerRuntimeConfigRef } from './runtime.js';
16
+ export { getRuntimeConfigRef, registerRuntimeConfigRef };
12
17
  // Bootstrap levers (OCR_ENV / OCR_HOME) come from the REAL process environment
13
18
  // only — there is no .env loader. A file-based override would be a second,
14
19
  // cwd-dependent source of truth next to the envs/current pointer.
@@ -22,10 +27,27 @@ import { getQuotaProber } from '../quota/prober.js';
22
27
  */
23
28
  export const DEFAULT_INBOUND_GRACE_MS = 1000;
24
29
  export const MAX_INBOUND_GRACE_MS = 2000;
30
+ /**
31
+ * Cap on concurrent inbound grace-wait sleepers. Each sleeper parks a request
32
+ * (and its socket) for up to MAX_INBOUND_GRACE_MS; under a retry storm the
33
+ * denied-path sleepers would otherwise accumulate without bound. Beyond this
34
+ * many, the gate skips the grace wait and fast-fails 429 like any other
35
+ * denial — the window contract is unchanged, only the absorb-burst courtesy
36
+ * is shed under pressure.
37
+ */
38
+ export const MAX_GRACE_SLEEPERS = 64;
39
+ /**
40
+ * Period between the limiter's durable window checkpoints (rateLimit.persist).
41
+ * The checkpoint is also flushed on graceful shutdown, so this interval is
42
+ * only the crash-loss bound: a hard kill loses at most the last interval of
43
+ * window events (the same honest-loss-bound pattern as the session-manager
44
+ * debounce).
45
+ */
46
+ export const RATE_LIMIT_CHECKPOINT_INTERVAL_MS = 30_000;
25
47
  const DEFAULT_CONFIG = {
26
- port: parseInt(process.env.PORT || '3000', 10),
48
+ port: parseInt(process.env.PORT || String(DEFAULT_GATEWAY_PORT), 10),
27
49
  host: process.env.HOST || '127.0.0.1',
28
- adminApiKey: process.env.ROUTER_API_KEY || undefined,
50
+ adminKey: process.env.OCR_ADMIN_KEY || process.env.ROUTER_API_KEY || undefined,
29
51
  // First-boot tier defaults are EMPTY pools: defaultConfigYaml() writes the
30
52
  // four tier shells into every brand-new config.yaml and the loadConfig()
31
53
  // fallback below re-applies them when a file has no `tiers:` section at all.
@@ -67,14 +89,38 @@ const DEFAULT_CONFIG = {
67
89
  },
68
90
  proxy: {
69
91
  enabled: false, // opt-in: proxying only when explicitly enabled
92
+ mode: 'manual', // ADR-0022: manual keeps proxy.url; mihomo routes via the local core
70
93
  url: 'http://127.0.0.1:7890',
94
+ includes: [],
95
+ excludes: [],
96
+ mihomo: {
97
+ enabled: false,
98
+ binaryPath: '',
99
+ mixedPort: DEFAULT_MIHOMO_MIXED_PORT,
100
+ controllerPort: DEFAULT_MIHOMO_CONTROLLER_PORT,
101
+ controllerSecret: '',
102
+ subscriptions: [],
103
+ selectedGroup: DEFAULT_MIHOMO_GROUP,
104
+ selectedNodes: {},
105
+ },
71
106
  },
72
107
  forwardProxy: {
73
108
  enabled: false, // opt-in: full-capture MITM proxy must be enabled consciously
74
109
  port: DEFAULT_FORWARD_PROXY_PORT,
75
- host: '127.0.0.1',
76
- bypassHosts: [],
77
- viaOutboundProxy: false, // opt-in: transit egress via the outbound proxy policy
110
+ host: DEFAULT_FORWARD_PROXY_HOST,
111
+ maxConnections: DEFAULT_FORWARD_PROXY_MAX_CONNECTIONS,
112
+ requireCredential: false, // opt-in: loopback clients must also present an API key
113
+ // Rule table (ADR-0018 Revision 4): the fresh-install seed routes everything
114
+ // through the outbound proxy policy as a BLIND TUNNEL. Inert until BOTH this
115
+ // listener and `proxy.enabled` are on, so it costs a fresh install nothing.
116
+ rules: DEFAULT_FORWARD_PROXY_RULES,
117
+ // Interception posture: decrypt only what a capability declares (live
118
+ // client-gateway plugin claims + explicit `ingress: intercept` rows).
119
+ intercept: DEFAULT_FORWARD_PROXY_INTERCEPT,
120
+ accessLog: { enabled: true, persist: true, persistDays: DEFAULT_PROXY_ACCESS_LOG_PERSIST_DAYS },
121
+ // Upstream TLS trust for the origin legs (ADR-0019): system trust store
122
+ // unless the operator names a private CA or disables verification.
123
+ upstreamTls: { insecure: false },
78
124
  },
79
125
  compression: {
80
126
  rtk: { enabled: false },
@@ -92,6 +138,7 @@ const DEFAULT_CONFIG = {
92
138
  maxBodyBytes: DEFAULT_MAX_BODY_BYTES,
93
139
  maxSessionMB: 512,
94
140
  storeMedia: true,
141
+ redactSecrets: true, // forced on by CaptureRecorder; a false value is ignored (S-06)
95
142
  },
96
143
  tracePersist: {
97
144
  enabled: true, // default on: console history survives restarts (pure observability data)
@@ -99,25 +146,10 @@ const DEFAULT_CONFIG = {
99
146
  maxTotalMB: 100,
100
147
  },
101
148
  circuitBreaker: {
102
- enabled: true,
103
- failureThreshold: 3,
104
- slidingWindowSize: 20,
105
- failureRateThreshold: 0.5,
106
- initialCooldownMs: 30000,
107
- maxCooldownMs: 5 * 3600 * 1000, // 5 hours max cooldown
108
- cooldownMultiplier: 2.0,
109
- quotaCooldownMs: 12 * 3600 * 1000, // 12 hours for quota/balance exhaustion
110
- halfOpenMaxProbes: 1,
111
- activeProbing: {
112
- enabled: false,
113
- intervalMs: 60000,
114
- },
115
- credentialAffinity: {
116
- // a session keeps its credential while its pair breaker is up;
117
- // idle past this window it re-spreads like a new session (the upstream
118
- // prompt cache is gone by then anyway). 300000 = Anthropic cache TTL.
119
- cacheTtlMs: DEFAULT_CREDENTIAL_AFFINITY_CACHE_TTL_MS,
120
- },
149
+ // Global knobs mirror the runtime default exactly once (single source:
150
+ // resilience/circuit-breaker.ts); shadow/persistence/rules below are
151
+ // config-only surfaces with no runtime twin.
152
+ ...DEFAULT_CIRCUIT_BREAKER_CONFIG,
121
153
  // Shadow mode (spec docs/design/circuit-breaker-rules-config.md): rules
122
154
  // evaluate and record fully but the gate never denies; manual trips,
123
155
  // DISABLED and SUSPECT stay enforced.
@@ -157,7 +189,7 @@ const DEFAULT_CONFIG = {
157
189
  backoffMs: 200,
158
190
  jitterMs: 100,
159
191
  retryOnCauses: [...DEFAULT_RETRIABLE_CAUSES],
160
- maxRateLimitWaitMs: 2000,
192
+ maxRateLimitWaitMs: DEFAULT_MAX_RATE_LIMIT_WAIT_MS,
161
193
  },
162
194
  failover: {
163
195
  enabled: true,
@@ -169,7 +201,10 @@ const DEFAULT_CONFIG = {
169
201
  inboundGraceMs: DEFAULT_INBOUND_GRACE_MS,
170
202
  persist: { enabled: true },
171
203
  },
172
- streaming: { enabled: true },
204
+ // Two axes (ADR-0008 §1): `allow` streams only when the caller asks;
205
+ // `stream` keeps the provider leg on the upstream SSE reader even for JSON
206
+ // callers — TTFT/stall measurement on by default, client timing unchanged.
207
+ streaming: { client: { mode: 'allow' }, upstream: { mode: 'stream' } },
173
208
  apiKeys: [],
174
209
  models: [],
175
210
  };
@@ -283,9 +318,126 @@ function resolveRequestCapture(parsed) {
283
318
  // boolean needs the ?? chain (false must survive); deliberately NOT in the
284
319
  // pick union, which now types only the boolean/string keys.
285
320
  storeMedia: (raw.storeMedia ?? base.storeMedia),
321
+ redactSecrets: (raw.redactSecrets ?? base.redactSecrets),
286
322
  dir: pick('dir'),
287
323
  };
288
324
  }
325
+ /**
326
+ * Resolve the `streaming:` tree (ADR-0008 §1). Only the two registered axes
327
+ * are picked, so a retired key (`enabled` before schemaVersion 3 — rewritten
328
+ * by the v2→v3 migration) or junk never round-trips into a saved config. An
329
+ * unrecognized mode value falls back to the shipping default instead of
330
+ * silently disabling a capability.
331
+ */
332
+ function resolveStreamingConfig(raw) {
333
+ const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
334
+ const pickMode = (value, allowed, fallback) => typeof value === 'string' && allowed.includes(value) ? value : fallback;
335
+ const client = src.client && typeof src.client === 'object' ? src.client : {};
336
+ const upstream = src.upstream && typeof src.upstream === 'object' ? src.upstream : {};
337
+ return {
338
+ client: { mode: pickMode(client.mode, STREAMING_CLIENT_MODES, 'allow') },
339
+ upstream: { mode: pickMode(upstream.mode, STREAMING_UPSTREAM_MODES, 'stream') },
340
+ };
341
+ }
342
+ /** The two registered mode sets — one declaration, imported by the console contract. */
343
+ const STREAMING_CLIENT_MODES = ['allow', 'deny', 'always'];
344
+ const STREAMING_UPSTREAM_MODES = ['follow', 'stream', 'buffered'];
345
+ /**
346
+ * Resolve the whole `forwardProxy` section (ADR-0018).
347
+ */
348
+ function resolveForwardProxyConfig(raw) {
349
+ const rawFp = (raw ?? {});
350
+ const fp = { ...DEFAULT_CONFIG.forwardProxy, ...rawFp };
351
+ // The section carries exactly the keys `ForwardProxyConfig` declares. Any
352
+ // other key a hand-edited file still holds — a retired key (`bypassHosts`,
353
+ // `viaOutboundProxy`, `mitmHosts`, the interim `egress` / `egressRules` /
354
+ // `decryptRules` shapes, `authToken`) or a typo — is dropped here: never
355
+ // folded, never translated, never re-persisted on the next console save.
356
+ // `authToken` (the retired shared proxy secret — proxy auth is API-key only,
357
+ // ADR-0008) is the one that stings: an install that authenticated a loopback
358
+ // proxy with it lands on an UNauthenticated listener until a key exists and
359
+ // `forwardProxy.requireCredential` is on. Retired keys are never translated
360
+ // (ADR-0018 §6), so the ADR is where the operator learns this.
361
+ const declared = {
362
+ enabled: fp.enabled,
363
+ port: fp.port,
364
+ host: fp.host,
365
+ caDir: fp.caDir,
366
+ maxConnections: fp.maxConnections,
367
+ requireCredential: fp.requireCredential === true,
368
+ accessLog: fp.accessLog,
369
+ rules: fp.rules,
370
+ /** ADR-0018 Revision 4: only the two declared words survive; anything else
371
+ * (a typo, a retired spelling) falls back to the claims posture — the
372
+ * SAFE direction, never to machine-wide decryption. */
373
+ intercept: normalizeInterceptPosture(rawFp.intercept),
374
+ upstreamTls: fp.upstreamTls,
375
+ };
376
+ // An EXPLICIT `rules` array in the user's file wins (even empty — an empty
377
+ // table is a decision); otherwise the shipped default table applies.
378
+ const rules = Array.isArray(rawFp.rules) ? normalizeRuleTable({ rules: rawFp.rules }) : normalizeRuleTable(declared);
379
+ return {
380
+ ...declared,
381
+ rules,
382
+ maxConnections: normalizeMaxConnections(fp.maxConnections),
383
+ accessLog: normalizeAccessLogConfig(fp.accessLog),
384
+ upstreamTls: normalizeUpstreamTlsConfig(fp.upstreamTls),
385
+ };
386
+ }
387
+ /**
388
+ * Resolve `forwardProxy.intercept` (ADR-0018 Revision 4): exactly `'claims'`
389
+ * and `'all'` parse; every other value (a typo, a retired word, a non-string)
390
+ * is ignored and the safe posture applies. Junk must never buy machine-wide
391
+ * decryption.
392
+ */
393
+ function normalizeInterceptPosture(raw) {
394
+ return typeof raw === 'string' && INTERCEPT_POSTURES.includes(raw)
395
+ ? raw
396
+ : DEFAULT_FORWARD_PROXY_INTERCEPT;
397
+ }
398
+ /**
399
+ * Resolve `forwardProxy.upstreamTls` (ADR-0019) — same trust boundary as the
400
+ * rest of the section: junk falls back to the system trust store, never to a
401
+ * silently disabled verification. `insecure` is only ever true when the operator
402
+ * literally wrote `true`.
403
+ */
404
+ function normalizeUpstreamTlsConfig(raw) {
405
+ const r = (raw ?? {});
406
+ const caFile = typeof r.caFile === 'string' && r.caFile.trim() ? r.caFile.trim() : undefined;
407
+ return { ...(caFile ? { caFile } : {}), insecure: r.insecure === true };
408
+ }
409
+ /**
410
+ * Resolve `forwardProxy.maxConnections` — junk falls back to the default (no
411
+ * coercion), a real number is floored and clamped to the declared bounds so a
412
+ * typo cannot turn the cap into "unlimited" or "reject everything".
413
+ */
414
+ function normalizeMaxConnections(raw) {
415
+ if (typeof raw !== 'number' || !Number.isFinite(raw))
416
+ return DEFAULT_FORWARD_PROXY_MAX_CONNECTIONS;
417
+ return Math.min(FORWARD_PROXY_MAX_CONNECTIONS_MAX, Math.max(FORWARD_PROXY_MAX_CONNECTIONS_MIN, Math.floor(raw)));
418
+ }
419
+ /**
420
+ * Resolve `forwardProxy.accessLog` — same trust boundary as resolveRateLimit:
421
+ * junk values fall back to defaults, not coercion. bodyBytes: absent = the
422
+ * consumer applies DEFAULT_PROXY_ACCESS_LOG_BODY_BYTES (1 MiB, spill-to-file);
423
+ * 0 = headers only; a positive number = per-side inline cap.
424
+ * persistDays clamps to 1..365.
425
+ */
426
+ function normalizeAccessLogConfig(raw) {
427
+ const r = (raw ?? {});
428
+ const bodyBytes = typeof r.bodyBytes === 'number' && Number.isFinite(r.bodyBytes)
429
+ ? Math.max(0, Math.floor(r.bodyBytes))
430
+ : undefined;
431
+ const persistDaysRaw = typeof r.persistDays === 'number' && Number.isFinite(r.persistDays)
432
+ ? Math.floor(r.persistDays)
433
+ : DEFAULT_PROXY_ACCESS_LOG_PERSIST_DAYS;
434
+ return {
435
+ enabled: r.enabled !== false,
436
+ bodyBytes,
437
+ persist: r.persist !== false,
438
+ persistDays: Math.min(PROXY_ACCESS_LOG_PERSIST_DAYS_MAX, Math.max(PROXY_ACCESS_LOG_PERSIST_DAYS_MIN, persistDaysRaw)),
439
+ };
440
+ }
289
441
  /**
290
442
  * Resolve the `circuitBreaker:` tree from a raw parsed config. Top-level knobs
291
443
  * merge shallow (unchanged from the old spread); the NEW `rules` tree merges
@@ -310,7 +462,7 @@ function resolveCircuitBreaker(parsed) {
310
462
  // ── value cleaners (trust-boundary validation: junk → unset → fallback) ──
311
463
  const ms = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : undefined;
312
464
  const flag = (v, fallback) => (typeof v === 'boolean' ? v : fallback);
313
- const scope = (v) => v === 'pair' || v === 'credential' || v === 'model' ? v : 'auto';
465
+ const scope = (v) => v === 'pair' || v === 'credential' || v === 'model' || v === 'provider' ? v : 'auto';
314
466
  const canaryMode = (v) => v === 'initial' || v === 'close' ? v : 'backoff';
315
467
  // Merge one rule object over an explicit key list (unknown keys dropped —
316
468
  // round-trip hygiene): raw value wins per key, null/absent falls to base.
@@ -434,43 +586,460 @@ export function resolveRateLimit(parsed) {
434
586
  const persistRaw = (raw.persist ?? {});
435
587
  return { inboundGraceMs: graceMs, persist: { enabled: persistRaw.enabled !== false } };
436
588
  }
437
- /** One-shot guard for the retired `providers[]` deprecation warning (loadConfig runs per request on some paths). */
438
- let _retireWarned = false;
589
+ /** One-shot guard for the schema-version mismatch warning (loadConfig runs per request on some paths). */
590
+ let _schemaVersionWarned = false;
591
+ /** One-shot guard for the schemaVersion-position warning. */
592
+ let _schemaOrderWarned = false;
593
+ /** One-shot guard for the forward-proxy rule-table lint (ADR-0018). */
594
+ let _rulesLintWarned = false;
595
+ /**
596
+ * The port the config FILE names, captured on the read path. The `PORT` env
597
+ * lever overrides the LISTEN port but must never become a file value: a
598
+ * `PORT=4700 bun run dev` boot would otherwise persist 4700 onto an installed
599
+ * gateway's config.yaml (boot-time saves such as the catalog sync run
600
+ * unconditionally) and silently relocate that gateway on its next restart.
601
+ */
602
+ let _diskPort;
603
+ /**
604
+ * Boot-time egress lint (ADR-0018). The console renders the same codes per row
605
+ * with translations, but a hand-edited config.yaml never opens the console —
606
+ * one warn per process so a table that cannot do what it says is never silent.
607
+ *
608
+ * Gated on `forwardProxy.enabled`: with the listener off the table routes
609
+ * nothing, so warning about it would be noise on every fresh install.
610
+ */
611
+ function warnForwardProxyRulesOnce(raw, proxyEnabled) {
612
+ if (_rulesLintWarned)
613
+ return;
614
+ const fp = (raw ?? {});
615
+ if (fp.enabled !== true)
616
+ return;
617
+ _rulesLintWarned = true;
618
+ // Lint the RAW rows (position-preserving): `lintRules` runs the same parse as
619
+ // the resolver, so a warning's index addresses the row the operator typed.
620
+ for (const w of lintRules(fp.rules, proxyEnabled, normalizeInterceptPosture(fp.intercept))) {
621
+ const at = w.ruleIndex === undefined ? '' : ` rule #${w.ruleIndex + 1}`;
622
+ console.warn(`[Config] forwardProxy.rules${at}: ${w.code}${w.detail ? ` (${w.detail})` : ''}`);
623
+ }
624
+ }
625
+ const SUBSCRIPTION_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
626
+ const GROUP_NAME_RE = /^[A-Za-z0-9_-]{1,64}$/;
627
+ function clampPort(value, fallback) {
628
+ const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
629
+ if (!Number.isInteger(n) || n < 1 || n > 65535)
630
+ return fallback;
631
+ return n;
632
+ }
633
+ /** Numeric field clamped to a range, with the shipped default for junk. */
634
+ function clampRange(value, min, max, fallback) {
635
+ const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
636
+ if (!Number.isFinite(n))
637
+ return fallback;
638
+ return Math.min(max, Math.max(min, Math.round(n)));
639
+ }
640
+ /**
641
+ * `proxy.mihomo.groupInterval`: absent (or junk) stays undefined so
642
+ * `renderMihomoConfig` can apply the shipped default; an explicit number is
643
+ * clamped into the cadence bounds. Pinning a default here would freeze
644
+ * today's value into every saved file and silently override later changes.
645
+ */
646
+ function sanitizeGroupInterval(value) {
647
+ if (value === undefined || value === null)
648
+ return undefined;
649
+ const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
650
+ if (!Number.isFinite(n))
651
+ return undefined;
652
+ return Math.min(MIHOMO_GROUP_INTERVAL_MAX_SEC, Math.max(MIHOMO_GROUP_INTERVAL_MIN_SEC, Math.round(n)));
653
+ }
654
+ function stringList(value) {
655
+ if (!Array.isArray(value))
656
+ return [];
657
+ return value.filter((item) => typeof item === 'string').map((item) => item.trim()).filter(Boolean);
658
+ }
659
+ /** Upper bound: a rule table longer than this is a subscription dump, not an
660
+ * operator's decision, and it would slow every request at match time. */
661
+ const CUSTOM_RULES_MAX = 256;
662
+ const CUSTOM_RULE_PAYLOAD_MAX = 512;
663
+ /** Longest provenance label kept on a rule (a name, not a document). */
664
+ const CUSTOM_RULE_SOURCE_MAX = 40;
665
+ /** The one rule-type whitelist: the sanitizer validates against it, the
666
+ * subscription importer maps against it, and the console offers exactly it. */
667
+ export const MIHOMO_CUSTOM_RULE_TYPES = [
668
+ 'DOMAIN', 'DOMAIN-SUFFIX', 'DOMAIN-KEYWORD',
669
+ 'IP-CIDR', 'IP-CIDR6',
670
+ 'DST-PORT', 'SRC-PORT',
671
+ 'PROCESS-NAME', 'PROCESS-PATH',
672
+ ];
673
+ export const MIHOMO_CUSTOM_RULES_MAX = CUSTOM_RULES_MAX;
674
+ const CUSTOM_RULE_TYPES = new Set(MIHOMO_CUSTOM_RULE_TYPES);
675
+ const CUSTOM_RULE_TARGETS = new Set(['PROXY', 'DIRECT', 'REJECT']);
676
+ /**
677
+ * Whitelist custom rules on every read.
678
+ *
679
+ * Everything is validated against fixed sets because these strings are written
680
+ * VERBATIM into the generated YAML as `TYPE,payload,target`: a payload carrying
681
+ * a newline or a comma would splice extra fields (or whole rules) into the
682
+ * document. Unknown types are DROPPED rather than passed through — mihomo's
683
+ * behaviour with a rule it cannot evaluate is either a hard load failure or a
684
+ * silent fallthrough, and an operator cannot debug either from the console.
685
+ */
686
+ function sanitizeCustomRules(raw) {
687
+ if (!Array.isArray(raw))
688
+ return [];
689
+ const out = [];
690
+ for (const item of raw) {
691
+ if (out.length >= CUSTOM_RULES_MAX)
692
+ break;
693
+ if (!item || typeof item !== 'object')
694
+ continue;
695
+ const rec = item;
696
+ const type = typeof rec.type === 'string' ? rec.type.trim().toUpperCase() : '';
697
+ const payload = typeof rec.payload === 'string' ? rec.payload.trim() : '';
698
+ const targetRaw = typeof rec.target === 'string' ? rec.target.trim().toUpperCase() : '';
699
+ if (!CUSTOM_RULE_TYPES.has(type))
700
+ continue;
701
+ if (!payload || payload.length > CUSTOM_RULE_PAYLOAD_MAX)
702
+ continue;
703
+ // One line, no separators: the payload becomes a single YAML list entry.
704
+ if (payload.includes(',') || payload.includes('\n') || payload.includes('\r'))
705
+ continue;
706
+ // Provenance is metadata, not routing: keep it short and printable, but a
707
+ // junk label must not cost the rule.
708
+ // eslint-disable-next-line no-control-regex
709
+ const sourceRaw = typeof rec.source === 'string' ? rec.source.replace(/[\u0000-\u001f\u007f]/g, ' ').trim() : '';
710
+ out.push({
711
+ type: type,
712
+ payload,
713
+ target: (CUSTOM_RULE_TARGETS.has(targetRaw) ? targetRaw : 'PROXY'),
714
+ ...(sourceRaw ? { source: sourceRaw.slice(0, CUSTOM_RULE_SOURCE_MAX) } : null),
715
+ });
716
+ }
717
+ return out;
718
+ }
719
+ function sanitizeSubscriptions(raw) {
720
+ if (!Array.isArray(raw))
721
+ return [];
722
+ const out = [];
723
+ const seen = new Set();
724
+ for (const item of raw) {
725
+ if (!item || typeof item !== 'object')
726
+ continue;
727
+ const rec = item;
728
+ const id = typeof rec.id === 'string' ? rec.id.trim() : '';
729
+ const name = typeof rec.name === 'string' ? rec.name.trim() : '';
730
+ const url = typeof rec.url === 'string' ? rec.url.trim() : '';
731
+ if (!SUBSCRIPTION_ID_RE.test(id) || !name || seen.has(id))
732
+ continue;
733
+ try {
734
+ const parsed = new URL(url);
735
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
736
+ continue;
737
+ }
738
+ catch {
739
+ continue;
740
+ }
741
+ seen.add(id);
742
+ let interval = DEFAULT_MIHOMO_SUB_INTERVAL_SEC;
743
+ if (typeof rec.interval === 'number' && Number.isFinite(rec.interval)) {
744
+ interval = Math.min(MIHOMO_SUB_INTERVAL_MAX_SEC, Math.max(MIHOMO_SUB_INTERVAL_MIN_SEC, Math.round(rec.interval)));
745
+ }
746
+ out.push({
747
+ id,
748
+ name: name.slice(0, 80),
749
+ url,
750
+ interval,
751
+ enabled: rec.enabled !== false,
752
+ });
753
+ }
754
+ return out;
755
+ }
756
+ const MANUAL_NODE_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
757
+ /** Longest raw proxy mapping kept per node (a mapping, not a document). */
758
+ const MANUAL_NODE_YAML_MAX = 16 * 1024;
759
+ /** Names mihomo already owns; a manual proxy may not shadow one. */
760
+ const MANUAL_NODE_RESERVED_NAMES = {
761
+ DIRECT: true, REJECT: true, PASS: true, GLOBAL: true, COMPATIBLE: true,
762
+ };
763
+ function cleanNodeText(raw, max) {
764
+ if (typeof raw !== 'string')
765
+ return '';
766
+ const value = raw.trim();
767
+ if (!value || value.length > max)
768
+ return '';
769
+ // One line, printable: these strings land in the generated YAML and in
770
+ // mihomo's own parser; a control character can only break it.
771
+ // eslint-disable-next-line no-control-regex
772
+ if (/[\u0000-\u001f\u007f]/.test(value))
773
+ return '';
774
+ return value;
775
+ }
776
+ function cleanNodeHost(raw, max) {
777
+ const value = cleanNodeText(raw, max);
778
+ return value && !/\s/.test(value) ? value : '';
779
+ }
780
+ /**
781
+ * Whitelist hand-authored nodes on every read (ADR-0022).
782
+ *
783
+ * Only the fields belonging to the declared protocol survive: switching a
784
+ * node's type must not leave a stale uuid or password in the generated YAML.
785
+ * A row missing its identity or credentials is DROPPED — the core would fail
786
+ * to load the whole config for one bad proxy, and a silent fall-through is
787
+ * worse than an empty list the console can show.
788
+ */
789
+ function sanitizeManualNodes(raw, group) {
790
+ // A proxy named like the generated group (or a built-in) makes mihomo reject
791
+ // the whole config; the route checks this too, but a hand-edited file must
792
+ // not get past the loader.
793
+ const reserved = (name) => name.toUpperCase() in MANUAL_NODE_RESERVED_NAMES || name.toUpperCase() === group.toUpperCase();
794
+ if (!Array.isArray(raw))
795
+ return [];
796
+ const out = [];
797
+ const seenIds = new Set();
798
+ const seenNames = new Set();
799
+ for (const item of raw) {
800
+ if (!item || typeof item !== 'object')
801
+ continue;
802
+ const rec = item;
803
+ const id = typeof rec.id === 'string' ? rec.id.trim() : '';
804
+ if (!MANUAL_NODE_ID_RE.test(id) || seenIds.has(id))
805
+ continue;
806
+ const rawYaml = typeof rec.yaml === 'string' ? rec.yaml.trim() : '';
807
+ if (rawYaml) {
808
+ // Raw pasted mapping: the operator owns every key, so only the identity
809
+ // fields are validated. `stringify` is the canonical form (anchors and
810
+ // aliases resolved), which is also what the console edits.
811
+ if (rawYaml.length > MANUAL_NODE_YAML_MAX)
812
+ continue;
813
+ let mapping;
814
+ try {
815
+ mapping = parse(rawYaml);
816
+ }
817
+ catch {
818
+ continue;
819
+ }
820
+ if (!mapping || typeof mapping !== 'object' || Array.isArray(mapping))
821
+ continue;
822
+ const proxy = mapping;
823
+ const name = cleanNodeText(proxy.name, 64);
824
+ const type = typeof proxy.type === 'string' ? proxy.type.trim().toLowerCase().slice(0, 32) : '';
825
+ const server = cleanNodeHost(proxy.server, 253);
826
+ const rawPort = typeof proxy.port === 'string' ? Number(proxy.port) : proxy.port;
827
+ const port = typeof rawPort === 'number' && Number.isInteger(rawPort) && rawPort >= 1 && rawPort <= 65535
828
+ ? rawPort
829
+ : 0;
830
+ if (!name || !server || !port || !type)
831
+ continue;
832
+ // A whitelisted protocol still needs its credentials: the core loads the
833
+ // generated document as a whole, so one incomplete proxy drops every node.
834
+ if (missingNodeCredential(proxy))
835
+ continue;
836
+ if (reserved(name) || seenNames.has(name.toLowerCase()))
837
+ continue;
838
+ seenIds.add(id);
839
+ seenNames.add(name.toLowerCase());
840
+ out.push({ id, name, type, server, port, yaml: stringify({ ...proxy, name, type, server, port }) });
841
+ continue;
842
+ }
843
+ const typed = sanitizeTypedNode(rec, id);
844
+ if (!typed.node)
845
+ continue;
846
+ const node = typed.node;
847
+ if (reserved(node.name) || seenNames.has(node.name.toLowerCase()))
848
+ continue;
849
+ seenIds.add(id);
850
+ seenNames.add(node.name.toLowerCase());
851
+ out.push(node);
852
+ }
853
+ return out;
854
+ }
855
+ function sanitizeSelectedNodes(raw) {
856
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
857
+ return {};
858
+ const out = {};
859
+ for (const [key, value] of Object.entries(raw)) {
860
+ if (typeof value !== 'string')
861
+ continue;
862
+ const name = key.trim();
863
+ const node = value.trim();
864
+ if (!name || !node || name.length > 128 || node.length > 256)
865
+ continue;
866
+ out[name] = node;
867
+ }
868
+ return out;
869
+ }
870
+ /**
871
+ * Normalize `proxy` on every read. Missing mihomo fields take the shipped
872
+ * defaults; junk subscriptions are dropped; `mode` stays `manual` unless the
873
+ * file explicitly asks for mihomo (or sets `mihomo.enabled` with no mode).
874
+ * Pure value cleaning — not a schema migration (ADR-0016 / ADR-0022).
875
+ */
876
+ /**
877
+ * Health-check / delay-test URL: http(s), hostful, no embedded credentials.
878
+ * Junk falls back to the factory default rather than reaching the generated
879
+ * config (the core would reject the whole document for one bad URL).
880
+ */
881
+ function sanitizeTestUrl(raw) {
882
+ if (typeof raw !== 'string')
883
+ return DEFAULT_MIHOMO_TEST_URL;
884
+ const value = raw.trim();
885
+ if (!value || value.length > 2048)
886
+ return DEFAULT_MIHOMO_TEST_URL;
887
+ try {
888
+ const parsed = new URL(value);
889
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
890
+ return DEFAULT_MIHOMO_TEST_URL;
891
+ if (!parsed.hostname || parsed.username || parsed.password)
892
+ return DEFAULT_MIHOMO_TEST_URL;
893
+ return value;
894
+ }
895
+ catch {
896
+ return DEFAULT_MIHOMO_TEST_URL;
897
+ }
898
+ }
899
+ export function sanitizeProxyConfig(raw) {
900
+ const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
901
+ const mihomoRaw = src.mihomo && typeof src.mihomo === 'object' && !Array.isArray(src.mihomo) ? src.mihomo : {};
902
+ const mode = src.mode === 'mihomo' || (src.mode !== 'manual' && mihomoRaw.enabled === true) ? 'mihomo' : 'manual';
903
+ const group = typeof mihomoRaw.selectedGroup === 'string' && GROUP_NAME_RE.test(mihomoRaw.selectedGroup.trim())
904
+ ? mihomoRaw.selectedGroup.trim()
905
+ : DEFAULT_MIHOMO_GROUP;
906
+ const secret = typeof mihomoRaw.controllerSecret === 'string' ? mihomoRaw.controllerSecret.trim().slice(0, 256) : '';
907
+ const binaryPath = typeof mihomoRaw.binaryPath === 'string' ? mihomoRaw.binaryPath.trim().slice(0, 1024) : '';
908
+ // mihomo's outbound mode. Whitelisted like every other field: anything else
909
+ // falls back to 'rule' instead of reaching the generated config.
910
+ const routingMode = mihomoRaw.routingMode === 'global' || mihomoRaw.routingMode === 'direct'
911
+ ? mihomoRaw.routingMode
912
+ : 'rule';
913
+ // Group picker mode. Same whitelist discipline as `routingMode`: junk falls
914
+ // back to the manual selector instead of reaching the generated config.
915
+ const groupType = mihomoRaw.groupType === 'url-test' || mihomoRaw.groupType === 'fallback'
916
+ ? mihomoRaw.groupType
917
+ : 'select';
918
+ // Absent stays absent so the renderer applies the shipped default; a junk
919
+ // value is dropped rather than pinned to a number the operator never chose
920
+ // (both used to be materialized as 300, which also froze mihomo's default
921
+ // into every saved file).
922
+ const groupInterval = sanitizeGroupInterval(mihomoRaw.groupInterval);
923
+ const groupTolerance = clampRange(mihomoRaw.groupTolerance, 0, MIHOMO_GROUP_TOLERANCE_MAX_MS, DEFAULT_MIHOMO_GROUP_TOLERANCE_MS);
924
+ // A remembered pick belongs to the MANUAL selector only. `url-test` /
925
+ // `fallback` hand the choice to the core, and restoring the pick would pin
926
+ // the group (mihomo's `Set` outranks its own delay ordering while the pinned
927
+ // node is alive) — so an automatic group keeps no entry for its own group.
928
+ // Other groups' entries survive: the map describes the operator's manual
929
+ // choices, not this group type.
930
+ const selectedNodes = sanitizeSelectedNodes(mihomoRaw.selectedNodes);
931
+ if (groupType !== 'select')
932
+ delete selectedNodes[group];
933
+ const mihomo = {
934
+ enabled: mode === 'mihomo',
935
+ // Tri-state passthrough (see MihomoConfig.autoStart): only an explicit
936
+ // boolean is written, so "absent" keeps meaning "follow the mode". Do not
937
+ // materialize it — that would erase the difference between "never chosen"
938
+ // and "stopped by hand".
939
+ ...(typeof mihomoRaw.autoStart === 'boolean' ? { autoStart: mihomoRaw.autoStart } : {}),
940
+ binaryPath,
941
+ mixedPort: clampPort(mihomoRaw.mixedPort, DEFAULT_MIHOMO_MIXED_PORT),
942
+ controllerPort: clampPort(mihomoRaw.controllerPort, DEFAULT_MIHOMO_CONTROLLER_PORT),
943
+ controllerSecret: secret,
944
+ subscriptions: sanitizeSubscriptions(mihomoRaw.subscriptions),
945
+ testUrl: sanitizeTestUrl(mihomoRaw.testUrl),
946
+ manualNodes: sanitizeManualNodes(mihomoRaw.manualNodes, group),
947
+ selectedGroup: group,
948
+ routingMode,
949
+ groupType,
950
+ groupInterval,
951
+ groupTolerance,
952
+ rules: sanitizeCustomRules(mihomoRaw.rules),
953
+ selectedNodes,
954
+ };
955
+ return {
956
+ enabled: src.enabled === true,
957
+ mode,
958
+ url: typeof src.url === 'string' ? src.url : DEFAULT_CONFIG.proxy?.url,
959
+ includes: stringList(src.includes),
960
+ excludes: stringList(src.excludes),
961
+ mihomo,
962
+ };
963
+ }
964
+ /**
965
+ * Deep-merge a proxy patch onto the stored section so a save that only
966
+ * names `url` / `includes` cannot wipe subscriptions or the controller secret.
967
+ * An explicit `subscriptions` / `manualNodes` array or `selectedNodes` object
968
+ * replaces that field; omitting `mihomo` keeps the stored sidecar section.
969
+ */
970
+ export function mergeProxyConfig(current, incoming) {
971
+ const prev = current ?? {};
972
+ const prevMihomo = prev.mihomo ?? {};
973
+ const incomingMihomo = incoming.mihomo;
974
+ const mihomo = {
975
+ ...prevMihomo,
976
+ ...(incomingMihomo ?? {}),
977
+ subscriptions: incomingMihomo && Object.prototype.hasOwnProperty.call(incomingMihomo, 'subscriptions')
978
+ ? incomingMihomo.subscriptions
979
+ : prevMihomo.subscriptions,
980
+ manualNodes: incomingMihomo && Object.prototype.hasOwnProperty.call(incomingMihomo, 'manualNodes')
981
+ ? incomingMihomo.manualNodes
982
+ : prevMihomo.manualNodes,
983
+ selectedNodes: incomingMihomo && Object.prototype.hasOwnProperty.call(incomingMihomo, 'selectedNodes')
984
+ ? incomingMihomo.selectedNodes
985
+ : prevMihomo.selectedNodes,
986
+ };
987
+ return sanitizeProxyConfig({
988
+ ...prev,
989
+ ...incoming,
990
+ mihomo,
991
+ });
992
+ }
439
993
  export function loadConfig(configPath) {
440
994
  const resolvedPath = getConfigPath(configPath);
995
+ // Only the ACTIVE file's port is remembered (an explicit configPath is a
996
+ // read of some other fixture/env and must not steer saveConfig's writes).
997
+ if (configPath === undefined)
998
+ _diskPort = undefined;
441
999
  if (fs.existsSync(resolvedPath)) {
442
1000
  try {
443
1001
  const raw = fs.readFileSync(resolvedPath, 'utf8');
444
1002
  const parsed = parse(raw);
445
- // Removed keys (retired systems: `rules:`, `flywheel:` + `classifier.localModel`
446
- // (the learning flywheel and the Layer 1 micro-classifier),
447
- // `classifier.layer2.decisionCapture`, the renamed `capture:` section,
448
- // key-level `role`, and the retired hand-written `providers[]` + `models[]` +
449
- // `systemoneUpstreams[]` surfaces (ADR-0010 — connection defs live only in the provider-defs file,
450
- // models materialize from defs + catalog at boot; the `models` field on the
451
- // returned object is the RUNTIME carrier index.ts overwrites with
452
- // boot.models, never the disk value)) are STRIPPED here so
453
- // stale keys never re-persist on the next config save. No dual-read, no
454
- // migration — the config tree is the only source of truth.
455
- const { rules: _removedRules, capture: _removedCapture, flywheel: _removedFlywheel, providers: _removedProviders, models: _removedModels, systemoneUpstreams: _removedSystemoneUpstreams, ...parsedRest } = parsed || {};
456
- // One-shot migration visibility: leftover `providers:` / hand-written
457
- // `models:` sections mean the file was authored against a retired surface
458
- // (ADR-0010) — its entries are silently absent from the pool, so say so ONCE.
459
- const _legacySections = [];
460
- for (const key of ['providers', 'models', 'systemoneUpstreams']) {
461
- if (parsed && Array.isArray(parsed[key]) && parsed[key].length > 0)
462
- _legacySections.push(`'${key}:'`);
1003
+ // STRICT schema contract (ADR-0016): the runtime only ever reads the
1004
+ // CURRENT disk schema. Older files are upgraded ON DISK at boot
1005
+ // (upgradeConfigFile) — never here; this read path has no migration.
1006
+ // A non-current version reaching this point means the boot upgrade did
1007
+ // not process this file (a hand-copied file, a test fixture) — the same
1008
+ // lenient fallback as a syntactically broken file applies (defaults +
1009
+ // one warn). `toRuntimeConfig` is the plain v1 disk→runtime expansion,
1010
+ // not a compat shim; retired-surface keys (rules/capture/flywheel/
1011
+ // providers/models/systemoneUpstreams) are unmapped and therefore
1012
+ // already absent — stale keys never re-persist on the next save.
1013
+ // Contract (ADR-0016): `schemaVersion` is the FIRST key of the file —
1014
+ // a human scanning the file must see the format version before
1015
+ // anything else. Writers always emit it first; a mispositioned key in
1016
+ // a hand-edited file loads (the version itself still gates) but draws
1017
+ // a one-shot order warning.
1018
+ const firstKey = Object.keys(parsed ?? {})[0];
1019
+ if (firstKey !== 'schemaVersion' && !_schemaOrderWarned) {
1020
+ _schemaOrderWarned = true;
1021
+ console.warn(`[Config] ${resolvedPath}: 'schemaVersion' should be the FIRST key of config.yaml ` +
1022
+ `(found '${firstKey ?? 'nothing'}' first). Move it to the top — the next gateway save will.`);
1023
+ }
1024
+ const fileVersion = typeof parsed?.schemaVersion === 'number' && Number.isInteger(parsed.schemaVersion)
1025
+ ? parsed.schemaVersion
1026
+ : 0;
1027
+ if (fileVersion !== SCHEMA_VERSION) {
1028
+ if (!_schemaVersionWarned) {
1029
+ _schemaVersionWarned = true;
1030
+ console.warn(`[Config] ${resolvedPath}: schemaVersion ${fileVersion} !== current ${SCHEMA_VERSION} — the boot-time ` +
1031
+ `config upgrade has not processed this file. Loading built-in defaults; restart the gateway to migrate.`);
1032
+ }
1033
+ return DEFAULT_CONFIG;
463
1034
  }
464
- if (_legacySections.length > 0 && !_retireWarned) {
465
- _retireWarned = true;
466
- const sections = _legacySections.join(' and ');
467
- console.warn(`[Config] Deprecated ${sections} section(s) found in ${resolvedPath} — these hand-written surfaces were retired ` +
468
- `(ADR-0010); providers come from <ocrHome>/providers.json, models materialize from defs + catalog at boot. ` +
469
- `The section(s) are ignored and will not re-persist.`);
1035
+ const flat = toRuntimeConfig(parsed);
1036
+ if (configPath === undefined) {
1037
+ _diskPort = typeof flat.port === 'number' && Number.isFinite(flat.port) ? flat.port : undefined;
470
1038
  }
1039
+ warnForwardProxyRulesOnce(flat.forwardProxy, flat.proxy?.enabled === true);
471
1040
  return {
472
1041
  ...DEFAULT_CONFIG,
473
- ...parsedRest,
1042
+ ...flat,
474
1043
  // Explicit PORT env is the bootstrap/deployment lever (same tier as
475
1044
  // OCR_HOME): the desktop shell and the daemon restart flows pin the
476
1045
  // listen port via env, so a config.yaml `port:` must NOT override it
@@ -482,49 +1051,49 @@ export function loadConfig(configPath) {
482
1051
  // `role` (removed key-level RBAC — unrestricted is expressed by
483
1052
  // simply not configuring modelAccess) is stripped so stale keys
484
1053
  // don't get re-persisted on the next config save.
485
- apiKeys: (parsed?.apiKeys || DEFAULT_CONFIG.apiKeys).map(({ role: _role, ...k }) => k),
486
- webAuth: sanitizeWebAuthInput(parsed?.webAuth),
1054
+ apiKeys: (flat.apiKeys || DEFAULT_CONFIG.apiKeys).map(({ role: _role, ...k }) => k),
1055
+ webAuth: sanitizeWebAuthInput(flat.webAuth),
487
1056
  // Absent `tiers:` section → the DEFAULT_CONFIG empty tier shells; an
488
1057
  // explicit `tiers: {}` stays `{}` (truthy). Both leave every pool
489
1058
  // empty by design (defaults ship no members) — the boot-direct
490
1059
  // warning points at the /tiers page. Cloned so a future in-place
491
1060
  // edit cannot poison the module template.
492
- tiers: parsed?.tiers || structuredClone(DEFAULT_CONFIG.tiers),
493
- routing: { ...DEFAULT_CONFIG.routing, ...parsed?.routing },
494
- fallback: { ...DEFAULT_CONFIG.fallback, ...parsed?.fallback },
1061
+ tiers: flat.tiers || structuredClone(DEFAULT_CONFIG.tiers),
1062
+ routing: { ...DEFAULT_CONFIG.routing, ...flat.routing },
1063
+ fallback: { ...DEFAULT_CONFIG.fallback, ...flat.fallback },
495
1064
  // Retired classifier keys (`localModel` / `layer1` — the Layer 1
496
1065
  // micro-classifier is gone) are stripped alongside the retired Layer 2
497
1066
  // vendor keys (`provider` / `baseUrl` / `apiKey` — the decision layer now calls
498
1067
  // a registered model over the System One protocol) so stale values
499
1068
  // don't get re-persisted on the next console save.
500
1069
  classifier: {
501
- layer2: sanitizeLayer2Input(parsed?.classifier?.layer2),
1070
+ layer2: sanitizeLayer2Input(flat.classifier?.layer2),
502
1071
  },
503
- routeEntries: sanitizeRouteEntriesInput(parsed?.routeEntries),
504
- directives: sanitizeDirectivesInput(parsed?.directives),
505
- proxy: { ...DEFAULT_CONFIG.proxy, ...parsed?.proxy },
506
- forwardProxy: { ...DEFAULT_CONFIG.forwardProxy, ...parsed?.forwardProxy },
1072
+ routeEntries: sanitizeRouteEntriesInput(flat.routeEntries),
1073
+ directives: sanitizeDirectivesInput(flat.directives),
1074
+ proxy: sanitizeProxyConfig(flat.proxy ?? DEFAULT_CONFIG.proxy),
1075
+ forwardProxy: resolveForwardProxyConfig(flat.forwardProxy),
507
1076
  compression: {
508
- rtk: { ...DEFAULT_CONFIG.compression?.rtk, ...parsed?.compression?.rtk },
509
- headroom: { ...DEFAULT_CONFIG.compression?.headroom, ...parsed?.compression?.headroom },
510
- caveman: { ...DEFAULT_CONFIG.compression?.caveman, ...parsed?.compression?.caveman },
1077
+ rtk: { ...DEFAULT_CONFIG.compression?.rtk, ...flat.compression?.rtk },
1078
+ headroom: { ...DEFAULT_CONFIG.compression?.headroom, ...flat.compression?.headroom },
1079
+ caveman: { ...DEFAULT_CONFIG.compression?.caveman, ...flat.compression?.caveman },
511
1080
  },
512
- requestCapture: resolveRequestCapture(parsed),
513
- tracePersist: { ...DEFAULT_CONFIG.tracePersist, ...parsed?.tracePersist },
514
- circuitBreaker: resolveCircuitBreaker(parsed),
515
- rateLimit: resolveRateLimit(parsed),
1081
+ streaming: resolveStreamingConfig(flat.streaming),
1082
+ requestCapture: resolveRequestCapture(flat),
1083
+ tracePersist: { ...DEFAULT_CONFIG.tracePersist, ...flat.tracePersist },
1084
+ circuitBreaker: resolveCircuitBreaker(flat),
1085
+ rateLimit: resolveRateLimit(flat),
516
1086
  retry: {
517
- enabled: parsed?.retry?.enabled ?? DEFAULT_CONFIG.retry?.enabled,
518
- inplace: { ...DEFAULT_CONFIG.retry?.inplace, ...parsed?.retry?.inplace },
519
- failover: { ...DEFAULT_CONFIG.retry?.failover, ...parsed?.retry?.failover },
1087
+ enabled: flat.retry?.enabled ?? DEFAULT_CONFIG.retry?.enabled,
1088
+ inplace: { ...DEFAULT_CONFIG.retry?.inplace, ...flat.retry?.inplace },
1089
+ failover: { ...DEFAULT_CONFIG.retry?.failover, ...flat.retry?.failover },
520
1090
  },
521
- // RUNTIME carrier only — the disk value is stripped above; index.ts
1091
+ // RUNTIME carrier only — the disk value never maps; index.ts
522
1092
  // assigns boot.models over this before registry construction.
523
1093
  models: DEFAULT_CONFIG.models,
524
- combos: parsed?.combos || [],
525
- modelProfiles: parsed?.modelProfiles || [],
526
- clientProfileMemory: parsed?.clientProfileMemory || {},
527
- catalog: parsed?.catalog,
1094
+ combos: flat.combos || [],
1095
+ clientProfileMemory: flat.clientProfileMemory || {},
1096
+ catalog: flat.catalog,
528
1097
  };
529
1098
  }
530
1099
  catch (err) {
@@ -543,7 +1112,13 @@ export function defaultConfigYaml() {
543
1112
  // `models` is the RUNTIME carrier (index.ts assigns boot.models) — the
544
1113
  // retired yaml surface must not reappear in the fresh-install template.
545
1114
  const { models: _omitted, ...template } = DEFAULT_CONFIG;
546
- return annotateYamlComments(stringify(template));
1115
+ // `PORT` is a bootstrap lever (see saveConfig): a template written during a
1116
+ // PORT-fed boot (e.g. `bun run dev`) must still name the product default, or
1117
+ // that one boot's env value would silently become the env's permanent port.
1118
+ template.port = DEFAULT_GATEWAY_PORT;
1119
+ // ZERO-COMMENT disk contract (ADR-0016): config.yaml carries values only —
1120
+ // field comments are console-rendered on demand (see comments-zh/en.ts).
1121
+ return stringify({ schemaVersion: SCHEMA_VERSION, ...toDiskConfig(template) });
547
1122
  }
548
1123
  /**
549
1124
  * First-boot template initialization: when the active environment has no
@@ -576,6 +1151,55 @@ export function ensureDefaultConfigFile() {
576
1151
  return { created: false, path: configPath };
577
1152
  }
578
1153
  }
1154
+ /**
1155
+ * Boot-time config schema upgrade (ADR-0016): the ONE place a legacy/older
1156
+ * config.yaml is migrated. Runs before the first loadConfig of the process;
1157
+ * on success the on-disk file IS the current schema — the runtime read path
1158
+ * (loadConfig) never migrates, it only asserts the version.
1159
+ * - file version < current → migrate the chain, rewrite in place
1160
+ * (`.bak` snapshot first — the raw page's rollback promise), warn the
1161
+ * change list once.
1162
+ * - file version > current → BOOT ERROR ("upgrade OCR"), same contract as
1163
+ * the env-container import gate; fail-fast, never silent fallback.
1164
+ * Idempotent: a current-version file is untouched.
1165
+ */
1166
+ export function upgradeConfigFile() {
1167
+ const configPath = getConfigPath();
1168
+ if (!fs.existsSync(configPath))
1169
+ return { migrated: false, fromVersion: SCHEMA_VERSION };
1170
+ let parsed;
1171
+ try {
1172
+ parsed = parse(fs.readFileSync(configPath, 'utf8'));
1173
+ }
1174
+ catch (err) {
1175
+ // Syntax errors are loadConfig's lenient tier — not an upgrade concern.
1176
+ return { migrated: false, fromVersion: SCHEMA_VERSION };
1177
+ }
1178
+ const { disk, fromVersion, warnings, tooNew } = migrateConfig(parsed);
1179
+ if (tooNew) {
1180
+ throw new Error(`config.yaml schemaVersion ${fromVersion} is NEWER than this build supports (current ${SCHEMA_VERSION}). ` +
1181
+ `Upgrade OmniCellRouter — refusing to start with a newer schema.`);
1182
+ }
1183
+ if (fromVersion === SCHEMA_VERSION)
1184
+ return { migrated: false, fromVersion };
1185
+ try {
1186
+ fs.copyFileSync(configPath, `${configPath}.bak`);
1187
+ fs.writeFileSync(configPath, stringify(disk), 'utf8');
1188
+ }
1189
+ catch (err) {
1190
+ // Rewrite failure must not brick the boot: loadConfig will see the old
1191
+ // version and fall back to defaults with its own warn (same tier as a
1192
+ // broken file), and the next boot retries the upgrade.
1193
+ console.warn(`[Config] Could not rewrite ${configPath} at schemaVersion ${SCHEMA_VERSION}: ${err.message}`);
1194
+ return { migrated: false, fromVersion };
1195
+ }
1196
+ if (warnings.length > 0) {
1197
+ console.warn(`[Config] ${configPath}: config schema upgraded v${fromVersion} → v${SCHEMA_VERSION}:`);
1198
+ for (const w of warnings)
1199
+ console.warn(` - ${w}`);
1200
+ }
1201
+ return { migrated: true, fromVersion };
1202
+ }
579
1203
  export function getRawConfig() {
580
1204
  const configPath = getConfigPath();
581
1205
  if (fs.existsSync(configPath)) {
@@ -592,18 +1216,39 @@ export function saveRawConfig(yamlContent) {
592
1216
  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
593
1217
  return { success: false, error: 'YAML must define an object configuration' };
594
1218
  }
595
- // config.yaml.bak snapshot BEFORE overwriting — the raw page's own copy
596
- // (yaml.desc / savedNotice) promises this backup; keeping the promise true
597
- // gives hand-edits a manual rollback path (loadConfig itself never
598
- // rejects: a semantically wrong but syntactically valid file loads
599
- // leniently, so the .bak is the only undo a raw save ever has).
1219
+ // Writers ALWAYS emit the CURRENT schema (ADR-0016): a raw save of an
1220
+ // older-format draft (or a hand-copied file pasted into the editor) is
1221
+ // migrated + regrouped before it touches disk — annotation comments
1222
+ // replace the draft's, matching every other save path. A draft targeting
1223
+ // a NEWER schema is refused ("upgrade OCR"). A config.yaml.bak snapshot
1224
+ // precedes every overwrite — the raw page's own copy (yaml.desc /
1225
+ // savedNotice) promises this backup; keeping the promise true gives
1226
+ // hand-edits a manual rollback path (loadConfig itself never rejects: a
1227
+ // semantically wrong but syntactically valid file loads leniently, so
1228
+ // the .bak is the only undo a raw save ever has).
1229
+ const { disk, tooNew, fromVersion, warnings } = migrateConfig(parsed);
1230
+ if (tooNew) {
1231
+ return {
1232
+ success: false,
1233
+ error: `config schemaVersion ${fromVersion} is newer than this build supports (current ${SCHEMA_VERSION}) — upgrade OmniCellRouter`,
1234
+ };
1235
+ }
600
1236
  if (fs.existsSync(configPath)) {
601
1237
  fs.copyFileSync(configPath, `${configPath}.bak`);
602
1238
  }
603
- fs.writeFileSync(configPath, yamlContent, 'utf8');
604
- // The raw save is a config save too: refresh the auth snapshot view, the
1239
+ // schemaVersion is machine-managed (ADR-0016): the operator can misplace
1240
+ // it, never lose it. A verbatim write is only allowed when the version key
1241
+ // is BOTH current AND the first key; anything else goes through the
1242
+ // canonical regroup, which rewrites it first with the current version.
1243
+ const firstIsVersion = parsed.schemaVersion === SCHEMA_VERSION && Object.keys(parsed)[0] === 'schemaVersion';
1244
+ fs.writeFileSync(configPath, fromVersion === SCHEMA_VERSION && firstIsVersion ? yamlContent : stringify(disk), 'utf8');
1245
+ if (warnings.length > 0) {
1246
+ console.warn(`[Config] ${configPath}: draft upgraded v${fromVersion} → v${SCHEMA_VERSION}:`);
1247
+ for (const w of warnings)
1248
+ console.warn(` - ${w}`);
1249
+ }
605
1250
  // credentials overlay AND the limiter rule table through the SAME routine as
606
- // saveConfig (the pre-fix here left runtimeConfigRef stale — the YAML
1251
+ // saveConfig (the pre-fix here left the live snapshot stale — the YAML
607
1252
  // editor violated the module's own hot-apply promise).
608
1253
  syncRuntimeAuthView(loadConfig());
609
1254
  return { success: true };
@@ -612,27 +1257,6 @@ export function saveRawConfig(yamlContent) {
612
1257
  return { success: false, error: err.message };
613
1258
  }
614
1259
  }
615
- /**
616
- * Live reference to the RUNNING server's config object (registered by
617
- * createServer). The auth preHandler prefers `config.apiKeys` over a fresh
618
- * disk read (boot snapshot) — without syncing, a key edited via the UI or the
619
- * YAML editor would persist to config.yaml yet keep failing on the wire until
620
- * the next restart. Every config save refreshes the snapshot's keys in-place.
621
- */
622
- let runtimeConfigRef;
623
- /** Called once by createServer so config saves can refresh the boot snapshot. */
624
- export function registerRuntimeConfigRef(cfg) {
625
- runtimeConfigRef = cfg;
626
- }
627
- /**
628
- * Live config snapshot (createServer's object, hot-synced by saveConfig for
629
- * the fields the running gateway reads per request: apiKeys, webAuth).
630
- * Console-auth endpoints prefer it over a disk re-read so the gate and the
631
- * credential checks can never disagree.
632
- */
633
- export function getRuntimeConfigRef() {
634
- return runtimeConfigRef;
635
- }
636
1260
  /**
637
1261
  * Single sync routine for BOTH writers (saveConfig / saveRawConfig): the
638
1262
  * module docstring above registerRuntimeConfigRef promises "a key edited via
@@ -643,30 +1267,45 @@ export function getRuntimeConfigRef() {
643
1267
  * path, not just the visual one.
644
1268
  */
645
1269
  function syncRuntimeAuthView(fresh) {
646
- if (runtimeConfigRef) {
647
- runtimeConfigRef.apiKeys = fresh.apiKeys;
648
- runtimeConfigRef.webAuth = fresh.webAuth;
649
- runtimeConfigRef.credentials = fresh.credentials;
1270
+ const live = getRuntimeConfigRef();
1271
+ if (live) {
1272
+ live.apiKeys = fresh.apiKeys;
1273
+ live.webAuth = fresh.webAuth;
1274
+ live.credentials = fresh.credentials;
650
1275
  // quotaProbes/quota ride the SAME routine (iron rule: a raw-YAML
651
1276
  // save must never leave the runtime view stale): the prober reads its
652
1277
  // entry set off the live ref on every reloadConfig(), and the console
653
1278
  // quota panel reads rejected/coverage state from it.
654
- runtimeConfigRef.quotaProbes = fresh.quotaProbes;
655
- runtimeConfigRef.quota = fresh.quota;
1279
+ live.quotaProbes = fresh.quotaProbes;
1280
+ live.quota = fresh.quota;
656
1281
  // rateLimit (inbound grace) too: resolveActiveAuthConfig reads the boot
657
1282
  // snapshot FIRST (`config.rateLimit?.inboundGraceMs ?? disk…` — the disk
658
1283
  // arm never fires because loadConfig always resolves the section), so
659
1284
  // without this line the grace knob would silently ignore every save.
660
- runtimeConfigRef.rateLimit = fresh.rateLimit;
1285
+ live.rateLimit = fresh.rateLimit;
661
1286
  // classifier / routing / systemone hot-apply too (per-request reads only —
662
1287
  // the decision layer resolves model/timeout/effortDecision per evaluate, the mode
663
1288
  // lever per processInternal, the System One defaultModel per decision):
664
1289
  // the /auto page's "restart to apply" era is over for everything it edits.
665
- // Sections with boot-time consumers (streaming executors, models,
666
- // tiers bootstrap) deliberately stay restart-only.
667
- runtimeConfigRef.classifier = fresh.classifier;
668
- runtimeConfigRef.routing = fresh.routing;
669
- runtimeConfigRef.systemone = fresh.systemone;
1290
+ // Sections with boot-time consumers (models, tiers bootstrap, plugin
1291
+ // streams) deliberately stay restart-only.
1292
+ live.classifier = fresh.classifier;
1293
+ live.routing = fresh.routing;
1294
+ live.systemone = fresh.systemone;
1295
+ // streaming too: both axes are read PER REQUEST (surfaces/chat-pipeline.ts
1296
+ // for the client shape, the orchestrator for the provider transport), so
1297
+ // only the WIRE capability (which providers implement createStream) is
1298
+ // boot-fixed. The pipeline gate is re-seeded by the save handlers.
1299
+ live.streaming = fresh.streaming;
1300
+ // forwardProxy too — the MITM rule table and admission gate read the live
1301
+ // boot snapshot per request, so a save must land here or the console's
1302
+ // "takes effect immediately" promise is false. Strict credential mode is
1303
+ // read from the same object by the gateway plugin host.
1304
+ live.forwardProxy = fresh.forwardProxy;
1305
+ // proxy policy is hot-applied (initProxyConfig on the save path). Keep
1306
+ // the boot snapshot on the same object so a later reader of the live
1307
+ // ref does not keep the pre-save endpoint.
1308
+ live.proxy = fresh.proxy;
670
1309
  }
671
1310
  getRateLimiter().reload(fresh);
672
1311
  // Rebuild the effective quota plan right after the ref sync (the prober
@@ -690,6 +1329,21 @@ export function saveConfig(newConfig) {
690
1329
  delete bodyRest.requestCapture.systemone;
691
1330
  }
692
1331
  const merged = { ...current, ...bodyRest };
1332
+ if (bodyRest.proxy && typeof bodyRest.proxy === 'object') {
1333
+ merged.proxy = mergeProxyConfig(current.proxy, bodyRest.proxy);
1334
+ }
1335
+ // `PORT` is a bootstrap lever, never a file value (see _diskPort): a save
1336
+ // that does not itself name a port keeps the file's own value, so a dev
1337
+ // boot's env port cannot relocate an installed gateway on its next restart.
1338
+ // A file that names no port must stay port-less — deleting the key lets the
1339
+ // next boot re-derive it (PORT or DEFAULT_GATEWAY_PORT) instead of freezing
1340
+ // this boot's env value into the file.
1341
+ if (process.env.PORT?.trim() && bodyRest.port === undefined) {
1342
+ if (_diskPort !== undefined)
1343
+ merged.port = _diskPort;
1344
+ else
1345
+ delete merged.port;
1346
+ }
693
1347
  // `current` comes from loadConfig(): the retired surfaces and the models
694
1348
  // runtime carrier are already stripped to [] — do not persist empty
695
1349
  // retired keys into the file (defaultConfigYaml omits them too).
@@ -703,8 +1357,22 @@ export function saveConfig(newConfig) {
703
1357
  merged.webAuth = { ...merged.webAuth, passwordHash: current.webAuth.passwordHash };
704
1358
  }
705
1359
  merged.webAuth = sanitizeWebAuthInput(merged.webAuth);
706
- const yamlContent = annotateYamlComments(stringify(merged));
707
- fs.writeFileSync(configPath, yamlContent, 'utf8');
1360
+ // One-step undo for EVERY save, not just the raw-page editor: a sanitizer
1361
+ // regression once dropped a whole section and the console save persisted
1362
+ // the loss with no previous file to restore. Best effort — an absent file
1363
+ // (first boot) simply has nothing to back up.
1364
+ try {
1365
+ fs.copyFileSync(configPath, `${configPath}.bak`);
1366
+ }
1367
+ catch {
1368
+ /* first write or read-only filesystem */
1369
+ }
1370
+ // Writers ALWAYS emit the CURRENT schema: the flat runtime merge is
1371
+ // regrouped through the single mapping table before serialization
1372
+ // (ADR-0016 — a save upgrades the file, there is no downgrade path).
1373
+ // ZERO-COMMENT disk contract: values only — comments are console-rendered
1374
+ // on demand from comments-zh.ts / comments-en.ts.
1375
+ fs.writeFileSync(configPath, stringify({ schemaVersion: SCHEMA_VERSION, ...toDiskConfig(merged) }), 'utf8');
708
1376
  // Single sync routine for both writers (see syncRuntimeAuthRef doc): the
709
1377
  // running gateway's key snapshot, the credentials overlay and the limiter
710
1378
  // rule table follow every save (key CRUD, visual editor, raw YAML — all
@@ -722,245 +1390,3 @@ export function saveConfig(newConfig) {
722
1390
  // per-field comments from the map below before writing, keeping the on-disk
723
1391
  // file self-documenting. saveRawConfig() writes user YAML verbatim and keeps
724
1392
  // whatever comments the user typed.
725
- const YAML_FILE_HEADER = [
726
- 'OmniCellRouter 网关配置(config.yaml)',
727
- '可视化编辑:控制台「可视化配置」页;手写编辑:「配置文件」页(原文保存,注释保留)',
728
- '注意:大部分配置保存即时生效(代理/捕捉/梯队/组合/熔断/限流等,逐项见注释);标注「重启网关生效」的段落需重启;价格单位均为 美元/百万 tokens',
729
- ].join('\n');
730
- /** yaml pkg renders commentBefore verbatim after '#', so pad one space per line ourselves. */
731
- const padComment = (text) => ' ' + text.replace(/\n/g, '\n ');
732
- /** Field path (dotted, relative to root) → zh-CN comment. `tiers.*` covers any tier name. */
733
- const YAML_FIELD_COMMENTS = {
734
- port: '网关监听端口',
735
- host: '监听地址(默认 127.0.0.1 仅本机;0.0.0.0 = 监听所有网卡,非回环绑定强制启用 webAuth 登录)',
736
- adminApiKey: '推理面主密钥(/v1/* 全模型访问),亦可作为控制台 /api/admin/* 的程序化访问凭据(Authorization: Bearer)',
737
- webAuth: '控制台登录鉴权(/admin 管理面的凭证密码;绑定非回环地址时强制启用)',
738
- 'webAuth.enabled': '控制台登录开关:true 需凭证密码登录;绑定 0.0.0.0 / 局域网 IP 时必须为 true(否则网关拒绝启动),仅 127.0.0.1 绑定可关闭',
739
- 'webAuth.username': '控制台登录用户名',
740
- 'webAuth.passwordHash': '登录密码的 scrypt 哈希(格式 scrypt$<saltHex>$<hashHex>,绝不存明文;在控制台「系统设置」页修改,勿手写)',
741
- tiers: '梯队成员策略:候选池唯一依据 = 各梯队显式 members 成员列表 + 全局排除名单;出厂默认为四个空梯队(不内置任何成员 glob,运行时也不自动生成种子),首次启动所有候选池为空、`auto` 无法路由,需在控制台 /tiers 页或本文件添加 members;无任何规则命中的模型=未分类,不进任何池;主选策略只影响池内用法(控制台 /tiers 页可视化编辑,保存即时生效;删除整个 tiers 段会在下次加载时恢复这套空默认)',
742
- 'tiers.*.members': '成员列表(顺序=优先级/failover 链):每项 { pattern, weight?, effortMap? } —— pattern 匹配完整模型 id(provider/model),glob 通配(* 任意 / ? 单字符,不区分大小写),不带通配符=子串匹配、写完整 id=单项;pattern 亦可写 combo:<组合id> 引用模型组合——每次提交/保存时原位展开为该组合已注册成员(组合编辑后梯队池自动跟随;权重取自组合成员条目;死引用=组合不存在/已停用/无已注册成员,展开为空并在保存检查告警);effortMap=思考级别翻译(如 { none: high, low: high },未配置的级别原样透传),组合引用上的 effortMap 作用于其全部展开成员;同一模型/组合可加入多个梯队——各梯队成员资格独立计算,链序/权重/effortMap 均取自本梯队自己的规则',
743
- 'tiers.exclude': '全局排除名单(在原始 YAML 页编辑;/tiers 页保存时原样回传):命中的模型不进入任何梯队候选池(无条件;仅可按 id 直连或经组合调用)',
744
- 'tiers.*.selection': '主选策略:priority 优先级 / weighted 加权随机 / round_robin 轮询',
745
- 'tiers.*.match': '【仅匹配建议引擎】不参与路由、不再生成成员列表:用于模型目录页推荐、/tiers 页预览与保存时检查;候选池唯一依据是上方 members(出厂默认为空,无内置 glob),请在控制台 /tiers 页增删成员(保存即时生效)',
746
- 'tiers.*.match.patterns': '【仅匹配建议引擎】名称通配符(glob)',
747
- 'tiers.*.match.minInputPerM': '【仅匹配建议引擎】输入价下限 $/M',
748
- 'tiers.*.match.maxInputPerM': '【仅匹配建议引擎】输入价上限 $/M',
749
- 'tiers.*.match.exclude': '【仅匹配建议引擎】名称/价格否决(不给出该梯队建议)',
750
- 'tiers.*.match.excludeTiers': '【仅匹配建议引擎】锚定排除(被引梯队的条件命中即否决)',
751
- routing: '路由模式:smart=分类级联(默认)/ cost=始终 lite / quality=始终 pro',
752
- fallback: '失败兜底:重试耗尽后按梯队升级重试',
753
- 'fallback.maxRetries': '兜底重试次数',
754
- 'fallback.escalateTier': '兜底升级目标梯队',
755
- 'fallback.injectErrorContext': '兜底请求是否注入上游错误上下文',
756
- classifier: '意图分类器(smart 模式的 lite/pro/ultra 判定)',
757
- 'classifier.layer2.enabled': 'Layer2 判定开关(经本机 System One 协议调用已注册模型)',
758
- 'classifier.layer2.model': '判定模型 id(已注册的模型;留空则用 systemone.defaultModel)',
759
- systemone: 'System One 决策面(POST /v1/systemone):本机协议直连已注册模型,其余模型走 chat-model 转换;此节的 defaultModel 为未指定 model 的请求兜底,同时在 classifier.layer2.model 留空时充当 L2 决策层的决策模型',
760
- 'systemone.defaultModel': 'System One 默认模型(已注册模型 id):为未指定 model(或 model=auto)的 /v1/systemone 请求兜底,不经梯队级联;classifier.layer2.model 留空时 L2 决策层也用它。重启网关生效',
761
- 'classifier.layer2.timeoutMs': '判定超时(毫秒,默认 5000):未命中缓存的新上下文先等判定再放行(串行计价),超时回落默认 plus 梯队;经 chat 转换的判定模型 1.5 秒内很少答完,建议 3000-10000。保存后即时生效',
762
- 'classifier.layer2.decisionCache': '判定决策缓存(相同上下文复用判定结果)',
763
- 'classifier.layer2.collectEnabled': 'L2 决策样本采集开关(默认 false 关闭):单键门控,落盘 data/layer2-decisions.jsonl(不进捕捉页),64MB 封顶后停写并告警一次;热生效',
764
- 'classifier.layer2.effortDecision': 'L2 决策思考级别判定开关(默认 false 关闭):开启后决策层在同一次调用中同时判定梯队与思考级别,仅对省略 reasoning_effort 的请求补位(客户端显式值永远优先),判定结果逐轮浮动不进会话棘轮;注意决策层抬档会多花思考 token 费用',
765
- 'classifier.layer2.effortFloor': 'L2 可下探的最低思考级别(默认 low):只约束决策模型自己的选择,绝不覆盖客户端显式值;自动机制不降档,更低档位只能由 @ocr-effort-down 指令发起',
766
- directives: '升档指令(ADR-0011):在最后一条 user 消息里写 @ocr-tier-up / @ocr-tier-down / @ocr-effort-up / @ocr-effort-down 让当轮升/降一档,或写 @ocr-tier-ultra / @ocr-effort-high 直接把当轮钉在指定档位(会话天花板只限制自动升档,指令本来就不受它约束);@ocr-continue 表示纯续写——不作用任何档位,单独成消息时整条抹除,当轮按原档位续写上一条回复;指令每轮都会从上行消息链抹除,只作用于当轮,不改变会话梯队上限,也不写回经验表;同轴「钉住」优先于「步进」',
767
- 'directives.enabled': '指令总开关(默认开):关闭后既不抹除也不生效,@ocr-* 字样会作为普通文本原样发往上游;保存后即时生效',
768
- 'directives.prefix': '指令命名空间(默认 @ocr-):形如 @ + 短标识 + 结尾分隔符(- _ . :),3-32 字符;ocr 是行业通用缩写(如光学字符识别),若你的提示词里会出现 @ocr-pipeline 这类文本,可改成 @omnicell- 等更少冲突的前缀;非法值回落默认;改动会让此前写下的旧前缀 token 变回普通文本(一次性前缀缓存失效)',
769
- routeEntries: '路由经验表:按归一化 prompt 记忆历史路由档位;enabled 关闭即整个子系统停用(查询/写入/审计台账全停);升档/降档由 @ocr-* 指令显式发起,不再自动判定',
770
- 'routeEntries.enabled': '经验表总开关(查询、白名单写入与审计台账);保存后即时生效',
771
- 'routeEntries.snippetEnabled': '是否存 prompt 前 200 字符片段供控制台浏览/人工识别(隐私敏感,默认开;关闭只影响新写入,不删除已存片段)',
772
- 'routeEntries.maxEntries': '经验条目上限(按最后活动时间 LRU 淘汰;人工编辑条目豁免淘汰;非正数/非法值加载时回落默认 5000)',
773
- 'circuitBreaker': '熔断器(按模型统计失败并自动摘除,见 /guardrails 页);规则组 rules 可逐条开关并覆写参数,保存后即时生效(无需重启;仅 persistence.debounceMs 需重启)',
774
- 'circuitBreaker.failureThreshold': '窗口内失败次数阈值(达到即熔断);rules.trip.consecutiveFailures.threshold 未设置时的全局默认值',
775
- 'circuitBreaker.slidingWindowSize': '滑动窗口样本数;rules.trip.failureRate.windowSize 未设置时的全局默认值',
776
- 'circuitBreaker.failureRateThreshold': '失败率阈值(0-1);rules.trip.failureRate.failureRate 未设置时的全局默认值',
777
- 'circuitBreaker.initialCooldownMs': '首次熔断冷却时长(毫秒);各规则冷却参数未设置时的全局默认值',
778
- 'circuitBreaker.maxCooldownMs': '冷却时长上限(毫秒),任何推导冷却(含 429 Retry-After 钳制)的总封顶',
779
- 'circuitBreaker.cooldownMultiplier': '连续熔断的冷却指数退避倍数;rules.trip.consecutiveFailures.cooldownMultiplier 与 rules.recovery.cooldownMultiplier 未设置时的默认值',
780
- 'circuitBreaker.quotaCooldownMs': '配额/余额耗尽专用冷却时长(毫秒);rules.trip.quota/auth.cooldownMs 未设置时的默认值',
781
- 'circuitBreaker.halfOpenMaxProbes': '半开状态最大并发探测数;rules.recovery.halfOpen.maxProbes 未设置时的默认值(同时是主动探测每模型每周期的预算,下限 1)',
782
- 'circuitBreaker.activeProbing': '主动探测(冷却期内定时试探是否恢复)',
783
- 'circuitBreaker.activeProbing.intervalMs': '探测间隔(毫秒)',
784
- 'circuitBreaker.credentialAffinity': '会话凭证亲和(多凭证供应商:会话绑定一个凭证,仅故障转移时切换,绝不负载均衡)',
785
- 'circuitBreaker.credentialAffinity.cacheTtlMs': '亲和窗口(毫秒,默认 300000 = Anthropic 提示缓存 5 分钟);空闲超过此窗口的会话按新会话重新分散选号',
786
- 'circuitBreaker.rules': '熔断规则组,阅读顺序=因果链:counting 计不计入失败 → trip 何时熔断 → recovery 如何恢复;每项缺省=沿用上方全局旋钮/当前行为;整段缺省与旧版行为逐字节一致;保存后即时生效(新规则从下一次判定起生效,已有熔断状态不回溯重评)',
787
- 'circuitBreaker.rules.counting': 'A 区:哪些错误算失败(计入 trip 规则),各自熔断的最短时长(minCooldownMs 下限,经 max(下限, 计算值) 生效)',
788
- 'circuitBreaker.rules.counting.serverErrors': '5xx/网络抖动(SERVICE_UNAVAILABLE)计入开关+冷却下限;关闭=既不熔断也不计数(默认开,下限默认=initialCooldownMs)',
789
- 'circuitBreaker.rules.counting.serverErrors.enabled': '关闭后 5xx/抖动不再计入熔断统计',
790
- 'circuitBreaker.rules.counting.serverErrors.minCooldownMs': '此类失败触发的熔断不短于该毫秒数(默认=initialCooldownMs)',
791
- 'circuitBreaker.rules.counting.unknownErrors': '未分类上游错误计入开关+冷却下限(默认开,下限默认=initialCooldownMs)',
792
- 'circuitBreaker.rules.counting.unknownErrors.enabled': '关闭后未分类错误不再计入熔断统计',
793
- 'circuitBreaker.rules.counting.unknownErrors.minCooldownMs': '此类失败触发的熔断不短于该毫秒数(默认=initialCooldownMs)',
794
- 'circuitBreaker.rules.counting.rateLimitErrors': '429 的计入性无开关(分类器始终计数);本键只拥有“无 Retry-After 时”的冷却下限(默认 min(60000, initialCooldownMs))',
795
- 'circuitBreaker.rules.counting.rateLimitErrors.minCooldownMs': '无 Retry-After 的 429 计入后的熔断冷却下限(毫秒);带 Retry-After 的沿用其推导值',
796
- 'circuitBreaker.rules.counting.clientErrors': '400/422 客户端错误是否计入失败(默认关=现行为不惩罚;开启后按 trip 规则自身阶梯计)',
797
- 'circuitBreaker.rules.counting.clientErrors.enabled': '开启后 400/422 计入熔断统计(不建议:客户端问题不应惩罚上游)',
798
- 'circuitBreaker.rules.trip': 'B 区:计数到的失败何时打开熔断;scope=blast 半径覆写 auto|pair|credential|model(仅在有凭据归属时生效,无链供应商自然退化为模型级);五个开关全部关闭=自动熔断彻底关闭(手动熔断不受影响)',
799
- 'circuitBreaker.rules.trip.quota': '402/配额措辞 → 立即熔断(默认开);关闭=402 既不熔断也不计数,并会释放存量 breaker.quota 熔断记录(保存时与重启恢复时均对账丢弃)',
800
- 'circuitBreaker.rules.trip.quota.enabled': '关闭后 402 不再自动熔断',
801
- 'circuitBreaker.rules.trip.quota.cooldownMs': '402 硬熔断时长(毫秒,默认=quotaCooldownMs 12h)',
802
- 'circuitBreaker.rules.trip.quota.scope': 'blast 半径覆写:auto=按错误类型(402 默认 credential=该凭据全部模型)/ pair=仅模型×该凭据 / credential=该凭据全部模型 / model=该模型全部凭据',
803
- 'circuitBreaker.rules.trip.auth': '401 → 立即熔断(默认开);关闭=401 既不熔断也不计数,并释放存量 breaker.auth 记录',
804
- 'circuitBreaker.rules.trip.auth.enabled': '关闭后 401 不再自动熔断',
805
- 'circuitBreaker.rules.trip.auth.cooldownMs': '401 硬熔断时长(毫秒,默认=quotaCooldownMs 12h)',
806
- 'circuitBreaker.rules.trip.auth.markSuspect': '熔断时把该凭证标记为 SUSPECT(默认开);关闭只停止新标记——已存在的标记仍拦截选路,直到手动清除',
807
- 'circuitBreaker.rules.trip.auth.scope': 'blast 半径覆写(401 默认 credential);见 rules.trip 说明',
808
- 'circuitBreaker.rules.trip.rateLimit': '429 带 Retry-After 且超过 hardTripAboveMs → 硬熔断;关闭=此类 429 降级为“计入统计的失败”(不是忽略),其 Retry-After 推导下限照常流入 max(下限, 计算值)',
809
- 'circuitBreaker.rules.trip.rateLimit.enabled': '关闭后长 Retry-After 的 429 不再硬熔断,只计入统计失败',
810
- 'circuitBreaker.rules.trip.rateLimit.hardTripAboveMs': '硬/软分界(毫秒):Retry-After 超过它才硬熔断;默认=retry.inplace.maxRateLimitWaitMs(覆写后与重试侧分界脱钩,属有意分歧)',
811
- 'circuitBreaker.rules.trip.rateLimit.minCooldownMs': 'Retry-After 推导冷却的下限(毫秒,默认 1000;总封顶仍是全局 maxCooldownMs)',
812
- 'circuitBreaker.rules.trip.rateLimit.scope': 'blast 半径覆写(429 默认 pair;“每日/每周额度”措辞默认 credential);见 rules.trip 说明',
813
- 'circuitBreaker.rules.trip.consecutiveFailures': '连续失败达阈值 → 熔断(默认开);关闭=连续阈值不再检查;阶梯:initialCooldownMs×cooldownMultiplier^n,封顶 maxCooldownMs',
814
- 'circuitBreaker.rules.trip.consecutiveFailures.enabled': '关闭后不再按“连续失败次数”自动熔断',
815
- 'circuitBreaker.rules.trip.consecutiveFailures.threshold': '连续失败次数阈值(默认=failureThreshold 3)',
816
- 'circuitBreaker.rules.trip.consecutiveFailures.initialCooldownMs': '阶梯首档冷却(毫秒,默认=initialCooldownMs)',
817
- 'circuitBreaker.rules.trip.consecutiveFailures.cooldownMultiplier': '阶梯倍数(默认=cooldownMultiplier 2.0)',
818
- 'circuitBreaker.rules.trip.consecutiveFailures.maxCooldownMs': '阶梯封顶(毫秒,默认=maxCooldownMs 5h)',
819
- 'circuitBreaker.rules.trip.consecutiveFailures.scope': 'blast 半径覆写(计入统计类失败默认按分类器 scope:5xx=credential、未分类=pair);见 rules.trip 说明',
820
- 'circuitBreaker.rules.trip.failureRate': '滑动窗口失败率 → 熔断(默认开);关闭=窗口速率不再检查;速率仅在已记录调用数 >= minCalls 时评估',
821
- 'circuitBreaker.rules.trip.failureRate.enabled': '关闭后不再按“窗口失败率”自动熔断',
822
- 'circuitBreaker.rules.trip.failureRate.windowSize': '共享结果环形缓冲大小(默认=slidingWindowSize 20;是熔断器构造参数,改变会影响持久化窗口切片)',
823
- 'circuitBreaker.rules.trip.failureRate.failureRate': '失败率阈值(0-1 小数,默认=failureRateThreshold 0.5)',
824
- 'circuitBreaker.rules.trip.failureRate.minCalls': '评估速率所需的最少已记录调用数(默认=windowSize 即旧版“满窗才判”,下限 0,封顶 windowSize;调低可在稀疏流量上更快熔断)',
825
- 'circuitBreaker.rules.trip.failureRate.cooldownMs': '速率熔断时长(毫秒,默认=initialCooldownMs)',
826
- 'circuitBreaker.rules.trip.failureRate.scope': 'blast 半径覆写;见 rules.trip 说明(与 consecutiveFailures 同时覆写时,前者优先——两条规则共用一次记录)',
827
- 'circuitBreaker.rules.recovery': 'C 区:已熔断模型如何恢复;半开试航=最多 maxProbes 个并发探测,成功累计到 successThreshold 才完全恢复(CLOSED)',
828
- 'circuitBreaker.rules.recovery.onCanaryFailure': '探测失败/试航批次未达标/半开超时后的去向:backoff=阶梯加倍再熔(现行)/ initial=按阶梯首档重新熔 / close=乐观恢复(保留 consecutiveFailures 与当前阶梯,下次失败即以更高档重熔;手动熔断无视 close,必定重新打开)',
829
- 'circuitBreaker.rules.recovery.cooldownMultiplier': 'backoff 去向的阶梯倍数(默认=cooldownMultiplier 2.0)',
830
- 'circuitBreaker.rules.recovery.halfOpen': '半开试航参数;maxProbes 同时是主动探测每模型每周期预算',
831
- 'circuitBreaker.rules.recovery.halfOpen.maxProbes': '半开并发探测预算(默认=halfOpenMaxProbes 1;下限 1——0 会饿死恢复通道)',
832
- 'circuitBreaker.rules.recovery.halfOpen.successThreshold': '半开恢复所需成功探测数(默认 1=首成即闭;封顶 maxProbes)',
833
- 'circuitBreaker.rules.recovery.halfOpen.maxWaitMs': '半开最长停留时间(毫秒,默认 0=永久等待,现行);超时按 onCanaryFailure 去向处理',
834
- 'circuitBreaker.shadow': '影子模式:规则照常评估、照常熔断记录/快照/事件(试航槽、阶梯、窗口全部真实推进),但 canExecute/peek 绝不拦流量;手动 OPEN、DISABLED、SUSPECT 不受影子豁免;用于上线前验证规则',
835
- 'circuitBreaker.persistence': '熔断状态落盘策略',
836
- 'circuitBreaker.persistence.debounceMs': 'breaker-state 文件写入去抖间隔(毫秒,默认 1000;崩溃丢失窗口即此去抖时长)',
837
- retry: '重试策略',
838
- 'retry.inplace': '原地重试(同一模型)',
839
- 'retry.inplace.maxAttempts': '额外重试次数',
840
- 'retry.inplace.backoffMs': '重试基础退避(毫秒)',
841
- 'retry.inplace.jitterMs': '退避随机抖动(毫秒)',
842
- 'retry.inplace.retryOnCauses': '触发重试的错误类型',
843
- 'retry.inplace.maxRateLimitWaitMs': '429 Retry-After 最大等待(毫秒)',
844
- 'retry.failover': '故障转移(切换候选模型重试)',
845
- 'retry.failover.maxAttempts': '故障转移尝试次数',
846
- 'retry.failover.tierCrossPolicy': '跨梯队策略:allow_escalate 允许向上升级',
847
- rateLimit: '限流策略开关(窗口本身在 apiKeys[].limits 与 credentials: 叠加层)',
848
- 'rateLimit.persist': '已触发限流事件账本的持久化:写入 traces.db(与 trace/FinOps 共库独立句柄),重启后 /rate-limit 页仍可回看上一次的触发历史;观测性写入 fail-open,永不阻塞请求路径',
849
- 'rateLimit.persist.enabled': '账本持久化开关(默认开);关闭=仅内存环(重启清零)',
850
- 'rateLimit.inboundGraceMs': '宽限等待(毫秒,默认 1000,上限 2000,0=关闭):客户端密钥窗口满、但重开等待不超过该值时,网关原地等待窗口重开后复查一次(不循环),复查仍满或等待超限才回 429 + Retry-After——吸收亚秒级突发,避免短限流变成用户可见错误;长窗口维持快速失败:限流契约不变,等待归属客户端自己的退避',
851
- apiKeys: '客户端接入密钥(sk-ocr-*,见 /keys 页);每个密钥可配 limits=入站滑动窗口限流,规则项 { window, requests | tokens | costUsd }(window 用时长语法 30s/5m/1h/1d;同一项可写多个维度=各自独立计数;任一窗口满即拒——宽限等待内(rateLimit.inboundGraceMs)先原地等满复查一次,否则 429 + Retry-After;被拒请求不计入窗口;保存即时生效);requests 维度覆盖全部四条推理线(前向代理 MITM 腿不经该入口、不入站计量);tokens/costUsd 在 chat 形态线(chat/messages/responses)与 systemone 决策线均于完成时记账(决策线以协议 usage 为准,上游未带 usage 的 native 应答只计 requests)',
852
- credentials: '模型凭证限流叠加层(原始 YAML 页编辑,保存即时生效):按 provider id 分组,每项 { keyHashPrefix, limits } —— keyHashPrefix 是该凭据 sha256 的前 12 位(控制台凭据卡片可见,与凭证增删改名无关;大小写不敏感——编译/匹配时归一,磁盘保留原文);limits 规则语法同 apiKeys(滑动窗口;requests=请求数、tokens=消耗 token 数、costUsd=费用美元,按完成时刻记账);出站限流只做整形:超限凭证在 NEW 会话选号时跳过、绝不改动已绑定会话(重绑会烧上游提示缓存)、候选耗尽时末位强制放行,真正的上游 429 仍由熔断器处理决策线例外:/v1/systemone 不经候选池——不做本地跳过/拒绝、也不经熔断,上游错误逐字透传;但该线的出站 dispatch 与完成记账照常计入,凭证窗口会被它填充。内部腿(L2 决策、健康探测)的上游调用不经任何记账,不会填充窗口',
853
- 'credentials.*': '该 provider 的凭证规则列表(键=provider id,如 anthropic);条目 { keyHashPrefix, limits }',
854
- quota: '额度探测调度:额度覆盖表与代码 adapter 随 release 内置,此处只调调度器;凭据出现即自动探测(激活随凭据),探测失败≠额度失败——保留旧值置 stale,绝不触发熔断/下架;声明上限只展示、不门控路由',
855
- 'quota.enabled': '额度探测总开关(默认 true);false = 停止一切出网额度探测(已存快照仍可展示,标注 stale 逻辑不变)',
856
- 'quota.intervalMs': '调度 tick(毫秒,默认 60000,钳制 [10000, 3600000]);每条目另有 cacheTtl 钳制 [60s, 24h] 的到期窗口 + 抖动,429 触发引擎级全局退避(非条目字段)',
857
- quotaProbes: '自定义额度探测(长尾/自建网关,原始 YAML 页编辑,保存即时生效):按 provider id 分组,条目 { url, windows, headers?, cacheTtlMs?, successIf?, override?, forkedFrom?, verifiedAt? } —— 铁律(仅约束本层):url 只写相对路径且解析后必须落在该 provider 推理 baseURL 的 origin 内(拒 ../ / / 协议头);认证固定复用推理同款 Bearer(需拼装/换 scheme/派生头的服务商走内置代码 adapter,不进本表);GET-only;1 条目=1 URL;覆盖内置条目必须显式 override: <内置条目 id>(静默遮蔽被拒加载),fork 条目带 forkedFrom+verifiedAt 血统戳。windows 声明式抽取(12 构件:static/each/eachObject 三形态、firstOf、used/total/remaining 二推三、invert、scale、where 仅限存在/相等/∈、名称模板+枚举映射、静态 headers、successIf 单等值、unlimited、headers 取数、秒/毫秒/ISO 时间判别;算术/跨调用注入/值比较/正则/时间差/按URL反义/头值插值 七类禁例出现即整条拒绝加载并在控制台额度页显示原因)',
858
- 'quotaProbes.*': '该 provider 的探测条目数组(键=provider id,如 my-gateway);每条目一张窗口表:windows { form: static|each|eachObject, path?, window|windows, plan? } —— 字段抽取 { path | header | literal, firstOf?, scale?, invertOf?, time? };used/total/remaining 任二者可推第三;where 仅限存在/相等/∈ 三谓词;名称 nameSpec { from, enumMap, fallback } 或 template 纯插值({field});successIf 单等值',
859
- opencode: 'OpenCode 本地服务连接',
860
- proxy: '出站代理策略(保存后即时生效,无需重启;作用于上游模型调用 / Layer2 判定 / 目录与 logo 同步;localhost/127.0.0.1 永不走代理)',
861
- 'proxy.enabled': '出站代理总开关(默认 false 不启用;true 时按 url 与包含/排除规则出站)',
862
- 'proxy.url': '全局代理 URL,http(s)://[user:pass@]host:port —— 需要鉴权时把用户名:密码嵌在 @ 前(自动转为 Proxy-Authorization,含 HTTPS CONNECT 隧道;特殊字符需 URL 编码);留空 = 直连',
863
- 'proxy.includes': '包含规则(glob):非空时仅命中者走代理;pattern 匹配 provider/model 组合与模型 id —— anthropic/* 为 provider 级,*/claude-* 或 claude-* 为模型级',
864
- 'proxy.excludes': '排除规则(glob):命中者强制直连;与 includes 同设时先执行(excludes 命中 = 直连,其余再按 includes 过滤)',
865
- forwardProxy: '入站前向代理(HTTP_PROXY/HTTPS_PROXY 服务端):默认全量接管——解密后的 LLM 协议流量(chat/messages/responses)走路由管线,其余透明转发;loopback 与 bypassHosts 命中者纯隧道透传;需在被代理客户端信任导出的 CA(重启网关生效)',
866
- 'forwardProxy.enabled': '入站代理总开关(默认 false)',
867
- 'forwardProxy.port': '代理监听端口(默认 4555;客户端 HTTP_PROXY/HTTPS_PROXY 指向 http://127.0.0.1:4555)',
868
- 'forwardProxy.host': '代理监听地址(默认 127.0.0.1,仅本机)',
869
- 'forwardProxy.bypassHosts': '例外主机(glob):纯字符串 = 直连隧道;{ host, viaProxy: true } = 经出站代理隧道(逐主机勾选);loopback 永远绕过',
870
- 'forwardProxy.caDir': 'MITM CA 存放目录(默认 ~/.omnicell-router/forward-proxy)',
871
- 'forwardProxy.viaOutboundProxy': '非例外主机的转发请求(未被拦截接管的 GET 等)是否经出站代理;例外主机的出站方式在 bypassHosts 逐行勾选',
872
- compression: 'Token 压缩(rtk 工具输出压缩 + headroom 上下文压缩 + caveman 输出风格注入;全部失败时放行原文,重启网关生效)',
873
- 'compression.rtk.enabled': 'rtk 工具输出压缩:git/grep/ls/tree/日志/构建输出等工具结果文本压缩 60-90%(本地确定性压缩器,不破坏上游前缀缓存)',
874
- 'compression.headroom.enabled': 'headroom 上下文压缩:转发前调用 headroom sidecar 的 /v1/compress(失败/超时自动放行原文;会话模式保上游前缀缓存)',
875
- 'compression.headroom.url': 'headroom sidecar 地址(需自行运行 headroom proxy,默认 127.0.0.1:8787,仅本机回环)',
876
- 'compression.headroom.timeoutMs': 'headroom 调用超时(毫秒,超时放行原文)',
877
- 'compression.headroom.compressUserMessages': '同时压缩 user 角色文本(会话模式下自动忽略)',
878
- 'compression.headroom.autoStart': '网关启动时自动拉起 headroom sidecar(先探测 /health 复用已在运行的实例,没有才以分离进程启动 headroom proxy --mode cache;仅支持 loopback 地址;sidecar 独立常驻、不随网关退出,会话重放状态跨网关重启保留)',
879
- 'compression.caveman.enabled': 'caveman 输出压缩:向 system 幂等注入简洁风格提示词,显著压缩输出 token(代码/路径/命令逐字保留)',
880
- 'compression.caveman.level': 'caveman 强度:lite / full / ultra / wenyan-lite / wenyan / wenyan-ultra(文言)',
881
- requestCapture: '请求全量捕获(HTTP 交换审计日志;默认关闭):请求/响应原文落盘 JSONL,捕获体可能含敏感数据且占用磁盘,按日期目录保留、到期或超容量自动清理;单会话另有 maxSessionMB 封顶(失控的 agent 循环不会吃光共享容量,触顶档案停止追加并落一条 archive-overflow 终态行)',
882
- 'requestCapture.storeMedia': 'base64 图片/文档等二进制载荷转存硬盘(默认 true):请求体中的 base64 媒体替换为 [MEDIA …sha256=… file=media/…] 占位符,内容寻址去重(同一张图多轮重发只落一份),随日期目录同批清理;关闭或写盘失败时仍替换为无 file= 的占位符(不留 base64 在归档里),对话回放页可直接显示缩略图',
883
- catalog: '目录数据源:远程 catalog 源定义与本地锚定(控制台 /catalog 页可视化编辑,改后即时生效)',
884
- 'catalog.syncIntervalMs': '目录自动同步周期(毫秒,默认 86400000 = 24h)',
885
- 'catalog.lockedModels': '本地锚定的模型 id 列表:这些模型的本地定义值(含 0 价)不被任何远程源覆盖',
886
- 'catalog.autoPullModels': '自动拉取总开关:每个同步周期为自定义服务商拉取模型清单(live /v1/models 优先,只新增不覆盖;默认 true)。注意:按服务商需在 catalog.autoPullPatterns 中声明才会真正拉取',
887
- 'catalog.autoPullPatterns': '按服务商的自动拉取白名单:仅声明的服务商才会被定时拉取,且只拉取匹配 glob 的模型 id(逗号分隔多模式,如 zhipu/glm-*);未声明的服务商完全不自动拉取,控制台手动拉取不受影响。热生效',
888
- 'catalog.autoPullPatterns.*': '该服务商的自动拉取 glob:只拉取匹配的模型 id(逗号分隔多模式,如 zhipu/glm-*,openai/*, anthropic/*);留空/删除该条目即停止自动拉取该服务商',
889
- combos: '自定义模型组合(combo):把若干已注册模型组成一个虚拟模型名,客户端直接以 combo id 作为 model 调用(控制台 /combos 页可视化编辑,保存后即时生效,无需重启)',
890
- 'combos.*.selection': '主选策略:priority 配置顺序(默认)/ weighted 加权随机 / round_robin 轮询',
891
- 'combos.*.disabled': '禁用开关:true 时该组合下线——不再出现在模型目录(不可选),客户端以该组合 id 调用会被直接拒绝(不可用);控制台仍可查看并重新启用',
892
- 'combos.*.models': '成员列表(顺序即故障转移链序):成员可写 \'model-id\' 或 { id, weight }(weight 用于 weighted/round_robin,默认 1)',
893
- 'combos.*.note': '备注:仅控制台展示的自由文本,不参与路由',
894
- modelProfiles: '模型方案:一张「槽位 → 模型引用(modelRef)」命名表,与具体客户端无关。客户端挂接(应用)时选择方案,把各 agent/subagent 绑定到槽位,一次写入全部模型(控制台 /model-profiles 页可视化编辑;方案本身不参与路由,仅在应用时把 modelRef 写进客户端自身配置)',
895
- 'modelProfiles.*.id': '方案 id(唯一,供客户端挂接引用)',
896
- 'modelProfiles.*.name': '方案显示名',
897
- 'modelProfiles.*.slots': '槽位表:槽位名 → modelRef(注册模型 id / 组合 id / auto / lite / plus / pro / ultra)',
898
- 'modelProfiles.*.note': '备注:仅控制台展示的自由文本,不参与路由',
899
- clientProfileMemory: '控制台表单记忆(按环境保存):各客户端挂接表单上次选择的模型方案、槽位映射与模型列表模式(none=不设置(默认)/ custom=自定义 / follow=跟随所选 API Key 的权限),以及上次写入的 API Key id(apiKeyId;挂接总是写入所选 Key,不存明文),仅用于页面回填,不参与路由、也不影响实际接管配置',
900
- defaultModels: '默认模型(网关自身内部调用花费的模型,不参与客户端路由)',
901
- 'defaultModels.translation': '控制台内部翻译(技能描述/README)使用的模型:填写网关可见的 modelRef(档位别名 lite/plus/pro/ultra 或已注册模型 id)。未设置 = lite;配置的模型失败降级到 lite,lite 也失败则如实报错——链条绝不自行升级到 auto(内部非关键调用不允许无上限花费;显式写 auto 视为运营者自担成本,照常生效)。可解析性在请求时校验(模型在启动时才注册);更换该值不使已缓存翻译失效(缓存按原文+语言键控,为派生数据)',
902
- session: '会话粘性(棘轮:会话内模型不漂移)',
903
- 'session.strategy': '会话策略:monotonic 单调棘轮 / sticky 粘性 / stateless 无状态',
904
- 'session.ttlSeconds': '会话保持时长(秒)',
905
- 'session.maxSessions': '会话表容量上限',
906
- streaming: '推理流式(上游 SSE 逐帧转发,而非整段缓冲后再分块)',
907
- 'streaming.enabled': '默认 true。仅对具备流式执行器的线型生效(当前为 OpenAI chat/completions;Anthropic/Google/Responses 仍走缓冲路径)。Schema 断言级联中,lite 冲锋腿始终缓冲(正文先过本地断言、可能整轮作废重问);断言失败后的升档终答腿与直连路径一样照常流式。置 false 为回滚开关:上述全部恢复"上游非流式 + 网关重新分块"的旧行为,客户端首字节时间重新等于上游整段生成时间。修改后需重启生效',
908
- responses: 'Responses 协议面(POST /v1/responses):网关侧 previous_response_id 会话链',
909
- 'responses.persist': '会话链磁盘恢复(默认 false):开启后每轮增量以 JSONL 恢复日志写入本环境数据目录(文件权限 0600),启动时自动重放,24 小时过期自动清理——网关重启后长对话仍可续接;关闭时重启即断链(返回 400,客户端需重发完整 input)。日志含对话原文,属敏感数据落盘,与请求捕获(requestCapture)同级隐私考量;磁盘写入失败绝不影响请求本身',
910
- };
911
- function lookupYamlComment(path) {
912
- const direct = YAML_FIELD_COMMENTS[path];
913
- if (direct !== undefined)
914
- return direct;
915
- const segs = path.split('.');
916
- // Dynamic map level: tiers.<name>[.field…] → tiers.*[…]
917
- if (segs[0] === 'tiers' && segs.length >= 2) {
918
- segs[1] = '*';
919
- return YAML_FIELD_COMMENTS[segs.join('.')];
920
- }
921
- // Dynamic map level: combos.<comboId>.<field…> → combos.*.<field…>
922
- if (segs[0] === 'combos' && segs.length >= 3) {
923
- return YAML_FIELD_COMMENTS[`combos.*.${segs.slice(2).join('.')}`];
924
- }
925
- // Dynamic map level: credentials.<providerId> → credentials.*
926
- if (segs[0] === 'credentials' && segs.length >= 2) {
927
- return YAML_FIELD_COMMENTS['credentials.*'];
928
- }
929
- // Dynamic map level: catalog.autoPullPatterns.<providerId> → catalog.autoPullPatterns.*
930
- if (segs[0] === 'catalog' && segs[1] === 'autoPullPatterns' && segs.length >= 3) {
931
- return YAML_FIELD_COMMENTS['catalog.autoPullPatterns.*'];
932
- }
933
- // Dynamic array level: modelProfiles.<index>.<field…> → modelProfiles.*.<field…>
934
- if (segs[0] === 'modelProfiles' && segs.length >= 3) {
935
- return YAML_FIELD_COMMENTS[`modelProfiles.*.${segs.slice(2).join('.')}`];
936
- }
937
- return undefined;
938
- }
939
- function applyYamlComments(node, prefix) {
940
- if (!node || typeof node !== 'object' || !Array.isArray(node.items))
941
- return;
942
- for (const pair of node.items) {
943
- const keyNode = pair?.key;
944
- const keyName = keyNode?.value != null ? String(keyNode.value) : null;
945
- if (!keyName)
946
- continue;
947
- const fieldPath = prefix ? `${prefix}.${keyName}` : keyName;
948
- const comment = lookupYamlComment(fieldPath);
949
- if (comment)
950
- keyNode.commentBefore = padComment(comment);
951
- // Recurse into plain mappings only; sequences (models/apiKeys/weights…) are
952
- // documented at their key — per-item comments would drown the file.
953
- if (isMap(pair.value))
954
- applyYamlComments(pair.value, fieldPath);
955
- }
956
- }
957
- /** Attach file header + per-field comments; returns input untouched if it can't be parsed as a mapping. */
958
- export function annotateYamlComments(yamlText) {
959
- const doc = parseDocument(yamlText);
960
- if (doc.errors.length > 0 || !isMap(doc.contents))
961
- return yamlText;
962
- if (!doc.commentBefore)
963
- doc.commentBefore = padComment(YAML_FILE_HEADER);
964
- applyYamlComments(doc.contents, '');
965
- return doc.toString();
966
- }