@toolkit-cli/toolkode 1.3.7 → 1.3.9

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 (674) hide show
  1. package/package.json +18 -151
  2. package/{script/postinstall.mjs → postinstall.mjs} +5 -5
  3. package/AGENTS.md +0 -69
  4. package/BUN_SHELL_MIGRATION_PLAN.md +0 -136
  5. package/Dockerfile +0 -18
  6. package/README.md +0 -15
  7. package/bin/opencode +0 -179
  8. package/bunfig.toml +0 -7
  9. package/drizzle.config.ts +0 -10
  10. package/git +0 -0
  11. package/migration/20260127222353_familiar_lady_ursula/migration.sql +0 -90
  12. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +0 -796
  13. package/migration/20260211171708_add_project_commands/migration.sql +0 -1
  14. package/migration/20260211171708_add_project_commands/snapshot.json +0 -806
  15. package/migration/20260213144116_wakeful_the_professor/migration.sql +0 -11
  16. package/migration/20260213144116_wakeful_the_professor/snapshot.json +0 -897
  17. package/migration/20260225215848_workspace/migration.sql +0 -7
  18. package/migration/20260225215848_workspace/snapshot.json +0 -959
  19. package/migration/20260227213759_add_session_workspace_id/migration.sql +0 -2
  20. package/migration/20260227213759_add_session_workspace_id/snapshot.json +0 -983
  21. package/migration/20260228203230_blue_harpoon/migration.sql +0 -17
  22. package/migration/20260228203230_blue_harpoon/snapshot.json +0 -1102
  23. package/migration/20260303231226_add_workspace_fields/migration.sql +0 -5
  24. package/migration/20260303231226_add_workspace_fields/snapshot.json +0 -1013
  25. package/migration/20260309230000_move_org_to_state/migration.sql +0 -3
  26. package/migration/20260309230000_move_org_to_state/snapshot.json +0 -1156
  27. package/migration/20260312043431_session_message_cursor/migration.sql +0 -4
  28. package/migration/20260312043431_session_message_cursor/snapshot.json +0 -1168
  29. package/migration/20260323234822_events/migration.sql +0 -13
  30. package/migration/20260323234822_events/snapshot.json +0 -1271
  31. package/parsers-config.ts +0 -290
  32. package/script/build-node.ts +0 -54
  33. package/script/build.ts +0 -276
  34. package/script/check-migrations.ts +0 -16
  35. package/script/publish.ts +0 -181
  36. package/script/schema.ts +0 -63
  37. package/script/seed-e2e.ts +0 -60
  38. package/script/upgrade-opentui.ts +0 -64
  39. package/specs/effect-migration.md +0 -293
  40. package/specs/tui-plugins.md +0 -389
  41. package/src/account/account.sql.ts +0 -39
  42. package/src/account/index.ts +0 -397
  43. package/src/account/repo.ts +0 -163
  44. package/src/account/schema.ts +0 -91
  45. package/src/acp/README.md +0 -174
  46. package/src/acp/agent.ts +0 -1743
  47. package/src/acp/session.ts +0 -116
  48. package/src/acp/types.ts +0 -24
  49. package/src/agent/agent.ts +0 -418
  50. package/src/agent/generate.txt +0 -75
  51. package/src/agent/prompt/compaction.txt +0 -14
  52. package/src/agent/prompt/explore.txt +0 -18
  53. package/src/agent/prompt/summary.txt +0 -11
  54. package/src/agent/prompt/title.txt +0 -44
  55. package/src/auth/index.ts +0 -115
  56. package/src/bun/index.ts +0 -128
  57. package/src/bun/registry.ts +0 -50
  58. package/src/bus/bus-event.ts +0 -40
  59. package/src/bus/global.ts +0 -10
  60. package/src/bus/index.ts +0 -184
  61. package/src/channel/index.ts +0 -231
  62. package/src/cli/bootstrap.ts +0 -17
  63. package/src/cli/cmd/account.ts +0 -257
  64. package/src/cli/cmd/acp.ts +0 -70
  65. package/src/cli/cmd/agent.ts +0 -245
  66. package/src/cli/cmd/cmd.ts +0 -7
  67. package/src/cli/cmd/db.ts +0 -119
  68. package/src/cli/cmd/debug/agent.ts +0 -167
  69. package/src/cli/cmd/debug/config.ts +0 -16
  70. package/src/cli/cmd/debug/file.ts +0 -97
  71. package/src/cli/cmd/debug/index.ts +0 -48
  72. package/src/cli/cmd/debug/lsp.ts +0 -53
  73. package/src/cli/cmd/debug/ripgrep.ts +0 -87
  74. package/src/cli/cmd/debug/scrap.ts +0 -16
  75. package/src/cli/cmd/debug/skill.ts +0 -16
  76. package/src/cli/cmd/debug/snapshot.ts +0 -52
  77. package/src/cli/cmd/export.ts +0 -89
  78. package/src/cli/cmd/generate.ts +0 -38
  79. package/src/cli/cmd/github.ts +0 -1646
  80. package/src/cli/cmd/import.ts +0 -207
  81. package/src/cli/cmd/mcp.ts +0 -754
  82. package/src/cli/cmd/models.ts +0 -78
  83. package/src/cli/cmd/plug.ts +0 -231
  84. package/src/cli/cmd/pr.ts +0 -127
  85. package/src/cli/cmd/providers.ts +0 -482
  86. package/src/cli/cmd/run.ts +0 -738
  87. package/src/cli/cmd/serve.ts +0 -42
  88. package/src/cli/cmd/session.ts +0 -159
  89. package/src/cli/cmd/stats.ts +0 -410
  90. package/src/cli/cmd/tui/app.tsx +0 -1255
  91. package/src/cli/cmd/tui/attach.ts +0 -88
  92. package/src/cli/cmd/tui/component/border.tsx +0 -21
  93. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  94. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -171
  95. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  96. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -264
  97. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -334
  98. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -108
  99. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  100. package/src/cli/cmd/tui/component/dialog-skill.tsx +0 -36
  101. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
  102. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -168
  103. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  104. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  105. package/src/cli/cmd/tui/component/dialog-variant.tsx +0 -29
  106. package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +0 -320
  107. package/src/cli/cmd/tui/component/error-component.tsx +0 -91
  108. package/src/cli/cmd/tui/component/logo.tsx +0 -86
  109. package/src/cli/cmd/tui/component/plugin-route-missing.tsx +0 -14
  110. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -667
  111. package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -90
  112. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  113. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1353
  114. package/src/cli/cmd/tui/component/prompt/part.ts +0 -16
  115. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  116. package/src/cli/cmd/tui/component/spinner.tsx +0 -24
  117. package/src/cli/cmd/tui/component/startup-loading.tsx +0 -63
  118. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  119. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  120. package/src/cli/cmd/tui/component/workspace/dialog-session-list.tsx +0 -151
  121. package/src/cli/cmd/tui/context/args.tsx +0 -15
  122. package/src/cli/cmd/tui/context/directory.ts +0 -13
  123. package/src/cli/cmd/tui/context/exit.tsx +0 -60
  124. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  125. package/src/cli/cmd/tui/context/keybind.tsx +0 -105
  126. package/src/cli/cmd/tui/context/kv.tsx +0 -52
  127. package/src/cli/cmd/tui/context/local.tsx +0 -406
  128. package/src/cli/cmd/tui/context/plugin-keybinds.ts +0 -41
  129. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  130. package/src/cli/cmd/tui/context/route.tsx +0 -52
  131. package/src/cli/cmd/tui/context/sdk.tsx +0 -128
  132. package/src/cli/cmd/tui/context/sync.tsx +0 -504
  133. package/src/cli/cmd/tui/context/theme/amber.json +0 -245
  134. package/src/cli/cmd/tui/context/theme/amiga.json +0 -245
  135. package/src/cli/cmd/tui/context/theme/atari.json +0 -245
  136. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  137. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  138. package/src/cli/cmd/tui/context/theme/borland.json +0 -245
  139. package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
  140. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  141. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  142. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  143. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  144. package/src/cli/cmd/tui/context/theme/commodore.json +0 -245
  145. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  146. package/src/cli/cmd/tui/context/theme/dos-edit.json +0 -245
  147. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  148. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  149. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  150. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  151. package/src/cli/cmd/tui/context/theme/gnu.json +0 -245
  152. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -242
  153. package/src/cli/cmd/tui/context/theme/hacker.json +0 -245
  154. package/src/cli/cmd/tui/context/theme/irix.json +0 -245
  155. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  156. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
  157. package/src/cli/cmd/tui/context/theme/mac84.json +0 -245
  158. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  159. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  160. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  161. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  162. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  163. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  164. package/src/cli/cmd/tui/context/theme/norton.json +0 -245
  165. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  166. package/src/cli/cmd/tui/context/theme/opencode.json +0 -245
  167. package/src/cli/cmd/tui/context/theme/orng.json +0 -249
  168. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  169. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  170. package/src/cli/cmd/tui/context/theme/pine.json +0 -245
  171. package/src/cli/cmd/tui/context/theme/retrowave.json +0 -245
  172. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  173. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  174. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  175. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  176. package/src/cli/cmd/tui/context/theme/toolkode.json +0 -245
  177. package/src/cli/cmd/tui/context/theme/tron.json +0 -245
  178. package/src/cli/cmd/tui/context/theme/ubuntu.json +0 -245
  179. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  180. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  181. package/src/cli/cmd/tui/context/theme/vt100.json +0 -245
  182. package/src/cli/cmd/tui/context/theme/xcode.json +0 -245
  183. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  184. package/src/cli/cmd/tui/context/theme.tsx +0 -1288
  185. package/src/cli/cmd/tui/context/tui-config.tsx +0 -9
  186. package/src/cli/cmd/tui/event.ts +0 -49
  187. package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +0 -152
  188. package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +0 -50
  189. package/src/cli/cmd/tui/feature-plugins/sidebar/agents-panel.tsx +0 -95
  190. package/src/cli/cmd/tui/feature-plugins/sidebar/btw-panel.tsx +0 -105
  191. package/src/cli/cmd/tui/feature-plugins/sidebar/commands-panel.tsx +0 -40
  192. package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +0 -63
  193. package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +0 -62
  194. package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +0 -93
  195. package/src/cli/cmd/tui/feature-plugins/sidebar/git-panel.tsx +0 -36
  196. package/src/cli/cmd/tui/feature-plugins/sidebar/loop-panel.tsx +0 -124
  197. package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +0 -66
  198. package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +0 -96
  199. package/src/cli/cmd/tui/feature-plugins/sidebar/session-panel.tsx +0 -48
  200. package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +0 -48
  201. package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +0 -270
  202. package/src/cli/cmd/tui/plugin/api.tsx +0 -420
  203. package/src/cli/cmd/tui/plugin/index.ts +0 -3
  204. package/src/cli/cmd/tui/plugin/internal.ts +0 -37
  205. package/src/cli/cmd/tui/plugin/runtime.ts +0 -967
  206. package/src/cli/cmd/tui/plugin/slots.tsx +0 -61
  207. package/src/cli/cmd/tui/routes/home.tsx +0 -173
  208. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -65
  209. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -110
  210. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  211. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  212. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
  213. package/src/cli/cmd/tui/routes/session/index.tsx +0 -2229
  214. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -685
  215. package/src/cli/cmd/tui/routes/session/question.tsx +0 -467
  216. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -72
  217. package/src/cli/cmd/tui/routes/session/subagent-footer.tsx +0 -131
  218. package/src/cli/cmd/tui/thread.ts +0 -232
  219. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -59
  220. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -89
  221. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -208
  222. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -40
  223. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -106
  224. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -402
  225. package/src/cli/cmd/tui/ui/dialog.tsx +0 -192
  226. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  227. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  228. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  229. package/src/cli/cmd/tui/util/clipboard.ts +0 -192
  230. package/src/cli/cmd/tui/util/editor.ts +0 -37
  231. package/src/cli/cmd/tui/util/selection.ts +0 -25
  232. package/src/cli/cmd/tui/util/signal.ts +0 -7
  233. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  234. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  235. package/src/cli/cmd/tui/win32.ts +0 -129
  236. package/src/cli/cmd/tui/worker.ts +0 -204
  237. package/src/cli/cmd/uninstall.ts +0 -353
  238. package/src/cli/cmd/upgrade.ts +0 -73
  239. package/src/cli/cmd/web.ts +0 -81
  240. package/src/cli/effect/prompt.ts +0 -25
  241. package/src/cli/error.ts +0 -46
  242. package/src/cli/logo.ts +0 -7
  243. package/src/cli/network.ts +0 -60
  244. package/src/cli/ui.ts +0 -116
  245. package/src/cli/upgrade.ts +0 -31
  246. package/src/command/index.ts +0 -195
  247. package/src/command/template/initialize.txt +0 -10
  248. package/src/command/template/review.txt +0 -101
  249. package/src/config/config.ts +0 -1693
  250. package/src/config/markdown.ts +0 -99
  251. package/src/config/migrate-tui-config.ts +0 -155
  252. package/src/config/paths.ts +0 -174
  253. package/src/config/tui-schema.ts +0 -36
  254. package/src/config/tui.ts +0 -212
  255. package/src/control-plane/adaptors/index.ts +0 -20
  256. package/src/control-plane/adaptors/worktree.ts +0 -38
  257. package/src/control-plane/schema.ts +0 -17
  258. package/src/control-plane/sse.ts +0 -66
  259. package/src/control-plane/types.ts +0 -21
  260. package/src/control-plane/workspace.sql.ts +0 -17
  261. package/src/control-plane/workspace.ts +0 -154
  262. package/src/cron/index.ts +0 -241
  263. package/src/cron/parse.ts +0 -189
  264. package/src/effect/cross-spawn-spawner.ts +0 -479
  265. package/src/effect/instance-registry.ts +0 -12
  266. package/src/effect/instance-state.ts +0 -47
  267. package/src/effect/run-service.ts +0 -19
  268. package/src/env/index.ts +0 -28
  269. package/src/file/ignore.ts +0 -82
  270. package/src/file/index.ts +0 -693
  271. package/src/file/protected.ts +0 -59
  272. package/src/file/ripgrep.ts +0 -376
  273. package/src/file/time.ts +0 -128
  274. package/src/file/watcher.ts +0 -171
  275. package/src/filesystem/index.ts +0 -226
  276. package/src/flag/flag.ts +0 -157
  277. package/src/format/formatter.ts +0 -396
  278. package/src/format/index.ts +0 -199
  279. package/src/global/index.ts +0 -54
  280. package/src/hooks/index.ts +0 -302
  281. package/src/id/id.ts +0 -85
  282. package/src/ide/index.ts +0 -74
  283. package/src/index.ts +0 -243
  284. package/src/installation/index.ts +0 -363
  285. package/src/lsp/client.ts +0 -252
  286. package/src/lsp/index.ts +0 -558
  287. package/src/lsp/language.ts +0 -120
  288. package/src/lsp/launch.ts +0 -21
  289. package/src/lsp/server.ts +0 -2093
  290. package/src/mcp/auth.ts +0 -181
  291. package/src/mcp/index.ts +0 -926
  292. package/src/mcp/oauth-callback.ts +0 -215
  293. package/src/mcp/oauth-provider.ts +0 -185
  294. package/src/node.ts +0 -1
  295. package/src/patch/index.ts +0 -680
  296. package/src/permission/arity.ts +0 -163
  297. package/src/permission/evaluate.ts +0 -15
  298. package/src/permission/index.ts +0 -322
  299. package/src/permission/schema.ts +0 -17
  300. package/src/plugin/codex.ts +0 -628
  301. package/src/plugin/copilot.ts +0 -343
  302. package/src/plugin/index.ts +0 -331
  303. package/src/plugin/install.ts +0 -384
  304. package/src/plugin/meta.ts +0 -165
  305. package/src/plugin/shared.ts +0 -172
  306. package/src/project/bootstrap.ts +0 -31
  307. package/src/project/instance.ts +0 -167
  308. package/src/project/project.sql.ts +0 -16
  309. package/src/project/project.ts +0 -519
  310. package/src/project/schema.ts +0 -16
  311. package/src/project/state.ts +0 -70
  312. package/src/project/vcs.ts +0 -124
  313. package/src/provider/auth.ts +0 -252
  314. package/src/provider/error.ts +0 -197
  315. package/src/provider/models.ts +0 -138
  316. package/src/provider/provider.ts +0 -1593
  317. package/src/provider/schema.ts +0 -39
  318. package/src/provider/sdk/copilot/README.md +0 -5
  319. package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -170
  320. package/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  321. package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -19
  322. package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  323. package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -815
  324. package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  325. package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  326. package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -83
  327. package/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  328. package/src/provider/sdk/copilot/index.ts +0 -2
  329. package/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  330. package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -335
  331. package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  332. package/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  333. package/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  334. package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -214
  335. package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1769
  336. package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -173
  337. package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  338. package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -87
  339. package/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -127
  340. package/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -114
  341. package/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -64
  342. package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -103
  343. package/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -102
  344. package/src/provider/toolkit-manifest.ts +0 -110
  345. package/src/provider/transform.ts +0 -1045
  346. package/src/pty/index.ts +0 -397
  347. package/src/pty/schema.ts +0 -17
  348. package/src/question/index.ts +0 -221
  349. package/src/question/schema.ts +0 -17
  350. package/src/server/error.ts +0 -36
  351. package/src/server/event.ts +0 -7
  352. package/src/server/instance.ts +0 -285
  353. package/src/server/mdns.ts +0 -60
  354. package/src/server/middleware.ts +0 -29
  355. package/src/server/projectors.ts +0 -28
  356. package/src/server/router.ts +0 -99
  357. package/src/server/routes/config.ts +0 -92
  358. package/src/server/routes/event.ts +0 -83
  359. package/src/server/routes/experimental.ts +0 -271
  360. package/src/server/routes/file.ts +0 -197
  361. package/src/server/routes/global.ts +0 -339
  362. package/src/server/routes/mcp.ts +0 -225
  363. package/src/server/routes/permission.ts +0 -69
  364. package/src/server/routes/project.ts +0 -118
  365. package/src/server/routes/provider.ts +0 -171
  366. package/src/server/routes/pty.ts +0 -211
  367. package/src/server/routes/question.ts +0 -99
  368. package/src/server/routes/session.ts +0 -1031
  369. package/src/server/routes/tui.ts +0 -379
  370. package/src/server/routes/workspace.ts +0 -94
  371. package/src/server/server.ts +0 -312
  372. package/src/session/compaction.ts +0 -424
  373. package/src/session/index.ts +0 -882
  374. package/src/session/instruction.ts +0 -321
  375. package/src/session/llm.ts +0 -341
  376. package/src/session/message-v2.ts +0 -1030
  377. package/src/session/message.ts +0 -191
  378. package/src/session/overflow.ts +0 -22
  379. package/src/session/processor.ts +0 -554
  380. package/src/session/projectors.ts +0 -135
  381. package/src/session/prompt/anthropic.txt +0 -105
  382. package/src/session/prompt/beast.txt +0 -147
  383. package/src/session/prompt/build-switch.txt +0 -5
  384. package/src/session/prompt/codex.txt +0 -79
  385. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  386. package/src/session/prompt/default.txt +0 -108
  387. package/src/session/prompt/gemini.txt +0 -155
  388. package/src/session/prompt/gpt.txt +0 -107
  389. package/src/session/prompt/max-steps.txt +0 -16
  390. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  391. package/src/session/prompt/plan.txt +0 -26
  392. package/src/session/prompt/trinity.txt +0 -97
  393. package/src/session/prompt.ts +0 -2058
  394. package/src/session/retry.ts +0 -106
  395. package/src/session/revert.ts +0 -138
  396. package/src/session/schema.ts +0 -38
  397. package/src/session/session.sql.ts +0 -103
  398. package/src/session/status.ts +0 -102
  399. package/src/session/summary.ts +0 -170
  400. package/src/session/system.ts +0 -74
  401. package/src/session/todo.ts +0 -57
  402. package/src/share/share-next.ts +0 -288
  403. package/src/share/share.sql.ts +0 -13
  404. package/src/shell/shell.ts +0 -73
  405. package/src/skill/discovery.ts +0 -116
  406. package/src/skill/index.ts +0 -284
  407. package/src/skills-marketplace/index.ts +0 -305
  408. package/src/snapshot/index.ts +0 -489
  409. package/src/sql.d.ts +0 -4
  410. package/src/storage/db.bun.ts +0 -8
  411. package/src/storage/db.node.ts +0 -8
  412. package/src/storage/db.ts +0 -177
  413. package/src/storage/json-migration.ts +0 -425
  414. package/src/storage/schema.sql.ts +0 -10
  415. package/src/storage/schema.ts +0 -5
  416. package/src/storage/storage.ts +0 -217
  417. package/src/sync/README.md +0 -179
  418. package/src/sync/event.sql.ts +0 -16
  419. package/src/sync/index.ts +0 -263
  420. package/src/sync/schema.ts +0 -14
  421. package/src/team/index.ts +0 -428
  422. package/src/tool/apply_patch.ts +0 -281
  423. package/src/tool/apply_patch.txt +0 -33
  424. package/src/tool/bash.ts +0 -271
  425. package/src/tool/bash.txt +0 -115
  426. package/src/tool/batch.ts +0 -183
  427. package/src/tool/batch.txt +0 -24
  428. package/src/tool/codesearch.ts +0 -132
  429. package/src/tool/codesearch.txt +0 -12
  430. package/src/tool/cron-create.ts +0 -54
  431. package/src/tool/cron-create.txt +0 -16
  432. package/src/tool/cron-delete.ts +0 -29
  433. package/src/tool/cron-delete.txt +0 -1
  434. package/src/tool/cron-list.ts +0 -41
  435. package/src/tool/cron-list.txt +0 -1
  436. package/src/tool/edit.ts +0 -667
  437. package/src/tool/edit.txt +0 -10
  438. package/src/tool/external-directory.ts +0 -32
  439. package/src/tool/glob.ts +0 -78
  440. package/src/tool/glob.txt +0 -6
  441. package/src/tool/grep.ts +0 -156
  442. package/src/tool/grep.txt +0 -8
  443. package/src/tool/invalid.ts +0 -17
  444. package/src/tool/ls.ts +0 -121
  445. package/src/tool/ls.txt +0 -1
  446. package/src/tool/lsp.ts +0 -97
  447. package/src/tool/lsp.txt +0 -19
  448. package/src/tool/multiedit.ts +0 -46
  449. package/src/tool/multiedit.txt +0 -41
  450. package/src/tool/plan-enter.txt +0 -14
  451. package/src/tool/plan-exit.txt +0 -13
  452. package/src/tool/plan.ts +0 -131
  453. package/src/tool/question.ts +0 -33
  454. package/src/tool/question.txt +0 -10
  455. package/src/tool/read.ts +0 -293
  456. package/src/tool/read.txt +0 -14
  457. package/src/tool/registry.ts +0 -232
  458. package/src/tool/schema.ts +0 -17
  459. package/src/tool/send-message.ts +0 -59
  460. package/src/tool/send-message.txt +0 -7
  461. package/src/tool/skill.ts +0 -105
  462. package/src/tool/task.ts +0 -230
  463. package/src/tool/task.txt +0 -62
  464. package/src/tool/team.ts +0 -235
  465. package/src/tool/team.txt +0 -22
  466. package/src/tool/todo.ts +0 -31
  467. package/src/tool/todowrite.txt +0 -167
  468. package/src/tool/tool.ts +0 -90
  469. package/src/tool/truncate.ts +0 -144
  470. package/src/tool/truncation-dir.ts +0 -4
  471. package/src/tool/webfetch.ts +0 -206
  472. package/src/tool/webfetch.txt +0 -13
  473. package/src/tool/websearch.ts +0 -150
  474. package/src/tool/websearch.txt +0 -14
  475. package/src/tool/write.ts +0 -84
  476. package/src/tool/write.txt +0 -8
  477. package/src/util/abort.ts +0 -35
  478. package/src/util/archive.ts +0 -17
  479. package/src/util/color.ts +0 -19
  480. package/src/util/context.ts +0 -25
  481. package/src/util/data-url.ts +0 -9
  482. package/src/util/defer.ts +0 -12
  483. package/src/util/effect-http-client.ts +0 -11
  484. package/src/util/effect-zod.ts +0 -98
  485. package/src/util/error.ts +0 -77
  486. package/src/util/filesystem.ts +0 -203
  487. package/src/util/flock.ts +0 -333
  488. package/src/util/fn.ts +0 -21
  489. package/src/util/format.ts +0 -20
  490. package/src/util/git.ts +0 -35
  491. package/src/util/glob.ts +0 -34
  492. package/src/util/hash.ts +0 -7
  493. package/src/util/iife.ts +0 -3
  494. package/src/util/keybind.ts +0 -103
  495. package/src/util/lazy.ts +0 -23
  496. package/src/util/locale.ts +0 -81
  497. package/src/util/lock.ts +0 -98
  498. package/src/util/log.ts +0 -182
  499. package/src/util/network.ts +0 -9
  500. package/src/util/process.ts +0 -172
  501. package/src/util/queue.ts +0 -32
  502. package/src/util/record.ts +0 -3
  503. package/src/util/rpc.ts +0 -66
  504. package/src/util/schema.ts +0 -53
  505. package/src/util/scrap.ts +0 -10
  506. package/src/util/signal.ts +0 -12
  507. package/src/util/timeout.ts +0 -14
  508. package/src/util/token.ts +0 -7
  509. package/src/util/update-schema.ts +0 -13
  510. package/src/util/which.ts +0 -14
  511. package/src/util/wildcard.ts +0 -59
  512. package/src/worktree/index.ts +0 -638
  513. package/sst-env.d.ts +0 -10
  514. package/test/AGENTS.md +0 -81
  515. package/test/account/repo.test.ts +0 -326
  516. package/test/account/service.test.ts +0 -282
  517. package/test/acp/agent-interface.test.ts +0 -51
  518. package/test/acp/event-subscription.test.ts +0 -685
  519. package/test/agent/agent.test.ts +0 -717
  520. package/test/auth/auth.test.ts +0 -58
  521. package/test/bun.test.ts +0 -53
  522. package/test/bus/bus-effect.test.ts +0 -164
  523. package/test/bus/bus-integration.test.ts +0 -87
  524. package/test/bus/bus.test.ts +0 -219
  525. package/test/cli/account.test.ts +0 -26
  526. package/test/cli/cmd/tui/prompt-part.test.ts +0 -47
  527. package/test/cli/github-action.test.ts +0 -198
  528. package/test/cli/github-remote.test.ts +0 -80
  529. package/test/cli/import.test.ts +0 -54
  530. package/test/cli/plugin-auth-picker.test.ts +0 -120
  531. package/test/cli/tui/keybind-plugin.test.ts +0 -90
  532. package/test/cli/tui/plugin-add.test.ts +0 -61
  533. package/test/cli/tui/plugin-install.test.ts +0 -95
  534. package/test/cli/tui/plugin-lifecycle.test.ts +0 -225
  535. package/test/cli/tui/plugin-loader-entrypoint.test.ts +0 -189
  536. package/test/cli/tui/plugin-loader-pure.test.ts +0 -71
  537. package/test/cli/tui/plugin-loader.test.ts +0 -563
  538. package/test/cli/tui/plugin-toggle.test.ts +0 -157
  539. package/test/cli/tui/theme-store.test.ts +0 -51
  540. package/test/cli/tui/thread.test.ts +0 -128
  541. package/test/cli/tui/transcript.test.ts +0 -322
  542. package/test/config/agent-color.test.ts +0 -71
  543. package/test/config/config.test.ts +0 -2187
  544. package/test/config/fixtures/empty-frontmatter.md +0 -4
  545. package/test/config/fixtures/frontmatter.md +0 -28
  546. package/test/config/fixtures/markdown-header.md +0 -11
  547. package/test/config/fixtures/no-frontmatter.md +0 -1
  548. package/test/config/fixtures/weird-model-id.md +0 -13
  549. package/test/config/markdown.test.ts +0 -228
  550. package/test/config/tui.test.ts +0 -667
  551. package/test/control-plane/sse.test.ts +0 -56
  552. package/test/effect/cross-spawn-spawner.test.ts +0 -402
  553. package/test/effect/instance-state.test.ts +0 -384
  554. package/test/effect/run-service.test.ts +0 -46
  555. package/test/file/fsmonitor.test.ts +0 -62
  556. package/test/file/ignore.test.ts +0 -10
  557. package/test/file/index.test.ts +0 -946
  558. package/test/file/path-traversal.test.ts +0 -198
  559. package/test/file/ripgrep.test.ts +0 -54
  560. package/test/file/time.test.ts +0 -354
  561. package/test/file/watcher.test.ts +0 -247
  562. package/test/filesystem/filesystem.test.ts +0 -319
  563. package/test/fixture/db.ts +0 -11
  564. package/test/fixture/fixture.test.ts +0 -26
  565. package/test/fixture/fixture.ts +0 -141
  566. package/test/fixture/flock-worker.ts +0 -72
  567. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  568. package/test/fixture/plug-worker.ts +0 -93
  569. package/test/fixture/plugin-meta-worker.ts +0 -26
  570. package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
  571. package/test/fixture/skills/agents-sdk/references/callable.md +0 -92
  572. package/test/fixture/skills/cloudflare/SKILL.md +0 -211
  573. package/test/fixture/skills/index.json +0 -6
  574. package/test/fixture/tui-plugin.ts +0 -335
  575. package/test/fixture/tui-runtime.ts +0 -34
  576. package/test/format/format.test.ts +0 -179
  577. package/test/ide/ide.test.ts +0 -82
  578. package/test/installation/installation.test.ts +0 -151
  579. package/test/keybind.test.ts +0 -421
  580. package/test/lib/effect.ts +0 -37
  581. package/test/lib/filesystem.ts +0 -10
  582. package/test/lsp/client.test.ts +0 -95
  583. package/test/lsp/index.test.ts +0 -55
  584. package/test/lsp/launch.test.ts +0 -22
  585. package/test/lsp/lifecycle.test.ts +0 -147
  586. package/test/mcp/headers.test.ts +0 -153
  587. package/test/mcp/lifecycle.test.ts +0 -750
  588. package/test/mcp/oauth-auto-connect.test.ts +0 -199
  589. package/test/mcp/oauth-browser.test.ts +0 -249
  590. package/test/memory/abort-leak.test.ts +0 -137
  591. package/test/patch/patch.test.ts +0 -348
  592. package/test/permission/arity.test.ts +0 -33
  593. package/test/permission/next.test.ts +0 -1148
  594. package/test/permission-task.test.ts +0 -323
  595. package/test/plugin/auth-override.test.ts +0 -74
  596. package/test/plugin/codex.test.ts +0 -123
  597. package/test/plugin/install-concurrency.test.ts +0 -134
  598. package/test/plugin/install.test.ts +0 -504
  599. package/test/plugin/loader-shared.test.ts +0 -625
  600. package/test/plugin/meta.test.ts +0 -137
  601. package/test/plugin/trigger.test.ts +0 -111
  602. package/test/preload.ts +0 -90
  603. package/test/project/migrate-global.test.ts +0 -140
  604. package/test/project/project.test.ts +0 -459
  605. package/test/project/state.test.ts +0 -115
  606. package/test/project/vcs.test.ts +0 -116
  607. package/test/project/worktree-remove.test.ts +0 -96
  608. package/test/project/worktree.test.ts +0 -173
  609. package/test/provider/amazon-bedrock.test.ts +0 -447
  610. package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
  611. package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
  612. package/test/provider/gitlab-duo.test.ts +0 -412
  613. package/test/provider/provider.test.ts +0 -2284
  614. package/test/provider/transform.test.ts +0 -2758
  615. package/test/pty/pty-output-isolation.test.ts +0 -141
  616. package/test/pty/pty-session.test.ts +0 -92
  617. package/test/question/question.test.ts +0 -453
  618. package/test/server/global-session-list.test.ts +0 -89
  619. package/test/server/project-init-git.test.ts +0 -121
  620. package/test/server/session-list.test.ts +0 -90
  621. package/test/server/session-messages.test.ts +0 -132
  622. package/test/server/session-select.test.ts +0 -78
  623. package/test/session/compaction.test.ts +0 -1094
  624. package/test/session/instruction.test.ts +0 -170
  625. package/test/session/llm.test.ts +0 -882
  626. package/test/session/message-v2.test.ts +0 -957
  627. package/test/session/messages-pagination.test.ts +0 -115
  628. package/test/session/processor-effect.test.ts +0 -838
  629. package/test/session/prompt.test.ts +0 -518
  630. package/test/session/retry.test.ts +0 -232
  631. package/test/session/revert-compact.test.ts +0 -286
  632. package/test/session/session.test.ts +0 -142
  633. package/test/session/structured-output-integration.test.ts +0 -233
  634. package/test/session/structured-output.test.ts +0 -391
  635. package/test/session/system.test.ts +0 -59
  636. package/test/share/share-next.test.ts +0 -76
  637. package/test/skill/discovery.test.ts +0 -116
  638. package/test/skill/skill.test.ts +0 -392
  639. package/test/snapshot/snapshot.test.ts +0 -1235
  640. package/test/storage/db.test.ts +0 -14
  641. package/test/storage/json-migration.test.ts +0 -849
  642. package/test/sync/index.test.ts +0 -191
  643. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  644. package/test/tool/apply_patch.test.ts +0 -567
  645. package/test/tool/bash.test.ts +0 -403
  646. package/test/tool/edit.test.ts +0 -681
  647. package/test/tool/external-directory.test.ts +0 -128
  648. package/test/tool/fixtures/large-image.png +0 -0
  649. package/test/tool/fixtures/models-api.json +0 -38413
  650. package/test/tool/grep.test.ts +0 -111
  651. package/test/tool/question.test.ts +0 -108
  652. package/test/tool/read.test.ts +0 -509
  653. package/test/tool/registry.test.ts +0 -126
  654. package/test/tool/skill.test.ts +0 -167
  655. package/test/tool/task.test.ts +0 -49
  656. package/test/tool/truncation.test.ts +0 -161
  657. package/test/tool/webfetch.test.ts +0 -101
  658. package/test/tool/write.test.ts +0 -353
  659. package/test/util/data-url.test.ts +0 -14
  660. package/test/util/effect-zod.test.ts +0 -61
  661. package/test/util/error.test.ts +0 -38
  662. package/test/util/filesystem.test.ts +0 -558
  663. package/test/util/flock.test.ts +0 -383
  664. package/test/util/format.test.ts +0 -59
  665. package/test/util/glob.test.ts +0 -164
  666. package/test/util/iife.test.ts +0 -36
  667. package/test/util/lazy.test.ts +0 -50
  668. package/test/util/lock.test.ts +0 -72
  669. package/test/util/module.test.ts +0 -59
  670. package/test/util/process.test.ts +0 -128
  671. package/test/util/timeout.test.ts +0 -21
  672. package/test/util/which.test.ts +0 -100
  673. package/test/util/wildcard.test.ts +0 -90
  674. package/tsconfig.json +0 -23
@@ -1,2284 +0,0 @@
1
- import { test, expect } from "bun:test"
2
- import path from "path"
3
-
4
- import { tmpdir } from "../fixture/fixture"
5
- import { Instance } from "../../src/project/instance"
6
- import { Provider } from "../../src/provider/provider"
7
- import { ProviderID, ModelID } from "../../src/provider/schema"
8
- import { Env } from "../../src/env"
9
-
10
- test("provider loaded from env variable", async () => {
11
- await using tmp = await tmpdir({
12
- init: async (dir) => {
13
- await Bun.write(
14
- path.join(dir, "opencode.json"),
15
- JSON.stringify({
16
- $schema: "https://toolkode.com/config.json",
17
- }),
18
- )
19
- },
20
- })
21
- await Instance.provide({
22
- directory: tmp.path,
23
- init: async () => {
24
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
25
- },
26
- fn: async () => {
27
- const providers = await Provider.list()
28
- expect(providers[ProviderID.anthropic]).toBeDefined()
29
- // Provider should retain its connection source even if custom loaders
30
- // merge additional options.
31
- expect(providers[ProviderID.anthropic].source).toBe("env")
32
- expect(providers[ProviderID.anthropic].options.headers["anthropic-beta"]).toBeDefined()
33
- },
34
- })
35
- })
36
-
37
- test("provider loaded from config with apiKey option", async () => {
38
- await using tmp = await tmpdir({
39
- init: async (dir) => {
40
- await Bun.write(
41
- path.join(dir, "opencode.json"),
42
- JSON.stringify({
43
- $schema: "https://toolkode.com/config.json",
44
- provider: {
45
- anthropic: {
46
- options: {
47
- apiKey: "config-api-key",
48
- },
49
- },
50
- },
51
- }),
52
- )
53
- },
54
- })
55
- await Instance.provide({
56
- directory: tmp.path,
57
- fn: async () => {
58
- const providers = await Provider.list()
59
- expect(providers[ProviderID.anthropic]).toBeDefined()
60
- },
61
- })
62
- })
63
-
64
- test("disabled_providers excludes provider", async () => {
65
- await using tmp = await tmpdir({
66
- init: async (dir) => {
67
- await Bun.write(
68
- path.join(dir, "opencode.json"),
69
- JSON.stringify({
70
- $schema: "https://toolkode.com/config.json",
71
- disabled_providers: ["anthropic"],
72
- }),
73
- )
74
- },
75
- })
76
- await Instance.provide({
77
- directory: tmp.path,
78
- init: async () => {
79
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
80
- },
81
- fn: async () => {
82
- const providers = await Provider.list()
83
- expect(providers[ProviderID.anthropic]).toBeUndefined()
84
- },
85
- })
86
- })
87
-
88
- test("enabled_providers restricts to only listed providers", async () => {
89
- await using tmp = await tmpdir({
90
- init: async (dir) => {
91
- await Bun.write(
92
- path.join(dir, "opencode.json"),
93
- JSON.stringify({
94
- $schema: "https://toolkode.com/config.json",
95
- enabled_providers: ["anthropic"],
96
- }),
97
- )
98
- },
99
- })
100
- await Instance.provide({
101
- directory: tmp.path,
102
- init: async () => {
103
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
104
- Env.set("OPENAI_API_KEY", "test-openai-key")
105
- },
106
- fn: async () => {
107
- const providers = await Provider.list()
108
- expect(providers[ProviderID.anthropic]).toBeDefined()
109
- expect(providers[ProviderID.openai]).toBeUndefined()
110
- },
111
- })
112
- })
113
-
114
- test("model whitelist filters models for provider", async () => {
115
- await using tmp = await tmpdir({
116
- init: async (dir) => {
117
- await Bun.write(
118
- path.join(dir, "opencode.json"),
119
- JSON.stringify({
120
- $schema: "https://toolkode.com/config.json",
121
- provider: {
122
- anthropic: {
123
- whitelist: ["claude-sonnet-4-20250514"],
124
- },
125
- },
126
- }),
127
- )
128
- },
129
- })
130
- await Instance.provide({
131
- directory: tmp.path,
132
- init: async () => {
133
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
134
- },
135
- fn: async () => {
136
- const providers = await Provider.list()
137
- expect(providers[ProviderID.anthropic]).toBeDefined()
138
- const models = Object.keys(providers[ProviderID.anthropic].models)
139
- expect(models).toContain("claude-sonnet-4-20250514")
140
- expect(models.length).toBe(1)
141
- },
142
- })
143
- })
144
-
145
- test("model blacklist excludes specific models", async () => {
146
- await using tmp = await tmpdir({
147
- init: async (dir) => {
148
- await Bun.write(
149
- path.join(dir, "opencode.json"),
150
- JSON.stringify({
151
- $schema: "https://toolkode.com/config.json",
152
- provider: {
153
- anthropic: {
154
- blacklist: ["claude-sonnet-4-20250514"],
155
- },
156
- },
157
- }),
158
- )
159
- },
160
- })
161
- await Instance.provide({
162
- directory: tmp.path,
163
- init: async () => {
164
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
165
- },
166
- fn: async () => {
167
- const providers = await Provider.list()
168
- expect(providers[ProviderID.anthropic]).toBeDefined()
169
- const models = Object.keys(providers[ProviderID.anthropic].models)
170
- expect(models).not.toContain("claude-sonnet-4-20250514")
171
- },
172
- })
173
- })
174
-
175
- test("custom model alias via config", async () => {
176
- await using tmp = await tmpdir({
177
- init: async (dir) => {
178
- await Bun.write(
179
- path.join(dir, "opencode.json"),
180
- JSON.stringify({
181
- $schema: "https://toolkode.com/config.json",
182
- provider: {
183
- anthropic: {
184
- models: {
185
- "my-alias": {
186
- id: "claude-sonnet-4-20250514",
187
- name: "My Custom Alias",
188
- },
189
- },
190
- },
191
- },
192
- }),
193
- )
194
- },
195
- })
196
- await Instance.provide({
197
- directory: tmp.path,
198
- init: async () => {
199
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
200
- },
201
- fn: async () => {
202
- const providers = await Provider.list()
203
- expect(providers[ProviderID.anthropic]).toBeDefined()
204
- expect(providers[ProviderID.anthropic].models["my-alias"]).toBeDefined()
205
- expect(providers[ProviderID.anthropic].models["my-alias"].name).toBe("My Custom Alias")
206
- },
207
- })
208
- })
209
-
210
- test("custom provider with npm package", async () => {
211
- await using tmp = await tmpdir({
212
- init: async (dir) => {
213
- await Bun.write(
214
- path.join(dir, "opencode.json"),
215
- JSON.stringify({
216
- $schema: "https://toolkode.com/config.json",
217
- provider: {
218
- "custom-provider": {
219
- name: "Custom Provider",
220
- npm: "@ai-sdk/openai-compatible",
221
- api: "https://api.custom.com/v1",
222
- env: ["CUSTOM_API_KEY"],
223
- models: {
224
- "custom-model": {
225
- name: "Custom Model",
226
- tool_call: true,
227
- limit: {
228
- context: 128000,
229
- output: 4096,
230
- },
231
- },
232
- },
233
- options: {
234
- apiKey: "custom-key",
235
- },
236
- },
237
- },
238
- }),
239
- )
240
- },
241
- })
242
- await Instance.provide({
243
- directory: tmp.path,
244
- fn: async () => {
245
- const providers = await Provider.list()
246
- expect(providers[ProviderID.make("custom-provider")]).toBeDefined()
247
- expect(providers[ProviderID.make("custom-provider")].name).toBe("Custom Provider")
248
- expect(providers[ProviderID.make("custom-provider")].models["custom-model"]).toBeDefined()
249
- },
250
- })
251
- })
252
-
253
- test("env variable takes precedence, config merges options", async () => {
254
- await using tmp = await tmpdir({
255
- init: async (dir) => {
256
- await Bun.write(
257
- path.join(dir, "opencode.json"),
258
- JSON.stringify({
259
- $schema: "https://toolkode.com/config.json",
260
- provider: {
261
- anthropic: {
262
- options: {
263
- timeout: 60000,
264
- chunkTimeout: 15000,
265
- },
266
- },
267
- },
268
- }),
269
- )
270
- },
271
- })
272
- await Instance.provide({
273
- directory: tmp.path,
274
- init: async () => {
275
- Env.set("ANTHROPIC_API_KEY", "env-api-key")
276
- },
277
- fn: async () => {
278
- const providers = await Provider.list()
279
- expect(providers[ProviderID.anthropic]).toBeDefined()
280
- // Config options should be merged
281
- expect(providers[ProviderID.anthropic].options.timeout).toBe(60000)
282
- expect(providers[ProviderID.anthropic].options.chunkTimeout).toBe(15000)
283
- },
284
- })
285
- })
286
-
287
- test("getModel returns model for valid provider/model", async () => {
288
- await using tmp = await tmpdir({
289
- init: async (dir) => {
290
- await Bun.write(
291
- path.join(dir, "opencode.json"),
292
- JSON.stringify({
293
- $schema: "https://toolkode.com/config.json",
294
- }),
295
- )
296
- },
297
- })
298
- await Instance.provide({
299
- directory: tmp.path,
300
- init: async () => {
301
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
302
- },
303
- fn: async () => {
304
- const model = await Provider.getModel(ProviderID.anthropic, ModelID.make("claude-sonnet-4-20250514"))
305
- expect(model).toBeDefined()
306
- expect(String(model.providerID)).toBe("anthropic")
307
- expect(String(model.id)).toBe("claude-sonnet-4-20250514")
308
- const language = await Provider.getLanguage(model)
309
- expect(language).toBeDefined()
310
- },
311
- })
312
- })
313
-
314
- test("getModel throws ModelNotFoundError for invalid model", async () => {
315
- await using tmp = await tmpdir({
316
- init: async (dir) => {
317
- await Bun.write(
318
- path.join(dir, "opencode.json"),
319
- JSON.stringify({
320
- $schema: "https://toolkode.com/config.json",
321
- }),
322
- )
323
- },
324
- })
325
- await Instance.provide({
326
- directory: tmp.path,
327
- init: async () => {
328
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
329
- },
330
- fn: async () => {
331
- expect(Provider.getModel(ProviderID.anthropic, ModelID.make("nonexistent-model"))).rejects.toThrow()
332
- },
333
- })
334
- })
335
-
336
- test("getModel throws ModelNotFoundError for invalid provider", async () => {
337
- await using tmp = await tmpdir({
338
- init: async (dir) => {
339
- await Bun.write(
340
- path.join(dir, "opencode.json"),
341
- JSON.stringify({
342
- $schema: "https://toolkode.com/config.json",
343
- }),
344
- )
345
- },
346
- })
347
- await Instance.provide({
348
- directory: tmp.path,
349
- fn: async () => {
350
- expect(Provider.getModel(ProviderID.make("nonexistent-provider"), ModelID.make("some-model"))).rejects.toThrow()
351
- },
352
- })
353
- })
354
-
355
- test("parseModel correctly parses provider/model string", () => {
356
- const result = Provider.parseModel("anthropic/claude-sonnet-4")
357
- expect(String(result.providerID)).toBe("anthropic")
358
- expect(String(result.modelID)).toBe("claude-sonnet-4")
359
- })
360
-
361
- test("parseModel handles model IDs with slashes", () => {
362
- const result = Provider.parseModel("openrouter/anthropic/claude-3-opus")
363
- expect(String(result.providerID)).toBe("openrouter")
364
- expect(String(result.modelID)).toBe("anthropic/claude-3-opus")
365
- })
366
-
367
- test("defaultModel returns first available model when no config set", async () => {
368
- await using tmp = await tmpdir({
369
- init: async (dir) => {
370
- await Bun.write(
371
- path.join(dir, "opencode.json"),
372
- JSON.stringify({
373
- $schema: "https://toolkode.com/config.json",
374
- }),
375
- )
376
- },
377
- })
378
- await Instance.provide({
379
- directory: tmp.path,
380
- init: async () => {
381
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
382
- },
383
- fn: async () => {
384
- const model = await Provider.defaultModel()
385
- expect(model.providerID).toBeDefined()
386
- expect(model.modelID).toBeDefined()
387
- },
388
- })
389
- })
390
-
391
- test("defaultModel respects config model setting", async () => {
392
- await using tmp = await tmpdir({
393
- init: async (dir) => {
394
- await Bun.write(
395
- path.join(dir, "opencode.json"),
396
- JSON.stringify({
397
- $schema: "https://toolkode.com/config.json",
398
- model: "anthropic/claude-sonnet-4-20250514",
399
- }),
400
- )
401
- },
402
- })
403
- await Instance.provide({
404
- directory: tmp.path,
405
- init: async () => {
406
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
407
- },
408
- fn: async () => {
409
- const model = await Provider.defaultModel()
410
- expect(String(model.providerID)).toBe("anthropic")
411
- expect(String(model.modelID)).toBe("claude-sonnet-4-20250514")
412
- },
413
- })
414
- })
415
-
416
- test("provider with baseURL from config", async () => {
417
- await using tmp = await tmpdir({
418
- init: async (dir) => {
419
- await Bun.write(
420
- path.join(dir, "opencode.json"),
421
- JSON.stringify({
422
- $schema: "https://toolkode.com/config.json",
423
- provider: {
424
- "custom-openai": {
425
- name: "Custom OpenAI",
426
- npm: "@ai-sdk/openai-compatible",
427
- env: [],
428
- models: {
429
- "gpt-4": {
430
- name: "GPT-4",
431
- tool_call: true,
432
- limit: { context: 128000, output: 4096 },
433
- },
434
- },
435
- options: {
436
- apiKey: "test-key",
437
- baseURL: "https://custom.openai.com/v1",
438
- },
439
- },
440
- },
441
- }),
442
- )
443
- },
444
- })
445
- await Instance.provide({
446
- directory: tmp.path,
447
- fn: async () => {
448
- const providers = await Provider.list()
449
- expect(providers[ProviderID.make("custom-openai")]).toBeDefined()
450
- expect(providers[ProviderID.make("custom-openai")].options.baseURL).toBe("https://custom.openai.com/v1")
451
- },
452
- })
453
- })
454
-
455
- test("model cost defaults to zero when not specified", async () => {
456
- await using tmp = await tmpdir({
457
- init: async (dir) => {
458
- await Bun.write(
459
- path.join(dir, "opencode.json"),
460
- JSON.stringify({
461
- $schema: "https://toolkode.com/config.json",
462
- provider: {
463
- "test-provider": {
464
- name: "Test Provider",
465
- npm: "@ai-sdk/openai-compatible",
466
- env: [],
467
- models: {
468
- "test-model": {
469
- name: "Test Model",
470
- tool_call: true,
471
- limit: { context: 128000, output: 4096 },
472
- },
473
- },
474
- options: {
475
- apiKey: "test-key",
476
- },
477
- },
478
- },
479
- }),
480
- )
481
- },
482
- })
483
- await Instance.provide({
484
- directory: tmp.path,
485
- fn: async () => {
486
- const providers = await Provider.list()
487
- const model = providers[ProviderID.make("test-provider")].models["test-model"]
488
- expect(model.cost.input).toBe(0)
489
- expect(model.cost.output).toBe(0)
490
- expect(model.cost.cache.read).toBe(0)
491
- expect(model.cost.cache.write).toBe(0)
492
- },
493
- })
494
- })
495
-
496
- test("model options are merged from existing model", async () => {
497
- await using tmp = await tmpdir({
498
- init: async (dir) => {
499
- await Bun.write(
500
- path.join(dir, "opencode.json"),
501
- JSON.stringify({
502
- $schema: "https://toolkode.com/config.json",
503
- provider: {
504
- anthropic: {
505
- models: {
506
- "claude-sonnet-4-20250514": {
507
- options: {
508
- customOption: "custom-value",
509
- },
510
- },
511
- },
512
- },
513
- },
514
- }),
515
- )
516
- },
517
- })
518
- await Instance.provide({
519
- directory: tmp.path,
520
- init: async () => {
521
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
522
- },
523
- fn: async () => {
524
- const providers = await Provider.list()
525
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
526
- expect(model.options.customOption).toBe("custom-value")
527
- },
528
- })
529
- })
530
-
531
- test("provider removed when all models filtered out", async () => {
532
- await using tmp = await tmpdir({
533
- init: async (dir) => {
534
- await Bun.write(
535
- path.join(dir, "opencode.json"),
536
- JSON.stringify({
537
- $schema: "https://toolkode.com/config.json",
538
- provider: {
539
- anthropic: {
540
- whitelist: ["nonexistent-model"],
541
- },
542
- },
543
- }),
544
- )
545
- },
546
- })
547
- await Instance.provide({
548
- directory: tmp.path,
549
- init: async () => {
550
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
551
- },
552
- fn: async () => {
553
- const providers = await Provider.list()
554
- expect(providers[ProviderID.anthropic]).toBeUndefined()
555
- },
556
- })
557
- })
558
-
559
- test("closest finds model by partial match", async () => {
560
- await using tmp = await tmpdir({
561
- init: async (dir) => {
562
- await Bun.write(
563
- path.join(dir, "opencode.json"),
564
- JSON.stringify({
565
- $schema: "https://toolkode.com/config.json",
566
- }),
567
- )
568
- },
569
- })
570
- await Instance.provide({
571
- directory: tmp.path,
572
- init: async () => {
573
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
574
- },
575
- fn: async () => {
576
- const result = await Provider.closest(ProviderID.anthropic, ["sonnet-4"])
577
- expect(result).toBeDefined()
578
- expect(String(result?.providerID)).toBe("anthropic")
579
- expect(String(result?.modelID)).toContain("sonnet-4")
580
- },
581
- })
582
- })
583
-
584
- test("closest returns undefined for nonexistent provider", async () => {
585
- await using tmp = await tmpdir({
586
- init: async (dir) => {
587
- await Bun.write(
588
- path.join(dir, "opencode.json"),
589
- JSON.stringify({
590
- $schema: "https://toolkode.com/config.json",
591
- }),
592
- )
593
- },
594
- })
595
- await Instance.provide({
596
- directory: tmp.path,
597
- fn: async () => {
598
- const result = await Provider.closest(ProviderID.make("nonexistent"), ["model"])
599
- expect(result).toBeUndefined()
600
- },
601
- })
602
- })
603
-
604
- test("getModel uses realIdByKey for aliased models", async () => {
605
- await using tmp = await tmpdir({
606
- init: async (dir) => {
607
- await Bun.write(
608
- path.join(dir, "opencode.json"),
609
- JSON.stringify({
610
- $schema: "https://toolkode.com/config.json",
611
- provider: {
612
- anthropic: {
613
- models: {
614
- "my-sonnet": {
615
- id: "claude-sonnet-4-20250514",
616
- name: "My Sonnet Alias",
617
- },
618
- },
619
- },
620
- },
621
- }),
622
- )
623
- },
624
- })
625
- await Instance.provide({
626
- directory: tmp.path,
627
- init: async () => {
628
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
629
- },
630
- fn: async () => {
631
- const providers = await Provider.list()
632
- expect(providers[ProviderID.anthropic].models["my-sonnet"]).toBeDefined()
633
-
634
- const model = await Provider.getModel(ProviderID.anthropic, ModelID.make("my-sonnet"))
635
- expect(model).toBeDefined()
636
- expect(String(model.id)).toBe("my-sonnet")
637
- expect(model.name).toBe("My Sonnet Alias")
638
- },
639
- })
640
- })
641
-
642
- test("provider api field sets model api.url", async () => {
643
- await using tmp = await tmpdir({
644
- init: async (dir) => {
645
- await Bun.write(
646
- path.join(dir, "opencode.json"),
647
- JSON.stringify({
648
- $schema: "https://toolkode.com/config.json",
649
- provider: {
650
- "custom-api": {
651
- name: "Custom API",
652
- npm: "@ai-sdk/openai-compatible",
653
- api: "https://api.example.com/v1",
654
- env: [],
655
- models: {
656
- "model-1": {
657
- name: "Model 1",
658
- tool_call: true,
659
- limit: { context: 8000, output: 2000 },
660
- },
661
- },
662
- options: {
663
- apiKey: "test-key",
664
- },
665
- },
666
- },
667
- }),
668
- )
669
- },
670
- })
671
- await Instance.provide({
672
- directory: tmp.path,
673
- fn: async () => {
674
- const providers = await Provider.list()
675
- // api field is stored on model.api.url, used by getSDK to set baseURL
676
- expect(providers[ProviderID.make("custom-api")].models["model-1"].api.url).toBe("https://api.example.com/v1")
677
- },
678
- })
679
- })
680
-
681
- test("explicit baseURL overrides api field", async () => {
682
- await using tmp = await tmpdir({
683
- init: async (dir) => {
684
- await Bun.write(
685
- path.join(dir, "opencode.json"),
686
- JSON.stringify({
687
- $schema: "https://toolkode.com/config.json",
688
- provider: {
689
- "custom-api": {
690
- name: "Custom API",
691
- npm: "@ai-sdk/openai-compatible",
692
- api: "https://api.example.com/v1",
693
- env: [],
694
- models: {
695
- "model-1": {
696
- name: "Model 1",
697
- tool_call: true,
698
- limit: { context: 8000, output: 2000 },
699
- },
700
- },
701
- options: {
702
- apiKey: "test-key",
703
- baseURL: "https://custom.override.com/v1",
704
- },
705
- },
706
- },
707
- }),
708
- )
709
- },
710
- })
711
- await Instance.provide({
712
- directory: tmp.path,
713
- fn: async () => {
714
- const providers = await Provider.list()
715
- expect(providers[ProviderID.make("custom-api")].options.baseURL).toBe("https://custom.override.com/v1")
716
- },
717
- })
718
- })
719
-
720
- test("model inherits properties from existing database model", async () => {
721
- await using tmp = await tmpdir({
722
- init: async (dir) => {
723
- await Bun.write(
724
- path.join(dir, "opencode.json"),
725
- JSON.stringify({
726
- $schema: "https://toolkode.com/config.json",
727
- provider: {
728
- anthropic: {
729
- models: {
730
- "claude-sonnet-4-20250514": {
731
- name: "Custom Name for Sonnet",
732
- },
733
- },
734
- },
735
- },
736
- }),
737
- )
738
- },
739
- })
740
- await Instance.provide({
741
- directory: tmp.path,
742
- init: async () => {
743
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
744
- },
745
- fn: async () => {
746
- const providers = await Provider.list()
747
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
748
- expect(model.name).toBe("Custom Name for Sonnet")
749
- expect(model.capabilities.toolcall).toBe(true)
750
- expect(model.capabilities.attachment).toBe(true)
751
- expect(model.limit.context).toBeGreaterThan(0)
752
- },
753
- })
754
- })
755
-
756
- test("disabled_providers prevents loading even with env var", async () => {
757
- await using tmp = await tmpdir({
758
- init: async (dir) => {
759
- await Bun.write(
760
- path.join(dir, "opencode.json"),
761
- JSON.stringify({
762
- $schema: "https://toolkode.com/config.json",
763
- disabled_providers: ["openai"],
764
- }),
765
- )
766
- },
767
- })
768
- await Instance.provide({
769
- directory: tmp.path,
770
- init: async () => {
771
- Env.set("OPENAI_API_KEY", "test-openai-key")
772
- },
773
- fn: async () => {
774
- const providers = await Provider.list()
775
- expect(providers[ProviderID.openai]).toBeUndefined()
776
- },
777
- })
778
- })
779
-
780
- test("enabled_providers with empty array allows no providers", async () => {
781
- await using tmp = await tmpdir({
782
- init: async (dir) => {
783
- await Bun.write(
784
- path.join(dir, "opencode.json"),
785
- JSON.stringify({
786
- $schema: "https://toolkode.com/config.json",
787
- enabled_providers: [],
788
- }),
789
- )
790
- },
791
- })
792
- await Instance.provide({
793
- directory: tmp.path,
794
- init: async () => {
795
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
796
- Env.set("OPENAI_API_KEY", "test-openai-key")
797
- },
798
- fn: async () => {
799
- const providers = await Provider.list()
800
- expect(Object.keys(providers).length).toBe(0)
801
- },
802
- })
803
- })
804
-
805
- test("whitelist and blacklist can be combined", async () => {
806
- await using tmp = await tmpdir({
807
- init: async (dir) => {
808
- await Bun.write(
809
- path.join(dir, "opencode.json"),
810
- JSON.stringify({
811
- $schema: "https://toolkode.com/config.json",
812
- provider: {
813
- anthropic: {
814
- whitelist: ["claude-sonnet-4-20250514", "claude-opus-4-20250514"],
815
- blacklist: ["claude-opus-4-20250514"],
816
- },
817
- },
818
- }),
819
- )
820
- },
821
- })
822
- await Instance.provide({
823
- directory: tmp.path,
824
- init: async () => {
825
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
826
- },
827
- fn: async () => {
828
- const providers = await Provider.list()
829
- expect(providers[ProviderID.anthropic]).toBeDefined()
830
- const models = Object.keys(providers[ProviderID.anthropic].models)
831
- expect(models).toContain("claude-sonnet-4-20250514")
832
- expect(models).not.toContain("claude-opus-4-20250514")
833
- expect(models.length).toBe(1)
834
- },
835
- })
836
- })
837
-
838
- test("model modalities default correctly", async () => {
839
- await using tmp = await tmpdir({
840
- init: async (dir) => {
841
- await Bun.write(
842
- path.join(dir, "opencode.json"),
843
- JSON.stringify({
844
- $schema: "https://toolkode.com/config.json",
845
- provider: {
846
- "test-provider": {
847
- name: "Test",
848
- npm: "@ai-sdk/openai-compatible",
849
- env: [],
850
- models: {
851
- "test-model": {
852
- name: "Test Model",
853
- tool_call: true,
854
- limit: { context: 8000, output: 2000 },
855
- },
856
- },
857
- options: { apiKey: "test" },
858
- },
859
- },
860
- }),
861
- )
862
- },
863
- })
864
- await Instance.provide({
865
- directory: tmp.path,
866
- fn: async () => {
867
- const providers = await Provider.list()
868
- const model = providers[ProviderID.make("test-provider")].models["test-model"]
869
- expect(model.capabilities.input.text).toBe(true)
870
- expect(model.capabilities.output.text).toBe(true)
871
- },
872
- })
873
- })
874
-
875
- test("model with custom cost values", async () => {
876
- await using tmp = await tmpdir({
877
- init: async (dir) => {
878
- await Bun.write(
879
- path.join(dir, "opencode.json"),
880
- JSON.stringify({
881
- $schema: "https://toolkode.com/config.json",
882
- provider: {
883
- "test-provider": {
884
- name: "Test",
885
- npm: "@ai-sdk/openai-compatible",
886
- env: [],
887
- models: {
888
- "test-model": {
889
- name: "Test Model",
890
- tool_call: true,
891
- limit: { context: 8000, output: 2000 },
892
- cost: {
893
- input: 5,
894
- output: 15,
895
- cache_read: 2.5,
896
- cache_write: 7.5,
897
- },
898
- },
899
- },
900
- options: { apiKey: "test" },
901
- },
902
- },
903
- }),
904
- )
905
- },
906
- })
907
- await Instance.provide({
908
- directory: tmp.path,
909
- fn: async () => {
910
- const providers = await Provider.list()
911
- const model = providers[ProviderID.make("test-provider")].models["test-model"]
912
- expect(model.cost.input).toBe(5)
913
- expect(model.cost.output).toBe(15)
914
- expect(model.cost.cache.read).toBe(2.5)
915
- expect(model.cost.cache.write).toBe(7.5)
916
- },
917
- })
918
- })
919
-
920
- test("getSmallModel returns appropriate small model", async () => {
921
- await using tmp = await tmpdir({
922
- init: async (dir) => {
923
- await Bun.write(
924
- path.join(dir, "opencode.json"),
925
- JSON.stringify({
926
- $schema: "https://toolkode.com/config.json",
927
- }),
928
- )
929
- },
930
- })
931
- await Instance.provide({
932
- directory: tmp.path,
933
- init: async () => {
934
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
935
- },
936
- fn: async () => {
937
- const model = await Provider.getSmallModel(ProviderID.anthropic)
938
- expect(model).toBeDefined()
939
- expect(model?.id).toContain("haiku")
940
- },
941
- })
942
- })
943
-
944
- test("getSmallModel respects config small_model override", async () => {
945
- await using tmp = await tmpdir({
946
- init: async (dir) => {
947
- await Bun.write(
948
- path.join(dir, "opencode.json"),
949
- JSON.stringify({
950
- $schema: "https://toolkode.com/config.json",
951
- small_model: "anthropic/claude-sonnet-4-20250514",
952
- }),
953
- )
954
- },
955
- })
956
- await Instance.provide({
957
- directory: tmp.path,
958
- init: async () => {
959
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
960
- },
961
- fn: async () => {
962
- const model = await Provider.getSmallModel(ProviderID.anthropic)
963
- expect(model).toBeDefined()
964
- expect(String(model?.providerID)).toBe("anthropic")
965
- expect(String(model?.id)).toBe("claude-sonnet-4-20250514")
966
- },
967
- })
968
- })
969
-
970
- test("provider.sort prioritizes preferred models", () => {
971
- const models = [
972
- { id: "random-model", name: "Random" },
973
- { id: "claude-sonnet-4-latest", name: "Claude Sonnet 4" },
974
- { id: "gpt-5-turbo", name: "GPT-5 Turbo" },
975
- { id: "other-model", name: "Other" },
976
- ] as any[]
977
-
978
- const sorted = Provider.sort(models)
979
- expect(sorted[0].id).toContain("sonnet-4")
980
- expect(sorted[0].id).toContain("latest")
981
- expect(sorted[sorted.length - 1].id).not.toContain("gpt-5")
982
- expect(sorted[sorted.length - 1].id).not.toContain("sonnet-4")
983
- })
984
-
985
- test("multiple providers can be configured simultaneously", async () => {
986
- await using tmp = await tmpdir({
987
- init: async (dir) => {
988
- await Bun.write(
989
- path.join(dir, "opencode.json"),
990
- JSON.stringify({
991
- $schema: "https://toolkode.com/config.json",
992
- provider: {
993
- anthropic: {
994
- options: { timeout: 30000 },
995
- },
996
- openai: {
997
- options: { timeout: 60000 },
998
- },
999
- },
1000
- }),
1001
- )
1002
- },
1003
- })
1004
- await Instance.provide({
1005
- directory: tmp.path,
1006
- init: async () => {
1007
- Env.set("ANTHROPIC_API_KEY", "test-anthropic-key")
1008
- Env.set("OPENAI_API_KEY", "test-openai-key")
1009
- },
1010
- fn: async () => {
1011
- const providers = await Provider.list()
1012
- expect(providers[ProviderID.anthropic]).toBeDefined()
1013
- expect(providers[ProviderID.openai]).toBeDefined()
1014
- expect(providers[ProviderID.anthropic].options.timeout).toBe(30000)
1015
- expect(providers[ProviderID.openai].options.timeout).toBe(60000)
1016
- },
1017
- })
1018
- })
1019
-
1020
- test("provider with custom npm package", async () => {
1021
- await using tmp = await tmpdir({
1022
- init: async (dir) => {
1023
- await Bun.write(
1024
- path.join(dir, "opencode.json"),
1025
- JSON.stringify({
1026
- $schema: "https://toolkode.com/config.json",
1027
- provider: {
1028
- "local-llm": {
1029
- name: "Local LLM",
1030
- npm: "@ai-sdk/openai-compatible",
1031
- env: [],
1032
- models: {
1033
- "llama-3": {
1034
- name: "Llama 3",
1035
- tool_call: true,
1036
- limit: { context: 8192, output: 2048 },
1037
- },
1038
- },
1039
- options: {
1040
- apiKey: "not-needed",
1041
- baseURL: "http://localhost:11434/v1",
1042
- },
1043
- },
1044
- },
1045
- }),
1046
- )
1047
- },
1048
- })
1049
- await Instance.provide({
1050
- directory: tmp.path,
1051
- fn: async () => {
1052
- const providers = await Provider.list()
1053
- expect(providers[ProviderID.make("local-llm")]).toBeDefined()
1054
- expect(providers[ProviderID.make("local-llm")].models["llama-3"].api.npm).toBe("@ai-sdk/openai-compatible")
1055
- expect(providers[ProviderID.make("local-llm")].options.baseURL).toBe("http://localhost:11434/v1")
1056
- },
1057
- })
1058
- })
1059
-
1060
- // Edge cases for model configuration
1061
-
1062
- test("model alias name defaults to alias key when id differs", async () => {
1063
- await using tmp = await tmpdir({
1064
- init: async (dir) => {
1065
- await Bun.write(
1066
- path.join(dir, "opencode.json"),
1067
- JSON.stringify({
1068
- $schema: "https://toolkode.com/config.json",
1069
- provider: {
1070
- anthropic: {
1071
- models: {
1072
- sonnet: {
1073
- id: "claude-sonnet-4-20250514",
1074
- // no name specified - should default to "sonnet" (the key)
1075
- },
1076
- },
1077
- },
1078
- },
1079
- }),
1080
- )
1081
- },
1082
- })
1083
- await Instance.provide({
1084
- directory: tmp.path,
1085
- init: async () => {
1086
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1087
- },
1088
- fn: async () => {
1089
- const providers = await Provider.list()
1090
- expect(providers[ProviderID.anthropic].models["sonnet"].name).toBe("sonnet")
1091
- },
1092
- })
1093
- })
1094
-
1095
- test("provider with multiple env var options only includes apiKey when single env", async () => {
1096
- await using tmp = await tmpdir({
1097
- init: async (dir) => {
1098
- await Bun.write(
1099
- path.join(dir, "opencode.json"),
1100
- JSON.stringify({
1101
- $schema: "https://toolkode.com/config.json",
1102
- provider: {
1103
- "multi-env": {
1104
- name: "Multi Env Provider",
1105
- npm: "@ai-sdk/openai-compatible",
1106
- env: ["MULTI_ENV_KEY_1", "MULTI_ENV_KEY_2"],
1107
- models: {
1108
- "model-1": {
1109
- name: "Model 1",
1110
- tool_call: true,
1111
- limit: { context: 8000, output: 2000 },
1112
- },
1113
- },
1114
- options: {
1115
- baseURL: "https://api.example.com/v1",
1116
- },
1117
- },
1118
- },
1119
- }),
1120
- )
1121
- },
1122
- })
1123
- await Instance.provide({
1124
- directory: tmp.path,
1125
- init: async () => {
1126
- Env.set("MULTI_ENV_KEY_1", "test-key")
1127
- },
1128
- fn: async () => {
1129
- const providers = await Provider.list()
1130
- expect(providers[ProviderID.make("multi-env")]).toBeDefined()
1131
- // When multiple env options exist, key should NOT be auto-set
1132
- expect(providers[ProviderID.make("multi-env")].key).toBeUndefined()
1133
- },
1134
- })
1135
- })
1136
-
1137
- test("provider with single env var includes apiKey automatically", async () => {
1138
- await using tmp = await tmpdir({
1139
- init: async (dir) => {
1140
- await Bun.write(
1141
- path.join(dir, "opencode.json"),
1142
- JSON.stringify({
1143
- $schema: "https://toolkode.com/config.json",
1144
- provider: {
1145
- "single-env": {
1146
- name: "Single Env Provider",
1147
- npm: "@ai-sdk/openai-compatible",
1148
- env: ["SINGLE_ENV_KEY"],
1149
- models: {
1150
- "model-1": {
1151
- name: "Model 1",
1152
- tool_call: true,
1153
- limit: { context: 8000, output: 2000 },
1154
- },
1155
- },
1156
- options: {
1157
- baseURL: "https://api.example.com/v1",
1158
- },
1159
- },
1160
- },
1161
- }),
1162
- )
1163
- },
1164
- })
1165
- await Instance.provide({
1166
- directory: tmp.path,
1167
- init: async () => {
1168
- Env.set("SINGLE_ENV_KEY", "my-api-key")
1169
- },
1170
- fn: async () => {
1171
- const providers = await Provider.list()
1172
- expect(providers[ProviderID.make("single-env")]).toBeDefined()
1173
- // Single env option should auto-set key
1174
- expect(providers[ProviderID.make("single-env")].key).toBe("my-api-key")
1175
- },
1176
- })
1177
- })
1178
-
1179
- test("model cost overrides existing cost values", async () => {
1180
- await using tmp = await tmpdir({
1181
- init: async (dir) => {
1182
- await Bun.write(
1183
- path.join(dir, "opencode.json"),
1184
- JSON.stringify({
1185
- $schema: "https://toolkode.com/config.json",
1186
- provider: {
1187
- anthropic: {
1188
- models: {
1189
- "claude-sonnet-4-20250514": {
1190
- cost: {
1191
- input: 999,
1192
- output: 888,
1193
- },
1194
- },
1195
- },
1196
- },
1197
- },
1198
- }),
1199
- )
1200
- },
1201
- })
1202
- await Instance.provide({
1203
- directory: tmp.path,
1204
- init: async () => {
1205
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1206
- },
1207
- fn: async () => {
1208
- const providers = await Provider.list()
1209
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1210
- expect(model.cost.input).toBe(999)
1211
- expect(model.cost.output).toBe(888)
1212
- },
1213
- })
1214
- })
1215
-
1216
- test("completely new provider not in database can be configured", async () => {
1217
- await using tmp = await tmpdir({
1218
- init: async (dir) => {
1219
- await Bun.write(
1220
- path.join(dir, "opencode.json"),
1221
- JSON.stringify({
1222
- $schema: "https://toolkode.com/config.json",
1223
- provider: {
1224
- "brand-new-provider": {
1225
- name: "Brand New",
1226
- npm: "@ai-sdk/openai-compatible",
1227
- env: [],
1228
- api: "https://new-api.com/v1",
1229
- models: {
1230
- "new-model": {
1231
- name: "New Model",
1232
- tool_call: true,
1233
- reasoning: true,
1234
- attachment: true,
1235
- temperature: true,
1236
- limit: { context: 32000, output: 8000 },
1237
- modalities: {
1238
- input: ["text", "image"],
1239
- output: ["text"],
1240
- },
1241
- },
1242
- },
1243
- options: {
1244
- apiKey: "new-key",
1245
- },
1246
- },
1247
- },
1248
- }),
1249
- )
1250
- },
1251
- })
1252
- await Instance.provide({
1253
- directory: tmp.path,
1254
- fn: async () => {
1255
- const providers = await Provider.list()
1256
- expect(providers[ProviderID.make("brand-new-provider")]).toBeDefined()
1257
- expect(providers[ProviderID.make("brand-new-provider")].name).toBe("Brand New")
1258
- const model = providers[ProviderID.make("brand-new-provider")].models["new-model"]
1259
- expect(model.capabilities.reasoning).toBe(true)
1260
- expect(model.capabilities.attachment).toBe(true)
1261
- expect(model.capabilities.input.image).toBe(true)
1262
- },
1263
- })
1264
- })
1265
-
1266
- test("disabled_providers and enabled_providers interaction", async () => {
1267
- await using tmp = await tmpdir({
1268
- init: async (dir) => {
1269
- await Bun.write(
1270
- path.join(dir, "opencode.json"),
1271
- JSON.stringify({
1272
- $schema: "https://toolkode.com/config.json",
1273
- // enabled_providers takes precedence - only these are considered
1274
- enabled_providers: ["anthropic", "openai"],
1275
- // Then disabled_providers filters from the enabled set
1276
- disabled_providers: ["openai"],
1277
- }),
1278
- )
1279
- },
1280
- })
1281
- await Instance.provide({
1282
- directory: tmp.path,
1283
- init: async () => {
1284
- Env.set("ANTHROPIC_API_KEY", "test-anthropic")
1285
- Env.set("OPENAI_API_KEY", "test-openai")
1286
- Env.set("GOOGLE_GENERATIVE_AI_API_KEY", "test-google")
1287
- },
1288
- fn: async () => {
1289
- const providers = await Provider.list()
1290
- // anthropic: in enabled, not in disabled = allowed
1291
- expect(providers[ProviderID.anthropic]).toBeDefined()
1292
- // openai: in enabled, but also in disabled = NOT allowed
1293
- expect(providers[ProviderID.openai]).toBeUndefined()
1294
- // google: not in enabled = NOT allowed (even though not disabled)
1295
- expect(providers[ProviderID.google]).toBeUndefined()
1296
- },
1297
- })
1298
- })
1299
-
1300
- test("model with tool_call false", async () => {
1301
- await using tmp = await tmpdir({
1302
- init: async (dir) => {
1303
- await Bun.write(
1304
- path.join(dir, "opencode.json"),
1305
- JSON.stringify({
1306
- $schema: "https://toolkode.com/config.json",
1307
- provider: {
1308
- "no-tools": {
1309
- name: "No Tools Provider",
1310
- npm: "@ai-sdk/openai-compatible",
1311
- env: [],
1312
- models: {
1313
- "basic-model": {
1314
- name: "Basic Model",
1315
- tool_call: false,
1316
- limit: { context: 4000, output: 1000 },
1317
- },
1318
- },
1319
- options: { apiKey: "test" },
1320
- },
1321
- },
1322
- }),
1323
- )
1324
- },
1325
- })
1326
- await Instance.provide({
1327
- directory: tmp.path,
1328
- fn: async () => {
1329
- const providers = await Provider.list()
1330
- expect(providers[ProviderID.make("no-tools")].models["basic-model"].capabilities.toolcall).toBe(false)
1331
- },
1332
- })
1333
- })
1334
-
1335
- test("model defaults tool_call to true when not specified", async () => {
1336
- await using tmp = await tmpdir({
1337
- init: async (dir) => {
1338
- await Bun.write(
1339
- path.join(dir, "opencode.json"),
1340
- JSON.stringify({
1341
- $schema: "https://toolkode.com/config.json",
1342
- provider: {
1343
- "default-tools": {
1344
- name: "Default Tools Provider",
1345
- npm: "@ai-sdk/openai-compatible",
1346
- env: [],
1347
- models: {
1348
- model: {
1349
- name: "Model",
1350
- // tool_call not specified
1351
- limit: { context: 4000, output: 1000 },
1352
- },
1353
- },
1354
- options: { apiKey: "test" },
1355
- },
1356
- },
1357
- }),
1358
- )
1359
- },
1360
- })
1361
- await Instance.provide({
1362
- directory: tmp.path,
1363
- fn: async () => {
1364
- const providers = await Provider.list()
1365
- expect(providers[ProviderID.make("default-tools")].models["model"].capabilities.toolcall).toBe(true)
1366
- },
1367
- })
1368
- })
1369
-
1370
- test("model headers are preserved", async () => {
1371
- await using tmp = await tmpdir({
1372
- init: async (dir) => {
1373
- await Bun.write(
1374
- path.join(dir, "opencode.json"),
1375
- JSON.stringify({
1376
- $schema: "https://toolkode.com/config.json",
1377
- provider: {
1378
- "headers-provider": {
1379
- name: "Headers Provider",
1380
- npm: "@ai-sdk/openai-compatible",
1381
- env: [],
1382
- models: {
1383
- model: {
1384
- name: "Model",
1385
- tool_call: true,
1386
- limit: { context: 4000, output: 1000 },
1387
- headers: {
1388
- "X-Custom-Header": "custom-value",
1389
- Authorization: "Bearer special-token",
1390
- },
1391
- },
1392
- },
1393
- options: { apiKey: "test" },
1394
- },
1395
- },
1396
- }),
1397
- )
1398
- },
1399
- })
1400
- await Instance.provide({
1401
- directory: tmp.path,
1402
- fn: async () => {
1403
- const providers = await Provider.list()
1404
- const model = providers[ProviderID.make("headers-provider")].models["model"]
1405
- expect(model.headers).toEqual({
1406
- "X-Custom-Header": "custom-value",
1407
- Authorization: "Bearer special-token",
1408
- })
1409
- },
1410
- })
1411
- })
1412
-
1413
- test("provider env fallback - second env var used if first missing", async () => {
1414
- await using tmp = await tmpdir({
1415
- init: async (dir) => {
1416
- await Bun.write(
1417
- path.join(dir, "opencode.json"),
1418
- JSON.stringify({
1419
- $schema: "https://toolkode.com/config.json",
1420
- provider: {
1421
- "fallback-env": {
1422
- name: "Fallback Env Provider",
1423
- npm: "@ai-sdk/openai-compatible",
1424
- env: ["PRIMARY_KEY", "FALLBACK_KEY"],
1425
- models: {
1426
- model: {
1427
- name: "Model",
1428
- tool_call: true,
1429
- limit: { context: 4000, output: 1000 },
1430
- },
1431
- },
1432
- options: { baseURL: "https://api.example.com" },
1433
- },
1434
- },
1435
- }),
1436
- )
1437
- },
1438
- })
1439
- await Instance.provide({
1440
- directory: tmp.path,
1441
- init: async () => {
1442
- // Only set fallback, not primary
1443
- Env.set("FALLBACK_KEY", "fallback-api-key")
1444
- },
1445
- fn: async () => {
1446
- const providers = await Provider.list()
1447
- // Provider should load because fallback env var is set
1448
- expect(providers[ProviderID.make("fallback-env")]).toBeDefined()
1449
- },
1450
- })
1451
- })
1452
-
1453
- test("getModel returns consistent results", async () => {
1454
- await using tmp = await tmpdir({
1455
- init: async (dir) => {
1456
- await Bun.write(
1457
- path.join(dir, "opencode.json"),
1458
- JSON.stringify({
1459
- $schema: "https://toolkode.com/config.json",
1460
- }),
1461
- )
1462
- },
1463
- })
1464
- await Instance.provide({
1465
- directory: tmp.path,
1466
- init: async () => {
1467
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1468
- },
1469
- fn: async () => {
1470
- const model1 = await Provider.getModel(ProviderID.anthropic, ModelID.make("claude-sonnet-4-20250514"))
1471
- const model2 = await Provider.getModel(ProviderID.anthropic, ModelID.make("claude-sonnet-4-20250514"))
1472
- expect(model1.providerID).toEqual(model2.providerID)
1473
- expect(model1.id).toEqual(model2.id)
1474
- expect(model1).toEqual(model2)
1475
- },
1476
- })
1477
- })
1478
-
1479
- test("provider name defaults to id when not in database", async () => {
1480
- await using tmp = await tmpdir({
1481
- init: async (dir) => {
1482
- await Bun.write(
1483
- path.join(dir, "opencode.json"),
1484
- JSON.stringify({
1485
- $schema: "https://toolkode.com/config.json",
1486
- provider: {
1487
- "my-custom-id": {
1488
- // no name specified
1489
- npm: "@ai-sdk/openai-compatible",
1490
- env: [],
1491
- models: {
1492
- model: {
1493
- name: "Model",
1494
- tool_call: true,
1495
- limit: { context: 4000, output: 1000 },
1496
- },
1497
- },
1498
- options: { apiKey: "test" },
1499
- },
1500
- },
1501
- }),
1502
- )
1503
- },
1504
- })
1505
- await Instance.provide({
1506
- directory: tmp.path,
1507
- fn: async () => {
1508
- const providers = await Provider.list()
1509
- expect(providers[ProviderID.make("my-custom-id")].name).toBe("my-custom-id")
1510
- },
1511
- })
1512
- })
1513
-
1514
- test("ModelNotFoundError includes suggestions for typos", async () => {
1515
- await using tmp = await tmpdir({
1516
- init: async (dir) => {
1517
- await Bun.write(
1518
- path.join(dir, "opencode.json"),
1519
- JSON.stringify({
1520
- $schema: "https://toolkode.com/config.json",
1521
- }),
1522
- )
1523
- },
1524
- })
1525
- await Instance.provide({
1526
- directory: tmp.path,
1527
- init: async () => {
1528
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1529
- },
1530
- fn: async () => {
1531
- try {
1532
- await Provider.getModel(ProviderID.anthropic, ModelID.make("claude-sonet-4")) // typo: sonet instead of sonnet
1533
- expect(true).toBe(false) // Should not reach here
1534
- } catch (e: any) {
1535
- expect(e.data.suggestions).toBeDefined()
1536
- expect(e.data.suggestions.length).toBeGreaterThan(0)
1537
- }
1538
- },
1539
- })
1540
- })
1541
-
1542
- test("ModelNotFoundError for provider includes suggestions", async () => {
1543
- await using tmp = await tmpdir({
1544
- init: async (dir) => {
1545
- await Bun.write(
1546
- path.join(dir, "opencode.json"),
1547
- JSON.stringify({
1548
- $schema: "https://toolkode.com/config.json",
1549
- }),
1550
- )
1551
- },
1552
- })
1553
- await Instance.provide({
1554
- directory: tmp.path,
1555
- init: async () => {
1556
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1557
- },
1558
- fn: async () => {
1559
- try {
1560
- await Provider.getModel(ProviderID.make("antropic"), ModelID.make("claude-sonnet-4")) // typo: antropic
1561
- expect(true).toBe(false) // Should not reach here
1562
- } catch (e: any) {
1563
- expect(e.data.suggestions).toBeDefined()
1564
- expect(e.data.suggestions).toContain("anthropic")
1565
- }
1566
- },
1567
- })
1568
- })
1569
-
1570
- test("getProvider returns undefined for nonexistent provider", async () => {
1571
- await using tmp = await tmpdir({
1572
- init: async (dir) => {
1573
- await Bun.write(
1574
- path.join(dir, "opencode.json"),
1575
- JSON.stringify({
1576
- $schema: "https://toolkode.com/config.json",
1577
- }),
1578
- )
1579
- },
1580
- })
1581
- await Instance.provide({
1582
- directory: tmp.path,
1583
- fn: async () => {
1584
- const provider = await Provider.getProvider(ProviderID.make("nonexistent"))
1585
- expect(provider).toBeUndefined()
1586
- },
1587
- })
1588
- })
1589
-
1590
- test("getProvider returns provider info", async () => {
1591
- await using tmp = await tmpdir({
1592
- init: async (dir) => {
1593
- await Bun.write(
1594
- path.join(dir, "opencode.json"),
1595
- JSON.stringify({
1596
- $schema: "https://toolkode.com/config.json",
1597
- }),
1598
- )
1599
- },
1600
- })
1601
- await Instance.provide({
1602
- directory: tmp.path,
1603
- init: async () => {
1604
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1605
- },
1606
- fn: async () => {
1607
- const provider = await Provider.getProvider(ProviderID.anthropic)
1608
- expect(provider).toBeDefined()
1609
- expect(String(provider?.id)).toBe("anthropic")
1610
- },
1611
- })
1612
- })
1613
-
1614
- test("closest returns undefined when no partial match found", async () => {
1615
- await using tmp = await tmpdir({
1616
- init: async (dir) => {
1617
- await Bun.write(
1618
- path.join(dir, "opencode.json"),
1619
- JSON.stringify({
1620
- $schema: "https://toolkode.com/config.json",
1621
- }),
1622
- )
1623
- },
1624
- })
1625
- await Instance.provide({
1626
- directory: tmp.path,
1627
- init: async () => {
1628
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1629
- },
1630
- fn: async () => {
1631
- const result = await Provider.closest(ProviderID.anthropic, ["nonexistent-xyz-model"])
1632
- expect(result).toBeUndefined()
1633
- },
1634
- })
1635
- })
1636
-
1637
- test("closest checks multiple query terms in order", async () => {
1638
- await using tmp = await tmpdir({
1639
- init: async (dir) => {
1640
- await Bun.write(
1641
- path.join(dir, "opencode.json"),
1642
- JSON.stringify({
1643
- $schema: "https://toolkode.com/config.json",
1644
- }),
1645
- )
1646
- },
1647
- })
1648
- await Instance.provide({
1649
- directory: tmp.path,
1650
- init: async () => {
1651
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1652
- },
1653
- fn: async () => {
1654
- // First term won't match, second will
1655
- const result = await Provider.closest(ProviderID.anthropic, ["nonexistent", "haiku"])
1656
- expect(result).toBeDefined()
1657
- expect(result?.modelID).toContain("haiku")
1658
- },
1659
- })
1660
- })
1661
-
1662
- test("model limit defaults to zero when not specified", async () => {
1663
- await using tmp = await tmpdir({
1664
- init: async (dir) => {
1665
- await Bun.write(
1666
- path.join(dir, "opencode.json"),
1667
- JSON.stringify({
1668
- $schema: "https://toolkode.com/config.json",
1669
- provider: {
1670
- "no-limit": {
1671
- name: "No Limit Provider",
1672
- npm: "@ai-sdk/openai-compatible",
1673
- env: [],
1674
- models: {
1675
- model: {
1676
- name: "Model",
1677
- tool_call: true,
1678
- // no limit specified
1679
- },
1680
- },
1681
- options: { apiKey: "test" },
1682
- },
1683
- },
1684
- }),
1685
- )
1686
- },
1687
- })
1688
- await Instance.provide({
1689
- directory: tmp.path,
1690
- fn: async () => {
1691
- const providers = await Provider.list()
1692
- const model = providers[ProviderID.make("no-limit")].models["model"]
1693
- expect(model.limit.context).toBe(0)
1694
- expect(model.limit.output).toBe(0)
1695
- },
1696
- })
1697
- })
1698
-
1699
- test("provider options are deeply merged", async () => {
1700
- await using tmp = await tmpdir({
1701
- init: async (dir) => {
1702
- await Bun.write(
1703
- path.join(dir, "opencode.json"),
1704
- JSON.stringify({
1705
- $schema: "https://toolkode.com/config.json",
1706
- provider: {
1707
- anthropic: {
1708
- options: {
1709
- headers: {
1710
- "X-Custom": "custom-value",
1711
- },
1712
- timeout: 30000,
1713
- },
1714
- },
1715
- },
1716
- }),
1717
- )
1718
- },
1719
- })
1720
- await Instance.provide({
1721
- directory: tmp.path,
1722
- init: async () => {
1723
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1724
- },
1725
- fn: async () => {
1726
- const providers = await Provider.list()
1727
- // Custom options should be merged
1728
- expect(providers[ProviderID.anthropic].options.timeout).toBe(30000)
1729
- expect(providers[ProviderID.anthropic].options.headers["X-Custom"]).toBe("custom-value")
1730
- // anthropic custom loader adds its own headers, they should coexist
1731
- expect(providers[ProviderID.anthropic].options.headers["anthropic-beta"]).toBeDefined()
1732
- },
1733
- })
1734
- })
1735
-
1736
- test("custom model inherits npm package from models.dev provider config", async () => {
1737
- await using tmp = await tmpdir({
1738
- init: async (dir) => {
1739
- await Bun.write(
1740
- path.join(dir, "opencode.json"),
1741
- JSON.stringify({
1742
- $schema: "https://toolkode.com/config.json",
1743
- provider: {
1744
- openai: {
1745
- models: {
1746
- "my-custom-model": {
1747
- name: "My Custom Model",
1748
- tool_call: true,
1749
- limit: { context: 8000, output: 2000 },
1750
- },
1751
- },
1752
- },
1753
- },
1754
- }),
1755
- )
1756
- },
1757
- })
1758
- await Instance.provide({
1759
- directory: tmp.path,
1760
- init: async () => {
1761
- Env.set("OPENAI_API_KEY", "test-api-key")
1762
- },
1763
- fn: async () => {
1764
- const providers = await Provider.list()
1765
- const model = providers[ProviderID.openai].models["my-custom-model"]
1766
- expect(model).toBeDefined()
1767
- expect(model.api.npm).toBe("@ai-sdk/openai")
1768
- },
1769
- })
1770
- })
1771
-
1772
- test("custom model inherits api.url from models.dev provider", async () => {
1773
- await using tmp = await tmpdir({
1774
- init: async (dir) => {
1775
- await Bun.write(
1776
- path.join(dir, "opencode.json"),
1777
- JSON.stringify({
1778
- $schema: "https://toolkode.com/config.json",
1779
- provider: {
1780
- openrouter: {
1781
- models: {
1782
- "prime-intellect/intellect-3": {},
1783
- "deepseek/deepseek-r1-0528": {
1784
- name: "DeepSeek R1",
1785
- },
1786
- },
1787
- },
1788
- },
1789
- }),
1790
- )
1791
- },
1792
- })
1793
- await Instance.provide({
1794
- directory: tmp.path,
1795
- init: async () => {
1796
- Env.set("OPENROUTER_API_KEY", "test-api-key")
1797
- },
1798
- fn: async () => {
1799
- const providers = await Provider.list()
1800
- expect(providers[ProviderID.openrouter]).toBeDefined()
1801
-
1802
- // New model not in database should inherit api.url from provider
1803
- const intellect = providers[ProviderID.openrouter].models["prime-intellect/intellect-3"]
1804
- expect(intellect).toBeDefined()
1805
- expect(intellect.api.url).toBe("https://openrouter.ai/api/v1")
1806
-
1807
- // Another new model should also inherit api.url
1808
- const deepseek = providers[ProviderID.openrouter].models["deepseek/deepseek-r1-0528"]
1809
- expect(deepseek).toBeDefined()
1810
- expect(deepseek.api.url).toBe("https://openrouter.ai/api/v1")
1811
- expect(deepseek.name).toBe("DeepSeek R1")
1812
- },
1813
- })
1814
- })
1815
-
1816
- test("model variants are generated for reasoning models", async () => {
1817
- await using tmp = await tmpdir({
1818
- init: async (dir) => {
1819
- await Bun.write(
1820
- path.join(dir, "opencode.json"),
1821
- JSON.stringify({
1822
- $schema: "https://toolkode.com/config.json",
1823
- }),
1824
- )
1825
- },
1826
- })
1827
- await Instance.provide({
1828
- directory: tmp.path,
1829
- init: async () => {
1830
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1831
- },
1832
- fn: async () => {
1833
- const providers = await Provider.list()
1834
- // Claude sonnet 4 has reasoning capability
1835
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1836
- expect(model.capabilities.reasoning).toBe(true)
1837
- expect(model.variants).toBeDefined()
1838
- expect(Object.keys(model.variants!).length).toBeGreaterThan(0)
1839
- },
1840
- })
1841
- })
1842
-
1843
- test("model variants can be disabled via config", async () => {
1844
- await using tmp = await tmpdir({
1845
- init: async (dir) => {
1846
- await Bun.write(
1847
- path.join(dir, "opencode.json"),
1848
- JSON.stringify({
1849
- $schema: "https://toolkode.com/config.json",
1850
- provider: {
1851
- anthropic: {
1852
- models: {
1853
- "claude-sonnet-4-20250514": {
1854
- variants: {
1855
- high: { disabled: true },
1856
- },
1857
- },
1858
- },
1859
- },
1860
- },
1861
- }),
1862
- )
1863
- },
1864
- })
1865
- await Instance.provide({
1866
- directory: tmp.path,
1867
- init: async () => {
1868
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1869
- },
1870
- fn: async () => {
1871
- const providers = await Provider.list()
1872
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1873
- expect(model.variants).toBeDefined()
1874
- expect(model.variants!["high"]).toBeUndefined()
1875
- // max variant should still exist
1876
- expect(model.variants!["max"]).toBeDefined()
1877
- },
1878
- })
1879
- })
1880
-
1881
- test("model variants can be customized via config", async () => {
1882
- await using tmp = await tmpdir({
1883
- init: async (dir) => {
1884
- await Bun.write(
1885
- path.join(dir, "opencode.json"),
1886
- JSON.stringify({
1887
- $schema: "https://toolkode.com/config.json",
1888
- provider: {
1889
- anthropic: {
1890
- models: {
1891
- "claude-sonnet-4-20250514": {
1892
- variants: {
1893
- high: {
1894
- thinking: {
1895
- type: "enabled",
1896
- budgetTokens: 20000,
1897
- },
1898
- },
1899
- },
1900
- },
1901
- },
1902
- },
1903
- },
1904
- }),
1905
- )
1906
- },
1907
- })
1908
- await Instance.provide({
1909
- directory: tmp.path,
1910
- init: async () => {
1911
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1912
- },
1913
- fn: async () => {
1914
- const providers = await Provider.list()
1915
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1916
- expect(model.variants!["high"]).toBeDefined()
1917
- expect(model.variants!["high"].thinking.budgetTokens).toBe(20000)
1918
- },
1919
- })
1920
- })
1921
-
1922
- test("disabled key is stripped from variant config", async () => {
1923
- await using tmp = await tmpdir({
1924
- init: async (dir) => {
1925
- await Bun.write(
1926
- path.join(dir, "opencode.json"),
1927
- JSON.stringify({
1928
- $schema: "https://toolkode.com/config.json",
1929
- provider: {
1930
- anthropic: {
1931
- models: {
1932
- "claude-sonnet-4-20250514": {
1933
- variants: {
1934
- max: {
1935
- disabled: false,
1936
- customField: "test",
1937
- },
1938
- },
1939
- },
1940
- },
1941
- },
1942
- },
1943
- }),
1944
- )
1945
- },
1946
- })
1947
- await Instance.provide({
1948
- directory: tmp.path,
1949
- init: async () => {
1950
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1951
- },
1952
- fn: async () => {
1953
- const providers = await Provider.list()
1954
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1955
- expect(model.variants!["max"]).toBeDefined()
1956
- expect(model.variants!["max"].disabled).toBeUndefined()
1957
- expect(model.variants!["max"].customField).toBe("test")
1958
- },
1959
- })
1960
- })
1961
-
1962
- test("all variants can be disabled via config", async () => {
1963
- await using tmp = await tmpdir({
1964
- init: async (dir) => {
1965
- await Bun.write(
1966
- path.join(dir, "opencode.json"),
1967
- JSON.stringify({
1968
- $schema: "https://toolkode.com/config.json",
1969
- provider: {
1970
- anthropic: {
1971
- models: {
1972
- "claude-sonnet-4-20250514": {
1973
- variants: {
1974
- high: { disabled: true },
1975
- max: { disabled: true },
1976
- },
1977
- },
1978
- },
1979
- },
1980
- },
1981
- }),
1982
- )
1983
- },
1984
- })
1985
- await Instance.provide({
1986
- directory: tmp.path,
1987
- init: async () => {
1988
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1989
- },
1990
- fn: async () => {
1991
- const providers = await Provider.list()
1992
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
1993
- expect(model.variants).toBeDefined()
1994
- expect(Object.keys(model.variants!).length).toBe(0)
1995
- },
1996
- })
1997
- })
1998
-
1999
- test("variant config merges with generated variants", async () => {
2000
- await using tmp = await tmpdir({
2001
- init: async (dir) => {
2002
- await Bun.write(
2003
- path.join(dir, "opencode.json"),
2004
- JSON.stringify({
2005
- $schema: "https://toolkode.com/config.json",
2006
- provider: {
2007
- anthropic: {
2008
- models: {
2009
- "claude-sonnet-4-20250514": {
2010
- variants: {
2011
- high: {
2012
- extraOption: "custom-value",
2013
- },
2014
- },
2015
- },
2016
- },
2017
- },
2018
- },
2019
- }),
2020
- )
2021
- },
2022
- })
2023
- await Instance.provide({
2024
- directory: tmp.path,
2025
- init: async () => {
2026
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
2027
- },
2028
- fn: async () => {
2029
- const providers = await Provider.list()
2030
- const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
2031
- expect(model.variants!["high"]).toBeDefined()
2032
- // Should have both the generated thinking config and the custom option
2033
- expect(model.variants!["high"].thinking).toBeDefined()
2034
- expect(model.variants!["high"].extraOption).toBe("custom-value")
2035
- },
2036
- })
2037
- })
2038
-
2039
- test("variants filtered in second pass for database models", async () => {
2040
- await using tmp = await tmpdir({
2041
- init: async (dir) => {
2042
- await Bun.write(
2043
- path.join(dir, "opencode.json"),
2044
- JSON.stringify({
2045
- $schema: "https://toolkode.com/config.json",
2046
- provider: {
2047
- openai: {
2048
- models: {
2049
- "gpt-5": {
2050
- variants: {
2051
- high: { disabled: true },
2052
- },
2053
- },
2054
- },
2055
- },
2056
- },
2057
- }),
2058
- )
2059
- },
2060
- })
2061
- await Instance.provide({
2062
- directory: tmp.path,
2063
- init: async () => {
2064
- Env.set("OPENAI_API_KEY", "test-api-key")
2065
- },
2066
- fn: async () => {
2067
- const providers = await Provider.list()
2068
- const model = providers[ProviderID.openai].models["gpt-5"]
2069
- expect(model.variants).toBeDefined()
2070
- expect(model.variants!["high"]).toBeUndefined()
2071
- // Other variants should still exist
2072
- expect(model.variants!["medium"]).toBeDefined()
2073
- },
2074
- })
2075
- })
2076
-
2077
- test("custom model with variants enabled and disabled", async () => {
2078
- await using tmp = await tmpdir({
2079
- init: async (dir) => {
2080
- await Bun.write(
2081
- path.join(dir, "opencode.json"),
2082
- JSON.stringify({
2083
- $schema: "https://toolkode.com/config.json",
2084
- provider: {
2085
- "custom-reasoning": {
2086
- name: "Custom Reasoning Provider",
2087
- npm: "@ai-sdk/openai-compatible",
2088
- env: [],
2089
- models: {
2090
- "reasoning-model": {
2091
- name: "Reasoning Model",
2092
- tool_call: true,
2093
- reasoning: true,
2094
- limit: { context: 128000, output: 16000 },
2095
- variants: {
2096
- low: { reasoningEffort: "low" },
2097
- medium: { reasoningEffort: "medium" },
2098
- high: { reasoningEffort: "high", disabled: true },
2099
- custom: { reasoningEffort: "custom", budgetTokens: 5000 },
2100
- },
2101
- },
2102
- },
2103
- options: { apiKey: "test-key" },
2104
- },
2105
- },
2106
- }),
2107
- )
2108
- },
2109
- })
2110
- await Instance.provide({
2111
- directory: tmp.path,
2112
- fn: async () => {
2113
- const providers = await Provider.list()
2114
- const model = providers[ProviderID.make("custom-reasoning")].models["reasoning-model"]
2115
- expect(model.variants).toBeDefined()
2116
- // Enabled variants should exist
2117
- expect(model.variants!["low"]).toBeDefined()
2118
- expect(model.variants!["low"].reasoningEffort).toBe("low")
2119
- expect(model.variants!["medium"]).toBeDefined()
2120
- expect(model.variants!["medium"].reasoningEffort).toBe("medium")
2121
- expect(model.variants!["custom"]).toBeDefined()
2122
- expect(model.variants!["custom"].reasoningEffort).toBe("custom")
2123
- expect(model.variants!["custom"].budgetTokens).toBe(5000)
2124
- // Disabled variant should not exist
2125
- expect(model.variants!["high"]).toBeUndefined()
2126
- // disabled key should be stripped from all variants
2127
- expect(model.variants!["low"].disabled).toBeUndefined()
2128
- expect(model.variants!["medium"].disabled).toBeUndefined()
2129
- expect(model.variants!["custom"].disabled).toBeUndefined()
2130
- },
2131
- })
2132
- })
2133
-
2134
- test("Google Vertex: retains baseURL for custom proxy", async () => {
2135
- await using tmp = await tmpdir({
2136
- init: async (dir) => {
2137
- await Bun.write(
2138
- path.join(dir, "opencode.json"),
2139
- JSON.stringify({
2140
- $schema: "https://toolkode.com/config.json",
2141
- provider: {
2142
- "vertex-proxy": {
2143
- name: "Vertex Proxy",
2144
- npm: "@ai-sdk/google-vertex",
2145
- api: "https://my-proxy.com/v1",
2146
- env: ["GOOGLE_APPLICATION_CREDENTIALS"], // Mock env var requirement
2147
- models: {
2148
- "gemini-pro": {
2149
- name: "Gemini Pro",
2150
- tool_call: true,
2151
- },
2152
- },
2153
- options: {
2154
- project: "test-project",
2155
- location: "us-central1",
2156
- baseURL: "https://my-proxy.com/v1", // Should be retained
2157
- },
2158
- },
2159
- },
2160
- }),
2161
- )
2162
- },
2163
- })
2164
-
2165
- await Instance.provide({
2166
- directory: tmp.path,
2167
- init: async () => {
2168
- Env.set("GOOGLE_APPLICATION_CREDENTIALS", "test-creds")
2169
- },
2170
- fn: async () => {
2171
- const providers = await Provider.list()
2172
- expect(providers[ProviderID.make("vertex-proxy")]).toBeDefined()
2173
- expect(providers[ProviderID.make("vertex-proxy")].options.baseURL).toBe("https://my-proxy.com/v1")
2174
- },
2175
- })
2176
- })
2177
-
2178
- test("Google Vertex: supports OpenAI compatible models", async () => {
2179
- await using tmp = await tmpdir({
2180
- init: async (dir) => {
2181
- await Bun.write(
2182
- path.join(dir, "opencode.json"),
2183
- JSON.stringify({
2184
- $schema: "https://toolkode.com/config.json",
2185
- provider: {
2186
- "vertex-openai": {
2187
- name: "Vertex OpenAI",
2188
- npm: "@ai-sdk/google-vertex",
2189
- env: ["GOOGLE_APPLICATION_CREDENTIALS"],
2190
- models: {
2191
- "gpt-4": {
2192
- name: "GPT-4",
2193
- provider: {
2194
- npm: "@ai-sdk/openai-compatible",
2195
- api: "https://api.openai.com/v1",
2196
- },
2197
- },
2198
- },
2199
- options: {
2200
- project: "test-project",
2201
- location: "us-central1",
2202
- },
2203
- },
2204
- },
2205
- }),
2206
- )
2207
- },
2208
- })
2209
-
2210
- await Instance.provide({
2211
- directory: tmp.path,
2212
- init: async () => {
2213
- Env.set("GOOGLE_APPLICATION_CREDENTIALS", "test-creds")
2214
- },
2215
- fn: async () => {
2216
- const providers = await Provider.list()
2217
- const model = providers[ProviderID.make("vertex-openai")].models["gpt-4"]
2218
-
2219
- expect(model).toBeDefined()
2220
- expect(model.api.npm).toBe("@ai-sdk/openai-compatible")
2221
- },
2222
- })
2223
- })
2224
-
2225
- test("cloudflare-ai-gateway loads with env variables", async () => {
2226
- await using tmp = await tmpdir({
2227
- init: async (dir) => {
2228
- await Bun.write(
2229
- path.join(dir, "opencode.json"),
2230
- JSON.stringify({
2231
- $schema: "https://toolkode.com/config.json",
2232
- }),
2233
- )
2234
- },
2235
- })
2236
- await Instance.provide({
2237
- directory: tmp.path,
2238
- init: async () => {
2239
- Env.set("CLOUDFLARE_ACCOUNT_ID", "test-account")
2240
- Env.set("CLOUDFLARE_GATEWAY_ID", "test-gateway")
2241
- Env.set("CLOUDFLARE_API_TOKEN", "test-token")
2242
- },
2243
- fn: async () => {
2244
- const providers = await Provider.list()
2245
- expect(providers[ProviderID.make("cloudflare-ai-gateway")]).toBeDefined()
2246
- },
2247
- })
2248
- })
2249
-
2250
- test("cloudflare-ai-gateway forwards config metadata options", async () => {
2251
- await using tmp = await tmpdir({
2252
- init: async (dir) => {
2253
- await Bun.write(
2254
- path.join(dir, "opencode.json"),
2255
- JSON.stringify({
2256
- $schema: "https://toolkode.com/config.json",
2257
- provider: {
2258
- "cloudflare-ai-gateway": {
2259
- options: {
2260
- metadata: { invoked_by: "test", project: "opencode" },
2261
- },
2262
- },
2263
- },
2264
- }),
2265
- )
2266
- },
2267
- })
2268
- await Instance.provide({
2269
- directory: tmp.path,
2270
- init: async () => {
2271
- Env.set("CLOUDFLARE_ACCOUNT_ID", "test-account")
2272
- Env.set("CLOUDFLARE_GATEWAY_ID", "test-gateway")
2273
- Env.set("CLOUDFLARE_API_TOKEN", "test-token")
2274
- },
2275
- fn: async () => {
2276
- const providers = await Provider.list()
2277
- expect(providers[ProviderID.make("cloudflare-ai-gateway")]).toBeDefined()
2278
- expect(providers[ProviderID.make("cloudflare-ai-gateway")].options.metadata).toEqual({
2279
- invoked_by: "test",
2280
- project: "opencode",
2281
- })
2282
- },
2283
- })
2284
- })