@toolkit-cli/toolkode 1.3.7

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 (676) hide show
  1. package/AGENTS.md +69 -0
  2. package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
  3. package/Dockerfile +18 -0
  4. package/README.md +15 -0
  5. package/bin/opencode +179 -0
  6. package/bin/toolkode +17 -0
  7. package/bin/toolkode.cjs +190 -0
  8. package/bunfig.toml +7 -0
  9. package/drizzle.config.ts +10 -0
  10. package/git +0 -0
  11. package/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
  12. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
  13. package/migration/20260211171708_add_project_commands/migration.sql +1 -0
  14. package/migration/20260211171708_add_project_commands/snapshot.json +806 -0
  15. package/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
  16. package/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
  17. package/migration/20260225215848_workspace/migration.sql +7 -0
  18. package/migration/20260225215848_workspace/snapshot.json +959 -0
  19. package/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
  20. package/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
  21. package/migration/20260228203230_blue_harpoon/migration.sql +17 -0
  22. package/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
  23. package/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
  24. package/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
  25. package/migration/20260309230000_move_org_to_state/migration.sql +3 -0
  26. package/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
  27. package/migration/20260312043431_session_message_cursor/migration.sql +4 -0
  28. package/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
  29. package/migration/20260323234822_events/migration.sql +13 -0
  30. package/migration/20260323234822_events/snapshot.json +1271 -0
  31. package/package.json +160 -0
  32. package/parsers-config.ts +290 -0
  33. package/script/build-node.ts +54 -0
  34. package/script/build.ts +276 -0
  35. package/script/check-migrations.ts +16 -0
  36. package/script/postinstall.mjs +131 -0
  37. package/script/publish.ts +181 -0
  38. package/script/schema.ts +63 -0
  39. package/script/seed-e2e.ts +60 -0
  40. package/script/upgrade-opentui.ts +64 -0
  41. package/specs/effect-migration.md +293 -0
  42. package/specs/tui-plugins.md +389 -0
  43. package/src/account/account.sql.ts +39 -0
  44. package/src/account/index.ts +397 -0
  45. package/src/account/repo.ts +163 -0
  46. package/src/account/schema.ts +91 -0
  47. package/src/acp/README.md +174 -0
  48. package/src/acp/agent.ts +1743 -0
  49. package/src/acp/session.ts +116 -0
  50. package/src/acp/types.ts +24 -0
  51. package/src/agent/agent.ts +418 -0
  52. package/src/agent/generate.txt +75 -0
  53. package/src/agent/prompt/compaction.txt +14 -0
  54. package/src/agent/prompt/explore.txt +18 -0
  55. package/src/agent/prompt/summary.txt +11 -0
  56. package/src/agent/prompt/title.txt +44 -0
  57. package/src/auth/index.ts +115 -0
  58. package/src/bun/index.ts +128 -0
  59. package/src/bun/registry.ts +50 -0
  60. package/src/bus/bus-event.ts +40 -0
  61. package/src/bus/global.ts +10 -0
  62. package/src/bus/index.ts +184 -0
  63. package/src/channel/index.ts +231 -0
  64. package/src/cli/bootstrap.ts +17 -0
  65. package/src/cli/cmd/account.ts +257 -0
  66. package/src/cli/cmd/acp.ts +70 -0
  67. package/src/cli/cmd/agent.ts +245 -0
  68. package/src/cli/cmd/cmd.ts +7 -0
  69. package/src/cli/cmd/db.ts +119 -0
  70. package/src/cli/cmd/debug/agent.ts +167 -0
  71. package/src/cli/cmd/debug/config.ts +16 -0
  72. package/src/cli/cmd/debug/file.ts +97 -0
  73. package/src/cli/cmd/debug/index.ts +48 -0
  74. package/src/cli/cmd/debug/lsp.ts +53 -0
  75. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  76. package/src/cli/cmd/debug/scrap.ts +16 -0
  77. package/src/cli/cmd/debug/skill.ts +16 -0
  78. package/src/cli/cmd/debug/snapshot.ts +52 -0
  79. package/src/cli/cmd/export.ts +89 -0
  80. package/src/cli/cmd/generate.ts +38 -0
  81. package/src/cli/cmd/github.ts +1646 -0
  82. package/src/cli/cmd/import.ts +207 -0
  83. package/src/cli/cmd/mcp.ts +754 -0
  84. package/src/cli/cmd/models.ts +78 -0
  85. package/src/cli/cmd/plug.ts +231 -0
  86. package/src/cli/cmd/pr.ts +127 -0
  87. package/src/cli/cmd/providers.ts +482 -0
  88. package/src/cli/cmd/run.ts +738 -0
  89. package/src/cli/cmd/serve.ts +42 -0
  90. package/src/cli/cmd/session.ts +159 -0
  91. package/src/cli/cmd/stats.ts +410 -0
  92. package/src/cli/cmd/tui/app.tsx +1255 -0
  93. package/src/cli/cmd/tui/attach.ts +88 -0
  94. package/src/cli/cmd/tui/component/border.tsx +21 -0
  95. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  96. package/src/cli/cmd/tui/component/dialog-command.tsx +171 -0
  97. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  98. package/src/cli/cmd/tui/component/dialog-model.tsx +264 -0
  99. package/src/cli/cmd/tui/component/dialog-provider.tsx +334 -0
  100. package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
  101. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  102. package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
  103. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  104. package/src/cli/cmd/tui/component/dialog-status.tsx +168 -0
  105. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  106. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  107. package/src/cli/cmd/tui/component/dialog-variant.tsx +29 -0
  108. package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +320 -0
  109. package/src/cli/cmd/tui/component/error-component.tsx +91 -0
  110. package/src/cli/cmd/tui/component/logo.tsx +86 -0
  111. package/src/cli/cmd/tui/component/plugin-route-missing.tsx +14 -0
  112. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +667 -0
  113. package/src/cli/cmd/tui/component/prompt/frecency.tsx +90 -0
  114. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  115. package/src/cli/cmd/tui/component/prompt/index.tsx +1353 -0
  116. package/src/cli/cmd/tui/component/prompt/part.ts +16 -0
  117. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  118. package/src/cli/cmd/tui/component/spinner.tsx +24 -0
  119. package/src/cli/cmd/tui/component/startup-loading.tsx +63 -0
  120. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  121. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  122. package/src/cli/cmd/tui/component/workspace/dialog-session-list.tsx +151 -0
  123. package/src/cli/cmd/tui/context/args.tsx +15 -0
  124. package/src/cli/cmd/tui/context/directory.ts +13 -0
  125. package/src/cli/cmd/tui/context/exit.tsx +60 -0
  126. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  127. package/src/cli/cmd/tui/context/keybind.tsx +105 -0
  128. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  129. package/src/cli/cmd/tui/context/local.tsx +406 -0
  130. package/src/cli/cmd/tui/context/plugin-keybinds.ts +41 -0
  131. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  132. package/src/cli/cmd/tui/context/route.tsx +52 -0
  133. package/src/cli/cmd/tui/context/sdk.tsx +128 -0
  134. package/src/cli/cmd/tui/context/sync.tsx +504 -0
  135. package/src/cli/cmd/tui/context/theme/amber.json +245 -0
  136. package/src/cli/cmd/tui/context/theme/amiga.json +245 -0
  137. package/src/cli/cmd/tui/context/theme/atari.json +245 -0
  138. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  139. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  140. package/src/cli/cmd/tui/context/theme/borland.json +245 -0
  141. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  142. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  143. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  144. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  145. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  146. package/src/cli/cmd/tui/context/theme/commodore.json +245 -0
  147. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  148. package/src/cli/cmd/tui/context/theme/dos-edit.json +245 -0
  149. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  150. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  151. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  152. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  153. package/src/cli/cmd/tui/context/theme/gnu.json +245 -0
  154. package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  155. package/src/cli/cmd/tui/context/theme/hacker.json +245 -0
  156. package/src/cli/cmd/tui/context/theme/irix.json +245 -0
  157. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  158. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  159. package/src/cli/cmd/tui/context/theme/mac84.json +245 -0
  160. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  161. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  162. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  163. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  164. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  165. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  166. package/src/cli/cmd/tui/context/theme/norton.json +245 -0
  167. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  168. package/src/cli/cmd/tui/context/theme/opencode.json +245 -0
  169. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  170. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  171. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  172. package/src/cli/cmd/tui/context/theme/pine.json +245 -0
  173. package/src/cli/cmd/tui/context/theme/retrowave.json +245 -0
  174. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  175. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  176. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  177. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  178. package/src/cli/cmd/tui/context/theme/toolkode.json +245 -0
  179. package/src/cli/cmd/tui/context/theme/tron.json +245 -0
  180. package/src/cli/cmd/tui/context/theme/ubuntu.json +245 -0
  181. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  182. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  183. package/src/cli/cmd/tui/context/theme/vt100.json +245 -0
  184. package/src/cli/cmd/tui/context/theme/xcode.json +245 -0
  185. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  186. package/src/cli/cmd/tui/context/theme.tsx +1288 -0
  187. package/src/cli/cmd/tui/context/tui-config.tsx +9 -0
  188. package/src/cli/cmd/tui/event.ts +49 -0
  189. package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +152 -0
  190. package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +50 -0
  191. package/src/cli/cmd/tui/feature-plugins/sidebar/agents-panel.tsx +95 -0
  192. package/src/cli/cmd/tui/feature-plugins/sidebar/btw-panel.tsx +105 -0
  193. package/src/cli/cmd/tui/feature-plugins/sidebar/commands-panel.tsx +40 -0
  194. package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +63 -0
  195. package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +62 -0
  196. package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +93 -0
  197. package/src/cli/cmd/tui/feature-plugins/sidebar/git-panel.tsx +36 -0
  198. package/src/cli/cmd/tui/feature-plugins/sidebar/loop-panel.tsx +124 -0
  199. package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +66 -0
  200. package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +96 -0
  201. package/src/cli/cmd/tui/feature-plugins/sidebar/session-panel.tsx +48 -0
  202. package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +48 -0
  203. package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +270 -0
  204. package/src/cli/cmd/tui/plugin/api.tsx +420 -0
  205. package/src/cli/cmd/tui/plugin/index.ts +3 -0
  206. package/src/cli/cmd/tui/plugin/internal.ts +37 -0
  207. package/src/cli/cmd/tui/plugin/runtime.ts +967 -0
  208. package/src/cli/cmd/tui/plugin/slots.tsx +61 -0
  209. package/src/cli/cmd/tui/routes/home.tsx +173 -0
  210. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +65 -0
  211. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +110 -0
  212. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  213. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  214. package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  215. package/src/cli/cmd/tui/routes/session/index.tsx +2229 -0
  216. package/src/cli/cmd/tui/routes/session/permission.tsx +685 -0
  217. package/src/cli/cmd/tui/routes/session/question.tsx +467 -0
  218. package/src/cli/cmd/tui/routes/session/sidebar.tsx +72 -0
  219. package/src/cli/cmd/tui/routes/session/subagent-footer.tsx +131 -0
  220. package/src/cli/cmd/tui/thread.ts +232 -0
  221. package/src/cli/cmd/tui/ui/dialog-alert.tsx +59 -0
  222. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +89 -0
  223. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +208 -0
  224. package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
  225. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +106 -0
  226. package/src/cli/cmd/tui/ui/dialog-select.tsx +402 -0
  227. package/src/cli/cmd/tui/ui/dialog.tsx +192 -0
  228. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  229. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  230. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  231. package/src/cli/cmd/tui/util/clipboard.ts +192 -0
  232. package/src/cli/cmd/tui/util/editor.ts +37 -0
  233. package/src/cli/cmd/tui/util/selection.ts +25 -0
  234. package/src/cli/cmd/tui/util/signal.ts +7 -0
  235. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  236. package/src/cli/cmd/tui/util/transcript.ts +98 -0
  237. package/src/cli/cmd/tui/win32.ts +129 -0
  238. package/src/cli/cmd/tui/worker.ts +204 -0
  239. package/src/cli/cmd/uninstall.ts +353 -0
  240. package/src/cli/cmd/upgrade.ts +73 -0
  241. package/src/cli/cmd/web.ts +81 -0
  242. package/src/cli/effect/prompt.ts +25 -0
  243. package/src/cli/error.ts +46 -0
  244. package/src/cli/logo.ts +7 -0
  245. package/src/cli/network.ts +60 -0
  246. package/src/cli/ui.ts +116 -0
  247. package/src/cli/upgrade.ts +31 -0
  248. package/src/command/index.ts +195 -0
  249. package/src/command/template/initialize.txt +10 -0
  250. package/src/command/template/review.txt +101 -0
  251. package/src/config/config.ts +1693 -0
  252. package/src/config/markdown.ts +99 -0
  253. package/src/config/migrate-tui-config.ts +155 -0
  254. package/src/config/paths.ts +174 -0
  255. package/src/config/tui-schema.ts +36 -0
  256. package/src/config/tui.ts +212 -0
  257. package/src/control-plane/adaptors/index.ts +20 -0
  258. package/src/control-plane/adaptors/worktree.ts +38 -0
  259. package/src/control-plane/schema.ts +17 -0
  260. package/src/control-plane/sse.ts +66 -0
  261. package/src/control-plane/types.ts +21 -0
  262. package/src/control-plane/workspace.sql.ts +17 -0
  263. package/src/control-plane/workspace.ts +154 -0
  264. package/src/cron/index.ts +241 -0
  265. package/src/cron/parse.ts +189 -0
  266. package/src/effect/cross-spawn-spawner.ts +479 -0
  267. package/src/effect/instance-registry.ts +12 -0
  268. package/src/effect/instance-state.ts +47 -0
  269. package/src/effect/run-service.ts +19 -0
  270. package/src/env/index.ts +28 -0
  271. package/src/file/ignore.ts +82 -0
  272. package/src/file/index.ts +693 -0
  273. package/src/file/protected.ts +59 -0
  274. package/src/file/ripgrep.ts +376 -0
  275. package/src/file/time.ts +128 -0
  276. package/src/file/watcher.ts +171 -0
  277. package/src/filesystem/index.ts +226 -0
  278. package/src/flag/flag.ts +157 -0
  279. package/src/format/formatter.ts +396 -0
  280. package/src/format/index.ts +199 -0
  281. package/src/global/index.ts +54 -0
  282. package/src/hooks/index.ts +302 -0
  283. package/src/id/id.ts +85 -0
  284. package/src/ide/index.ts +74 -0
  285. package/src/index.ts +243 -0
  286. package/src/installation/index.ts +363 -0
  287. package/src/lsp/client.ts +252 -0
  288. package/src/lsp/index.ts +558 -0
  289. package/src/lsp/language.ts +120 -0
  290. package/src/lsp/launch.ts +21 -0
  291. package/src/lsp/server.ts +2093 -0
  292. package/src/mcp/auth.ts +181 -0
  293. package/src/mcp/index.ts +926 -0
  294. package/src/mcp/oauth-callback.ts +215 -0
  295. package/src/mcp/oauth-provider.ts +185 -0
  296. package/src/node.ts +1 -0
  297. package/src/patch/index.ts +680 -0
  298. package/src/permission/arity.ts +163 -0
  299. package/src/permission/evaluate.ts +15 -0
  300. package/src/permission/index.ts +322 -0
  301. package/src/permission/schema.ts +17 -0
  302. package/src/plugin/codex.ts +628 -0
  303. package/src/plugin/copilot.ts +343 -0
  304. package/src/plugin/index.ts +331 -0
  305. package/src/plugin/install.ts +384 -0
  306. package/src/plugin/meta.ts +165 -0
  307. package/src/plugin/shared.ts +172 -0
  308. package/src/project/bootstrap.ts +31 -0
  309. package/src/project/instance.ts +167 -0
  310. package/src/project/project.sql.ts +16 -0
  311. package/src/project/project.ts +519 -0
  312. package/src/project/schema.ts +16 -0
  313. package/src/project/state.ts +70 -0
  314. package/src/project/vcs.ts +124 -0
  315. package/src/provider/auth.ts +252 -0
  316. package/src/provider/error.ts +197 -0
  317. package/src/provider/models.ts +138 -0
  318. package/src/provider/provider.ts +1593 -0
  319. package/src/provider/schema.ts +39 -0
  320. package/src/provider/sdk/copilot/README.md +5 -0
  321. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
  322. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  323. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
  324. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  325. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +815 -0
  326. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  327. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  328. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +83 -0
  329. package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  330. package/src/provider/sdk/copilot/index.ts +2 -0
  331. package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  332. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +335 -0
  333. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  334. package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  335. package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  336. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +214 -0
  337. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1769 -0
  338. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +173 -0
  339. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  340. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +87 -0
  341. package/src/provider/sdk/copilot/responses/tool/file-search.ts +127 -0
  342. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +114 -0
  343. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +64 -0
  344. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +103 -0
  345. package/src/provider/sdk/copilot/responses/tool/web-search.ts +102 -0
  346. package/src/provider/toolkit-manifest.ts +110 -0
  347. package/src/provider/transform.ts +1045 -0
  348. package/src/pty/index.ts +397 -0
  349. package/src/pty/schema.ts +17 -0
  350. package/src/question/index.ts +221 -0
  351. package/src/question/schema.ts +17 -0
  352. package/src/server/error.ts +36 -0
  353. package/src/server/event.ts +7 -0
  354. package/src/server/instance.ts +285 -0
  355. package/src/server/mdns.ts +60 -0
  356. package/src/server/middleware.ts +29 -0
  357. package/src/server/projectors.ts +28 -0
  358. package/src/server/router.ts +99 -0
  359. package/src/server/routes/config.ts +92 -0
  360. package/src/server/routes/event.ts +83 -0
  361. package/src/server/routes/experimental.ts +271 -0
  362. package/src/server/routes/file.ts +197 -0
  363. package/src/server/routes/global.ts +339 -0
  364. package/src/server/routes/mcp.ts +225 -0
  365. package/src/server/routes/permission.ts +69 -0
  366. package/src/server/routes/project.ts +118 -0
  367. package/src/server/routes/provider.ts +171 -0
  368. package/src/server/routes/pty.ts +211 -0
  369. package/src/server/routes/question.ts +99 -0
  370. package/src/server/routes/session.ts +1031 -0
  371. package/src/server/routes/tui.ts +379 -0
  372. package/src/server/routes/workspace.ts +94 -0
  373. package/src/server/server.ts +312 -0
  374. package/src/session/compaction.ts +424 -0
  375. package/src/session/index.ts +882 -0
  376. package/src/session/instruction.ts +321 -0
  377. package/src/session/llm.ts +341 -0
  378. package/src/session/message-v2.ts +1030 -0
  379. package/src/session/message.ts +191 -0
  380. package/src/session/overflow.ts +22 -0
  381. package/src/session/processor.ts +554 -0
  382. package/src/session/projectors.ts +135 -0
  383. package/src/session/prompt/anthropic.txt +105 -0
  384. package/src/session/prompt/beast.txt +147 -0
  385. package/src/session/prompt/build-switch.txt +5 -0
  386. package/src/session/prompt/codex.txt +79 -0
  387. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  388. package/src/session/prompt/default.txt +108 -0
  389. package/src/session/prompt/gemini.txt +155 -0
  390. package/src/session/prompt/gpt.txt +107 -0
  391. package/src/session/prompt/max-steps.txt +16 -0
  392. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  393. package/src/session/prompt/plan.txt +26 -0
  394. package/src/session/prompt/trinity.txt +97 -0
  395. package/src/session/prompt.ts +2058 -0
  396. package/src/session/retry.ts +106 -0
  397. package/src/session/revert.ts +138 -0
  398. package/src/session/schema.ts +38 -0
  399. package/src/session/session.sql.ts +103 -0
  400. package/src/session/status.ts +102 -0
  401. package/src/session/summary.ts +170 -0
  402. package/src/session/system.ts +74 -0
  403. package/src/session/todo.ts +57 -0
  404. package/src/share/share-next.ts +288 -0
  405. package/src/share/share.sql.ts +13 -0
  406. package/src/shell/shell.ts +73 -0
  407. package/src/skill/discovery.ts +116 -0
  408. package/src/skill/index.ts +284 -0
  409. package/src/skills-marketplace/index.ts +305 -0
  410. package/src/snapshot/index.ts +489 -0
  411. package/src/sql.d.ts +4 -0
  412. package/src/storage/db.bun.ts +8 -0
  413. package/src/storage/db.node.ts +8 -0
  414. package/src/storage/db.ts +177 -0
  415. package/src/storage/json-migration.ts +425 -0
  416. package/src/storage/schema.sql.ts +10 -0
  417. package/src/storage/schema.ts +5 -0
  418. package/src/storage/storage.ts +217 -0
  419. package/src/sync/README.md +179 -0
  420. package/src/sync/event.sql.ts +16 -0
  421. package/src/sync/index.ts +263 -0
  422. package/src/sync/schema.ts +14 -0
  423. package/src/team/index.ts +428 -0
  424. package/src/tool/apply_patch.ts +281 -0
  425. package/src/tool/apply_patch.txt +33 -0
  426. package/src/tool/bash.ts +271 -0
  427. package/src/tool/bash.txt +115 -0
  428. package/src/tool/batch.ts +183 -0
  429. package/src/tool/batch.txt +24 -0
  430. package/src/tool/codesearch.ts +132 -0
  431. package/src/tool/codesearch.txt +12 -0
  432. package/src/tool/cron-create.ts +54 -0
  433. package/src/tool/cron-create.txt +16 -0
  434. package/src/tool/cron-delete.ts +29 -0
  435. package/src/tool/cron-delete.txt +1 -0
  436. package/src/tool/cron-list.ts +41 -0
  437. package/src/tool/cron-list.txt +1 -0
  438. package/src/tool/edit.ts +667 -0
  439. package/src/tool/edit.txt +10 -0
  440. package/src/tool/external-directory.ts +32 -0
  441. package/src/tool/glob.ts +78 -0
  442. package/src/tool/glob.txt +6 -0
  443. package/src/tool/grep.ts +156 -0
  444. package/src/tool/grep.txt +8 -0
  445. package/src/tool/invalid.ts +17 -0
  446. package/src/tool/ls.ts +121 -0
  447. package/src/tool/ls.txt +1 -0
  448. package/src/tool/lsp.ts +97 -0
  449. package/src/tool/lsp.txt +19 -0
  450. package/src/tool/multiedit.ts +46 -0
  451. package/src/tool/multiedit.txt +41 -0
  452. package/src/tool/plan-enter.txt +14 -0
  453. package/src/tool/plan-exit.txt +13 -0
  454. package/src/tool/plan.ts +131 -0
  455. package/src/tool/question.ts +33 -0
  456. package/src/tool/question.txt +10 -0
  457. package/src/tool/read.ts +293 -0
  458. package/src/tool/read.txt +14 -0
  459. package/src/tool/registry.ts +232 -0
  460. package/src/tool/schema.ts +17 -0
  461. package/src/tool/send-message.ts +59 -0
  462. package/src/tool/send-message.txt +7 -0
  463. package/src/tool/skill.ts +105 -0
  464. package/src/tool/task.ts +230 -0
  465. package/src/tool/task.txt +62 -0
  466. package/src/tool/team.ts +235 -0
  467. package/src/tool/team.txt +22 -0
  468. package/src/tool/todo.ts +31 -0
  469. package/src/tool/todowrite.txt +167 -0
  470. package/src/tool/tool.ts +90 -0
  471. package/src/tool/truncate.ts +144 -0
  472. package/src/tool/truncation-dir.ts +4 -0
  473. package/src/tool/webfetch.ts +206 -0
  474. package/src/tool/webfetch.txt +13 -0
  475. package/src/tool/websearch.ts +150 -0
  476. package/src/tool/websearch.txt +14 -0
  477. package/src/tool/write.ts +84 -0
  478. package/src/tool/write.txt +8 -0
  479. package/src/util/abort.ts +35 -0
  480. package/src/util/archive.ts +17 -0
  481. package/src/util/color.ts +19 -0
  482. package/src/util/context.ts +25 -0
  483. package/src/util/data-url.ts +9 -0
  484. package/src/util/defer.ts +12 -0
  485. package/src/util/effect-http-client.ts +11 -0
  486. package/src/util/effect-zod.ts +98 -0
  487. package/src/util/error.ts +77 -0
  488. package/src/util/filesystem.ts +203 -0
  489. package/src/util/flock.ts +333 -0
  490. package/src/util/fn.ts +21 -0
  491. package/src/util/format.ts +20 -0
  492. package/src/util/git.ts +35 -0
  493. package/src/util/glob.ts +34 -0
  494. package/src/util/hash.ts +7 -0
  495. package/src/util/iife.ts +3 -0
  496. package/src/util/keybind.ts +103 -0
  497. package/src/util/lazy.ts +23 -0
  498. package/src/util/locale.ts +81 -0
  499. package/src/util/lock.ts +98 -0
  500. package/src/util/log.ts +182 -0
  501. package/src/util/network.ts +9 -0
  502. package/src/util/process.ts +172 -0
  503. package/src/util/queue.ts +32 -0
  504. package/src/util/record.ts +3 -0
  505. package/src/util/rpc.ts +66 -0
  506. package/src/util/schema.ts +53 -0
  507. package/src/util/scrap.ts +10 -0
  508. package/src/util/signal.ts +12 -0
  509. package/src/util/timeout.ts +14 -0
  510. package/src/util/token.ts +7 -0
  511. package/src/util/update-schema.ts +13 -0
  512. package/src/util/which.ts +14 -0
  513. package/src/util/wildcard.ts +59 -0
  514. package/src/worktree/index.ts +638 -0
  515. package/sst-env.d.ts +10 -0
  516. package/test/AGENTS.md +81 -0
  517. package/test/account/repo.test.ts +326 -0
  518. package/test/account/service.test.ts +282 -0
  519. package/test/acp/agent-interface.test.ts +51 -0
  520. package/test/acp/event-subscription.test.ts +685 -0
  521. package/test/agent/agent.test.ts +717 -0
  522. package/test/auth/auth.test.ts +58 -0
  523. package/test/bun.test.ts +53 -0
  524. package/test/bus/bus-effect.test.ts +164 -0
  525. package/test/bus/bus-integration.test.ts +87 -0
  526. package/test/bus/bus.test.ts +219 -0
  527. package/test/cli/account.test.ts +26 -0
  528. package/test/cli/cmd/tui/prompt-part.test.ts +47 -0
  529. package/test/cli/github-action.test.ts +198 -0
  530. package/test/cli/github-remote.test.ts +80 -0
  531. package/test/cli/import.test.ts +54 -0
  532. package/test/cli/plugin-auth-picker.test.ts +120 -0
  533. package/test/cli/tui/keybind-plugin.test.ts +90 -0
  534. package/test/cli/tui/plugin-add.test.ts +61 -0
  535. package/test/cli/tui/plugin-install.test.ts +95 -0
  536. package/test/cli/tui/plugin-lifecycle.test.ts +225 -0
  537. package/test/cli/tui/plugin-loader-entrypoint.test.ts +189 -0
  538. package/test/cli/tui/plugin-loader-pure.test.ts +71 -0
  539. package/test/cli/tui/plugin-loader.test.ts +563 -0
  540. package/test/cli/tui/plugin-toggle.test.ts +157 -0
  541. package/test/cli/tui/theme-store.test.ts +51 -0
  542. package/test/cli/tui/thread.test.ts +128 -0
  543. package/test/cli/tui/transcript.test.ts +322 -0
  544. package/test/config/agent-color.test.ts +71 -0
  545. package/test/config/config.test.ts +2187 -0
  546. package/test/config/fixtures/empty-frontmatter.md +4 -0
  547. package/test/config/fixtures/frontmatter.md +28 -0
  548. package/test/config/fixtures/markdown-header.md +11 -0
  549. package/test/config/fixtures/no-frontmatter.md +1 -0
  550. package/test/config/fixtures/weird-model-id.md +13 -0
  551. package/test/config/markdown.test.ts +228 -0
  552. package/test/config/tui.test.ts +667 -0
  553. package/test/control-plane/sse.test.ts +56 -0
  554. package/test/effect/cross-spawn-spawner.test.ts +402 -0
  555. package/test/effect/instance-state.test.ts +384 -0
  556. package/test/effect/run-service.test.ts +46 -0
  557. package/test/file/fsmonitor.test.ts +62 -0
  558. package/test/file/ignore.test.ts +10 -0
  559. package/test/file/index.test.ts +946 -0
  560. package/test/file/path-traversal.test.ts +198 -0
  561. package/test/file/ripgrep.test.ts +54 -0
  562. package/test/file/time.test.ts +354 -0
  563. package/test/file/watcher.test.ts +247 -0
  564. package/test/filesystem/filesystem.test.ts +319 -0
  565. package/test/fixture/db.ts +11 -0
  566. package/test/fixture/fixture.test.ts +26 -0
  567. package/test/fixture/fixture.ts +141 -0
  568. package/test/fixture/flock-worker.ts +72 -0
  569. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  570. package/test/fixture/plug-worker.ts +93 -0
  571. package/test/fixture/plugin-meta-worker.ts +26 -0
  572. package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
  573. package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
  574. package/test/fixture/skills/cloudflare/SKILL.md +211 -0
  575. package/test/fixture/skills/index.json +6 -0
  576. package/test/fixture/tui-plugin.ts +335 -0
  577. package/test/fixture/tui-runtime.ts +34 -0
  578. package/test/format/format.test.ts +179 -0
  579. package/test/ide/ide.test.ts +82 -0
  580. package/test/installation/installation.test.ts +151 -0
  581. package/test/keybind.test.ts +421 -0
  582. package/test/lib/effect.ts +37 -0
  583. package/test/lib/filesystem.ts +10 -0
  584. package/test/lsp/client.test.ts +95 -0
  585. package/test/lsp/index.test.ts +55 -0
  586. package/test/lsp/launch.test.ts +22 -0
  587. package/test/lsp/lifecycle.test.ts +147 -0
  588. package/test/mcp/headers.test.ts +153 -0
  589. package/test/mcp/lifecycle.test.ts +750 -0
  590. package/test/mcp/oauth-auto-connect.test.ts +199 -0
  591. package/test/mcp/oauth-browser.test.ts +249 -0
  592. package/test/memory/abort-leak.test.ts +137 -0
  593. package/test/patch/patch.test.ts +348 -0
  594. package/test/permission/arity.test.ts +33 -0
  595. package/test/permission/next.test.ts +1148 -0
  596. package/test/permission-task.test.ts +323 -0
  597. package/test/plugin/auth-override.test.ts +74 -0
  598. package/test/plugin/codex.test.ts +123 -0
  599. package/test/plugin/install-concurrency.test.ts +134 -0
  600. package/test/plugin/install.test.ts +504 -0
  601. package/test/plugin/loader-shared.test.ts +625 -0
  602. package/test/plugin/meta.test.ts +137 -0
  603. package/test/plugin/trigger.test.ts +111 -0
  604. package/test/preload.ts +90 -0
  605. package/test/project/migrate-global.test.ts +140 -0
  606. package/test/project/project.test.ts +459 -0
  607. package/test/project/state.test.ts +115 -0
  608. package/test/project/vcs.test.ts +116 -0
  609. package/test/project/worktree-remove.test.ts +96 -0
  610. package/test/project/worktree.test.ts +173 -0
  611. package/test/provider/amazon-bedrock.test.ts +447 -0
  612. package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
  613. package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
  614. package/test/provider/gitlab-duo.test.ts +412 -0
  615. package/test/provider/provider.test.ts +2284 -0
  616. package/test/provider/transform.test.ts +2758 -0
  617. package/test/pty/pty-output-isolation.test.ts +141 -0
  618. package/test/pty/pty-session.test.ts +92 -0
  619. package/test/question/question.test.ts +453 -0
  620. package/test/server/global-session-list.test.ts +89 -0
  621. package/test/server/project-init-git.test.ts +121 -0
  622. package/test/server/session-list.test.ts +90 -0
  623. package/test/server/session-messages.test.ts +132 -0
  624. package/test/server/session-select.test.ts +78 -0
  625. package/test/session/compaction.test.ts +1094 -0
  626. package/test/session/instruction.test.ts +170 -0
  627. package/test/session/llm.test.ts +882 -0
  628. package/test/session/message-v2.test.ts +957 -0
  629. package/test/session/messages-pagination.test.ts +115 -0
  630. package/test/session/processor-effect.test.ts +838 -0
  631. package/test/session/prompt.test.ts +518 -0
  632. package/test/session/retry.test.ts +232 -0
  633. package/test/session/revert-compact.test.ts +286 -0
  634. package/test/session/session.test.ts +142 -0
  635. package/test/session/structured-output-integration.test.ts +233 -0
  636. package/test/session/structured-output.test.ts +391 -0
  637. package/test/session/system.test.ts +59 -0
  638. package/test/share/share-next.test.ts +76 -0
  639. package/test/skill/discovery.test.ts +116 -0
  640. package/test/skill/skill.test.ts +392 -0
  641. package/test/snapshot/snapshot.test.ts +1235 -0
  642. package/test/storage/db.test.ts +14 -0
  643. package/test/storage/json-migration.test.ts +849 -0
  644. package/test/sync/index.test.ts +191 -0
  645. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  646. package/test/tool/apply_patch.test.ts +567 -0
  647. package/test/tool/bash.test.ts +403 -0
  648. package/test/tool/edit.test.ts +681 -0
  649. package/test/tool/external-directory.test.ts +128 -0
  650. package/test/tool/fixtures/large-image.png +0 -0
  651. package/test/tool/fixtures/models-api.json +38413 -0
  652. package/test/tool/grep.test.ts +111 -0
  653. package/test/tool/question.test.ts +108 -0
  654. package/test/tool/read.test.ts +509 -0
  655. package/test/tool/registry.test.ts +126 -0
  656. package/test/tool/skill.test.ts +167 -0
  657. package/test/tool/task.test.ts +49 -0
  658. package/test/tool/truncation.test.ts +161 -0
  659. package/test/tool/webfetch.test.ts +101 -0
  660. package/test/tool/write.test.ts +353 -0
  661. package/test/util/data-url.test.ts +14 -0
  662. package/test/util/effect-zod.test.ts +61 -0
  663. package/test/util/error.test.ts +38 -0
  664. package/test/util/filesystem.test.ts +558 -0
  665. package/test/util/flock.test.ts +383 -0
  666. package/test/util/format.test.ts +59 -0
  667. package/test/util/glob.test.ts +164 -0
  668. package/test/util/iife.test.ts +36 -0
  669. package/test/util/lazy.test.ts +50 -0
  670. package/test/util/lock.test.ts +72 -0
  671. package/test/util/module.test.ts +59 -0
  672. package/test/util/process.test.ts +128 -0
  673. package/test/util/timeout.test.ts +21 -0
  674. package/test/util/which.test.ts +100 -0
  675. package/test/util/wildcard.test.ts +90 -0
  676. package/tsconfig.json +23 -0
@@ -0,0 +1,2758 @@
1
+ import { describe, expect, test } from "bun:test"
2
+ import { ProviderTransform } from "../../src/provider/transform"
3
+ import { ModelID, ProviderID } from "../../src/provider/schema"
4
+
5
+ const OUTPUT_TOKEN_MAX = 32000
6
+
7
+ describe("ProviderTransform.options - setCacheKey", () => {
8
+ const sessionID = "test-session-123"
9
+
10
+ const mockModel = {
11
+ id: "anthropic/claude-3-5-sonnet",
12
+ providerID: "anthropic",
13
+ api: {
14
+ id: "claude-3-5-sonnet-20241022",
15
+ url: "https://api.anthropic.com",
16
+ npm: "@ai-sdk/anthropic",
17
+ },
18
+ name: "Claude 3.5 Sonnet",
19
+ capabilities: {
20
+ temperature: true,
21
+ reasoning: false,
22
+ attachment: true,
23
+ toolcall: true,
24
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
25
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
26
+ interleaved: false,
27
+ },
28
+ cost: {
29
+ input: 0.003,
30
+ output: 0.015,
31
+ cache: { read: 0.0003, write: 0.00375 },
32
+ },
33
+ limit: {
34
+ context: 200000,
35
+ output: 8192,
36
+ },
37
+ status: "active",
38
+ options: {},
39
+ headers: {},
40
+ } as any
41
+
42
+ test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
43
+ const result = ProviderTransform.options({
44
+ model: mockModel,
45
+ sessionID,
46
+ providerOptions: { setCacheKey: true },
47
+ })
48
+ expect(result.promptCacheKey).toBe(sessionID)
49
+ })
50
+
51
+ test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
52
+ const result = ProviderTransform.options({
53
+ model: mockModel,
54
+ sessionID,
55
+ providerOptions: { setCacheKey: false },
56
+ })
57
+ expect(result.promptCacheKey).toBeUndefined()
58
+ })
59
+
60
+ test("should not set promptCacheKey when providerOptions is undefined", () => {
61
+ const result = ProviderTransform.options({
62
+ model: mockModel,
63
+ sessionID,
64
+ providerOptions: undefined,
65
+ })
66
+ expect(result.promptCacheKey).toBeUndefined()
67
+ })
68
+
69
+ test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
70
+ const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
71
+ expect(result.promptCacheKey).toBeUndefined()
72
+ })
73
+
74
+ test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
75
+ const openaiModel = {
76
+ ...mockModel,
77
+ providerID: "openai",
78
+ api: {
79
+ id: "gpt-4",
80
+ url: "https://api.openai.com",
81
+ npm: "@ai-sdk/openai",
82
+ },
83
+ }
84
+ const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
85
+ expect(result.promptCacheKey).toBe(sessionID)
86
+ })
87
+
88
+ test("should set store=false for openai provider", () => {
89
+ const openaiModel = {
90
+ ...mockModel,
91
+ providerID: "openai",
92
+ api: {
93
+ id: "gpt-4",
94
+ url: "https://api.openai.com",
95
+ npm: "@ai-sdk/openai",
96
+ },
97
+ }
98
+ const result = ProviderTransform.options({
99
+ model: openaiModel,
100
+ sessionID,
101
+ providerOptions: {},
102
+ })
103
+ expect(result.store).toBe(false)
104
+ })
105
+ })
106
+
107
+ describe("ProviderTransform.options - google thinkingConfig gating", () => {
108
+ const sessionID = "test-session-123"
109
+
110
+ const createGoogleModel = (reasoning: boolean, npm: "@ai-sdk/google" | "@ai-sdk/google-vertex") =>
111
+ ({
112
+ id: `${npm === "@ai-sdk/google" ? "google" : "google-vertex"}/gemini-2.0-flash`,
113
+ providerID: npm === "@ai-sdk/google" ? "google" : "google-vertex",
114
+ api: {
115
+ id: "gemini-2.0-flash",
116
+ url: npm === "@ai-sdk/google" ? "https://generativelanguage.googleapis.com" : "https://vertexai.googleapis.com",
117
+ npm,
118
+ },
119
+ name: "Gemini 2.0 Flash",
120
+ capabilities: {
121
+ temperature: true,
122
+ reasoning,
123
+ attachment: true,
124
+ toolcall: true,
125
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
126
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
127
+ interleaved: false,
128
+ },
129
+ cost: {
130
+ input: 0.001,
131
+ output: 0.002,
132
+ cache: { read: 0.0001, write: 0.0002 },
133
+ },
134
+ limit: {
135
+ context: 1_000_000,
136
+ output: 8192,
137
+ },
138
+ status: "active",
139
+ options: {},
140
+ headers: {},
141
+ }) as any
142
+
143
+ test("does not set thinkingConfig for google models without reasoning capability", () => {
144
+ const result = ProviderTransform.options({
145
+ model: createGoogleModel(false, "@ai-sdk/google"),
146
+ sessionID,
147
+ providerOptions: {},
148
+ })
149
+ expect(result.thinkingConfig).toBeUndefined()
150
+ })
151
+
152
+ test("sets thinkingConfig for google models with reasoning capability", () => {
153
+ const result = ProviderTransform.options({
154
+ model: createGoogleModel(true, "@ai-sdk/google"),
155
+ sessionID,
156
+ providerOptions: {},
157
+ })
158
+ expect(result.thinkingConfig).toEqual({
159
+ includeThoughts: true,
160
+ })
161
+ })
162
+
163
+ test("does not set thinkingConfig for vertex models without reasoning capability", () => {
164
+ const result = ProviderTransform.options({
165
+ model: createGoogleModel(false, "@ai-sdk/google-vertex"),
166
+ sessionID,
167
+ providerOptions: {},
168
+ })
169
+ expect(result.thinkingConfig).toBeUndefined()
170
+ })
171
+ })
172
+
173
+ describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
174
+ const sessionID = "test-session-123"
175
+
176
+ const createGpt5Model = (apiId: string) =>
177
+ ({
178
+ id: `openai/${apiId}`,
179
+ providerID: "openai",
180
+ api: {
181
+ id: apiId,
182
+ url: "https://api.openai.com",
183
+ npm: "@ai-sdk/openai",
184
+ },
185
+ name: apiId,
186
+ capabilities: {
187
+ temperature: true,
188
+ reasoning: true,
189
+ attachment: true,
190
+ toolcall: true,
191
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
192
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
193
+ interleaved: false,
194
+ },
195
+ cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
196
+ limit: { context: 128000, output: 4096 },
197
+ status: "active",
198
+ options: {},
199
+ headers: {},
200
+ }) as any
201
+
202
+ test("gpt-5.2 should have textVerbosity set to low", () => {
203
+ const model = createGpt5Model("gpt-5.2")
204
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
205
+ expect(result.textVerbosity).toBe("low")
206
+ })
207
+
208
+ test("gpt-5.1 should have textVerbosity set to low", () => {
209
+ const model = createGpt5Model("gpt-5.1")
210
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
211
+ expect(result.textVerbosity).toBe("low")
212
+ })
213
+
214
+ test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
215
+ const model = createGpt5Model("gpt-5.2-chat-latest")
216
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
217
+ expect(result.textVerbosity).toBeUndefined()
218
+ })
219
+
220
+ test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
221
+ const model = createGpt5Model("gpt-5.1-chat-latest")
222
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
223
+ expect(result.textVerbosity).toBeUndefined()
224
+ })
225
+
226
+ test("gpt-5.2-chat should NOT have textVerbosity set", () => {
227
+ const model = createGpt5Model("gpt-5.2-chat")
228
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
229
+ expect(result.textVerbosity).toBeUndefined()
230
+ })
231
+
232
+ test("gpt-5-chat should NOT have textVerbosity set", () => {
233
+ const model = createGpt5Model("gpt-5-chat")
234
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
235
+ expect(result.textVerbosity).toBeUndefined()
236
+ })
237
+
238
+ test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
239
+ const model = createGpt5Model("gpt-5.2-codex")
240
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
241
+ expect(result.textVerbosity).toBeUndefined()
242
+ })
243
+ })
244
+
245
+ describe("ProviderTransform.options - gateway", () => {
246
+ const sessionID = "test-session-123"
247
+
248
+ const createModel = (id: string) =>
249
+ ({
250
+ id,
251
+ providerID: "vercel",
252
+ api: {
253
+ id,
254
+ url: "https://ai-gateway.vercel.sh/v3/ai",
255
+ npm: "@ai-sdk/gateway",
256
+ },
257
+ name: id,
258
+ capabilities: {
259
+ temperature: true,
260
+ reasoning: true,
261
+ attachment: true,
262
+ toolcall: true,
263
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
264
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
265
+ interleaved: false,
266
+ },
267
+ cost: {
268
+ input: 0.001,
269
+ output: 0.002,
270
+ cache: { read: 0.0001, write: 0.0002 },
271
+ },
272
+ limit: {
273
+ context: 200_000,
274
+ output: 8192,
275
+ },
276
+ status: "active",
277
+ options: {},
278
+ headers: {},
279
+ release_date: "2024-01-01",
280
+ }) as any
281
+
282
+ test("puts gateway defaults under gateway key", () => {
283
+ const model = createModel("anthropic/claude-sonnet-4")
284
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
285
+ expect(result).toEqual({
286
+ gateway: {
287
+ caching: "auto",
288
+ },
289
+ })
290
+ })
291
+ })
292
+
293
+ describe("ProviderTransform.providerOptions", () => {
294
+ const createModel = (overrides: Partial<any> = {}) =>
295
+ ({
296
+ id: "test/test-model",
297
+ providerID: "test",
298
+ api: {
299
+ id: "test-model",
300
+ url: "https://api.test.com",
301
+ npm: "@ai-sdk/openai",
302
+ },
303
+ name: "Test Model",
304
+ capabilities: {
305
+ temperature: true,
306
+ reasoning: true,
307
+ attachment: true,
308
+ toolcall: true,
309
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
310
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
311
+ interleaved: false,
312
+ },
313
+ cost: {
314
+ input: 0.001,
315
+ output: 0.002,
316
+ cache: { read: 0.0001, write: 0.0002 },
317
+ },
318
+ limit: {
319
+ context: 200_000,
320
+ output: 64_000,
321
+ },
322
+ status: "active",
323
+ options: {},
324
+ headers: {},
325
+ release_date: "2024-01-01",
326
+ ...overrides,
327
+ }) as any
328
+
329
+ test("uses sdk key for non-gateway models", () => {
330
+ const model = createModel({
331
+ providerID: "my-bedrock",
332
+ api: {
333
+ id: "anthropic.claude-sonnet-4",
334
+ url: "https://bedrock.aws",
335
+ npm: "@ai-sdk/amazon-bedrock",
336
+ },
337
+ })
338
+
339
+ expect(ProviderTransform.providerOptions(model, { cachePoint: { type: "default" } })).toEqual({
340
+ bedrock: { cachePoint: { type: "default" } },
341
+ })
342
+ })
343
+
344
+ test("uses gateway model provider slug for gateway models", () => {
345
+ const model = createModel({
346
+ providerID: "vercel",
347
+ api: {
348
+ id: "anthropic/claude-sonnet-4",
349
+ url: "https://ai-gateway.vercel.sh/v3/ai",
350
+ npm: "@ai-sdk/gateway",
351
+ },
352
+ })
353
+
354
+ expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
355
+ anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
356
+ })
357
+ })
358
+
359
+ test("falls back to gateway key when gateway api id is unscoped", () => {
360
+ const model = createModel({
361
+ id: "anthropic/claude-sonnet-4",
362
+ providerID: "vercel",
363
+ api: {
364
+ id: "claude-sonnet-4",
365
+ url: "https://ai-gateway.vercel.sh/v3/ai",
366
+ npm: "@ai-sdk/gateway",
367
+ },
368
+ })
369
+
370
+ expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
371
+ gateway: { thinking: { type: "enabled", budgetTokens: 12_000 } },
372
+ })
373
+ })
374
+
375
+ test("splits gateway routing options from provider-specific options", () => {
376
+ const model = createModel({
377
+ providerID: "vercel",
378
+ api: {
379
+ id: "anthropic/claude-sonnet-4",
380
+ url: "https://ai-gateway.vercel.sh/v3/ai",
381
+ npm: "@ai-sdk/gateway",
382
+ },
383
+ })
384
+
385
+ expect(
386
+ ProviderTransform.providerOptions(model, {
387
+ gateway: { order: ["vertex", "anthropic"] },
388
+ thinking: { type: "enabled", budgetTokens: 12_000 },
389
+ }),
390
+ ).toEqual({
391
+ gateway: { order: ["vertex", "anthropic"] },
392
+ anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
393
+ } as any)
394
+ })
395
+
396
+ test("falls back to gateway key when model id has no provider slug", () => {
397
+ const model = createModel({
398
+ id: "claude-sonnet-4",
399
+ providerID: "vercel",
400
+ api: {
401
+ id: "claude-sonnet-4",
402
+ url: "https://ai-gateway.vercel.sh/v3/ai",
403
+ npm: "@ai-sdk/gateway",
404
+ },
405
+ })
406
+
407
+ expect(ProviderTransform.providerOptions(model, { reasoningEffort: "high" })).toEqual({
408
+ gateway: { reasoningEffort: "high" },
409
+ })
410
+ })
411
+
412
+ test("maps amazon slug to bedrock for provider options", () => {
413
+ const model = createModel({
414
+ providerID: "vercel",
415
+ api: {
416
+ id: "amazon/nova-2-lite",
417
+ url: "https://ai-gateway.vercel.sh/v3/ai",
418
+ npm: "@ai-sdk/gateway",
419
+ },
420
+ })
421
+
422
+ expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({
423
+ bedrock: { reasoningConfig: { type: "enabled" } },
424
+ })
425
+ })
426
+
427
+ test("uses groq slug for groq models", () => {
428
+ const model = createModel({
429
+ providerID: "vercel",
430
+ api: {
431
+ id: "groq/llama-3.3-70b-versatile",
432
+ url: "https://ai-gateway.vercel.sh/v3/ai",
433
+ npm: "@ai-sdk/gateway",
434
+ },
435
+ })
436
+
437
+ expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({
438
+ groq: { reasoningFormat: "parsed" },
439
+ })
440
+ })
441
+ })
442
+
443
+ describe("ProviderTransform.schema - gemini array items", () => {
444
+ test("adds missing items for array properties", () => {
445
+ const geminiModel = {
446
+ providerID: "google",
447
+ api: {
448
+ id: "gemini-3-pro",
449
+ },
450
+ } as any
451
+
452
+ const schema = {
453
+ type: "object",
454
+ properties: {
455
+ nodes: { type: "array" },
456
+ edges: { type: "array", items: { type: "string" } },
457
+ },
458
+ } as any
459
+
460
+ const result = ProviderTransform.schema(geminiModel, schema) as any
461
+
462
+ expect(result.properties.nodes.items).toBeDefined()
463
+ expect(result.properties.edges.items.type).toBe("string")
464
+ })
465
+ })
466
+
467
+ describe("ProviderTransform.schema - gemini nested array items", () => {
468
+ const geminiModel = {
469
+ providerID: "google",
470
+ api: {
471
+ id: "gemini-3-pro",
472
+ },
473
+ } as any
474
+
475
+ test("adds type to 2D array with empty inner items", () => {
476
+ const schema = {
477
+ type: "object",
478
+ properties: {
479
+ values: {
480
+ type: "array",
481
+ items: {
482
+ type: "array",
483
+ items: {}, // Empty items object
484
+ },
485
+ },
486
+ },
487
+ } as any
488
+
489
+ const result = ProviderTransform.schema(geminiModel, schema) as any
490
+
491
+ // Inner items should have a default type
492
+ expect(result.properties.values.items.items.type).toBe("string")
493
+ })
494
+
495
+ test("adds items and type to 2D array with missing inner items", () => {
496
+ const schema = {
497
+ type: "object",
498
+ properties: {
499
+ data: {
500
+ type: "array",
501
+ items: { type: "array" }, // No items at all
502
+ },
503
+ },
504
+ } as any
505
+
506
+ const result = ProviderTransform.schema(geminiModel, schema) as any
507
+
508
+ expect(result.properties.data.items.items).toBeDefined()
509
+ expect(result.properties.data.items.items.type).toBe("string")
510
+ })
511
+
512
+ test("handles deeply nested arrays (3D)", () => {
513
+ const schema = {
514
+ type: "object",
515
+ properties: {
516
+ matrix: {
517
+ type: "array",
518
+ items: {
519
+ type: "array",
520
+ items: {
521
+ type: "array",
522
+ // No items
523
+ },
524
+ },
525
+ },
526
+ },
527
+ } as any
528
+
529
+ const result = ProviderTransform.schema(geminiModel, schema) as any
530
+
531
+ expect(result.properties.matrix.items.items.items).toBeDefined()
532
+ expect(result.properties.matrix.items.items.items.type).toBe("string")
533
+ })
534
+
535
+ test("preserves existing item types in nested arrays", () => {
536
+ const schema = {
537
+ type: "object",
538
+ properties: {
539
+ numbers: {
540
+ type: "array",
541
+ items: {
542
+ type: "array",
543
+ items: { type: "number" }, // Has explicit type
544
+ },
545
+ },
546
+ },
547
+ } as any
548
+
549
+ const result = ProviderTransform.schema(geminiModel, schema) as any
550
+
551
+ // Should preserve the explicit type
552
+ expect(result.properties.numbers.items.items.type).toBe("number")
553
+ })
554
+
555
+ test("handles mixed nested structures with objects and arrays", () => {
556
+ const schema = {
557
+ type: "object",
558
+ properties: {
559
+ spreadsheetData: {
560
+ type: "object",
561
+ properties: {
562
+ rows: {
563
+ type: "array",
564
+ items: {
565
+ type: "array",
566
+ items: {}, // Empty items
567
+ },
568
+ },
569
+ },
570
+ },
571
+ },
572
+ } as any
573
+
574
+ const result = ProviderTransform.schema(geminiModel, schema) as any
575
+
576
+ expect(result.properties.spreadsheetData.properties.rows.items.items.type).toBe("string")
577
+ })
578
+ })
579
+
580
+ describe("ProviderTransform.schema - gemini combiner nodes", () => {
581
+ const geminiModel = {
582
+ providerID: "google",
583
+ api: {
584
+ id: "gemini-3-pro",
585
+ },
586
+ } as any
587
+
588
+ const walk = (node: any, cb: (node: any, path: (string | number)[]) => void, path: (string | number)[] = []) => {
589
+ if (node === null || typeof node !== "object") {
590
+ return
591
+ }
592
+ if (Array.isArray(node)) {
593
+ node.forEach((item, i) => walk(item, cb, [...path, i]))
594
+ return
595
+ }
596
+ cb(node, path)
597
+ Object.entries(node).forEach(([key, value]) => walk(value, cb, [...path, key]))
598
+ }
599
+
600
+ test("keeps edits.items.anyOf without adding type", () => {
601
+ const schema = {
602
+ type: "object",
603
+ properties: {
604
+ edits: {
605
+ type: "array",
606
+ items: {
607
+ anyOf: [
608
+ {
609
+ type: "object",
610
+ properties: {
611
+ old_string: { type: "string" },
612
+ new_string: { type: "string" },
613
+ },
614
+ required: ["old_string", "new_string"],
615
+ },
616
+ {
617
+ type: "object",
618
+ properties: {
619
+ old_string: { type: "string" },
620
+ new_string: { type: "string" },
621
+ replace_all: { type: "boolean" },
622
+ },
623
+ required: ["old_string", "new_string"],
624
+ },
625
+ ],
626
+ },
627
+ },
628
+ },
629
+ required: ["edits"],
630
+ } as any
631
+
632
+ const result = ProviderTransform.schema(geminiModel, schema) as any
633
+
634
+ expect(Array.isArray(result.properties.edits.items.anyOf)).toBe(true)
635
+ expect(result.properties.edits.items.type).toBeUndefined()
636
+ })
637
+
638
+ test("does not add sibling keys to combiner nodes during sanitize", () => {
639
+ const schema = {
640
+ type: "object",
641
+ properties: {
642
+ edits: {
643
+ type: "array",
644
+ items: {
645
+ anyOf: [{ type: "string" }, { type: "number" }],
646
+ },
647
+ },
648
+ value: {
649
+ oneOf: [{ type: "string" }, { type: "boolean" }],
650
+ },
651
+ meta: {
652
+ allOf: [
653
+ {
654
+ type: "object",
655
+ properties: { a: { type: "string" } },
656
+ },
657
+ {
658
+ type: "object",
659
+ properties: { b: { type: "string" } },
660
+ },
661
+ ],
662
+ },
663
+ },
664
+ } as any
665
+ const input = JSON.parse(JSON.stringify(schema))
666
+ const result = ProviderTransform.schema(geminiModel, schema) as any
667
+
668
+ walk(result, (node, path) => {
669
+ const hasCombiner = Array.isArray(node.anyOf) || Array.isArray(node.oneOf) || Array.isArray(node.allOf)
670
+ if (!hasCombiner) {
671
+ return
672
+ }
673
+ const before = path.reduce((acc: any, key) => acc?.[key], input)
674
+ const added = Object.keys(node).filter((key) => !(key in before))
675
+ expect(added).toEqual([])
676
+ })
677
+ })
678
+ })
679
+
680
+ describe("ProviderTransform.schema - gemini non-object properties removal", () => {
681
+ const geminiModel = {
682
+ providerID: "google",
683
+ api: {
684
+ id: "gemini-3-pro",
685
+ },
686
+ } as any
687
+
688
+ test("removes properties from non-object types", () => {
689
+ const schema = {
690
+ type: "object",
691
+ properties: {
692
+ data: {
693
+ type: "string",
694
+ properties: { invalid: { type: "string" } },
695
+ },
696
+ },
697
+ } as any
698
+
699
+ const result = ProviderTransform.schema(geminiModel, schema) as any
700
+
701
+ expect(result.properties.data.type).toBe("string")
702
+ expect(result.properties.data.properties).toBeUndefined()
703
+ })
704
+
705
+ test("removes required from non-object types", () => {
706
+ const schema = {
707
+ type: "object",
708
+ properties: {
709
+ data: {
710
+ type: "array",
711
+ items: { type: "string" },
712
+ required: ["invalid"],
713
+ },
714
+ },
715
+ } as any
716
+
717
+ const result = ProviderTransform.schema(geminiModel, schema) as any
718
+
719
+ expect(result.properties.data.type).toBe("array")
720
+ expect(result.properties.data.required).toBeUndefined()
721
+ })
722
+
723
+ test("removes properties and required from nested non-object types", () => {
724
+ const schema = {
725
+ type: "object",
726
+ properties: {
727
+ outer: {
728
+ type: "object",
729
+ properties: {
730
+ inner: {
731
+ type: "number",
732
+ properties: { bad: { type: "string" } },
733
+ required: ["bad"],
734
+ },
735
+ },
736
+ },
737
+ },
738
+ } as any
739
+
740
+ const result = ProviderTransform.schema(geminiModel, schema) as any
741
+
742
+ expect(result.properties.outer.properties.inner.type).toBe("number")
743
+ expect(result.properties.outer.properties.inner.properties).toBeUndefined()
744
+ expect(result.properties.outer.properties.inner.required).toBeUndefined()
745
+ })
746
+
747
+ test("keeps properties and required on object types", () => {
748
+ const schema = {
749
+ type: "object",
750
+ properties: {
751
+ data: {
752
+ type: "object",
753
+ properties: { name: { type: "string" } },
754
+ required: ["name"],
755
+ },
756
+ },
757
+ } as any
758
+
759
+ const result = ProviderTransform.schema(geminiModel, schema) as any
760
+
761
+ expect(result.properties.data.type).toBe("object")
762
+ expect(result.properties.data.properties).toBeDefined()
763
+ expect(result.properties.data.required).toEqual(["name"])
764
+ })
765
+
766
+ test("does not affect non-gemini providers", () => {
767
+ const openaiModel = {
768
+ providerID: "openai",
769
+ api: {
770
+ id: "gpt-4",
771
+ },
772
+ } as any
773
+
774
+ const schema = {
775
+ type: "object",
776
+ properties: {
777
+ data: {
778
+ type: "string",
779
+ properties: { invalid: { type: "string" } },
780
+ },
781
+ },
782
+ } as any
783
+
784
+ const result = ProviderTransform.schema(openaiModel, schema) as any
785
+
786
+ expect(result.properties.data.properties).toBeDefined()
787
+ })
788
+ })
789
+
790
+ describe("ProviderTransform.message - DeepSeek reasoning content", () => {
791
+ test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
792
+ const msgs = [
793
+ {
794
+ role: "assistant",
795
+ content: [
796
+ { type: "reasoning", text: "Let me think about this..." },
797
+ {
798
+ type: "tool-call",
799
+ toolCallId: "test",
800
+ toolName: "bash",
801
+ input: { command: "echo hello" },
802
+ },
803
+ ],
804
+ },
805
+ ] as any[]
806
+
807
+ const result = ProviderTransform.message(
808
+ msgs,
809
+ {
810
+ id: ModelID.make("deepseek/deepseek-chat"),
811
+ providerID: ProviderID.make("deepseek"),
812
+ api: {
813
+ id: "deepseek-chat",
814
+ url: "https://api.deepseek.com",
815
+ npm: "@ai-sdk/openai-compatible",
816
+ },
817
+ name: "DeepSeek Chat",
818
+ capabilities: {
819
+ temperature: true,
820
+ reasoning: true,
821
+ attachment: false,
822
+ toolcall: true,
823
+ input: { text: true, audio: false, image: false, video: false, pdf: false },
824
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
825
+ interleaved: {
826
+ field: "reasoning_content",
827
+ },
828
+ },
829
+ cost: {
830
+ input: 0.001,
831
+ output: 0.002,
832
+ cache: { read: 0.0001, write: 0.0002 },
833
+ },
834
+ limit: {
835
+ context: 128000,
836
+ output: 8192,
837
+ },
838
+ status: "active",
839
+ options: {},
840
+ headers: {},
841
+ release_date: "2023-04-01",
842
+ },
843
+ {},
844
+ )
845
+
846
+ expect(result).toHaveLength(1)
847
+ expect(result[0].content).toEqual([
848
+ {
849
+ type: "tool-call",
850
+ toolCallId: "test",
851
+ toolName: "bash",
852
+ input: { command: "echo hello" },
853
+ },
854
+ ])
855
+ expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
856
+ })
857
+
858
+ test("Non-DeepSeek providers leave reasoning content unchanged", () => {
859
+ const msgs = [
860
+ {
861
+ role: "assistant",
862
+ content: [
863
+ { type: "reasoning", text: "Should not be processed" },
864
+ { type: "text", text: "Answer" },
865
+ ],
866
+ },
867
+ ] as any[]
868
+
869
+ const result = ProviderTransform.message(
870
+ msgs,
871
+ {
872
+ id: ModelID.make("openai/gpt-4"),
873
+ providerID: ProviderID.make("openai"),
874
+ api: {
875
+ id: "gpt-4",
876
+ url: "https://api.openai.com",
877
+ npm: "@ai-sdk/openai",
878
+ },
879
+ name: "GPT-4",
880
+ capabilities: {
881
+ temperature: true,
882
+ reasoning: false,
883
+ attachment: true,
884
+ toolcall: true,
885
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
886
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
887
+ interleaved: false,
888
+ },
889
+ cost: {
890
+ input: 0.03,
891
+ output: 0.06,
892
+ cache: { read: 0.001, write: 0.002 },
893
+ },
894
+ limit: {
895
+ context: 128000,
896
+ output: 4096,
897
+ },
898
+ status: "active",
899
+ options: {},
900
+ headers: {},
901
+ release_date: "2023-04-01",
902
+ },
903
+ {},
904
+ )
905
+
906
+ expect(result[0].content).toEqual([
907
+ { type: "reasoning", text: "Should not be processed" },
908
+ { type: "text", text: "Answer" },
909
+ ])
910
+ expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
911
+ })
912
+ })
913
+
914
+ describe("ProviderTransform.message - empty image handling", () => {
915
+ const mockModel = {
916
+ id: "anthropic/claude-3-5-sonnet",
917
+ providerID: "anthropic",
918
+ api: {
919
+ id: "claude-3-5-sonnet-20241022",
920
+ url: "https://api.anthropic.com",
921
+ npm: "@ai-sdk/anthropic",
922
+ },
923
+ name: "Claude 3.5 Sonnet",
924
+ capabilities: {
925
+ temperature: true,
926
+ reasoning: false,
927
+ attachment: true,
928
+ toolcall: true,
929
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
930
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
931
+ interleaved: false,
932
+ },
933
+ cost: {
934
+ input: 0.003,
935
+ output: 0.015,
936
+ cache: { read: 0.0003, write: 0.00375 },
937
+ },
938
+ limit: {
939
+ context: 200000,
940
+ output: 8192,
941
+ },
942
+ status: "active",
943
+ options: {},
944
+ headers: {},
945
+ } as any
946
+
947
+ test("should replace empty base64 image with error text", () => {
948
+ const msgs = [
949
+ {
950
+ role: "user",
951
+ content: [
952
+ { type: "text", text: "What is in this image?" },
953
+ { type: "image", image: "data:image/png;base64," },
954
+ ],
955
+ },
956
+ ] as any[]
957
+
958
+ const result = ProviderTransform.message(msgs, mockModel, {})
959
+
960
+ expect(result).toHaveLength(1)
961
+ expect(result[0].content).toHaveLength(2)
962
+ expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
963
+ expect(result[0].content[1]).toEqual({
964
+ type: "text",
965
+ text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
966
+ })
967
+ })
968
+
969
+ test("should keep valid base64 images unchanged", () => {
970
+ const validBase64 =
971
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
972
+ const msgs = [
973
+ {
974
+ role: "user",
975
+ content: [
976
+ { type: "text", text: "What is in this image?" },
977
+ { type: "image", image: `data:image/png;base64,${validBase64}` },
978
+ ],
979
+ },
980
+ ] as any[]
981
+
982
+ const result = ProviderTransform.message(msgs, mockModel, {})
983
+
984
+ expect(result).toHaveLength(1)
985
+ expect(result[0].content).toHaveLength(2)
986
+ expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
987
+ expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
988
+ })
989
+
990
+ test("should handle mixed valid and empty images", () => {
991
+ const validBase64 =
992
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
993
+ const msgs = [
994
+ {
995
+ role: "user",
996
+ content: [
997
+ { type: "text", text: "Compare these images" },
998
+ { type: "image", image: `data:image/png;base64,${validBase64}` },
999
+ { type: "image", image: "data:image/jpeg;base64," },
1000
+ ],
1001
+ },
1002
+ ] as any[]
1003
+
1004
+ const result = ProviderTransform.message(msgs, mockModel, {})
1005
+
1006
+ expect(result).toHaveLength(1)
1007
+ expect(result[0].content).toHaveLength(3)
1008
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
1009
+ expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
1010
+ expect(result[0].content[2]).toEqual({
1011
+ type: "text",
1012
+ text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
1013
+ })
1014
+ })
1015
+ })
1016
+
1017
+ describe("ProviderTransform.message - anthropic empty content filtering", () => {
1018
+ const anthropicModel = {
1019
+ id: "anthropic/claude-3-5-sonnet",
1020
+ providerID: "anthropic",
1021
+ api: {
1022
+ id: "claude-3-5-sonnet-20241022",
1023
+ url: "https://api.anthropic.com",
1024
+ npm: "@ai-sdk/anthropic",
1025
+ },
1026
+ name: "Claude 3.5 Sonnet",
1027
+ capabilities: {
1028
+ temperature: true,
1029
+ reasoning: false,
1030
+ attachment: true,
1031
+ toolcall: true,
1032
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
1033
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1034
+ interleaved: false,
1035
+ },
1036
+ cost: {
1037
+ input: 0.003,
1038
+ output: 0.015,
1039
+ cache: { read: 0.0003, write: 0.00375 },
1040
+ },
1041
+ limit: {
1042
+ context: 200000,
1043
+ output: 8192,
1044
+ },
1045
+ status: "active",
1046
+ options: {},
1047
+ headers: {},
1048
+ } as any
1049
+
1050
+ test("filters out messages with empty string content", () => {
1051
+ const msgs = [
1052
+ { role: "user", content: "Hello" },
1053
+ { role: "assistant", content: "" },
1054
+ { role: "user", content: "World" },
1055
+ ] as any[]
1056
+
1057
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1058
+
1059
+ expect(result).toHaveLength(2)
1060
+ expect(result[0].content).toBe("Hello")
1061
+ expect(result[1].content).toBe("World")
1062
+ })
1063
+
1064
+ test("filters out empty text parts from array content", () => {
1065
+ const msgs = [
1066
+ {
1067
+ role: "assistant",
1068
+ content: [
1069
+ { type: "text", text: "" },
1070
+ { type: "text", text: "Hello" },
1071
+ { type: "text", text: "" },
1072
+ ],
1073
+ },
1074
+ ] as any[]
1075
+
1076
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1077
+
1078
+ expect(result).toHaveLength(1)
1079
+ expect(result[0].content).toHaveLength(1)
1080
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
1081
+ })
1082
+
1083
+ test("filters out empty reasoning parts from array content", () => {
1084
+ const msgs = [
1085
+ {
1086
+ role: "assistant",
1087
+ content: [
1088
+ { type: "reasoning", text: "" },
1089
+ { type: "text", text: "Answer" },
1090
+ { type: "reasoning", text: "" },
1091
+ ],
1092
+ },
1093
+ ] as any[]
1094
+
1095
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1096
+
1097
+ expect(result).toHaveLength(1)
1098
+ expect(result[0].content).toHaveLength(1)
1099
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
1100
+ })
1101
+
1102
+ test("removes entire message when all parts are empty", () => {
1103
+ const msgs = [
1104
+ { role: "user", content: "Hello" },
1105
+ {
1106
+ role: "assistant",
1107
+ content: [
1108
+ { type: "text", text: "" },
1109
+ { type: "reasoning", text: "" },
1110
+ ],
1111
+ },
1112
+ { role: "user", content: "World" },
1113
+ ] as any[]
1114
+
1115
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1116
+
1117
+ expect(result).toHaveLength(2)
1118
+ expect(result[0].content).toBe("Hello")
1119
+ expect(result[1].content).toBe("World")
1120
+ })
1121
+
1122
+ test("keeps non-text/reasoning parts even if text parts are empty", () => {
1123
+ const msgs = [
1124
+ {
1125
+ role: "assistant",
1126
+ content: [
1127
+ { type: "text", text: "" },
1128
+ { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
1129
+ ],
1130
+ },
1131
+ ] as any[]
1132
+
1133
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1134
+
1135
+ expect(result).toHaveLength(1)
1136
+ expect(result[0].content).toHaveLength(1)
1137
+ expect(result[0].content[0]).toEqual({
1138
+ type: "tool-call",
1139
+ toolCallId: "123",
1140
+ toolName: "bash",
1141
+ input: { command: "ls" },
1142
+ })
1143
+ })
1144
+
1145
+ test("keeps messages with valid text alongside empty parts", () => {
1146
+ const msgs = [
1147
+ {
1148
+ role: "assistant",
1149
+ content: [
1150
+ { type: "reasoning", text: "Thinking..." },
1151
+ { type: "text", text: "" },
1152
+ { type: "text", text: "Result" },
1153
+ ],
1154
+ },
1155
+ ] as any[]
1156
+
1157
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
1158
+
1159
+ expect(result).toHaveLength(1)
1160
+ expect(result[0].content).toHaveLength(2)
1161
+ expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
1162
+ expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
1163
+ })
1164
+
1165
+ test("filters empty content for bedrock provider", () => {
1166
+ const bedrockModel = {
1167
+ ...anthropicModel,
1168
+ id: "amazon-bedrock/anthropic.claude-opus-4-6",
1169
+ providerID: "amazon-bedrock",
1170
+ api: {
1171
+ id: "anthropic.claude-opus-4-6",
1172
+ url: "https://bedrock-runtime.us-east-1.amazonaws.com",
1173
+ npm: "@ai-sdk/amazon-bedrock",
1174
+ },
1175
+ }
1176
+
1177
+ const msgs = [
1178
+ { role: "user", content: "Hello" },
1179
+ { role: "assistant", content: "" },
1180
+ {
1181
+ role: "assistant",
1182
+ content: [
1183
+ { type: "text", text: "" },
1184
+ { type: "text", text: "Answer" },
1185
+ ],
1186
+ },
1187
+ ] as any[]
1188
+
1189
+ const result = ProviderTransform.message(msgs, bedrockModel, {})
1190
+
1191
+ expect(result).toHaveLength(2)
1192
+ expect(result[0].content).toBe("Hello")
1193
+ expect(result[1].content).toHaveLength(1)
1194
+ expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" })
1195
+ })
1196
+
1197
+ test("does not filter for non-anthropic providers", () => {
1198
+ const openaiModel = {
1199
+ ...anthropicModel,
1200
+ providerID: "openai",
1201
+ api: {
1202
+ id: "gpt-4",
1203
+ url: "https://api.openai.com",
1204
+ npm: "@ai-sdk/openai",
1205
+ },
1206
+ }
1207
+
1208
+ const msgs = [
1209
+ { role: "assistant", content: "" },
1210
+ {
1211
+ role: "assistant",
1212
+ content: [{ type: "text", text: "" }],
1213
+ },
1214
+ ] as any[]
1215
+
1216
+ const result = ProviderTransform.message(msgs, openaiModel, {})
1217
+
1218
+ expect(result).toHaveLength(2)
1219
+ expect(result[0].content).toBe("")
1220
+ expect(result[1].content).toHaveLength(1)
1221
+ })
1222
+ })
1223
+
1224
+ describe("ProviderTransform.message - strip openai metadata when store=false", () => {
1225
+ const openaiModel = {
1226
+ id: "openai/gpt-5",
1227
+ providerID: "openai",
1228
+ api: {
1229
+ id: "gpt-5",
1230
+ url: "https://api.openai.com",
1231
+ npm: "@ai-sdk/openai",
1232
+ },
1233
+ name: "GPT-5",
1234
+ capabilities: {
1235
+ temperature: true,
1236
+ reasoning: true,
1237
+ attachment: true,
1238
+ toolcall: true,
1239
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
1240
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1241
+ interleaved: false,
1242
+ },
1243
+ cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
1244
+ limit: { context: 128000, output: 4096 },
1245
+ status: "active",
1246
+ options: {},
1247
+ headers: {},
1248
+ } as any
1249
+
1250
+ test("preserves itemId and reasoningEncryptedContent when store=false", () => {
1251
+ const msgs = [
1252
+ {
1253
+ role: "assistant",
1254
+ content: [
1255
+ {
1256
+ type: "reasoning",
1257
+ text: "thinking...",
1258
+ providerOptions: {
1259
+ openai: {
1260
+ itemId: "rs_123",
1261
+ reasoningEncryptedContent: "encrypted",
1262
+ },
1263
+ },
1264
+ },
1265
+ {
1266
+ type: "text",
1267
+ text: "Hello",
1268
+ providerOptions: {
1269
+ openai: {
1270
+ itemId: "msg_456",
1271
+ },
1272
+ },
1273
+ },
1274
+ ],
1275
+ },
1276
+ ] as any[]
1277
+
1278
+ const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
1279
+
1280
+ expect(result).toHaveLength(1)
1281
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
1282
+ expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
1283
+ })
1284
+
1285
+ test("preserves itemId and reasoningEncryptedContent when store=false even when not openai", () => {
1286
+ const zenModel = {
1287
+ ...openaiModel,
1288
+ providerID: "zen",
1289
+ }
1290
+ const msgs = [
1291
+ {
1292
+ role: "assistant",
1293
+ content: [
1294
+ {
1295
+ type: "reasoning",
1296
+ text: "thinking...",
1297
+ providerOptions: {
1298
+ openai: {
1299
+ itemId: "rs_123",
1300
+ reasoningEncryptedContent: "encrypted",
1301
+ },
1302
+ },
1303
+ },
1304
+ {
1305
+ type: "text",
1306
+ text: "Hello",
1307
+ providerOptions: {
1308
+ openai: {
1309
+ itemId: "msg_456",
1310
+ },
1311
+ },
1312
+ },
1313
+ ],
1314
+ },
1315
+ ] as any[]
1316
+
1317
+ const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
1318
+
1319
+ expect(result).toHaveLength(1)
1320
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
1321
+ expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
1322
+ })
1323
+
1324
+ test("preserves other openai options including itemId", () => {
1325
+ const msgs = [
1326
+ {
1327
+ role: "assistant",
1328
+ content: [
1329
+ {
1330
+ type: "text",
1331
+ text: "Hello",
1332
+ providerOptions: {
1333
+ openai: {
1334
+ itemId: "msg_123",
1335
+ otherOption: "value",
1336
+ },
1337
+ },
1338
+ },
1339
+ ],
1340
+ },
1341
+ ] as any[]
1342
+
1343
+ const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
1344
+
1345
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1346
+ expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
1347
+ })
1348
+
1349
+ test("preserves metadata for openai package when store is true", () => {
1350
+ const msgs = [
1351
+ {
1352
+ role: "assistant",
1353
+ content: [
1354
+ {
1355
+ type: "text",
1356
+ text: "Hello",
1357
+ providerOptions: {
1358
+ openai: {
1359
+ itemId: "msg_123",
1360
+ },
1361
+ },
1362
+ },
1363
+ ],
1364
+ },
1365
+ ] as any[]
1366
+
1367
+ // openai package preserves itemId regardless of store value
1368
+ const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
1369
+
1370
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1371
+ })
1372
+
1373
+ test("preserves metadata for non-openai packages when store is false", () => {
1374
+ const anthropicModel = {
1375
+ ...openaiModel,
1376
+ providerID: "anthropic",
1377
+ api: {
1378
+ id: "claude-3",
1379
+ url: "https://api.anthropic.com",
1380
+ npm: "@ai-sdk/anthropic",
1381
+ },
1382
+ }
1383
+ const msgs = [
1384
+ {
1385
+ role: "assistant",
1386
+ content: [
1387
+ {
1388
+ type: "text",
1389
+ text: "Hello",
1390
+ providerOptions: {
1391
+ openai: {
1392
+ itemId: "msg_123",
1393
+ },
1394
+ },
1395
+ },
1396
+ ],
1397
+ },
1398
+ ] as any[]
1399
+
1400
+ // store=false preserves metadata for non-openai packages
1401
+ const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
1402
+
1403
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1404
+ })
1405
+
1406
+ test("preserves metadata using providerID key when store is false", () => {
1407
+ const opencodeModel = {
1408
+ ...openaiModel,
1409
+ providerID: "opencode",
1410
+ api: {
1411
+ id: "opencode-test",
1412
+ url: "https://api.opencode.ai",
1413
+ npm: "@ai-sdk/openai-compatible",
1414
+ },
1415
+ }
1416
+ const msgs = [
1417
+ {
1418
+ role: "assistant",
1419
+ content: [
1420
+ {
1421
+ type: "text",
1422
+ text: "Hello",
1423
+ providerOptions: {
1424
+ opencode: {
1425
+ itemId: "msg_123",
1426
+ otherOption: "value",
1427
+ },
1428
+ },
1429
+ },
1430
+ ],
1431
+ },
1432
+ ] as any[]
1433
+
1434
+ const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
1435
+
1436
+ expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
1437
+ expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
1438
+ })
1439
+
1440
+ test("preserves itemId across all providerOptions keys", () => {
1441
+ const opencodeModel = {
1442
+ ...openaiModel,
1443
+ providerID: "opencode",
1444
+ api: {
1445
+ id: "opencode-test",
1446
+ url: "https://api.opencode.ai",
1447
+ npm: "@ai-sdk/openai-compatible",
1448
+ },
1449
+ }
1450
+ const msgs = [
1451
+ {
1452
+ role: "assistant",
1453
+ providerOptions: {
1454
+ openai: { itemId: "msg_root" },
1455
+ opencode: { itemId: "msg_opencode" },
1456
+ extra: { itemId: "msg_extra" },
1457
+ },
1458
+ content: [
1459
+ {
1460
+ type: "text",
1461
+ text: "Hello",
1462
+ providerOptions: {
1463
+ openai: { itemId: "msg_openai_part" },
1464
+ opencode: { itemId: "msg_opencode_part" },
1465
+ extra: { itemId: "msg_extra_part" },
1466
+ },
1467
+ },
1468
+ ],
1469
+ },
1470
+ ] as any[]
1471
+
1472
+ const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
1473
+
1474
+ expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
1475
+ expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
1476
+ expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
1477
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
1478
+ expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
1479
+ expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
1480
+ })
1481
+
1482
+ test("does not strip metadata for non-openai packages when store is not false", () => {
1483
+ const anthropicModel = {
1484
+ ...openaiModel,
1485
+ providerID: "anthropic",
1486
+ api: {
1487
+ id: "claude-3",
1488
+ url: "https://api.anthropic.com",
1489
+ npm: "@ai-sdk/anthropic",
1490
+ },
1491
+ }
1492
+ const msgs = [
1493
+ {
1494
+ role: "assistant",
1495
+ content: [
1496
+ {
1497
+ type: "text",
1498
+ text: "Hello",
1499
+ providerOptions: {
1500
+ openai: {
1501
+ itemId: "msg_123",
1502
+ },
1503
+ },
1504
+ },
1505
+ ],
1506
+ },
1507
+ ] as any[]
1508
+
1509
+ const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
1510
+
1511
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1512
+ })
1513
+ })
1514
+
1515
+ describe("ProviderTransform.message - providerOptions key remapping", () => {
1516
+ const createModel = (providerID: string, npm: string) =>
1517
+ ({
1518
+ id: `${providerID}/test-model`,
1519
+ providerID,
1520
+ api: {
1521
+ id: "test-model",
1522
+ url: "https://api.test.com",
1523
+ npm,
1524
+ },
1525
+ name: "Test Model",
1526
+ capabilities: {
1527
+ temperature: true,
1528
+ reasoning: false,
1529
+ attachment: true,
1530
+ toolcall: true,
1531
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
1532
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1533
+ interleaved: false,
1534
+ },
1535
+ cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
1536
+ limit: { context: 128000, output: 8192 },
1537
+ status: "active",
1538
+ options: {},
1539
+ headers: {},
1540
+ }) as any
1541
+
1542
+ test("azure keeps 'azure' key and does not remap to 'openai'", () => {
1543
+ const model = createModel("azure", "@ai-sdk/azure")
1544
+ const msgs = [
1545
+ {
1546
+ role: "user",
1547
+ content: "Hello",
1548
+ providerOptions: {
1549
+ azure: { someOption: "value" },
1550
+ },
1551
+ },
1552
+ ] as any[]
1553
+
1554
+ const result = ProviderTransform.message(msgs, model, {})
1555
+
1556
+ expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
1557
+ expect(result[0].providerOptions?.openai).toBeUndefined()
1558
+ })
1559
+
1560
+ test("copilot remaps providerID to 'copilot' key", () => {
1561
+ const model = createModel("github-copilot", "@ai-sdk/github-copilot")
1562
+ const msgs = [
1563
+ {
1564
+ role: "user",
1565
+ content: "Hello",
1566
+ providerOptions: {
1567
+ copilot: { someOption: "value" },
1568
+ },
1569
+ },
1570
+ ] as any[]
1571
+
1572
+ const result = ProviderTransform.message(msgs, model, {})
1573
+
1574
+ expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
1575
+ expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
1576
+ })
1577
+
1578
+ test("bedrock remaps providerID to 'bedrock' key", () => {
1579
+ const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
1580
+ const msgs = [
1581
+ {
1582
+ role: "user",
1583
+ content: "Hello",
1584
+ providerOptions: {
1585
+ "my-bedrock": { someOption: "value" },
1586
+ },
1587
+ },
1588
+ ] as any[]
1589
+
1590
+ const result = ProviderTransform.message(msgs, model, {})
1591
+
1592
+ expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
1593
+ expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
1594
+ })
1595
+ })
1596
+
1597
+ describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
1598
+ test("adds cachePoint", () => {
1599
+ const model = {
1600
+ id: "amazon-bedrock/custom-claude-sonnet-4.5",
1601
+ providerID: "amazon-bedrock",
1602
+ api: {
1603
+ id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
1604
+ url: "https://api.test.com",
1605
+ npm: "@ai-sdk/amazon-bedrock",
1606
+ },
1607
+ name: "Custom inference profile",
1608
+ capabilities: {},
1609
+ options: {},
1610
+ headers: {},
1611
+ } as any
1612
+
1613
+ const msgs = [
1614
+ {
1615
+ role: "user",
1616
+ content: "Hello",
1617
+ },
1618
+ ] as any[]
1619
+
1620
+ const result = ProviderTransform.message(msgs, model, {})
1621
+
1622
+ expect(result[0].providerOptions?.bedrock).toEqual(
1623
+ expect.objectContaining({
1624
+ cachePoint: {
1625
+ type: "default",
1626
+ },
1627
+ }),
1628
+ )
1629
+ })
1630
+ })
1631
+
1632
+ describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
1633
+ test("applies cache options at message level when npm package is amazon-bedrock", () => {
1634
+ const model = {
1635
+ id: "aws/us.anthropic.claude-opus-4-6-v1",
1636
+ providerID: "aws",
1637
+ api: {
1638
+ id: "us.anthropic.claude-opus-4-6-v1",
1639
+ url: "https://bedrock-runtime.us-east-1.amazonaws.com",
1640
+ npm: "@ai-sdk/amazon-bedrock",
1641
+ },
1642
+ name: "Claude Opus 4.6",
1643
+ capabilities: {},
1644
+ options: {},
1645
+ headers: {},
1646
+ } as any
1647
+
1648
+ const msgs = [
1649
+ {
1650
+ role: "system",
1651
+ content: [{ type: "text", text: "You are a helpful assistant" }],
1652
+ },
1653
+ {
1654
+ role: "user",
1655
+ content: [{ type: "text", text: "Hello" }],
1656
+ },
1657
+ ] as any[]
1658
+
1659
+ const result = ProviderTransform.message(msgs, model, {}) as any[]
1660
+
1661
+ // Cache should be at the message level and not the content-part level
1662
+ expect(result[0].providerOptions?.bedrock).toEqual({
1663
+ cachePoint: { type: "default" },
1664
+ })
1665
+ expect(result[0].content[0].providerOptions?.bedrock).toBeUndefined()
1666
+ })
1667
+ })
1668
+
1669
+ describe("ProviderTransform.message - cache control on gateway", () => {
1670
+ const createModel = (overrides: Partial<any> = {}) =>
1671
+ ({
1672
+ id: "anthropic/claude-sonnet-4",
1673
+ providerID: "vercel",
1674
+ api: {
1675
+ id: "anthropic/claude-sonnet-4",
1676
+ url: "https://ai-gateway.vercel.sh/v3/ai",
1677
+ npm: "@ai-sdk/gateway",
1678
+ },
1679
+ name: "Claude Sonnet 4",
1680
+ capabilities: {
1681
+ temperature: true,
1682
+ reasoning: true,
1683
+ attachment: true,
1684
+ toolcall: true,
1685
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
1686
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1687
+ interleaved: false,
1688
+ },
1689
+ cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
1690
+ limit: { context: 200_000, output: 8192 },
1691
+ status: "active",
1692
+ options: {},
1693
+ headers: {},
1694
+ ...overrides,
1695
+ }) as any
1696
+
1697
+ test("gateway does not set cache control for anthropic models", () => {
1698
+ const model = createModel()
1699
+ const msgs = [
1700
+ {
1701
+ role: "system",
1702
+ content: [{ type: "text", text: "You are a helpful assistant" }],
1703
+ },
1704
+ {
1705
+ role: "user",
1706
+ content: "Hello",
1707
+ },
1708
+ ] as any[]
1709
+
1710
+ const result = ProviderTransform.message(msgs, model, {}) as any[]
1711
+
1712
+ expect(result[0].content[0].providerOptions).toBeUndefined()
1713
+ expect(result[0].providerOptions).toBeUndefined()
1714
+ })
1715
+
1716
+ test("non-gateway anthropic keeps existing cache control behavior", () => {
1717
+ const model = createModel({
1718
+ providerID: "anthropic",
1719
+ api: {
1720
+ id: "claude-sonnet-4",
1721
+ url: "https://api.anthropic.com",
1722
+ npm: "@ai-sdk/anthropic",
1723
+ },
1724
+ })
1725
+ const msgs = [
1726
+ {
1727
+ role: "system",
1728
+ content: "You are a helpful assistant",
1729
+ },
1730
+ {
1731
+ role: "user",
1732
+ content: "Hello",
1733
+ },
1734
+ ] as any[]
1735
+
1736
+ const result = ProviderTransform.message(msgs, model, {}) as any[]
1737
+
1738
+ expect(result[0].providerOptions).toEqual({
1739
+ anthropic: {
1740
+ cacheControl: {
1741
+ type: "ephemeral",
1742
+ },
1743
+ },
1744
+ openrouter: {
1745
+ cacheControl: {
1746
+ type: "ephemeral",
1747
+ },
1748
+ },
1749
+ bedrock: {
1750
+ cachePoint: {
1751
+ type: "default",
1752
+ },
1753
+ },
1754
+ openaiCompatible: {
1755
+ cache_control: {
1756
+ type: "ephemeral",
1757
+ },
1758
+ },
1759
+ copilot: {
1760
+ copilot_cache_control: {
1761
+ type: "ephemeral",
1762
+ },
1763
+ },
1764
+ })
1765
+ })
1766
+ })
1767
+
1768
+ describe("ProviderTransform.variants", () => {
1769
+ const createMockModel = (overrides: Partial<any> = {}): any => ({
1770
+ id: "test/test-model",
1771
+ providerID: "test",
1772
+ api: {
1773
+ id: "test-model",
1774
+ url: "https://api.test.com",
1775
+ npm: "@ai-sdk/openai",
1776
+ },
1777
+ name: "Test Model",
1778
+ capabilities: {
1779
+ temperature: true,
1780
+ reasoning: true,
1781
+ attachment: true,
1782
+ toolcall: true,
1783
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
1784
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1785
+ interleaved: false,
1786
+ },
1787
+ cost: {
1788
+ input: 0.001,
1789
+ output: 0.002,
1790
+ cache: { read: 0.0001, write: 0.0002 },
1791
+ },
1792
+ limit: {
1793
+ context: 200_000,
1794
+ output: 64_000,
1795
+ },
1796
+ status: "active",
1797
+ options: {},
1798
+ headers: {},
1799
+ release_date: "2024-01-01",
1800
+ ...overrides,
1801
+ })
1802
+
1803
+ test("returns empty object when model has no reasoning capabilities", () => {
1804
+ const model = createMockModel({
1805
+ capabilities: { reasoning: false },
1806
+ })
1807
+ const result = ProviderTransform.variants(model)
1808
+ expect(result).toEqual({})
1809
+ })
1810
+
1811
+ test("deepseek returns empty object", () => {
1812
+ const model = createMockModel({
1813
+ id: "deepseek/deepseek-chat",
1814
+ providerID: "deepseek",
1815
+ api: {
1816
+ id: "deepseek-chat",
1817
+ url: "https://api.deepseek.com",
1818
+ npm: "@ai-sdk/openai-compatible",
1819
+ },
1820
+ })
1821
+ const result = ProviderTransform.variants(model)
1822
+ expect(result).toEqual({})
1823
+ })
1824
+
1825
+ test("minimax returns empty object", () => {
1826
+ const model = createMockModel({
1827
+ id: "minimax/minimax-model",
1828
+ providerID: "minimax",
1829
+ api: {
1830
+ id: "minimax-model",
1831
+ url: "https://api.minimax.com",
1832
+ npm: "@ai-sdk/openai-compatible",
1833
+ },
1834
+ })
1835
+ const result = ProviderTransform.variants(model)
1836
+ expect(result).toEqual({})
1837
+ })
1838
+
1839
+ test("glm returns empty object", () => {
1840
+ const model = createMockModel({
1841
+ id: "glm/glm-4",
1842
+ providerID: "glm",
1843
+ api: {
1844
+ id: "glm-4",
1845
+ url: "https://api.glm.com",
1846
+ npm: "@ai-sdk/openai-compatible",
1847
+ },
1848
+ })
1849
+ const result = ProviderTransform.variants(model)
1850
+ expect(result).toEqual({})
1851
+ })
1852
+
1853
+ test("mistral returns empty object", () => {
1854
+ const model = createMockModel({
1855
+ id: "mistral/mistral-large",
1856
+ providerID: "mistral",
1857
+ api: {
1858
+ id: "mistral-large-latest",
1859
+ url: "https://api.mistral.com",
1860
+ npm: "@ai-sdk/mistral",
1861
+ },
1862
+ })
1863
+ const result = ProviderTransform.variants(model)
1864
+ expect(result).toEqual({})
1865
+ })
1866
+
1867
+ describe("@openrouter/ai-sdk-provider", () => {
1868
+ test("returns empty object for non-qualifying models", () => {
1869
+ const model = createMockModel({
1870
+ id: "openrouter/test-model",
1871
+ providerID: "openrouter",
1872
+ api: {
1873
+ id: "test-model",
1874
+ url: "https://openrouter.ai",
1875
+ npm: "@openrouter/ai-sdk-provider",
1876
+ },
1877
+ })
1878
+ const result = ProviderTransform.variants(model)
1879
+ expect(result).toEqual({})
1880
+ })
1881
+
1882
+ test("gpt models return OPENAI_EFFORTS with reasoning", () => {
1883
+ const model = createMockModel({
1884
+ id: "openrouter/gpt-4",
1885
+ providerID: "openrouter",
1886
+ api: {
1887
+ id: "gpt-4",
1888
+ url: "https://openrouter.ai",
1889
+ npm: "@openrouter/ai-sdk-provider",
1890
+ },
1891
+ })
1892
+ const result = ProviderTransform.variants(model)
1893
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1894
+ expect(result.low).toEqual({ reasoning: { effort: "low" } })
1895
+ expect(result.high).toEqual({ reasoning: { effort: "high" } })
1896
+ })
1897
+
1898
+ test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
1899
+ const model = createMockModel({
1900
+ id: "openrouter/gemini-3-5-pro",
1901
+ providerID: "openrouter",
1902
+ api: {
1903
+ id: "gemini-3-5-pro",
1904
+ url: "https://openrouter.ai",
1905
+ npm: "@openrouter/ai-sdk-provider",
1906
+ },
1907
+ })
1908
+ const result = ProviderTransform.variants(model)
1909
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1910
+ })
1911
+
1912
+ test("grok-4 returns empty object", () => {
1913
+ const model = createMockModel({
1914
+ id: "openrouter/grok-4",
1915
+ providerID: "openrouter",
1916
+ api: {
1917
+ id: "grok-4",
1918
+ url: "https://openrouter.ai",
1919
+ npm: "@openrouter/ai-sdk-provider",
1920
+ },
1921
+ })
1922
+ const result = ProviderTransform.variants(model)
1923
+ expect(result).toEqual({})
1924
+ })
1925
+
1926
+ test("grok-3-mini returns low and high with reasoning", () => {
1927
+ const model = createMockModel({
1928
+ id: "openrouter/grok-3-mini",
1929
+ providerID: "openrouter",
1930
+ api: {
1931
+ id: "grok-3-mini",
1932
+ url: "https://openrouter.ai",
1933
+ npm: "@openrouter/ai-sdk-provider",
1934
+ },
1935
+ })
1936
+ const result = ProviderTransform.variants(model)
1937
+ expect(Object.keys(result)).toEqual(["low", "high"])
1938
+ expect(result.low).toEqual({ reasoning: { effort: "low" } })
1939
+ expect(result.high).toEqual({ reasoning: { effort: "high" } })
1940
+ })
1941
+ })
1942
+
1943
+ describe("@ai-sdk/gateway", () => {
1944
+ test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
1945
+ const model = createMockModel({
1946
+ id: "anthropic/claude-sonnet-4-6",
1947
+ providerID: "gateway",
1948
+ api: {
1949
+ id: "anthropic/claude-sonnet-4-6",
1950
+ url: "https://gateway.ai",
1951
+ npm: "@ai-sdk/gateway",
1952
+ },
1953
+ })
1954
+ const result = ProviderTransform.variants(model)
1955
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1956
+ expect(result.medium).toEqual({
1957
+ thinking: {
1958
+ type: "adaptive",
1959
+ },
1960
+ effort: "medium",
1961
+ })
1962
+ })
1963
+
1964
+ test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
1965
+ const model = createMockModel({
1966
+ id: "anthropic/claude-sonnet-4-6",
1967
+ providerID: "gateway",
1968
+ api: {
1969
+ id: "anthropic/claude-sonnet-4.6",
1970
+ url: "https://gateway.ai",
1971
+ npm: "@ai-sdk/gateway",
1972
+ },
1973
+ })
1974
+ const result = ProviderTransform.variants(model)
1975
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1976
+ expect(result.medium).toEqual({
1977
+ thinking: {
1978
+ type: "adaptive",
1979
+ },
1980
+ effort: "medium",
1981
+ })
1982
+ })
1983
+
1984
+ test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
1985
+ const model = createMockModel({
1986
+ id: "anthropic/claude-opus-4-6",
1987
+ providerID: "gateway",
1988
+ api: {
1989
+ id: "anthropic/claude-opus-4.6",
1990
+ url: "https://gateway.ai",
1991
+ npm: "@ai-sdk/gateway",
1992
+ },
1993
+ })
1994
+ const result = ProviderTransform.variants(model)
1995
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1996
+ expect(result.high).toEqual({
1997
+ thinking: {
1998
+ type: "adaptive",
1999
+ },
2000
+ effort: "high",
2001
+ })
2002
+ })
2003
+
2004
+ test("anthropic models return anthropic thinking options", () => {
2005
+ const model = createMockModel({
2006
+ id: "anthropic/claude-sonnet-4",
2007
+ providerID: "gateway",
2008
+ api: {
2009
+ id: "anthropic/claude-sonnet-4",
2010
+ url: "https://gateway.ai",
2011
+ npm: "@ai-sdk/gateway",
2012
+ },
2013
+ })
2014
+ const result = ProviderTransform.variants(model)
2015
+ expect(Object.keys(result)).toEqual(["high", "max"])
2016
+ expect(result.high).toEqual({
2017
+ thinking: {
2018
+ type: "enabled",
2019
+ budgetTokens: 16000,
2020
+ },
2021
+ })
2022
+ expect(result.max).toEqual({
2023
+ thinking: {
2024
+ type: "enabled",
2025
+ budgetTokens: 31999,
2026
+ },
2027
+ })
2028
+ })
2029
+
2030
+ test("returns OPENAI_EFFORTS with reasoningEffort", () => {
2031
+ const model = createMockModel({
2032
+ id: "gateway/gateway-model",
2033
+ providerID: "gateway",
2034
+ api: {
2035
+ id: "gateway-model",
2036
+ url: "https://gateway.ai",
2037
+ npm: "@ai-sdk/gateway",
2038
+ },
2039
+ })
2040
+ const result = ProviderTransform.variants(model)
2041
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
2042
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2043
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2044
+ })
2045
+ })
2046
+
2047
+ describe("@ai-sdk/github-copilot", () => {
2048
+ test("standard models return low, medium, high", () => {
2049
+ const model = createMockModel({
2050
+ id: "gpt-4.5",
2051
+ providerID: "github-copilot",
2052
+ api: {
2053
+ id: "gpt-4.5",
2054
+ url: "https://api.githubcopilot.com",
2055
+ npm: "@ai-sdk/github-copilot",
2056
+ },
2057
+ })
2058
+ const result = ProviderTransform.variants(model)
2059
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2060
+ expect(result.low).toEqual({
2061
+ reasoningEffort: "low",
2062
+ reasoningSummary: "auto",
2063
+ include: ["reasoning.encrypted_content"],
2064
+ })
2065
+ })
2066
+
2067
+ test("gpt-5.1-codex-max includes xhigh", () => {
2068
+ const model = createMockModel({
2069
+ id: "gpt-5.1-codex-max",
2070
+ providerID: "github-copilot",
2071
+ api: {
2072
+ id: "gpt-5.1-codex-max",
2073
+ url: "https://api.githubcopilot.com",
2074
+ npm: "@ai-sdk/github-copilot",
2075
+ },
2076
+ })
2077
+ const result = ProviderTransform.variants(model)
2078
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
2079
+ })
2080
+
2081
+ test("gpt-5.1-codex-mini does not include xhigh", () => {
2082
+ const model = createMockModel({
2083
+ id: "gpt-5.1-codex-mini",
2084
+ providerID: "github-copilot",
2085
+ api: {
2086
+ id: "gpt-5.1-codex-mini",
2087
+ url: "https://api.githubcopilot.com",
2088
+ npm: "@ai-sdk/github-copilot",
2089
+ },
2090
+ })
2091
+ const result = ProviderTransform.variants(model)
2092
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2093
+ })
2094
+
2095
+ test("gpt-5.1-codex does not include xhigh", () => {
2096
+ const model = createMockModel({
2097
+ id: "gpt-5.1-codex",
2098
+ providerID: "github-copilot",
2099
+ api: {
2100
+ id: "gpt-5.1-codex",
2101
+ url: "https://api.githubcopilot.com",
2102
+ npm: "@ai-sdk/github-copilot",
2103
+ },
2104
+ })
2105
+ const result = ProviderTransform.variants(model)
2106
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2107
+ })
2108
+
2109
+ test("gpt-5.2 includes xhigh", () => {
2110
+ const model = createMockModel({
2111
+ id: "gpt-5.2",
2112
+ providerID: "github-copilot",
2113
+ api: {
2114
+ id: "gpt-5.2",
2115
+ url: "https://api.githubcopilot.com",
2116
+ npm: "@ai-sdk/github-copilot",
2117
+ },
2118
+ })
2119
+ const result = ProviderTransform.variants(model)
2120
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
2121
+ expect(result.xhigh).toEqual({
2122
+ reasoningEffort: "xhigh",
2123
+ reasoningSummary: "auto",
2124
+ include: ["reasoning.encrypted_content"],
2125
+ })
2126
+ })
2127
+
2128
+ test("gpt-5.2-codex includes xhigh", () => {
2129
+ const model = createMockModel({
2130
+ id: "gpt-5.2-codex",
2131
+ providerID: "github-copilot",
2132
+ api: {
2133
+ id: "gpt-5.2-codex",
2134
+ url: "https://api.githubcopilot.com",
2135
+ npm: "@ai-sdk/github-copilot",
2136
+ },
2137
+ })
2138
+ const result = ProviderTransform.variants(model)
2139
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
2140
+ })
2141
+
2142
+ test("gpt-5.3-codex includes xhigh", () => {
2143
+ const model = createMockModel({
2144
+ id: "gpt-5.3-codex",
2145
+ providerID: "github-copilot",
2146
+ api: {
2147
+ id: "gpt-5.3-codex",
2148
+ url: "https://api.githubcopilot.com",
2149
+ npm: "@ai-sdk/github-copilot",
2150
+ },
2151
+ })
2152
+ const result = ProviderTransform.variants(model)
2153
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
2154
+ })
2155
+
2156
+ test("gpt-5.4 includes xhigh", () => {
2157
+ const model = createMockModel({
2158
+ id: "gpt-5.4",
2159
+ release_date: "2026-03-05",
2160
+ providerID: "github-copilot",
2161
+ api: {
2162
+ id: "gpt-5.4",
2163
+ url: "https://api.githubcopilot.com",
2164
+ npm: "@ai-sdk/github-copilot",
2165
+ },
2166
+ })
2167
+ const result = ProviderTransform.variants(model)
2168
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
2169
+ })
2170
+ })
2171
+
2172
+ describe("@ai-sdk/cerebras", () => {
2173
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
2174
+ const model = createMockModel({
2175
+ id: "cerebras/llama-4",
2176
+ providerID: "cerebras",
2177
+ api: {
2178
+ id: "llama-4-sc",
2179
+ url: "https://api.cerebras.ai",
2180
+ npm: "@ai-sdk/cerebras",
2181
+ },
2182
+ })
2183
+ const result = ProviderTransform.variants(model)
2184
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2185
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2186
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2187
+ })
2188
+ })
2189
+
2190
+ describe("@ai-sdk/togetherai", () => {
2191
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
2192
+ const model = createMockModel({
2193
+ id: "togetherai/llama-4",
2194
+ providerID: "togetherai",
2195
+ api: {
2196
+ id: "llama-4-sc",
2197
+ url: "https://api.togetherai.com",
2198
+ npm: "@ai-sdk/togetherai",
2199
+ },
2200
+ })
2201
+ const result = ProviderTransform.variants(model)
2202
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2203
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2204
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2205
+ })
2206
+ })
2207
+
2208
+ describe("@ai-sdk/xai", () => {
2209
+ test("grok-3 returns empty object", () => {
2210
+ const model = createMockModel({
2211
+ id: "xai/grok-3",
2212
+ providerID: "xai",
2213
+ api: {
2214
+ id: "grok-3",
2215
+ url: "https://api.x.ai",
2216
+ npm: "@ai-sdk/xai",
2217
+ },
2218
+ })
2219
+ const result = ProviderTransform.variants(model)
2220
+ expect(result).toEqual({})
2221
+ })
2222
+
2223
+ test("grok-3-mini returns low and high with reasoningEffort", () => {
2224
+ const model = createMockModel({
2225
+ id: "xai/grok-3-mini",
2226
+ providerID: "xai",
2227
+ api: {
2228
+ id: "grok-3-mini",
2229
+ url: "https://api.x.ai",
2230
+ npm: "@ai-sdk/xai",
2231
+ },
2232
+ })
2233
+ const result = ProviderTransform.variants(model)
2234
+ expect(Object.keys(result)).toEqual(["low", "high"])
2235
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2236
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2237
+ })
2238
+ })
2239
+
2240
+ describe("@ai-sdk/deepinfra", () => {
2241
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
2242
+ const model = createMockModel({
2243
+ id: "deepinfra/llama-4",
2244
+ providerID: "deepinfra",
2245
+ api: {
2246
+ id: "llama-4-sc",
2247
+ url: "https://api.deepinfra.com",
2248
+ npm: "@ai-sdk/deepinfra",
2249
+ },
2250
+ })
2251
+ const result = ProviderTransform.variants(model)
2252
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2253
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2254
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2255
+ })
2256
+ })
2257
+
2258
+ describe("@ai-sdk/openai-compatible", () => {
2259
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
2260
+ const model = createMockModel({
2261
+ id: "custom-provider/custom-model",
2262
+ providerID: "custom-provider",
2263
+ api: {
2264
+ id: "custom-model",
2265
+ url: "https://api.custom.com",
2266
+ npm: "@ai-sdk/openai-compatible",
2267
+ },
2268
+ })
2269
+ const result = ProviderTransform.variants(model)
2270
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2271
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2272
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2273
+ })
2274
+ })
2275
+
2276
+ describe("@ai-sdk/azure", () => {
2277
+ test("o1-mini returns empty object", () => {
2278
+ const model = createMockModel({
2279
+ id: "o1-mini",
2280
+ providerID: "azure",
2281
+ api: {
2282
+ id: "o1-mini",
2283
+ url: "https://azure.com",
2284
+ npm: "@ai-sdk/azure",
2285
+ },
2286
+ })
2287
+ const result = ProviderTransform.variants(model)
2288
+ expect(result).toEqual({})
2289
+ })
2290
+
2291
+ test("standard azure models return custom efforts with reasoningSummary", () => {
2292
+ const model = createMockModel({
2293
+ id: "o1",
2294
+ providerID: "azure",
2295
+ api: {
2296
+ id: "o1",
2297
+ url: "https://azure.com",
2298
+ npm: "@ai-sdk/azure",
2299
+ },
2300
+ })
2301
+ const result = ProviderTransform.variants(model)
2302
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2303
+ expect(result.low).toEqual({
2304
+ reasoningEffort: "low",
2305
+ reasoningSummary: "auto",
2306
+ include: ["reasoning.encrypted_content"],
2307
+ })
2308
+ })
2309
+
2310
+ test("gpt-5 adds minimal effort", () => {
2311
+ const model = createMockModel({
2312
+ id: "gpt-5",
2313
+ providerID: "azure",
2314
+ api: {
2315
+ id: "gpt-5",
2316
+ url: "https://azure.com",
2317
+ npm: "@ai-sdk/azure",
2318
+ },
2319
+ })
2320
+ const result = ProviderTransform.variants(model)
2321
+ expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
2322
+ })
2323
+ })
2324
+
2325
+ describe("@ai-sdk/openai", () => {
2326
+ test("gpt-5-pro returns empty object", () => {
2327
+ const model = createMockModel({
2328
+ id: "gpt-5-pro",
2329
+ providerID: "openai",
2330
+ api: {
2331
+ id: "gpt-5-pro",
2332
+ url: "https://api.openai.com",
2333
+ npm: "@ai-sdk/openai",
2334
+ },
2335
+ })
2336
+ const result = ProviderTransform.variants(model)
2337
+ expect(result).toEqual({})
2338
+ })
2339
+
2340
+ test("standard openai models return custom efforts with reasoningSummary", () => {
2341
+ const model = createMockModel({
2342
+ id: "gpt-5",
2343
+ providerID: "openai",
2344
+ api: {
2345
+ id: "gpt-5",
2346
+ url: "https://api.openai.com",
2347
+ npm: "@ai-sdk/openai",
2348
+ },
2349
+ release_date: "2024-06-01",
2350
+ })
2351
+ const result = ProviderTransform.variants(model)
2352
+ expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
2353
+ expect(result.low).toEqual({
2354
+ reasoningEffort: "low",
2355
+ reasoningSummary: "auto",
2356
+ include: ["reasoning.encrypted_content"],
2357
+ })
2358
+ })
2359
+
2360
+ test("models after 2025-11-13 include 'none' effort", () => {
2361
+ const model = createMockModel({
2362
+ id: "gpt-5-nano",
2363
+ providerID: "openai",
2364
+ api: {
2365
+ id: "gpt-5-nano",
2366
+ url: "https://api.openai.com",
2367
+ npm: "@ai-sdk/openai",
2368
+ },
2369
+ release_date: "2025-11-14",
2370
+ })
2371
+ const result = ProviderTransform.variants(model)
2372
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
2373
+ })
2374
+
2375
+ test("models after 2025-12-04 include 'xhigh' effort", () => {
2376
+ const model = createMockModel({
2377
+ id: "openai/gpt-5-chat",
2378
+ providerID: "openai",
2379
+ api: {
2380
+ id: "gpt-5-chat",
2381
+ url: "https://api.openai.com",
2382
+ npm: "@ai-sdk/openai",
2383
+ },
2384
+ release_date: "2025-12-05",
2385
+ })
2386
+ const result = ProviderTransform.variants(model)
2387
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
2388
+ })
2389
+ })
2390
+
2391
+ describe("@ai-sdk/anthropic", () => {
2392
+ test("sonnet 4.6 returns adaptive thinking options", () => {
2393
+ const model = createMockModel({
2394
+ id: "anthropic/claude-sonnet-4-6",
2395
+ providerID: "anthropic",
2396
+ api: {
2397
+ id: "claude-sonnet-4-6",
2398
+ url: "https://api.anthropic.com",
2399
+ npm: "@ai-sdk/anthropic",
2400
+ },
2401
+ })
2402
+ const result = ProviderTransform.variants(model)
2403
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2404
+ expect(result.high).toEqual({
2405
+ thinking: {
2406
+ type: "adaptive",
2407
+ },
2408
+ effort: "high",
2409
+ })
2410
+ })
2411
+
2412
+ test("returns high and max with thinking config", () => {
2413
+ const model = createMockModel({
2414
+ id: "anthropic/claude-4",
2415
+ providerID: "anthropic",
2416
+ api: {
2417
+ id: "claude-4",
2418
+ url: "https://api.anthropic.com",
2419
+ npm: "@ai-sdk/anthropic",
2420
+ },
2421
+ })
2422
+ const result = ProviderTransform.variants(model)
2423
+ expect(Object.keys(result)).toEqual(["high", "max"])
2424
+ expect(result.high).toEqual({
2425
+ thinking: {
2426
+ type: "enabled",
2427
+ budgetTokens: 16000,
2428
+ },
2429
+ })
2430
+ expect(result.max).toEqual({
2431
+ thinking: {
2432
+ type: "enabled",
2433
+ budgetTokens: 31999,
2434
+ },
2435
+ })
2436
+ })
2437
+ })
2438
+
2439
+ describe("@ai-sdk/amazon-bedrock", () => {
2440
+ test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
2441
+ const model = createMockModel({
2442
+ id: "bedrock/anthropic-claude-sonnet-4-6",
2443
+ providerID: "bedrock",
2444
+ api: {
2445
+ id: "anthropic.claude-sonnet-4-6",
2446
+ url: "https://bedrock.amazonaws.com",
2447
+ npm: "@ai-sdk/amazon-bedrock",
2448
+ },
2449
+ })
2450
+ const result = ProviderTransform.variants(model)
2451
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2452
+ expect(result.max).toEqual({
2453
+ reasoningConfig: {
2454
+ type: "adaptive",
2455
+ maxReasoningEffort: "max",
2456
+ },
2457
+ })
2458
+ })
2459
+
2460
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
2461
+ const model = createMockModel({
2462
+ id: "bedrock/llama-4",
2463
+ providerID: "bedrock",
2464
+ api: {
2465
+ id: "llama-4-sc",
2466
+ url: "https://bedrock.amazonaws.com",
2467
+ npm: "@ai-sdk/amazon-bedrock",
2468
+ },
2469
+ })
2470
+ const result = ProviderTransform.variants(model)
2471
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2472
+ expect(result.low).toEqual({
2473
+ reasoningConfig: {
2474
+ type: "enabled",
2475
+ maxReasoningEffort: "low",
2476
+ },
2477
+ })
2478
+ })
2479
+ })
2480
+
2481
+ describe("@ai-sdk/google", () => {
2482
+ test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
2483
+ const model = createMockModel({
2484
+ id: "google/gemini-2.5-pro",
2485
+ providerID: "google",
2486
+ api: {
2487
+ id: "gemini-2.5-pro",
2488
+ url: "https://generativelanguage.googleapis.com",
2489
+ npm: "@ai-sdk/google",
2490
+ },
2491
+ })
2492
+ const result = ProviderTransform.variants(model)
2493
+ expect(Object.keys(result)).toEqual(["high", "max"])
2494
+ expect(result.high).toEqual({
2495
+ thinkingConfig: {
2496
+ includeThoughts: true,
2497
+ thinkingBudget: 16000,
2498
+ },
2499
+ })
2500
+ expect(result.max).toEqual({
2501
+ thinkingConfig: {
2502
+ includeThoughts: true,
2503
+ thinkingBudget: 24576,
2504
+ },
2505
+ })
2506
+ })
2507
+
2508
+ test("other gemini models return low and high with thinkingLevel", () => {
2509
+ const model = createMockModel({
2510
+ id: "google/gemini-2.0-pro",
2511
+ providerID: "google",
2512
+ api: {
2513
+ id: "gemini-2.0-pro",
2514
+ url: "https://generativelanguage.googleapis.com",
2515
+ npm: "@ai-sdk/google",
2516
+ },
2517
+ })
2518
+ const result = ProviderTransform.variants(model)
2519
+ expect(Object.keys(result)).toEqual(["low", "high"])
2520
+ expect(result.low).toEqual({
2521
+ thinkingConfig: {
2522
+ includeThoughts: true,
2523
+ thinkingLevel: "low",
2524
+ },
2525
+ })
2526
+ expect(result.high).toEqual({
2527
+ thinkingConfig: {
2528
+ includeThoughts: true,
2529
+ thinkingLevel: "high",
2530
+ },
2531
+ })
2532
+ })
2533
+ })
2534
+
2535
+ describe("@ai-sdk/google-vertex", () => {
2536
+ test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
2537
+ const model = createMockModel({
2538
+ id: "google-vertex/gemini-2.5-pro",
2539
+ providerID: "google-vertex",
2540
+ api: {
2541
+ id: "gemini-2.5-pro",
2542
+ url: "https://vertexai.googleapis.com",
2543
+ npm: "@ai-sdk/google-vertex",
2544
+ },
2545
+ })
2546
+ const result = ProviderTransform.variants(model)
2547
+ expect(Object.keys(result)).toEqual(["high", "max"])
2548
+ })
2549
+
2550
+ test("other vertex models return low and high with thinkingLevel", () => {
2551
+ const model = createMockModel({
2552
+ id: "google-vertex/gemini-2.0-pro",
2553
+ providerID: "google-vertex",
2554
+ api: {
2555
+ id: "gemini-2.0-pro",
2556
+ url: "https://vertexai.googleapis.com",
2557
+ npm: "@ai-sdk/google-vertex",
2558
+ },
2559
+ })
2560
+ const result = ProviderTransform.variants(model)
2561
+ expect(Object.keys(result)).toEqual(["low", "high"])
2562
+ })
2563
+ })
2564
+
2565
+ describe("@ai-sdk/cohere", () => {
2566
+ test("returns empty object", () => {
2567
+ const model = createMockModel({
2568
+ id: "cohere/command-r",
2569
+ providerID: "cohere",
2570
+ api: {
2571
+ id: "command-r",
2572
+ url: "https://api.cohere.com",
2573
+ npm: "@ai-sdk/cohere",
2574
+ },
2575
+ })
2576
+ const result = ProviderTransform.variants(model)
2577
+ expect(result).toEqual({})
2578
+ })
2579
+ })
2580
+
2581
+ describe("@ai-sdk/groq", () => {
2582
+ test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
2583
+ const model = createMockModel({
2584
+ id: "groq/llama-4",
2585
+ providerID: "groq",
2586
+ api: {
2587
+ id: "llama-4-sc",
2588
+ url: "https://api.groq.com",
2589
+ npm: "@ai-sdk/groq",
2590
+ },
2591
+ })
2592
+ const result = ProviderTransform.variants(model)
2593
+ expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
2594
+ expect(result.none).toEqual({
2595
+ reasoningEffort: "none",
2596
+ })
2597
+ expect(result.low).toEqual({
2598
+ reasoningEffort: "low",
2599
+ })
2600
+ })
2601
+ })
2602
+
2603
+ describe("@ai-sdk/perplexity", () => {
2604
+ test("returns empty object", () => {
2605
+ const model = createMockModel({
2606
+ id: "perplexity/sonar-plus",
2607
+ providerID: "perplexity",
2608
+ api: {
2609
+ id: "sonar-plus",
2610
+ url: "https://api.perplexity.ai",
2611
+ npm: "@ai-sdk/perplexity",
2612
+ },
2613
+ })
2614
+ const result = ProviderTransform.variants(model)
2615
+ expect(result).toEqual({})
2616
+ })
2617
+ })
2618
+
2619
+ describe("@jerome-benoit/sap-ai-provider-v2", () => {
2620
+ test("anthropic models return thinking variants", () => {
2621
+ const model = createMockModel({
2622
+ id: "sap-ai-core/anthropic--claude-sonnet-4",
2623
+ providerID: "sap-ai-core",
2624
+ api: {
2625
+ id: "anthropic--claude-sonnet-4",
2626
+ url: "https://api.ai.sap",
2627
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2628
+ },
2629
+ })
2630
+ const result = ProviderTransform.variants(model)
2631
+ expect(Object.keys(result)).toEqual(["high", "max"])
2632
+ expect(result.high).toEqual({
2633
+ thinking: {
2634
+ type: "enabled",
2635
+ budgetTokens: 16000,
2636
+ },
2637
+ })
2638
+ expect(result.max).toEqual({
2639
+ thinking: {
2640
+ type: "enabled",
2641
+ budgetTokens: 31999,
2642
+ },
2643
+ })
2644
+ })
2645
+
2646
+ test("anthropic 4.6 models return adaptive thinking variants", () => {
2647
+ const model = createMockModel({
2648
+ id: "sap-ai-core/anthropic--claude-sonnet-4-6",
2649
+ providerID: "sap-ai-core",
2650
+ api: {
2651
+ id: "anthropic--claude-sonnet-4-6",
2652
+ url: "https://api.ai.sap",
2653
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2654
+ },
2655
+ })
2656
+ const result = ProviderTransform.variants(model)
2657
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2658
+ expect(result.low).toEqual({
2659
+ thinking: {
2660
+ type: "adaptive",
2661
+ },
2662
+ effort: "low",
2663
+ })
2664
+ expect(result.max).toEqual({
2665
+ thinking: {
2666
+ type: "adaptive",
2667
+ },
2668
+ effort: "max",
2669
+ })
2670
+ })
2671
+
2672
+ test("gemini 2.5 models return thinkingConfig variants", () => {
2673
+ const model = createMockModel({
2674
+ id: "sap-ai-core/gcp--gemini-2.5-pro",
2675
+ providerID: "sap-ai-core",
2676
+ api: {
2677
+ id: "gcp--gemini-2.5-pro",
2678
+ url: "https://api.ai.sap",
2679
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2680
+ },
2681
+ })
2682
+ const result = ProviderTransform.variants(model)
2683
+ expect(Object.keys(result)).toEqual(["high", "max"])
2684
+ expect(result.high).toEqual({
2685
+ thinkingConfig: {
2686
+ includeThoughts: true,
2687
+ thinkingBudget: 16000,
2688
+ },
2689
+ })
2690
+ expect(result.max).toEqual({
2691
+ thinkingConfig: {
2692
+ includeThoughts: true,
2693
+ thinkingBudget: 24576,
2694
+ },
2695
+ })
2696
+ })
2697
+
2698
+ test("gpt models return reasoningEffort variants", () => {
2699
+ const model = createMockModel({
2700
+ id: "sap-ai-core/azure-openai--gpt-4o",
2701
+ providerID: "sap-ai-core",
2702
+ api: {
2703
+ id: "azure-openai--gpt-4o",
2704
+ url: "https://api.ai.sap",
2705
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2706
+ },
2707
+ })
2708
+ const result = ProviderTransform.variants(model)
2709
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2710
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2711
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2712
+ })
2713
+
2714
+ test("o-series models return reasoningEffort variants", () => {
2715
+ const model = createMockModel({
2716
+ id: "sap-ai-core/azure-openai--o3-mini",
2717
+ providerID: "sap-ai-core",
2718
+ api: {
2719
+ id: "azure-openai--o3-mini",
2720
+ url: "https://api.ai.sap",
2721
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2722
+ },
2723
+ })
2724
+ const result = ProviderTransform.variants(model)
2725
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2726
+ expect(result.low).toEqual({ reasoningEffort: "low" })
2727
+ expect(result.high).toEqual({ reasoningEffort: "high" })
2728
+ })
2729
+
2730
+ test("sonar models return empty object", () => {
2731
+ const model = createMockModel({
2732
+ id: "sap-ai-core/perplexity--sonar-pro",
2733
+ providerID: "sap-ai-core",
2734
+ api: {
2735
+ id: "perplexity--sonar-pro",
2736
+ url: "https://api.ai.sap",
2737
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2738
+ },
2739
+ })
2740
+ const result = ProviderTransform.variants(model)
2741
+ expect(result).toEqual({})
2742
+ })
2743
+
2744
+ test("mistral models return empty object", () => {
2745
+ const model = createMockModel({
2746
+ id: "sap-ai-core/mistral--mistral-large",
2747
+ providerID: "sap-ai-core",
2748
+ api: {
2749
+ id: "mistral--mistral-large",
2750
+ url: "https://api.ai.sap",
2751
+ npm: "@jerome-benoit/sap-ai-provider-v2",
2752
+ },
2753
+ })
2754
+ const result = ProviderTransform.variants(model)
2755
+ expect(result).toEqual({})
2756
+ })
2757
+ })
2758
+ })