@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107

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 (465) hide show
  1. package/bin/ocx.mjs +215 -20
  2. package/gui/dist/assets/App-6TFtZsUF.css +1 -0
  3. package/gui/dist/assets/App-B8_sOxoz.js +59 -0
  4. package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
  5. package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
  6. package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
  7. package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
  8. package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
  9. package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
  10. package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
  11. package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
  12. package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
  13. package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
  14. package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
  15. package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
  16. package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
  17. package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
  18. package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
  19. package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
  20. package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
  21. package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
  22. package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
  23. package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
  24. package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
  25. package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
  26. package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
  27. package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
  28. package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
  29. package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
  30. package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
  31. package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
  32. package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
  33. package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
  34. package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
  35. package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
  36. package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
  37. package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
  38. package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
  39. package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
  40. package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
  41. package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
  42. package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
  43. package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
  44. package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
  45. package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
  46. package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
  47. package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
  48. package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
  49. package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
  50. package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
  51. package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
  52. package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
  53. package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
  54. package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
  55. package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
  56. package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
  57. package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
  58. package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
  59. package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
  60. package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
  61. package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
  62. package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
  63. package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
  64. package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
  65. package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
  66. package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
  67. package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
  68. package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
  69. package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
  70. package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
  71. package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
  72. package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
  73. package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
  74. package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
  75. package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
  76. package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
  77. package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
  78. package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
  79. package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
  80. package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
  81. package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
  82. package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
  83. package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
  84. package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
  85. package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
  86. package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
  87. package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
  88. package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
  89. package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
  90. package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
  91. package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
  92. package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
  93. package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
  94. package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
  95. package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
  96. package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
  97. package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
  98. package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  99. package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  100. package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  101. package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  102. package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  103. package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  104. package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  105. package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  106. package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  107. package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  108. package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  109. package/gui/dist/assets/index-5REODpG3.css +2 -0
  110. package/gui/dist/assets/index-BWKBeK77.js +94 -0
  111. package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
  112. package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
  113. package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
  114. package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
  115. package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
  116. package/gui/dist/classic/index.html +47 -0
  117. package/gui/dist/favicon.png +0 -0
  118. package/gui/dist/favicon.svg +14 -0
  119. package/gui/dist/index.html +15 -2
  120. package/package.json +1 -1
  121. package/src/adapters/anthropic.ts +17 -8
  122. package/src/adapters/command-code.ts +15 -16
  123. package/src/adapters/cursor/transport-retry.ts +2 -2
  124. package/src/adapters/devin/cloud-direct/chat.ts +15 -6
  125. package/src/adapters/google.ts +7 -7
  126. package/src/adapters/kiro/adapter.ts +18 -3
  127. package/src/adapters/kiro/conversation.ts +8 -8
  128. package/src/adapters/kiro/payload.ts +45 -12
  129. package/src/adapters/kiro/stream.ts +230 -14
  130. package/src/adapters/kiro/structured-output-json.ts +191 -0
  131. package/src/adapters/kiro/structured-output-schema.ts +542 -0
  132. package/src/adapters/kiro/structured-output.ts +367 -0
  133. package/src/adapters/kiro-constants.ts +24 -1
  134. package/src/adapters/kiro-events.ts +31 -1
  135. package/src/adapters/kiro-retry.ts +3 -3
  136. package/src/adapters/kiro-tools.ts +14 -9
  137. package/src/adapters/kiro-wire.ts +9 -5
  138. package/src/adapters/ollama-native.ts +11 -1
  139. package/src/adapters/openai-chat/messages.ts +58 -5
  140. package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
  141. package/src/adapters/openai-chat/passthrough.ts +5 -3
  142. package/src/adapters/openai-chat/tool-schema.ts +83 -13
  143. package/src/adapters/openai-responses/empty-assistant.ts +15 -3
  144. package/src/adapters/openai-responses/opengateway-input.ts +18 -6
  145. package/src/adapters/openai-responses/passthrough.ts +5 -4
  146. package/src/adapters/openai-responses/reasoning.ts +9 -4
  147. package/src/adapters/openai-responses/request-strips.ts +1 -1
  148. package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
  149. package/src/adapters/physical-send.ts +3 -3
  150. package/src/adapters/qoder/live-models.ts +115 -1
  151. package/src/adapters/zed-openai-stream.ts +2 -1
  152. package/src/bridge/errors.ts +11 -2
  153. package/src/bridge/response-json.ts +2 -1
  154. package/src/bridge/sse.ts +14 -6
  155. package/src/chat/failure-verdict.ts +21 -0
  156. package/src/chat/outbound.ts +139 -21
  157. package/src/claude/failure-verdict.ts +21 -0
  158. package/src/claude/inbound-content-options.ts +15 -2
  159. package/src/claude/inbound-model-options.ts +2 -1
  160. package/src/claude/inbound-records.ts +2 -0
  161. package/src/claude/inbound.ts +17 -11
  162. package/src/claude/outbound.ts +98 -22
  163. package/src/cli/capabilities-access-remote.ts +13 -0
  164. package/src/cli/capabilities-base.ts +26 -3
  165. package/src/cli/capabilities-command.ts +12 -3
  166. package/src/cli/capabilities-provider-models.ts +3 -3
  167. package/src/cli/capability-contracts.ts +2 -0
  168. package/src/cli/codex-launch-auth.ts +30 -1
  169. package/src/cli/codex-launcher.ts +12 -5
  170. package/src/cli/codex-shim-autorestore.ts +12 -4
  171. package/src/cli/config-command.ts +11 -2
  172. package/src/cli/connect.ts +17 -2
  173. package/src/cli/dispatch.ts +14 -177
  174. package/src/cli/doctor.ts +95 -7
  175. package/src/cli/help.ts +2 -2
  176. package/src/cli/index.ts +17 -8
  177. package/src/cli/link-apply-restart.ts +9 -2
  178. package/src/cli/link.ts +1 -1
  179. package/src/cli/models.ts +124 -38
  180. package/src/cli/registry.ts +12 -4
  181. package/src/cli/restart-failure.ts +17 -0
  182. package/src/cli/root.ts +8 -0
  183. package/src/cli/stop-approval.ts +2 -2
  184. package/src/cli/sync-command.ts +243 -0
  185. package/src/cli/sync-fanout-process.ts +92 -0
  186. package/src/cli/sync-fanout.ts +161 -0
  187. package/src/cli/sync-flags.ts +10 -0
  188. package/src/cli/sync-link-status.ts +39 -0
  189. package/src/cli/sync-update-guard.ts +18 -0
  190. package/src/cli/system-restart-client.ts +5 -0
  191. package/src/cli/uninstall-client-state.ts +12 -1
  192. package/src/cli/update-restart-child.ts +13 -3
  193. package/src/cli/update-restart-home.ts +6 -3
  194. package/src/cli/update-restart.ts +36 -19
  195. package/src/client/connect.ts +35 -15
  196. package/src/client/hub-client.ts +5 -0
  197. package/src/client/link-home.ts +3 -2
  198. package/src/client/link-management-relay.ts +39 -2
  199. package/src/client/link-readiness.ts +3 -1
  200. package/src/client/machine-api.ts +2 -1
  201. package/src/client/machine-listener.ts +10 -0
  202. package/src/client/orphan-token-recovery.ts +322 -0
  203. package/src/client/restore-ownership.ts +19 -1
  204. package/src/client/runtime-restart.ts +12 -4
  205. package/src/client/runtime.ts +40 -11
  206. package/src/client/stop-routing.ts +62 -0
  207. package/src/client/sync-runtime.ts +65 -0
  208. package/src/clients/config-export.ts +32 -3
  209. package/src/codex/auth-context.ts +49 -103
  210. package/src/codex/catalog/antigravity-discovery.ts +16 -5
  211. package/src/codex/catalog/provider-models.ts +18 -12
  212. package/src/codex/forward-transport-headers.ts +35 -6
  213. package/src/codex/inject/config-toml.ts +88 -0
  214. package/src/codex/inject/multi-agent-v2.ts +30 -4
  215. package/src/codex/inject/plan.ts +34 -7
  216. package/src/codex/inject-coordination.ts +11 -0
  217. package/src/codex/inject.ts +18 -7
  218. package/src/codex/lineage.ts +13 -7
  219. package/src/codex/native-profile-api.ts +27 -1
  220. package/src/codex/quota.ts +22 -6
  221. package/src/codex/request-owned-affinity-key.ts +11 -0
  222. package/src/codex/request-owned-affinity.ts +118 -0
  223. package/src/codex/request-owned-main-pin.ts +86 -0
  224. package/src/codex/role-capability.ts +52 -41
  225. package/src/codex/routing/active-account.ts +13 -5
  226. package/src/codex/routing/selection.ts +40 -1
  227. package/src/codex/routing/thread-affinity-store.ts +916 -0
  228. package/src/codex/routing/thread-affinity.ts +90 -12
  229. package/src/codex/shim-diagnostics.ts +7 -0
  230. package/src/codex/shim-legacy-record.ts +290 -0
  231. package/src/codex/shim-windows-refresh.ts +9 -2
  232. package/src/codex/shim-wrapper-write.ts +7 -0
  233. package/src/codex/shim.ts +80 -21
  234. package/src/codex/toml-source-lines.ts +72 -13
  235. package/src/combos/failover.ts +6 -109
  236. package/src/combos/request.ts +2 -2
  237. package/src/combos/resolve.ts +29 -11
  238. package/src/config/diagnostics.ts +9 -9
  239. package/src/config/load-degrade.ts +27 -27
  240. package/src/config/process-state.ts +5 -0
  241. package/src/config/provider-validation.ts +9 -2
  242. package/src/config/removed-opencode-free-backup.ts +6 -3
  243. package/src/config/schema/leaf-validators.ts +1 -0
  244. package/src/config/tracked-runtime-inspection.ts +3 -3
  245. package/src/generated/compatibility-version.json +595 -255
  246. package/src/images/loop.ts +4 -3
  247. package/src/lib/client-error-body.ts +215 -0
  248. package/src/lib/client-retry-after.ts +66 -0
  249. package/src/lib/config-ownership-removal.ts +422 -0
  250. package/src/lib/config-ownership.ts +650 -81
  251. package/src/lib/context-overflow-verdict.ts +113 -0
  252. package/src/lib/crash-guard.ts +4 -2
  253. package/src/lib/desktop-cli-handoff.d.mts +4 -5
  254. package/src/lib/desktop-cli-handoff.mjs +18 -17
  255. package/src/lib/empty-tool-catalog.ts +25 -3
  256. package/src/lib/error-destination.ts +47 -0
  257. package/src/lib/errors.ts +1 -0
  258. package/src/lib/failure-detail.ts +66 -0
  259. package/src/lib/local-management-capability.ts +3 -1
  260. package/src/lib/messages-error-body.ts +162 -0
  261. package/src/lib/messages-sse-error-presentation.ts +93 -0
  262. package/src/lib/model-identity.ts +44 -0
  263. package/src/lib/passive-read.ts +9 -4
  264. package/src/lib/private-sqlite-path.ts +124 -0
  265. package/src/lib/response-service-tier.ts +17 -0
  266. package/src/lib/retry-after.ts +3 -0
  267. package/src/lib/socks5-fetch.ts +21 -9
  268. package/src/lib/spend-ledger-owner.ts +43 -4
  269. package/src/lib/upstream-condition.ts +142 -0
  270. package/src/lib/upstream-retry.ts +95 -12
  271. package/src/lib/windows-owner-acl.ts +22 -9
  272. package/src/lib/winsw.ts +5 -5
  273. package/src/lib/workflow-budget.ts +3 -1
  274. package/src/link/remote-platform.ts +14 -0
  275. package/src/link/remote-windows.ts +51 -9
  276. package/src/link/ssh-argv.ts +63 -10
  277. package/src/oauth/generic-account-failover.ts +13 -11
  278. package/src/oauth/index.ts +42 -73
  279. package/src/oauth/oauth-errors.ts +67 -0
  280. package/src/oauth/store.ts +21 -11
  281. package/src/protocols/codecs/messages-ir.ts +15 -9
  282. package/src/protocols/codecs/ollama.ts +197 -0
  283. package/src/protocols/encoders/adapter-events.ts +30 -7
  284. package/src/protocols/encoders/chat.ts +18 -10
  285. package/src/protocols/encoders/messages.ts +72 -28
  286. package/src/protocols/trace.ts +18 -0
  287. package/src/providers/antigravity-models.ts +45 -12
  288. package/src/providers/fastwire.ts +3 -2
  289. package/src/providers/free-directory.ts +2 -2
  290. package/src/providers/quota/anthropic-usage-windows.ts +13 -3
  291. package/src/providers/quota/vendor-probes-key.ts +60 -24
  292. package/src/providers/reasoning-metadata.ts +2 -1
  293. package/src/providers/registry/entries-extended.ts +9 -0
  294. package/src/providers/request-pacing.ts +3 -2
  295. package/src/reasoning-effort.ts +7 -2
  296. package/src/remote/hub-usage.ts +3 -0
  297. package/src/responses/apply-patch-envelope.ts +45 -19
  298. package/src/responses/compaction-history-framing.ts +5 -1
  299. package/src/responses/freeform-wrapper-scan.ts +5 -3
  300. package/src/responses/progressive-freeform-input.ts +354 -45
  301. package/src/routing/fallback-policy.ts +3 -1
  302. package/src/server/admission-model-scope.ts +17 -6
  303. package/src/server/admitted-http-turn.ts +57 -0
  304. package/src/server/anthropic-rate-limit-headers.ts +75 -3
  305. package/src/server/auth-cors.ts +5 -0
  306. package/src/server/chat-completions.ts +45 -20
  307. package/src/server/chat-native-sse.ts +52 -7
  308. package/src/server/chat-native.ts +60 -35
  309. package/src/server/claude-bridge-pool-session.ts +59 -0
  310. package/src/server/claude-messages.ts +174 -84
  311. package/src/server/context-history.ts +5 -1
  312. package/src/server/gui-static.ts +4 -1
  313. package/src/server/hub-usage.ts +7 -2
  314. package/src/server/inbound-body-admission.ts +11 -4
  315. package/src/server/index/link-management.ts +8 -0
  316. package/src/server/index/ollama-routes.ts +91 -0
  317. package/src/server/index/serve-options.ts +44 -24
  318. package/src/server/index/startup-warnings.ts +5 -12
  319. package/src/server/index/websocket-handler.ts +5 -2
  320. package/src/server/index.ts +6 -36
  321. package/src/server/inference/client-encoder-delivery.ts +9 -3
  322. package/src/server/json-serialized-bytes.ts +44 -0
  323. package/src/server/management/agent-settings-routes.ts +24 -21
  324. package/src/server/management/codex-cli-update-routes.ts +2 -1
  325. package/src/server/management/logs-usage-routes.ts +89 -4
  326. package/src/server/management/provider-routes.ts +2 -22
  327. package/src/server/management/qoder-provider-probe.ts +105 -0
  328. package/src/server/management/route-registry.ts +4 -1
  329. package/src/server/management/usage-aggregate-cache.ts +15 -5
  330. package/src/server/management/usage-source-facets.ts +38 -0
  331. package/src/server/messages-native-scope.ts +2 -1
  332. package/src/server/messages-native-tool-guard.ts +12 -4
  333. package/src/server/messages-native.ts +123 -47
  334. package/src/server/messages-response-headers.ts +25 -11
  335. package/src/server/messages-shared.ts +99 -65
  336. package/src/server/messages-sse-error-filter.ts +199 -0
  337. package/src/server/native-final-log.ts +93 -0
  338. package/src/server/ollama-inbound.ts +349 -0
  339. package/src/server/ollama-native-paths.ts +21 -0
  340. package/src/server/ollama-route-policy.ts +73 -0
  341. package/src/server/relay.ts +22 -3
  342. package/src/server/request-decompress.ts +4 -2
  343. package/src/server/request-log-failure-attribution.ts +22 -0
  344. package/src/server/request-log-failure-detail.ts +80 -0
  345. package/src/server/request-log-terminal-status.ts +4 -2
  346. package/src/server/request-log.ts +91 -42
  347. package/src/server/response-log-body.ts +6 -1
  348. package/src/server/responses/account-change-state.ts +17 -6
  349. package/src/server/responses/adapter-continuation.ts +17 -6
  350. package/src/server/responses/adapter-delivery.ts +17 -10
  351. package/src/server/responses/adapter-dispatch.ts +32 -31
  352. package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
  353. package/src/server/responses/codex-auth-error.ts +24 -19
  354. package/src/server/responses/codex-ws-exchange.ts +11 -8
  355. package/src/server/responses/codex-ws-metadata.ts +94 -21
  356. package/src/server/responses/codex-ws-request.ts +3 -1
  357. package/src/server/responses/codex-ws-wire.ts +19 -3
  358. package/src/server/responses/compact.ts +57 -24
  359. package/src/server/responses/compaction-recovery.ts +4 -2
  360. package/src/server/responses/compaction-routing.ts +9 -4
  361. package/src/server/responses/core-auth.ts +32 -14
  362. package/src/server/responses/core-codex-account.ts +17 -6
  363. package/src/server/responses/core-combo-failure.ts +7 -1
  364. package/src/server/responses/core-combo-native.ts +2 -1
  365. package/src/server/responses/core-combo.ts +43 -27
  366. package/src/server/responses/core-errors.ts +24 -21
  367. package/src/server/responses/core-lifetime.ts +6 -3
  368. package/src/server/responses/core-normalize.ts +1 -0
  369. package/src/server/responses/core-options.ts +9 -0
  370. package/src/server/responses/core-pipeline.ts +4 -3
  371. package/src/server/responses/empty-completion-guard.ts +4 -1
  372. package/src/server/responses/fetch-helpers.ts +7 -1
  373. package/src/server/responses/input-admission.ts +28 -2
  374. package/src/server/responses/native-injection.ts +1 -1
  375. package/src/server/responses/native-response-json.ts +13 -4
  376. package/src/server/responses/native-response-output.ts +1 -2
  377. package/src/server/responses/non-replayable-error.ts +2 -1
  378. package/src/server/responses/pacing-overload.ts +3 -2
  379. package/src/server/responses/passthrough-delivery.ts +55 -14
  380. package/src/server/responses/passthrough-dispatch.ts +20 -18
  381. package/src/server/responses/passthrough-error.ts +9 -9
  382. package/src/server/responses/policy-fallback.ts +2 -1
  383. package/src/server/responses/request-prepare.ts +69 -48
  384. package/src/server/responses/request-transport.ts +36 -31
  385. package/src/server/responses/response-effects.ts +3 -2
  386. package/src/server/responses/run-turn-execution.ts +6 -6
  387. package/src/server/responses/sidecar-execution.ts +16 -12
  388. package/src/server/responses/spend-storage-error.ts +2 -1
  389. package/src/server/responses/terminal-guard.ts +30 -0
  390. package/src/server/responses/ws-upstream.ts +9 -0
  391. package/src/server/responses-custom-tool-repair.ts +14 -3
  392. package/src/server/responses-terminal-repair.ts +5 -2
  393. package/src/server/responses-undeclared-tool-guard.ts +39 -16
  394. package/src/server/restart-replacement.ts +3 -1
  395. package/src/server/safe-response-headers.ts +162 -13
  396. package/src/server/sse-payload-rewrite.ts +23 -11
  397. package/src/server/turn-state-handles.ts +164 -0
  398. package/src/server/workflow-refusal.ts +2 -1
  399. package/src/server/ws-bridge.ts +4 -0
  400. package/src/service/definition.ts +36 -4
  401. package/src/service/launchd.ts +89 -32
  402. package/src/service/logging.ts +34 -7
  403. package/src/service/ownership-mutation-lease.d.mts +11 -2
  404. package/src/service/ownership-mutation-lease.mjs +53 -11
  405. package/src/service/plist-xml.ts +59 -0
  406. package/src/service/state.ts +8 -0
  407. package/src/service/systemd-env.ts +2 -0
  408. package/src/service/systemd.ts +31 -7
  409. package/src/service/windows-taskxml.ts +16 -7
  410. package/src/service-manager-probe.ts +4 -10
  411. package/src/types/config.ts +2 -0
  412. package/src/types/provider.ts +2 -0
  413. package/src/types/request.ts +13 -1
  414. package/src/update/config-preflight.ts +48 -0
  415. package/src/update/index.ts +148 -26
  416. package/src/update/npm-install.d.mts +8 -0
  417. package/src/update/npm-install.mjs +20 -1
  418. package/src/update/orchestrated-admission.d.mts +4 -0
  419. package/src/update/orchestrated-admission.mjs +12 -0
  420. package/src/update/orchestrated-arguments.d.mts +12 -0
  421. package/src/update/orchestrated-arguments.mjs +64 -0
  422. package/src/update/orchestrated-child.d.mts +12 -0
  423. package/src/update/orchestrated-child.mjs +70 -0
  424. package/src/update/orchestrated-entry.ts +234 -0
  425. package/src/update/orchestrated-identity-probe-entry.ts +20 -0
  426. package/src/update/orchestrated-identity.ts +53 -0
  427. package/src/update/orchestrated-live-identity.ts +48 -0
  428. package/src/update/orchestrated-node-driver.mjs +99 -0
  429. package/src/update/orchestrated-outcome.d.mts +21 -0
  430. package/src/update/orchestrated-outcome.mjs +40 -0
  431. package/src/update/orchestrated-plan.ts +49 -0
  432. package/src/update/orchestrated-pnpm.d.mts +8 -0
  433. package/src/update/orchestrated-pnpm.mjs +33 -0
  434. package/src/update/orchestrated-session.d.mts +37 -0
  435. package/src/update/orchestrated-session.mjs +264 -0
  436. package/src/update/orchestrated-token.d.mts +10 -0
  437. package/src/update/orchestrated-token.mjs +21 -0
  438. package/src/update/orchestrated-token.ts +3 -0
  439. package/src/update/orchestrated-tree.d.mts +1 -0
  440. package/src/update/orchestrated-tree.mjs +14 -0
  441. package/src/update/pnpm-global-install.d.mts +6 -0
  442. package/src/update/pnpm-global-install.mjs +9 -2
  443. package/src/update/posix-install-supervisor-entry.mjs +6 -0
  444. package/src/update/posix-install-supervisor.d.mts +10 -0
  445. package/src/update/posix-install-supervisor.mjs +88 -0
  446. package/src/update/sync-update-mutex.d.mts +10 -0
  447. package/src/update/sync-update-mutex.mjs +164 -0
  448. package/src/update/sync-update-mutex.ts +1 -0
  449. package/src/update/test-home-guard.mjs +33 -0
  450. package/src/update/transactional-install.mjs +2 -2
  451. package/src/usage/client.ts +43 -0
  452. package/src/usage/error-detail.ts +225 -0
  453. package/src/usage/log.ts +64 -27
  454. package/src/usage/source-facets.ts +51 -0
  455. package/src/usage/source-filter.ts +65 -0
  456. package/src/usage/summary.ts +50 -8
  457. package/src/web-search/anthropic-executor.ts +105 -24
  458. package/src/web-search/executor.ts +5 -3
  459. package/src/web-search/loop.ts +33 -6
  460. package/src/web-search/progress-stream.ts +64 -5
  461. package/gui/dist/assets/App-bwugJRKn.js +0 -58
  462. package/gui/dist/assets/index-ebuVUtB7.js +0 -94
  463. package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
  464. /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
  465. /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
@@ -2,6 +2,7 @@ import { isMistralChatTarget, isNativeOpenAIChatTarget, stripBracketedModelSuffi
2
2
  import { reasoningDetailSegmentForWire } from "./response-events";
3
3
  import { translatedChatDeveloperWireRole } from "./developer-role";
4
4
  import { singleLeadingSystemMessages } from "./single-system";
5
+ import { limitMistralChatImages } from "./mistral-image-limit";
5
6
  import { isVolcengineArkPaygChatTarget } from "./tool-schema";
6
7
  import { contentPartsToText } from "../image";
7
8
  import { EMPTY_TOOL_OUTPUT_ANNOTATION, isWhitespaceOnlyTextPartArray } from "../empty-tool-output-annotation";
@@ -112,6 +113,12 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
112
113
  let pendingToolResultAudioParts: unknown[] = [];
113
114
  let mintedIdSeq = 0;
114
115
  const seenWireCallIds = new Set<string>();
116
+ // One call id can arrive with more than one result: Codex code mode records the yield marker
117
+ // for a running cell, then each late `notify()`/wait output as a further result for the same
118
+ // call. OpenAI-compatible chat providers reject the second `role:"tool"` reply for an id that
119
+ // was already answered ("Duplicate tool output for call_id"), so the repeats stay out of the
120
+ // wire body and their text is appended to the result that already answered the call.
121
+ const answeredToolResults = new Map<string, { content: unknown }>();
115
122
 
116
123
  const mintCallId = (): string => {
117
124
  let id = "";
@@ -167,6 +174,20 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
167
174
  releaseDeferredBarriers();
168
175
  };
169
176
 
177
+ /** Append a repeated result for an already-answered call to the answer that call already got. */
178
+ const appendAnsweredToolResultText = (
179
+ message: { content: unknown },
180
+ text: string,
181
+ ): void => {
182
+ if (text.length === 0) return;
183
+ const current = message.content;
184
+ // `toolResultTextForWire` always returns text for a `role:"tool"` reply, so the answer is a
185
+ // string; an unexpected shape still keeps both halves rather than dropping the repeat.
186
+ message.content = typeof current === "string" && current.length > 0
187
+ ? `${current}\n\n${text}`
188
+ : typeof current === "string" ? text : [current, text];
189
+ };
190
+
170
191
  const nativeOpenAI = isNativeOpenAIChatTarget(provider);
171
192
  // Leading-system chat templates reject non-leading system and every developer role while a
172
193
  // later user renders in place: Qwen3.8-27B, Flash-Next, and the OrcaSAQ-2-Cyber-27B GGUF family.
@@ -369,11 +390,13 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
369
390
  let toolCallId = msg.toolCallId;
370
391
  const matchIdx = toolCallId ? pendingToolCalls.findIndex(c => c.id === toolCallId) : -1;
371
392
  if (matchIdx >= 0 && toolCallId) {
372
- out.push({
393
+ const toolMsg = {
373
394
  role: "tool",
374
395
  tool_call_id: toolCallId,
375
396
  content: toolResultTextForWire(msg.content, provider.annotateEmptyToolOutputs === true),
376
- });
397
+ };
398
+ out.push(toolMsg);
399
+ answeredToolResults.set(toolCallId, toolMsg);
377
400
  pendingToolResultImageParts.push(...toolResultImageChatParts(msg.content));
378
401
  pendingToolResultAudioParts.push(...toolResultAudioChatParts(msg.content));
379
402
  pendingToolCalls.splice(matchIdx, 1);
@@ -382,6 +405,34 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
382
405
  flushToolResultAudio();
383
406
  releaseDeferredBarriers();
384
407
  }
408
+ } else if (
409
+ toolCallId
410
+ && answeredToolResults.has(toolCallId)
411
+ && !pendingToolCalls.some(c => c.id === toolCallId)
412
+ ) {
413
+ const answer = answeredToolResults.get(toolCallId)!;
414
+ const text = toolResultTextForWire(msg.content, provider.annotateEmptyToolOutputs === true);
415
+ if (out[out.length - 1] === answer && deferredBarrierMessages.length === 0) {
416
+ // Adjacent results can share one reply without moving anything across a later turn.
417
+ appendAnsweredToolResultText(answer, text);
418
+ pendingToolResultImageParts.push(...toolResultImageChatParts(msg.content));
419
+ pendingToolResultAudioParts.push(...toolResultAudioChatParts(msg.content));
420
+ if (pendingToolCalls.length === 0) {
421
+ flushToolResultImages();
422
+ flushToolResultAudio();
423
+ }
424
+ } else {
425
+ // Chat cannot repeat a tool reply. Keep late text and media together at their
426
+ // recorded position, identified by call ID; an open tool block must close first.
427
+ const media = typeof msg.content === "string" ? [] : msg.content.flatMap(part => [
428
+ ...toolResultImageChatParts([part]), ...toolResultAudioChatParts([part]),
429
+ ]);
430
+ const carrier = { role: "user", content: [
431
+ { type: "text", text: `[ocx] additional output for tool call ${toolCallId}:\n${text}` },
432
+ ...media,
433
+ ] };
434
+ (pendingToolCalls.length > 0 ? deferredBarrierMessages : out).push(carrier);
435
+ }
385
436
  } else {
386
437
  if (!toolCallId) toolCallId = `call_orphan_${out.length}`;
387
438
  flushPendingToolCalls();
@@ -422,11 +473,13 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
422
473
  }],
423
474
  });
424
475
  seenWireCallIds.add(toolCallId);
425
- out.push({
476
+ const toolMsg = {
426
477
  role: "tool",
427
478
  tool_call_id: toolCallId,
428
479
  content: toolResultTextForWire(msg.content, provider.annotateEmptyToolOutputs === true),
429
- });
480
+ };
481
+ out.push(toolMsg);
482
+ answeredToolResults.set(toolCallId, toolMsg);
430
483
  pendingToolResultImageParts.push(...toolResultImageChatParts(msg.content));
431
484
  pendingToolResultAudioParts.push(...toolResultAudioChatParts(msg.content));
432
485
  flushToolResultImages();
@@ -439,7 +492,7 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
439
492
 
440
493
  flushPendingToolCalls();
441
494
  releaseDeferredBarriers();
442
- return singleLeadingSystemMessages(out, provider) as unknown[];
495
+ return limitMistralChatImages(singleLeadingSystemMessages(out, provider), provider, parsed.modelId) as unknown[];
443
496
  }
444
497
 
445
498
  export function safeToolName(name: string | undefined): string {
@@ -0,0 +1,50 @@
1
+ import type { OcxProviderConfig } from "../../types";
2
+ import { declaredModelCapabilities, mergeReasoningModelCapabilities } from "../../providers/reasoning-capabilities";
3
+ import { registryEntryForProviderDestination } from "../../providers/registry";
4
+ import { isMistralChatTarget } from "./wire";
5
+
6
+ /**
7
+ * Mistral counts every image in the replayed history against a per-request cap. Its vision guide
8
+ * (https://docs.mistral.ai/capabilities/vision/) documents 8, and most vision models refuse a ninth
9
+ * with HTTP 400 ("Total number of images exceeds the maximum allowed of 8"). Models that accept more
10
+ * declare `modelCapabilities.<id>.mistralMaxImages`: the registry row carries measured caps, matched
11
+ * by destination so a renamed Mistral row keeps them, and an operator declaration outranks it.
12
+ */
13
+ export const MISTRAL_DEFAULT_MAX_IMAGES = 8;
14
+
15
+ /** The images one Chat request may carry for this model at this destination. */
16
+ export function mistralMaxImages(provider: OcxProviderConfig, modelId: string): number {
17
+ const rows = mergeReasoningModelCapabilities(registryEntryForProviderDestination(provider)?.modelCapabilities, provider.modelCapabilities);
18
+ return declaredModelCapabilities(rows, modelId)?.mistralMaxImages ?? MISTRAL_DEFAULT_MAX_IMAGES;
19
+ }
20
+
21
+ function isRecord(value: unknown): value is Record<string, unknown> {
22
+ return value !== null && typeof value === "object" && !Array.isArray(value);
23
+ }
24
+
25
+ /**
26
+ * Keep the newest images a first-party Mistral request may carry and replace older ones with a
27
+ * text note, across every message (promoted tool-result images included). Normalizes the outbound
28
+ * copy only: messages that change are copied, so history and other destinations stay intact.
29
+ */
30
+ export function limitMistralChatImages(messages: unknown, provider: OcxProviderConfig, modelId: string): unknown {
31
+ if (!isMistralChatTarget(provider) || !Array.isArray(messages)) return messages;
32
+ const maxImages = mistralMaxImages(provider, modelId);
33
+ const images: Array<{ message: number; part: number }> = [];
34
+ messages.forEach((message, index) => {
35
+ if (!isRecord(message) || !Array.isArray(message.content)) return;
36
+ message.content.forEach((part, partIndex) => {
37
+ if (isRecord(part) && part.type === "image_url") images.push({ message: index, part: partIndex });
38
+ });
39
+ });
40
+ const excess = images.length - maxImages;
41
+ if (excess <= 0) return messages;
42
+ const note = { type: "text", text: `[image omitted: Mistral accepts at most ${maxImages} images per request for this model; older images were dropped]` };
43
+ const out = [...messages];
44
+ for (const { message, part } of images.slice(0, excess)) {
45
+ const original = messages[message] as Record<string, unknown>;
46
+ if (out[message] === original) out[message] = { ...original, content: [...(original.content as unknown[])] };
47
+ ((out[message] as Record<string, unknown>).content as unknown[])[part] = note;
48
+ }
49
+ return out;
50
+ }
@@ -4,6 +4,7 @@ import type { AdapterRequest } from "../base";
4
4
  import { frameAgentRouterMessages } from "../agentrouter";
5
5
  import { applyExplicitChatDeveloperRole } from "./developer-role";
6
6
  import { singleLeadingSystemMessages } from "./single-system";
7
+ import { limitMistralChatImages } from "./mistral-image-limit";
7
8
  import { openRouterProviderPayload, resolveOpenRouterRouting } from "../../providers/openrouter-routing";
8
9
  import { resolveVercelGatewayRouting, vercelGatewayProviderPayload } from "../../providers/vercel-gateway-routing";
9
10
  import { fastPolicyForModel } from "../../providers/service-tier";
@@ -78,11 +79,12 @@ export function buildOpenAIChatPassthroughRequest(
78
79
  // and the conversion changes the role of those messages and nothing else, so the position
79
80
  // of every message and every other field survive unchanged. Missing thinking history is
80
81
  // repaired below using the same preserve policy as the translated Chat builder.
81
- // The explicit single-system policy can then merge instruction slots.
82
- messages: singleLeadingSystemMessages(applyExplicitChatDeveloperRole(
82
+ // The explicit single-system policy can then merge instruction slots, and Mistral's
83
+ // per-request image cap applies as it does to translated Chat.
84
+ messages: limitMistralChatImages(singleLeadingSystemMessages(applyExplicitChatDeveloperRole(
83
85
  frameAgentRouterMessages(provider.baseUrl, rawBody.messages),
84
86
  provider,
85
- ), provider),
87
+ ), provider), provider, modelId),
86
88
  stream,
87
89
  };
88
90
  for (const field of CHAT_PASSTHROUGH_FIELDS) {
@@ -37,7 +37,55 @@ function sanitizeZenToolParameters(value: unknown): unknown {
37
37
  return out;
38
38
  }
39
39
 
40
- function ensureZenRootObjectSchema(schema: unknown): Record<string, unknown> {
40
+ /** Inspect composition edges only: property schemas and literal values are not branches. */
41
+ function hasUnreadClaudeComposition(branch: Record<string, unknown>, budget: { nestedRemaining: number }): boolean {
42
+ const pending = [branch];
43
+ const seen = new Set<object>(pending);
44
+ while (pending.length > 0) {
45
+ const node = pending.pop()!;
46
+ for (const key of ["oneOf", "anyOf", "allOf"]) {
47
+ const variants = node[key];
48
+ if (!Array.isArray(variants)) continue;
49
+ for (const variant of variants) {
50
+ if (budget.nestedRemaining-- <= 0) return true;
51
+ if (!variant || typeof variant !== "object" || Array.isArray(variant)) continue;
52
+ if (Object.hasOwn(variant, "properties")) {
53
+ const properties = (variant as Record<string, unknown>).properties;
54
+ if (!properties || typeof properties !== "object" || Array.isArray(properties) || Object.keys(properties).length > 0) return true;
55
+ const prototype = Object.getPrototypeOf(properties);
56
+ if (prototype !== null && prototype !== Object.prototype) return true;
57
+ }
58
+ if (Object.hasOwn(variant, "$ref") || seen.has(variant)) return true;
59
+ seen.add(variant);
60
+ pending.push(variant as Record<string, unknown>);
61
+ }
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
67
+ /** Read only root-branch ref chains; never expand property schemas or literal data. */
68
+ function claudeRootBranchLayers(branch: Record<string, unknown>, root: Record<string, unknown>, budget: { remaining: number; nestedRemaining: number }): Record<string, unknown>[] | undefined {
69
+ if (typeof branch.$ref === "string" && ["oneOf", "anyOf", "allOf"].some(key => Array.isArray(branch[key]))) return undefined;
70
+ if (hasUnreadClaudeComposition(branch, budget)) return undefined;
71
+ const layers = [branch];
72
+ const seen = new Set<object>([branch]);
73
+ let current = branch;
74
+ // One budget across all branches bounds repeated references as well as long chains.
75
+ while (typeof current.$ref === "string") {
76
+ if (budget.remaining-- <= 0) return undefined;
77
+ const target = lookupLocalJsonPointer(root, current.$ref);
78
+ if (!target || typeof target !== "object" || Array.isArray(target) || seen.has(target)) return undefined;
79
+ seen.add(target);
80
+ current = target as Record<string, unknown>;
81
+ if (["oneOf", "anyOf", "allOf"].some(key => Array.isArray(current[key]))) return undefined;
82
+ layers.push(current);
83
+ }
84
+ // Referenced fields first, then referring siblings; later branches still win.
85
+ return layers.reverse();
86
+ }
87
+
88
+ function ensureZenRootObjectSchema(schema: unknown, sanitizeNested = true): Record<string, unknown> {
41
89
  const obj = schema && typeof schema === "object" && !Array.isArray(schema)
42
90
  ? schema as Record<string, unknown>
43
91
  : {};
@@ -46,14 +94,15 @@ function ensureZenRootObjectSchema(schema: unknown): Record<string, unknown> {
46
94
  const rootType = obj.type;
47
95
  const rootObjectType = rootType === "object" || (Array.isArray(rootType) && rootType.includes("object"));
48
96
  if (!hasComposition) {
49
- const base = sanitizeZenToolParameters(obj) as Record<string, unknown>;
97
+ const base = (sanitizeNested ? sanitizeZenToolParameters(obj) : { ...obj }) as Record<string, unknown>;
50
98
  return rootObjectType && base.type === "object" ? base : { ...base, type: "object" };
51
99
  }
52
100
 
53
- const props: Record<string, unknown> = {};
101
+ const props: Record<string, unknown> = sanitizeNested ? {} : Object.create(null);
54
102
  const required = new Set<string>();
103
+ const refBudget = { remaining: 64, nestedRemaining: 256 };
55
104
  if (obj.properties && typeof obj.properties === "object") {
56
- Object.assign(props, sanitizeZenSchemaMap(obj.properties) as Record<string, unknown>);
105
+ Object.assign(props, sanitizeNested ? sanitizeZenSchemaMap(obj.properties) : obj.properties);
57
106
  }
58
107
  if (Array.isArray(obj.required)) {
59
108
  for (const entry of obj.required) if (typeof entry === "string") required.add(entry);
@@ -64,17 +113,22 @@ function ensureZenRootObjectSchema(schema: unknown): Record<string, unknown> {
64
113
  const mergeRequired = key === "allOf";
65
114
  for (const variant of variants) {
66
115
  if (!variant || typeof variant !== "object" || Array.isArray(variant)) continue;
67
- const rec = variant as Record<string, unknown>;
68
- if (rec.properties && typeof rec.properties === "object") {
69
- Object.assign(props, sanitizeZenSchemaMap(rec.properties) as Record<string, unknown>);
70
- }
71
- if (mergeRequired && Array.isArray(rec.required)) {
72
- for (const entry of rec.required) if (typeof entry === "string") required.add(entry);
116
+ const branch = variant as Record<string, unknown>;
117
+ const layers = sanitizeNested ? [branch] : claudeRootBranchLayers(branch, obj, refBudget);
118
+ // Keep the unsupported schema visible to the provider rather than losing arguments.
119
+ if (!layers) return { ...obj, type: "object" };
120
+ for (const rec of layers) {
121
+ if (rec.properties && typeof rec.properties === "object") {
122
+ Object.assign(props, sanitizeNested ? sanitizeZenSchemaMap(rec.properties) : rec.properties);
123
+ }
124
+ if (mergeRequired && Array.isArray(rec.required)) {
125
+ for (const entry of rec.required) if (typeof entry === "string") required.add(entry);
126
+ }
73
127
  }
74
128
  }
75
129
  }
76
130
 
77
- const merged = sanitizeZenToolParameters(obj) as Record<string, unknown>;
131
+ const merged = (sanitizeNested ? sanitizeZenToolParameters(obj) : { ...obj }) as Record<string, unknown>;
78
132
  delete merged.oneOf;
79
133
  delete merged.anyOf;
80
134
  delete merged.allOf;
@@ -93,6 +147,21 @@ function shouldSanitizeZenToolParameters(provider: OcxProviderConfig): boolean {
93
147
  /** Azure Model Router (and Gemini-in-the-pool) 400s Codex MCP schemas whose root is a union. */
94
148
  const AZURE_CHAT_FORBIDDEN_ROOT_KEYS = ["oneOf", "anyOf", "allOf", "enum", "const", "not"] as const;
95
149
 
150
+ /**
151
+ * Anthropic validates every tool `input_schema` as a plain object and answers 400
152
+ * "input_schema does not support oneOf, allOf, or anyOf at the top level". Gateways that
153
+ * front Claude behind a Chat Completions wire (new-api / EasyRouter style relays) forward the
154
+ * schema as-is, so a Codex MCP tool with a union root fails the whole turn. The provider-wide
155
+ * adapter cannot be split per model, so decide on the upstream model id: Claude ids get the
156
+ * inline root flattening plus bounded local branch-ref handling; other models are untouched.
157
+ */
158
+ function isClaudeModelId(modelId: string | undefined): boolean {
159
+ if (typeof modelId !== "string") return false;
160
+ const id = modelId.trim().toLowerCase();
161
+ const tail = id.slice(id.lastIndexOf("/") + 1);
162
+ return tail.startsWith("claude-");
163
+ }
164
+
96
165
  function isAzureOpenAiChatTarget(provider: OcxProviderConfig): boolean {
97
166
  try {
98
167
  const host = new URL(provider.baseUrl).hostname.toLowerCase();
@@ -576,14 +645,15 @@ export function toolsToChatFormatForProvider(
576
645
  const base = toolsToChatFormat(parsed, provider, registry);
577
646
  const azureChat = isAzureOpenAiChatTarget(provider);
578
647
  const zenChat = shouldSanitizeZenToolParameters(provider);
579
- if (!base || (!zenChat && !azureChat)) return base;
648
+ const claudeChat = isClaudeModelId(parsed._wireModelOverride ?? parsed.modelId);
649
+ if (!base || (!zenChat && !azureChat && !claudeChat)) return base;
580
650
  return base.map(tool => {
581
651
  if (!tool || typeof tool !== "object") return tool;
582
652
  const functionDef = (tool as { function?: Record<string, unknown> }).function;
583
653
  if (!functionDef || typeof functionDef !== "object") return tool;
584
654
  const parameters = azureChat
585
655
  ? sanitizeAzureChatToolParameters(functionDef.parameters ?? {})
586
- : ensureZenRootObjectSchema(functionDef.parameters ?? {});
656
+ : ensureZenRootObjectSchema(functionDef.parameters ?? {}, zenChat);
587
657
  const nextFunction: Record<string, unknown> = { ...functionDef, parameters };
588
658
  // strict: true plus a flattened schema is rejected by Gemini-in-the-pool routers.
589
659
  if (azureChat) delete nextFunction.strict;
@@ -16,11 +16,23 @@ function isEmptyAssistantMessage(item: unknown): boolean {
16
16
  return item.content === "" || (Array.isArray(item.content) && item.content.every(isEmptyTextPart));
17
17
  }
18
18
 
19
+ /** Exactly Kimi Code's native Responses endpoint; lookalike hosts and other Kimi paths do not match. */
20
+ export function isKimiCodingResponsesUrl(responseUrl: string): boolean {
21
+ let url: URL;
22
+ try { url = new URL(responseUrl); } catch { return false; }
23
+ return url.hostname === "api.kimi.com" && /^\/coding\/v1\/responses\/?$/.test(url.pathname);
24
+ }
25
+
26
+ /** The same endpoint over HTTPS on the default port only, for request rewrites scoped to Kimi Code itself. */
27
+ export function isKimiCodingResponsesHttpsUrl(responseUrl: string): boolean {
28
+ if (!isKimiCodingResponsesUrl(responseUrl)) return false;
29
+ const url = new URL(responseUrl);
30
+ return url.protocol === "https:" && url.port === "";
31
+ }
32
+
19
33
  /** Kimi Code rejects content-empty assistant messages even on its native Responses endpoint. */
20
34
  export function stripKimiEmptyAssistantMessages(body: unknown, responseUrl: string): unknown {
21
- let url: URL;
22
- try { url = new URL(responseUrl); } catch { return body; }
23
- if (url.hostname !== "api.kimi.com" || !/^\/coding\/v1\/responses\/?$/.test(url.pathname)) return body;
35
+ if (!isKimiCodingResponsesUrl(responseUrl)) return body;
24
36
  if (!isPlainObject(body) || !Array.isArray(body.input)) return body;
25
37
  const referencedIds = new Set<string>();
26
38
  for (const item of body.input) {
@@ -1,5 +1,8 @@
1
1
  import { isPlainObject } from "./internal";
2
- import { normalizeResponsesToolResultAdjacency } from "./tool-output-recovery";
2
+ import {
3
+ mergeRepeatedResponsesToolOutputs,
4
+ normalizeResponsesToolResultAdjacency,
5
+ } from "./tool-output-recovery";
3
6
 
4
7
  export class OpenGatewayInputCompatibilityError extends Error {
5
8
  constructor() {
@@ -128,11 +131,20 @@ export function normalizeOpenGatewayResponsesInput(body: unknown, url: string):
128
131
  // Same exact-URL boundary as completion recovery; a query-routed variant is a different destination.
129
132
  if (url !== "https://apis.opengateway.ai/v1/responses" || !isPlainObject(body) || !Array.isArray(body.input)) return body;
130
133
 
131
- const direct = projectOpenGatewayInput(body.input);
132
- if (!direct.changed) return body;
133
- const aligned = normalizeResponsesToolResultAdjacency(body);
134
- if (!isPlainObject(aligned) || !Array.isArray(aligned.input) || aligned === body) {
135
- return { ...body, input: direct.input };
134
+ // Codex records several outputs for one code-mode call (the yield marker, then late cell
135
+ // output). This gateway's parser answers the repeat with "Messages with role 'tool' must be a
136
+ // response to a preceding message with 'tool_calls'", which blocks every later turn of the
137
+ // thread, so repeated outputs are joined even when every part is already a plain string and
138
+ // no projection below has anything to change.
139
+ const merged = mergeRepeatedResponsesToolOutputs(body);
140
+ const source = (isPlainObject(merged) && Array.isArray(merged.input)
141
+ ? { ...merged, input: merged.input }
142
+ : { ...body, input: body.input }) as Record<string, unknown> & { input: unknown[] };
143
+ const direct = projectOpenGatewayInput(source.input);
144
+ if (!direct.changed) return source;
145
+ const aligned = normalizeResponsesToolResultAdjacency(source);
146
+ if (!isPlainObject(aligned) || !Array.isArray(aligned.input) || aligned === source) {
147
+ return { ...source, input: direct.input };
136
148
  }
137
149
  const paired = projectOpenGatewayInput(aligned.input);
138
150
  return { ...aligned, input: paired.changed ? paired.input : direct.input };
@@ -57,7 +57,7 @@ import { observeOutbound } from "../../usage/cache-diagnostic";
57
57
  import { normalizeMuseToolCatalog } from "./muse-tool-catalog";
58
58
  import { normalizeMuseToolChoice } from "./muse-tool-choice";
59
59
  import { declaresHostedWebSearch, projectHostedSearchHistory, renderCompactionSearchHistoryItems } from "./compaction-search-history";
60
- import { stripKimiEmptyAssistantMessages } from "./empty-assistant";
60
+ import { isKimiCodingResponsesHttpsUrl, stripKimiEmptyAssistantMessages } from "./empty-assistant";
61
61
  import { normalizeOpenGatewayResponsesInput } from "./opengateway-input";
62
62
 
63
63
  /**
@@ -358,12 +358,13 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
358
358
  // OpenCode Go speaks the same dialect, which the final model id and URL identify.
359
359
  outBody = normalizeXaiResponsesWebSearch(outBody, provider, { modelId: parsed.modelId, responseUrl: url });
360
360
  outBody = injectXaiResponsesXSearch(outBody, provider, parsed._replayPrefixLen);
361
- // xAI, Meta and Azure answer 400 for `output.encrypted_content` instead of ignoring it;
362
- // Codex Desktop asks for it on every turn (#7878).
361
+ // xAI, Meta, Azure and Kimi Code (#8075) answer 400 for `output.encrypted_content`
362
+ // instead of ignoring it; Codex Desktop asks for it on every turn (#7878).
363
363
  // Azure also rejects this exact include entry, including on plain Responses routes.
364
364
  const isAzureResponses = provider.adapter === "azure" || provider.adapter === "azure-openai"
365
365
  || new URL(url).hostname.toLowerCase().endsWith(".openai.azure.com");
366
- if (isXaiResponsesDestination(provider) || isMetaAiResponsesDestination(url) || isAzureResponses) {
366
+ if (isXaiResponsesDestination(provider) || isMetaAiResponsesDestination(url) || isAzureResponses
367
+ || isKimiCodingResponsesHttpsUrl(url)) {
367
368
  outBody = stripUnsupportedOutputInclude(outBody);
368
369
  }
369
370
  // xAI and explicitly classified compatible gateways reject these OpenAI web_search
@@ -174,10 +174,15 @@ export function sanitizeReasoningInputContent(
174
174
 
175
175
  /** Assistant-authored history items: what DeepSeek merges into one assistant message. */
176
176
  function isAssistantTurnItem(item: unknown): boolean {
177
- if (!isPlainObject(item) || typeof item.type !== "string") return false;
178
- if (item.type === "reasoning") return true;
179
- if (item.type === "message") return item.role === "assistant";
180
- return item.type.endsWith("_call");
177
+ if (!isPlainObject(item)) return false;
178
+ // Responses input accepts the message shorthand without `type`. ZCode sends its assistant
179
+ // text that way, directly ahead of the same turn's function calls; reading only a typed
180
+ // `message` would split the turn and place the placeholder backfill after the text, which
181
+ // DeepSeek refuses with the same reasoning_text 400.
182
+ const type = typeof item.type === "string" ? item.type : "role" in item ? "message" : undefined;
183
+ if (type === "reasoning") return true;
184
+ if (type === "message") return item.role === "assistant";
185
+ return type?.endsWith("_call") === true;
181
186
  }
182
187
 
183
188
  function isClientToolCallItem(item: unknown): boolean {
@@ -8,7 +8,7 @@ import { activateDeferredTool } from "./tool-schema";
8
8
  import { stripOpenAiOnlyWebSearchFields } from "./web-search";
9
9
 
10
10
  /**
11
- * Codex requests output.encrypted_content, which xAI, Meta and Azure reject with HTTP 400.
11
+ * Codex requests output.encrypted_content, which xAI, Meta, Azure and Kimi Code reject with HTTP 400.
12
12
  * The caller gates this on the destination. Preserve reasoning.encrypted_content
13
13
  * for stateless replay and leave unknown or malformed values for upstream validation.
14
14
  */
@@ -535,6 +535,85 @@ export function repairOrphanedInputItems(
535
535
  * - 장점, 단점 및 영향: DeepSeek keeps one reasoning-bearing assistant turn for parallel calls and still accepts hook-interleaved single calls; tolerant providers stay byte/order equivalent, and duplicate, missing, or backwards call/result pairs are not guessed.
536
536
  */
537
537
  export function normalizeResponsesToolResultAdjacency(body: unknown): unknown {
538
+ return normalizeAdjacentToolBatches(mergeRepeatedResponsesToolOutputs(body));
539
+ }
540
+
541
+ type ToolOutputContent = string | unknown[];
542
+
543
+ function toolOutputParts(output: ToolOutputContent): unknown[] {
544
+ if (Array.isArray(output)) return output;
545
+ return output.length > 0 ? [{ type: "input_text", text: output }] : [];
546
+ }
547
+
548
+ /**
549
+ * Join every output recorded for one Responses tool call into that call's first output.
550
+ *
551
+ * Codex code mode records several `custom_tool_call_output` items for one `exec` call: the yield
552
+ * marker (`Script running with cell ID N`), then each `notify()`/late cell output, sometimes after a
553
+ * later `wait` call. Tolerant upstreams accept that history. Strict OpenAI-compatible destinations
554
+ * reject it — DeepSeek answers `Duplicate tool output for call_id`, and OpenGateway's Responses API
555
+ * answers `Messages with role 'tool' must be a response to a preceding message with 'tool_calls'`
556
+ * — so every later turn of the thread fails, and the adjacency pass below refuses the whole body
557
+ * because the pair is not unique.
558
+ *
559
+ * Only an unambiguous shape is merged: exactly one matching call, and every output after it.
560
+ * Outputs are joined once in arrival order at the first output's position (the same rule the
561
+ * ollama-native mapper uses since #6576), so no content is dropped and no call is fabricated.
562
+ * String outputs stay strings when every piece is a string; otherwise all pieces become content
563
+ * parts. Reused call ids, outputs without a call, and outputs before their call stay untouched.
564
+ */
565
+ export function mergeRepeatedResponsesToolOutputs(body: unknown): unknown {
566
+ if (!isPlainObject(body) || !Array.isArray(body.input)) return body;
567
+ const input = body.input;
568
+ const calls = new Map<string, number[]>();
569
+ const outputs = new Map<string, number[]>();
570
+ const record = (map: Map<string, number[]>, key: string, index: number): void => {
571
+ const existing = map.get(key);
572
+ if (existing) existing.push(index);
573
+ else map.set(key, [index]);
574
+ };
575
+ for (let index = 0; index < input.length; index += 1) {
576
+ const item = input[index];
577
+ if (!isPlainObject(item) || typeof item.call_id !== "string" || item.call_id.length === 0) continue;
578
+ if (item.type === "function_call" || item.type === "local_shell_call") record(calls, `function:${item.call_id}`, index);
579
+ else if (item.type === "custom_tool_call") record(calls, `custom:${item.call_id}`, index);
580
+ else if (item.type === "function_call_output") record(outputs, `function:${item.call_id}`, index);
581
+ else if (item.type === "custom_tool_call_output") record(outputs, `custom:${item.call_id}`, index);
582
+ }
583
+
584
+ const merged = new Map<number, unknown>();
585
+ const dropped = new Set<number>();
586
+ for (const [key, outputIndices] of outputs) {
587
+ if (outputIndices.length < 2) continue;
588
+ const callIndices = calls.get(key);
589
+ if (!callIndices || callIndices.length !== 1 || outputIndices[0]! < callIndices[0]!) continue;
590
+ const pieces: ToolOutputContent[] = [];
591
+ let readable = true;
592
+ for (const outputIndex of outputIndices) {
593
+ const output = (input[outputIndex] as Record<string, unknown>).output;
594
+ if (typeof output === "string" || Array.isArray(output)) pieces.push(output);
595
+ else readable = false;
596
+ }
597
+ if (!readable) continue;
598
+ const allText = pieces.every((piece): piece is string => typeof piece === "string");
599
+ const joined = allText
600
+ ? pieces.filter(piece => piece.length > 0).join("\n\n")
601
+ : pieces.flatMap(toolOutputParts);
602
+ const [first, ...rest] = outputIndices;
603
+ merged.set(first!, { ...(input[first!] as Record<string, unknown>), output: joined });
604
+ for (const index of rest) dropped.add(index);
605
+ }
606
+ if (merged.size === 0) return body;
607
+
608
+ const next: unknown[] = [];
609
+ for (let index = 0; index < input.length; index += 1) {
610
+ if (dropped.has(index)) continue;
611
+ next.push(merged.has(index) ? merged.get(index) : input[index]);
612
+ }
613
+ return { ...body, input: next };
614
+ }
615
+
616
+ function normalizeAdjacentToolBatches(body: unknown): unknown {
538
617
  if (!isPlainObject(body) || !Array.isArray(body.input)) return body;
539
618
  const input = body.input;
540
619
  const calls = new Map<string, number[]>();
@@ -1,7 +1,7 @@
1
1
  import type { AdapterFetchContext } from "./base";
2
2
  import type { SendClass } from "../lib/request-execution-budget";
3
3
  import type { AttemptRecoveryKind } from "../usage/log";
4
- import { abortError, SendBudgetExhaustedError } from "../lib/upstream-retry";
4
+ import { abortError, SendBudgetExhaustedError, errorDestinationLabel } from "../lib/upstream-retry";
5
5
  import {
6
6
  releaseProviderRequestSlot,
7
7
  sendTrackingRequestSlot,
@@ -30,14 +30,14 @@ export function createAdapterPhysicalSend(ctx: AdapterFetchContext = {}, fallbac
30
30
  const decision = ctx.sendBudget?.reserveDispatch({
31
31
  sendClass: options.sendClass ?? "transient", targetKey: options.url,
32
32
  });
33
- if (decision && !decision.allowed) throw new SendBudgetExhaustedError(options.url);
33
+ if (decision && !decision.allowed) throw new SendBudgetExhaustedError(errorDestinationLabel(options.url));
34
34
  const permit = decision?.allowed ? decision.permit : undefined;
35
35
  let dispatched = false;
36
36
  const physicalExecutor = (async (input, init) => {
37
37
  if (ctx.abortSignal?.aborted) throw abortError(ctx.abortSignal);
38
38
  if (init?.signal?.aborted) throw abortError(init.signal);
39
39
  const run = async (): Promise<Response> => {
40
- if (dispatched || (permit && !permit.use())) throw new SendBudgetExhaustedError(options.url);
40
+ if (dispatched || (permit && !permit.use())) throw new SendBudgetExhaustedError(errorDestinationLabel(options.url));
41
41
  dispatched = true;
42
42
  ordinal += 1;
43
43
  ctx.onPhysicalSend?.({ ordinal, ...(options.recovery ? { recovery: options.recovery } : {}) });