innocode 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (434) hide show
  1. package/AGENTS.md +27 -0
  2. package/Dockerfile +18 -0
  3. package/README.md +15 -0
  4. package/bin/innocode +84 -0
  5. package/bin/opencode +84 -0
  6. package/bunfig.toml +5 -0
  7. package/package.json +126 -0
  8. package/parsers-config.ts +253 -0
  9. package/script/build.ts +198 -0
  10. package/script/postinstall.mjs +125 -0
  11. package/script/publish.ts +186 -0
  12. package/script/schema.ts +47 -0
  13. package/script/seed-e2e.ts +50 -0
  14. package/src/acp/README.md +164 -0
  15. package/src/acp/agent.ts +1676 -0
  16. package/src/acp/session.ts +117 -0
  17. package/src/acp/types.ts +23 -0
  18. package/src/agent/agent.ts +338 -0
  19. package/src/agent/generate.txt +75 -0
  20. package/src/agent/prompt/compaction.txt +14 -0
  21. package/src/agent/prompt/explore.txt +18 -0
  22. package/src/agent/prompt/summary.txt +11 -0
  23. package/src/agent/prompt/title.txt +44 -0
  24. package/src/auth/index.ts +70 -0
  25. package/src/bun/index.ts +137 -0
  26. package/src/bun/registry.ts +48 -0
  27. package/src/bus/bus-event.ts +43 -0
  28. package/src/bus/global.ts +10 -0
  29. package/src/bus/index.ts +105 -0
  30. package/src/cli/bootstrap.ts +17 -0
  31. package/src/cli/cmd/acp.ts +70 -0
  32. package/src/cli/cmd/agent.ts +257 -0
  33. package/src/cli/cmd/auth.ts +400 -0
  34. package/src/cli/cmd/cmd.ts +7 -0
  35. package/src/cli/cmd/debug/agent.ts +167 -0
  36. package/src/cli/cmd/debug/config.ts +16 -0
  37. package/src/cli/cmd/debug/file.ts +97 -0
  38. package/src/cli/cmd/debug/index.ts +48 -0
  39. package/src/cli/cmd/debug/lsp.ts +52 -0
  40. package/src/cli/cmd/debug/ripgrep.ts +87 -0
  41. package/src/cli/cmd/debug/scrap.ts +16 -0
  42. package/src/cli/cmd/debug/skill.ts +16 -0
  43. package/src/cli/cmd/debug/snapshot.ts +52 -0
  44. package/src/cli/cmd/export.ts +88 -0
  45. package/src/cli/cmd/generate.ts +38 -0
  46. package/src/cli/cmd/github.ts +1540 -0
  47. package/src/cli/cmd/import.ts +147 -0
  48. package/src/cli/cmd/mcp.ts +765 -0
  49. package/src/cli/cmd/models.ts +77 -0
  50. package/src/cli/cmd/pr.ts +113 -0
  51. package/src/cli/cmd/run.ts +598 -0
  52. package/src/cli/cmd/serve.ts +20 -0
  53. package/src/cli/cmd/session.ts +135 -0
  54. package/src/cli/cmd/stats.ts +426 -0
  55. package/src/cli/cmd/tui/app.tsx +812 -0
  56. package/src/cli/cmd/tui/attach.ts +60 -0
  57. package/src/cli/cmd/tui/component/border.tsx +21 -0
  58. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  59. package/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
  60. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  61. package/src/cli/cmd/tui/component/dialog-model.tsx +165 -0
  62. package/src/cli/cmd/tui/component/dialog-provider.tsx +243 -0
  63. package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
  64. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  65. package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
  66. package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  67. package/src/cli/cmd/tui/component/dialog-status.tsx +167 -0
  68. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  69. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  70. package/src/cli/cmd/tui/component/logo.tsx +85 -0
  71. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +666 -0
  72. package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
  73. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  74. package/src/cli/cmd/tui/component/prompt/index.tsx +1153 -0
  75. package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  76. package/src/cli/cmd/tui/component/spinner.tsx +24 -0
  77. package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  78. package/src/cli/cmd/tui/component/tips.tsx +153 -0
  79. package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  80. package/src/cli/cmd/tui/context/args.tsx +15 -0
  81. package/src/cli/cmd/tui/context/directory.ts +13 -0
  82. package/src/cli/cmd/tui/context/exit.tsx +54 -0
  83. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  84. package/src/cli/cmd/tui/context/keybind.tsx +100 -0
  85. package/src/cli/cmd/tui/context/kv.tsx +52 -0
  86. package/src/cli/cmd/tui/context/local.tsx +409 -0
  87. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  88. package/src/cli/cmd/tui/context/route.tsx +46 -0
  89. package/src/cli/cmd/tui/context/sdk.tsx +101 -0
  90. package/src/cli/cmd/tui/context/sync.tsx +470 -0
  91. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  92. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  93. package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  94. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  95. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  96. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  97. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  98. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  99. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  100. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  101. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  102. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  103. package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  104. package/src/cli/cmd/tui/context/theme/innocode.json +245 -0
  105. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  106. package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  107. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  108. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  109. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  110. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  111. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  112. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  113. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  114. package/src/cli/cmd/tui/context/theme/orng.json +249 -0
  115. package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  116. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  117. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  118. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  119. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  120. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  121. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  122. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  123. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  124. package/src/cli/cmd/tui/context/theme.tsx +1154 -0
  125. package/src/cli/cmd/tui/event.ts +48 -0
  126. package/src/cli/cmd/tui/routes/home.tsx +145 -0
  127. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  128. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  129. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  130. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  131. package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  132. package/src/cli/cmd/tui/routes/session/header.tsx +135 -0
  133. package/src/cli/cmd/tui/routes/session/index.tsx +2139 -0
  134. package/src/cli/cmd/tui/routes/session/permission.tsx +508 -0
  135. package/src/cli/cmd/tui/routes/session/question.tsx +466 -0
  136. package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
  137. package/src/cli/cmd/tui/thread.ts +188 -0
  138. package/src/cli/cmd/tui/ui/dialog-alert.tsx +59 -0
  139. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +85 -0
  140. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +207 -0
  141. package/src/cli/cmd/tui/ui/dialog-help.tsx +40 -0
  142. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +80 -0
  143. package/src/cli/cmd/tui/ui/dialog-select.tsx +401 -0
  144. package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
  145. package/src/cli/cmd/tui/ui/link.tsx +28 -0
  146. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  147. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  148. package/src/cli/cmd/tui/util/clipboard.ts +159 -0
  149. package/src/cli/cmd/tui/util/editor.ts +32 -0
  150. package/src/cli/cmd/tui/util/signal.ts +7 -0
  151. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  152. package/src/cli/cmd/tui/util/transcript.ts +98 -0
  153. package/src/cli/cmd/tui/win32.ts +129 -0
  154. package/src/cli/cmd/tui/worker.ts +152 -0
  155. package/src/cli/cmd/uninstall.ts +363 -0
  156. package/src/cli/cmd/upgrade.ts +73 -0
  157. package/src/cli/cmd/web.ts +81 -0
  158. package/src/cli/error.ts +57 -0
  159. package/src/cli/logo.ts +6 -0
  160. package/src/cli/network.ts +60 -0
  161. package/src/cli/ui.ts +113 -0
  162. package/src/cli/upgrade.ts +25 -0
  163. package/src/command/index.ts +150 -0
  164. package/src/command/template/initialize.txt +10 -0
  165. package/src/command/template/review.txt +101 -0
  166. package/src/config/config.ts +1517 -0
  167. package/src/config/markdown.ts +98 -0
  168. package/src/env/index.ts +28 -0
  169. package/src/file/ignore.ts +83 -0
  170. package/src/file/index.ts +583 -0
  171. package/src/file/ripgrep.ts +375 -0
  172. package/src/file/time.ts +69 -0
  173. package/src/file/watcher.ts +127 -0
  174. package/src/flag/flag.ts +148 -0
  175. package/src/format/formatter.ts +366 -0
  176. package/src/format/index.ts +137 -0
  177. package/src/global/index.ts +80 -0
  178. package/src/id/id.ts +83 -0
  179. package/src/ide/index.ts +76 -0
  180. package/src/index.ts +160 -0
  181. package/src/installation/index.ts +268 -0
  182. package/src/lsp/client.ts +252 -0
  183. package/src/lsp/index.ts +485 -0
  184. package/src/lsp/language.ts +119 -0
  185. package/src/lsp/server.ts +2046 -0
  186. package/src/mcp/auth.ts +132 -0
  187. package/src/mcp/index.ts +937 -0
  188. package/src/mcp/oauth-callback.ts +200 -0
  189. package/src/mcp/oauth-provider.ts +154 -0
  190. package/src/patch/index.ts +680 -0
  191. package/src/permission/arity.ts +163 -0
  192. package/src/permission/index.ts +210 -0
  193. package/src/permission/next.ts +280 -0
  194. package/src/plugin/codex.ts +624 -0
  195. package/src/plugin/copilot.ts +327 -0
  196. package/src/plugin/index.ts +138 -0
  197. package/src/project/bootstrap.ts +35 -0
  198. package/src/project/instance.ts +114 -0
  199. package/src/project/project.ts +371 -0
  200. package/src/project/state.ts +70 -0
  201. package/src/project/vcs.ts +76 -0
  202. package/src/provider/auth.ts +147 -0
  203. package/src/provider/error.ts +189 -0
  204. package/src/provider/models.ts +133 -0
  205. package/src/provider/provider.ts +1370 -0
  206. package/src/provider/sdk/copilot/README.md +5 -0
  207. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +164 -0
  208. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
  209. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +17 -0
  210. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
  211. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +780 -0
  212. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
  213. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
  214. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +87 -0
  215. package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
  216. package/src/provider/sdk/copilot/index.ts +2 -0
  217. package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
  218. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +303 -0
  219. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
  220. package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
  221. package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
  222. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +207 -0
  223. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1732 -0
  224. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +177 -0
  225. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
  226. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +88 -0
  227. package/src/provider/sdk/copilot/responses/tool/file-search.ts +128 -0
  228. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +115 -0
  229. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +65 -0
  230. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +104 -0
  231. package/src/provider/sdk/copilot/responses/tool/web-search.ts +103 -0
  232. package/src/provider/transform.ts +806 -0
  233. package/src/pty/index.ts +286 -0
  234. package/src/question/index.ts +171 -0
  235. package/src/scheduler/index.ts +61 -0
  236. package/src/server/error.ts +36 -0
  237. package/src/server/event.ts +7 -0
  238. package/src/server/mdns.ts +60 -0
  239. package/src/server/routes/config.ts +92 -0
  240. package/src/server/routes/experimental.ts +208 -0
  241. package/src/server/routes/file.ts +197 -0
  242. package/src/server/routes/global.ts +183 -0
  243. package/src/server/routes/mcp.ts +225 -0
  244. package/src/server/routes/permission.ts +68 -0
  245. package/src/server/routes/project.ts +82 -0
  246. package/src/server/routes/provider.ts +179 -0
  247. package/src/server/routes/pty.ts +176 -0
  248. package/src/server/routes/question.ts +98 -0
  249. package/src/server/routes/session.ts +939 -0
  250. package/src/server/routes/tui.ts +379 -0
  251. package/src/server/server.ts +621 -0
  252. package/src/session/compaction.ts +261 -0
  253. package/src/session/index.ts +543 -0
  254. package/src/session/instruction.ts +197 -0
  255. package/src/session/llm.ts +283 -0
  256. package/src/session/message-v2.ts +841 -0
  257. package/src/session/message.ts +189 -0
  258. package/src/session/processor.ts +410 -0
  259. package/src/session/prompt/anthropic-20250930.txt +166 -0
  260. package/src/session/prompt/anthropic.txt +105 -0
  261. package/src/session/prompt/beast.txt +147 -0
  262. package/src/session/prompt/build-switch.txt +5 -0
  263. package/src/session/prompt/codex_header.txt +79 -0
  264. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  265. package/src/session/prompt/gemini.txt +155 -0
  266. package/src/session/prompt/max-steps.txt +16 -0
  267. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  268. package/src/session/prompt/plan.txt +26 -0
  269. package/src/session/prompt/qwen.txt +109 -0
  270. package/src/session/prompt/trinity.txt +97 -0
  271. package/src/session/prompt.ts +1964 -0
  272. package/src/session/retry.ts +101 -0
  273. package/src/session/revert.ts +121 -0
  274. package/src/session/status.ts +76 -0
  275. package/src/session/summary.ts +203 -0
  276. package/src/session/system.ts +54 -0
  277. package/src/session/todo.ts +37 -0
  278. package/src/share/share-next.ts +200 -0
  279. package/src/share/share.ts +92 -0
  280. package/src/shell/shell.ts +67 -0
  281. package/src/skill/discovery.ts +97 -0
  282. package/src/skill/index.ts +1 -0
  283. package/src/skill/skill.ts +188 -0
  284. package/src/snapshot/index.ts +255 -0
  285. package/src/storage/storage.ts +227 -0
  286. package/src/tool/apply_patch.ts +281 -0
  287. package/src/tool/apply_patch.txt +33 -0
  288. package/src/tool/bash.ts +269 -0
  289. package/src/tool/bash.txt +115 -0
  290. package/src/tool/batch.ts +175 -0
  291. package/src/tool/batch.txt +24 -0
  292. package/src/tool/codesearch.ts +132 -0
  293. package/src/tool/codesearch.txt +12 -0
  294. package/src/tool/edit.ts +655 -0
  295. package/src/tool/edit.txt +10 -0
  296. package/src/tool/external-directory.ts +32 -0
  297. package/src/tool/glob.ts +80 -0
  298. package/src/tool/glob.txt +6 -0
  299. package/src/tool/grep.ts +150 -0
  300. package/src/tool/grep.txt +8 -0
  301. package/src/tool/invalid.ts +17 -0
  302. package/src/tool/ls.ts +121 -0
  303. package/src/tool/ls.txt +1 -0
  304. package/src/tool/lsp.ts +96 -0
  305. package/src/tool/lsp.txt +19 -0
  306. package/src/tool/multiedit.ts +46 -0
  307. package/src/tool/multiedit.txt +41 -0
  308. package/src/tool/plan-enter.txt +14 -0
  309. package/src/tool/plan-exit.txt +13 -0
  310. package/src/tool/plan.ts +130 -0
  311. package/src/tool/question.ts +33 -0
  312. package/src/tool/question.txt +10 -0
  313. package/src/tool/read.ts +261 -0
  314. package/src/tool/read.txt +14 -0
  315. package/src/tool/registry.ts +160 -0
  316. package/src/tool/skill.ts +123 -0
  317. package/src/tool/task.ts +165 -0
  318. package/src/tool/task.txt +60 -0
  319. package/src/tool/todo.ts +53 -0
  320. package/src/tool/todoread.txt +14 -0
  321. package/src/tool/todowrite.txt +167 -0
  322. package/src/tool/tool.ts +89 -0
  323. package/src/tool/truncation.ts +106 -0
  324. package/src/tool/webfetch.ts +186 -0
  325. package/src/tool/webfetch.txt +13 -0
  326. package/src/tool/websearch.ts +150 -0
  327. package/src/tool/websearch.txt +14 -0
  328. package/src/tool/write.ts +85 -0
  329. package/src/tool/write.txt +8 -0
  330. package/src/util/abort.ts +35 -0
  331. package/src/util/archive.ts +16 -0
  332. package/src/util/color.ts +19 -0
  333. package/src/util/context.ts +25 -0
  334. package/src/util/defer.ts +12 -0
  335. package/src/util/eventloop.ts +20 -0
  336. package/src/util/filesystem.ts +93 -0
  337. package/src/util/fn.ts +11 -0
  338. package/src/util/format.ts +20 -0
  339. package/src/util/iife.ts +3 -0
  340. package/src/util/keybind.ts +103 -0
  341. package/src/util/lazy.ts +18 -0
  342. package/src/util/locale.ts +81 -0
  343. package/src/util/lock.ts +98 -0
  344. package/src/util/log.ts +180 -0
  345. package/src/util/proxied.ts +3 -0
  346. package/src/util/queue.ts +32 -0
  347. package/src/util/rpc.ts +66 -0
  348. package/src/util/scrap.ts +10 -0
  349. package/src/util/signal.ts +12 -0
  350. package/src/util/timeout.ts +14 -0
  351. package/src/util/token.ts +7 -0
  352. package/src/util/wildcard.ts +56 -0
  353. package/src/worktree/index.ts +612 -0
  354. package/sst-env.d.ts +9 -0
  355. package/test/acp/agent-interface.test.ts +51 -0
  356. package/test/acp/event-subscription.test.ts +436 -0
  357. package/test/agent/agent.test.ts +675 -0
  358. package/test/bun.test.ts +53 -0
  359. package/test/cli/github-action.test.ts +161 -0
  360. package/test/cli/github-remote.test.ts +80 -0
  361. package/test/cli/import.test.ts +38 -0
  362. package/test/cli/tui/transcript.test.ts +322 -0
  363. package/test/config/agent-color.test.ts +71 -0
  364. package/test/config/config.test.ts +1802 -0
  365. package/test/config/fixtures/empty-frontmatter.md +4 -0
  366. package/test/config/fixtures/frontmatter.md +28 -0
  367. package/test/config/fixtures/markdown-header.md +11 -0
  368. package/test/config/fixtures/no-frontmatter.md +1 -0
  369. package/test/config/fixtures/weird-model-id.md +13 -0
  370. package/test/config/markdown.test.ts +228 -0
  371. package/test/file/ignore.test.ts +10 -0
  372. package/test/file/path-traversal.test.ts +198 -0
  373. package/test/file/ripgrep.test.ts +39 -0
  374. package/test/fixture/fixture.ts +45 -0
  375. package/test/fixture/lsp/fake-lsp-server.js +77 -0
  376. package/test/ide/ide.test.ts +82 -0
  377. package/test/keybind.test.ts +421 -0
  378. package/test/lsp/client.test.ts +95 -0
  379. package/test/mcp/headers.test.ts +153 -0
  380. package/test/mcp/oauth-browser.test.ts +249 -0
  381. package/test/memory/abort-leak.test.ts +136 -0
  382. package/test/patch/patch.test.ts +348 -0
  383. package/test/permission/arity.test.ts +33 -0
  384. package/test/permission/next.test.ts +690 -0
  385. package/test/permission-task.test.ts +319 -0
  386. package/test/plugin/auth-override.test.ts +44 -0
  387. package/test/plugin/codex.test.ts +123 -0
  388. package/test/preload.ts +63 -0
  389. package/test/project/project.test.ts +120 -0
  390. package/test/provider/amazon-bedrock.test.ts +445 -0
  391. package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
  392. package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
  393. package/test/provider/gitlab-duo.test.ts +262 -0
  394. package/test/provider/provider.test.ts +2129 -0
  395. package/test/provider/transform.test.ts +1928 -0
  396. package/test/question/question.test.ts +300 -0
  397. package/test/scheduler.test.ts +73 -0
  398. package/test/server/session-list.test.ts +39 -0
  399. package/test/server/session-select.test.ts +78 -0
  400. package/test/session/compaction.test.ts +423 -0
  401. package/test/session/instruction.test.ts +170 -0
  402. package/test/session/llm.test.ts +667 -0
  403. package/test/session/message-v2.test.ts +924 -0
  404. package/test/session/prompt-missing-file.test.ts +53 -0
  405. package/test/session/prompt-special-chars.test.ts +56 -0
  406. package/test/session/prompt-variant.test.ts +68 -0
  407. package/test/session/retry.test.ts +188 -0
  408. package/test/session/revert-compact.test.ts +285 -0
  409. package/test/session/session.test.ts +71 -0
  410. package/test/session/structured-output-integration.test.ts +233 -0
  411. package/test/session/structured-output.test.ts +385 -0
  412. package/test/skill/discovery.test.ts +60 -0
  413. package/test/skill/skill.test.ts +388 -0
  414. package/test/snapshot/snapshot.test.ts +1040 -0
  415. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  416. package/test/tool/apply_patch.test.ts +559 -0
  417. package/test/tool/bash.test.ts +399 -0
  418. package/test/tool/external-directory.test.ts +127 -0
  419. package/test/tool/fixtures/large-image.png +0 -0
  420. package/test/tool/fixtures/models-api.json +38413 -0
  421. package/test/tool/grep.test.ts +110 -0
  422. package/test/tool/question.test.ts +107 -0
  423. package/test/tool/read.test.ts +421 -0
  424. package/test/tool/registry.test.ts +122 -0
  425. package/test/tool/skill.test.ts +112 -0
  426. package/test/tool/truncation.test.ts +159 -0
  427. package/test/util/filesystem.test.ts +39 -0
  428. package/test/util/format.test.ts +59 -0
  429. package/test/util/iife.test.ts +36 -0
  430. package/test/util/lazy.test.ts +50 -0
  431. package/test/util/lock.test.ts +72 -0
  432. package/test/util/timeout.test.ts +21 -0
  433. package/test/util/wildcard.test.ts +75 -0
  434. package/tsconfig.json +16 -0
@@ -0,0 +1,1928 @@
1
+ import { describe, expect, test } from "bun:test"
2
+ import { ProviderTransform } from "../../src/provider/transform"
3
+
4
+ const OUTPUT_TOKEN_MAX = 32000
5
+
6
+ describe("ProviderTransform.options - setCacheKey", () => {
7
+ const sessionID = "test-session-123"
8
+
9
+ const mockModel = {
10
+ id: "anthropic/claude-3-5-sonnet",
11
+ providerID: "anthropic",
12
+ api: {
13
+ id: "claude-3-5-sonnet-20241022",
14
+ url: "https://api.anthropic.com",
15
+ npm: "@ai-sdk/anthropic",
16
+ },
17
+ name: "Claude 3.5 Sonnet",
18
+ capabilities: {
19
+ temperature: true,
20
+ reasoning: false,
21
+ attachment: true,
22
+ toolcall: true,
23
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
24
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
25
+ interleaved: false,
26
+ },
27
+ cost: {
28
+ input: 0.003,
29
+ output: 0.015,
30
+ cache: { read: 0.0003, write: 0.00375 },
31
+ },
32
+ limit: {
33
+ context: 200000,
34
+ output: 8192,
35
+ },
36
+ status: "active",
37
+ options: {},
38
+ headers: {},
39
+ } as any
40
+
41
+ test("should set promptCacheKey when providerOptions.setCacheKey is true", () => {
42
+ const result = ProviderTransform.options({
43
+ model: mockModel,
44
+ sessionID,
45
+ providerOptions: { setCacheKey: true },
46
+ })
47
+ expect(result.promptCacheKey).toBe(sessionID)
48
+ })
49
+
50
+ test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => {
51
+ const result = ProviderTransform.options({
52
+ model: mockModel,
53
+ sessionID,
54
+ providerOptions: { setCacheKey: false },
55
+ })
56
+ expect(result.promptCacheKey).toBeUndefined()
57
+ })
58
+
59
+ test("should not set promptCacheKey when providerOptions is undefined", () => {
60
+ const result = ProviderTransform.options({
61
+ model: mockModel,
62
+ sessionID,
63
+ providerOptions: undefined,
64
+ })
65
+ expect(result.promptCacheKey).toBeUndefined()
66
+ })
67
+
68
+ test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => {
69
+ const result = ProviderTransform.options({ model: mockModel, sessionID, providerOptions: {} })
70
+ expect(result.promptCacheKey).toBeUndefined()
71
+ })
72
+
73
+ test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
74
+ const openaiModel = {
75
+ ...mockModel,
76
+ providerID: "openai",
77
+ api: {
78
+ id: "gpt-4",
79
+ url: "https://api.openai.com",
80
+ npm: "@ai-sdk/openai",
81
+ },
82
+ }
83
+ const result = ProviderTransform.options({ model: openaiModel, sessionID, providerOptions: {} })
84
+ expect(result.promptCacheKey).toBe(sessionID)
85
+ })
86
+
87
+ test("should set store=false for openai provider", () => {
88
+ const openaiModel = {
89
+ ...mockModel,
90
+ providerID: "openai",
91
+ api: {
92
+ id: "gpt-4",
93
+ url: "https://api.openai.com",
94
+ npm: "@ai-sdk/openai",
95
+ },
96
+ }
97
+ const result = ProviderTransform.options({
98
+ model: openaiModel,
99
+ sessionID,
100
+ providerOptions: {},
101
+ })
102
+ expect(result.store).toBe(false)
103
+ })
104
+ })
105
+
106
+ describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
107
+ const sessionID = "test-session-123"
108
+
109
+ const createGpt5Model = (apiId: string) =>
110
+ ({
111
+ id: `openai/${apiId}`,
112
+ providerID: "openai",
113
+ api: {
114
+ id: apiId,
115
+ url: "https://api.openai.com",
116
+ npm: "@ai-sdk/openai",
117
+ },
118
+ name: apiId,
119
+ capabilities: {
120
+ temperature: true,
121
+ reasoning: true,
122
+ attachment: true,
123
+ toolcall: true,
124
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
125
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
126
+ interleaved: false,
127
+ },
128
+ cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
129
+ limit: { context: 128000, output: 4096 },
130
+ status: "active",
131
+ options: {},
132
+ headers: {},
133
+ }) as any
134
+
135
+ test("gpt-5.2 should have textVerbosity set to low", () => {
136
+ const model = createGpt5Model("gpt-5.2")
137
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
138
+ expect(result.textVerbosity).toBe("low")
139
+ })
140
+
141
+ test("gpt-5.1 should have textVerbosity set to low", () => {
142
+ const model = createGpt5Model("gpt-5.1")
143
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
144
+ expect(result.textVerbosity).toBe("low")
145
+ })
146
+
147
+ test("gpt-5.2-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
148
+ const model = createGpt5Model("gpt-5.2-chat-latest")
149
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
150
+ expect(result.textVerbosity).toBeUndefined()
151
+ })
152
+
153
+ test("gpt-5.1-chat-latest should NOT have textVerbosity set (only supports medium)", () => {
154
+ const model = createGpt5Model("gpt-5.1-chat-latest")
155
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
156
+ expect(result.textVerbosity).toBeUndefined()
157
+ })
158
+
159
+ test("gpt-5.2-chat should NOT have textVerbosity set", () => {
160
+ const model = createGpt5Model("gpt-5.2-chat")
161
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
162
+ expect(result.textVerbosity).toBeUndefined()
163
+ })
164
+
165
+ test("gpt-5-chat should NOT have textVerbosity set", () => {
166
+ const model = createGpt5Model("gpt-5-chat")
167
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
168
+ expect(result.textVerbosity).toBeUndefined()
169
+ })
170
+
171
+ test("gpt-5.2-codex should NOT have textVerbosity set (codex models excluded)", () => {
172
+ const model = createGpt5Model("gpt-5.2-codex")
173
+ const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
174
+ expect(result.textVerbosity).toBeUndefined()
175
+ })
176
+ })
177
+
178
+ describe("ProviderTransform.schema - gemini array items", () => {
179
+ test("adds missing items for array properties", () => {
180
+ const geminiModel = {
181
+ providerID: "google",
182
+ api: {
183
+ id: "gemini-3-pro",
184
+ },
185
+ } as any
186
+
187
+ const schema = {
188
+ type: "object",
189
+ properties: {
190
+ nodes: { type: "array" },
191
+ edges: { type: "array", items: { type: "string" } },
192
+ },
193
+ } as any
194
+
195
+ const result = ProviderTransform.schema(geminiModel, schema) as any
196
+
197
+ expect(result.properties.nodes.items).toBeDefined()
198
+ expect(result.properties.edges.items.type).toBe("string")
199
+ })
200
+ })
201
+
202
+ describe("ProviderTransform.schema - gemini nested array items", () => {
203
+ const geminiModel = {
204
+ providerID: "google",
205
+ api: {
206
+ id: "gemini-3-pro",
207
+ },
208
+ } as any
209
+
210
+ test("adds type to 2D array with empty inner items", () => {
211
+ const schema = {
212
+ type: "object",
213
+ properties: {
214
+ values: {
215
+ type: "array",
216
+ items: {
217
+ type: "array",
218
+ items: {}, // Empty items object
219
+ },
220
+ },
221
+ },
222
+ } as any
223
+
224
+ const result = ProviderTransform.schema(geminiModel, schema) as any
225
+
226
+ // Inner items should have a default type
227
+ expect(result.properties.values.items.items.type).toBe("string")
228
+ })
229
+
230
+ test("adds items and type to 2D array with missing inner items", () => {
231
+ const schema = {
232
+ type: "object",
233
+ properties: {
234
+ data: {
235
+ type: "array",
236
+ items: { type: "array" }, // No items at all
237
+ },
238
+ },
239
+ } as any
240
+
241
+ const result = ProviderTransform.schema(geminiModel, schema) as any
242
+
243
+ expect(result.properties.data.items.items).toBeDefined()
244
+ expect(result.properties.data.items.items.type).toBe("string")
245
+ })
246
+
247
+ test("handles deeply nested arrays (3D)", () => {
248
+ const schema = {
249
+ type: "object",
250
+ properties: {
251
+ matrix: {
252
+ type: "array",
253
+ items: {
254
+ type: "array",
255
+ items: {
256
+ type: "array",
257
+ // No items
258
+ },
259
+ },
260
+ },
261
+ },
262
+ } as any
263
+
264
+ const result = ProviderTransform.schema(geminiModel, schema) as any
265
+
266
+ expect(result.properties.matrix.items.items.items).toBeDefined()
267
+ expect(result.properties.matrix.items.items.items.type).toBe("string")
268
+ })
269
+
270
+ test("preserves existing item types in nested arrays", () => {
271
+ const schema = {
272
+ type: "object",
273
+ properties: {
274
+ numbers: {
275
+ type: "array",
276
+ items: {
277
+ type: "array",
278
+ items: { type: "number" }, // Has explicit type
279
+ },
280
+ },
281
+ },
282
+ } as any
283
+
284
+ const result = ProviderTransform.schema(geminiModel, schema) as any
285
+
286
+ // Should preserve the explicit type
287
+ expect(result.properties.numbers.items.items.type).toBe("number")
288
+ })
289
+
290
+ test("handles mixed nested structures with objects and arrays", () => {
291
+ const schema = {
292
+ type: "object",
293
+ properties: {
294
+ spreadsheetData: {
295
+ type: "object",
296
+ properties: {
297
+ rows: {
298
+ type: "array",
299
+ items: {
300
+ type: "array",
301
+ items: {}, // Empty items
302
+ },
303
+ },
304
+ },
305
+ },
306
+ },
307
+ } as any
308
+
309
+ const result = ProviderTransform.schema(geminiModel, schema) as any
310
+
311
+ expect(result.properties.spreadsheetData.properties.rows.items.items.type).toBe("string")
312
+ })
313
+ })
314
+
315
+ describe("ProviderTransform.schema - gemini non-object properties removal", () => {
316
+ const geminiModel = {
317
+ providerID: "google",
318
+ api: {
319
+ id: "gemini-3-pro",
320
+ },
321
+ } as any
322
+
323
+ test("removes properties from non-object types", () => {
324
+ const schema = {
325
+ type: "object",
326
+ properties: {
327
+ data: {
328
+ type: "string",
329
+ properties: { invalid: { type: "string" } },
330
+ },
331
+ },
332
+ } as any
333
+
334
+ const result = ProviderTransform.schema(geminiModel, schema) as any
335
+
336
+ expect(result.properties.data.type).toBe("string")
337
+ expect(result.properties.data.properties).toBeUndefined()
338
+ })
339
+
340
+ test("removes required from non-object types", () => {
341
+ const schema = {
342
+ type: "object",
343
+ properties: {
344
+ data: {
345
+ type: "array",
346
+ items: { type: "string" },
347
+ required: ["invalid"],
348
+ },
349
+ },
350
+ } as any
351
+
352
+ const result = ProviderTransform.schema(geminiModel, schema) as any
353
+
354
+ expect(result.properties.data.type).toBe("array")
355
+ expect(result.properties.data.required).toBeUndefined()
356
+ })
357
+
358
+ test("removes properties and required from nested non-object types", () => {
359
+ const schema = {
360
+ type: "object",
361
+ properties: {
362
+ outer: {
363
+ type: "object",
364
+ properties: {
365
+ inner: {
366
+ type: "number",
367
+ properties: { bad: { type: "string" } },
368
+ required: ["bad"],
369
+ },
370
+ },
371
+ },
372
+ },
373
+ } as any
374
+
375
+ const result = ProviderTransform.schema(geminiModel, schema) as any
376
+
377
+ expect(result.properties.outer.properties.inner.type).toBe("number")
378
+ expect(result.properties.outer.properties.inner.properties).toBeUndefined()
379
+ expect(result.properties.outer.properties.inner.required).toBeUndefined()
380
+ })
381
+
382
+ test("keeps properties and required on object types", () => {
383
+ const schema = {
384
+ type: "object",
385
+ properties: {
386
+ data: {
387
+ type: "object",
388
+ properties: { name: { type: "string" } },
389
+ required: ["name"],
390
+ },
391
+ },
392
+ } as any
393
+
394
+ const result = ProviderTransform.schema(geminiModel, schema) as any
395
+
396
+ expect(result.properties.data.type).toBe("object")
397
+ expect(result.properties.data.properties).toBeDefined()
398
+ expect(result.properties.data.required).toEqual(["name"])
399
+ })
400
+
401
+ test("does not affect non-gemini providers", () => {
402
+ const openaiModel = {
403
+ providerID: "openai",
404
+ api: {
405
+ id: "gpt-4",
406
+ },
407
+ } as any
408
+
409
+ const schema = {
410
+ type: "object",
411
+ properties: {
412
+ data: {
413
+ type: "string",
414
+ properties: { invalid: { type: "string" } },
415
+ },
416
+ },
417
+ } as any
418
+
419
+ const result = ProviderTransform.schema(openaiModel, schema) as any
420
+
421
+ expect(result.properties.data.properties).toBeDefined()
422
+ })
423
+ })
424
+
425
+ describe("ProviderTransform.message - DeepSeek reasoning content", () => {
426
+ test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
427
+ const msgs = [
428
+ {
429
+ role: "assistant",
430
+ content: [
431
+ { type: "reasoning", text: "Let me think about this..." },
432
+ {
433
+ type: "tool-call",
434
+ toolCallId: "test",
435
+ toolName: "bash",
436
+ input: { command: "echo hello" },
437
+ },
438
+ ],
439
+ },
440
+ ] as any[]
441
+
442
+ const result = ProviderTransform.message(
443
+ msgs,
444
+ {
445
+ id: "deepseek/deepseek-chat",
446
+ providerID: "deepseek",
447
+ api: {
448
+ id: "deepseek-chat",
449
+ url: "https://api.deepseek.com",
450
+ npm: "@ai-sdk/openai-compatible",
451
+ },
452
+ name: "DeepSeek Chat",
453
+ capabilities: {
454
+ temperature: true,
455
+ reasoning: true,
456
+ attachment: false,
457
+ toolcall: true,
458
+ input: { text: true, audio: false, image: false, video: false, pdf: false },
459
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
460
+ interleaved: {
461
+ field: "reasoning_content",
462
+ },
463
+ },
464
+ cost: {
465
+ input: 0.001,
466
+ output: 0.002,
467
+ cache: { read: 0.0001, write: 0.0002 },
468
+ },
469
+ limit: {
470
+ context: 128000,
471
+ output: 8192,
472
+ },
473
+ status: "active",
474
+ options: {},
475
+ headers: {},
476
+ release_date: "2023-04-01",
477
+ },
478
+ {},
479
+ )
480
+
481
+ expect(result).toHaveLength(1)
482
+ expect(result[0].content).toEqual([
483
+ {
484
+ type: "tool-call",
485
+ toolCallId: "test",
486
+ toolName: "bash",
487
+ input: { command: "echo hello" },
488
+ },
489
+ ])
490
+ expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
491
+ })
492
+
493
+ test("Non-DeepSeek providers leave reasoning content unchanged", () => {
494
+ const msgs = [
495
+ {
496
+ role: "assistant",
497
+ content: [
498
+ { type: "reasoning", text: "Should not be processed" },
499
+ { type: "text", text: "Answer" },
500
+ ],
501
+ },
502
+ ] as any[]
503
+
504
+ const result = ProviderTransform.message(
505
+ msgs,
506
+ {
507
+ id: "openai/gpt-4",
508
+ providerID: "openai",
509
+ api: {
510
+ id: "gpt-4",
511
+ url: "https://api.openai.com",
512
+ npm: "@ai-sdk/openai",
513
+ },
514
+ name: "GPT-4",
515
+ capabilities: {
516
+ temperature: true,
517
+ reasoning: false,
518
+ attachment: true,
519
+ toolcall: true,
520
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
521
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
522
+ interleaved: false,
523
+ },
524
+ cost: {
525
+ input: 0.03,
526
+ output: 0.06,
527
+ cache: { read: 0.001, write: 0.002 },
528
+ },
529
+ limit: {
530
+ context: 128000,
531
+ output: 4096,
532
+ },
533
+ status: "active",
534
+ options: {},
535
+ headers: {},
536
+ release_date: "2023-04-01",
537
+ },
538
+ {},
539
+ )
540
+
541
+ expect(result[0].content).toEqual([
542
+ { type: "reasoning", text: "Should not be processed" },
543
+ { type: "text", text: "Answer" },
544
+ ])
545
+ expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBeUndefined()
546
+ })
547
+ })
548
+
549
+ describe("ProviderTransform.message - empty image handling", () => {
550
+ const mockModel = {
551
+ id: "anthropic/claude-3-5-sonnet",
552
+ providerID: "anthropic",
553
+ api: {
554
+ id: "claude-3-5-sonnet-20241022",
555
+ url: "https://api.anthropic.com",
556
+ npm: "@ai-sdk/anthropic",
557
+ },
558
+ name: "Claude 3.5 Sonnet",
559
+ capabilities: {
560
+ temperature: true,
561
+ reasoning: false,
562
+ attachment: true,
563
+ toolcall: true,
564
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
565
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
566
+ interleaved: false,
567
+ },
568
+ cost: {
569
+ input: 0.003,
570
+ output: 0.015,
571
+ cache: { read: 0.0003, write: 0.00375 },
572
+ },
573
+ limit: {
574
+ context: 200000,
575
+ output: 8192,
576
+ },
577
+ status: "active",
578
+ options: {},
579
+ headers: {},
580
+ } as any
581
+
582
+ test("should replace empty base64 image with error text", () => {
583
+ const msgs = [
584
+ {
585
+ role: "user",
586
+ content: [
587
+ { type: "text", text: "What is in this image?" },
588
+ { type: "image", image: "data:image/png;base64," },
589
+ ],
590
+ },
591
+ ] as any[]
592
+
593
+ const result = ProviderTransform.message(msgs, mockModel, {})
594
+
595
+ expect(result).toHaveLength(1)
596
+ expect(result[0].content).toHaveLength(2)
597
+ expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
598
+ expect(result[0].content[1]).toEqual({
599
+ type: "text",
600
+ text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
601
+ })
602
+ })
603
+
604
+ test("should keep valid base64 images unchanged", () => {
605
+ const validBase64 =
606
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
607
+ const msgs = [
608
+ {
609
+ role: "user",
610
+ content: [
611
+ { type: "text", text: "What is in this image?" },
612
+ { type: "image", image: `data:image/png;base64,${validBase64}` },
613
+ ],
614
+ },
615
+ ] as any[]
616
+
617
+ const result = ProviderTransform.message(msgs, mockModel, {})
618
+
619
+ expect(result).toHaveLength(1)
620
+ expect(result[0].content).toHaveLength(2)
621
+ expect(result[0].content[0]).toEqual({ type: "text", text: "What is in this image?" })
622
+ expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
623
+ })
624
+
625
+ test("should handle mixed valid and empty images", () => {
626
+ const validBase64 =
627
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
628
+ const msgs = [
629
+ {
630
+ role: "user",
631
+ content: [
632
+ { type: "text", text: "Compare these images" },
633
+ { type: "image", image: `data:image/png;base64,${validBase64}` },
634
+ { type: "image", image: "data:image/jpeg;base64," },
635
+ ],
636
+ },
637
+ ] as any[]
638
+
639
+ const result = ProviderTransform.message(msgs, mockModel, {})
640
+
641
+ expect(result).toHaveLength(1)
642
+ expect(result[0].content).toHaveLength(3)
643
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Compare these images" })
644
+ expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
645
+ expect(result[0].content[2]).toEqual({
646
+ type: "text",
647
+ text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
648
+ })
649
+ })
650
+ })
651
+
652
+ describe("ProviderTransform.message - anthropic empty content filtering", () => {
653
+ const anthropicModel = {
654
+ id: "anthropic/claude-3-5-sonnet",
655
+ providerID: "anthropic",
656
+ api: {
657
+ id: "claude-3-5-sonnet-20241022",
658
+ url: "https://api.anthropic.com",
659
+ npm: "@ai-sdk/anthropic",
660
+ },
661
+ name: "Claude 3.5 Sonnet",
662
+ capabilities: {
663
+ temperature: true,
664
+ reasoning: false,
665
+ attachment: true,
666
+ toolcall: true,
667
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
668
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
669
+ interleaved: false,
670
+ },
671
+ cost: {
672
+ input: 0.003,
673
+ output: 0.015,
674
+ cache: { read: 0.0003, write: 0.00375 },
675
+ },
676
+ limit: {
677
+ context: 200000,
678
+ output: 8192,
679
+ },
680
+ status: "active",
681
+ options: {},
682
+ headers: {},
683
+ } as any
684
+
685
+ test("filters out messages with empty string content", () => {
686
+ const msgs = [
687
+ { role: "user", content: "Hello" },
688
+ { role: "assistant", content: "" },
689
+ { role: "user", content: "World" },
690
+ ] as any[]
691
+
692
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
693
+
694
+ expect(result).toHaveLength(2)
695
+ expect(result[0].content).toBe("Hello")
696
+ expect(result[1].content).toBe("World")
697
+ })
698
+
699
+ test("filters out empty text parts from array content", () => {
700
+ const msgs = [
701
+ {
702
+ role: "assistant",
703
+ content: [
704
+ { type: "text", text: "" },
705
+ { type: "text", text: "Hello" },
706
+ { type: "text", text: "" },
707
+ ],
708
+ },
709
+ ] as any[]
710
+
711
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
712
+
713
+ expect(result).toHaveLength(1)
714
+ expect(result[0].content).toHaveLength(1)
715
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Hello" })
716
+ })
717
+
718
+ test("filters out empty reasoning parts from array content", () => {
719
+ const msgs = [
720
+ {
721
+ role: "assistant",
722
+ content: [
723
+ { type: "reasoning", text: "" },
724
+ { type: "text", text: "Answer" },
725
+ { type: "reasoning", text: "" },
726
+ ],
727
+ },
728
+ ] as any[]
729
+
730
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
731
+
732
+ expect(result).toHaveLength(1)
733
+ expect(result[0].content).toHaveLength(1)
734
+ expect(result[0].content[0]).toEqual({ type: "text", text: "Answer" })
735
+ })
736
+
737
+ test("removes entire message when all parts are empty", () => {
738
+ const msgs = [
739
+ { role: "user", content: "Hello" },
740
+ {
741
+ role: "assistant",
742
+ content: [
743
+ { type: "text", text: "" },
744
+ { type: "reasoning", text: "" },
745
+ ],
746
+ },
747
+ { role: "user", content: "World" },
748
+ ] as any[]
749
+
750
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
751
+
752
+ expect(result).toHaveLength(2)
753
+ expect(result[0].content).toBe("Hello")
754
+ expect(result[1].content).toBe("World")
755
+ })
756
+
757
+ test("keeps non-text/reasoning parts even if text parts are empty", () => {
758
+ const msgs = [
759
+ {
760
+ role: "assistant",
761
+ content: [
762
+ { type: "text", text: "" },
763
+ { type: "tool-call", toolCallId: "123", toolName: "bash", input: { command: "ls" } },
764
+ ],
765
+ },
766
+ ] as any[]
767
+
768
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
769
+
770
+ expect(result).toHaveLength(1)
771
+ expect(result[0].content).toHaveLength(1)
772
+ expect(result[0].content[0]).toEqual({
773
+ type: "tool-call",
774
+ toolCallId: "123",
775
+ toolName: "bash",
776
+ input: { command: "ls" },
777
+ })
778
+ })
779
+
780
+ test("keeps messages with valid text alongside empty parts", () => {
781
+ const msgs = [
782
+ {
783
+ role: "assistant",
784
+ content: [
785
+ { type: "reasoning", text: "Thinking..." },
786
+ { type: "text", text: "" },
787
+ { type: "text", text: "Result" },
788
+ ],
789
+ },
790
+ ] as any[]
791
+
792
+ const result = ProviderTransform.message(msgs, anthropicModel, {})
793
+
794
+ expect(result).toHaveLength(1)
795
+ expect(result[0].content).toHaveLength(2)
796
+ expect(result[0].content[0]).toEqual({ type: "reasoning", text: "Thinking..." })
797
+ expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
798
+ })
799
+
800
+ test("does not filter for non-anthropic providers", () => {
801
+ const openaiModel = {
802
+ ...anthropicModel,
803
+ providerID: "openai",
804
+ api: {
805
+ id: "gpt-4",
806
+ url: "https://api.openai.com",
807
+ npm: "@ai-sdk/openai",
808
+ },
809
+ }
810
+
811
+ const msgs = [
812
+ { role: "assistant", content: "" },
813
+ {
814
+ role: "assistant",
815
+ content: [{ type: "text", text: "" }],
816
+ },
817
+ ] as any[]
818
+
819
+ const result = ProviderTransform.message(msgs, openaiModel, {})
820
+
821
+ expect(result).toHaveLength(2)
822
+ expect(result[0].content).toBe("")
823
+ expect(result[1].content).toHaveLength(1)
824
+ })
825
+ })
826
+
827
+ describe("ProviderTransform.message - strip openai metadata when store=false", () => {
828
+ const openaiModel = {
829
+ id: "openai/gpt-5",
830
+ providerID: "openai",
831
+ api: {
832
+ id: "gpt-5",
833
+ url: "https://api.openai.com",
834
+ npm: "@ai-sdk/openai",
835
+ },
836
+ name: "GPT-5",
837
+ capabilities: {
838
+ temperature: true,
839
+ reasoning: true,
840
+ attachment: true,
841
+ toolcall: true,
842
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
843
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
844
+ interleaved: false,
845
+ },
846
+ cost: { input: 0.03, output: 0.06, cache: { read: 0.001, write: 0.002 } },
847
+ limit: { context: 128000, output: 4096 },
848
+ status: "active",
849
+ options: {},
850
+ headers: {},
851
+ } as any
852
+
853
+ test("preserves itemId and reasoningEncryptedContent when store=false", () => {
854
+ const msgs = [
855
+ {
856
+ role: "assistant",
857
+ content: [
858
+ {
859
+ type: "reasoning",
860
+ text: "thinking...",
861
+ providerOptions: {
862
+ openai: {
863
+ itemId: "rs_123",
864
+ reasoningEncryptedContent: "encrypted",
865
+ },
866
+ },
867
+ },
868
+ {
869
+ type: "text",
870
+ text: "Hello",
871
+ providerOptions: {
872
+ openai: {
873
+ itemId: "msg_456",
874
+ },
875
+ },
876
+ },
877
+ ],
878
+ },
879
+ ] as any[]
880
+
881
+ const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
882
+
883
+ expect(result).toHaveLength(1)
884
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
885
+ expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
886
+ })
887
+
888
+ test("preserves itemId and reasoningEncryptedContent when store=false even when not openai", () => {
889
+ const zenModel = {
890
+ ...openaiModel,
891
+ providerID: "zen",
892
+ }
893
+ const msgs = [
894
+ {
895
+ role: "assistant",
896
+ content: [
897
+ {
898
+ type: "reasoning",
899
+ text: "thinking...",
900
+ providerOptions: {
901
+ openai: {
902
+ itemId: "rs_123",
903
+ reasoningEncryptedContent: "encrypted",
904
+ },
905
+ },
906
+ },
907
+ {
908
+ type: "text",
909
+ text: "Hello",
910
+ providerOptions: {
911
+ openai: {
912
+ itemId: "msg_456",
913
+ },
914
+ },
915
+ },
916
+ ],
917
+ },
918
+ ] as any[]
919
+
920
+ const result = ProviderTransform.message(msgs, zenModel, { store: false }) as any[]
921
+
922
+ expect(result).toHaveLength(1)
923
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("rs_123")
924
+ expect(result[0].content[1].providerOptions?.openai?.itemId).toBe("msg_456")
925
+ })
926
+
927
+ test("preserves other openai options including itemId", () => {
928
+ const msgs = [
929
+ {
930
+ role: "assistant",
931
+ content: [
932
+ {
933
+ type: "text",
934
+ text: "Hello",
935
+ providerOptions: {
936
+ openai: {
937
+ itemId: "msg_123",
938
+ otherOption: "value",
939
+ },
940
+ },
941
+ },
942
+ ],
943
+ },
944
+ ] as any[]
945
+
946
+ const result = ProviderTransform.message(msgs, openaiModel, { store: false }) as any[]
947
+
948
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
949
+ expect(result[0].content[0].providerOptions?.openai?.otherOption).toBe("value")
950
+ })
951
+
952
+ test("preserves metadata for openai package when store is true", () => {
953
+ const msgs = [
954
+ {
955
+ role: "assistant",
956
+ content: [
957
+ {
958
+ type: "text",
959
+ text: "Hello",
960
+ providerOptions: {
961
+ openai: {
962
+ itemId: "msg_123",
963
+ },
964
+ },
965
+ },
966
+ ],
967
+ },
968
+ ] as any[]
969
+
970
+ // openai package preserves itemId regardless of store value
971
+ const result = ProviderTransform.message(msgs, openaiModel, { store: true }) as any[]
972
+
973
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
974
+ })
975
+
976
+ test("preserves metadata for non-openai packages when store is false", () => {
977
+ const anthropicModel = {
978
+ ...openaiModel,
979
+ providerID: "anthropic",
980
+ api: {
981
+ id: "claude-3",
982
+ url: "https://api.anthropic.com",
983
+ npm: "@ai-sdk/anthropic",
984
+ },
985
+ }
986
+ const msgs = [
987
+ {
988
+ role: "assistant",
989
+ content: [
990
+ {
991
+ type: "text",
992
+ text: "Hello",
993
+ providerOptions: {
994
+ openai: {
995
+ itemId: "msg_123",
996
+ },
997
+ },
998
+ },
999
+ ],
1000
+ },
1001
+ ] as any[]
1002
+
1003
+ // store=false preserves metadata for non-openai packages
1004
+ const result = ProviderTransform.message(msgs, anthropicModel, { store: false }) as any[]
1005
+
1006
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1007
+ })
1008
+
1009
+ test("preserves metadata using providerID key when store is false", () => {
1010
+ const opencodeModel = {
1011
+ ...openaiModel,
1012
+ providerID: "opencode",
1013
+ api: {
1014
+ id: "opencode-test",
1015
+ url: "https://api.opencode.ai",
1016
+ npm: "@ai-sdk/openai-compatible",
1017
+ },
1018
+ }
1019
+ const msgs = [
1020
+ {
1021
+ role: "assistant",
1022
+ content: [
1023
+ {
1024
+ type: "text",
1025
+ text: "Hello",
1026
+ providerOptions: {
1027
+ opencode: {
1028
+ itemId: "msg_123",
1029
+ otherOption: "value",
1030
+ },
1031
+ },
1032
+ },
1033
+ ],
1034
+ },
1035
+ ] as any[]
1036
+
1037
+ const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
1038
+
1039
+ expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_123")
1040
+ expect(result[0].content[0].providerOptions?.opencode?.otherOption).toBe("value")
1041
+ })
1042
+
1043
+ test("preserves itemId across all providerOptions keys", () => {
1044
+ const opencodeModel = {
1045
+ ...openaiModel,
1046
+ providerID: "opencode",
1047
+ api: {
1048
+ id: "opencode-test",
1049
+ url: "https://api.opencode.ai",
1050
+ npm: "@ai-sdk/openai-compatible",
1051
+ },
1052
+ }
1053
+ const msgs = [
1054
+ {
1055
+ role: "assistant",
1056
+ providerOptions: {
1057
+ openai: { itemId: "msg_root" },
1058
+ opencode: { itemId: "msg_opencode" },
1059
+ extra: { itemId: "msg_extra" },
1060
+ },
1061
+ content: [
1062
+ {
1063
+ type: "text",
1064
+ text: "Hello",
1065
+ providerOptions: {
1066
+ openai: { itemId: "msg_openai_part" },
1067
+ opencode: { itemId: "msg_opencode_part" },
1068
+ extra: { itemId: "msg_extra_part" },
1069
+ },
1070
+ },
1071
+ ],
1072
+ },
1073
+ ] as any[]
1074
+
1075
+ const result = ProviderTransform.message(msgs, opencodeModel, { store: false }) as any[]
1076
+
1077
+ expect(result[0].providerOptions?.openai?.itemId).toBe("msg_root")
1078
+ expect(result[0].providerOptions?.opencode?.itemId).toBe("msg_opencode")
1079
+ expect(result[0].providerOptions?.extra?.itemId).toBe("msg_extra")
1080
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_openai_part")
1081
+ expect(result[0].content[0].providerOptions?.opencode?.itemId).toBe("msg_opencode_part")
1082
+ expect(result[0].content[0].providerOptions?.extra?.itemId).toBe("msg_extra_part")
1083
+ })
1084
+
1085
+ test("does not strip metadata for non-openai packages when store is not false", () => {
1086
+ const anthropicModel = {
1087
+ ...openaiModel,
1088
+ providerID: "anthropic",
1089
+ api: {
1090
+ id: "claude-3",
1091
+ url: "https://api.anthropic.com",
1092
+ npm: "@ai-sdk/anthropic",
1093
+ },
1094
+ }
1095
+ const msgs = [
1096
+ {
1097
+ role: "assistant",
1098
+ content: [
1099
+ {
1100
+ type: "text",
1101
+ text: "Hello",
1102
+ providerOptions: {
1103
+ openai: {
1104
+ itemId: "msg_123",
1105
+ },
1106
+ },
1107
+ },
1108
+ ],
1109
+ },
1110
+ ] as any[]
1111
+
1112
+ const result = ProviderTransform.message(msgs, anthropicModel, {}) as any[]
1113
+
1114
+ expect(result[0].content[0].providerOptions?.openai?.itemId).toBe("msg_123")
1115
+ })
1116
+ })
1117
+
1118
+ describe("ProviderTransform.message - providerOptions key remapping", () => {
1119
+ const createModel = (providerID: string, npm: string) =>
1120
+ ({
1121
+ id: `${providerID}/test-model`,
1122
+ providerID,
1123
+ api: {
1124
+ id: "test-model",
1125
+ url: "https://api.test.com",
1126
+ npm,
1127
+ },
1128
+ name: "Test Model",
1129
+ capabilities: {
1130
+ temperature: true,
1131
+ reasoning: false,
1132
+ attachment: true,
1133
+ toolcall: true,
1134
+ input: { text: true, audio: false, image: true, video: false, pdf: true },
1135
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1136
+ interleaved: false,
1137
+ },
1138
+ cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
1139
+ limit: { context: 128000, output: 8192 },
1140
+ status: "active",
1141
+ options: {},
1142
+ headers: {},
1143
+ }) as any
1144
+
1145
+ test("azure keeps 'azure' key and does not remap to 'openai'", () => {
1146
+ const model = createModel("azure", "@ai-sdk/azure")
1147
+ const msgs = [
1148
+ {
1149
+ role: "user",
1150
+ content: "Hello",
1151
+ providerOptions: {
1152
+ azure: { someOption: "value" },
1153
+ },
1154
+ },
1155
+ ] as any[]
1156
+
1157
+ const result = ProviderTransform.message(msgs, model, {})
1158
+
1159
+ expect(result[0].providerOptions?.azure).toEqual({ someOption: "value" })
1160
+ expect(result[0].providerOptions?.openai).toBeUndefined()
1161
+ })
1162
+
1163
+ test("copilot remaps providerID to 'copilot' key", () => {
1164
+ const model = createModel("github-copilot", "@ai-sdk/github-copilot")
1165
+ const msgs = [
1166
+ {
1167
+ role: "user",
1168
+ content: "Hello",
1169
+ providerOptions: {
1170
+ copilot: { someOption: "value" },
1171
+ },
1172
+ },
1173
+ ] as any[]
1174
+
1175
+ const result = ProviderTransform.message(msgs, model, {})
1176
+
1177
+ expect(result[0].providerOptions?.copilot).toEqual({ someOption: "value" })
1178
+ expect(result[0].providerOptions?.["github-copilot"]).toBeUndefined()
1179
+ })
1180
+
1181
+ test("bedrock remaps providerID to 'bedrock' key", () => {
1182
+ const model = createModel("my-bedrock", "@ai-sdk/amazon-bedrock")
1183
+ const msgs = [
1184
+ {
1185
+ role: "user",
1186
+ content: "Hello",
1187
+ providerOptions: {
1188
+ "my-bedrock": { someOption: "value" },
1189
+ },
1190
+ },
1191
+ ] as any[]
1192
+
1193
+ const result = ProviderTransform.message(msgs, model, {})
1194
+
1195
+ expect(result[0].providerOptions?.bedrock).toEqual({ someOption: "value" })
1196
+ expect(result[0].providerOptions?.["my-bedrock"]).toBeUndefined()
1197
+ })
1198
+ })
1199
+
1200
+ describe("ProviderTransform.message - claude w/bedrock custom inference profile", () => {
1201
+ test("adds cachePoint", () => {
1202
+ const model = {
1203
+ id: "amazon-bedrock/custom-claude-sonnet-4.5",
1204
+ providerID: "amazon-bedrock",
1205
+ api: {
1206
+ id: "arn:aws:bedrock:xxx:yyy:application-inference-profile/zzz",
1207
+ url: "https://api.test.com",
1208
+ npm: "@ai-sdk/amazon-bedrock",
1209
+ },
1210
+ name: "Custom inference profile",
1211
+ capabilities: {},
1212
+ options: {},
1213
+ headers: {},
1214
+ } as any
1215
+
1216
+ const msgs = [
1217
+ {
1218
+ role: "user",
1219
+ content: "Hello",
1220
+ },
1221
+ ] as any[]
1222
+
1223
+ const result = ProviderTransform.message(msgs, model, {})
1224
+
1225
+ expect(result[0].providerOptions?.bedrock).toEqual(
1226
+ expect.objectContaining({
1227
+ cachePoint: {
1228
+ type: "default",
1229
+ },
1230
+ }),
1231
+ )
1232
+ })
1233
+ })
1234
+
1235
+ describe("ProviderTransform.variants", () => {
1236
+ const createMockModel = (overrides: Partial<any> = {}): any => ({
1237
+ id: "test/test-model",
1238
+ providerID: "test",
1239
+ api: {
1240
+ id: "test-model",
1241
+ url: "https://api.test.com",
1242
+ npm: "@ai-sdk/openai",
1243
+ },
1244
+ name: "Test Model",
1245
+ capabilities: {
1246
+ temperature: true,
1247
+ reasoning: true,
1248
+ attachment: true,
1249
+ toolcall: true,
1250
+ input: { text: true, audio: false, image: true, video: false, pdf: false },
1251
+ output: { text: true, audio: false, image: false, video: false, pdf: false },
1252
+ interleaved: false,
1253
+ },
1254
+ cost: {
1255
+ input: 0.001,
1256
+ output: 0.002,
1257
+ cache: { read: 0.0001, write: 0.0002 },
1258
+ },
1259
+ limit: {
1260
+ context: 200_000,
1261
+ output: 64_000,
1262
+ },
1263
+ status: "active",
1264
+ options: {},
1265
+ headers: {},
1266
+ release_date: "2024-01-01",
1267
+ ...overrides,
1268
+ })
1269
+
1270
+ test("returns empty object when model has no reasoning capabilities", () => {
1271
+ const model = createMockModel({
1272
+ capabilities: { reasoning: false },
1273
+ })
1274
+ const result = ProviderTransform.variants(model)
1275
+ expect(result).toEqual({})
1276
+ })
1277
+
1278
+ test("deepseek returns empty object", () => {
1279
+ const model = createMockModel({
1280
+ id: "deepseek/deepseek-chat",
1281
+ providerID: "deepseek",
1282
+ api: {
1283
+ id: "deepseek-chat",
1284
+ url: "https://api.deepseek.com",
1285
+ npm: "@ai-sdk/openai-compatible",
1286
+ },
1287
+ })
1288
+ const result = ProviderTransform.variants(model)
1289
+ expect(result).toEqual({})
1290
+ })
1291
+
1292
+ test("minimax returns empty object", () => {
1293
+ const model = createMockModel({
1294
+ id: "minimax/minimax-model",
1295
+ providerID: "minimax",
1296
+ api: {
1297
+ id: "minimax-model",
1298
+ url: "https://api.minimax.com",
1299
+ npm: "@ai-sdk/openai-compatible",
1300
+ },
1301
+ })
1302
+ const result = ProviderTransform.variants(model)
1303
+ expect(result).toEqual({})
1304
+ })
1305
+
1306
+ test("glm returns empty object", () => {
1307
+ const model = createMockModel({
1308
+ id: "glm/glm-4",
1309
+ providerID: "glm",
1310
+ api: {
1311
+ id: "glm-4",
1312
+ url: "https://api.glm.com",
1313
+ npm: "@ai-sdk/openai-compatible",
1314
+ },
1315
+ })
1316
+ const result = ProviderTransform.variants(model)
1317
+ expect(result).toEqual({})
1318
+ })
1319
+
1320
+ test("mistral returns empty object", () => {
1321
+ const model = createMockModel({
1322
+ id: "mistral/mistral-large",
1323
+ providerID: "mistral",
1324
+ api: {
1325
+ id: "mistral-large-latest",
1326
+ url: "https://api.mistral.com",
1327
+ npm: "@ai-sdk/mistral",
1328
+ },
1329
+ })
1330
+ const result = ProviderTransform.variants(model)
1331
+ expect(result).toEqual({})
1332
+ })
1333
+
1334
+ describe("@openrouter/ai-sdk-provider", () => {
1335
+ test("returns empty object for non-qualifying models", () => {
1336
+ const model = createMockModel({
1337
+ id: "openrouter/test-model",
1338
+ providerID: "openrouter",
1339
+ api: {
1340
+ id: "test-model",
1341
+ url: "https://openrouter.ai",
1342
+ npm: "@openrouter/ai-sdk-provider",
1343
+ },
1344
+ })
1345
+ const result = ProviderTransform.variants(model)
1346
+ expect(result).toEqual({})
1347
+ })
1348
+
1349
+ test("gpt models return OPENAI_EFFORTS with reasoning", () => {
1350
+ const model = createMockModel({
1351
+ id: "openrouter/gpt-4",
1352
+ providerID: "openrouter",
1353
+ api: {
1354
+ id: "gpt-4",
1355
+ url: "https://openrouter.ai",
1356
+ npm: "@openrouter/ai-sdk-provider",
1357
+ },
1358
+ })
1359
+ const result = ProviderTransform.variants(model)
1360
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1361
+ expect(result.low).toEqual({ reasoning: { effort: "low" } })
1362
+ expect(result.high).toEqual({ reasoning: { effort: "high" } })
1363
+ })
1364
+
1365
+ test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
1366
+ const model = createMockModel({
1367
+ id: "openrouter/gemini-3-5-pro",
1368
+ providerID: "openrouter",
1369
+ api: {
1370
+ id: "gemini-3-5-pro",
1371
+ url: "https://openrouter.ai",
1372
+ npm: "@openrouter/ai-sdk-provider",
1373
+ },
1374
+ })
1375
+ const result = ProviderTransform.variants(model)
1376
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1377
+ })
1378
+
1379
+ test("grok-4 returns empty object", () => {
1380
+ const model = createMockModel({
1381
+ id: "openrouter/grok-4",
1382
+ providerID: "openrouter",
1383
+ api: {
1384
+ id: "grok-4",
1385
+ url: "https://openrouter.ai",
1386
+ npm: "@openrouter/ai-sdk-provider",
1387
+ },
1388
+ })
1389
+ const result = ProviderTransform.variants(model)
1390
+ expect(result).toEqual({})
1391
+ })
1392
+
1393
+ test("grok-3-mini returns low and high with reasoning", () => {
1394
+ const model = createMockModel({
1395
+ id: "openrouter/grok-3-mini",
1396
+ providerID: "openrouter",
1397
+ api: {
1398
+ id: "grok-3-mini",
1399
+ url: "https://openrouter.ai",
1400
+ npm: "@openrouter/ai-sdk-provider",
1401
+ },
1402
+ })
1403
+ const result = ProviderTransform.variants(model)
1404
+ expect(Object.keys(result)).toEqual(["low", "high"])
1405
+ expect(result.low).toEqual({ reasoning: { effort: "low" } })
1406
+ expect(result.high).toEqual({ reasoning: { effort: "high" } })
1407
+ })
1408
+ })
1409
+
1410
+ describe("@ai-sdk/gateway", () => {
1411
+ test("returns OPENAI_EFFORTS with reasoningEffort", () => {
1412
+ const model = createMockModel({
1413
+ id: "gateway/gateway-model",
1414
+ providerID: "gateway",
1415
+ api: {
1416
+ id: "gateway-model",
1417
+ url: "https://gateway.ai",
1418
+ npm: "@ai-sdk/gateway",
1419
+ },
1420
+ })
1421
+ const result = ProviderTransform.variants(model)
1422
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1423
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1424
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1425
+ })
1426
+ })
1427
+
1428
+ describe("@ai-sdk/github-copilot", () => {
1429
+ test("standard models return low, medium, high", () => {
1430
+ const model = createMockModel({
1431
+ id: "gpt-4.5",
1432
+ providerID: "github-copilot",
1433
+ api: {
1434
+ id: "gpt-4.5",
1435
+ url: "https://api.githubcopilot.com",
1436
+ npm: "@ai-sdk/github-copilot",
1437
+ },
1438
+ })
1439
+ const result = ProviderTransform.variants(model)
1440
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1441
+ expect(result.low).toEqual({
1442
+ reasoningEffort: "low",
1443
+ reasoningSummary: "auto",
1444
+ include: ["reasoning.encrypted_content"],
1445
+ })
1446
+ })
1447
+
1448
+ test("gpt-5.1-codex-max includes xhigh", () => {
1449
+ const model = createMockModel({
1450
+ id: "gpt-5.1-codex-max",
1451
+ providerID: "github-copilot",
1452
+ api: {
1453
+ id: "gpt-5.1-codex-max",
1454
+ url: "https://api.githubcopilot.com",
1455
+ npm: "@ai-sdk/github-copilot",
1456
+ },
1457
+ })
1458
+ const result = ProviderTransform.variants(model)
1459
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
1460
+ })
1461
+
1462
+ test("gpt-5.1-codex-mini does not include xhigh", () => {
1463
+ const model = createMockModel({
1464
+ id: "gpt-5.1-codex-mini",
1465
+ providerID: "github-copilot",
1466
+ api: {
1467
+ id: "gpt-5.1-codex-mini",
1468
+ url: "https://api.githubcopilot.com",
1469
+ npm: "@ai-sdk/github-copilot",
1470
+ },
1471
+ })
1472
+ const result = ProviderTransform.variants(model)
1473
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1474
+ })
1475
+
1476
+ test("gpt-5.1-codex does not include xhigh", () => {
1477
+ const model = createMockModel({
1478
+ id: "gpt-5.1-codex",
1479
+ providerID: "github-copilot",
1480
+ api: {
1481
+ id: "gpt-5.1-codex",
1482
+ url: "https://api.githubcopilot.com",
1483
+ npm: "@ai-sdk/github-copilot",
1484
+ },
1485
+ })
1486
+ const result = ProviderTransform.variants(model)
1487
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1488
+ })
1489
+
1490
+ test("gpt-5.2 includes xhigh", () => {
1491
+ const model = createMockModel({
1492
+ id: "gpt-5.2",
1493
+ providerID: "github-copilot",
1494
+ api: {
1495
+ id: "gpt-5.2",
1496
+ url: "https://api.githubcopilot.com",
1497
+ npm: "@ai-sdk/github-copilot",
1498
+ },
1499
+ })
1500
+ const result = ProviderTransform.variants(model)
1501
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
1502
+ expect(result.xhigh).toEqual({
1503
+ reasoningEffort: "xhigh",
1504
+ reasoningSummary: "auto",
1505
+ include: ["reasoning.encrypted_content"],
1506
+ })
1507
+ })
1508
+
1509
+ test("gpt-5.2-codex includes xhigh", () => {
1510
+ const model = createMockModel({
1511
+ id: "gpt-5.2-codex",
1512
+ providerID: "github-copilot",
1513
+ api: {
1514
+ id: "gpt-5.2-codex",
1515
+ url: "https://api.githubcopilot.com",
1516
+ npm: "@ai-sdk/github-copilot",
1517
+ },
1518
+ })
1519
+ const result = ProviderTransform.variants(model)
1520
+ expect(Object.keys(result)).toEqual(["low", "medium", "high", "xhigh"])
1521
+ })
1522
+ })
1523
+
1524
+ describe("@ai-sdk/cerebras", () => {
1525
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
1526
+ const model = createMockModel({
1527
+ id: "cerebras/llama-4",
1528
+ providerID: "cerebras",
1529
+ api: {
1530
+ id: "llama-4-sc",
1531
+ url: "https://api.cerebras.ai",
1532
+ npm: "@ai-sdk/cerebras",
1533
+ },
1534
+ })
1535
+ const result = ProviderTransform.variants(model)
1536
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1537
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1538
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1539
+ })
1540
+ })
1541
+
1542
+ describe("@ai-sdk/togetherai", () => {
1543
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
1544
+ const model = createMockModel({
1545
+ id: "togetherai/llama-4",
1546
+ providerID: "togetherai",
1547
+ api: {
1548
+ id: "llama-4-sc",
1549
+ url: "https://api.togetherai.com",
1550
+ npm: "@ai-sdk/togetherai",
1551
+ },
1552
+ })
1553
+ const result = ProviderTransform.variants(model)
1554
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1555
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1556
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1557
+ })
1558
+ })
1559
+
1560
+ describe("@ai-sdk/xai", () => {
1561
+ test("grok-3 returns empty object", () => {
1562
+ const model = createMockModel({
1563
+ id: "xai/grok-3",
1564
+ providerID: "xai",
1565
+ api: {
1566
+ id: "grok-3",
1567
+ url: "https://api.x.ai",
1568
+ npm: "@ai-sdk/xai",
1569
+ },
1570
+ })
1571
+ const result = ProviderTransform.variants(model)
1572
+ expect(result).toEqual({})
1573
+ })
1574
+
1575
+ test("grok-3-mini returns low and high with reasoningEffort", () => {
1576
+ const model = createMockModel({
1577
+ id: "xai/grok-3-mini",
1578
+ providerID: "xai",
1579
+ api: {
1580
+ id: "grok-3-mini",
1581
+ url: "https://api.x.ai",
1582
+ npm: "@ai-sdk/xai",
1583
+ },
1584
+ })
1585
+ const result = ProviderTransform.variants(model)
1586
+ expect(Object.keys(result)).toEqual(["low", "high"])
1587
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1588
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1589
+ })
1590
+ })
1591
+
1592
+ describe("@ai-sdk/deepinfra", () => {
1593
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
1594
+ const model = createMockModel({
1595
+ id: "deepinfra/llama-4",
1596
+ providerID: "deepinfra",
1597
+ api: {
1598
+ id: "llama-4-sc",
1599
+ url: "https://api.deepinfra.com",
1600
+ npm: "@ai-sdk/deepinfra",
1601
+ },
1602
+ })
1603
+ const result = ProviderTransform.variants(model)
1604
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1605
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1606
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1607
+ })
1608
+ })
1609
+
1610
+ describe("@ai-sdk/openai-compatible", () => {
1611
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningEffort", () => {
1612
+ const model = createMockModel({
1613
+ id: "custom-provider/custom-model",
1614
+ providerID: "custom-provider",
1615
+ api: {
1616
+ id: "custom-model",
1617
+ url: "https://api.custom.com",
1618
+ npm: "@ai-sdk/openai-compatible",
1619
+ },
1620
+ })
1621
+ const result = ProviderTransform.variants(model)
1622
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1623
+ expect(result.low).toEqual({ reasoningEffort: "low" })
1624
+ expect(result.high).toEqual({ reasoningEffort: "high" })
1625
+ })
1626
+ })
1627
+
1628
+ describe("@ai-sdk/azure", () => {
1629
+ test("o1-mini returns empty object", () => {
1630
+ const model = createMockModel({
1631
+ id: "o1-mini",
1632
+ providerID: "azure",
1633
+ api: {
1634
+ id: "o1-mini",
1635
+ url: "https://azure.com",
1636
+ npm: "@ai-sdk/azure",
1637
+ },
1638
+ })
1639
+ const result = ProviderTransform.variants(model)
1640
+ expect(result).toEqual({})
1641
+ })
1642
+
1643
+ test("standard azure models return custom efforts with reasoningSummary", () => {
1644
+ const model = createMockModel({
1645
+ id: "o1",
1646
+ providerID: "azure",
1647
+ api: {
1648
+ id: "o1",
1649
+ url: "https://azure.com",
1650
+ npm: "@ai-sdk/azure",
1651
+ },
1652
+ })
1653
+ const result = ProviderTransform.variants(model)
1654
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1655
+ expect(result.low).toEqual({
1656
+ reasoningEffort: "low",
1657
+ reasoningSummary: "auto",
1658
+ include: ["reasoning.encrypted_content"],
1659
+ })
1660
+ })
1661
+
1662
+ test("gpt-5 adds minimal effort", () => {
1663
+ const model = createMockModel({
1664
+ id: "gpt-5",
1665
+ providerID: "azure",
1666
+ api: {
1667
+ id: "gpt-5",
1668
+ url: "https://azure.com",
1669
+ npm: "@ai-sdk/azure",
1670
+ },
1671
+ })
1672
+ const result = ProviderTransform.variants(model)
1673
+ expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
1674
+ })
1675
+ })
1676
+
1677
+ describe("@ai-sdk/openai", () => {
1678
+ test("gpt-5-pro returns empty object", () => {
1679
+ const model = createMockModel({
1680
+ id: "gpt-5-pro",
1681
+ providerID: "openai",
1682
+ api: {
1683
+ id: "gpt-5-pro",
1684
+ url: "https://api.openai.com",
1685
+ npm: "@ai-sdk/openai",
1686
+ },
1687
+ })
1688
+ const result = ProviderTransform.variants(model)
1689
+ expect(result).toEqual({})
1690
+ })
1691
+
1692
+ test("standard openai models return custom efforts with reasoningSummary", () => {
1693
+ const model = createMockModel({
1694
+ id: "gpt-5",
1695
+ providerID: "openai",
1696
+ api: {
1697
+ id: "gpt-5",
1698
+ url: "https://api.openai.com",
1699
+ npm: "@ai-sdk/openai",
1700
+ },
1701
+ release_date: "2024-06-01",
1702
+ })
1703
+ const result = ProviderTransform.variants(model)
1704
+ expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
1705
+ expect(result.low).toEqual({
1706
+ reasoningEffort: "low",
1707
+ reasoningSummary: "auto",
1708
+ include: ["reasoning.encrypted_content"],
1709
+ })
1710
+ })
1711
+
1712
+ test("models after 2025-11-13 include 'none' effort", () => {
1713
+ const model = createMockModel({
1714
+ id: "gpt-5-nano",
1715
+ providerID: "openai",
1716
+ api: {
1717
+ id: "gpt-5-nano",
1718
+ url: "https://api.openai.com",
1719
+ npm: "@ai-sdk/openai",
1720
+ },
1721
+ release_date: "2025-11-14",
1722
+ })
1723
+ const result = ProviderTransform.variants(model)
1724
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high"])
1725
+ })
1726
+
1727
+ test("models after 2025-12-04 include 'xhigh' effort", () => {
1728
+ const model = createMockModel({
1729
+ id: "openai/gpt-5-chat",
1730
+ providerID: "openai",
1731
+ api: {
1732
+ id: "gpt-5-chat",
1733
+ url: "https://api.openai.com",
1734
+ npm: "@ai-sdk/openai",
1735
+ },
1736
+ release_date: "2025-12-05",
1737
+ })
1738
+ const result = ProviderTransform.variants(model)
1739
+ expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
1740
+ })
1741
+ })
1742
+
1743
+ describe("@ai-sdk/anthropic", () => {
1744
+ test("returns high and max with thinking config", () => {
1745
+ const model = createMockModel({
1746
+ id: "anthropic/claude-4",
1747
+ providerID: "anthropic",
1748
+ api: {
1749
+ id: "claude-4",
1750
+ url: "https://api.anthropic.com",
1751
+ npm: "@ai-sdk/anthropic",
1752
+ },
1753
+ })
1754
+ const result = ProviderTransform.variants(model)
1755
+ expect(Object.keys(result)).toEqual(["high", "max"])
1756
+ expect(result.high).toEqual({
1757
+ thinking: {
1758
+ type: "enabled",
1759
+ budgetTokens: 16000,
1760
+ },
1761
+ })
1762
+ expect(result.max).toEqual({
1763
+ thinking: {
1764
+ type: "enabled",
1765
+ budgetTokens: 31999,
1766
+ },
1767
+ })
1768
+ })
1769
+ })
1770
+
1771
+ describe("@ai-sdk/amazon-bedrock", () => {
1772
+ test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
1773
+ const model = createMockModel({
1774
+ id: "bedrock/llama-4",
1775
+ providerID: "bedrock",
1776
+ api: {
1777
+ id: "llama-4-sc",
1778
+ url: "https://bedrock.amazonaws.com",
1779
+ npm: "@ai-sdk/amazon-bedrock",
1780
+ },
1781
+ })
1782
+ const result = ProviderTransform.variants(model)
1783
+ expect(Object.keys(result)).toEqual(["low", "medium", "high"])
1784
+ expect(result.low).toEqual({
1785
+ reasoningConfig: {
1786
+ type: "enabled",
1787
+ maxReasoningEffort: "low",
1788
+ },
1789
+ })
1790
+ })
1791
+ })
1792
+
1793
+ describe("@ai-sdk/google", () => {
1794
+ test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
1795
+ const model = createMockModel({
1796
+ id: "google/gemini-2.5-pro",
1797
+ providerID: "google",
1798
+ api: {
1799
+ id: "gemini-2.5-pro",
1800
+ url: "https://generativelanguage.googleapis.com",
1801
+ npm: "@ai-sdk/google",
1802
+ },
1803
+ })
1804
+ const result = ProviderTransform.variants(model)
1805
+ expect(Object.keys(result)).toEqual(["high", "max"])
1806
+ expect(result.high).toEqual({
1807
+ thinkingConfig: {
1808
+ includeThoughts: true,
1809
+ thinkingBudget: 16000,
1810
+ },
1811
+ })
1812
+ expect(result.max).toEqual({
1813
+ thinkingConfig: {
1814
+ includeThoughts: true,
1815
+ thinkingBudget: 24576,
1816
+ },
1817
+ })
1818
+ })
1819
+
1820
+ test("other gemini models return low and high with thinkingLevel", () => {
1821
+ const model = createMockModel({
1822
+ id: "google/gemini-2.0-pro",
1823
+ providerID: "google",
1824
+ api: {
1825
+ id: "gemini-2.0-pro",
1826
+ url: "https://generativelanguage.googleapis.com",
1827
+ npm: "@ai-sdk/google",
1828
+ },
1829
+ })
1830
+ const result = ProviderTransform.variants(model)
1831
+ expect(Object.keys(result)).toEqual(["low", "high"])
1832
+ expect(result.low).toEqual({
1833
+ includeThoughts: true,
1834
+ thinkingLevel: "low",
1835
+ })
1836
+ expect(result.high).toEqual({
1837
+ includeThoughts: true,
1838
+ thinkingLevel: "high",
1839
+ })
1840
+ })
1841
+ })
1842
+
1843
+ describe("@ai-sdk/google-vertex", () => {
1844
+ test("gemini-2.5 returns high and max with thinkingConfig and thinkingBudget", () => {
1845
+ const model = createMockModel({
1846
+ id: "google-vertex/gemini-2.5-pro",
1847
+ providerID: "google-vertex",
1848
+ api: {
1849
+ id: "gemini-2.5-pro",
1850
+ url: "https://vertexai.googleapis.com",
1851
+ npm: "@ai-sdk/google-vertex",
1852
+ },
1853
+ })
1854
+ const result = ProviderTransform.variants(model)
1855
+ expect(Object.keys(result)).toEqual(["high", "max"])
1856
+ })
1857
+
1858
+ test("other vertex models return low and high with thinkingLevel", () => {
1859
+ const model = createMockModel({
1860
+ id: "google-vertex/gemini-2.0-pro",
1861
+ providerID: "google-vertex",
1862
+ api: {
1863
+ id: "gemini-2.0-pro",
1864
+ url: "https://vertexai.googleapis.com",
1865
+ npm: "@ai-sdk/google-vertex",
1866
+ },
1867
+ })
1868
+ const result = ProviderTransform.variants(model)
1869
+ expect(Object.keys(result)).toEqual(["low", "high"])
1870
+ })
1871
+ })
1872
+
1873
+ describe("@ai-sdk/cohere", () => {
1874
+ test("returns empty object", () => {
1875
+ const model = createMockModel({
1876
+ id: "cohere/command-r",
1877
+ providerID: "cohere",
1878
+ api: {
1879
+ id: "command-r",
1880
+ url: "https://api.cohere.com",
1881
+ npm: "@ai-sdk/cohere",
1882
+ },
1883
+ })
1884
+ const result = ProviderTransform.variants(model)
1885
+ expect(result).toEqual({})
1886
+ })
1887
+ })
1888
+
1889
+ describe("@ai-sdk/groq", () => {
1890
+ test("returns none and WIDELY_SUPPORTED_EFFORTS with thinkingLevel", () => {
1891
+ const model = createMockModel({
1892
+ id: "groq/llama-4",
1893
+ providerID: "groq",
1894
+ api: {
1895
+ id: "llama-4-sc",
1896
+ url: "https://api.groq.com",
1897
+ npm: "@ai-sdk/groq",
1898
+ },
1899
+ })
1900
+ const result = ProviderTransform.variants(model)
1901
+ expect(Object.keys(result)).toEqual(["none", "low", "medium", "high"])
1902
+ expect(result.none).toEqual({
1903
+ includeThoughts: true,
1904
+ thinkingLevel: "none",
1905
+ })
1906
+ expect(result.low).toEqual({
1907
+ includeThoughts: true,
1908
+ thinkingLevel: "low",
1909
+ })
1910
+ })
1911
+ })
1912
+
1913
+ describe("@ai-sdk/perplexity", () => {
1914
+ test("returns empty object", () => {
1915
+ const model = createMockModel({
1916
+ id: "perplexity/sonar-plus",
1917
+ providerID: "perplexity",
1918
+ api: {
1919
+ id: "sonar-plus",
1920
+ url: "https://api.perplexity.ai",
1921
+ npm: "@ai-sdk/perplexity",
1922
+ },
1923
+ })
1924
+ const result = ProviderTransform.variants(model)
1925
+ expect(result).toEqual({})
1926
+ })
1927
+ })
1928
+ })