@bitkyc08/opencodex 2.91.0 → 2.93.0-preview.20261027

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 (360) hide show
  1. package/bin/ocx.mjs +47 -8
  2. package/gui/dist/assets/App-CJZoq-uF.js +58 -0
  3. package/gui/dist/assets/{Tray-BuLy7hL1.js → Tray-BWQPcgZn.js} +1 -1
  4. package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
  5. package/gui/dist/assets/index-Xfct8owH.js +94 -0
  6. package/gui/dist/assets/quota-summary-DxToX1rV.js +1 -0
  7. package/gui/dist/index.html +2 -2
  8. package/gui/dist/provider-icons/workbuddy-color.svg +29 -0
  9. package/package.json +8 -7
  10. package/src/adapters/anthropic.ts +28 -5
  11. package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
  12. package/src/adapters/coding-agent/profile.ts +54 -16
  13. package/src/adapters/coding-agent/turn.ts +30 -2
  14. package/src/adapters/command-code.ts +114 -7
  15. package/src/adapters/cursor/native-exec-fs.ts +11 -9
  16. package/src/adapters/devin/live-models.ts +4 -0
  17. package/src/adapters/google-vertex-endpoint.ts +9 -1
  18. package/src/adapters/google-vertex-key-project.ts +223 -0
  19. package/src/adapters/google-wire-compiler.ts +1 -2
  20. package/src/adapters/google.ts +13 -3
  21. package/src/adapters/kiro/reasoning.ts +2 -0
  22. package/src/adapters/kiro-refusal.ts +6 -1
  23. package/src/adapters/kiro-wire.ts +1 -1
  24. package/src/adapters/openai-chat/messages.ts +8 -2
  25. package/src/adapters/openai-chat/passthrough.ts +35 -14
  26. package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
  27. package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
  28. package/src/adapters/openai-chat/required-tool-result.ts +64 -0
  29. package/src/adapters/openai-chat/tool-name-registry.ts +3 -1
  30. package/src/adapters/openai-chat.ts +9 -10
  31. package/src/adapters/openai-responses/passthrough.ts +7 -4
  32. package/src/adapters/openai-responses/reasoning.ts +13 -0
  33. package/src/adapters/openai-responses/request-strips.ts +60 -0
  34. package/src/adapters/qoder/adapter.ts +129 -8
  35. package/src/adapters/qoder/scaffold-guard.ts +5 -0
  36. package/src/adapters/reasoning-controls.ts +16 -0
  37. package/src/adapters/registry.ts +5 -0
  38. package/src/adapters/tool-call-id.ts +1 -3
  39. package/src/adapters/workbuddy-schema.ts +61 -0
  40. package/src/adapters/workbuddy.ts +68 -0
  41. package/src/bridge/errors.ts +27 -0
  42. package/src/bridge/response-json.ts +1 -1
  43. package/src/bridge/sse.ts +1 -1
  44. package/src/bridge.ts +1 -1
  45. package/src/chat/inbound.ts +4 -1
  46. package/src/chat/outbound.ts +20 -6
  47. package/src/chat/reasoning-details.ts +28 -5
  48. package/src/claude/desktop-first-party.ts +54 -4
  49. package/src/claude/desktop-picker.ts +11 -8
  50. package/src/claude/first-party-settings.ts +3 -1
  51. package/src/claude/inbound.ts +2 -1
  52. package/src/claude/intercept/local-ca.ts +2 -1
  53. package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
  54. package/src/claude/intercept/picker-ca-startup.ts +3 -1
  55. package/src/claude/intercept/picker-models.ts +6 -3
  56. package/src/claude/intercept/picker-runtime.ts +3 -2
  57. package/src/claude/intercept/runtime.ts +6 -3
  58. package/src/claude/model-info.ts +31 -8
  59. package/src/cli/account-api.ts +11 -0
  60. package/src/cli/capabilities-agents-routing.ts +3 -3
  61. package/src/cli/capabilities-base.ts +7 -1
  62. package/src/cli/capabilities-observe-system.ts +10 -0
  63. package/src/cli/claude-desktop.ts +9 -8
  64. package/src/cli/claude.ts +3 -2
  65. package/src/cli/codex-cli-update.ts +8 -0
  66. package/src/cli/codex-shim-autorestore.ts +9 -0
  67. package/src/cli/combo-result.ts +13 -0
  68. package/src/cli/combo-stats.ts +3 -0
  69. package/src/cli/combo.ts +83 -41
  70. package/src/cli/cross-home-owner.ts +13 -1
  71. package/src/cli/dispatch.ts +25 -6
  72. package/src/cli/ensure-desired-integrations.ts +8 -6
  73. package/src/cli/export-command.ts +4 -1
  74. package/src/cli/help.ts +2 -1
  75. package/src/cli/index.ts +45 -45
  76. package/src/cli/integration-plan-dto.ts +4 -0
  77. package/src/cli/launcher-context.ts +49 -2
  78. package/src/cli/link.ts +45 -32
  79. package/src/cli/opencode.ts +20 -9
  80. package/src/cli/provider.ts +2 -1
  81. package/src/cli/registry.ts +6 -4
  82. package/src/cli/root.ts +9 -0
  83. package/src/cli/status.ts +59 -1
  84. package/src/cli/stop-restore.ts +113 -0
  85. package/src/cli/sync-expectation.ts +60 -0
  86. package/src/cli/uninstall-integrations.ts +41 -7
  87. package/src/cli/usage-compare.ts +68 -12
  88. package/src/client/connect.ts +40 -3
  89. package/src/client/link-home.ts +10 -1
  90. package/src/client/link-ingress.ts +1 -1
  91. package/src/client/link-readiness.ts +97 -0
  92. package/src/client/link-relay-transport.ts +79 -11
  93. package/src/client/link-relay.ts +74 -15
  94. package/src/client/link-tunnel.ts +45 -18
  95. package/src/client/machine-api.ts +3 -1
  96. package/src/client/machine-listener.ts +20 -2
  97. package/src/client/runtime.ts +20 -2
  98. package/src/client/sync-expectation.ts +118 -0
  99. package/src/clients/config-export/agent-clients.ts +96 -0
  100. package/src/clients/config-export/contracts.ts +25 -7
  101. package/src/clients/config-export/qoder.ts +38 -23
  102. package/src/clients/config-export/reasoning-metadata.ts +55 -8
  103. package/src/clients/config-export.ts +12 -0
  104. package/src/clients/lazycodex.ts +7 -2
  105. package/src/clients/reasoning-controls.ts +49 -0
  106. package/src/codex/account-store.ts +17 -3
  107. package/src/codex/app-server-restart-service.ts +6 -5
  108. package/src/codex/auth-api/account-identity.ts +14 -0
  109. package/src/codex/auth-api/account-list.ts +29 -2
  110. package/src/codex/auth-api/http.ts +13 -0
  111. package/src/codex/auth-api/main-account-probe.ts +2 -2
  112. package/src/codex/auth-api/pool-mode-gate.ts +16 -3
  113. package/src/codex/auth-api/pool-quota-probe.ts +15 -0
  114. package/src/codex/auth-context.ts +15 -12
  115. package/src/codex/catalog/build-entries.ts +22 -0
  116. package/src/codex/catalog/configured-tiers.ts +70 -0
  117. package/src/codex/catalog/effort.ts +52 -11
  118. package/src/codex/catalog/gather-capture.ts +5 -2
  119. package/src/codex/catalog/heal-observation.ts +155 -13
  120. package/src/codex/catalog/metadata.ts +6 -0
  121. package/src/codex/catalog/model-hints.ts +60 -11
  122. package/src/codex/catalog/model-visibility.ts +3 -2
  123. package/src/codex/catalog/native-models.ts +18 -3
  124. package/src/codex/catalog/parsing.ts +10 -8
  125. package/src/codex/catalog/pinned-models.ts +2 -1
  126. package/src/codex/catalog/provider-models.ts +18 -13
  127. package/src/codex/catalog/retained-sync.ts +2 -1
  128. package/src/codex/catalog/routed-gather.ts +19 -20
  129. package/src/codex/catalog/write-audit.ts +3 -2
  130. package/src/codex/catalog-self-heal.ts +43 -23
  131. package/src/codex/chatgpt-refresh-failure.ts +6 -2
  132. package/src/codex/cli-install-provenance.ts +418 -0
  133. package/src/codex/cli-installation-targets.ts +5 -1
  134. package/src/codex/cli-update-plan.ts +43 -16
  135. package/src/codex/collision-identity.ts +30 -5
  136. package/src/codex/convergence.ts +4 -3
  137. package/src/codex/data/roster-pinned-models.json +177 -1
  138. package/src/codex/desired-state.ts +6 -1
  139. package/src/codex/desktop-app/picker-freshness.ts +10 -8
  140. package/src/codex/desktop-compatibility/installed-build.ts +88 -12
  141. package/src/codex/desktop-compatibility/runtime.ts +29 -5
  142. package/src/codex/desktop-compatibility/usage-activation.ts +2 -1
  143. package/src/codex/desktop-compatibility/usage-controller.ts +9 -1
  144. package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
  145. package/src/codex/inject/config-toml.ts +0 -18
  146. package/src/codex/inject/plan.ts +18 -3
  147. package/src/codex/inject/remove.ts +6 -2
  148. package/src/codex/inject.ts +1 -1
  149. package/src/codex/journal.ts +61 -1
  150. package/src/codex/model-entitlements.ts +1 -1
  151. package/src/codex/native-main-owner.ts +27 -1
  152. package/src/codex/native-profile-store.ts +2 -1
  153. package/src/codex/pool-credit-policy.ts +35 -1
  154. package/src/codex/pool-refresh-backoff.ts +3 -1
  155. package/src/codex/quota-types.ts +3 -0
  156. package/src/codex/quota.ts +24 -4
  157. package/src/codex/role-auto-assign.ts +6 -2
  158. package/src/codex/subagent-defaults.ts +49 -4
  159. package/src/codex/user-identity.ts +35 -6
  160. package/src/codex/windows-current-sid.ts +162 -0
  161. package/src/combos/failover.ts +17 -2
  162. package/src/combos/jev-decision-contract.ts +22 -1
  163. package/src/combos/jev-quota-activation.ts +5 -1
  164. package/src/combos/jev-quota-route.ts +1 -1
  165. package/src/combos/jev-quota.ts +9 -1
  166. package/src/combos/jev-service-exchange.ts +3 -1
  167. package/src/combos/jev-session-pin-config.ts +51 -0
  168. package/src/combos/jev.ts +101 -9
  169. package/src/combos/resolve.ts +45 -1
  170. package/src/combos/types.ts +43 -0
  171. package/src/config/load-degrade.ts +5 -0
  172. package/src/config/paths.ts +19 -3
  173. package/src/config/pending-teardown.ts +22 -1
  174. package/src/config/provider-validation.ts +22 -4
  175. package/src/config/removed-opencode-free.ts +11 -0
  176. package/src/config/schema/leaf-validators.ts +6 -0
  177. package/src/generated/compatibility-version.json +467 -311
  178. package/src/generated/model-metadata.ts +5 -5
  179. package/src/images/loop.ts +16 -2
  180. package/src/integrations/catalog-refresh.ts +1 -1
  181. package/src/integrations/hermes-profiles.ts +251 -0
  182. package/src/integrations/merge.ts +8 -0
  183. package/src/integrations/mutation-plan.ts +19 -4
  184. package/src/integrations/registry.ts +5 -0
  185. package/src/integrations/state.ts +36 -1
  186. package/src/integrations/writer.ts +18 -4
  187. package/src/lib/bun-path-runtime.mjs +2 -1
  188. package/src/lib/decision-quota-sink.ts +10 -0
  189. package/src/lib/errors.ts +62 -0
  190. package/src/lib/eventstream-decoder.ts +81 -37
  191. package/src/lib/opaque-proxy-tunnel.ts +32 -8
  192. package/src/lib/pinned-http.ts +35 -2
  193. package/src/lib/process-control.ts +13 -1
  194. package/src/lib/socks5-fetch.ts +59 -64
  195. package/src/lib/socks5-upload-waiter.ts +50 -0
  196. package/src/lib/sse-decoder.ts +7 -2
  197. package/src/lib/state-store-sweeper.ts +40 -14
  198. package/src/lib/translator-budget.ts +4 -4
  199. package/src/lib/upstream-retry.ts +4 -1
  200. package/src/lib/windows-native-principal-worker.ts +14 -0
  201. package/src/lib/windows-native-principal.ts +188 -0
  202. package/src/lib/windows-secret-acl.ts +39 -3
  203. package/src/lib/windows-user-principal.ts +62 -18
  204. package/src/link/diagnostics.ts +193 -0
  205. package/src/link/relay-auth.ts +6 -0
  206. package/src/link/ssh-config.ts +35 -3
  207. package/src/link/status-projection.ts +39 -0
  208. package/src/link/supervisor.ts +45 -12
  209. package/src/link/tunnel-history.ts +109 -0
  210. package/src/link/tunnel-state.ts +80 -17
  211. package/src/messaging/remote-files.ts +24 -1
  212. package/src/oauth/generic-account-failover.ts +91 -7
  213. package/src/oauth/index.ts +15 -0
  214. package/src/oauth/model-discovery-auth.ts +5 -0
  215. package/src/oauth/store.ts +4 -1
  216. package/src/oauth/token-guardian.ts +7 -0
  217. package/src/oauth/types.ts +9 -0
  218. package/src/oauth/workbuddy.ts +139 -0
  219. package/src/providers/account-quota-disk.ts +12 -4
  220. package/src/providers/antigravity-quota-identity.ts +37 -0
  221. package/src/providers/base-url-choices.ts +8 -5
  222. package/src/providers/codebuddy-models.ts +6 -0
  223. package/src/providers/codex-capacity.ts +3 -1
  224. package/src/providers/derive.ts +51 -3
  225. package/src/providers/kiro-models.ts +3 -0
  226. package/src/providers/mimo-thinking.ts +12 -0
  227. package/src/providers/model-discovery.ts +2 -0
  228. package/src/providers/model-rename-fields.ts +2 -0
  229. package/src/providers/model-rename-migration.ts +10 -0
  230. package/src/providers/openai-sidecar-credit.ts +2 -2
  231. package/src/providers/quota/account-cache.ts +3 -2
  232. package/src/providers/quota/antigravity.ts +25 -14
  233. package/src/providers/quota/report-cache.ts +13 -4
  234. package/src/providers/quota/vendor-probes-key.ts +60 -0
  235. package/src/providers/quota/workbuddy.ts +83 -0
  236. package/src/providers/quota-decision-antigravity.ts +64 -0
  237. package/src/providers/quota-decision-publication.ts +11 -0
  238. package/src/providers/quota-decision-snapshot.ts +21 -4
  239. package/src/providers/quota-types.ts +2 -0
  240. package/src/providers/quota.ts +3 -1
  241. package/src/providers/reasoning-capabilities.ts +76 -0
  242. package/src/providers/registry/entries-core.ts +23 -12
  243. package/src/providers/registry/entries-extended.ts +83 -27
  244. package/src/providers/registry/model-ids.ts +5 -0
  245. package/src/providers/registry/model-seeds.ts +120 -56
  246. package/src/providers/registry/types.ts +29 -2
  247. package/src/providers/resolved-model-policy.ts +30 -10
  248. package/src/providers/routed-config.ts +24 -1
  249. package/src/providers/stale-model-roster-migration.ts +123 -18
  250. package/src/providers/workbuddy-credit-balance.ts +81 -0
  251. package/src/providers/workbuddy-models.ts +37 -0
  252. package/src/providers/workbuddy.ts +60 -0
  253. package/src/remote-control/workspace-pi-runtime.ts +11 -6
  254. package/src/responses/compaction-summary.ts +45 -0
  255. package/src/responses/muse-tool-name-alias.ts +1 -2
  256. package/src/responses/parser.ts +3 -2
  257. package/src/responses/reasoning-replay-cache.ts +18 -14
  258. package/src/responses/schema.ts +1 -0
  259. package/src/responses/thought-signature-replay.ts +10 -2
  260. package/src/router.ts +2 -0
  261. package/src/routing/analytics.ts +2 -3
  262. package/src/routing/capability.ts +8 -2
  263. package/src/routing/fallback-policy.ts +3 -3
  264. package/src/routing/history/ingest.ts +28 -3
  265. package/src/server/auth-cors.ts +4 -2
  266. package/src/server/chat-completions.ts +21 -1
  267. package/src/server/chat-native-eligibility.ts +7 -0
  268. package/src/server/chat-native-reasoning.ts +24 -7
  269. package/src/server/chat-native.ts +13 -2
  270. package/src/server/claude-messages.ts +3 -0
  271. package/src/server/direct-local-http.ts +5 -2
  272. package/src/server/effort-policy.ts +5 -1
  273. package/src/server/index/link-relay-sessions.ts +9 -5
  274. package/src/server/index/live-sideband.ts +18 -15
  275. package/src/server/index/optional-listeners.ts +4 -0
  276. package/src/server/index/serve-options.ts +5 -4
  277. package/src/server/local-management-read-client.ts +3 -1
  278. package/src/server/management/agent-settings-routes.ts +27 -15
  279. package/src/server/management/combo-routes.ts +14 -4
  280. package/src/server/management/config-routes.ts +2 -2
  281. package/src/server/management/decision-discovery.ts +12 -2
  282. package/src/server/management/hermes-profile-routes.ts +156 -0
  283. package/src/server/management/integration-routes.ts +85 -24
  284. package/src/server/management/link-routes.ts +5 -2
  285. package/src/server/management/model-routes.ts +2 -2
  286. package/src/server/management/model-row-export-metadata.ts +25 -6
  287. package/src/server/management/model-rows.ts +15 -20
  288. package/src/server/management/native-integration-routes.ts +11 -8
  289. package/src/server/management/provider-routes.ts +1 -1
  290. package/src/server/management/route-registry.ts +4 -0
  291. package/src/server/management-api.ts +5 -0
  292. package/src/server/models-capabilities.ts +21 -3
  293. package/src/server/port-reclaim.ts +51 -9
  294. package/src/server/request-log-conversation.ts +49 -0
  295. package/src/server/request-log.ts +2 -0
  296. package/src/server/responses/adapter-delivery.ts +11 -1
  297. package/src/server/responses/adapter-dispatch.ts +2 -2
  298. package/src/server/responses/anthropic-thinking-recovery.ts +1 -0
  299. package/src/server/responses/codex-ws-exchange.ts +39 -9
  300. package/src/server/responses/codex-ws-session.ts +38 -4
  301. package/src/server/responses/codex-ws-wire.ts +6 -1
  302. package/src/server/responses/combo-required-tool-contract.ts +103 -0
  303. package/src/server/responses/combo-stream-preflight.ts +8 -1
  304. package/src/server/responses/compact.ts +14 -5
  305. package/src/server/responses/context-overflow.ts +8 -1
  306. package/src/server/responses/core-combo-failure.ts +10 -0
  307. package/src/server/responses/core-combo.ts +74 -44
  308. package/src/server/responses/core-lifetime.ts +5 -2
  309. package/src/server/responses/core-normalize.ts +17 -4
  310. package/src/server/responses/core-opaque-recovery.ts +1 -0
  311. package/src/server/responses/core-options.ts +7 -0
  312. package/src/server/responses/core-replay.ts +2 -1
  313. package/src/server/responses/jev-combo-choice.ts +39 -0
  314. package/src/server/responses/jev-session-pin.ts +203 -0
  315. package/src/server/responses/main-hard-lock-routing.ts +60 -44
  316. package/src/server/responses/passthrough-delivery.ts +44 -2
  317. package/src/server/responses/policy-fallback.ts +6 -1
  318. package/src/server/responses/request-compression.ts +12 -7
  319. package/src/server/responses/request-prepare.ts +32 -7
  320. package/src/server/responses/request-sidecar-auth.ts +2 -0
  321. package/src/server/responses/request-transport.ts +25 -6
  322. package/src/server/responses/response-effects.ts +22 -10
  323. package/src/server/responses/run-turn-execution.ts +2 -4
  324. package/src/server/responses/sidecar-execution.ts +13 -7
  325. package/src/server/responses-phase-inference.ts +267 -0
  326. package/src/server/sse-payload-rewrite.ts +14 -1
  327. package/src/server/stop-teardown.ts +36 -1
  328. package/src/server/ws-bridge.ts +1 -1
  329. package/src/service/definition.ts +20 -8
  330. package/src/service/desktop-supervision.d.mts +7 -4
  331. package/src/service/desktop-supervision.mjs +90 -13
  332. package/src/service/ownership-mutation-lease.mjs +21 -7
  333. package/src/types/config.ts +14 -2
  334. package/src/types/provider.ts +29 -7
  335. package/src/types/request.ts +11 -0
  336. package/src/types/wire.ts +1 -0
  337. package/src/types.ts +1 -0
  338. package/src/update/bind-probe.ts +29 -0
  339. package/src/update/codex-cli-update-launch-policy.d.mts +9 -0
  340. package/src/update/codex-cli-update-launch-policy.mjs +30 -0
  341. package/src/update/job.ts +10 -29
  342. package/src/update/npm-install-job.ps1 +173 -0
  343. package/src/update/npm-install.mjs +70 -0
  344. package/src/update/stop-contract.d.mts +1 -0
  345. package/src/update/stop-contract.mjs +14 -0
  346. package/src/update/stop-decision.d.mts +1 -1
  347. package/src/update/stop-decision.mjs +13 -3
  348. package/src/update/teardown-handover.ts +166 -0
  349. package/src/update/transactional-install.d.mts +14 -3
  350. package/src/update/transactional-install.mjs +33 -7
  351. package/src/usage/expected-prices.ts +64 -31
  352. package/src/usage/jev-stats.ts +54 -14
  353. package/src/usage/timeline.ts +19 -9
  354. package/src/vision/eligibility.ts +15 -5
  355. package/src/vision/plan.ts +2 -2
  356. package/src/web-search/loop.ts +16 -2
  357. package/gui/dist/assets/App-nZ34cR5G.js +0 -58
  358. package/gui/dist/assets/index-DGXS51sp.js +0 -94
  359. package/gui/dist/assets/index-DPeB9HpV.css +0 -1
  360. package/gui/dist/assets/quota-summary-DO1Sx5TM.js +0 -1
@@ -10,10 +10,12 @@ import { applyGithubCopilotContextTier } from "../../providers/github-copilot-co
10
10
  import { canonicalFastTierMarker, decideTier, type ResolvedFastPolicy } from "../../providers/fastwire";
11
11
  import { debugProviderDiagnostic } from "../../lib/debug";
12
12
  import { isDebugEnabled } from "../../lib/debug-settings";
13
- import { modelRecordValue } from "../../reasoning-effort";
14
13
  import { modelInList, type OcxProviderConfig } from "../../types";
14
+ import { mapReasoningEffort, modelRecordValue } from "../../reasoning-effort";
15
+ import { resolveReasoningCapabilities } from "../../providers/reasoning-capabilities";
15
16
  import { chatParallelToolCallsWireValue } from "./parallel-tool-calls";
16
- import { applyExplicitChatReasoningWirePolicy } from "./reasoning-wire";
17
+ import { applyExplicitChatReasoningWirePolicy, declaresIndependentChatReasoningControls } from "./reasoning-wire";
18
+ import { declaresThinkingToggleWire, reasoningControlsAreUnsupported } from "../reasoning-controls";
17
19
  import { planNativeChatReasoningReplay } from "./reasoning-replay";
18
20
  import type { OcxReasoningReplayScopeRef } from "../../types";
19
21
  import { jsonUtf8Bytes } from "../../lib/json-byte-size";
@@ -87,22 +89,40 @@ export function buildOpenAIChatPassthroughRequest(
87
89
  const replayPlan = planNativeChatReasoningReplay(body.messages, provider, modelId, replayScope,
88
90
  Array.isArray(rawBody.tools) && rawBody.tools.length > 0, maxSerializedBytes);
89
91
  if (protectGlmSummaryBudget(body, provider.baseUrl, body.reasoning_effort)) body.reasoning_effort = "low";
92
+ const toggleWire = declaresThinkingToggleWire(provider, modelId);
93
+ const independentControls = declaresIndependentChatReasoningControls(provider, modelId);
90
94
  const rawEfforts = modelRecordValue(provider.modelReasoningEfforts, modelId) ?? provider.reasoningEfforts;
91
- const reasoningDisabled = modelInList(provider.noReasoningModels, modelId) || rawEfforts?.length === 0;
95
+ const reasoningDisabled = modelInList(provider.noReasoningModels, modelId)
96
+ || (!toggleWire && rawEfforts?.length === 0) || reasoningControlsAreUnsupported(provider, modelId);
92
97
  if (reasoningDisabled) {
93
98
  delete body.reasoning_effort;
94
99
  }
95
100
  const hasTools = Array.isArray(rawBody.tools) && rawBody.tools.length > 0;
96
101
  const requestedEffort = typeof body.reasoning_effort === "string" ? body.reasoning_effort : undefined;
97
- applyExplicitChatReasoningWirePolicy({
102
+ const explicitThinkingEnabled = rawBody.reasoning !== null && typeof rawBody.reasoning === "object"
103
+ && typeof (rawBody.reasoning as { enabled?: unknown }).enabled === "boolean"
104
+ ? (rawBody.reasoning as { enabled: boolean }).enabled
105
+ : undefined;
106
+ const explicitReasoning = applyExplicitChatReasoningWirePolicy({
98
107
  provider,
99
108
  modelId,
100
109
  hasTools,
110
+ thinkingEnabled: explicitThinkingEnabled,
101
111
  requestedEffort,
102
- wireEffort: requestedEffort,
112
+ wireEffort: toggleWire && independentControls ? mapReasoningEffort(provider, modelId, requestedEffort) : requestedEffort,
103
113
  reasoningDisabled,
104
114
  body,
105
115
  });
116
+ let reasoningLog = explicitReasoning.handled ? explicitReasoning.reasoningLog : undefined;
117
+ // A native caller's own thinking object is already in the upstream wire shape. Forward it only
118
+ // on a provider-declared toggle wire, below an explicit reasoning.enabled but above a default.
119
+ if (!reasoningDisabled && toggleWire && independentControls
120
+ && resolveReasoningCapabilities(provider, modelId).supportsThinkingToggle !== false
121
+ && explicitThinkingEnabled === undefined
122
+ && rawBody.thinking !== undefined) {
123
+ body.thinking = rawBody.thinking;
124
+ reasoningLog = undefined;
125
+ }
106
126
 
107
127
  const openRouterRouting = resolveOpenRouterRouting(provider, modelId);
108
128
  if (openRouterRouting) body.provider = openRouterProviderPayload(openRouterRouting);
@@ -170,15 +190,13 @@ export function buildOpenAIChatPassthroughRequest(
170
190
  // The binding constraint is the final size base + net, so a shrinking replay may legitimately
171
191
  // measure a base above the cap; only a base above max - net makes the result unserializable.
172
192
  let baseBytes = 0;
173
- if (replayPlan.hasChanges) {
174
- try {
175
- baseBytes = jsonUtf8Bytes(transformedBody(), maxSerializedBytes - replayPlan.serializedBytes);
176
- } catch (error) {
177
- if (isTranslatorBudgetExceededError(error)) {
178
- throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
179
- }
180
- throw error;
193
+ try {
194
+ baseBytes = jsonUtf8Bytes(transformedBody(), maxSerializedBytes - replayPlan.serializedBytes);
195
+ } catch (error) {
196
+ if (isTranslatorBudgetExceededError(error)) {
197
+ throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
181
198
  }
199
+ throw error;
182
200
  }
183
201
  if (replayPlan.serializedBytes > maxSerializedBytes - baseBytes) {
184
202
  throw new TranslatorBudgetExceededError("request_copies", maxSerializedBytes);
@@ -210,5 +228,8 @@ export function buildOpenAIChatPassthroughRequest(
210
228
  });
211
229
  }
212
230
 
213
- return { url, method: "POST", headers, body: bodyJson };
231
+ return {
232
+ url, method: "POST", headers, body: bodyJson,
233
+ ...(reasoningLog ? { reasoningLog } : {}),
234
+ };
214
235
  }
@@ -9,9 +9,15 @@ export const isChatRecord = (value: unknown): value is Rec =>
9
9
 
10
10
  const REASONING_CONTENT_FIELD_BYTES = Buffer.byteLength('"reasoning_content":', "utf8");
11
11
 
12
- const isDeepSeekThinkingModel = (modelId: string): boolean =>
12
+ export const isDeepSeekThinkingModel = (modelId: string): boolean =>
13
13
  /(?:^|\/)deepseek-(?:v\d+(?:\.\d+)*-(?:flash|pro)|flash|pro)(?:$|[-_:])/i.test(modelId);
14
14
 
15
+ export const isReflectionThinkingModel = (modelId: string): boolean =>
16
+ /(?:^|\/)(?:reflection|stealth)(?:$|[-_:/.])/i.test(modelId);
17
+
18
+ export const isThinkingModelFamily = (modelId: string): boolean =>
19
+ isDeepSeekThinkingModel(modelId) || isReflectionThinkingModel(modelId);
20
+
15
21
  /** DeepSeek thinking tool replay is a model contract, independent of the gateway's name. */
16
22
  export function chatReasoningReplayPolicy(provider: OcxProviderConfig, modelId: string): {
17
23
  preserve: boolean; placeholder: boolean;
@@ -19,7 +25,7 @@ export function chatReasoningReplayPolicy(provider: OcxProviderConfig, modelId:
19
25
  // Match whole model-family tokens, including dotted versions, namespace and deployment suffixes.
20
26
  // Legacy chat/reasoner and distilled R1 models do not share the thinking tool-call contract.
21
27
  const preserve = provider.preserveReasoningContentModels === undefined
22
- ? isDeepSeekThinkingModel(modelId)
28
+ ? isThinkingModelFamily(modelId)
23
29
  : modelInList(provider.preserveReasoningContentModels, modelId);
24
30
  return {
25
31
  preserve,
@@ -59,21 +65,26 @@ export function planNativeChatReasoningReplay(
59
65
  const plans: ReplayMessagePlan[] = [];
60
66
  let serializedBytes = 0;
61
67
  for (const message of messages) {
62
- if (!isChatRecord(message) || message.role !== "assistant"
63
- || (typeof message.reasoning_content === "string" && message.reasoning_content.length > 0)) continue;
64
- const calls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
65
- // DeepSeek's tools contract covers all prior assistant turns, even plain answers.
66
- // Those turns have no call id for original replay; only the configured fallback applies.
67
- if (calls.length === 0 && !(hasTools && isDeepSeekThinkingModel(modelId))) continue;
68
- const cached = new Set<string>();
69
- for (const tool of calls) {
70
- if (!isChatRecord(tool) || typeof tool.id !== "string") continue;
71
- const text = peekReasoningForCall(tool.id, scope);
72
- if (text) cached.add(text);
68
+ if (!isChatRecord(message) || message.role !== "assistant") continue;
69
+ if (typeof message.reasoning_content === "string" && message.reasoning_content.length > 0) continue;
70
+ let parts: string[];
71
+ if (typeof message.reasoning === "string" && message.reasoning.length > 0) {
72
+ parts = [message.reasoning];
73
+ } else {
74
+ const calls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
75
+ // DeepSeek tools contract covers prior assistant turns when tools are present.
76
+ // Thinking models like reflection/beam require reasoning replay even without tools.
77
+ if (calls.length === 0 && !(hasTools && isDeepSeekThinkingModel(modelId)) && !isReflectionThinkingModel(modelId)) continue;
78
+ const cached = new Set<string>();
79
+ for (const tool of calls) {
80
+ if (!isChatRecord(tool) || typeof tool.id !== "string") continue;
81
+ const text = peekReasoningForCall(tool.id, scope);
82
+ if (text) cached.add(text);
83
+ }
84
+ parts = cached.size > 0
85
+ ? [...cached]
86
+ : policy.placeholder ? [" "] : [];
73
87
  }
74
- const parts = cached.size > 0
75
- ? [...cached]
76
- : policy.placeholder ? [" "] : [];
77
88
  if (parts.length === 0) continue;
78
89
 
79
90
  // The envelope delta around the joined value is exact for the plain JSON the Chat
@@ -1,11 +1,34 @@
1
+ import { resolveThinkingEnabled } from "../../clients/reasoning-controls";
2
+ import { declaredModelCapabilities, resolveReasoningCapabilities } from "../../providers/reasoning-capabilities";
3
+ import { registryEntryForProviderDestination } from "../../providers/registry";
1
4
  import { modelInList, type OcxProviderConfig } from "../../types";
2
5
  import type { AdapterRequest } from "../base";
6
+ import { declaresThinkingToggleWire, reasoningControlsAreUnsupported } from "../reasoning-controls";
3
7
  import { isNativeOpenAIChatTarget } from "./wire";
4
8
 
5
9
  export type ExplicitChatReasoningWireResult =
6
10
  | { handled: false }
7
11
  | { handled: true; reasoningLog?: AdapterRequest["reasoningLog"] };
8
12
 
13
+ function isThinkingToggleType(value: string | undefined): value is "enabled" | "disabled" | "adaptive" {
14
+ return value === "enabled" || value === "disabled" || value === "adaptive";
15
+ }
16
+
17
+ /** A legacy ladder alone must not opt a translated toggle wire into a second control. */
18
+ export function declaresIndependentChatReasoningEffort(provider: OcxProviderConfig, modelId: string): boolean {
19
+ const explicit = declaredModelCapabilities(provider.modelCapabilities, modelId)?.supportsReasoningEffort;
20
+ const registry = declaredModelCapabilities(registryEntryForProviderDestination(provider)?.modelCapabilities, modelId)?.supportsReasoningEffort;
21
+ return (explicit ?? registry) === true;
22
+ }
23
+
24
+ /** Only explicit control axes opt legacy Chat destinations into independent projection. */
25
+ export function declaresIndependentChatReasoningControls(provider: OcxProviderConfig, modelId: string): boolean {
26
+ const explicit = declaredModelCapabilities(provider.modelCapabilities, modelId);
27
+ const registry = declaredModelCapabilities(registryEntryForProviderDestination(provider)?.modelCapabilities, modelId);
28
+ return (["supportsThinkingToggle", "supportsReasoningEffort"] as const)
29
+ .some(axis => typeof (explicit?.[axis] ?? registry?.[axis]) === "boolean");
30
+ }
31
+
9
32
  /**
10
33
  * Apply provider-declared reasoning wire policy after the effective provider is resolved.
11
34
  * Unset declarations are a no-op so native Chat keeps forwarding the caller's raw field.
@@ -14,6 +37,7 @@ export function applyExplicitChatReasoningWirePolicy(options: {
14
37
  provider: OcxProviderConfig;
15
38
  modelId: string;
16
39
  hasTools: boolean;
40
+ thinkingEnabled: boolean | undefined;
17
41
  requestedEffort: string | undefined;
18
42
  wireEffort: string | undefined;
19
43
  reasoningDisabled: boolean;
@@ -23,19 +47,103 @@ export function applyExplicitChatReasoningWirePolicy(options: {
23
47
  provider,
24
48
  modelId,
25
49
  hasTools,
50
+ thinkingEnabled,
26
51
  requestedEffort,
27
- wireEffort,
52
+ wireEffort: mappedWireEffort,
28
53
  reasoningDisabled,
29
54
  body,
30
55
  } = options;
31
56
 
32
- if (reasoningDisabled) return { handled: false };
57
+ const capabilities = resolveReasoningCapabilities(provider, modelId);
58
+ if (reasoningDisabled || reasoningControlsAreUnsupported(provider, modelId)) {
59
+ delete body.reasoning_effort;
60
+ delete body.reasoning;
61
+ delete body.thinking;
62
+ return { handled: true };
63
+ }
64
+ const toggleWire = declaresThinkingToggleWire(provider, modelId);
65
+ const toggleDisabled = toggleWire && capabilities.supportsThinkingToggle === false;
66
+ // Legacy tool omission precedes discriminator mapping; independent switches are separate
67
+ // from strength omission and retain their declared behavior below.
68
+ if (hasTools && modelInList(provider.omitReasoningEffortWithToolsModels, modelId)
69
+ && !declaresIndependentChatReasoningControls(provider, modelId)) {
70
+ delete body.reasoning_effort;
71
+ delete body.reasoning;
72
+ return { handled: true };
73
+ }
74
+ // Ignore legacy toggle discriminators on a disabled toggle axis, but retain real effort
75
+ // mappings (including omission) and run them through the shared effort policy below.
76
+ const requestedStrength = requestedEffort === "ultra" ? "max" : requestedEffort;
77
+ const wireEffort = toggleDisabled && isThinkingToggleType(mappedWireEffort) ? requestedStrength : mappedWireEffort;
78
+ if (capabilities.supportsReasoningEffort === false && !toggleWire) {
79
+ delete body.reasoning_effort;
80
+ delete body.reasoning;
81
+ if (capabilities.supportsThinkingToggle === false) delete body.thinking;
82
+ return { handled: true };
83
+ }
84
+ const resolvedThinkingEnabled = toggleWire && !toggleDisabled
85
+ ? resolveThinkingEnabled(provider, modelId, { thinkingEnabled, reasoning: requestedEffort })
86
+ : undefined;
87
+ if (toggleDisabled) {
88
+ delete body.thinking;
89
+ delete body.reasoning;
90
+ delete body.reasoning_effort;
91
+ } else if (toggleWire) {
92
+ // These values are the provider's declared thinking discriminator, never strengths. This
93
+ // remains true when the catalog also advertises a separate, real effort axis.
94
+ if (isThinkingToggleType(wireEffort)) {
95
+ const thinkingType = resolvedThinkingEnabled === undefined
96
+ ? wireEffort
97
+ : resolvedThinkingEnabled ? "enabled" : "disabled";
98
+ body.thinking = { type: thinkingType };
99
+ delete body.reasoning_effort;
100
+ delete body.reasoning;
101
+ return {
102
+ handled: true,
103
+ reasoningLog: {
104
+ effectiveEffort: thinkingType,
105
+ wireField: "thinking.type",
106
+ wireValue: thinkingType,
107
+ },
108
+ };
109
+ }
110
+ if (resolvedThinkingEnabled !== undefined) {
111
+ const thinkingType = resolvedThinkingEnabled ? "enabled" : "disabled";
112
+ body.thinking = { type: thinkingType };
113
+ // A second control still goes through tool omission and gateway projection below.
114
+ if (capabilities.supportsReasoningEffort === false) {
115
+ delete body.reasoning_effort;
116
+ delete body.reasoning;
117
+ return {
118
+ handled: true,
119
+ reasoningLog: {
120
+ effectiveEffort: thinkingType,
121
+ wireField: "thinking.type",
122
+ wireValue: thinkingType,
123
+ },
124
+ };
125
+ }
126
+ }
127
+ if (capabilities.supportsReasoningEffort === false) {
128
+ delete body.reasoning_effort;
129
+ delete body.reasoning;
130
+ return { handled: true };
131
+ }
132
+ }
33
133
  if (hasTools && modelInList(provider.omitReasoningEffortWithToolsModels, modelId)) {
34
134
  delete body.reasoning_effort;
35
135
  delete body.reasoning;
36
136
  return { handled: true };
37
137
  }
38
- if (provider.reasoningWireFormat !== "gateway-object") return { handled: false };
138
+ if (provider.reasoningWireFormat !== "gateway-object") {
139
+ if (!toggleDisabled) return { handled: false };
140
+ if (wireEffort === undefined) return { handled: true };
141
+ body.reasoning_effort = wireEffort;
142
+ return {
143
+ handled: true,
144
+ reasoningLog: { effectiveEffort: wireEffort, wireField: "reasoning_effort", wireValue: wireEffort },
145
+ };
146
+ }
39
147
 
40
148
  const nativeOpenAI = isNativeOpenAIChatTarget(provider);
41
149
  if (requestedEffort === "none") {
@@ -52,17 +160,18 @@ export function applyExplicitChatReasoningWirePolicy(options: {
52
160
  };
53
161
  }
54
162
  delete body.reasoning_effort;
55
- body.reasoning = { enabled: false };
163
+ const enabled = resolvedThinkingEnabled ?? false;
164
+ body.reasoning = { enabled };
56
165
  return {
57
166
  handled: true,
58
167
  reasoningLog: {
59
- effectiveEffort: "none",
168
+ effectiveEffort: enabled ? "enabled" : "none",
60
169
  wireField: "reasoning.enabled",
61
- wireValue: false,
170
+ wireValue: enabled,
62
171
  },
63
172
  };
64
173
  }
65
- if (wireEffort === undefined) return { handled: false };
174
+ if (wireEffort === undefined) return { handled: toggleDisabled };
66
175
 
67
176
  if (nativeOpenAI) {
68
177
  delete body.reasoning;
@@ -77,7 +186,7 @@ export function applyExplicitChatReasoningWirePolicy(options: {
77
186
  };
78
187
  }
79
188
  delete body.reasoning_effort;
80
- body.reasoning = { enabled: true, effort: wireEffort };
189
+ body.reasoning = { enabled: resolvedThinkingEnabled ?? true, effort: wireEffort };
81
190
  return {
82
191
  handled: true,
83
192
  reasoningLog: {
@@ -0,0 +1,64 @@
1
+ import type { ProviderAdapter } from "../base";
2
+ import { requiresToolCall, type AdapterEvent, type OcxParsedRequest } from "../../types";
3
+ import { releaseTranslatedEvent, retainTranslatedEvent, type TranslatorBudget } from "../../lib/translator-budget";
4
+ import type { AdapterTierMetadata } from "../../providers/fastwire";
5
+ import { isTruncatedStopReason } from "../../responses/truncated-stop-reason";
6
+
7
+ function requiresClientCall(parsed: OcxParsedRequest): boolean {
8
+ if (!requiresToolCall(parsed.options.toolChoice)) return false;
9
+ // Sidecars own their own tool lifecycle; this boundary validates client-executed calls only.
10
+ return !(parsed.context.tools ?? []).some(t => t.webSearch || t.imageGeneration || t.videoGeneration || t.advisor);
11
+ }
12
+
13
+ function terminalGuard(required: boolean): (event: AdapterEvent) => AdapterEvent {
14
+ // The shared response bridge owns tool-choice authorization and alias restoration.
15
+ // Count a completed call here without introducing a second, narrower name resolver.
16
+ let pending = false;
17
+ let fulfilled = false;
18
+ let failed = false;
19
+ return event => {
20
+ if (event.type === "tool_call_start") pending = true;
21
+ if (event.type === "tool_call_end") { fulfilled ||= pending; pending = false; }
22
+ if (event.type === "error" || event.type === "incomplete") failed = true;
23
+ if (event.type !== "done" || !required || fulfilled || failed || isTruncatedStopReason(event.stopReason)) return event;
24
+ // Preserve delivered output and consumption. A mandatory call is a contract, not a hint
25
+ // that permits replaying an already-visible turn or silently reporting text as success.
26
+ return {
27
+ type: "error", status: 502, errorType: "upstream_error", code: "required_tool_not_called",
28
+ message: "The upstream response completed without the required client tool call.",
29
+ retryable: false, usage: event.usage,
30
+ };
31
+ };
32
+ }
33
+
34
+ /** Keep the same per-request lifetime as the Chat adapter's tool-name registry. */
35
+ export function withRequiredChatToolResult(adapter: ProviderAdapter): ProviderAdapter {
36
+ let required = false;
37
+ return {
38
+ ...adapter,
39
+ buildRequest(parsed, incoming) {
40
+ required = requiresClientCall(parsed);
41
+ return adapter.buildRequest(parsed, incoming);
42
+ },
43
+ async *parseStream(response, budget, tierMetadata) {
44
+ const guard = terminalGuard(required);
45
+ for await (const event of adapter.parseStream(response, budget, tierMetadata)) yield guard(event);
46
+ },
47
+ ...(adapter.parseResponse ? {
48
+ async parseResponse(response: Response, budget: TranslatorBudget, tierMetadata?: AdapterTierMetadata) {
49
+ const events = await adapter.parseResponse!(response, budget, tierMetadata);
50
+ const guard = terminalGuard(required);
51
+ for (let i = 0; i < events.length; i++) {
52
+ const original = events[i]!;
53
+ const guarded = guard(original);
54
+ if (guarded !== original) {
55
+ releaseTranslatedEvent(original, budget);
56
+ retainTranslatedEvent(guarded, budget);
57
+ events[i] = guarded;
58
+ }
59
+ }
60
+ return events;
61
+ },
62
+ } : {}),
63
+ };
64
+ }
@@ -63,6 +63,7 @@ export function openAIChatToolNameIdentities(parsed: OcxParsedRequest): ToolIden
63
63
  */
64
64
  export function createOpenAIChatToolNameRegistry(
65
65
  tools: readonly ToolIdentity[] | undefined,
66
+ strictNames = false,
66
67
  ): OpenAIChatToolNameRegistry {
67
68
  const identities = new Map<string, ToolIdentity>();
68
69
  for (const tool of tools ?? []) identities.set(identityKey(tool), tool);
@@ -85,6 +86,7 @@ export function createOpenAIChatToolNameRegistry(
85
86
  for (const [key, tool] of sortedIdentities) {
86
87
  const wireName = namespacedToolName(tool.namespace, tool.name);
87
88
  const candidate = (tool.namespace !== undefined && wireName.length > MAX_CHAT_TOOL_NAME_LENGTH)
89
+ || (strictNames && !/^[A-Za-z0-9_-]+$/.test(wireName))
88
90
  || RESERVED_ALIAS_PATTERN.test(wireName)
89
91
  || wireOwners.get(wireName) === null
90
92
  ? boundedAlias(tool, wireName)
@@ -157,7 +159,7 @@ export function withOpenAIChatToolNames<T>(
157
159
  let registry = createOpenAIChatToolNameRegistry(undefined);
158
160
  return build({
159
161
  messages(parsed, baseUrl, messages): unknown {
160
- registry = createOpenAIChatToolNameRegistry(openAIChatToolNameIdentities(parsed));
162
+ registry = createOpenAIChatToolNameRegistry(openAIChatToolNameIdentities(parsed), baseUrl === "https://www.workbuddy.ai/v2");
161
163
  return frameAgentRouterMessages(baseUrl, aliasOpenAIChatMessageToolNames(messages, registry));
162
164
  },
163
165
  registry: () => registry,
@@ -1,10 +1,10 @@
1
+ import { withRequiredChatToolResult } from "./openai-chat/required-tool-result";
1
2
  import { hasShrinkableOpenAIChatImages, normalizeOpenAIChatImages } from "./openai-chat-images";
2
3
  import { protectGlmSummaryBudget, resolveMaxTokens } from "./openai-chat/summary-budget";
3
4
  import { chatParallelToolCallsWireValue } from "./openai-chat/parallel-tool-calls";
4
- import { applyExplicitChatReasoningWirePolicy } from "./openai-chat/reasoning-wire";
5
+ import { applyExplicitChatReasoningWirePolicy, declaresIndependentChatReasoningEffort } from "./openai-chat/reasoning-wire";
5
6
  import type { AdapterRequest, IncomingMeta, ProviderAdapter } from "./base";
6
- import type { AdapterEvent, OcxParsedRequest, OcxProviderConfig, OcxUsage } from "../types";
7
- import { modelInList } from "../types";
7
+ import { modelInList, type AdapterEvent, type OcxParsedRequest, type OcxProviderConfig, type OcxUsage } from "../types";
8
8
  import { mapReasoningEffort } from "../reasoning-effort";
9
9
  import { debugProviderDiagnostic } from "../lib/debug";
10
10
  import { sseFieldValue } from "../lib/sse-decoder";
@@ -49,7 +49,6 @@ import { openAIChatTransport, stripBracketedModelSuffix } from "./openai-chat/wi
49
49
  import { toolChoiceToChatFormat, toolsToChatFormatForProvider } from "./openai-chat/tool-schema";
50
50
  import { freeformToolsByWireName, type FreeformToolIdentity, reconcileStructuredToolCall, reconcileStructuredToolCalls } from "./openai-chat/serialized-tool-call-content";
51
51
  import { StandaloneBareToolCallBuffer, reconcileStandaloneBareToolCallEvents } from "./openai-chat/standalone-bare-tool-calls";
52
-
53
52
  export { stripBracketedModelSuffix } from "./openai-chat/wire";
54
53
  export { buildOpenAIChatPassthroughRequest } from "./openai-chat/passthrough";
55
54
  export { formatOpenAIChatErrorBody } from "./openai-chat/errors";
@@ -91,7 +90,7 @@ function canSerializeOpenAIChatServiceTier(
91
90
  export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAdapter {
92
91
  let lastRequestedModelId: string | undefined;
93
92
  let freeformTools = new Map<string, FreeformToolIdentity>();
94
- return withOpenAIChatToolNames(toolNames => ({
93
+ return withRequiredChatToolResult(withOpenAIChatToolNames(toolNames => ({
95
94
  name: "openai-chat",
96
95
 
97
96
  formatErrorBody: formatOpenAIChatErrorBody,
@@ -153,7 +152,7 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
153
152
  const explicitReasoning = applyExplicitChatReasoningWirePolicy({
154
153
  provider,
155
154
  modelId: parsed.modelId,
156
- hasTools: !!tools,
155
+ hasTools: !!tools, thinkingEnabled: parsed.options.thinkingEnabled,
157
156
  requestedEffort,
158
157
  wireEffort: reasoningEffort,
159
158
  reasoningDisabled,
@@ -173,7 +172,7 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
173
172
  wireValue: budget,
174
173
  };
175
174
  }
176
- } else if (modelInList(provider.thinkingToggleModels, parsed.modelId)) {
175
+ } else if (modelInList(provider.thinkingToggleModels, parsed.modelId) && !declaresIndependentChatReasoningEffort(provider, parsed.modelId)) {
177
176
  if (reasoningEffort === "enabled" || reasoningEffort === "disabled" || reasoningEffort === "adaptive") {
178
177
  body.thinking = { type: reasoningEffort };
179
178
  reasoningLog = {
@@ -614,9 +613,9 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
614
613
  }
615
614
  bufferBytes = nextBufferBytes;
616
615
 
617
- const lines = buffer.split("\n");
616
+ const lines = decoded.includes("\n") ? buffer.split("\n") : [buffer];
618
617
  buffer = lines.pop() ?? "";
619
- const residualBytes = budgetEncoder.encode(buffer).byteLength;
618
+ const residualBytes = lines.length ? budgetEncoder.encode(buffer).byteLength : bufferBytes;
620
619
  const residualReservation = budget.reserveTransient(residualBytes, { kind: "live_transient" });
621
620
  residualReservation.commitRetained();
622
621
  budget.releaseRetained(bufferBytes, { kind: "live_transient" });
@@ -818,5 +817,5 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
818
817
  budget.releaseRetained(responseBytes, { kind: "retained_collectors" });
819
818
  }
820
819
  },
821
- }));
820
+ })));
822
821
  }
@@ -39,8 +39,8 @@ import {
39
39
  createAdapterTierMetadata,
40
40
  emittedFastWire,
41
41
  } from "../../providers/fastwire";
42
- import { dropResponsesReasoningInputItems, mapRoutedResponsesReasoningEffort, normalizeConfiguredReasoningSummaryDelivery, sanitizeReasoningInputContent, stripDisabledReasoningSummaries, stripDisabledVerbosity, stripNoneReasoningSummary, stripUnsupportedReasoningSummaryDelivery } from "./reasoning";
43
- import { scrubOcxCompactionItems, stripCanonicalOnlyInputItems, stripCanonicalOnlyToolFields, stripCanonicalOnlyTopLevelFields, stripInternalChatMessageMetadataPassthrough, stripInvalidItemIds, stripItemIdsWhenUnstored, stripProviderInputItemMetadata, stripRejectedSamplingParams } from "./request-strips";
42
+ import { dropResponsesReasoningInputItems, mapRoutedResponsesReasoningEffort, normalizeConfiguredReasoningSummaryDelivery, sanitizeReasoningInputContent, stripDisabledReasoningSummaries, stripDisabledVerbosity, stripInternalReasoningEnabled, stripNoneReasoningSummary, stripUnsupportedReasoningSummaryDelivery } from "./reasoning";
43
+ import { repairUrlCitationAnnotations, scrubOcxCompactionItems, stripCanonicalOnlyInputItems, stripCanonicalOnlyToolFields, stripCanonicalOnlyTopLevelFields, stripInternalChatMessageMetadataPassthrough, stripInvalidItemIds, stripItemIdsWhenUnstored, stripProviderInputItemMetadata, stripRejectedSamplingParams } from "./request-strips";
44
44
  import { notePlaintextReasoningDropped } from "./plaintext-reasoning-notice";
45
45
  import { stripCanonicalForwardPromptCacheOptions, stripDeprecatedPromptCacheRetention } from "./prompt-cache";
46
46
  import { isPlainObject } from "./internal";
@@ -315,7 +315,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
315
315
  outBody = repairLegacyDottedToolCallNames(outBody);
316
316
  // Shared HTTP/WS outbound projection, including concrete combo/fallback destinations.
317
317
  if (isOpenAiOperatedResponsesDestination(provider)) {
318
- outBody = stripProviderInputItemMetadata(outBody);
318
+ outBody = repairUrlCitationAnnotations(stripProviderInputItemMetadata(outBody));
319
319
  }
320
320
  if (!isCanonicalOpenAiForwardProvider(provider)) {
321
321
  if (provider.preserveResponsesMessageMetadata !== true) {
@@ -515,7 +515,10 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
515
515
  if (!isCanonicalOpenAiForwardProvider(provider)) {
516
516
  validateFinalCustomToolCompatibility(finalBody, provider.supportsResponsesCustomTools);
517
517
  }
518
- const wireBody = applyGithubCopilotContextTier(finalBody, provider, parsed.modelId, incoming.providerName);
518
+ let wireBody = applyGithubCopilotContextTier(finalBody, provider, parsed.modelId, incoming.providerName);
519
+ if (isOpenAiOperatedResponsesDestination(provider) || provider.reasoningWireFormat !== "gateway-object") {
520
+ wireBody = stripInternalReasoningEnabled(wireBody);
521
+ }
519
522
  const body = JSON.stringify(wireBody);
520
523
  const releaseBodyObservation = translatorBudget.observeExternallyCapped(
521
524
  "passthrough_serialization",
@@ -325,6 +325,19 @@ export function stripDisabledVerbosity(
325
325
  };
326
326
  }
327
327
 
328
+ /**
329
+ * `reasoning.enabled` is an OCX inbound compatibility extension, not an OpenAI Responses
330
+ * parameter. Strip it at Responses egress unless a custom destination explicitly declares
331
+ * the gateway-object wire; thinking capability alone does not declare a wire format.
332
+ */
333
+ export function stripInternalReasoningEnabled(body: unknown): unknown {
334
+ if (!isPlainObject(body) || !isPlainObject(body.reasoning) || !Object.hasOwn(body.reasoning, "enabled")) {
335
+ return body;
336
+ }
337
+ const { enabled: _enabled, ...reasoning } = body.reasoning;
338
+ return { ...body, ...(Object.keys(reasoning).length > 0 ? { reasoning } : { reasoning: undefined }) };
339
+ }
340
+
328
341
  /**
329
342
  * Normalize only the delivery enum Codex already emitted. Do not inject a field into callers that
330
343
  * did not request summaries, and leave every unconfigured provider/model byte-for-byte unchanged.
@@ -27,6 +27,66 @@ export function stripProviderInputItemMetadata(body: unknown): unknown {
27
27
  return input ? { ...body, input } : body;
28
28
  }
29
29
 
30
+ function isUrlCitationIndex(value: unknown): value is number {
31
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
32
+ }
33
+
34
+ /** Coerce a replayed citation index to a non-negative safe integer, falling back to 0. */
35
+ function repairUrlCitationIndex(value: unknown): number {
36
+ if (isUrlCitationIndex(value)) return value;
37
+ if (typeof value === "string" && /^\d+$/.test(value)) {
38
+ const index = Number(value);
39
+ if (isUrlCitationIndex(index)) return index;
40
+ }
41
+ return 0;
42
+ }
43
+
44
+ /**
45
+ * OpenAI Responses requires `title` (string) and integer `start_index`/`end_index` on every
46
+ * `url_citation` annotation of a replayed `output_text` part. History written by an older bridge
47
+ * (title omitted when the search source had none) or a lossy client otherwise fails every later
48
+ * request carrying it, most visibly remote compaction, with a deterministic HTTP 400
49
+ * (`Missing required parameter: input[N].content[M].annotations[K].title`).
50
+ * Repair only those fields on `url_citation` annotations of assistant message content; other
51
+ * annotation types, unknown keys and every other item are untouched. Copy on write: an already
52
+ * valid body is returned by reference.
53
+ */
54
+ export function repairUrlCitationAnnotations(body: unknown): unknown {
55
+ if (!isPlainObject(body) || !Array.isArray(body.input)) return body;
56
+ let input: unknown[] | undefined;
57
+ for (let itemIndex = 0; itemIndex < body.input.length; itemIndex += 1) {
58
+ const item = body.input[itemIndex];
59
+ if (!isPlainObject(item) || !Array.isArray(item.content)) continue;
60
+ let content: unknown[] | undefined;
61
+ for (let partIndex = 0; partIndex < item.content.length; partIndex += 1) {
62
+ const part = item.content[partIndex];
63
+ if (!isPlainObject(part) || part.type !== "output_text" || !Array.isArray(part.annotations)) continue;
64
+ let annotations: unknown[] | undefined;
65
+ for (let annIndex = 0; annIndex < part.annotations.length; annIndex += 1) {
66
+ const ann = part.annotations[annIndex];
67
+ if (!isPlainObject(ann) || ann.type !== "url_citation") continue;
68
+ const titleOk = typeof ann.title === "string";
69
+ const startOk = isUrlCitationIndex(ann.start_index);
70
+ const endOk = isUrlCitationIndex(ann.end_index);
71
+ if (titleOk && startOk && endOk) continue;
72
+ const next: Record<string, unknown> = { ...ann };
73
+ if (!titleOk) next.title = typeof ann.url === "string" ? ann.url : "";
74
+ if (!startOk) next.start_index = repairUrlCitationIndex(ann.start_index);
75
+ if (!endOk) next.end_index = repairUrlCitationIndex(ann.end_index);
76
+ annotations ??= [...part.annotations];
77
+ annotations[annIndex] = next;
78
+ }
79
+ if (!annotations) continue;
80
+ content ??= [...item.content];
81
+ content[partIndex] = { ...part, annotations };
82
+ }
83
+ if (!content) continue;
84
+ input ??= [...body.input];
85
+ input[itemIndex] = { ...item, content };
86
+ }
87
+ return input ? { ...body, input } : body;
88
+ }
89
+
30
90
  export function stripInvalidItemIds(body: unknown): unknown {
31
91
  if (!isPlainObject(body) || !Array.isArray(body.input)) return body;
32
92