artificial-code 1.17.13 → 1.17.15

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