@bitkyc08/opencodex 2.97.0 → 2.98.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 (290) hide show
  1. package/bin/ocx.mjs +1 -1
  2. package/gui/dist/assets/App-6TFtZsUF.css +1 -0
  3. package/gui/dist/assets/App-FQ0OtiMJ.js +59 -0
  4. package/gui/dist/assets/Tray-D2d5wqLq.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-A03mw_9y.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-BjTIN4to.js +94 -0
  111. package/gui/dist/assets/segment-thumb-features-Bf6vpwf8.js +1 -0
  112. package/gui/dist/classic/assets/App-C9Eg3nUo.js +58 -0
  113. package/gui/dist/{assets/Tray-CEw0y0jR.js → classic/assets/Tray-B8P8cokE.js} +1 -1
  114. package/gui/dist/classic/assets/index-DFAFnven.js +94 -0
  115. package/gui/dist/classic/assets/quota-summary-C-4HP4_5.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/google.ts +7 -7
  123. package/src/adapters/kiro/adapter.ts +18 -3
  124. package/src/adapters/kiro/conversation.ts +8 -8
  125. package/src/adapters/kiro/payload.ts +45 -12
  126. package/src/adapters/kiro/stream.ts +169 -12
  127. package/src/adapters/kiro/structured-output-json.ts +191 -0
  128. package/src/adapters/kiro/structured-output-schema.ts +542 -0
  129. package/src/adapters/kiro/structured-output.ts +367 -0
  130. package/src/adapters/kiro-constants.ts +9 -0
  131. package/src/adapters/kiro-tools.ts +14 -9
  132. package/src/adapters/kiro-wire.ts +9 -5
  133. package/src/adapters/openai-chat/messages.ts +58 -5
  134. package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
  135. package/src/adapters/openai-chat/passthrough.ts +5 -3
  136. package/src/adapters/openai-chat/tool-schema.ts +83 -13
  137. package/src/adapters/openai-responses/opengateway-input.ts +18 -6
  138. package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
  139. package/src/adapters/qoder/live-models.ts +115 -1
  140. package/src/claude/failure-verdict.ts +21 -0
  141. package/src/claude/inbound-content-options.ts +15 -2
  142. package/src/claude/inbound-model-options.ts +2 -1
  143. package/src/claude/inbound-records.ts +2 -0
  144. package/src/claude/inbound.ts +17 -11
  145. package/src/claude/outbound.ts +52 -23
  146. package/src/cli/capabilities-access-remote.ts +13 -0
  147. package/src/cli/capabilities-base.ts +1 -0
  148. package/src/cli/capabilities-provider-models.ts +3 -3
  149. package/src/cli/codex-shim-autorestore.ts +7 -0
  150. package/src/cli/config-command.ts +11 -2
  151. package/src/cli/connect.ts +17 -2
  152. package/src/cli/dispatch.ts +3 -1
  153. package/src/cli/doctor.ts +95 -7
  154. package/src/cli/index.ts +12 -7
  155. package/src/cli/link-apply-restart.ts +9 -2
  156. package/src/cli/models.ts +124 -38
  157. package/src/cli/registry.ts +1 -1
  158. package/src/cli/restart-failure.ts +17 -0
  159. package/src/cli/stop-approval.ts +2 -2
  160. package/src/cli/sync-command.ts +1 -1
  161. package/src/cli/sync-fanout.ts +15 -4
  162. package/src/cli/system-restart-client.ts +5 -0
  163. package/src/cli/uninstall-client-state.ts +12 -1
  164. package/src/cli/update-restart-child.ts +13 -3
  165. package/src/cli/update-restart-home.ts +6 -3
  166. package/src/cli/update-restart.ts +36 -19
  167. package/src/client/connect.ts +4 -1
  168. package/src/client/hub-client.ts +5 -0
  169. package/src/client/link-management-relay.ts +39 -2
  170. package/src/client/link-readiness.ts +3 -1
  171. package/src/client/machine-api.ts +2 -1
  172. package/src/client/machine-listener.ts +7 -0
  173. package/src/client/orphan-token-recovery.ts +322 -0
  174. package/src/codex/catalog/provider-models.ts +12 -4
  175. package/src/codex/native-profile-api.ts +27 -1
  176. package/src/codex/shim-diagnostics.ts +7 -0
  177. package/src/codex/shim-legacy-record.ts +290 -0
  178. package/src/codex/shim-windows-refresh.ts +9 -2
  179. package/src/codex/shim-wrapper-write.ts +7 -0
  180. package/src/codex/shim.ts +80 -21
  181. package/src/config/diagnostics.ts +9 -9
  182. package/src/config/load-degrade.ts +27 -27
  183. package/src/config/provider-validation.ts +9 -2
  184. package/src/config/removed-opencode-free-backup.ts +6 -3
  185. package/src/config/tracked-runtime-inspection.ts +3 -3
  186. package/src/generated/compatibility-version.json +219 -147
  187. package/src/images/loop.ts +2 -2
  188. package/src/lib/client-error-body.ts +37 -6
  189. package/src/lib/config-ownership-removal.ts +422 -0
  190. package/src/lib/config-ownership.ts +646 -81
  191. package/src/lib/context-overflow-verdict.ts +3 -3
  192. package/src/lib/crash-guard.ts +4 -2
  193. package/src/lib/desktop-cli-handoff.d.mts +3 -4
  194. package/src/lib/desktop-cli-handoff.mjs +7 -16
  195. package/src/lib/errors.ts +1 -0
  196. package/src/lib/local-management-capability.ts +3 -1
  197. package/src/lib/messages-error-body.ts +162 -0
  198. package/src/lib/messages-sse-error-presentation.ts +93 -0
  199. package/src/lib/passive-read.ts +9 -4
  200. package/src/lib/socks5-fetch.ts +21 -9
  201. package/src/lib/upstream-retry.ts +81 -1
  202. package/src/lib/windows-owner-acl.ts +9 -3
  203. package/src/lib/winsw.ts +5 -5
  204. package/src/lib/workflow-budget.ts +3 -1
  205. package/src/oauth/index.ts +7 -0
  206. package/src/oauth/store.ts +20 -10
  207. package/src/protocols/codecs/messages-ir.ts +15 -9
  208. package/src/protocols/encoders/adapter-events.ts +26 -7
  209. package/src/protocols/encoders/messages.ts +72 -28
  210. package/src/providers/antigravity-models.ts +45 -12
  211. package/src/providers/free-directory.ts +2 -2
  212. package/src/providers/reasoning-metadata.ts +2 -1
  213. package/src/providers/registry/entries-extended.ts +9 -0
  214. package/src/reasoning-effort.ts +7 -2
  215. package/src/remote/hub-usage.ts +3 -0
  216. package/src/server/admission-model-scope.ts +1 -1
  217. package/src/server/admitted-http-turn.ts +2 -1
  218. package/src/server/anthropic-rate-limit-headers.ts +75 -3
  219. package/src/server/claude-messages.ts +130 -67
  220. package/src/server/gui-static.ts +4 -1
  221. package/src/server/hub-usage.ts +7 -2
  222. package/src/server/index/link-management.ts +8 -0
  223. package/src/server/index/ollama-routes.ts +2 -0
  224. package/src/server/index/serve-options.ts +23 -20
  225. package/src/server/index/startup-warnings.ts +5 -12
  226. package/src/server/index/websocket-handler.ts +1 -0
  227. package/src/server/inference/client-encoder-delivery.ts +5 -1
  228. package/src/server/management/logs-usage-routes.ts +89 -4
  229. package/src/server/management/provider-routes.ts +2 -22
  230. package/src/server/management/qoder-provider-probe.ts +105 -0
  231. package/src/server/management/route-registry.ts +3 -0
  232. package/src/server/management/usage-aggregate-cache.ts +15 -5
  233. package/src/server/management/usage-source-facets.ts +38 -0
  234. package/src/server/messages-native-tool-guard.ts +11 -3
  235. package/src/server/messages-native.ts +111 -40
  236. package/src/server/messages-response-headers.ts +25 -11
  237. package/src/server/messages-shared.ts +94 -64
  238. package/src/server/messages-sse-error-filter.ts +199 -0
  239. package/src/server/request-log.ts +12 -0
  240. package/src/server/responses/adapter-continuation.ts +11 -5
  241. package/src/server/responses/adapter-delivery.ts +14 -8
  242. package/src/server/responses/adapter-dispatch.ts +8 -8
  243. package/src/server/responses/anthropic-thinking-recovery.ts +2 -2
  244. package/src/server/responses/codex-auth-error.ts +8 -4
  245. package/src/server/responses/codex-ws-wire.ts +19 -3
  246. package/src/server/responses/compact.ts +4 -1
  247. package/src/server/responses/core-auth.ts +1 -1
  248. package/src/server/responses/core-combo-failure.ts +2 -0
  249. package/src/server/responses/core-combo.ts +2 -0
  250. package/src/server/responses/core-errors.ts +5 -4
  251. package/src/server/responses/core-options.ts +2 -0
  252. package/src/server/responses/empty-completion-guard.ts +4 -1
  253. package/src/server/responses/pacing-overload.ts +1 -1
  254. package/src/server/responses/passthrough-dispatch.ts +5 -5
  255. package/src/server/responses/request-prepare.ts +3 -1
  256. package/src/server/responses/request-transport.ts +9 -8
  257. package/src/server/responses/response-effects.ts +3 -2
  258. package/src/server/responses/terminal-guard.ts +30 -0
  259. package/src/server/restart-replacement.ts +3 -1
  260. package/src/server/sse-payload-rewrite.ts +23 -11
  261. package/src/server/workflow-refusal.ts +1 -1
  262. package/src/server/ws-bridge.ts +4 -0
  263. package/src/service/definition.ts +36 -4
  264. package/src/service/launchd.ts +89 -32
  265. package/src/service/logging.ts +34 -7
  266. package/src/service/plist-xml.ts +59 -0
  267. package/src/service/state.ts +8 -0
  268. package/src/service/systemd-env.ts +2 -0
  269. package/src/service/systemd.ts +31 -7
  270. package/src/service/windows-taskxml.ts +16 -7
  271. package/src/service-manager-probe.ts +4 -10
  272. package/src/types/provider.ts +2 -0
  273. package/src/types/request.ts +13 -1
  274. package/src/update/config-preflight.ts +48 -0
  275. package/src/update/index.ts +15 -1
  276. package/src/usage/client.ts +43 -0
  277. package/src/usage/error-detail.ts +1 -1
  278. package/src/usage/log.ts +4 -0
  279. package/src/usage/source-facets.ts +51 -0
  280. package/src/usage/source-filter.ts +65 -0
  281. package/src/usage/summary.ts +50 -8
  282. package/src/web-search/anthropic-executor.ts +105 -24
  283. package/src/web-search/executor.ts +5 -3
  284. package/src/web-search/loop.ts +2 -1
  285. package/src/web-search/progress-stream.ts +64 -5
  286. package/gui/dist/assets/App-DuNhggE1.js +0 -58
  287. package/gui/dist/assets/index-CynE_Rue.js +0 -94
  288. package/gui/dist/assets/quota-summary-VHFSlUuM.js +0 -1
  289. /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
  290. /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
@@ -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;
@@ -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 };
@@ -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,4 +1,5 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { createHash } from "node:crypto";
2
3
  import { commandInvocation } from "../../lib/win-exec";
3
4
  import { isValidModelDiscoveryModelId } from "../../providers/model-discovery-limits";
4
5
  import { baseScopedEnv, redactSecrets } from "../coding-agent/turn";
@@ -50,6 +51,119 @@ export function parseQoderModelList(stdout: string): QoderModelsResult {
50
51
  return models.length > 0 ? { ok: true, models } : { ok: false, error: "empty" };
51
52
  }
52
53
 
54
+ /**
55
+ * Upper bound for one background `--list-models` run. The CLI starts a full agent runtime before it
56
+ * lists the account's roster; 14.5 s was measured on a working install (#8115), so the former 8 s
57
+ * bound discarded successful listings. Failures still end in the stale/static catalog and back off.
58
+ */
59
+ export const QODER_MODEL_DISCOVERY_TIMEOUT_MS = 30_000;
60
+
61
+ /**
62
+ * Deadline of an interactive caller (the dashboard connection test). When it passes, the caller
63
+ * reports the provider as still discovering; the run itself keeps its background bound.
64
+ */
65
+ export const QODER_INTERACTIVE_DEADLINE_MS = 8_000;
66
+
67
+ /**
68
+ * A successful listing stays joinable this long after it finished, so the catalog re-sync a late
69
+ * result triggers reads it instead of starting a second CLI run.
70
+ */
71
+ export const QODER_DISCOVERY_REUSE_MS = 60_000;
72
+
73
+ type QoderDiscoveryFlight = {
74
+ promise: Promise<QoderModelsResult>;
75
+ succeededAt?: number;
76
+ result?: QoderModelsResult;
77
+ /** Set once a catalog gather stored this result; until then it outranks a fresh cached roster. */
78
+ committed?: true;
79
+ };
80
+ const qoderDiscoveryFlights = new Map<string, QoderDiscoveryFlight>();
81
+
82
+ /**
83
+ * `scope` is the caller's provider name and model-cache generation. The roster is entitlement
84
+ * specific, so one flight serves exactly one PAT; binding it to the generation as well means a
85
+ * cache invalidation (an account or config change) revokes it, and a later caller can neither join
86
+ * a run started before the invalidation nor reuse its result.
87
+ */
88
+ function qoderDiscoveryKey(profile: QoderProfile, apiKey: string, scope: string): string {
89
+ return `${scope}\0${profile.providerId}\0${createHash("sha256").update(apiKey).digest("hex")}`;
90
+ }
91
+
92
+ /** Drop every success past the reuse window, so revoked generations and old PATs leave nothing behind. */
93
+ function sweepQoderDiscoveryFlights(now: number): void {
94
+ for (const [key, flight] of qoderDiscoveryFlights) {
95
+ if (flight.succeededAt !== undefined && now - flight.succeededAt >= QODER_DISCOVERY_REUSE_MS) qoderDiscoveryFlights.delete(key);
96
+ }
97
+ }
98
+
99
+ function joinableFlight(key: string, now: number): QoderDiscoveryFlight | undefined {
100
+ sweepQoderDiscoveryFlights(now);
101
+ const flight = qoderDiscoveryFlights.get(key);
102
+ if (!flight) return undefined;
103
+ if (flight.succeededAt === undefined || now - flight.succeededAt < QODER_DISCOVERY_REUSE_MS) return flight;
104
+ qoderDiscoveryFlights.delete(key);
105
+ return undefined;
106
+ }
107
+
108
+ /** True while a run for this PAT is in flight or its success can still be joined. */
109
+ export function qoderDiscoveryJoinable(profile: QoderProfile, apiKey: string, scope: string, now = Date.now()): boolean {
110
+ return joinableFlight(qoderDiscoveryKey(profile, apiKey, scope), now) !== undefined;
111
+ }
112
+
113
+ /**
114
+ * A successful run no gather has stored yet: one an interactive caller started and stopped waiting
115
+ * for. The gather uses it ahead of a fresh cached roster, which stays in place (and keeps serving
116
+ * as the stale fallback) until this result is accepted.
117
+ */
118
+ export function uncommittedQoderDiscovery(profile: QoderProfile, apiKey: string, scope: string, now = Date.now()): QoderModelsResult | undefined {
119
+ const flight = joinableFlight(qoderDiscoveryKey(profile, apiKey, scope), now);
120
+ return flight?.succeededAt !== undefined && !flight.committed ? flight.result : undefined;
121
+ }
122
+
123
+ /** Record that a gather stored this scope's successful run. */
124
+ export function markQoderDiscoveryCommitted(profile: QoderProfile, apiKey: string, scope: string): void {
125
+ const flight = qoderDiscoveryFlights.get(qoderDiscoveryKey(profile, apiKey, scope));
126
+ if (flight?.succeededAt !== undefined) flight.committed = true;
127
+ }
128
+
129
+ /**
130
+ * One `--list-models` run per PAT, shared by the background catalog gather and interactive callers.
131
+ * A failed run is forgotten when it settles; a successful one stays joinable for the reuse window.
132
+ */
133
+ export function discoverQoderModels(profile: QoderProfile, apiKey: string, scope: string, now = Date.now()): Promise<QoderModelsResult> {
134
+ const key = qoderDiscoveryKey(profile, apiKey, scope);
135
+ const existing = joinableFlight(key, now);
136
+ if (existing) return existing.promise;
137
+ const flight: QoderDiscoveryFlight = {
138
+ promise: Promise.resolve().then(() => fetchQoderModels(profile, apiKey)).then(result => {
139
+ if (result.ok) {
140
+ flight.succeededAt = Date.now();
141
+ flight.result = result;
142
+ // A key whose generation was revoked is never looked up again, so the success expires on
143
+ // its own; the identity check keeps a newer flight under the same key.
144
+ const expiry = setTimeout(() => {
145
+ if (qoderDiscoveryFlights.get(key) === flight) qoderDiscoveryFlights.delete(key);
146
+ }, QODER_DISCOVERY_REUSE_MS);
147
+ expiry.unref?.();
148
+ } else if (qoderDiscoveryFlights.get(key) === flight) qoderDiscoveryFlights.delete(key);
149
+ return result;
150
+ }, error => {
151
+ if (qoderDiscoveryFlights.get(key) === flight) qoderDiscoveryFlights.delete(key);
152
+ throw error;
153
+ }),
154
+ };
155
+ qoderDiscoveryFlights.set(key, flight);
156
+ return flight.promise;
157
+ }
158
+
159
+ export function clearQoderDiscoveryFlightsForTests(): void {
160
+ qoderDiscoveryFlights.clear();
161
+ }
162
+
163
+ export function qoderDiscoveryFlightCountForTests(): number {
164
+ return qoderDiscoveryFlights.size;
165
+ }
166
+
53
167
  function execQoder(command: string, args: readonly string[], options: Parameters<QoderExecFn>[2]): Promise<QoderExecResult> {
54
168
  return new Promise((resolve, reject) => {
55
169
  execFile(command, [...args], { ...options, encoding: "utf8" }, (error, stdout, stderr) => {
@@ -73,7 +187,7 @@ export async function fetchQoderModels(profile: QoderProfile, apiKey: string, de
73
187
  const result = await (deps.exec ?? execQoder)(invocation.file, invocation.args, {
74
188
  ...invocation.options,
75
189
  env,
76
- timeout: deps.timeoutMs ?? 8_000,
190
+ timeout: deps.timeoutMs ?? QODER_MODEL_DISCOVERY_TIMEOUT_MS,
77
191
  maxBuffer: MAX_OUTPUT_BYTES,
78
192
  windowsHide: true,
79
193
  });
@@ -0,0 +1,21 @@
1
+ type Rec = Record<string, unknown>;
2
+ /** Delivered projections and the original records consumed by one Messages collector. */
3
+ export interface MessagesFailureVerdictSink {
4
+ delivered?: { client: string; legacy: Rec }[];
5
+ collected?: Rec;
6
+ collectedProjection?: boolean;
7
+ collectedErrorEvent?: true;
8
+ }
9
+ export function admitMessagesFailure(sink: MessagesFailureVerdictSink | undefined, client: Rec, legacy: Rec): void {
10
+ if (sink) (sink.delivered ??= []).push({ client: JSON.stringify(client), legacy });
11
+ }
12
+ export function collectMessagesFailure(sink: MessagesFailureVerdictSink | undefined, client: Rec): void {
13
+ if (!sink) return;
14
+ sink.collectedErrorEvent = true;
15
+ const next = sink.delivered?.[0];
16
+ if (next?.client === JSON.stringify(client)) {
17
+ sink.delivered!.shift();
18
+ sink.collected = next.legacy;
19
+ sink.collectedProjection = true;
20
+ } else { sink.collected = client; sink.collectedProjection = false; }
21
+ }
@@ -1,3 +1,4 @@
1
+ import { markProxyError } from "../lib/client-error-body";
1
2
  import { isClaudeWebSearchToolName } from "./outbound";
2
3
  import { AnthropicRequestError, isRec, type Rec } from "./inbound-records";
3
4
 
@@ -40,6 +41,18 @@ export function systemToInstructions(system: unknown): string | undefined {
40
41
  return undefined;
41
42
  }
42
43
 
44
+ /**
45
+ * The `instructions` prefix ending at the caller's last cache-marked system block, when blocks
46
+ * follow it. Claude Code ends its system with a per-turn env block; joining everything into one
47
+ * Anthropic system block moved the breakpoint onto those changing bytes, so system and every
48
+ * later breakpoint missed on each turn. The Anthropic adapter splits its system here instead.
49
+ */
50
+ export function systemCachePrefix(system: unknown): string | undefined {
51
+ if (!Array.isArray(system)) return undefined;
52
+ const last = system.findLastIndex(block => isRec(block) && block.cache_control != null);
53
+ return last >= 0 && last < system.length - 1 ? systemToInstructions(system.slice(0, last + 1)) : undefined;
54
+ }
55
+
43
56
  export function toolsToResponses(tools: unknown): Rec[] | undefined {
44
57
  if (!Array.isArray(tools) || tools.length === 0) return undefined;
45
58
  // The shared hosted-search lane cannot enforce these constraints on every destination or
@@ -168,14 +181,14 @@ export function toolChoiceToResponses(choice: unknown, body: Rec): void {
168
181
  case "any": body.tool_choice = "required"; break;
169
182
  case "tool":
170
183
  if (typeof choice.name !== "string" || choice.name.length === 0) {
171
- throw new AnthropicRequestError("tool_choice.tool requires a name");
184
+ throw markProxyError(new AnthropicRequestError("tool_choice.tool requires a name"));
172
185
  }
173
186
  // Anthropic represents hosted WebSearch as a named tool choice, while
174
187
  // Responses requires the choice type to match the hosted declaration.
175
188
  // Preserve forced-tool intent rather than weakening it to `auto`.
176
189
  if (isClaudeWebSearchToolName(choice.name)
177
190
  && (!Array.isArray(body.tools) || !body.tools.some(tool => isRec(tool) && tool.type === "web_search"))) {
178
- throw new AnthropicRequestError("Restricted web search cannot be forced on a translated route without an available search declaration");
191
+ throw markProxyError(new AnthropicRequestError("Restricted web search cannot be forced on a translated route without an available search declaration"));
179
192
  }
180
193
  body.tool_choice = isClaudeWebSearchToolName(choice.name)
181
194
  ? { type: "web_search" }
@@ -1,3 +1,4 @@
1
+ import { markProxyError } from "../lib/client-error-body";
1
2
  import type { OcxConfig, OcxClaudeCodeConfig } from "../types";
2
3
  import { isAnthropicOutputSchema, satisfiesOpenAiStrictSchema } from "../adapters/anthropic-output-schema";
3
4
  import { resolveAlias } from "./alias";
@@ -60,7 +61,7 @@ export function resolveInboundModel(model: string, cc?: OcxClaudeCodeConfig): st
60
61
  // A missing date-shaped ID is ambiguous even after a successful but partial
61
62
  // discovery. Never infer that a genuine native model is invalid or reroute it.
62
63
  if (validDateAlias(base)) throw new DesktopModelMappingUnavailableError();
63
- throw new AnthropicRequestError("Unknown Claude Desktop alias; reapply the Desktop profile from the connected hub");
64
+ throw markProxyError(new AnthropicRequestError("Unknown Claude Desktop alias; reapply the Desktop profile from the connected hub"));
64
65
  }
65
66
  const stripped = model.replace(/-\d{8}$/, "");
66
67
  const dateless = map[stripped];
@@ -1,9 +1,11 @@
1
+ import { markProxyError } from "../lib/client-error-body";
1
2
  export class AnthropicRequestError extends Error {}
2
3
 
3
4
  /** A date-shaped Desktop ID can also name a genuine native model absent from discovery. */
4
5
  export class DesktopModelMappingUnavailableError extends AnthropicRequestError {
5
6
  constructor() {
6
7
  super("Claude Desktop model mapping is unavailable; refresh model discovery or reapply the connected hub profile");
8
+ markProxyError(this);
7
9
  }
8
10
  }
9
11
 
@@ -1,3 +1,5 @@
1
+ import { messagesRolePresentation } from "../lib/messages-error-body";
2
+ import { CLAUDE_CONTEXT_OVERFLOW_MESSAGE, markProxyError } from "../lib/client-error-body";
1
3
  /**
2
4
  * Claude Code inbound: Anthropic Messages API request -> internal /v1/responses body.
3
5
  *
@@ -34,9 +36,9 @@ export function anthropicImageBlockUrl(block: Rec): string | null {
34
36
  const source = block.source;
35
37
  if (!isRec(source)) return null;
36
38
  if (source.type === "file") {
37
- throw new AnthropicRequestError(
39
+ throw markProxyError(new AnthropicRequestError(
38
40
  "File-backed images require native Anthropic passthrough; use base64 or URL images on translated routes.",
39
- );
41
+ ));
40
42
  }
41
43
  if (source.type === "base64" && typeof source.data === "string") {
42
44
  const media = typeof source.media_type === "string" ? source.media_type : "image/png";
@@ -274,7 +276,7 @@ function userMessageToItems(content: unknown, input: Rec[], elide: SkillElisionC
274
276
  pushUserMessage(input, pending);
275
277
  pending = [];
276
278
  if (typeof raw.tool_use_id !== "string" || raw.tool_use_id.length === 0) {
277
- throw new AnthropicRequestError("tool_result requires tool_use_id");
279
+ throw markProxyError(new AnthropicRequestError("tool_result requires tool_use_id"));
278
280
  }
279
281
  input.push({
280
282
  type: "function_call_output",
@@ -319,7 +321,7 @@ function assistantMessageToItems(content: unknown, input: Rec[], budget: Transla
319
321
  case "tool_use": {
320
322
  flush();
321
323
  if (typeof raw.id !== "string" || raw.id.length === 0 || typeof raw.name !== "string" || raw.name.length === 0) {
322
- throw new AnthropicRequestError("tool_use requires id and name");
324
+ throw markProxyError(new AnthropicRequestError("tool_use requires id and name"));
323
325
  }
324
326
  input.push({ type: "function_call", call_id: raw.id, name: raw.name, arguments: JSON.stringify(raw.input ?? {}) });
325
327
  break;
@@ -330,8 +332,8 @@ function assistantMessageToItems(content: unknown, input: Rec[], budget: Transla
330
332
  const signature = typeof raw.signature === "string" ? raw.signature : "";
331
333
  if (signature.startsWith(OCX_REASONING_PREFIX)) {
332
334
  const owned = decodeReasoningEnvelope(signature, budget);
333
- if (!owned) throw new AnthropicRequestError("malformed ocxr1 reasoning signature");
334
- if (Object.hasOwn(owned, "sig")) throw new AnthropicRequestError("OpenCodex reasoning continuity cannot be replayed as an Anthropic signature");
335
+ if (!owned) throw markProxyError(new AnthropicRequestError("malformed ocxr1 reasoning signature"));
336
+ if (Object.hasOwn(owned, "sig")) throw markProxyError(new AnthropicRequestError("OpenCodex reasoning continuity cannot be replayed as an Anthropic signature"));
335
337
  if (owned.nat) {
336
338
  // The provider's own blob goes back only to the model that minted it; any other
337
339
  // model gets the visible text alone, as before this envelope field existed.
@@ -456,7 +458,7 @@ function translateAnthropicRequest(
456
458
  names: blockedNames,
457
459
  };
458
460
  for (const msg of raw.messages) {
459
- if (!isRec(msg)) throw new AnthropicRequestError("each message must be an object");
461
+ if (!isRec(msg)) throw markProxyError(new AnthropicRequestError("each message must be an object"));
460
462
  if (msg.role === "user") userMessageToItems(msg.content, input, elide);
461
463
  else if (msg.role === "assistant") assistantMessageToItems(msg.content, input, budget, raw.model, nativeReasoningReplay);
462
464
  else if (msg.role === "system") {
@@ -468,7 +470,11 @@ function translateAnthropicRequest(
468
470
  input.push({ type: "message", role: "developer", content: [{ type: "input_text", text }] });
469
471
  }
470
472
  }
471
- else throw new AnthropicRequestError(`unsupported message role: ${String(msg.role)}`);
473
+ else {
474
+ const role = messagesRolePresentation(msg.role);
475
+ if (role.coercionFailed) throw markProxyError(new TypeError("unsupported message role: unsupported"));
476
+ throw markProxyError(new AnthropicRequestError(role.overflow ? CLAUDE_CONTEXT_OVERFLOW_MESSAGE : "unsupported message role: unsupported"));
477
+ }
472
478
  }
473
479
 
474
480
  const body: Rec = {
@@ -495,12 +501,12 @@ function translateAnthropicRequest(
495
501
  }
496
502
 
497
503
  function assertAnthropicRequestShape(raw: unknown): asserts raw is Rec & { model: string; messages: unknown[] } {
498
- if (!isRec(raw)) throw new AnthropicRequestError("request body must be a JSON object");
504
+ if (!isRec(raw)) throw markProxyError(new AnthropicRequestError("request body must be a JSON object"));
499
505
  if (typeof raw.model !== "string" || raw.model.length === 0) {
500
- throw new AnthropicRequestError("model is required");
506
+ throw markProxyError(new AnthropicRequestError("model is required"));
501
507
  }
502
508
  if (!Array.isArray(raw.messages) || raw.messages.length === 0) {
503
- throw new AnthropicRequestError("messages must be a non-empty array");
509
+ throw markProxyError(new AnthropicRequestError("messages must be a non-empty array"));
504
510
  }
505
511
  }
506
512