onlycode 1.18.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/bin/{opencode.cjs → onlycode.cjs} +8 -42
  2. package/package.json +12 -147
  3. package/src/account/account.ts +0 -463
  4. package/src/account/repo.ts +0 -173
  5. package/src/account/schema.ts +0 -99
  6. package/src/account/url.ts +0 -8
  7. package/src/acp/agent.ts +0 -95
  8. package/src/acp/config-option.ts +0 -203
  9. package/src/acp/content.ts +0 -250
  10. package/src/acp/directory.ts +0 -210
  11. package/src/acp/error.ts +0 -90
  12. package/src/acp/event.ts +0 -342
  13. package/src/acp/permission.ts +0 -124
  14. package/src/acp/profile.ts +0 -42
  15. package/src/acp/service.ts +0 -1048
  16. package/src/acp/session.ts +0 -231
  17. package/src/acp/tool.ts +0 -367
  18. package/src/acp/usage.ts +0 -232
  19. package/src/agent/agent.ts +0 -459
  20. package/src/agent/generate.txt +0 -75
  21. package/src/agent/prompt/compaction.txt +0 -9
  22. package/src/agent/prompt/explore.txt +0 -18
  23. package/src/agent/prompt/summary.txt +0 -11
  24. package/src/agent/prompt/title.txt +0 -44
  25. package/src/agent/subagent-permissions.ts +0 -27
  26. package/src/audio.d.ts +0 -14
  27. package/src/auth/index.ts +0 -99
  28. package/src/background/job.ts +0 -39
  29. package/src/bus/global.ts +0 -22
  30. package/src/cli/bootstrap.ts +0 -11
  31. package/src/cli/cmd/account.ts +0 -264
  32. package/src/cli/cmd/acp.ts +0 -73
  33. package/src/cli/cmd/agent.ts +0 -259
  34. package/src/cli/cmd/attach.ts +0 -97
  35. package/src/cli/cmd/cmd.ts +0 -7
  36. package/src/cli/cmd/db.ts +0 -62
  37. package/src/cli/cmd/debug/agent.handler.ts +0 -193
  38. package/src/cli/cmd/debug/agent.ts +0 -27
  39. package/src/cli/cmd/debug/config.ts +0 -14
  40. package/src/cli/cmd/debug/file.ts +0 -73
  41. package/src/cli/cmd/debug/index.ts +0 -87
  42. package/src/cli/cmd/debug/lsp.ts +0 -50
  43. package/src/cli/cmd/debug/ripgrep.ts +0 -79
  44. package/src/cli/cmd/debug/scrap.ts +0 -15
  45. package/src/cli/cmd/debug/skill.ts +0 -15
  46. package/src/cli/cmd/debug/snapshot.ts +0 -50
  47. package/src/cli/cmd/debug/startup.ts +0 -11
  48. package/src/cli/cmd/debug/v2.ts +0 -44
  49. package/src/cli/cmd/export.ts +0 -292
  50. package/src/cli/cmd/generate.ts +0 -54
  51. package/src/cli/cmd/github.handler.ts +0 -1593
  52. package/src/cli/cmd/github.shared.ts +0 -30
  53. package/src/cli/cmd/github.ts +0 -42
  54. package/src/cli/cmd/import.ts +0 -224
  55. package/src/cli/cmd/mcp.ts +0 -849
  56. package/src/cli/cmd/models.ts +0 -66
  57. package/src/cli/cmd/plug.ts +0 -230
  58. package/src/cli/cmd/pr.ts +0 -115
  59. package/src/cli/cmd/prompt-display.ts +0 -1
  60. package/src/cli/cmd/providers.ts +0 -534
  61. package/src/cli/cmd/run/demo.ts +0 -1274
  62. package/src/cli/cmd/run/entry.body.ts +0 -205
  63. package/src/cli/cmd/run/footer.command.tsx +0 -1064
  64. package/src/cli/cmd/run/footer.menu.tsx +0 -351
  65. package/src/cli/cmd/run/footer.permission.tsx +0 -472
  66. package/src/cli/cmd/run/footer.prompt.tsx +0 -1306
  67. package/src/cli/cmd/run/footer.question.tsx +0 -573
  68. package/src/cli/cmd/run/footer.subagent.tsx +0 -173
  69. package/src/cli/cmd/run/footer.ts +0 -1129
  70. package/src/cli/cmd/run/footer.view.tsx +0 -943
  71. package/src/cli/cmd/run/footer.width.ts +0 -27
  72. package/src/cli/cmd/run/permission.shared.ts +0 -256
  73. package/src/cli/cmd/run/prompt.editor.ts +0 -157
  74. package/src/cli/cmd/run/prompt.shared.ts +0 -153
  75. package/src/cli/cmd/run/question.shared.ts +0 -340
  76. package/src/cli/cmd/run/runtime.boot.ts +0 -202
  77. package/src/cli/cmd/run/runtime.lifecycle.ts +0 -406
  78. package/src/cli/cmd/run/runtime.queue.ts +0 -349
  79. package/src/cli/cmd/run/runtime.shared.ts +0 -17
  80. package/src/cli/cmd/run/runtime.stdin.ts +0 -37
  81. package/src/cli/cmd/run/runtime.ts +0 -814
  82. package/src/cli/cmd/run/scrollback.shared.ts +0 -92
  83. package/src/cli/cmd/run/scrollback.surface.ts +0 -431
  84. package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
  85. package/src/cli/cmd/run/session-data.ts +0 -1113
  86. package/src/cli/cmd/run/session-replay.ts +0 -374
  87. package/src/cli/cmd/run/session.shared.ts +0 -196
  88. package/src/cli/cmd/run/splash.ts +0 -275
  89. package/src/cli/cmd/run/stream.transport.ts +0 -1462
  90. package/src/cli/cmd/run/stream.ts +0 -175
  91. package/src/cli/cmd/run/subagent-data.ts +0 -876
  92. package/src/cli/cmd/run/theme.ts +0 -690
  93. package/src/cli/cmd/run/tool.ts +0 -1489
  94. package/src/cli/cmd/run/trace.ts +0 -94
  95. package/src/cli/cmd/run/turn-summary.ts +0 -47
  96. package/src/cli/cmd/run/types.ts +0 -350
  97. package/src/cli/cmd/run/variant.shared.ts +0 -215
  98. package/src/cli/cmd/run.ts +0 -894
  99. package/src/cli/cmd/serve.ts +0 -24
  100. package/src/cli/cmd/session.ts +0 -147
  101. package/src/cli/cmd/stats.ts +0 -393
  102. package/src/cli/cmd/tui.ts +0 -224
  103. package/src/cli/cmd/uninstall.ts +0 -353
  104. package/src/cli/cmd/upgrade.ts +0 -74
  105. package/src/cli/cmd/web.ts +0 -84
  106. package/src/cli/effect/prompt.ts +0 -37
  107. package/src/cli/effect-cmd.ts +0 -96
  108. package/src/cli/error.ts +0 -130
  109. package/src/cli/heap.ts +0 -45
  110. package/src/cli/logo-pixel.ts +0 -35
  111. package/src/cli/logo.ts +0 -1
  112. package/src/cli/network.ts +0 -64
  113. package/src/cli/tui/layer.ts +0 -7
  114. package/src/cli/tui/validate-session.ts +0 -29
  115. package/src/cli/tui/worker.ts +0 -71
  116. package/src/cli/ui.ts +0 -148
  117. package/src/cli/upgrade.ts +0 -53
  118. package/src/command/index.ts +0 -184
  119. package/src/command/template/initialize.txt +0 -66
  120. package/src/command/template/review.txt +0 -101
  121. package/src/config/agent.ts +0 -59
  122. package/src/config/command.ts +0 -39
  123. package/src/config/config.ts +0 -686
  124. package/src/config/entry-name.ts +0 -19
  125. package/src/config/managed.ts +0 -69
  126. package/src/config/markdown.ts +0 -36
  127. package/src/config/parse.ts +0 -79
  128. package/src/config/paths.ts +0 -45
  129. package/src/config/plugin.ts +0 -79
  130. package/src/config/tui-cwd.ts +0 -5
  131. package/src/config/tui-host-attention.ts +0 -21
  132. package/src/config/tui-migrate.ts +0 -132
  133. package/src/config/tui.ts +0 -274
  134. package/src/config/variable.ts +0 -91
  135. package/src/control-plane/adapters/index.ts +0 -41
  136. package/src/control-plane/adapters/worktree.ts +0 -96
  137. package/src/control-plane/dev/README.md +0 -19
  138. package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
  139. package/src/control-plane/types.ts +0 -59
  140. package/src/control-plane/util.ts +0 -39
  141. package/src/control-plane/workspace-adapter-runtime.ts +0 -51
  142. package/src/control-plane/workspace-context.ts +0 -26
  143. package/src/control-plane/workspace.ts +0 -989
  144. package/src/effect/app-runtime.ts +0 -132
  145. package/src/effect/bootstrap-runtime.ts +0 -23
  146. package/src/effect/bridge.ts +0 -84
  147. package/src/effect/config-service.ts +0 -67
  148. package/src/effect/instance-ref.ts +0 -11
  149. package/src/effect/instance-registry.ts +0 -12
  150. package/src/effect/instance-state.ts +0 -69
  151. package/src/effect/promise.ts +0 -17
  152. package/src/effect/run-service.ts +0 -47
  153. package/src/effect/runner.ts +0 -217
  154. package/src/effect/runtime-flags.ts +0 -79
  155. package/src/env/index.ts +0 -43
  156. package/src/event-v2-bridge.ts +0 -79
  157. package/src/format/formatter.ts +0 -404
  158. package/src/format/index.ts +0 -205
  159. package/src/git/index.ts +0 -350
  160. package/src/id/id.ts +0 -80
  161. package/src/ide/index.ts +0 -61
  162. package/src/image/image.ts +0 -174
  163. package/src/index.ts +0 -142
  164. package/src/installation/index.ts +0 -350
  165. package/src/lsp/client.ts +0 -650
  166. package/src/lsp/diagnostic.ts +0 -29
  167. package/src/lsp/language.ts +0 -121
  168. package/src/lsp/launch.ts +0 -21
  169. package/src/lsp/lsp.ts +0 -511
  170. package/src/lsp/server.ts +0 -1983
  171. package/src/markdown.d.ts +0 -4
  172. package/src/mcp/auth.ts +0 -174
  173. package/src/mcp/catalog.ts +0 -153
  174. package/src/mcp/index.ts +0 -953
  175. package/src/mcp/oauth-callback.ts +0 -233
  176. package/src/mcp/oauth-provider.ts +0 -206
  177. package/src/node.ts +0 -4
  178. package/src/patch/index.ts +0 -686
  179. package/src/permission/arity.ts +0 -163
  180. package/src/permission/evaluate.ts +0 -1
  181. package/src/permission/index.ts +0 -230
  182. package/src/plugin/azure.ts +0 -26
  183. package/src/plugin/cloudflare.ts +0 -76
  184. package/src/plugin/digitalocean.ts +0 -383
  185. package/src/plugin/github-copilot/copilot.ts +0 -414
  186. package/src/plugin/github-copilot/models.ts +0 -246
  187. package/src/plugin/index.ts +0 -316
  188. package/src/plugin/install.ts +0 -439
  189. package/src/plugin/loader.ts +0 -237
  190. package/src/plugin/meta.ts +0 -188
  191. package/src/plugin/openai/README.md +0 -31
  192. package/src/plugin/openai/codex.ts +0 -641
  193. package/src/plugin/openai/ws-pool.ts +0 -270
  194. package/src/plugin/openai/ws.ts +0 -381
  195. package/src/plugin/pty-environment.ts +0 -24
  196. package/src/plugin/shared.ts +0 -323
  197. package/src/plugin/snowflake-cortex.ts +0 -529
  198. package/src/plugin/tui/internal.ts +0 -10
  199. package/src/plugin/tui/runtime.ts +0 -1130
  200. package/src/plugin/xai.ts +0 -716
  201. package/src/project/bootstrap-service.ts +0 -9
  202. package/src/project/bootstrap.ts +0 -76
  203. package/src/project/instance-context.ts +0 -24
  204. package/src/project/instance-layer.ts +0 -11
  205. package/src/project/instance-runtime.ts +0 -16
  206. package/src/project/instance-store.ts +0 -209
  207. package/src/project/project.ts +0 -519
  208. package/src/project/vcs.ts +0 -431
  209. package/src/provider/auth.ts +0 -233
  210. package/src/provider/error.ts +0 -188
  211. package/src/provider/model-status.ts +0 -8
  212. package/src/provider/provider.ts +0 -1975
  213. package/src/provider/transform.ts +0 -1543
  214. package/src/question/index.ts +0 -229
  215. package/src/question/schema.ts +0 -10
  216. package/src/server/auth.ts +0 -48
  217. package/src/server/event.ts +0 -13
  218. package/src/server/global-lifecycle.ts +0 -28
  219. package/src/server/init-projectors.ts +0 -3
  220. package/src/server/mdns.ts +0 -47
  221. package/src/server/projectors.ts +0 -1
  222. package/src/server/proxy-util.ts +0 -48
  223. package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
  224. package/src/server/routes/instance/httpapi/api.ts +0 -78
  225. package/src/server/routes/instance/httpapi/errors.ts +0 -193
  226. package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
  227. package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
  228. package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
  229. package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
  230. package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -275
  231. package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
  232. package/src/server/routes/instance/httpapi/groups/global.ts +0 -138
  233. package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
  234. package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
  235. package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
  236. package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
  237. package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
  238. package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
  239. package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
  240. package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
  241. package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
  242. package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
  243. package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
  244. package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
  245. package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
  246. package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
  247. package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
  248. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
  249. package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
  250. package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
  251. package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -192
  252. package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
  253. package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
  254. package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
  255. package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
  256. package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
  257. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
  258. package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
  259. package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
  260. package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
  261. package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
  262. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
  263. package/src/server/routes/instance/httpapi/handlers/session.ts +0 -440
  264. package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
  265. package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
  266. package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
  267. package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
  268. package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
  269. package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
  270. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
  271. package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
  272. package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
  273. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
  274. package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
  275. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
  276. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
  277. package/src/server/routes/instance/httpapi/public.ts +0 -535
  278. package/src/server/routes/instance/httpapi/server.ts +0 -298
  279. package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -57
  280. package/src/server/server.ts +0 -225
  281. package/src/server/shared/fence.ts +0 -60
  282. package/src/server/shared/pty-ticket.ts +0 -15
  283. package/src/server/shared/public-ui.ts +0 -12
  284. package/src/server/shared/tui-control.ts +0 -28
  285. package/src/server/shared/ui.ts +0 -108
  286. package/src/server/shared/workspace-routing.ts +0 -38
  287. package/src/server/tui-event.ts +0 -53
  288. package/src/session/compaction.ts +0 -620
  289. package/src/session/instruction.ts +0 -241
  290. package/src/session/llm/AGENTS.md +0 -90
  291. package/src/session/llm/ai-sdk.ts +0 -288
  292. package/src/session/llm/native-request.ts +0 -196
  293. package/src/session/llm/native-runtime.ts +0 -195
  294. package/src/session/llm/request.ts +0 -216
  295. package/src/session/llm.ts +0 -415
  296. package/src/session/message-error.ts +0 -14
  297. package/src/session/message-v2.ts +0 -747
  298. package/src/session/message.ts +0 -148
  299. package/src/session/overflow.ts +0 -34
  300. package/src/session/processor.ts +0 -1084
  301. package/src/session/prompt/anthropic.txt +0 -109
  302. package/src/session/prompt/beast.txt +0 -151
  303. package/src/session/prompt/build-switch.txt +0 -9
  304. package/src/session/prompt/codex.txt +0 -83
  305. package/src/session/prompt/copilot-gpt-5.txt +0 -147
  306. package/src/session/prompt/default.txt +0 -99
  307. package/src/session/prompt/gemini.txt +0 -159
  308. package/src/session/prompt/gpt.txt +0 -111
  309. package/src/session/prompt/kimi.txt +0 -99
  310. package/src/session/prompt/plan-mode.txt +0 -74
  311. package/src/session/prompt/plan-reminder-anthropic.txt +0 -71
  312. package/src/session/prompt/plan.txt +0 -30
  313. package/src/session/prompt/trinity.txt +0 -101
  314. package/src/session/prompt.ts +0 -1707
  315. package/src/session/reminders.ts +0 -92
  316. package/src/session/retry.ts +0 -201
  317. package/src/session/revert.ts +0 -160
  318. package/src/session/run-state.ts +0 -156
  319. package/src/session/schema.ts +0 -26
  320. package/src/session/session.ts +0 -1119
  321. package/src/session/status.ts +0 -97
  322. package/src/session/summary.ts +0 -165
  323. package/src/session/system.ts +0 -117
  324. package/src/session/todo.ts +0 -90
  325. package/src/session/tools.ts +0 -207
  326. package/src/share/session.ts +0 -61
  327. package/src/share/share-next.ts +0 -385
  328. package/src/skill/discovery.ts +0 -109
  329. package/src/skill/index.ts +0 -366
  330. package/src/snapshot/index.ts +0 -808
  331. package/src/sql.d.ts +0 -4
  332. package/src/storage/schema.ts +0 -5
  333. package/src/storage/storage.ts +0 -329
  334. package/src/sync/README.md +0 -179
  335. package/src/sync/schema.ts +0 -11
  336. package/src/temporary.ts +0 -31
  337. package/src/tool/apply_patch.ts +0 -315
  338. package/src/tool/apply_patch.txt +0 -33
  339. package/src/tool/apply_patch.zh.txt +0 -33
  340. package/src/tool/description.ts +0 -100
  341. package/src/tool/edit.ts +0 -739
  342. package/src/tool/edit.txt +0 -10
  343. package/src/tool/edit.zh.txt +0 -10
  344. package/src/tool/external-directory.ts +0 -49
  345. package/src/tool/glob.ts +0 -78
  346. package/src/tool/glob.txt +0 -6
  347. package/src/tool/glob.zh.txt +0 -6
  348. package/src/tool/grep.ts +0 -114
  349. package/src/tool/grep.txt +0 -8
  350. package/src/tool/grep.zh.txt +0 -8
  351. package/src/tool/invalid.ts +0 -21
  352. package/src/tool/json-schema.ts +0 -164
  353. package/src/tool/lsp.ts +0 -115
  354. package/src/tool/lsp.txt +0 -24
  355. package/src/tool/lsp.zh.txt +0 -24
  356. package/src/tool/mcp-websearch.ts +0 -96
  357. package/src/tool/plan-enter.txt +0 -14
  358. package/src/tool/plan-enter.zh.txt +0 -14
  359. package/src/tool/plan-exit.txt +0 -13
  360. package/src/tool/plan-exit.zh.txt +0 -13
  361. package/src/tool/plan.ts +0 -81
  362. package/src/tool/question.ts +0 -46
  363. package/src/tool/question.txt +0 -10
  364. package/src/tool/question.zh.txt +0 -10
  365. package/src/tool/read.ts +0 -388
  366. package/src/tool/read.txt +0 -14
  367. package/src/tool/read.zh.txt +0 -14
  368. package/src/tool/registry.ts +0 -440
  369. package/src/tool/schema.ts +0 -14
  370. package/src/tool/shell/id.ts +0 -19
  371. package/src/tool/shell/prompt.ts +0 -307
  372. package/src/tool/shell/shell.txt +0 -21
  373. package/src/tool/shell.ts +0 -657
  374. package/src/tool/skill.ts +0 -73
  375. package/src/tool/skill.txt +0 -5
  376. package/src/tool/skill.zh.txt +0 -5
  377. package/src/tool/task.ts +0 -348
  378. package/src/tool/task.txt +0 -19
  379. package/src/tool/task.zh.txt +0 -19
  380. package/src/tool/todo.ts +0 -59
  381. package/src/tool/todowrite.txt +0 -44
  382. package/src/tool/todowrite.zh.txt +0 -44
  383. package/src/tool/tool.ts +0 -183
  384. package/src/tool/truncate.ts +0 -158
  385. package/src/tool/truncation-dir.ts +0 -4
  386. package/src/tool/webfetch.ts +0 -194
  387. package/src/tool/webfetch.txt +0 -13
  388. package/src/tool/webfetch.zh.txt +0 -13
  389. package/src/tool/websearch.ts +0 -145
  390. package/src/tool/websearch.txt +0 -14
  391. package/src/tool/websearch.zh.txt +0 -14
  392. package/src/tool/write.ts +0 -106
  393. package/src/tool/write.txt +0 -8
  394. package/src/tool/write.zh.txt +0 -8
  395. package/src/util/archive.ts +0 -17
  396. package/src/util/bom.ts +0 -27
  397. package/src/util/data-url.ts +0 -9
  398. package/src/util/defer.ts +0 -10
  399. package/src/util/effect-http-client.ts +0 -11
  400. package/src/util/error.ts +0 -1
  401. package/src/util/filesystem.ts +0 -251
  402. package/src/util/html.ts +0 -8
  403. package/src/util/iife.ts +0 -3
  404. package/src/util/lazy.ts +0 -20
  405. package/src/util/local-context.ts +0 -25
  406. package/src/util/locale.ts +0 -2
  407. package/src/util/media.ts +0 -26
  408. package/src/util/process.ts +0 -177
  409. package/src/util/proxy-env.ts +0 -72
  410. package/src/util/queue.ts +0 -32
  411. package/src/util/record.ts +0 -1
  412. package/src/util/repository.ts +0 -232
  413. package/src/util/rpc.ts +0 -66
  414. package/src/util/signal.ts +0 -12
  415. package/src/util/timeout.ts +0 -13
  416. package/src/util/token.ts +0 -1
  417. package/src/util/wildcard.ts +0 -59
  418. package/src/worktree/index.ts +0 -654
@@ -1,1543 +0,0 @@
1
- import type { ModelMessage, ToolResultPart } from "ai"
2
- import { mergeDeep, unique } from "remeda"
3
- import type { JSONSchema7 } from "@ai-sdk/provider"
4
- import type * as Provider from "./provider"
5
- import type * as ModelsDev from "@opencode-ai/core/models-dev"
6
- import { iife } from "@/util/iife"
7
-
8
- type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
9
-
10
- function mimeToModality(mime: string): Modality | undefined {
11
- if (mime.startsWith("image/")) return "image"
12
- if (mime.startsWith("audio/")) return "audio"
13
- if (mime.startsWith("video/")) return "video"
14
- if (mime === "application/pdf") return "pdf"
15
- return undefined
16
- }
17
-
18
- export const OUTPUT_TOKEN_MAX = 32_000
19
-
20
- // OpenAI Responses `include` value that returns the encrypted reasoning state
21
- // needed for stateless multi-turn reasoning (store: false). Hoisted so every
22
- // branch that requests it stays in lockstep.
23
- const INCLUDE_ENCRYPTED_REASONING = ["reasoning.encrypted_content"] as const
24
-
25
- export function sanitizeSurrogates(content: string) {
26
- return content.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD")
27
- }
28
-
29
- // Maps npm package to the key the AI SDK expects for providerOptions
30
- function sdkKey(npm: string): string | undefined {
31
- switch (npm) {
32
- case "@ai-sdk/github-copilot":
33
- return "copilot"
34
- case "@ai-sdk/azure":
35
- return "azure"
36
- case "@ai-sdk/openai":
37
- return "openai"
38
- case "@ai-sdk/amazon-bedrock/mantle":
39
- return "openai"
40
- case "@ai-sdk/amazon-bedrock":
41
- return "bedrock"
42
- case "@ai-sdk/anthropic":
43
- case "@ai-sdk/google-vertex/anthropic":
44
- return "anthropic"
45
- case "@ai-sdk/google-vertex":
46
- return "vertex"
47
- case "@ai-sdk/google":
48
- return "google"
49
- case "@ai-sdk/gateway":
50
- return "gateway"
51
- case "@openrouter/ai-sdk-provider":
52
- return "openrouter"
53
- case "ai-gateway-provider":
54
- // ai-gateway-provider/unified wraps createOpenAICompatible({ name: "Unified" }),
55
- // and @ai-sdk/openai-compatible parses compatibleOptions from one of
56
- // "openai-compatible" / "openaiCompatible" / "Unified" / "unified". The
57
- // "openai-compatible" key emits a deprecation warning at runtime, so we
58
- // pick the camelCase form the SDK now treats as canonical.
59
- return "openaiCompatible"
60
- }
61
- return undefined
62
- }
63
-
64
- // TODO: fix this stupid inefficient dogshit function
65
- function normalizeMessages(
66
- msgs: ModelMessage[],
67
- model: Provider.Model,
68
- _options: Record<string, unknown>,
69
- ): ModelMessage[] {
70
- const sanitizeToolResultOutput = (content: ToolResultPart) => {
71
- if (content.output.type === "text" || content.output.type === "error-text") {
72
- content.output.value = sanitizeSurrogates(content.output.value)
73
- }
74
- if (content.output.type === "content") {
75
- content.output.value = content.output.value.map((item) => {
76
- if (item.type === "text") {
77
- item.text = sanitizeSurrogates(item.text)
78
- }
79
- return item
80
- })
81
- }
82
- return content
83
- }
84
-
85
- msgs = msgs.map((msg) => {
86
- switch (msg.role) {
87
- case "tool":
88
- if (!Array.isArray(msg.content)) return msg
89
- msg.content = msg.content.map((content) => {
90
- if (content.type === "tool-result") {
91
- return sanitizeToolResultOutput(content)
92
- }
93
- return content
94
- })
95
- return msg
96
-
97
- case "system":
98
- msg.content = sanitizeSurrogates(msg.content)
99
- return msg
100
-
101
- case "user":
102
- if (typeof msg.content === "string") {
103
- msg.content = sanitizeSurrogates(msg.content)
104
- } else {
105
- msg.content = msg.content.map((content) => {
106
- if (content.type === "text") {
107
- content.text = sanitizeSurrogates(content.text)
108
- }
109
- return content
110
- })
111
- }
112
- return msg
113
-
114
- case "assistant":
115
- if (typeof msg.content === "string") {
116
- msg.content = sanitizeSurrogates(msg.content)
117
- } else {
118
- msg.content = msg.content.map((content) => {
119
- if (content.type === "text" || content.type === "reasoning") {
120
- content.text = sanitizeSurrogates(content.text)
121
- }
122
- if (content.type === "tool-result") {
123
- return sanitizeToolResultOutput(content)
124
- }
125
- return content
126
- })
127
- }
128
- return msg
129
- }
130
- })
131
-
132
- // Anthropic rejects messages with empty content - filter out empty string messages
133
- // and remove empty text/reasoning parts from array content
134
- if (model.api.npm === "@ai-sdk/anthropic") {
135
- msgs = msgs
136
- .map((msg) => {
137
- if (typeof msg.content === "string") {
138
- if (msg.content === "") return undefined
139
- return msg
140
- }
141
- if (!Array.isArray(msg.content)) return msg
142
- const filtered = msg.content.filter((part) => {
143
- if (part.type === "text") {
144
- return part.text !== ""
145
- }
146
- if (part.type === "reasoning") {
147
- return (
148
- part.text.trim().length > 0 ||
149
- part.providerOptions?.anthropic?.signature != null ||
150
- part.providerOptions?.anthropic?.redactedData != null
151
- )
152
- }
153
- return true
154
- })
155
- if (filtered.length === 0) return undefined
156
- return { ...msg, content: filtered }
157
- })
158
- .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "")
159
- }
160
-
161
- // Bedrock specific transforms
162
- if (model.api.npm === "@ai-sdk/amazon-bedrock") {
163
- msgs = msgs
164
- .map((msg) => {
165
- if (typeof msg.content === "string") {
166
- if (msg.content === "") return undefined
167
- return msg
168
- }
169
- if (!Array.isArray(msg.content)) return msg
170
- const filtered = msg.content.filter((part) => {
171
- if (part.type === "text") {
172
- return part.text !== ""
173
- }
174
- if (part.type === "reasoning") {
175
- return (
176
- part.text.trim().length > 0 ||
177
- part.providerOptions?.bedrock?.signature != null ||
178
- part.providerOptions?.bedrock?.redactedData != null
179
- )
180
- }
181
- return true
182
- })
183
- if (filtered.length === 0) return undefined
184
- return { ...msg, content: filtered }
185
- })
186
- .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "")
187
- }
188
-
189
- if (model.api.id.includes("claude")) {
190
- const scrub = (id: string) => id.replace(/[^a-zA-Z0-9_-]/g, "_")
191
- msgs = msgs.map((msg) => {
192
- if (msg.role === "assistant" && Array.isArray(msg.content)) {
193
- return {
194
- ...msg,
195
- content: msg.content.map((part) => {
196
- if (part.type === "tool-call" || part.type === "tool-result") {
197
- return { ...part, toolCallId: scrub(part.toolCallId) }
198
- }
199
- return part
200
- }),
201
- }
202
- }
203
- if (msg.role === "tool" && Array.isArray(msg.content)) {
204
- return {
205
- ...msg,
206
- content: msg.content.map((part) => {
207
- if (part.type === "tool-result") {
208
- return { ...part, toolCallId: scrub(part.toolCallId) }
209
- }
210
- return part
211
- }),
212
- }
213
- }
214
- return msg
215
- })
216
- }
217
-
218
- if (
219
- model.providerID === "mistral" ||
220
- model.api.id.toLowerCase().includes("mistral") ||
221
- model.api.id.toLowerCase().includes("devstral")
222
- ) {
223
- const scrub = (id: string) => {
224
- return id
225
- .replace(/[^a-zA-Z0-9]/g, "") // Remove non-alphanumeric characters
226
- .substring(0, 9) // Take first 9 characters
227
- .padEnd(9, "0") // Pad with zeros if less than 9 characters
228
- }
229
- const result: ModelMessage[] = []
230
- for (let i = 0; i < msgs.length; i++) {
231
- const msg = msgs[i]
232
- const nextMsg = msgs[i + 1]
233
-
234
- if (msg.role === "assistant" && Array.isArray(msg.content)) {
235
- msg.content = msg.content.map((part) => {
236
- if (part.type === "tool-call" || part.type === "tool-result") {
237
- return { ...part, toolCallId: scrub(part.toolCallId) }
238
- }
239
- return part
240
- })
241
- }
242
- if (msg.role === "tool" && Array.isArray(msg.content)) {
243
- msg.content = msg.content.map((part) => {
244
- if (part.type === "tool-result") {
245
- return { ...part, toolCallId: scrub(part.toolCallId) }
246
- }
247
- return part
248
- })
249
- }
250
- result.push(msg)
251
-
252
- // Fix message sequence: tool messages cannot be followed by user messages
253
- if (msg.role === "tool" && nextMsg?.role === "user") {
254
- result.push({
255
- role: "assistant",
256
- content: [
257
- {
258
- type: "text",
259
- text: "Done.",
260
- },
261
- ],
262
- })
263
- }
264
- }
265
- return result
266
- }
267
-
268
- // Deepseek requires all assistant messages to have reasoning on them
269
- if (model.api.id.toLowerCase().includes("deepseek")) {
270
- msgs = msgs.map((msg) => {
271
- if (msg.role !== "assistant") return msg
272
- if (Array.isArray(msg.content)) {
273
- if (msg.content.some((part) => part.type === "reasoning")) return msg
274
- return { ...msg, content: [...msg.content, { type: "reasoning", text: "" }] }
275
- }
276
- return {
277
- ...msg,
278
- content: [
279
- ...(msg.content ? [{ type: "text" as const, text: msg.content }] : []),
280
- { type: "reasoning" as const, text: "" },
281
- ],
282
- }
283
- })
284
- }
285
-
286
- if (
287
- typeof model.capabilities.interleaved === "object" &&
288
- model.capabilities.interleaved.field &&
289
- model.api.npm !== "@openrouter/ai-sdk-provider"
290
- ) {
291
- const field = model.capabilities.interleaved.field
292
- return msgs.map((msg) => {
293
- if (msg.role === "assistant" && Array.isArray(msg.content)) {
294
- const reasoningParts = msg.content.filter((part: any) => part.type === "reasoning")
295
- const reasoningText = reasoningParts.map((part: any) => part.text).join("")
296
-
297
- // Filter out reasoning parts from content
298
- const filteredContent = msg.content.filter((part: any) => part.type !== "reasoning")
299
-
300
- // Include reasoning_content | reasoning_details directly on the message for all assistant messages.
301
- // Always set the field even when empty — some providers (e.g. DeepSeek) may return empty
302
- // reasoning_content which still needs to be sent back in subsequent requests.
303
- return {
304
- ...msg,
305
- content: filteredContent,
306
- providerOptions: {
307
- ...msg.providerOptions,
308
- openaiCompatible: {
309
- ...msg.providerOptions?.openaiCompatible,
310
- [field]: reasoningText,
311
- },
312
- },
313
- }
314
- }
315
-
316
- return msg
317
- })
318
- }
319
-
320
- return msgs
321
- }
322
-
323
- function applyCaching(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {
324
- const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
325
- const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
326
-
327
- const providerOptions = {
328
- anthropic: {
329
- cacheControl: { type: "ephemeral" },
330
- },
331
- openrouter: {
332
- cacheControl: { type: "ephemeral" },
333
- },
334
- bedrock: {
335
- cachePoint: { type: "default" },
336
- },
337
- openaiCompatible: {
338
- cache_control: { type: "ephemeral" },
339
- },
340
- copilot: {
341
- copilot_cache_control: { type: "ephemeral" },
342
- },
343
- alibaba: {
344
- cacheControl: { type: "ephemeral" },
345
- },
346
- }
347
-
348
- for (const msg of unique([...system, ...final])) {
349
- const useMessageLevelOptions =
350
- model.providerID === "anthropic" ||
351
- model.providerID.includes("bedrock") ||
352
- model.api.npm === "@ai-sdk/amazon-bedrock"
353
- const shouldUseContentOptions = !useMessageLevelOptions && Array.isArray(msg.content) && msg.content.length > 0
354
-
355
- if (shouldUseContentOptions) {
356
- const lastContent = msg.content[msg.content.length - 1]
357
- if (
358
- lastContent &&
359
- typeof lastContent === "object" &&
360
- lastContent.type !== "tool-approval-request" &&
361
- lastContent.type !== "tool-approval-response"
362
- ) {
363
- lastContent.providerOptions = mergeDeep(lastContent.providerOptions ?? {}, providerOptions)
364
- continue
365
- }
366
- }
367
-
368
- msg.providerOptions = mergeDeep(msg.providerOptions ?? {}, providerOptions)
369
- }
370
-
371
- return msgs
372
- }
373
-
374
- function unsupportedParts(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {
375
- return msgs.map((msg) => {
376
- if (msg.role !== "user" || !Array.isArray(msg.content)) return msg
377
-
378
- const filtered = msg.content.map((part) => {
379
- if (part.type !== "file" && part.type !== "image") return part
380
-
381
- // Check for empty base64 image data
382
- if (part.type === "image") {
383
- const imageStr = String(part.image)
384
- if (imageStr.startsWith("data:")) {
385
- const match = imageStr.match(/^data:([^;]+);base64,(.*)$/)
386
- if (match && (!match[2] || match[2].length === 0)) {
387
- return {
388
- type: "text" as const,
389
- text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
390
- }
391
- }
392
- }
393
- }
394
-
395
- const mime = part.type === "image" ? String(part.image).split(";")[0].replace("data:", "") : part.mediaType
396
- const filename = part.type === "file" ? part.filename : undefined
397
- const modality = mimeToModality(mime)
398
- if (!modality) return part
399
- if (model.capabilities.input[modality]) return part
400
-
401
- const name = filename ? `"${filename}"` : modality
402
- return {
403
- type: "text" as const,
404
- text: `ERROR: Cannot read ${name} (this model does not support ${modality} input). Inform the user.`,
405
- }
406
- })
407
-
408
- return { ...msg, content: filtered }
409
- })
410
- }
411
-
412
- function mapProviderOptions(
413
- msgs: ModelMessage[],
414
- transform: (options: Record<string, any> | undefined) => Record<string, any> | undefined,
415
- ) {
416
- return msgs.map((msg) => {
417
- if (!Array.isArray(msg.content)) return { ...msg, providerOptions: transform(msg.providerOptions) }
418
- return {
419
- ...msg,
420
- providerOptions: transform(msg.providerOptions),
421
- content: msg.content.map((part) =>
422
- part.type === "tool-approval-request" || part.type === "tool-approval-response"
423
- ? part
424
- : { ...part, providerOptions: transform(part.providerOptions) },
425
- ),
426
- } as typeof msg
427
- })
428
- }
429
-
430
- export function message(msgs: ModelMessage[], model: Provider.Model, options: Record<string, unknown>) {
431
- msgs = unsupportedParts(msgs, model)
432
- msgs = normalizeMessages(msgs, model, options)
433
- if (
434
- (model.providerID === "anthropic" ||
435
- model.providerID === "google-vertex-anthropic" ||
436
- model.api.id.includes("anthropic") ||
437
- model.api.id.includes("claude") ||
438
- model.id.includes("anthropic") ||
439
- model.id.includes("claude") ||
440
- model.api.npm === "@ai-sdk/anthropic" ||
441
- model.api.npm === "@ai-sdk/alibaba") &&
442
- model.api.npm !== "@ai-sdk/gateway"
443
- ) {
444
- msgs = applyCaching(msgs, model)
445
- }
446
-
447
- // Remap providerOptions keys from stored providerID to expected SDK key
448
- const key = sdkKey(model.api.npm)
449
- if (key && key !== model.providerID) {
450
- const remap = (opts: Record<string, any> | undefined) => {
451
- if (!opts) return opts
452
- if (!(model.providerID in opts)) return opts
453
- const result = { ...opts }
454
- result[key] = result[model.providerID]
455
- delete result[model.providerID]
456
- return result
457
- }
458
-
459
- msgs = mapProviderOptions(msgs, remap)
460
- }
461
-
462
- // Strip Responses item IDs before serialization, following Codex and keeping signed request bodies immutable.
463
- if (
464
- options.store !== true &&
465
- key &&
466
- ["@ai-sdk/openai", "@ai-sdk/azure", "@ai-sdk/amazon-bedrock/mantle"].includes(model.api.npm)
467
- ) {
468
- msgs = mapProviderOptions(msgs, (options) => {
469
- if (!options?.[key] || !("itemId" in options[key])) return options
470
- const metadata = { ...options[key] }
471
- delete metadata.itemId
472
- return { ...options, [key]: metadata }
473
- })
474
- }
475
-
476
- return msgs
477
- }
478
-
479
- export function temperature(model: Provider.Model) {
480
- const id = model.id.toLowerCase()
481
- if (id.includes("north-mini-code")) return 1.0
482
- if (id.includes("qwen")) return 0.55
483
- if (id.includes("claude")) return undefined
484
- if (id.includes("gemini")) return 1.0
485
- if (id.includes("glm-4.6")) return 1.0
486
- if (id.includes("glm-4.7")) return 1.0
487
- if (id.includes("minimax-m2")) return 1.0
488
- if (id.includes("kimi-k2")) {
489
- // kimi-k2-thinking & kimi-k2.5 && kimi-k2p5 && kimi-k2-5
490
- if (["thinking", "k2.", "k2p", "k2-5"].some((s) => id.includes(s))) {
491
- return 1.0
492
- }
493
- return 0.6
494
- }
495
- return undefined
496
- }
497
-
498
- export function topP(model: Provider.Model) {
499
- const id = model.id.toLowerCase()
500
- if (id.includes("qwen")) return 1
501
- if (["minimax-m2", "gemini", "kimi-k2.5", "kimi-k2p5", "kimi-k2-5"].some((s) => id.includes(s))) {
502
- return 0.95
503
- }
504
- return undefined
505
- }
506
-
507
- export function topK(model: Provider.Model) {
508
- const id = model.id.toLowerCase()
509
- if (id.includes("minimax-m2")) {
510
- if (["m2.", "m25", "m21"].some((s) => id.includes(s))) return 40
511
- return 20
512
- }
513
- if (id.includes("gemini")) return 64
514
- return undefined
515
- }
516
-
517
- const WIDELY_SUPPORTED_EFFORTS = ["low", "medium", "high"]
518
- const OPENAI_EFFORTS = ["none", "minimal", ...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
519
- const OPENAI_GPT5_1_EFFORTS = ["none", ...WIDELY_SUPPORTED_EFFORTS]
520
- const OPENAI_GPT5_2_PLUS_EFFORTS = [...OPENAI_GPT5_1_EFFORTS, "xhigh"]
521
- const OPENAI_GPT5_PRO_EFFORTS = ["high"]
522
- const OPENAI_GPT5_PRO_2_PLUS_EFFORTS = ["medium", "high", "xhigh"]
523
- const OPENAI_GPT5_CHAT_EFFORTS = ["medium"]
524
- const OPENAI_GPT5_CODEX_XHIGH_EFFORTS = [...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
525
- const OPENAI_GPT5_CODEX_3_PLUS_EFFORTS = ["none", ...OPENAI_GPT5_CODEX_XHIGH_EFFORTS]
526
-
527
- // OpenAI rolled out the `none` reasoning_effort tier on this date (Responses API).
528
- // Models released before it 400 on `reasoning_effort: "none"`, so we only expose
529
- // it as a variant for models new enough to accept it.
530
- const OPENAI_NONE_EFFORT_RELEASE_DATE = "2025-11-13"
531
-
532
- // OpenAI rolled out the `xhigh` reasoning_effort tier on this date. Same reasoning.
533
- const OPENAI_XHIGH_EFFORT_RELEASE_DATE = "2025-12-04"
534
-
535
- // Matches members of the gpt-5 family across the id formats we encounter:
536
- // "gpt-5", "gpt-5-nano", "gpt-5.4", "openai/gpt-5.4-codex".
537
- // Anchored to start-of-string or "/" so it doesn't false-match "gpt-50" or "gpt-5o".
538
- const GPT5_FAMILY_RE = /(?:^|\/)gpt-5(?:[.-]|$)/
539
- const GPT5_VERSION_RE = /(?:^|\/)gpt-5[.-](\d+)(?:[.-]|$)/
540
- const GPT5_PRO_RE = /(?:^|\/)gpt-5[.-]?pro(?:[.-]|$)/
541
- const GPT5_VERSIONED_PRO_RE = /(?:^|\/)gpt-5[.-]\d+[.-]pro(?:[.-]|$)/
542
-
543
- function gpt5Version(apiId: string) {
544
- return Number(GPT5_VERSION_RE.exec(apiId)?.[1]) || undefined
545
- }
546
-
547
- function versionedGpt5ReasoningEfforts(apiId: string) {
548
- if (GPT5_VERSIONED_PRO_RE.test(apiId)) return OPENAI_GPT5_PRO_2_PLUS_EFFORTS
549
- const version = gpt5Version(apiId)
550
- if (version === undefined) return undefined
551
- if (version === 1) return OPENAI_GPT5_1_EFFORTS
552
- return OPENAI_GPT5_2_PLUS_EFFORTS
553
- }
554
-
555
- function gpt5CodexReasoningEfforts(apiId: string) {
556
- if (!GPT5_FAMILY_RE.test(apiId) || !apiId.includes("codex")) return undefined
557
- const version = gpt5Version(apiId)
558
- if (version !== undefined && version >= 3) return OPENAI_GPT5_CODEX_3_PLUS_EFFORTS
559
- if (apiId.includes("codex-max") || (version !== undefined && version >= 2)) return OPENAI_GPT5_CODEX_XHIGH_EFFORTS
560
- return WIDELY_SUPPORTED_EFFORTS
561
- }
562
-
563
- function gpt5ChatReasoningEfforts(apiId: string) {
564
- if (!GPT5_FAMILY_RE.test(apiId) || !apiId.includes("-chat")) return undefined
565
- return gpt5Version(apiId) === undefined ? [] : OPENAI_GPT5_CHAT_EFFORTS
566
- }
567
-
568
- // Computes the reasoning_effort tiers an OpenAI (or OpenAI-compatible upstream
569
- // routed through it, e.g. cf-ai-gateway) model exposes. Effort order: weakest
570
- // to strongest.
571
- function openaiReasoningEfforts(apiId: string, releaseDate: string) {
572
- const id = apiId.toLowerCase()
573
- if (id.includes("deep-research")) return ["medium"]
574
- const chatEfforts = gpt5ChatReasoningEfforts(id)
575
- if (chatEfforts) return chatEfforts
576
- if (GPT5_PRO_RE.test(id)) return OPENAI_GPT5_PRO_EFFORTS
577
- const codexEfforts = gpt5CodexReasoningEfforts(id)
578
- if (codexEfforts) return codexEfforts
579
- const versionedEfforts = versionedGpt5ReasoningEfforts(id)
580
- // GPT-5.1 replaced GPT-5's `minimal` effort with `none`; GPT-5.2+
581
- // additionally accepts `xhigh`. Model pages list the supported subset.
582
- if (versionedEfforts) return versionedEfforts
583
- const efforts = [...WIDELY_SUPPORTED_EFFORTS]
584
- if (GPT5_FAMILY_RE.test(id)) efforts.unshift("minimal")
585
- if (releaseDate >= OPENAI_NONE_EFFORT_RELEASE_DATE) efforts.unshift("none")
586
- if (releaseDate >= OPENAI_XHIGH_EFFORT_RELEASE_DATE) efforts.push("xhigh")
587
- return efforts
588
- }
589
-
590
- function openaiCompatibleReasoningEfforts(id: string) {
591
- const apiId = id.toLowerCase()
592
- const chatEfforts = gpt5ChatReasoningEfforts(apiId)
593
- if (chatEfforts) return chatEfforts
594
- if (GPT5_PRO_RE.test(apiId)) return OPENAI_GPT5_PRO_EFFORTS
595
- return gpt5CodexReasoningEfforts(apiId) ?? versionedGpt5ReasoningEfforts(apiId) ?? OPENAI_EFFORTS
596
- }
597
-
598
- function anthropicOpus47OrLater(apiId: string) {
599
- // Matches "opus-4.7" (Anthropic/Bedrock/Vertex) and "claude-4.7-opus" (SAP AI Core inverted).
600
- // Greedy \d+ correctly extends to multi-digit majors (e.g. "claude-10.0-opus") for forward compatibility.
601
- const version = /opus-(\d+)[.-](\d+)(?:[.@-]|$)|claude-(\d+)[.-](\d+)-opus(?:[.@-]|$)/i.exec(apiId)
602
- if (!version) return false
603
- const major = Number(version[1] ?? version[3])
604
- const minor = Number(version[2] ?? version[4])
605
- return major > 4 || (major === 4 && minor >= 7)
606
- }
607
-
608
- function anthropicAdaptiveEfforts(apiId: string): string[] | null {
609
- if (anthropicOpus47OrLater(apiId) || apiId.includes("fable-5")) {
610
- return ["low", "medium", "high", "xhigh", "max"]
611
- }
612
- if (
613
- ["opus-4-6", "opus-4.6", "4-6-opus", "4.6-opus", "sonnet-4-6", "sonnet-4.6", "4-6-sonnet", "4.6-sonnet"].some((v) =>
614
- apiId.includes(v),
615
- )
616
- ) {
617
- return ["low", "medium", "high", "max"]
618
- }
619
- return null
620
- }
621
-
622
- function anthropicOmitsThinking(apiId: string) {
623
- return anthropicOpus47OrLater(apiId) || apiId.includes("fable-5")
624
- }
625
-
626
- function googleThinkingLevelEfforts(apiId: string) {
627
- const id = apiId.toLowerCase()
628
- if (!id.includes("gemini-3")) return ["low", "high"]
629
- if (id.includes("flash-image")) return ["minimal", "high"]
630
- if (id.includes("pro-image")) return ["high"]
631
- if (id.includes("flash")) return ["minimal", "low", "medium", "high"]
632
- return ["low", "medium", "high"]
633
- }
634
-
635
- function googleThinkingBudgetMax(apiId: string) {
636
- const id = apiId.toLowerCase()
637
- if (id.includes("2.5") && id.includes("pro") && !id.includes("flash")) return 32_768
638
- return 24_576
639
- }
640
-
641
- // SAP's Zod schema drops unknown top-level keys; reasoning controls survive
642
- // only via `modelParams` (catchall), forwarded verbatim by the SAP SDKs.
643
- function wrapInSapModelParams(variants: Record<string, Record<string, any>>): Record<string, Record<string, any>> {
644
- return Object.fromEntries(Object.entries(variants).map(([k, v]) => [k, { modelParams: v }]))
645
- }
646
-
647
- function googleThinkingVariants(model: Provider.Model): Record<string, Record<string, any>> {
648
- const id = model.api.id.toLowerCase()
649
- if (id.includes("2.5")) {
650
- return {
651
- high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
652
- max: {
653
- thinkingConfig: { includeThoughts: true, thinkingBudget: googleThinkingBudgetMax(id) },
654
- },
655
- }
656
- }
657
- return Object.fromEntries(
658
- googleThinkingLevelEfforts(id).map((effort) => [
659
- effort,
660
- { thinkingConfig: { includeThoughts: true, thinkingLevel: effort } },
661
- ]),
662
- )
663
- }
664
-
665
- export function variants(model: Provider.Model): Record<string, Record<string, any>> {
666
- if (!model.capabilities.reasoning) return {}
667
-
668
- const id = model.id.toLowerCase()
669
- const glm52 = ["glm-5.2", "glm-5-2", "glm-5p2"].some(
670
- (name) => id.includes(name) || model.api.id.toLowerCase().includes(name),
671
- )
672
- if (
673
- model.api.id.toLowerCase().includes("minimax-m3") &&
674
- ["@ai-sdk/anthropic", "@ai-sdk/openai-compatible"].includes(model.api.npm)
675
- ) {
676
- return {
677
- none: { thinking: { type: "disabled" } },
678
- thinking: { thinking: { type: "adaptive" } },
679
- }
680
- }
681
- const adaptiveThinkingOmitted = anthropicOmitsThinking(model.api.id)
682
- const adaptiveEfforts = anthropicAdaptiveEfforts(model.api.id)
683
- if (glm52 && model.api.npm === "@openrouter/ai-sdk-provider") {
684
- // OpenRouter maps xhigh to GLM-5.2's native max effort.
685
- return {
686
- high: { reasoning: { effort: "high" } },
687
- xhigh: { reasoning: { effort: "xhigh" } },
688
- }
689
- }
690
- if (glm52 && model.api.npm === "@ai-sdk/openai-compatible") {
691
- return {
692
- high: { reasoningEffort: "high" },
693
- max: { reasoningEffort: "max" },
694
- }
695
- }
696
- if (glm52 && model.api.npm === "@ai-sdk/anthropic") {
697
- return {
698
- high: { effort: "high" },
699
- max: { effort: "max" },
700
- }
701
- }
702
- if (
703
- id.includes("deepseek-chat") ||
704
- id.includes("deepseek-reasoner") ||
705
- id.includes("deepseek-r1") ||
706
- id.includes("deepseek-v3") ||
707
- id.includes("minimax") ||
708
- (id.includes("glm") && !glm52) ||
709
- id.includes("kimi") ||
710
- id.includes("k2p") ||
711
- id.includes("qwen") ||
712
- id.includes("big-pickle")
713
- )
714
- return {}
715
-
716
- // see: https://docs.x.ai/docs/guides/reasoning#control-how-hard-the-model-thinks
717
- if (id.includes("grok") && id.includes("grok-3-mini")) {
718
- if (model.api.npm === "@openrouter/ai-sdk-provider") {
719
- return {
720
- low: { reasoning: { effort: "low" } },
721
- high: { reasoning: { effort: "high" } },
722
- }
723
- }
724
- return {
725
- low: { reasoningEffort: "low" },
726
- high: { reasoningEffort: "high" },
727
- }
728
- }
729
- if (id.includes("grok")) return {}
730
-
731
- switch (model.api.npm) {
732
- case "@openrouter/ai-sdk-provider":
733
- return Object.fromEntries(
734
- (model.api.id.startsWith("openai/") || id.includes("gpt")
735
- ? openaiCompatibleReasoningEfforts(model.api.id)
736
- : WIDELY_SUPPORTED_EFFORTS
737
- ).map((effort) => [effort, { reasoning: { effort } }]),
738
- )
739
-
740
- case "ai-gateway-provider": {
741
- // Cloudflare AI Gateway routes every upstream through its OpenAI-compatible
742
- // /v1/compat endpoint, so the body is always OAI-shaped. The gateway
743
- // translates `reasoning_effort` to the upstream provider's native control
744
- // (e.g. Anthropic thinking budgets) when needed. Variants therefore stay
745
- // OAI-style for all upstreams, with an extended effort set for OpenAI
746
- // models that support it.
747
- if (model.api.id.startsWith("openai/")) {
748
- const efforts = openaiReasoningEfforts(model.api.id, model.release_date)
749
- return Object.fromEntries(efforts.map((effort) => [effort, { reasoningEffort: effort }]))
750
- }
751
- return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
752
- }
753
-
754
- case "@ai-sdk/gateway":
755
- if (model.id.includes("anthropic")) {
756
- if (adaptiveEfforts) {
757
- return Object.fromEntries(
758
- adaptiveEfforts.map((effort) => [
759
- effort,
760
- {
761
- thinking: {
762
- type: "adaptive",
763
- // Newer adaptive-only models default `display` to "omitted", which
764
- // returns empty thinking blocks. Force "summarized" so summaries
765
- // survive (4.6/Sonnet 4.6 already default to "summarized").
766
- ...(adaptiveThinkingOmitted ? { display: "summarized" } : {}),
767
- },
768
- effort,
769
- },
770
- ]),
771
- )
772
- }
773
- return {
774
- high: {
775
- thinking: {
776
- type: "enabled",
777
- budgetTokens: 16000,
778
- },
779
- },
780
- max: {
781
- thinking: {
782
- type: "enabled",
783
- budgetTokens: 31999,
784
- },
785
- },
786
- }
787
- }
788
- if (model.id.includes("google")) {
789
- if (id.includes("2.5")) {
790
- return {
791
- high: {
792
- thinkingConfig: {
793
- includeThoughts: true,
794
- thinkingBudget: 16000,
795
- },
796
- },
797
- max: {
798
- thinkingConfig: {
799
- includeThoughts: true,
800
- thinkingBudget: googleThinkingBudgetMax(id),
801
- },
802
- },
803
- }
804
- }
805
- return Object.fromEntries(
806
- ["low", "high"].map((effort) => [
807
- effort,
808
- {
809
- includeThoughts: true,
810
- thinkingLevel: effort,
811
- },
812
- ]),
813
- )
814
- }
815
- return Object.fromEntries(
816
- openaiCompatibleReasoningEfforts(model.api.id).map((effort) => [effort, { reasoningEffort: effort }]),
817
- )
818
-
819
- case "@ai-sdk/github-copilot":
820
- if (model.id.includes("gemini")) {
821
- // currently github copilot only returns thinking
822
- return {}
823
- }
824
- if (model.id.includes("claude")) {
825
- return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
826
- }
827
- const copilotEfforts = iife(() => {
828
- if (id.includes("5.1-codex-max") || id.includes("5.2") || id.includes("5.3"))
829
- return [...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
830
- const arr = [...WIDELY_SUPPORTED_EFFORTS]
831
- if (id.includes("gpt-5") && model.release_date >= "2025-12-04") arr.push("xhigh")
832
- return arr
833
- })
834
- return Object.fromEntries(
835
- copilotEfforts.map((effort) => [
836
- effort,
837
- {
838
- reasoningEffort: effort,
839
- reasoningSummary: "auto",
840
- include: INCLUDE_ENCRYPTED_REASONING,
841
- },
842
- ]),
843
- )
844
-
845
- case "@ai-sdk/cerebras":
846
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/cerebras
847
- case "@ai-sdk/togetherai":
848
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/togetherai
849
- case "@ai-sdk/xai":
850
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/xai
851
- case "@ai-sdk/deepinfra":
852
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/deepinfra
853
- case "venice-ai-sdk-provider":
854
- // https://docs.venice.ai/overview/guides/reasoning-models#reasoning-effort
855
- case "@ai-sdk/openai-compatible":
856
- if (model.api.id.toLowerCase().includes("north-mini-code")) {
857
- return Object.fromEntries(["none", "high"].map((effort) => [effort, { reasoningEffort: effort }]))
858
- }
859
- const efforts = [...WIDELY_SUPPORTED_EFFORTS]
860
- if (model.api.id.toLowerCase().includes("deepseek-v4")) {
861
- efforts.push("max")
862
- }
863
- return Object.fromEntries(efforts.map((effort) => [effort, { reasoningEffort: effort }]))
864
-
865
- case "@ai-sdk/azure":
866
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/azure
867
- if (id === "o1-mini") return {}
868
- return Object.fromEntries(
869
- openaiReasoningEfforts(id, model.release_date).map((effort) => [
870
- effort,
871
- {
872
- reasoningEffort: effort,
873
- reasoningSummary: "auto",
874
- include: INCLUDE_ENCRYPTED_REASONING,
875
- },
876
- ]),
877
- )
878
- case "@ai-sdk/amazon-bedrock/mantle":
879
- case "@ai-sdk/openai": {
880
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/openai
881
- const efforts = openaiReasoningEfforts(model.api.id, model.release_date)
882
- return Object.fromEntries(
883
- efforts.map((effort) => [
884
- effort,
885
- {
886
- reasoningEffort: effort,
887
- reasoningSummary: "auto",
888
- include: INCLUDE_ENCRYPTED_REASONING,
889
- },
890
- ]),
891
- )
892
- }
893
-
894
- case "@ai-sdk/anthropic":
895
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/anthropic
896
- case "@ai-sdk/google-vertex/anthropic":
897
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex#anthropic-provider
898
- if (adaptiveEfforts) {
899
- let efforts = [...adaptiveEfforts]
900
- if (model.providerID === "github-copilot") {
901
- if (model.api.id.includes("opus-4.7")) {
902
- efforts = ["medium"]
903
- }
904
- // Efforts currently supported are: low, medium, high
905
- efforts = efforts.filter((v) => v !== "max" && v !== "xhigh")
906
- }
907
- return Object.fromEntries(
908
- efforts.map((effort) => [
909
- effort,
910
- {
911
- thinking: {
912
- type: "adaptive",
913
- ...(adaptiveThinkingOmitted ? { display: "summarized" } : {}),
914
- },
915
- effort,
916
- },
917
- ]),
918
- )
919
- }
920
-
921
- if (["opus-4-5", "opus-4.5"].some((v) => model.api.id.includes(v))) {
922
- return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { effort }]))
923
- }
924
-
925
- return {
926
- high: {
927
- thinking: {
928
- type: "enabled",
929
- budgetTokens: Math.min(16_000, Math.floor(model.limit.output / 2 - 1)),
930
- },
931
- },
932
- max: {
933
- thinking: {
934
- type: "enabled",
935
- budgetTokens: Math.min(31_999, model.limit.output - 1),
936
- },
937
- },
938
- }
939
-
940
- case "@ai-sdk/amazon-bedrock":
941
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock
942
- if (adaptiveEfforts) {
943
- return Object.fromEntries(
944
- adaptiveEfforts.map((effort) => [
945
- effort,
946
- {
947
- reasoningConfig: {
948
- type: "adaptive",
949
- maxReasoningEffort: effort,
950
- ...(adaptiveThinkingOmitted ? { display: "summarized" } : {}),
951
- },
952
- },
953
- ]),
954
- )
955
- }
956
- // For Anthropic models on Bedrock, use reasoningConfig with budgetTokens
957
- if (model.api.id.includes("anthropic")) {
958
- return {
959
- high: {
960
- reasoningConfig: {
961
- type: "enabled",
962
- budgetTokens: 16000,
963
- },
964
- },
965
- max: {
966
- reasoningConfig: {
967
- type: "enabled",
968
- budgetTokens: 31999,
969
- },
970
- },
971
- }
972
- }
973
-
974
- // For Amazon Nova models, use reasoningConfig with maxReasoningEffort
975
- return Object.fromEntries(
976
- WIDELY_SUPPORTED_EFFORTS.map((effort) => [
977
- effort,
978
- {
979
- reasoningConfig: {
980
- type: "enabled",
981
- maxReasoningEffort: effort,
982
- },
983
- },
984
- ]),
985
- )
986
-
987
- case "@ai-sdk/google-vertex":
988
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex
989
- case "@ai-sdk/google":
990
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai
991
- return googleThinkingVariants(model)
992
-
993
- case "@ai-sdk/mistral":
994
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/mistral
995
- // https://docs.mistral.ai/capabilities/reasoning/adjustable
996
- if (!model.capabilities.reasoning) return {}
997
- // Only Mistral Small 4 and Medium 3.5 support reasoning
998
- const MISTRAL_REASONING_IDS = [
999
- "mistral-small-2603",
1000
- "mistral-small-latest",
1001
- "mistral-medium-3.5",
1002
- "mistral-medium-2604",
1003
- ]
1004
- const mistralId = model.api.id.toLowerCase()
1005
- if (!MISTRAL_REASONING_IDS.some((id) => mistralId.includes(id))) return {}
1006
- return {
1007
- high: { reasoningEffort: "high" },
1008
- }
1009
-
1010
- case "@ai-sdk/cohere":
1011
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/cohere
1012
- return {}
1013
-
1014
- case "@ai-sdk/groq":
1015
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/groq
1016
- const groqEffort = ["none", ...WIDELY_SUPPORTED_EFFORTS]
1017
- return Object.fromEntries(
1018
- groqEffort.map((effort) => [
1019
- effort,
1020
- {
1021
- reasoningEffort: effort,
1022
- },
1023
- ]),
1024
- )
1025
-
1026
- case "@ai-sdk/perplexity":
1027
- // https://v5.ai-sdk.dev/providers/ai-sdk-providers/perplexity
1028
- return {}
1029
-
1030
- case "@jerome-benoit/sap-ai-provider-v2": {
1031
- if (id.includes("anthropic")) {
1032
- if (adaptiveEfforts) {
1033
- // Bedrock adaptive splits `effort` out into `output_config` (vs Anthropic
1034
- // native which inlines it). Opus 4.7+ flipped `display` default to "omitted".
1035
- return wrapInSapModelParams(
1036
- Object.fromEntries(
1037
- adaptiveEfforts.map((effort) => [
1038
- effort,
1039
- {
1040
- thinking: { type: "adaptive", ...(adaptiveThinkingOmitted ? { display: "summarized" } : {}) },
1041
- output_config: { effort },
1042
- },
1043
- ]),
1044
- ),
1045
- )
1046
- }
1047
- return wrapInSapModelParams({
1048
- high: { thinking: { type: "enabled", budget_tokens: 16000 } },
1049
- max: { thinking: { type: "enabled", budget_tokens: 31999 } },
1050
- })
1051
- }
1052
- if (id.includes("gemini") && id.includes("2.5")) {
1053
- return wrapInSapModelParams(googleThinkingVariants(model))
1054
- }
1055
- if (id.includes("gpt") || /\bo[1-9]/.test(id)) {
1056
- const efforts = openaiReasoningEfforts(id, model.release_date)
1057
- return wrapInSapModelParams(Object.fromEntries(efforts.map((effort) => [effort, { reasoning_effort: effort }])))
1058
- }
1059
- return wrapInSapModelParams(
1060
- Object.fromEntries(["low", "medium", "high"].map((effort) => [effort, { reasoning_effort: effort }])),
1061
- )
1062
- }
1063
- }
1064
- return {}
1065
- }
1066
-
1067
- export function options(input: {
1068
- model: Provider.Model
1069
- sessionID: string
1070
- providerOptions?: Record<string, any>
1071
- }): Record<string, any> {
1072
- const result: Record<string, any> = {}
1073
-
1074
- if (
1075
- input.model.api.npm === "@ai-sdk/google-vertex/anthropic" ||
1076
- (!input.model.api.id.includes("claude") && input.model.api.npm === "@ai-sdk/anthropic")
1077
- ) {
1078
- result["toolStreaming"] = false
1079
- }
1080
-
1081
- // openai and providers using openai package should set store to false by default.
1082
- if (
1083
- input.model.providerID === "openai" ||
1084
- input.model.api.npm === "@ai-sdk/openai" ||
1085
- input.model.api.npm === "@ai-sdk/github-copilot" ||
1086
- input.model.api.npm === "@ai-sdk/amazon-bedrock/mantle"
1087
- ) {
1088
- result["store"] = false
1089
- }
1090
-
1091
- if (input.model.api.npm === "@ai-sdk/azure") {
1092
- result["store"] = false
1093
- result["promptCacheKey"] = input.sessionID
1094
- }
1095
-
1096
- if (input.model.api.npm === "@openrouter/ai-sdk-provider" || input.model.api.npm === "@llmgateway/ai-sdk-provider") {
1097
- result["usage"] = {
1098
- include: true,
1099
- }
1100
- if (input.model.api.id.includes("gemini-3")) {
1101
- result["reasoning"] = { effort: "high" }
1102
- }
1103
- }
1104
-
1105
- if (
1106
- input.model.providerID === "baseten" ||
1107
- (input.model.providerID === "opencode" && ["kimi-k2-thinking", "glm-4.6"].includes(input.model.api.id))
1108
- ) {
1109
- result["chat_template_args"] = { enable_thinking: true }
1110
- }
1111
-
1112
- if (
1113
- ["zai", "zhipuai"].some((id) => input.model.providerID.includes(id)) &&
1114
- input.model.api.npm === "@ai-sdk/openai-compatible"
1115
- ) {
1116
- result["thinking"] = {
1117
- type: "enabled",
1118
- clear_thinking: false,
1119
- }
1120
- }
1121
-
1122
- if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
1123
- result["promptCacheKey"] = input.sessionID
1124
- }
1125
-
1126
- if (input.model.api.npm === "@ai-sdk/google" || input.model.api.npm === "@ai-sdk/google-vertex") {
1127
- if (input.model.capabilities.reasoning) {
1128
- result["thinkingConfig"] = {
1129
- includeThoughts: true,
1130
- }
1131
- if (input.model.api.id.includes("gemini-3")) {
1132
- result["thinkingConfig"]["thinkingLevel"] = "high"
1133
- }
1134
- }
1135
- }
1136
-
1137
- const modelId = input.model.api.id.toLowerCase()
1138
-
1139
- // MiniMax's Anthropic interface defaults thinking off, unlike Chat Completions.
1140
- if (modelId.includes("minimax-m3") && input.model.api.npm === "@ai-sdk/anthropic") {
1141
- result["thinking"] = { type: "adaptive" }
1142
- }
1143
-
1144
- // Enable thinking by default for kimi models using anthropic SDK
1145
- if (
1146
- (input.model.api.npm === "@ai-sdk/anthropic" || input.model.api.npm === "@ai-sdk/google-vertex/anthropic") &&
1147
- (modelId.includes("k2p") || modelId.includes("kimi-k2.") || modelId.includes("kimi-k2p"))
1148
- ) {
1149
- result["thinking"] = {
1150
- type: "enabled",
1151
- budgetTokens: Math.min(16_000, Math.floor(input.model.limit.output / 2 - 1)),
1152
- }
1153
- }
1154
-
1155
- // Enable thinking for reasoning models on alibaba-cn (DashScope).
1156
- // DashScope's OpenAI-compatible API requires `enable_thinking: true` in the request body
1157
- // to return reasoning_content. Without it, models like kimi-k2.5, qwen-plus, qwen3, qwq,
1158
- // deepseek-r1, etc. never output thinking/reasoning tokens.
1159
- // Note: kimi-k2-thinking is excluded as it returns reasoning_content by default.
1160
- if (
1161
- input.model.providerID === "alibaba-cn" &&
1162
- input.model.capabilities.reasoning &&
1163
- input.model.api.npm === "@ai-sdk/openai-compatible" &&
1164
- !modelId.includes("kimi-k2-thinking")
1165
- ) {
1166
- result["enable_thinking"] = true
1167
- }
1168
-
1169
- if (input.model.api.npm === "@ai-sdk/azure" && input.model.api.id.includes("gpt-5.5")) {
1170
- result["reasoningSummary"] = "auto"
1171
- return result
1172
- }
1173
-
1174
- if (input.model.api.id.includes("gpt-5") && !input.model.api.id.includes("gpt-5-chat")) {
1175
- if (!input.model.api.id.includes("gpt-5-pro")) {
1176
- result["reasoningEffort"] = "medium"
1177
- if (
1178
- input.model.api.npm === "@ai-sdk/openai" ||
1179
- input.model.api.npm === "@ai-sdk/azure" ||
1180
- input.model.api.npm === "@ai-sdk/github-copilot" ||
1181
- input.model.api.npm === "@ai-sdk/amazon-bedrock/mantle"
1182
- ) {
1183
- result["reasoningSummary"] = "auto"
1184
- }
1185
- if (input.model.api.npm === "@ai-sdk/openai" || input.model.api.npm === "@ai-sdk/amazon-bedrock/mantle") {
1186
- result["include"] = INCLUDE_ENCRYPTED_REASONING
1187
- }
1188
- }
1189
-
1190
- // Only set textVerbosity for non-chat gpt-5.x models
1191
- // Chat models (e.g. gpt-5.2-chat-latest) only support "medium" verbosity
1192
- if (
1193
- input.model.api.id.includes("gpt-5.") &&
1194
- !input.model.api.id.includes("codex") &&
1195
- !input.model.api.id.includes("-chat") &&
1196
- input.model.providerID !== "azure"
1197
- ) {
1198
- result["textVerbosity"] = "low"
1199
- }
1200
-
1201
- if (input.model.providerID.startsWith("opencode")) {
1202
- result["promptCacheKey"] = input.sessionID
1203
- result["include"] = INCLUDE_ENCRYPTED_REASONING
1204
- result["reasoningSummary"] = "auto"
1205
- }
1206
- }
1207
-
1208
- if (input.model.providerID === "venice") {
1209
- result["promptCacheKey"] = input.sessionID
1210
- }
1211
-
1212
- if (input.model.providerID === "openrouter") {
1213
- result["prompt_cache_key"] = input.sessionID
1214
- }
1215
- if (input.model.api.npm === "@ai-sdk/gateway") {
1216
- result["gateway"] = {
1217
- caching: "auto",
1218
- }
1219
- }
1220
-
1221
- return result
1222
- }
1223
-
1224
- export function smallOptions(model: Provider.Model) {
1225
- const small = Object.values(model.variants ?? {})[0] ?? {}
1226
- if (
1227
- model.providerID === "openai" ||
1228
- model.api.npm === "@ai-sdk/openai" ||
1229
- model.api.npm === "@ai-sdk/github-copilot"
1230
- ) {
1231
- const base = { store: false }
1232
- return mergeDeep(base, small)
1233
- }
1234
- if (model.providerID === "openrouter" || model.providerID === "llmgateway") {
1235
- if (model.providerID === "openrouter" && small.reasoning?.effort === "low") {
1236
- return { reasoning: { effort: "none" } }
1237
- }
1238
- if (Object.keys(small).length === 0 && model.api.id.includes("google")) {
1239
- return { reasoning: { enabled: false } }
1240
- }
1241
- }
1242
-
1243
- if (model.providerID === "venice") {
1244
- if (Object.keys(small).length > 0) return small
1245
- return { veniceParameters: { disableThinking: true } }
1246
- }
1247
-
1248
- return small
1249
- }
1250
-
1251
- // Maps model ID prefix to provider slug used in providerOptions.
1252
- // Example: "amazon/nova-2-lite" → "bedrock"
1253
- const SLUG_OVERRIDES: Record<string, string> = {
1254
- amazon: "bedrock",
1255
- }
1256
-
1257
- export function providerOptions(model: Provider.Model, options: { [x: string]: any }) {
1258
- if (model.api.npm === "@ai-sdk/gateway") {
1259
- // Gateway providerOptions are split across two namespaces:
1260
- // - `gateway`: gateway-native routing/caching controls (order, only, byok, etc.)
1261
- // - `<upstream slug>`: provider-specific model options (anthropic/openai/...)
1262
- // We keep `gateway` as-is and route every other top-level option under the
1263
- // model-derived upstream slug.
1264
- const i = model.api.id.indexOf("/")
1265
- const rawSlug = i > 0 ? model.api.id.slice(0, i) : undefined
1266
- const slug = rawSlug ? (SLUG_OVERRIDES[rawSlug] ?? rawSlug) : undefined
1267
- const gateway = options.gateway
1268
- const rest = Object.fromEntries(Object.entries(options).filter(([k]) => k !== "gateway"))
1269
- const has = Object.keys(rest).length > 0
1270
-
1271
- const result: Record<string, any> = {}
1272
- if (gateway !== undefined) result.gateway = gateway
1273
-
1274
- if (has) {
1275
- if (slug) {
1276
- // Route model-specific options under the provider slug
1277
- result[slug] = rest
1278
- } else if (gateway && typeof gateway === "object" && !Array.isArray(gateway)) {
1279
- result.gateway = { ...gateway, ...rest }
1280
- } else {
1281
- result.gateway = rest
1282
- }
1283
- }
1284
-
1285
- return result
1286
- }
1287
-
1288
- // AI SDK packages that resolve providerOptionsName by splitting the
1289
- // provider name on "." (e.g. "wafer.ai" -> "wafer") need the same
1290
- // logic here so the key we write matches the key they read.
1291
- // Other SDKs (xai, mistral, groq, cohere, etc.) use hardcoded keys
1292
- // like "xai" or "cohere" - applying .split(".")[0] would break those.
1293
- const usesDotSplitOptions =
1294
- model.api.npm === "@ai-sdk/openai-compatible" ||
1295
- model.api.npm === "@ai-sdk/openai" ||
1296
- model.api.npm === "@ai-sdk/anthropic"
1297
- const key = sdkKey(model.api.npm) ?? (usesDotSplitOptions ? model.providerID.split(".")[0] : model.providerID)
1298
- // @ai-sdk/azure delegates to OpenAIChatLanguageModel which reads from
1299
- // providerOptions["openai"], but OpenAIResponsesLanguageModel checks
1300
- // "azure" first. Pass both so model options work on either code path.
1301
- if (model.api.npm === "@ai-sdk/azure") {
1302
- return { openai: options, azure: options }
1303
- }
1304
- return { [key]: options }
1305
- }
1306
-
1307
- export function maxOutputTokens(model: Provider.Model, outputTokenMax = OUTPUT_TOKEN_MAX): number {
1308
- return Math.min(model.limit.output, outputTokenMax) || outputTokenMax
1309
- }
1310
-
1311
- type JsonRecord = Record<string, unknown>
1312
-
1313
- function isPlainObject(value: unknown): value is JsonRecord {
1314
- return typeof value === "object" && value !== null && !Array.isArray(value)
1315
- }
1316
-
1317
- // Mirrors Codex's Rust JSON schema compatibility lowering for OpenAI tool schemas.
1318
- function sanitizeOpenAISchema(value: unknown): unknown {
1319
- const types = ["string", "number", "boolean", "integer", "object", "array", "null"]
1320
- const compositionKeys = ["anyOf", "oneOf", "allOf"]
1321
-
1322
- // JSON Schema's boolean form (`true`/`false`) is unsupported by OpenAI tool schemas.
1323
- if (typeof value === "boolean") return { type: "string" }
1324
- if (Array.isArray(value)) return value.map(sanitizeOpenAISchema)
1325
- if (!isPlainObject(value)) return value
1326
-
1327
- const result: JsonRecord = {}
1328
-
1329
- if (typeof value.$ref === "string") result.$ref = value.$ref
1330
- if (typeof value.description === "string") result.description = value.description
1331
- if ("const" in value) result.enum = [value.const]
1332
- else if (Array.isArray(value.enum)) result.enum = value.enum
1333
-
1334
- if (isPlainObject(value.properties)) {
1335
- result.properties = Object.fromEntries(
1336
- Object.entries(value.properties).map(([key, item]) => [key, sanitizeOpenAISchema(item)]),
1337
- )
1338
- }
1339
-
1340
- if (Array.isArray(value.required)) {
1341
- result.required = value.required.filter((item) => typeof item === "string")
1342
- }
1343
-
1344
- if ("items" in value) result.items = sanitizeOpenAISchema(value.items)
1345
-
1346
- if ("additionalProperties" in value) {
1347
- result.additionalProperties =
1348
- typeof value.additionalProperties === "boolean"
1349
- ? value.additionalProperties
1350
- : sanitizeOpenAISchema(value.additionalProperties)
1351
- }
1352
-
1353
- for (const key of compositionKeys) {
1354
- if (Array.isArray(value[key])) result[key] = value[key].map(sanitizeOpenAISchema)
1355
- }
1356
-
1357
- for (const key of ["$defs", "definitions"]) {
1358
- if (isPlainObject(value[key])) {
1359
- result[key] = Object.fromEntries(
1360
- Object.entries(value[key]).map(([name, item]) => [name, sanitizeOpenAISchema(item)]),
1361
- )
1362
- }
1363
- }
1364
-
1365
- const schemaTypes =
1366
- typeof value.type === "string"
1367
- ? types.includes(value.type)
1368
- ? [value.type]
1369
- : []
1370
- : Array.isArray(value.type)
1371
- ? value.type.filter((item) => typeof item === "string" && types.includes(item))
1372
- : []
1373
-
1374
- if (schemaTypes.length === 0 && (typeof result.$ref === "string" || compositionKeys.some((key) => key in result))) {
1375
- return result
1376
- }
1377
-
1378
- // MCP schemas may omit `type` while still using keywords that imply one.
1379
- // Keep the schema usable after unsupported keywords are dropped.
1380
- const inferredTypes =
1381
- schemaTypes.length > 0
1382
- ? schemaTypes
1383
- : ["properties", "required", "additionalProperties"].some((key) => key in value)
1384
- ? ["object"]
1385
- : ["items", "prefixItems"].some((key) => key in value)
1386
- ? ["array"]
1387
- : "enum" in result || "format" in value
1388
- ? ["string"]
1389
- : ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"].some((key) => key in value)
1390
- ? ["number"]
1391
- : []
1392
-
1393
- if (inferredTypes.length === 0) return {}
1394
-
1395
- result.type = inferredTypes.length === 1 ? inferredTypes[0] : inferredTypes
1396
- if (inferredTypes.includes("object") && !("properties" in result)) result.properties = {}
1397
- if (inferredTypes.includes("array") && !("items" in result)) result.items = { type: "string" }
1398
- return result
1399
- }
1400
-
1401
- export function schema(model: Provider.Model, schema: JSONSchema7): JSONSchema7 {
1402
- /*
1403
- if (["openai", "azure"].includes(providerID)) {
1404
- if (schema.type === "object" && schema.properties) {
1405
- for (const [key, value] of Object.entries(schema.properties)) {
1406
- if (schema.required?.includes(key)) continue
1407
- schema.properties[key] = {
1408
- anyOf: [
1409
- value as JSONSchema.JSONSchema,
1410
- {
1411
- type: "null",
1412
- },
1413
- ],
1414
- }
1415
- }
1416
- }
1417
- }
1418
- */
1419
-
1420
- if (model.api.npm === "@ai-sdk/openai" || model.api.npm === "@ai-sdk/azure") {
1421
- schema = sanitizeOpenAISchema(schema) as JSONSchema7
1422
- // Codex also applies lossy compaction above 4 KB; defer that until OnlyCode needs the same schema budget.
1423
- }
1424
-
1425
- if (model.providerID === "moonshotai" || model.api.id.toLowerCase().includes("kimi")) {
1426
- const sanitizeMoonshot = (obj: unknown): unknown => {
1427
- if (obj === null || typeof obj !== "object") return obj
1428
- if (Array.isArray(obj)) return obj.map(sanitizeMoonshot)
1429
- // Moonshot expands $ref before validation and rejects sibling keywords like description on the same node.
1430
- if ("$ref" in obj && typeof obj.$ref === "string") return { $ref: obj.$ref }
1431
- const result = Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, sanitizeMoonshot(value)]))
1432
- // MFJS does not support tuple-style `items` arrays; it requires one schema object for all array items.
1433
- if (Array.isArray(result.items)) result.items = result.items[0] ?? {}
1434
- return result
1435
- }
1436
-
1437
- const sanitized = sanitizeMoonshot(schema)
1438
- if (typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized)) {
1439
- schema = sanitized
1440
- }
1441
- }
1442
-
1443
- // Convert integer enums to string enums for Google/Gemini
1444
- if (model.providerID === "google" || model.api.id.includes("gemini")) {
1445
- const isPlainObject = (node: unknown): node is Record<string, any> =>
1446
- typeof node === "object" && node !== null && !Array.isArray(node)
1447
- const hasCombiner = (node: unknown) =>
1448
- isPlainObject(node) && (Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf))
1449
- const hasSchemaIntent = (node: unknown) => {
1450
- if (!isPlainObject(node)) return false
1451
- if (hasCombiner(node)) return true
1452
- return [
1453
- "type",
1454
- "properties",
1455
- "items",
1456
- "prefixItems",
1457
- "enum",
1458
- "const",
1459
- "$ref",
1460
- "additionalProperties",
1461
- "patternProperties",
1462
- "required",
1463
- "not",
1464
- "if",
1465
- "then",
1466
- "else",
1467
- ].some((key) => key in node)
1468
- }
1469
-
1470
- const sanitizeGemini = (obj: any): any => {
1471
- if (obj === null || typeof obj !== "object") {
1472
- return obj
1473
- }
1474
-
1475
- if (Array.isArray(obj)) {
1476
- return obj.map(sanitizeGemini)
1477
- }
1478
-
1479
- const result: any = {}
1480
- for (const [key, value] of Object.entries(obj)) {
1481
- if (key === "enum" && Array.isArray(value)) {
1482
- // Convert all enum values to strings
1483
- result[key] = value.map((v) => String(v))
1484
- // If we have integer type with enum, change type to string
1485
- if (result.type === "integer" || result.type === "number") {
1486
- result.type = "string"
1487
- }
1488
- } else if (typeof value === "object" && value !== null) {
1489
- result[key] = sanitizeGemini(value)
1490
- } else {
1491
- result[key] = value
1492
- }
1493
- }
1494
-
1495
- // Gemini requires a single `type`, not a JSON Schema type array such as
1496
- // `["number","string"]` (emitted by some MCP servers). Plain `@ai-sdk/google`
1497
- // rewrites these into an `anyOf` of single-type schemas, but OpenAI-compatible
1498
- // transports (e.g. GitHub Copilot proxying to Gemini) forward them verbatim
1499
- // and the backend rejects the array form. Mirror the SDK: split non-null
1500
- // types into `anyOf`, and lift `null` into `nullable`.
1501
- if (Array.isArray(result.type)) {
1502
- const hasNull = result.type.includes("null")
1503
- const nonNull = result.type.filter((entry: unknown) => entry !== "null")
1504
- if (nonNull.length === 0) {
1505
- result.type = "null"
1506
- } else {
1507
- delete result.type
1508
- result.anyOf = nonNull.map((entry: unknown) => ({ type: entry }))
1509
- if (hasNull) result.nullable = true
1510
- }
1511
- }
1512
-
1513
- // Filter required array to only include fields that exist in properties
1514
- if (result.type === "object" && result.properties && Array.isArray(result.required)) {
1515
- result.required = result.required.filter((field: any) => field in result.properties)
1516
- }
1517
-
1518
- if (result.type === "array" && !hasCombiner(result)) {
1519
- if (result.items == null) {
1520
- result.items = {}
1521
- }
1522
- // Ensure items has a type only when it's still schema-empty.
1523
- if (isPlainObject(result.items) && !hasSchemaIntent(result.items)) {
1524
- result.items.type = "string"
1525
- }
1526
- }
1527
-
1528
- // Remove properties/required from non-object types (Gemini rejects these)
1529
- if (result.type && result.type !== "object" && !hasCombiner(result)) {
1530
- delete result.properties
1531
- delete result.required
1532
- }
1533
-
1534
- return result
1535
- }
1536
-
1537
- schema = sanitizeGemini(schema)
1538
- }
1539
-
1540
- return schema
1541
- }
1542
-
1543
- export * as ProviderTransform from "./transform"