@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,20 +10,35 @@
10
10
  * This rewrites one thing: a saved `models` list that is still byte-for-byte the roster
11
11
  * this file names as `from`, on a provider that still carries the registry adapter, and
12
12
  * only while the registry currently seeds `to`. A list the user changed does not match and
13
- * is left alone. For each added id it also fills a per-model context window and default
14
- * effort, but only inside a container the row already has: enrichment fills those records
15
- * all-or-nothing, so creating one here would hide the rest of the registry seed.
13
+ * is left alone. For each added id it also fills a per-model context window, output limit
14
+ * and default effort, but only inside a container the row already has: enrichment fills
15
+ * those records all-or-nothing, so creating one here would hide the rest of the registry seed.
16
16
  * Same shape and restraint as `stale-context-window-migration`.
17
17
  */
18
- import { PROVIDER_REGISTRY } from "./registry";
18
+ import { ALIBABA_INTL_TOKEN_PLAN_BASE_URL, MOONSHOT_CN_BASE_URL, MOONSHOT_INTL_BASE_URL } from "./base-url-choices";
19
+ import { PROVIDER_REGISTRY, normalizedProviderEndpoint } from "./registry";
19
20
  import {
21
+ ALIBABA_TOKEN_PLAN_MODELS,
22
+ ALIBABA_INTL_TOKEN_PLAN_MODELS,
23
+ ALIBABA_TOKEN_PLAN_CONTEXT_WINDOWS,
24
+ ALIBABA_TOKEN_PLAN_MAX_OUTPUT_TOKENS,
25
+ KIMI_API_DEFAULT_REASONING_EFFORTS,
26
+ KIMI_API_MODEL_CONTEXT_WINDOWS,
27
+ KIMI_API_MODELS,
28
+ KIMI_API_MODELS_BEFORE_K31,
29
+ META_MODEL_API_MODELS,
30
+ META_MUSE_CONTEXT_WINDOW,
31
+ META_MUSE_MODELS,
32
+ META_MUSE_WONDER_MODEL,
20
33
  MINIMAX_M31_DEFAULT_REASONING_EFFORT,
21
- MINIMAX_M31_FLASH_PREVIEW,
34
+ MINIMAX_M31_FLASH,
35
+ MINIMAX_M31_FLASH_MAX_OUTPUT_TOKENS,
22
36
  MINIMAX_MODELS,
23
37
  MINIMAX_MODELS_BEFORE_M31,
24
38
  MINIMAX_MODEL_CONTEXT_WINDOWS,
25
39
  } from "./registry/model-seeds";
26
40
  import type { OcxConfig } from "../types";
41
+ import { modelRecordValue } from "../reasoning-effort";
27
42
 
28
43
  export interface StaleModelRoster {
29
44
  /** Registry provider id whose saved rows may carry the old roster. */
@@ -33,7 +48,18 @@ export interface StaleModelRoster {
33
48
  to: readonly string[];
34
49
  /** Per-model seed values for the added ids, written only into containers that exist. */
35
50
  contextWindows?: Readonly<Record<string, number>>;
51
+ /**
52
+ * Custom catalog rows read the saved map directly, so an added id missing from a
53
+ * partial map would publish without the registry output limit.
54
+ */
55
+ maxOutputTokens?: Readonly<Record<string, number>>;
36
56
  defaultReasoningEfforts?: Readonly<Record<string, string>>;
57
+ /**
58
+ * For a provider whose saved URL may point elsewhere (pay-as-you-go or Custom), the
59
+ * destinations whose roster `to` describes. A row on any other URL keeps its list; a row
60
+ * with no saved URL uses the registry default and is refreshed.
61
+ */
62
+ destinationBaseUrls?: readonly string[];
37
63
  }
38
64
 
39
65
  export interface StaleModelRosterProjection {
@@ -42,17 +68,72 @@ export interface StaleModelRosterProjection {
42
68
  warnings: string[];
43
69
  }
44
70
 
71
+ const ALIBABA_TOKEN_PLAN_MODELS_BEFORE_1017 = [
72
+ "qwen3.8-max", "qwen3.8-flash", "qwen3.7-max", "qwen3.7-plus", "qwen3.6-flash",
73
+ "deepseek-v4-pro", "deepseek-v4-flash-0731", "deepseek-v4.1-flash", "glm-5.2", "glm-5.3",
74
+ ];
75
+ const ALIBABA_INTL_TOKEN_PLAN_MODELS_BEFORE_1017 = [
76
+ "qwen3.8-max", "qwen3.8-flash", "qwen3.7-max", "qwen3.7-plus", "qwen3.6-plus", "qwen3.6-flash",
77
+ "deepseek-v4-pro", "deepseek-v4-pro-0813", "deepseek-v4-flash", "deepseek-v4-flash-0731", "deepseek-v4.1-flash", "deepseek-v3.2",
78
+ "kimi-k2.7-code", "kimi-k2.6", "kimi-k2.5",
79
+ "glm-5.2", "glm-5.3", "glm-5.1", "glm-5",
80
+ "MiniMax-M2.5",
81
+ ];
82
+
45
83
  /**
46
- * MiniMax-M3.1-Flash-Preview (2026-09-30). MiniMax's /v1/models roster does not list the
47
- * preview, so live discovery cannot add it; the catalog keeps it only when it is configured.
84
+ * MiniMax-M3.1-Flash (2026-10-21). MiniMax's /v1/models roster does not list the
85
+ * Flash, so live discovery cannot add it; the catalog keeps it only when it is configured.
48
86
  */
49
- export const STALE_MODEL_ROSTERS: readonly StaleModelRoster[] = ["minimax", "minimax-cn"].map(provider => ({
50
- provider,
51
- from: MINIMAX_MODELS_BEFORE_M31,
52
- to: MINIMAX_MODELS,
53
- contextWindows: { [MINIMAX_M31_FLASH_PREVIEW]: MINIMAX_MODEL_CONTEXT_WINDOWS[MINIMAX_M31_FLASH_PREVIEW]! },
54
- defaultReasoningEfforts: { [MINIMAX_M31_FLASH_PREVIEW]: MINIMAX_M31_DEFAULT_REASONING_EFFORT },
55
- }));
87
+ export const STALE_MODEL_ROSTERS: readonly StaleModelRoster[] = [
88
+ {
89
+ provider: "meta-model",
90
+ from: META_MUSE_MODELS,
91
+ to: META_MODEL_API_MODELS,
92
+ contextWindows: { [META_MUSE_WONDER_MODEL]: META_MUSE_CONTEXT_WINDOW },
93
+ // A Custom row may keep this id pointed at another gateway
94
+ // (preserveCustomDestination); only api.meta.ai publishes the roster `to` describes.
95
+ destinationBaseUrls: ["https://api.meta.ai/v1"],
96
+ },
97
+ {
98
+ provider: "deepseek",
99
+ from: ["deepseek-chat", "deepseek-reasoner", "deepseek-flash", "deepseek-v4-flash", "deepseek-v4-flash-vision-exp"],
100
+ to: ["deepseek-chat", "deepseek-reasoner", "deepseek-flash", "deepseek-v4-flash", "deepseek-v4-pro", "deepseek-v4-flash-vision-exp"],
101
+ contextWindows: { "deepseek-v4-pro": 1_048_576 },
102
+ destinationBaseUrls: ["https://api.deepseek.com", "https://api.deepseek.com/v1"],
103
+ },
104
+ ...["minimax", "minimax-cn"].map(provider => ({
105
+ provider,
106
+ from: MINIMAX_MODELS_BEFORE_M31,
107
+ to: MINIMAX_MODELS,
108
+ contextWindows: { [MINIMAX_M31_FLASH]: MINIMAX_MODEL_CONTEXT_WINDOWS[MINIMAX_M31_FLASH]! },
109
+ maxOutputTokens: { [MINIMAX_M31_FLASH]: MINIMAX_M31_FLASH_MAX_OUTPUT_TOKENS },
110
+ defaultReasoningEfforts: { [MINIMAX_M31_FLASH]: MINIMAX_M31_DEFAULT_REASONING_EFFORT },
111
+ })),
112
+ ...[
113
+ { provider: "alibaba-token-plan", from: ALIBABA_TOKEN_PLAN_MODELS_BEFORE_1017, to: ALIBABA_TOKEN_PLAN_MODELS },
114
+ // International honors pay-as-you-go and Custom URLs, which may still serve the retired ids.
115
+ // Beijing needs no guard: the router pins it to the registry Token Plan host.
116
+ {
117
+ provider: "alibaba-token-plan-intl", from: ALIBABA_INTL_TOKEN_PLAN_MODELS_BEFORE_1017, to: ALIBABA_INTL_TOKEN_PLAN_MODELS,
118
+ destinationBaseUrls: [ALIBABA_INTL_TOKEN_PLAN_BASE_URL],
119
+ },
120
+ ].map(entry => ({
121
+ ...entry,
122
+ contextWindows: ALIBABA_TOKEN_PLAN_CONTEXT_WINDOWS,
123
+ maxOutputTokens: ALIBABA_TOKEN_PLAN_MAX_OUTPUT_TOKENS,
124
+ defaultReasoningEfforts: { "deepseek-v4.1-flash-1017": "high" },
125
+ })),
126
+ // Kimi K3.1 Pro (#7653). Both the International and China platforms list kimi-k3.1-pro and
127
+ // -highspeed; a Custom URL may be another gateway, so it keeps its saved list.
128
+ {
129
+ provider: "moonshot",
130
+ from: KIMI_API_MODELS_BEFORE_K31,
131
+ to: KIMI_API_MODELS,
132
+ contextWindows: KIMI_API_MODEL_CONTEXT_WINDOWS,
133
+ defaultReasoningEfforts: KIMI_API_DEFAULT_REASONING_EFFORTS,
134
+ destinationBaseUrls: [MOONSHOT_INTL_BASE_URL, MOONSHOT_CN_BASE_URL],
135
+ },
136
+ ];
56
137
 
57
138
  function sameList(value: unknown, expected: readonly string[]): boolean {
58
139
  return Array.isArray(value)
@@ -65,12 +146,24 @@ function registrySeeds(provider: string, adapter: unknown, roster: readonly stri
65
146
  return entry !== undefined && entry.adapter === adapter && sameList(entry.models, roster);
66
147
  }
67
148
 
68
- function fillExisting<T>(container: Record<string, T> | undefined, values: Readonly<Record<string, T>> | undefined, ids: readonly string[]): void {
69
- if (!container || !values) return;
149
+ function servesRoster(baseUrl: unknown, destinations: readonly string[] | undefined): boolean {
150
+ if (!destinations || baseUrl === undefined || baseUrl === "") return true;
151
+ if (typeof baseUrl !== "string") return false;
152
+ const saved = normalizedProviderEndpoint(baseUrl);
153
+ return destinations.some(url => normalizedProviderEndpoint(url) === saved);
154
+ }
155
+
156
+ function fillExisting<T>(container: Record<string, T> | undefined, values: Readonly<Record<string, T>> | undefined, ids: readonly string[]): boolean {
157
+ if (!container || !values) return false;
158
+ let filled = false;
70
159
  for (const id of ids) {
71
160
  const value = values[id];
72
- if (value !== undefined && !Object.prototype.hasOwnProperty.call(container, id)) container[id] = value;
161
+ if (value !== undefined && modelRecordValue(container, id) === undefined) {
162
+ container[id] = value;
163
+ filled = true;
164
+ }
73
165
  }
166
+ return filled;
74
167
  }
75
168
 
76
169
  /** Pure projection. The caller decides whether to persist. */
@@ -85,10 +178,22 @@ export function projectStaleModelRosters(
85
178
  const prov = config.providers?.[entry.provider];
86
179
  if (!prov) continue;
87
180
  if (!registrySeeds(entry.provider, prov.adapter, entry.to)) continue;
88
- if (!sameList(prov.models, entry.from)) continue;
181
+ if (!servesRoster(prov.baseUrl, entry.destinationBaseUrls)) continue;
89
182
  const added = entry.to.filter(id => !entry.from.includes(id));
183
+ if (sameList(prov.models, entry.to)) {
184
+ // A row refreshed before output limits joined the refresh still has a partial map.
185
+ // Only that record is revisited: the earlier pass already filled windows and efforts,
186
+ // so refilling them could restore a key the operator has since removed.
187
+ if (fillExisting(prov.modelMaxOutputTokens, entry.maxOutputTokens, added)) {
188
+ changed = true;
189
+ warnings.push(`filled output limits for ${added.join(", ")} on the saved "${entry.provider}" row.`);
190
+ }
191
+ continue;
192
+ }
193
+ if (!sameList(prov.models, entry.from)) continue;
90
194
  prov.models = [...entry.to];
91
195
  fillExisting(prov.modelContextWindows, entry.contextWindows, added);
196
+ fillExisting(prov.modelMaxOutputTokens, entry.maxOutputTokens, added);
92
197
  fillExisting(prov.modelDefaultReasoningEfforts, entry.defaultReasoningEfforts, added);
93
198
  changed = true;
94
199
  warnings.push(
@@ -0,0 +1,81 @@
1
+ export interface WorkBuddyCreditAmount {
2
+ total: number;
3
+ used: number;
4
+ remaining: number;
5
+ frozen: number;
6
+ }
7
+
8
+ export const WORKBUDDY_CREDIT_KINDS = ["plan_base", "plan_bonus", "addon", "benefit", "other"] as const;
9
+ export type WorkBuddyCreditKind = typeof WORKBUDDY_CREDIT_KINDS[number];
10
+
11
+ /** Display-only credits; they are neither USD nor provider-wide model eligibility. */
12
+ export interface WorkBuddyCreditBalance extends WorkBuddyCreditAmount {
13
+ groups: Array<WorkBuddyCreditAmount & { kind: WorkBuddyCreditKind }>;
14
+ expiring?: { amount: number; at: number };
15
+ }
16
+
17
+ export function workBuddyRecord(value: unknown): Record<string, unknown> {
18
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
19
+ }
20
+
21
+ export function workBuddyCapacity(value: unknown): number | undefined {
22
+ if (typeof value !== "number" && !(typeof value === "string" && /^\d+(?:\.\d+)?$/.test(value))) return undefined;
23
+ const number = Number(value);
24
+ return Number.isFinite(number) && number >= 0 && number <= Number.MAX_SAFE_INTEGER ? number : undefined;
25
+ }
26
+
27
+ function amount(value: unknown): WorkBuddyCreditAmount | undefined {
28
+ const row = workBuddyRecord(value);
29
+ const total = workBuddyCapacity(row.total), used = workBuddyCapacity(row.used);
30
+ const remaining = workBuddyCapacity(row.remaining), frozen = workBuddyCapacity(row.frozen);
31
+ if (total === undefined || used === undefined || remaining === undefined || frozen === undefined) return undefined;
32
+ return { total, used, remaining, frozen };
33
+ }
34
+
35
+ /** Narrow wire/cache input before rendering, without admitting account or package identifiers. */
36
+ export function normalizeWorkBuddyCredits(value: unknown): WorkBuddyCreditBalance | undefined {
37
+ const row = workBuddyRecord(value), balance = amount(value);
38
+ if (!balance || !Array.isArray(row.groups) || row.groups.length > WORKBUDDY_CREDIT_KINDS.length) return undefined;
39
+ const groups: WorkBuddyCreditBalance["groups"] = [];
40
+ const seen = new Set<string>();
41
+ for (const raw of row.groups) {
42
+ const group = workBuddyRecord(raw), quantities = amount(group);
43
+ const kind = WORKBUDDY_CREDIT_KINDS.find(kind => kind === group.kind);
44
+ if (!quantities || !kind || seen.has(kind)) return undefined;
45
+ seen.add(kind); groups.push({ kind, ...quantities });
46
+ }
47
+ const expiring = workBuddyRecord(row.expiring), quantity = workBuddyCapacity(expiring.amount);
48
+ const at = typeof expiring.at === "number" && expiring.at > 0 && Number.isFinite(new Date(expiring.at).getTime()) ? expiring.at : undefined;
49
+ return { ...balance, groups, ...(quantity !== undefined && quantity > 0 && at !== undefined ? { expiring: { amount: quantity, at } } : {}) };
50
+ }
51
+
52
+ function packageAmount(row: Record<string, unknown>): WorkBuddyCreditAmount | undefined {
53
+ const total = workBuddyCapacity(row.CycleTotalCapacity), used = workBuddyCapacity(row.CycleUsedCapacity);
54
+ const frozen = row.CycleFrozenCapacity === undefined ? 0 : workBuddyCapacity(row.CycleFrozenCapacity);
55
+ if (total === undefined || used === undefined || frozen === undefined) return undefined;
56
+ const remaining = row.CycleRemainCapacity === undefined ? Math.max(0, total - used - frozen) : workBuddyCapacity(row.CycleRemainCapacity);
57
+ return remaining === undefined ? undefined : { total, used, remaining, frozen };
58
+ }
59
+
60
+ export function parseWorkBuddyCredits(value: unknown): WorkBuddyCreditBalance | undefined {
61
+ const summary = workBuddyRecord(value);
62
+ if (!Array.isArray(summary.Packages) || summary.Packages.length > 512) return undefined;
63
+ const balance: WorkBuddyCreditBalance = { total: 0, used: 0, remaining: 0, frozen: 0, groups: [] };
64
+ for (const raw of summary.Packages) {
65
+ const quantities = packageAmount(workBuddyRecord(raw));
66
+ if (!quantities) return undefined;
67
+ for (const key of ["total", "used", "remaining", "frozen"] as const) balance[key] += quantities[key];
68
+ }
69
+ // CreditGroups is a breakdown of Packages, not another balance to add to it.
70
+ if (Array.isArray(summary.CreditGroups) && summary.CreditGroups.length <= 16) {
71
+ for (const raw of summary.CreditGroups) {
72
+ const row = workBuddyRecord(raw), quantities = packageAmount(row);
73
+ if (!quantities) continue;
74
+ const kind = WORKBUDDY_CREDIT_KINDS.find(kind => kind === row.Kind) ?? "other";
75
+ const existing = balance.groups.find(group => group.kind === kind);
76
+ if (existing) for (const key of ["total", "used", "remaining", "frozen"] as const) existing[key] += quantities[key];
77
+ else balance.groups.push({ kind, ...quantities });
78
+ }
79
+ }
80
+ return normalizeWorkBuddyCredits(balance);
81
+ }
@@ -0,0 +1,37 @@
1
+ import { isValidModelDiscoveryModelId } from "./model-discovery-limits";
2
+ import type { ProviderModelItemsResult, ProviderModelsApiItem } from "./model-discovery";
3
+
4
+ function record(value: unknown): Record<string, unknown> {
5
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
6
+ }
7
+
8
+ /** The product catalog contains non-chat models too; only the CLI agent's roster is routable. */
9
+ export function extractWorkBuddyModels(value: unknown, limit: number): ProviderModelItemsResult {
10
+ const envelope = record(value), data = record(envelope.data);
11
+ if ((envelope.code !== 0 && envelope.code !== "0") || !Array.isArray(data.agents) || !Array.isArray(data.models)) return { ok: false, reason: "invalid_shape" };
12
+ if (data.models.length > limit || data.agents.length > limit) return { ok: false, reason: "too_many_models" };
13
+ const agent = data.agents.map(record).find(a => a.name === "cli");
14
+ if (!Array.isArray(agent?.models)) return { ok: false, reason: "invalid_shape" };
15
+ if (agent.models.length > limit) return { ok: false, reason: "too_many_models" };
16
+ const definitions = new Map(data.models.map(raw => { const row = record(raw); return [row.id, row] as const; }));
17
+ const items: ProviderModelsApiItem[] = [], seen = new Set<string>();
18
+ for (const id of agent.models) {
19
+ if (!isValidModelDiscoveryModelId(id)) return { ok: false, reason: "invalid_shape" };
20
+ if (seen.has(id)) continue;
21
+ seen.add(id);
22
+ const row = definitions.get(id) ?? {}, reasoning = record(row.reasoning);
23
+ const rawEfforts = Array.isArray(reasoning.supportedEfforts) ? reasoning.supportedEfforts
24
+ : row.supportsReasoning === true ? ["low", "high", "max"] : [];
25
+ const efforts = rawEfforts.filter(e => typeof e === "string" && ["low", "medium", "high", "xhigh", "max"].includes(e));
26
+ if (efforts.length && row.onlyReasoning !== true && reasoning.canDisableThinking !== false) efforts.unshift("none");
27
+ const positive = (v: unknown) => typeof v === "number" && Number.isSafeInteger(v) && v > 0 ? v : undefined;
28
+ items.push({
29
+ id, ...(typeof row.name === "string" && row.name.length <= 256 ? { name: row.name } : {}),
30
+ context_length: positive(row.maxInputTokens), max_input_tokens: positive(row.maxInputTokens),
31
+ max_output_tokens: positive(row.maxOutputTokens), reasoning_efforts: efforts,
32
+ // WorkBuddy AI filters images from GLM requests despite advertising supportsImages.
33
+ input_modalities: row.supportsImages === true && !id.startsWith("glm-") ? ["text", "image"] : ["text"],
34
+ });
35
+ }
36
+ return { ok: true, items, rawCount: agent.models.length };
37
+ }
@@ -0,0 +1,60 @@
1
+ import type { WorkBuddyOAuthMetadata } from "../oauth/types";
2
+ import { createHash } from "node:crypto";
3
+
4
+ export const WORKBUDDY_ORIGIN = "https://www.workbuddy.ai";
5
+ export const WORKBUDDY_BASE_URL = `${WORKBUDDY_ORIGIN}/v2`;
6
+ export const WORKBUDDY_CONFIG_URL = `${WORKBUDDY_ORIGIN}/v3/config`;
7
+ export const WORKBUDDY_USER_AGENT = "WorkBuddy/5.5.6";
8
+
9
+ export function workBuddyCatalogIdentity(access: string, metadata: WorkBuddyOAuthMetadata | undefined): string {
10
+ return createHash("sha256").update(JSON.stringify([access, metadata])).digest("hex");
11
+ }
12
+
13
+ export function workBuddyHeaderValue(value: unknown, max = 1024): value is string {
14
+ return typeof value === "string" && value.length > 0 && value.length <= max && /^[\x21-\x7e]+$/.test(value);
15
+ }
16
+
17
+ export function normalizeWorkBuddyMetadata(value: unknown): WorkBuddyOAuthMetadata | undefined {
18
+ if (!value || typeof value !== "object") return undefined;
19
+ const v = value as Partial<WorkBuddyOAuthMetadata>;
20
+ if (!workBuddyHeaderValue(v.uid) || !workBuddyHeaderValue(v.domain)) return undefined;
21
+ if (v.enterpriseId !== undefined && !workBuddyHeaderValue(v.enterpriseId)) return undefined;
22
+ return {
23
+ uid: v.uid, domain: v.domain,
24
+ ...(v.enterpriseId ? { enterpriseId: v.enterpriseId } : {}),
25
+ ...(typeof v.refreshExpiresAt === "number" && Number.isFinite(v.refreshExpiresAt) && v.refreshExpiresAt > 0
26
+ ? { refreshExpiresAt: v.refreshExpiresAt } : {}),
27
+ };
28
+ }
29
+
30
+ export function assertWorkBuddyDestination(baseUrl: string): void {
31
+ const u = new URL(baseUrl);
32
+ if (u.origin !== WORKBUDDY_ORIGIN || u.username || u.password || u.search || u.hash
33
+ || !["", "/v2", "/v2/chat/completions"].includes(u.pathname.replace(/\/+$/, ""))) {
34
+ throw new Error("WorkBuddy AI credentials require https://www.workbuddy.ai/v2");
35
+ }
36
+ }
37
+
38
+ export function workBuddyHeaders(access: string | undefined, metadata?: WorkBuddyOAuthMetadata): Record<string, string> {
39
+ const headers: Record<string, string> = {
40
+ "User-Agent": WORKBUDDY_USER_AGENT,
41
+ "X-Product": "SaaS", "X-IDE-Type": "WorkBuddy", "X-IDE-Name": "WorkBuddy",
42
+ "X-IDE-Version": "5.5.6", "X-Requested-With": "XMLHttpRequest",
43
+ "X-Agent-Intent": "craft", "X-Agent-Purpose": "conversation", "X-Agent-Type": "main",
44
+ };
45
+ if (access) {
46
+ if (!workBuddyHeaderValue(access, 32768)) throw new Error("Invalid WorkBuddy AI access token");
47
+ headers.Authorization = `Bearer ${access}`;
48
+ }
49
+ if (metadata) {
50
+ const valid = normalizeWorkBuddyMetadata(metadata);
51
+ if (!valid) throw new Error("WorkBuddy AI account identity unavailable; sign in again");
52
+ headers["X-User-Id"] = valid.uid;
53
+ headers["X-Domain"] = valid.domain;
54
+ if (valid.enterpriseId) {
55
+ headers["X-Enterprise-Id"] = valid.enterpriseId;
56
+ headers["X-Tenant-Id"] = valid.enterpriseId;
57
+ }
58
+ }
59
+ return headers;
60
+ }
@@ -137,13 +137,18 @@ class PiRpcProcess {
137
137
  async prompt(message: string): Promise<void> {
138
138
  if (this.activeSettle) throw new Error("Pi Remote Workspace turn is already active");
139
139
  const settled = new Promise<void>((resolve, reject) => { this.activeSettle = { resolve, reject }; });
140
+ const active = this.activeSettle;
140
141
  try {
141
- const accepted = await this.command("prompt", { message });
142
- if (accepted.success !== true) throw new Error(safeError(accepted.error, "Pi rejected the prompt"));
143
- await settled;
144
- } catch (error) {
145
- this.activeSettle = null;
146
- throw error;
142
+ // Either operation can fail first. Observe both immediately, including an
143
+ // extension error or child exit that arrives before the prompt response.
144
+ await Promise.all([
145
+ this.command("prompt", { message }).then(accepted => {
146
+ if (accepted.success !== true) throw new Error(safeError(accepted.error, "Pi rejected the prompt"));
147
+ }),
148
+ settled,
149
+ ]);
150
+ } finally {
151
+ if (this.activeSettle === active) this.activeSettle = null;
147
152
  }
148
153
  }
149
154
 
@@ -0,0 +1,45 @@
1
+ import type { AdapterEvent } from "../types";
2
+ import { releaseTranslatedEvent, type TranslatorBudget } from "../lib/translator-budget";
3
+ import { isTruncatedStopReason } from "./truncated-stop-reason";
4
+
5
+ /** Keep client/hosted tool events out of a routed Anthropic summary's compaction item. */
6
+ export async function* guardCompactionSummary(
7
+ events: AsyncIterable<AdapterEvent>,
8
+ budget: TranslatorBudget,
9
+ ): AsyncGenerator<AdapterEvent> {
10
+ let hasText = false;
11
+ let attemptedTool = false;
12
+ for await (const event of events) {
13
+ if (event.type === "text_delta" && !event.anthropicThinkingSignature) {
14
+ hasText ||= event.text.trim().length > 0;
15
+ yield event;
16
+ continue;
17
+ }
18
+ if (event.type === "error" || event.type === "incomplete") {
19
+ yield event;
20
+ return;
21
+ }
22
+ if (event.type === "done") {
23
+ if (!isTruncatedStopReason(event.stopReason)
24
+ // An absent stop reason is accepted, as on every other completion path: some
25
+ // Anthropic-compatible endpoints omit it. An explicit non-terminal reason is not.
26
+ && (attemptedTool || !hasText
27
+ || (event.stopReason !== undefined && event.stopReason !== "end_turn" && event.stopReason !== "stop_sequence"))) {
28
+ releaseTranslatedEvent(event, budget);
29
+ yield {
30
+ type: "error", status: 502, errorType: "upstream_error",
31
+ code: "compaction_invalid_summary", retryable: false,
32
+ message: "Compaction requires a non-empty text summary without tool calls and a normal completion.",
33
+ usage: event.usage,
34
+ };
35
+ } else {
36
+ yield event;
37
+ }
38
+ return;
39
+ }
40
+ if (event.type === "tool_call_start" || event.type === "tool_call_delta" || event.type === "tool_call_end"
41
+ || event.type === "web_search_call_begin" || event.type === "web_search_call_end") attemptedTool = true;
42
+ releaseTranslatedEvent(event, budget);
43
+ yield { type: "heartbeat" };
44
+ }
45
+ }
@@ -1,4 +1,3 @@
1
- import { createHash } from "node:crypto";
2
1
  import { wireToolInnerName } from "./tool-name-aliases";
3
2
 
4
3
  const MUSE_TOOL_NAME_MAX = 64;
@@ -53,7 +52,7 @@ function isPassThroughMuseToolName(name: string): boolean {
53
52
 
54
53
  function hashSuffix(originalName: string, salt: number): string {
55
54
  const hashInput = salt === 0 ? originalName : originalName + "#" + salt;
56
- return createHash("sha256").update(hashInput).digest("hex").slice(0, MUSE_TOOL_NAME_HASH_LEN);
55
+ return Bun.SHA256.hash(hashInput, "hex").slice(0, MUSE_TOOL_NAME_HASH_LEN);
57
56
  }
58
57
 
59
58
  /**
@@ -185,8 +185,8 @@ function attachPendingReasoningToCallOwner(
185
185
 
186
186
  const REASONING_EFFORTS = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
187
187
 
188
- export function hasValidatedActiveReasoningEffort(options: Pick<OcxRequestOptions, "reasoning">): boolean {
189
- return options.reasoning !== undefined && options.reasoning !== "none";
188
+ export function hasValidatedActiveReasoningEffort(options: Pick<OcxRequestOptions, "reasoning" | "thinkingEnabled">): boolean {
189
+ return options.thinkingEnabled ?? (options.reasoning !== undefined && options.reasoning !== "none");
190
190
  }
191
191
 
192
192
 
@@ -695,6 +695,7 @@ export function parseRequest(
695
695
  // `reasoning_effort_for_request`), so current clients never send it — but a catalog that
696
696
  // advertises ultra plus an older/direct caller can. Degrade it to max like upstream instead of
697
697
  // silently dropping reasoning altogether.
698
+ if (data.reasoning?.enabled !== undefined) options.thinkingEnabled = data.reasoning.enabled;
698
699
  const requestedEffort = data.reasoning?.effort === "ultra" ? "max" : data.reasoning?.effort;
699
700
  if (requestedEffort && REASONING_EFFORTS.has(requestedEffort)) {
700
701
  options.reasoning = requestedEffort;
@@ -143,8 +143,9 @@ function tupleForServingIdentity(
143
143
 
144
144
  function keyFor(callId: string, scope: OcxReasoningReplayScopeRef | undefined): string | undefined {
145
145
  const identity = tupleForIdentity(scope?.current);
146
- if (!nonEmpty(callId) || !nonEmpty(scope?.clientThreadId) || !identity) return undefined;
146
+ if (!nonEmpty(callId) || !nonEmpty(scope?.clientPrincipalId) || !nonEmpty(scope.clientThreadId) || !identity) return undefined;
147
147
  return JSON.stringify([
148
+ scope.clientPrincipalId,
148
149
  scope.clientThreadId,
149
150
  ...identity,
150
151
  callId,
@@ -166,18 +167,21 @@ function sweepExpiredServingIdentities(at: number): void {
166
167
 
167
168
  function servingIdentityFor(
168
169
  scope: OcxReasoningReplayScopeRef | undefined,
169
- ): { threadId: string; identity: string } | undefined {
170
+ ): { key: string; identity: string } | undefined {
170
171
  const threadId = scope?.clientThreadId;
171
172
  const identityTuple = tupleForServingIdentity(scope?.current);
172
173
  if (!nonEmpty(threadId) || !identityTuple) return undefined;
173
- return { threadId, identity: JSON.stringify(identityTuple) };
174
+ // Preserve physical safeguards for keyless callers in a separate namespace. A caller's
175
+ // thread name cannot select an authenticated principal's serving or rejection history.
176
+ const key = JSON.stringify([nonEmpty(scope?.clientPrincipalId) ? scope.clientPrincipalId : null, threadId]);
177
+ return { key, identity: JSON.stringify(identityTuple) };
174
178
  }
175
179
 
176
180
  function opaqueBlobRejectionKeyFor(
177
181
  scope: OcxReasoningReplayScopeRef | undefined,
178
182
  ): string | undefined {
179
183
  const current = servingIdentityFor(scope);
180
- return current ? JSON.stringify([current.threadId, current.identity]) : undefined;
184
+ return current ? JSON.stringify([current.key, current.identity]) : undefined;
181
185
  }
182
186
 
183
187
  function deleteOpaqueBlobRejection(key: string): void {
@@ -224,7 +228,7 @@ export function reasoningReplayServingIdentityChange(
224
228
  if (!current) return undefined;
225
229
  const at = now();
226
230
  sweepExpiredServingIdentities(at);
227
- const previous = servingIdentities.get(current.threadId);
231
+ const previous = servingIdentities.get(current.key);
228
232
  if (previous === undefined || previous.identity === current.identity) return undefined;
229
233
  const before = JSON.parse(previous.identity) as ReasoningReplayIdentityTuple;
230
234
  const after = JSON.parse(current.identity) as ReasoningReplayIdentityTuple;
@@ -254,7 +258,7 @@ export function reasoningReplayItemStoreChanged(
254
258
  if (!current) return false;
255
259
  const at = now();
256
260
  sweepExpiredServingIdentities(at);
257
- const previous = servingIdentities.get(current.threadId);
261
+ const previous = servingIdentities.get(current.key);
258
262
  if (previous === undefined || previous.identity === current.identity) return false;
259
263
  const storeOwner = (identity: string): string => {
260
264
  const [, destination, , , credential] = JSON.parse(identity) as ReasoningReplayIdentityTuple;
@@ -271,16 +275,16 @@ export function commitReasoningReplayServingIdentity(
271
275
  if (!current) return;
272
276
  const at = now();
273
277
  sweepExpiredServingIdentities(at);
274
- const previous = servingIdentities.get(current.threadId);
275
- const { threadId, identity } = current;
276
- const bytes = Buffer.byteLength(JSON.stringify([threadId, identity]), "utf8");
278
+ const previous = servingIdentities.get(current.key);
279
+ const { key, identity } = current;
280
+ const bytes = Buffer.byteLength(JSON.stringify([key, identity]), "utf8");
277
281
  if (bytes > MAX_TOTAL_BYTES) {
278
- deleteServingIdentity(threadId);
282
+ deleteServingIdentity(key);
279
283
  return;
280
284
  }
281
285
 
282
- if (previous) deleteServingIdentity(threadId);
283
- servingIdentities.set(threadId, { identity, bytes, at });
286
+ if (previous) deleteServingIdentity(key);
287
+ servingIdentities.set(key, { identity, bytes, at });
284
288
  servingIdentityTotalBytes += bytes;
285
289
  while (
286
290
  (servingIdentityTotalBytes > MAX_TOTAL_BYTES || servingIdentities.size > MAX_ENTRIES)
@@ -517,13 +521,13 @@ export function reasoningReplayKeyCredentialIdentity(
517
521
  return reasoningReplayCredentialIdentity("key", apiKey, provider.headers);
518
522
  }
519
523
 
520
- /** Replace only the holder snapshot so parsed-request copies observe rotations. */
524
+ /** Bind physical identity independently of the principal required for plaintext cache access. */
521
525
  export function bindReasoningReplayScope(
522
526
  scope: OcxReasoningReplayScopeRef | undefined,
523
527
  identity: OcxReasoningReplayIdentity | undefined,
524
528
  ): void {
525
529
  if (!scope) return;
526
- if (!identity || !keyFor("binding-check", { ...scope, current: identity })) {
530
+ if (!identity || !nonEmpty(scope.clientThreadId) || !tupleForIdentity(identity)) {
527
531
  delete scope.current;
528
532
  return;
529
533
  }
@@ -180,6 +180,7 @@ export const toolChoiceSchema = z.union([
180
180
  ]);
181
181
 
182
182
  export const reasoningConfigSchema = z.object({
183
+ enabled: z.boolean().optional(),
183
184
  effort: z.string().optional(),
184
185
  summary: z.enum(["auto", "concise", "detailed", "none"]).optional(),
185
186
  });
@@ -64,6 +64,7 @@ let entries = new Map<string, StoredEntry>();
64
64
  let totalBytes = 0;
65
65
  let loaded = false;
66
66
  let persistChain: Promise<void> = Promise.resolve();
67
+ let pendingPersist: Promise<void> | undefined;
67
68
 
68
69
  function storePath(): string {
69
70
  return join(getConfigDir(), STORE_FILE_NAME);
@@ -203,8 +204,12 @@ function prune(nowMs: number): void {
203
204
  }
204
205
 
205
206
  function persist(): Promise<void> {
206
- persistChain = persistChain
207
+ // Mutations share a queued snapshot only until serialization starts. Arrivals during
208
+ // its write get a subsequent batch, without extending earlier callers' barriers.
209
+ if (pendingPersist) return pendingPersist;
210
+ const batch = persistChain
207
211
  .then(async () => {
212
+ if (pendingPersist === batch) pendingPersist = undefined;
208
213
  const snapshot = JSON.stringify({
209
214
  version: STORE_VERSION,
210
215
  entries: [...entries].map(([key, entry]) => ({ key, sig: entry.sig, savedAt: entry.savedAt })),
@@ -214,7 +219,9 @@ function persist(): Promise<void> {
214
219
  .catch(() => {
215
220
  // Best-effort persistence: the in-memory store still serves the running process.
216
221
  });
217
- return persistChain;
222
+ pendingPersist = batch;
223
+ persistChain = batch;
224
+ return batch;
218
225
  }
219
226
 
220
227
  /**
@@ -331,6 +338,7 @@ export function resetThoughtSignatureReplayForTests(): void {
331
338
  totalBytes = 0;
332
339
  loaded = false;
333
340
  persistChain = Promise.resolve();
341
+ pendingPersist = undefined;
334
342
  cachedSalt = undefined;
335
343
  saltLoaded = false;
336
344
  }
package/src/router.ts CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  import { decodeRoutedModelIdOrThrow, encodeRoutedModelId } from "./providers/slug-codec";
34
34
  import { effectiveProviderAliasDecision, resolveModelAlias } from "./providers/default-aliases";
35
35
  import { resolveBlockedModelRedirect } from "./lib/shadow-call";
36
+ import { workBuddyCatalogIdentity } from "./providers/workbuddy";
36
37
  import { getRoutingCached } from "./codex/model-cache";
37
38
  import { codexAccountNamespaceEntries } from "./codex/account-namespaces";
38
39
  import {
@@ -177,6 +178,7 @@ export function knownModelIdsForProvider(
177
178
  if (!account || account.needsReauth || !Number.isFinite(account.credential.expires)
178
179
  || account.credential.expires <= Date.now()) return undefined;
179
180
  key = account.credential.access;
181
+ if (provName === "workbuddy-ai") return workBuddyCatalogIdentity(key, account.credential.workbuddy);
180
182
  if (routed.adapter === "devin") destination = validateDevinApiBaseUrl(account.credential.apiBaseUrl) ?? routed.baseUrl;
181
183
  }
182
184
  if (!key) return undefined;