@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
@@ -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
  });
@@ -1,3 +1,4 @@
1
+ import { markProxyError } from "../lib/client-error-body";
1
2
  import type { AdapterEvent, OcxMessagePhase, OcxUsage } from "../types";
2
3
  import type { TranslatorBudget } from "../lib/translator-budget";
3
4
  import { decodeServerSentEvents } from "../lib/sse-decoder";
@@ -700,7 +701,7 @@ export async function* translateZedOpenAiStream(
700
701
  yield* flushUnclosed(false);
701
702
  if (terminal) return;
702
703
  if (unfinished) {
703
- yield { type: "incomplete", reason: "adapter_eof", ...(usage ? { usage } : {}) };
704
+ yield markProxyError({ type: "incomplete" as const, reason: "adapter_eof", ...(usage ? { usage } : {}) });
704
705
  return;
705
706
  }
706
707
  const done: AdapterEvent = {
@@ -6,6 +6,7 @@ import {
6
6
  REPLAY_REFUSED_STATUS,
7
7
  retainReplayRefusal,
8
8
  } from "../lib/upstream-retry";
9
+ import { formatClientRetryAfter } from "../lib/client-retry-after";
9
10
  import {
10
11
  adapterFailureFromMessage,
11
12
  classifyError,
@@ -34,6 +35,12 @@ export function upstreamCodeForComboFailure(response: Response, bodyCode: string
34
35
  : bodyCode;
35
36
  }
36
37
 
38
+ /** Preserve formatted quota-code provenance when lifecycle helpers rebuild a response. */
39
+ export function carryFormattedQuotaSource(source: Response, target: Response): Response {
40
+ if (formattedQuotaSources.has(source)) formattedQuotaSources.set(target, formattedQuotaSources.get(source)!);
41
+ return target;
42
+ }
43
+
37
44
  export function formatErrorResponse(
38
45
  status: number,
39
46
  type: string,
@@ -93,7 +100,8 @@ export function formatErrorResponse(
93
100
  : error.code === SPEND_LEDGER_STORAGE_UNAVAILABLE_CODE ? 503
94
101
  : isReplayRefusalCode(error.code) ? REPLAY_REFUSED_STATUS : status;
95
102
  const headers = new Headers({ "Content-Type": "application/json" });
96
- const retryAfter = options?.retryAfter?.trim();
103
+ // Re-emitted as an integer this proxy formats; the incoming text is never echoed.
104
+ const retryAfter = formatClientRetryAfter(options?.retryAfter);
97
105
  if (error.code !== CYBER_POLICY_ERROR_CODE
98
106
  && !replayBlocked
99
107
  && retryAfter
@@ -155,6 +163,7 @@ export function formatUsageLimitReachedResponse(message: string, resetsAtMs: num
155
163
  ...(resetsAtMs !== null ? { resets_at: Math.ceil(resetsAtMs / 1000) } : {}),
156
164
  };
157
165
  const headers = new Headers({ "Content-Type": "application/json" });
158
- if (retryAfterSeconds !== null) headers.set("Retry-After", String(retryAfterSeconds));
166
+ const advice = retryAfterSeconds !== null ? formatClientRetryAfter(retryAfterSeconds) : undefined;
167
+ if (advice !== undefined) headers.set("Retry-After", advice);
159
168
  return new Response(JSON.stringify({ error }), { status: 429, headers });
160
169
  }
@@ -1,3 +1,4 @@
1
+ import { UNDECLARED_TOOL_CALL_MESSAGE } from "../lib/client-error-body";
1
2
  import { anthropicProgressItems } from "../responses/anthropic-progress";
2
3
  import type {
3
4
  AdapterEvent,
@@ -494,7 +495,7 @@ function buildResponseJSONWithBudget(
494
495
  ) {
495
496
  errorEvent = {
496
497
  type: "error",
497
- message: `routed provider emitted undeclared client tool "${effectiveName}"; only request-declared tools may be called`,
498
+ message: UNDECLARED_TOOL_CALL_MESSAGE,
498
499
  status: 502,
499
500
  errorType: "upstream_error",
500
501
  };
package/src/bridge/sse.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { UNDECLARED_TOOL_CALL_MESSAGE, isProxyError, rememberProxyIncomplete, carryProxyIncompleteContext } from "../lib/client-error-body";
1
2
  import { anthropicProgressItems } from "../responses/anthropic-progress";
2
3
  import type {
3
4
  AdapterEvent,
@@ -23,7 +24,7 @@ import {
23
24
  mayBecomePatchEnvelope,
24
25
  repairFreeformToolInput,
25
26
  } from "../responses/apply-patch-envelope";
26
- import { progressiveFreeformInput } from "../responses/progressive-freeform-input";
27
+ import { ProgressiveFreeformInputReader } from "../responses/progressive-freeform-input";
27
28
  import { encodeCompactionSummary, releaseCompactionCiphertextLease } from "../responses/compaction";
28
29
  import { compileCodeModeHelperInput, resolveCodeModeHelperName } from "../responses/code-mode-helper-compat";
29
30
  import { mayBecomeCodeModeShellInput } from "../responses/code-mode-shell-input";
@@ -76,6 +77,7 @@ export function bridgeToResponsesSSE(
76
77
  heartbeatMs = 2_000,
77
78
  options?: MaxOutputCompletionOptions & {
78
79
  responseId?: string;
80
+ proxyErrorContext?: object;
79
81
  /** Trusted structural grouping only; never provider state or execution authority. */
80
82
  outputItemIds?: { next(kind: "message" | "reasoning" | "function_call" | "custom_tool_call" | "tool_search_call"): string };
81
83
 
@@ -165,6 +167,7 @@ export function bridgeToResponsesSSE(
165
167
  };
166
168
  },
167
169
  ): ReadableStream<Uint8Array> {
170
+ const proxyIncompleteContext = options?.proxyErrorContext ?? {};
168
171
  const replayCacheScope = options?.replayCacheScope;
169
172
  const maxOutputCompletion = createMaxOutputCompletion(options);
170
173
  const outputItemId = (kind: "message" | "reasoning" | "function_call" | "custom_tool_call" | "tool_search_call", prefix: string): string =>
@@ -477,7 +480,7 @@ export function bridgeToResponsesSSE(
477
480
  // Full assistant text of a compaction turn (across message boundaries) — becomes the
478
481
  // synthetic compaction item's payload on done.
479
482
  let compaction = emptyChunks();
480
- let currentToolCall: { itemId: string; outputIndex: number; callId: string; name: string; args: string; argsBytes: number; namespace?: string; freeform?: boolean; toolSearch?: boolean; inputEmitted?: string; codeModeHelperName?: string; providerMetadata?: OcxProviderOpaqueToolCallMetadata } | null = null;
483
+ let currentToolCall: { itemId: string; outputIndex: number; callId: string; name: string; args: string; argsBytes: number; namespace?: string; freeform?: boolean; toolSearch?: boolean; inputEmitted?: string; freeformReader?: ProgressiveFreeformInputReader; codeModeHelperName?: string; providerMetadata?: OcxProviderOpaqueToolCallMetadata } | null = null;
481
484
  // Open native web-search cell (between begin and end). Holds the output index allocated on
482
485
  // begin so the matching done reuses it; closed as `failed` if the stream terminates early.
483
486
  let currentWebSearch: { itemId: string; eventId: string; outputIndex: number } | null = null;
@@ -1092,7 +1095,7 @@ export function bridgeToResponsesSSE(
1092
1095
  const failure = responseError(
1093
1096
  502,
1094
1097
  "upstream_error",
1095
- `routed provider emitted undeclared client tool "${effectiveName}"; only request-declared tools may be called`,
1098
+ UNDECLARED_TOOL_CALL_MESSAGE,
1096
1099
  );
1097
1100
  emit("response.failed", {
1098
1101
  response: {
@@ -1154,7 +1157,9 @@ export function bridgeToResponsesSSE(
1154
1157
  // is the same disagreement in the other direction.
1155
1158
  const ownsFreeformGrammar = currentToolCall.namespace === undefined
1156
1159
  || currentToolCall.namespace === "functions";
1157
- const full = progressiveFreeformInput(
1160
+ // One reader per call resumes where the previous delta stopped.
1161
+ currentToolCall.freeformReader ??= new ProgressiveFreeformInputReader();
1162
+ const full = currentToolCall.freeformReader.update(
1158
1163
  currentToolCall.args,
1159
1164
  ownsFreeformGrammar ? currentToolCall.name : "",
1160
1165
  );
@@ -1330,6 +1335,7 @@ export function bridgeToResponsesSSE(
1330
1335
  break;
1331
1336
  }
1332
1337
  case "incomplete": {
1338
+ if (isProxyError(event) && event.reason === "adapter_eof") rememberProxyIncomplete(proxyIncompleteContext, "adapter_eof");
1333
1339
  if (currentMsg) closeCurrentMessage();
1334
1340
  if (currentReasoning) closeCurrentReasoning();
1335
1341
  if (currentRawReasoning) closeCurrentRawReasoning();
@@ -1470,6 +1476,7 @@ export function bridgeToResponsesSSE(
1470
1476
  })) return;
1471
1477
  options?.onUsage?.(undefined);
1472
1478
  await awaitThoughtSignatureDurability();
1479
+ rememberProxyIncomplete(proxyIncompleteContext, "adapter_eof");
1473
1480
  emit("response.incomplete", {
1474
1481
  response: {
1475
1482
  ...responseSnapshot("incomplete", finishedItems),
@@ -1526,6 +1533,7 @@ export function bridgeToResponsesSSE(
1526
1533
  // barrier is not awaited on the stall-timeout kill path. The in-memory store is
1527
1534
  // already updated; only a crash between here and the queued write loses it,
1528
1535
  // which is the pre-#1926 status quo for an already-abnormal termination.
1536
+ rememberProxyIncomplete(proxyIncompleteContext, "upstream_stall_timeout");
1529
1537
  emit("response.incomplete", {
1530
1538
  response: {
1531
1539
  ...responseSnapshot("incomplete", finishedItems),
@@ -1558,7 +1566,7 @@ export function bridgeToResponsesSSE(
1558
1566
  }, heartbeatMs);
1559
1567
  };
1560
1568
 
1561
- return new ReadableStream<Uint8Array>({
1569
+ return carryProxyIncompleteContext(proxyIncompleteContext, new ReadableStream<Uint8Array>({
1562
1570
  start(streamController) {
1563
1571
  controller = streamController;
1564
1572
  startStream();
@@ -1577,5 +1585,5 @@ export function bridgeToResponsesSSE(
1577
1585
  releasePendingWebSources();
1578
1586
  disposeOwnedBudget();
1579
1587
  },
1580
- });
1588
+ }));
1581
1589
  }
@@ -0,0 +1,21 @@
1
+ import type { ClientErrorContract } from "../lib/client-error-body";
2
+ import { isCyberPolicyMessage, isTerminalRefusalCode } from "../lib/errors";
3
+ export interface FailureVerdict { status: number; type: string; code: string | null; message: string }
4
+ /** Passed explicitly through producer, lifetime wrappers and collector for one response. */
5
+ export interface FailureVerdictSink { verdict?: FailureVerdict; contract?: ClientErrorContract; proxyAuthored?: boolean }
6
+ export function legacyStreamErrorStatus(message: string): number {
7
+ const lower = message.toLowerCase();
8
+ if (isCyberPolicyMessage(lower)) return 400;
9
+ if (lower.includes("truncated")) return 502;
10
+ if (lower.includes("rate") || lower.includes("429")) return 429;
11
+ if (lower.includes("unauthor") || lower.includes("401") || lower.includes("api key")) return 401;
12
+ if (lower.includes("not found") || lower.includes("404")) return 404;
13
+ if (lower.includes("invalid") || lower.includes("400")) return 400;
14
+ return 502;
15
+ }
16
+ export function legacyFailureVerdict(payload: Record<string, unknown>): FailureVerdict {
17
+ const error = payload.error as { message: string; type: string; code: string | null };
18
+ const { message, code } = error;
19
+ return { message, code, type: code === "translation_buffer_limit" ? "upstream_error" : error.type,
20
+ status: code === "translation_buffer_limit" ? 502 : isTerminalRefusalCode(code) || isCyberPolicyMessage(message) ? 400 : legacyStreamErrorStatus(message) };
21
+ }
@@ -1,3 +1,7 @@
1
+ import { boundedServiceTier } from "../lib/response-service-tier";
2
+ import { isLikelyRealAnthropicThinkingSignature } from "../responses/reasoning-envelope";
3
+ import { ownedChatErrorPayload, CLIENT_ERROR_CONTRACTS, hasProxyErrorMessage, hasProxyIncomplete, type ClientErrorContract } from "../lib/client-error-body";
4
+ import { legacyFailureVerdict, legacyStreamErrorStatus as streamErrorStatus, type FailureVerdictSink } from "./failure-verdict";
1
5
  /**
2
6
  * Chat Completions outbound: internal /v1/responses output -> OpenAI Chat Completions shapes.
3
7
  *
@@ -126,16 +130,6 @@ export function isChatCompletionsStreamError(err: unknown): err is ChatCompletio
126
130
  return err instanceof ChatCompletionsStreamError;
127
131
  }
128
132
 
129
- function streamErrorStatus(message: string): number {
130
- const lower = message.toLowerCase();
131
- if (isCyberPolicyMessage(lower)) return 400;
132
- if (lower.includes("truncated")) return 502;
133
- if (lower.includes("rate") || lower.includes("429")) return 429;
134
- if (lower.includes("unauthor") || lower.includes("401") || lower.includes("api key")) return 401;
135
- if (lower.includes("not found") || lower.includes("404")) return 404;
136
- if (lower.includes("invalid") || lower.includes("400")) return 400;
137
- return 502;
138
- }
139
133
 
140
134
  export function dataFrame(payload: Rec | "[DONE]"): string {
141
135
  if (payload === "[DONE]") return "data: [DONE]\n\n";
@@ -169,6 +163,8 @@ export function appendedUtf8Bytes(previous: string, previousBytes: number, fragm
169
163
 
170
164
  /** Details a streamed Chat failure carries into its error frame. */
171
165
  export interface ChatCompletionsStreamFailure {
166
+ contract?: ClientErrorContract;
167
+ proxyAuthored?: boolean;
172
168
  code?: string | null;
173
169
  type?: string;
174
170
  status?: number;
@@ -179,7 +175,7 @@ export interface ChatCompletionsStreamFailure {
179
175
  * fixed, bounded failures that must be delivered even when the translation budget is exhausted.
180
176
  * Provider text is redacted; the two fixed failures carry no provider text at all.
181
177
  */
182
- export function chatCompletionsStreamErrorPayload(
178
+ function legacyChatCompletionsStreamErrorPayload(
183
179
  message: string,
184
180
  details?: ChatCompletionsStreamFailure,
185
181
  ): { payload: Rec; bounded: boolean } {
@@ -224,6 +220,25 @@ export function chatCompletionsStreamErrorPayload(
224
220
  };
225
221
  }
226
222
 
223
+ export function chatCompletionsStreamErrorPayload(message: string, details?: ChatCompletionsStreamFailure) {
224
+ const legacy = legacyChatCompletionsStreamErrorPayload(message, details);
225
+ const verdict = legacyFailureVerdict(legacy.payload);
226
+ const error = legacy.payload.error as { message: string; type: string; code: string | null };
227
+ return { bounded: legacy.bounded, verdict, payload: details?.proxyAuthored ? legacy.payload : ownedChatErrorPayload({
228
+ status: verdict.status, type: error.type, code: error.code, contract: details?.contract,
229
+ evidence: { status: verdict.status, type: error.type, code: error.code ?? undefined, message },
230
+ }) };
231
+ }
232
+
233
+ export function ownedChatErrorResponse(status: number, message: string, type?: string, code?: string | null, contract?: ClientErrorContract, proxyAuthored = false): Response {
234
+ const legacyBody = chatCompletionsErrorBody(status, message, type, code);
235
+ const legacy = legacyBody.error as { type: string; code: string | null };
236
+ const finalStatus = legacy.code === CYBER_POLICY_ERROR_CODE ? 400 : status;
237
+ return new Response(JSON.stringify(proxyAuthored ? legacyBody : ownedChatErrorPayload({ status: finalStatus, type: legacy.type, code: legacy.code, contract,
238
+ evidence: { status: finalStatus, type, code: code ?? undefined, message } })),
239
+ { status: finalStatus, headers: { "Content-Type": "application/json" } });
240
+ }
241
+
227
242
  /** How a Responses `response.failed` error object becomes a streamed Chat failure. */
228
243
  export function chatCompletionsFailedResponse(error: Rec): { message: string; details: ChatCompletionsStreamFailure } {
229
244
  const message = typeof error.message === "string" ? error.message : "upstream request failed";
@@ -250,7 +265,7 @@ export function chatCompletionsFailedResponse(error: Rec): { message: string; de
250
265
  export function chatCompletionsIncompleteOutcome(
251
266
  reason: unknown,
252
267
  message: unknown,
253
- ): { finishReason: "length" | "content_filter" } | { failMessage: string } {
268
+ ): { finishReason: "length" | "content_filter" } | { failMessage: string; originalFailMessage: string } {
254
269
  // Upstream Responses endpoints do not all use OpenAI's `max_output_tokens`: Volcengine Ark
255
270
  // (Coding Plan `/responses`) sends `incomplete_details.reason: "length"` for a hit output cap.
256
271
  // Read the reason through the shared truncation vocabulary so such a turn ends with
@@ -261,7 +276,8 @@ export function chatCompletionsIncompleteOutcome(
261
276
  if (truncation === "content_filter") return { finishReason: "content_filter" };
262
277
  const why = typeof reason === "string" ? reason : "unknown";
263
278
  return {
264
- failMessage: typeof message === "string" && message.length > 0
279
+ failMessage: CLIENT_ERROR_CONTRACTS.stream_incomplete,
280
+ originalFailMessage: typeof message === "string" && message.length > 0
265
281
  ? message
266
282
  : `upstream stream ended early (${why})`,
267
283
  };
@@ -281,7 +297,7 @@ function refusalTranslationError(): ChatCompletionsStreamError {
281
297
  export function responsesSseToChatCompletionsSse(
282
298
  upstream: ReadableStream<Uint8Array>,
283
299
  model: string,
284
- opts: { translatorBudget: TranslatorBudget },
300
+ opts: { translatorBudget: TranslatorBudget; failureVerdictSink?: FailureVerdictSink; proxyErrorContext?: object },
285
301
  ): ReadableStream<Uint8Array> {
286
302
  const translatorBudget = opts.translatorBudget;
287
303
  const encoder = new TextEncoder();
@@ -610,7 +626,7 @@ export function responsesSseToChatCompletionsSse(
610
626
  terminated = true;
611
627
  releaseRefusals();
612
628
  };
613
- const fail = (message: string, details?: { code?: string | null; type?: string; status?: number }) => {
629
+ const fail = (message: string, details?: ChatCompletionsStreamFailure) => {
614
630
  if (terminated) return;
615
631
  terminated = true;
616
632
  failed = true;
@@ -623,13 +639,14 @@ export function responsesSseToChatCompletionsSse(
623
639
  // Deliver the error frame then close the stream abnormally (no [DONE]).
624
640
  // Do not controller.error() — that can drop already-enqueued bytes from consumers
625
641
  // like response.text().
626
- const { payload, bounded } = chatCompletionsStreamErrorPayload(message, details);
642
+ const { payload, bounded, verdict } = chatCompletionsStreamErrorPayload(message, details);
627
643
  try {
628
644
  const frame = encoder.encode(dataFrame(payload));
629
645
  // These fixed, bounded failures must survive even when decoder-owned input
630
646
  // still fills the budget. They contain no provider text or IDs.
631
647
  if (bounded) controller.enqueue(frame);
632
648
  else enqueueLiveFrame(frame);
649
+ if (opts.failureVerdictSink) { opts.failureVerdictSink.verdict = verdict; opts.failureVerdictSink.contract = details?.contract; opts.failureVerdictSink.proxyAuthored = details?.proxyAuthored; }
633
650
  emittedFrames++;
634
651
  } catch {
635
652
  /* controller may already be closed */
@@ -789,14 +806,15 @@ export function responsesSseToChatCompletionsSse(
789
806
  // upstream_stall_timeout / adapter_eof / proxy-synthesized incompletes are
790
807
  // failures, not early finishes: emit an error frame and close WITHOUT
791
808
  // [DONE] instead of a success-looking stop/tool_calls + [DONE].
792
- fail(outcome.failMessage);
809
+ fail(outcome.originalFailMessage, { contract: "stream_incomplete",
810
+ proxyAuthored: hasProxyIncomplete(opts.proxyErrorContext ?? upstream, details.reason, details.message) });
793
811
  }
794
812
  break;
795
813
  }
796
814
  case "response.failed": {
797
815
  const response = isRec(data.response) ? data.response : {};
798
816
  const failure = chatCompletionsFailedResponse(isRec(response.error) ? response.error : {});
799
- fail(failure.message, failure.details);
817
+ fail(failure.message, { ...failure.details, proxyAuthored: hasProxyErrorMessage(opts.proxyErrorContext, failure.message, failure.details) });
800
818
  break;
801
819
  }
802
820
  default:
@@ -1003,11 +1021,105 @@ export function responsesJsonToChatCompletion(json: unknown, model: string, tran
1003
1021
  };
1004
1022
  }
1005
1023
 
1024
+ function flatNumericFields(value: unknown, fields: readonly string[]): Rec {
1025
+ const out: Rec = {};
1026
+ if (isRec(value)) for (const field of fields) {
1027
+ const number = value[field];
1028
+ if (typeof number === "number" && Number.isFinite(number) && number >= 0) out[field] = number;
1029
+ }
1030
+ return out;
1031
+ }
1032
+ function flatCollectorUsage(value: unknown): Rec | undefined {
1033
+ if (!isRec(value)) return undefined;
1034
+ const out = flatNumericFields(value, ["prompt_tokens", "completion_tokens", "total_tokens"]);
1035
+ for (const [field, counters] of [
1036
+ ["prompt_tokens_details", ["cached_tokens", "audio_tokens"]],
1037
+ ["completion_tokens_details", ["reasoning_tokens", "audio_tokens", "accepted_prediction_tokens", "rejected_prediction_tokens"]],
1038
+ ] as const) {
1039
+ const details = flatNumericFields(value[field], counters);
1040
+ if (Object.keys(details).length > 0) out[field] = details;
1041
+ }
1042
+ return out;
1043
+ }
1044
+ const FLAT_FINISH_REASONS: ReadonlyMap<string, string> = new Map([
1045
+ ["stop", "stop"], ["length", "length"], ["tool_calls", "tool_calls"], ["content_filter", "content_filter"],
1046
+ ["function_call", "function_call"], ["error", "error"],
1047
+ ]);
1048
+ function flatCollectorChoices(value: unknown): Rec[] | undefined {
1049
+ if (!Array.isArray(value)) return undefined;
1050
+ const first = value[0];
1051
+ if (!isRec(first)) return [];
1052
+ const choice: Rec = {};
1053
+ if (typeof first.finish_reason === "string") choice.finish_reason = FLAT_FINISH_REASONS.get(first.finish_reason) ?? "error";
1054
+ if (!isRec(first.delta)) return [choice];
1055
+ const original = first.delta;
1056
+ const delta: Rec = {};
1057
+ for (const field of ["content", "reasoning_content"]) if (typeof original[field] === "string") delta[field] = original[field];
1058
+ if (original.refusal !== undefined) {
1059
+ // Preserve the collector's invalid-refusal verdict without retaining an invalid object.
1060
+ delta.refusal = typeof original.refusal === "string" || original.refusal === null ? original.refusal : false;
1061
+ }
1062
+ if (Array.isArray(original.reasoning_details)) delta.reasoning_details = original.reasoning_details.filter(isRec).flatMap(detail => {
1063
+ const type = detail.type === "reasoning.text" ? "reasoning.text" : detail.type === "reasoning.encrypted" ? "reasoning.encrypted"
1064
+ : detail.type === "reasoning.summary" ? "reasoning.summary" : undefined;
1065
+ if (!type) return [];
1066
+ const entry: Rec = { type };
1067
+ if (type === "reasoning.text") {
1068
+ if (typeof detail.text === "string") entry.text = detail.text;
1069
+ if (typeof detail.signature === "string" && isLikelyRealAnthropicThinkingSignature(detail.signature)) entry.signature = detail.signature;
1070
+ } else if (type === "reasoning.summary") {
1071
+ if (typeof detail.summary !== "string") return [];
1072
+ entry.summary = detail.summary;
1073
+ } else if (typeof detail.data === "string") entry.data = detail.data;
1074
+ if (typeof detail.format === "string" && /^[A-Za-z][A-Za-z0-9._-]{0,95}-v[1-9][0-9]{0,3}$/.test(detail.format)) entry.format = detail.format;
1075
+ if (typeof detail.id === "string" && detail.id.length <= 128
1076
+ && /^(?:reasoning[-_]|summary[-_]|rs[-_])[A-Za-z0-9._:-]+$/.test(detail.id)) entry.id = detail.id;
1077
+ if (typeof detail.index === "number" && Number.isSafeInteger(detail.index) && detail.index >= 0) entry.index = detail.index;
1078
+ return [entry];
1079
+ });
1080
+ if (Array.isArray(original.tool_calls)) delta.tool_calls = original.tool_calls.filter(isRec).map(tool => {
1081
+ const call: Rec = {};
1082
+ if (typeof tool.index === "number" && Number.isSafeInteger(tool.index) && tool.index >= 0) call.index = tool.index;
1083
+ if (typeof tool.id === "string") call.id = tool.id;
1084
+ const fn: Rec = {};
1085
+ if (isRec(tool.function)) for (const field of ["name", "arguments"]) if (typeof tool.function[field] === "string") fn[field] = tool.function[field];
1086
+ call.function = fn;
1087
+ return call;
1088
+ });
1089
+ choice.delta = delta;
1090
+ return [choice];
1091
+ }
1092
+
1093
+ /** Client fields from ordinary chunks needed only by a buffered native collector. */
1094
+ export class ChatCompletionsCollectorSource {
1095
+ private pending: Array<{ wire: string; fields: string; bytes: number }> = [];
1096
+ constructor(private readonly budget: TranslatorBudget) {}
1097
+ retain(wire: string, chunk: Rec): void {
1098
+ const fields = JSON.stringify({ usage: flatCollectorUsage(chunk.usage), service_tier: boundedServiceTier(chunk.service_tier), choices: flatCollectorChoices(chunk.choices) });
1099
+ const bytes = Buffer.byteLength(wire) + Buffer.byteLength(fields) + 64;
1100
+ this.budget.chargeRetained(bytes, { kind: "retained_collectors" });
1101
+ this.pending.push({ wire, fields, bytes });
1102
+ }
1103
+ take(wire: string): Rec | undefined {
1104
+ const next = this.pending[0];
1105
+ if (!next || next.wire !== wire) return undefined;
1106
+ this.pending.shift();
1107
+ this.budget.releaseRetained(next.bytes, { kind: "retained_collectors" });
1108
+ return JSON.parse(next.fields) as Rec;
1109
+ }
1110
+ clear(): void {
1111
+ for (const entry of this.pending) this.budget.releaseRetained(entry.bytes, { kind: "retained_collectors" });
1112
+ this.pending.length = 0;
1113
+ }
1114
+ }
1115
+
1006
1116
  /** Fold a Chat Completions SSE stream into a final completion JSON. */
1007
1117
  export async function collectChatCompletion(
1008
1118
  stream: ReadableStream<Uint8Array>,
1009
1119
  model: string,
1010
1120
  translatorBudget: TranslatorBudget,
1121
+ failureVerdictSink?: FailureVerdictSink,
1122
+ collectorSource?: ChatCompletionsCollectorSource,
1011
1123
  ): Promise<Rec> {
1012
1124
  const reader = stream.getReader();
1013
1125
  const decoder = new TextDecoder();
@@ -1055,10 +1167,15 @@ export async function collectChatCompletion(
1055
1167
  for (let frame = buffer.next(); frame; frame = buffer.next()) {
1056
1168
  const data = sseDataPayload(frame.block)?.trim();
1057
1169
  if (!data || data === "[DONE]") continue;
1058
- let parsed: unknown;
1059
- try { parsed = JSON.parse(data); } catch { continue; }
1060
- if (!isRec(parsed)) continue;
1170
+ let decoded: unknown;
1171
+ try { decoded = JSON.parse(data); } catch { continue; }
1172
+ if (!isRec(decoded)) continue;
1173
+ const parsed = collectorSource?.take(data) ?? decoded;
1061
1174
  if (isRec(parsed.error)) {
1175
+ if (failureVerdictSink?.verdict) {
1176
+ const verdict = failureVerdictSink.verdict;
1177
+ throw new ChatCompletionsStreamError(verdict.message, verdict);
1178
+ }
1062
1179
  const message = typeof parsed.error.message === "string"
1063
1180
  ? parsed.error.message
1064
1181
  : "upstream request failed";
@@ -1157,6 +1274,7 @@ export async function collectChatCompletion(
1157
1274
  // Preserve the previous EOF contract: only delimiter-terminated events are collected.
1158
1275
  // A partial final frame is discarded, with its retained input ownership released.
1159
1276
  buffer.clear();
1277
+ collectorSource?.clear();
1160
1278
  reader.releaseLock();
1161
1279
  }
1162
1280
 
@@ -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" }