cerebras-cli 1.0.1 → 1.0.4

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 (314) hide show
  1. package/README.md +3 -5
  2. package/cerebras-cli-1.0.0.tgz +0 -0
  3. package/package.json +7 -88
  4. package/AGENTS.md +0 -27
  5. package/Dockerfile +0 -10
  6. package/bunfig.toml +0 -4
  7. package/parsers-config.ts +0 -239
  8. package/script/build.ts +0 -151
  9. package/script/postinstall.mjs +0 -122
  10. package/script/publish.ts +0 -256
  11. package/script/schema.ts +0 -47
  12. package/src/acp/README.md +0 -164
  13. package/src/acp/agent.ts +0 -812
  14. package/src/acp/session.ts +0 -70
  15. package/src/acp/types.ts +0 -22
  16. package/src/agent/agent.ts +0 -310
  17. package/src/agent/generate.txt +0 -75
  18. package/src/auth/index.ts +0 -70
  19. package/src/bun/index.ts +0 -152
  20. package/src/bus/global.ts +0 -10
  21. package/src/bus/index.ts +0 -142
  22. package/src/cli/bootstrap.ts +0 -17
  23. package/src/cli/cmd/acp.ts +0 -88
  24. package/src/cli/cmd/agent.ts +0 -165
  25. package/src/cli/cmd/auth.ts +0 -369
  26. package/src/cli/cmd/cmd.ts +0 -7
  27. package/src/cli/cmd/debug/config.ts +0 -15
  28. package/src/cli/cmd/debug/file.ts +0 -91
  29. package/src/cli/cmd/debug/index.ts +0 -41
  30. package/src/cli/cmd/debug/lsp.ts +0 -47
  31. package/src/cli/cmd/debug/ripgrep.ts +0 -83
  32. package/src/cli/cmd/debug/scrap.ts +0 -15
  33. package/src/cli/cmd/debug/snapshot.ts +0 -48
  34. package/src/cli/cmd/export.ts +0 -88
  35. package/src/cli/cmd/generate.ts +0 -38
  36. package/src/cli/cmd/github.ts +0 -1200
  37. package/src/cli/cmd/import.ts +0 -98
  38. package/src/cli/cmd/mcp.ts +0 -400
  39. package/src/cli/cmd/models.ts +0 -77
  40. package/src/cli/cmd/pr.ts +0 -112
  41. package/src/cli/cmd/run.ts +0 -342
  42. package/src/cli/cmd/serve.ts +0 -31
  43. package/src/cli/cmd/session.ts +0 -106
  44. package/src/cli/cmd/stats.ts +0 -298
  45. package/src/cli/cmd/tui/app.tsx +0 -732
  46. package/src/cli/cmd/tui/attach.ts +0 -25
  47. package/src/cli/cmd/tui/component/border.tsx +0 -21
  48. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  49. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
  50. package/src/cli/cmd/tui/component/dialog-feedback.tsx +0 -160
  51. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  52. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -223
  53. package/src/cli/cmd/tui/component/dialog-notification.tsx +0 -78
  54. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -222
  55. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -97
  56. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  57. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -114
  58. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  59. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  60. package/src/cli/cmd/tui/component/logo.tsx +0 -37
  61. package/src/cli/cmd/tui/component/notification-banner.tsx +0 -58
  62. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -530
  63. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -107
  64. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -931
  65. package/src/cli/cmd/tui/context/args.tsx +0 -14
  66. package/src/cli/cmd/tui/context/directory.ts +0 -12
  67. package/src/cli/cmd/tui/context/exit.tsx +0 -23
  68. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  69. package/src/cli/cmd/tui/context/keybind.tsx +0 -111
  70. package/src/cli/cmd/tui/context/kv.tsx +0 -49
  71. package/src/cli/cmd/tui/context/local.tsx +0 -339
  72. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  73. package/src/cli/cmd/tui/context/route.tsx +0 -45
  74. package/src/cli/cmd/tui/context/sdk.tsx +0 -75
  75. package/src/cli/cmd/tui/context/sync.tsx +0 -374
  76. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  77. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  78. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  79. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  80. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  81. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  82. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  83. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  84. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  85. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
  86. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  87. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  88. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  89. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  90. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  91. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  92. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  93. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  94. package/src/cli/cmd/tui/context/theme/orng.json +0 -245
  95. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  96. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  97. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  98. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  99. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  100. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  101. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  102. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  103. package/src/cli/cmd/tui/context/theme.tsx +0 -1077
  104. package/src/cli/cmd/tui/event.ts +0 -39
  105. package/src/cli/cmd/tui/routes/home.tsx +0 -104
  106. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -93
  107. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -37
  108. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -76
  109. package/src/cli/cmd/tui/routes/session/header.tsx +0 -183
  110. package/src/cli/cmd/tui/routes/session/index.tsx +0 -1703
  111. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -586
  112. package/src/cli/cmd/tui/spawn.ts +0 -60
  113. package/src/cli/cmd/tui/thread.ts +0 -120
  114. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -55
  115. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -81
  116. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -36
  117. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -75
  118. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -317
  119. package/src/cli/cmd/tui/ui/dialog.tsx +0 -170
  120. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  121. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  122. package/src/cli/cmd/tui/util/clipboard.ts +0 -127
  123. package/src/cli/cmd/tui/util/editor.ts +0 -32
  124. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  125. package/src/cli/cmd/tui/worker.ts +0 -63
  126. package/src/cli/cmd/uninstall.ts +0 -344
  127. package/src/cli/cmd/upgrade.ts +0 -67
  128. package/src/cli/cmd/web.ts +0 -84
  129. package/src/cli/error.ts +0 -55
  130. package/src/cli/ui.ts +0 -84
  131. package/src/cli/upgrade.ts +0 -25
  132. package/src/command/index.ts +0 -79
  133. package/src/command/template/initialize.txt +0 -10
  134. package/src/command/template/review.txt +0 -73
  135. package/src/config/config.ts +0 -886
  136. package/src/config/markdown.ts +0 -41
  137. package/src/env/index.ts +0 -26
  138. package/src/file/fzf.ts +0 -124
  139. package/src/file/ignore.ts +0 -83
  140. package/src/file/index.ts +0 -326
  141. package/src/file/ripgrep.ts +0 -391
  142. package/src/file/time.ts +0 -38
  143. package/src/file/watcher.ts +0 -89
  144. package/src/flag/flag.ts +0 -28
  145. package/src/format/formatter.ts +0 -277
  146. package/src/format/index.ts +0 -137
  147. package/src/global/index.ts +0 -52
  148. package/src/id/id.ts +0 -73
  149. package/src/ide/index.ts +0 -75
  150. package/src/index.ts +0 -158
  151. package/src/installation/index.ts +0 -194
  152. package/src/lsp/client.ts +0 -215
  153. package/src/lsp/index.ts +0 -370
  154. package/src/lsp/language.ts +0 -111
  155. package/src/lsp/server.ts +0 -1327
  156. package/src/mcp/auth.ts +0 -82
  157. package/src/mcp/index.ts +0 -576
  158. package/src/mcp/oauth-callback.ts +0 -203
  159. package/src/mcp/oauth-provider.ts +0 -132
  160. package/src/notification/index.ts +0 -101
  161. package/src/patch/index.ts +0 -622
  162. package/src/permission/index.ts +0 -198
  163. package/src/plugin/index.ts +0 -95
  164. package/src/project/bootstrap.ts +0 -31
  165. package/src/project/instance.ts +0 -68
  166. package/src/project/project.ts +0 -133
  167. package/src/project/state.ts +0 -65
  168. package/src/project/vcs.ts +0 -77
  169. package/src/provider/auth.ts +0 -143
  170. package/src/provider/models-macro.ts +0 -11
  171. package/src/provider/models.ts +0 -93
  172. package/src/provider/provider.ts +0 -996
  173. package/src/provider/sdk/openai-compatible/src/README.md +0 -5
  174. package/src/provider/sdk/openai-compatible/src/index.ts +0 -2
  175. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +0 -100
  176. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +0 -303
  177. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +0 -27
  178. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +0 -18
  179. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +0 -22
  180. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +0 -207
  181. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +0 -1713
  182. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +0 -177
  183. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +0 -1
  184. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +0 -88
  185. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +0 -128
  186. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +0 -115
  187. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +0 -65
  188. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +0 -104
  189. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +0 -103
  190. package/src/provider/transform.ts +0 -406
  191. package/src/pty/index.ts +0 -226
  192. package/src/ratelimit/index.ts +0 -185
  193. package/src/server/error.ts +0 -36
  194. package/src/server/project.ts +0 -50
  195. package/src/server/server.ts +0 -2463
  196. package/src/server/tui.ts +0 -71
  197. package/src/session/compaction.ts +0 -257
  198. package/src/session/index.ts +0 -470
  199. package/src/session/message-v2.ts +0 -641
  200. package/src/session/message.ts +0 -189
  201. package/src/session/processor.ts +0 -443
  202. package/src/session/prompt/anthropic-20250930.txt +0 -166
  203. package/src/session/prompt/anthropic.txt +0 -105
  204. package/src/session/prompt/anthropic_spoof.txt +0 -1
  205. package/src/session/prompt/beast.txt +0 -147
  206. package/src/session/prompt/build-switch.txt +0 -5
  207. package/src/session/prompt/codex.txt +0 -318
  208. package/src/session/prompt/compaction.txt +0 -12
  209. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  210. package/src/session/prompt/gemini.txt +0 -155
  211. package/src/session/prompt/max-steps.txt +0 -16
  212. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  213. package/src/session/prompt/plan.txt +0 -26
  214. package/src/session/prompt/polaris.txt +0 -107
  215. package/src/session/prompt/qwen.txt +0 -109
  216. package/src/session/prompt/summarize.txt +0 -4
  217. package/src/session/prompt/title.txt +0 -36
  218. package/src/session/prompt.ts +0 -1541
  219. package/src/session/retry.ts +0 -82
  220. package/src/session/revert.ts +0 -108
  221. package/src/session/status.ts +0 -75
  222. package/src/session/summary.ts +0 -203
  223. package/src/session/system.ts +0 -148
  224. package/src/session/todo.ts +0 -36
  225. package/src/share/share-next.ts +0 -195
  226. package/src/share/share.ts +0 -87
  227. package/src/snapshot/index.ts +0 -197
  228. package/src/storage/storage.ts +0 -226
  229. package/src/telemetry/index.ts +0 -232
  230. package/src/tool/bash.ts +0 -365
  231. package/src/tool/bash.txt +0 -128
  232. package/src/tool/batch.ts +0 -173
  233. package/src/tool/batch.txt +0 -28
  234. package/src/tool/codesearch.ts +0 -138
  235. package/src/tool/codesearch.txt +0 -12
  236. package/src/tool/edit.ts +0 -674
  237. package/src/tool/edit.txt +0 -10
  238. package/src/tool/glob.ts +0 -65
  239. package/src/tool/glob.txt +0 -6
  240. package/src/tool/grep.ts +0 -120
  241. package/src/tool/grep.txt +0 -8
  242. package/src/tool/invalid.ts +0 -17
  243. package/src/tool/ls.ts +0 -110
  244. package/src/tool/ls.txt +0 -1
  245. package/src/tool/lsp-diagnostics.ts +0 -26
  246. package/src/tool/lsp-diagnostics.txt +0 -1
  247. package/src/tool/lsp-hover.ts +0 -31
  248. package/src/tool/lsp-hover.txt +0 -1
  249. package/src/tool/multiedit.ts +0 -46
  250. package/src/tool/multiedit.txt +0 -41
  251. package/src/tool/patch.ts +0 -233
  252. package/src/tool/patch.txt +0 -1
  253. package/src/tool/read.ts +0 -217
  254. package/src/tool/read.txt +0 -12
  255. package/src/tool/registry.ts +0 -148
  256. package/src/tool/task.ts +0 -135
  257. package/src/tool/task.txt +0 -60
  258. package/src/tool/todo.ts +0 -39
  259. package/src/tool/todoread.txt +0 -14
  260. package/src/tool/todowrite.txt +0 -167
  261. package/src/tool/tool.ts +0 -66
  262. package/src/tool/webfetch.ts +0 -187
  263. package/src/tool/webfetch.txt +0 -14
  264. package/src/tool/websearch.ts +0 -150
  265. package/src/tool/websearch.txt +0 -11
  266. package/src/tool/write.ts +0 -99
  267. package/src/tool/write.txt +0 -8
  268. package/src/types/shims.d.ts +0 -3
  269. package/src/util/color.ts +0 -19
  270. package/src/util/context.ts +0 -25
  271. package/src/util/defer.ts +0 -12
  272. package/src/util/eventloop.ts +0 -20
  273. package/src/util/filesystem.ts +0 -69
  274. package/src/util/fn.ts +0 -11
  275. package/src/util/iife.ts +0 -3
  276. package/src/util/keybind.ts +0 -79
  277. package/src/util/lazy.ts +0 -11
  278. package/src/util/locale.ts +0 -81
  279. package/src/util/lock.ts +0 -98
  280. package/src/util/log.ts +0 -177
  281. package/src/util/queue.ts +0 -32
  282. package/src/util/rpc.ts +0 -42
  283. package/src/util/scrap.ts +0 -10
  284. package/src/util/signal.ts +0 -12
  285. package/src/util/timeout.ts +0 -14
  286. package/src/util/token.ts +0 -7
  287. package/src/util/wildcard.ts +0 -54
  288. package/sst-env.d.ts +0 -9
  289. package/test/bun.test.ts +0 -53
  290. package/test/config/agent-color.test.ts +0 -66
  291. package/test/config/config.test.ts +0 -503
  292. package/test/config/markdown.test.ts +0 -89
  293. package/test/file/ignore.test.ts +0 -10
  294. package/test/fixture/fixture.ts +0 -28
  295. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  296. package/test/ide/ide.test.ts +0 -82
  297. package/test/keybind.test.ts +0 -317
  298. package/test/lsp/client.test.ts +0 -95
  299. package/test/patch/patch.test.ts +0 -348
  300. package/test/preload.ts +0 -38
  301. package/test/project/project.test.ts +0 -42
  302. package/test/provider/provider.test.ts +0 -1809
  303. package/test/provider/transform.test.ts +0 -305
  304. package/test/session/retry.test.ts +0 -61
  305. package/test/session/session.test.ts +0 -71
  306. package/test/snapshot/snapshot.test.ts +0 -939
  307. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  308. package/test/tool/bash.test.ts +0 -55
  309. package/test/tool/patch.test.ts +0 -259
  310. package/test/util/iife.test.ts +0 -36
  311. package/test/util/lazy.test.ts +0 -50
  312. package/test/util/timeout.test.ts +0 -21
  313. package/test/util/wildcard.test.ts +0 -55
  314. package/tsconfig.json +0 -17
@@ -1,1809 +0,0 @@
1
- import { test, expect } from "bun:test"
2
- import path from "path"
3
- import { tmpdir } from "../fixture/fixture"
4
- import { Instance } from "../../src/project/instance"
5
- import { Provider } from "../../src/provider/provider"
6
- import { Env } from "../../src/env"
7
-
8
- test("provider loaded from env variable", async () => {
9
- await using tmp = await tmpdir({
10
- init: async (dir) => {
11
- await Bun.write(
12
- path.join(dir, "opencode.json"),
13
- JSON.stringify({
14
- $schema: "https://opencode.ai/config.json",
15
- }),
16
- )
17
- },
18
- })
19
- await Instance.provide({
20
- directory: tmp.path,
21
- init: async () => {
22
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
23
- },
24
- fn: async () => {
25
- const providers = await Provider.list()
26
- expect(providers["anthropic"]).toBeDefined()
27
- // Note: source becomes "custom" because CUSTOM_LOADERS run after env loading
28
- // and anthropic has a custom loader that merges additional options
29
- expect(providers["anthropic"].source).toBe("custom")
30
- },
31
- })
32
- })
33
-
34
- test("provider loaded from config with apiKey option", async () => {
35
- await using tmp = await tmpdir({
36
- init: async (dir) => {
37
- await Bun.write(
38
- path.join(dir, "opencode.json"),
39
- JSON.stringify({
40
- $schema: "https://opencode.ai/config.json",
41
- provider: {
42
- anthropic: {
43
- options: {
44
- apiKey: "config-api-key",
45
- },
46
- },
47
- },
48
- }),
49
- )
50
- },
51
- })
52
- await Instance.provide({
53
- directory: tmp.path,
54
- fn: async () => {
55
- const providers = await Provider.list()
56
- expect(providers["anthropic"]).toBeDefined()
57
- },
58
- })
59
- })
60
-
61
- test("disabled_providers excludes provider", async () => {
62
- await using tmp = await tmpdir({
63
- init: async (dir) => {
64
- await Bun.write(
65
- path.join(dir, "opencode.json"),
66
- JSON.stringify({
67
- $schema: "https://opencode.ai/config.json",
68
- disabled_providers: ["anthropic"],
69
- }),
70
- )
71
- },
72
- })
73
- await Instance.provide({
74
- directory: tmp.path,
75
- init: async () => {
76
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
77
- },
78
- fn: async () => {
79
- const providers = await Provider.list()
80
- expect(providers["anthropic"]).toBeUndefined()
81
- },
82
- })
83
- })
84
-
85
- test("enabled_providers restricts to only listed providers", async () => {
86
- await using tmp = await tmpdir({
87
- init: async (dir) => {
88
- await Bun.write(
89
- path.join(dir, "opencode.json"),
90
- JSON.stringify({
91
- $schema: "https://opencode.ai/config.json",
92
- enabled_providers: ["anthropic"],
93
- }),
94
- )
95
- },
96
- })
97
- await Instance.provide({
98
- directory: tmp.path,
99
- init: async () => {
100
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
101
- Env.set("OPENAI_API_KEY", "test-openai-key")
102
- },
103
- fn: async () => {
104
- const providers = await Provider.list()
105
- expect(providers["anthropic"]).toBeDefined()
106
- expect(providers["openai"]).toBeUndefined()
107
- },
108
- })
109
- })
110
-
111
- test("model whitelist filters models for provider", async () => {
112
- await using tmp = await tmpdir({
113
- init: async (dir) => {
114
- await Bun.write(
115
- path.join(dir, "opencode.json"),
116
- JSON.stringify({
117
- $schema: "https://opencode.ai/config.json",
118
- provider: {
119
- anthropic: {
120
- whitelist: ["claude-sonnet-4-20250514"],
121
- },
122
- },
123
- }),
124
- )
125
- },
126
- })
127
- await Instance.provide({
128
- directory: tmp.path,
129
- init: async () => {
130
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
131
- },
132
- fn: async () => {
133
- const providers = await Provider.list()
134
- expect(providers["anthropic"]).toBeDefined()
135
- const models = Object.keys(providers["anthropic"].models)
136
- expect(models).toContain("claude-sonnet-4-20250514")
137
- expect(models.length).toBe(1)
138
- },
139
- })
140
- })
141
-
142
- test("model blacklist excludes specific models", async () => {
143
- await using tmp = await tmpdir({
144
- init: async (dir) => {
145
- await Bun.write(
146
- path.join(dir, "opencode.json"),
147
- JSON.stringify({
148
- $schema: "https://opencode.ai/config.json",
149
- provider: {
150
- anthropic: {
151
- blacklist: ["claude-sonnet-4-20250514"],
152
- },
153
- },
154
- }),
155
- )
156
- },
157
- })
158
- await Instance.provide({
159
- directory: tmp.path,
160
- init: async () => {
161
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
162
- },
163
- fn: async () => {
164
- const providers = await Provider.list()
165
- expect(providers["anthropic"]).toBeDefined()
166
- const models = Object.keys(providers["anthropic"].models)
167
- expect(models).not.toContain("claude-sonnet-4-20250514")
168
- },
169
- })
170
- })
171
-
172
- test("custom model alias via config", async () => {
173
- await using tmp = await tmpdir({
174
- init: async (dir) => {
175
- await Bun.write(
176
- path.join(dir, "opencode.json"),
177
- JSON.stringify({
178
- $schema: "https://opencode.ai/config.json",
179
- provider: {
180
- anthropic: {
181
- models: {
182
- "my-alias": {
183
- id: "claude-sonnet-4-20250514",
184
- name: "My Custom Alias",
185
- },
186
- },
187
- },
188
- },
189
- }),
190
- )
191
- },
192
- })
193
- await Instance.provide({
194
- directory: tmp.path,
195
- init: async () => {
196
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
197
- },
198
- fn: async () => {
199
- const providers = await Provider.list()
200
- expect(providers["anthropic"]).toBeDefined()
201
- expect(providers["anthropic"].models["my-alias"]).toBeDefined()
202
- expect(providers["anthropic"].models["my-alias"].name).toBe("My Custom Alias")
203
- },
204
- })
205
- })
206
-
207
- test("custom provider with npm package", async () => {
208
- await using tmp = await tmpdir({
209
- init: async (dir) => {
210
- await Bun.write(
211
- path.join(dir, "opencode.json"),
212
- JSON.stringify({
213
- $schema: "https://opencode.ai/config.json",
214
- provider: {
215
- "custom-provider": {
216
- name: "Custom Provider",
217
- npm: "@ai-sdk/openai-compatible",
218
- api: "https://api.custom.com/v1",
219
- env: ["CUSTOM_API_KEY"],
220
- models: {
221
- "custom-model": {
222
- name: "Custom Model",
223
- tool_call: true,
224
- limit: {
225
- context: 128000,
226
- output: 4096,
227
- },
228
- },
229
- },
230
- options: {
231
- apiKey: "custom-key",
232
- },
233
- },
234
- },
235
- }),
236
- )
237
- },
238
- })
239
- await Instance.provide({
240
- directory: tmp.path,
241
- fn: async () => {
242
- const providers = await Provider.list()
243
- expect(providers["custom-provider"]).toBeDefined()
244
- expect(providers["custom-provider"].name).toBe("Custom Provider")
245
- expect(providers["custom-provider"].models["custom-model"]).toBeDefined()
246
- },
247
- })
248
- })
249
-
250
- test("env variable takes precedence, config merges options", async () => {
251
- await using tmp = await tmpdir({
252
- init: async (dir) => {
253
- await Bun.write(
254
- path.join(dir, "opencode.json"),
255
- JSON.stringify({
256
- $schema: "https://opencode.ai/config.json",
257
- provider: {
258
- anthropic: {
259
- options: {
260
- timeout: 60000,
261
- },
262
- },
263
- },
264
- }),
265
- )
266
- },
267
- })
268
- await Instance.provide({
269
- directory: tmp.path,
270
- init: async () => {
271
- Env.set("ANTHROPIC_API_KEY", "env-api-key")
272
- },
273
- fn: async () => {
274
- const providers = await Provider.list()
275
- expect(providers["anthropic"]).toBeDefined()
276
- // Config options should be merged
277
- expect(providers["anthropic"].options.timeout).toBe(60000)
278
- },
279
- })
280
- })
281
-
282
- test("getModel returns model for valid provider/model", async () => {
283
- await using tmp = await tmpdir({
284
- init: async (dir) => {
285
- await Bun.write(
286
- path.join(dir, "opencode.json"),
287
- JSON.stringify({
288
- $schema: "https://opencode.ai/config.json",
289
- }),
290
- )
291
- },
292
- })
293
- await Instance.provide({
294
- directory: tmp.path,
295
- init: async () => {
296
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
297
- },
298
- fn: async () => {
299
- const model = await Provider.getModel("anthropic", "claude-sonnet-4-20250514")
300
- expect(model).toBeDefined()
301
- expect(model.providerID).toBe("anthropic")
302
- expect(model.id).toBe("claude-sonnet-4-20250514")
303
- const language = await Provider.getLanguage(model)
304
- expect(language).toBeDefined()
305
- },
306
- })
307
- })
308
-
309
- test("getModel throws ModelNotFoundError for invalid model", async () => {
310
- await using tmp = await tmpdir({
311
- init: async (dir) => {
312
- await Bun.write(
313
- path.join(dir, "opencode.json"),
314
- JSON.stringify({
315
- $schema: "https://opencode.ai/config.json",
316
- }),
317
- )
318
- },
319
- })
320
- await Instance.provide({
321
- directory: tmp.path,
322
- init: async () => {
323
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
324
- },
325
- fn: async () => {
326
- expect(Provider.getModel("anthropic", "nonexistent-model")).rejects.toThrow()
327
- },
328
- })
329
- })
330
-
331
- test("getModel throws ModelNotFoundError for invalid provider", async () => {
332
- await using tmp = await tmpdir({
333
- init: async (dir) => {
334
- await Bun.write(
335
- path.join(dir, "opencode.json"),
336
- JSON.stringify({
337
- $schema: "https://opencode.ai/config.json",
338
- }),
339
- )
340
- },
341
- })
342
- await Instance.provide({
343
- directory: tmp.path,
344
- fn: async () => {
345
- expect(Provider.getModel("nonexistent-provider", "some-model")).rejects.toThrow()
346
- },
347
- })
348
- })
349
-
350
- test("parseModel correctly parses provider/model string", () => {
351
- const result = Provider.parseModel("anthropic/claude-sonnet-4")
352
- expect(result.providerID).toBe("anthropic")
353
- expect(result.modelID).toBe("claude-sonnet-4")
354
- })
355
-
356
- test("parseModel handles model IDs with slashes", () => {
357
- const result = Provider.parseModel("openrouter/anthropic/claude-3-opus")
358
- expect(result.providerID).toBe("openrouter")
359
- expect(result.modelID).toBe("anthropic/claude-3-opus")
360
- })
361
-
362
- test("defaultModel returns first available model when no config set", async () => {
363
- await using tmp = await tmpdir({
364
- init: async (dir) => {
365
- await Bun.write(
366
- path.join(dir, "opencode.json"),
367
- JSON.stringify({
368
- $schema: "https://opencode.ai/config.json",
369
- }),
370
- )
371
- },
372
- })
373
- await Instance.provide({
374
- directory: tmp.path,
375
- init: async () => {
376
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
377
- },
378
- fn: async () => {
379
- const model = await Provider.defaultModel()
380
- expect(model.providerID).toBeDefined()
381
- expect(model.modelID).toBeDefined()
382
- },
383
- })
384
- })
385
-
386
- test("defaultModel respects config model setting", async () => {
387
- await using tmp = await tmpdir({
388
- init: async (dir) => {
389
- await Bun.write(
390
- path.join(dir, "opencode.json"),
391
- JSON.stringify({
392
- $schema: "https://opencode.ai/config.json",
393
- model: "anthropic/claude-sonnet-4-20250514",
394
- }),
395
- )
396
- },
397
- })
398
- await Instance.provide({
399
- directory: tmp.path,
400
- init: async () => {
401
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
402
- },
403
- fn: async () => {
404
- const model = await Provider.defaultModel()
405
- expect(model.providerID).toBe("anthropic")
406
- expect(model.modelID).toBe("claude-sonnet-4-20250514")
407
- },
408
- })
409
- })
410
-
411
- test("provider with baseURL from config", async () => {
412
- await using tmp = await tmpdir({
413
- init: async (dir) => {
414
- await Bun.write(
415
- path.join(dir, "opencode.json"),
416
- JSON.stringify({
417
- $schema: "https://opencode.ai/config.json",
418
- provider: {
419
- "custom-openai": {
420
- name: "Custom OpenAI",
421
- npm: "@ai-sdk/openai-compatible",
422
- env: [],
423
- models: {
424
- "gpt-4": {
425
- name: "GPT-4",
426
- tool_call: true,
427
- limit: { context: 128000, output: 4096 },
428
- },
429
- },
430
- options: {
431
- apiKey: "test-key",
432
- baseURL: "https://custom.openai.com/v1",
433
- },
434
- },
435
- },
436
- }),
437
- )
438
- },
439
- })
440
- await Instance.provide({
441
- directory: tmp.path,
442
- fn: async () => {
443
- const providers = await Provider.list()
444
- expect(providers["custom-openai"]).toBeDefined()
445
- expect(providers["custom-openai"].options.baseURL).toBe("https://custom.openai.com/v1")
446
- },
447
- })
448
- })
449
-
450
- test("model cost defaults to zero when not specified", async () => {
451
- await using tmp = await tmpdir({
452
- init: async (dir) => {
453
- await Bun.write(
454
- path.join(dir, "opencode.json"),
455
- JSON.stringify({
456
- $schema: "https://opencode.ai/config.json",
457
- provider: {
458
- "test-provider": {
459
- name: "Test Provider",
460
- npm: "@ai-sdk/openai-compatible",
461
- env: [],
462
- models: {
463
- "test-model": {
464
- name: "Test Model",
465
- tool_call: true,
466
- limit: { context: 128000, output: 4096 },
467
- },
468
- },
469
- options: {
470
- apiKey: "test-key",
471
- },
472
- },
473
- },
474
- }),
475
- )
476
- },
477
- })
478
- await Instance.provide({
479
- directory: tmp.path,
480
- fn: async () => {
481
- const providers = await Provider.list()
482
- const model = providers["test-provider"].models["test-model"]
483
- expect(model.cost.input).toBe(0)
484
- expect(model.cost.output).toBe(0)
485
- expect(model.cost.cache.read).toBe(0)
486
- expect(model.cost.cache.write).toBe(0)
487
- },
488
- })
489
- })
490
-
491
- test("model options are merged from existing model", async () => {
492
- await using tmp = await tmpdir({
493
- init: async (dir) => {
494
- await Bun.write(
495
- path.join(dir, "opencode.json"),
496
- JSON.stringify({
497
- $schema: "https://opencode.ai/config.json",
498
- provider: {
499
- anthropic: {
500
- models: {
501
- "claude-sonnet-4-20250514": {
502
- options: {
503
- customOption: "custom-value",
504
- },
505
- },
506
- },
507
- },
508
- },
509
- }),
510
- )
511
- },
512
- })
513
- await Instance.provide({
514
- directory: tmp.path,
515
- init: async () => {
516
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
517
- },
518
- fn: async () => {
519
- const providers = await Provider.list()
520
- const model = providers["anthropic"].models["claude-sonnet-4-20250514"]
521
- expect(model.options.customOption).toBe("custom-value")
522
- },
523
- })
524
- })
525
-
526
- test("provider removed when all models filtered out", async () => {
527
- await using tmp = await tmpdir({
528
- init: async (dir) => {
529
- await Bun.write(
530
- path.join(dir, "opencode.json"),
531
- JSON.stringify({
532
- $schema: "https://opencode.ai/config.json",
533
- provider: {
534
- anthropic: {
535
- whitelist: ["nonexistent-model"],
536
- },
537
- },
538
- }),
539
- )
540
- },
541
- })
542
- await Instance.provide({
543
- directory: tmp.path,
544
- init: async () => {
545
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
546
- },
547
- fn: async () => {
548
- const providers = await Provider.list()
549
- expect(providers["anthropic"]).toBeUndefined()
550
- },
551
- })
552
- })
553
-
554
- test("closest finds model by partial match", async () => {
555
- await using tmp = await tmpdir({
556
- init: async (dir) => {
557
- await Bun.write(
558
- path.join(dir, "opencode.json"),
559
- JSON.stringify({
560
- $schema: "https://opencode.ai/config.json",
561
- }),
562
- )
563
- },
564
- })
565
- await Instance.provide({
566
- directory: tmp.path,
567
- init: async () => {
568
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
569
- },
570
- fn: async () => {
571
- const result = await Provider.closest("anthropic", ["sonnet-4"])
572
- expect(result).toBeDefined()
573
- expect(result?.providerID).toBe("anthropic")
574
- expect(result?.modelID).toContain("sonnet-4")
575
- },
576
- })
577
- })
578
-
579
- test("closest returns undefined for nonexistent provider", async () => {
580
- await using tmp = await tmpdir({
581
- init: async (dir) => {
582
- await Bun.write(
583
- path.join(dir, "opencode.json"),
584
- JSON.stringify({
585
- $schema: "https://opencode.ai/config.json",
586
- }),
587
- )
588
- },
589
- })
590
- await Instance.provide({
591
- directory: tmp.path,
592
- fn: async () => {
593
- const result = await Provider.closest("nonexistent", ["model"])
594
- expect(result).toBeUndefined()
595
- },
596
- })
597
- })
598
-
599
- test("getModel uses realIdByKey for aliased models", async () => {
600
- await using tmp = await tmpdir({
601
- init: async (dir) => {
602
- await Bun.write(
603
- path.join(dir, "opencode.json"),
604
- JSON.stringify({
605
- $schema: "https://opencode.ai/config.json",
606
- provider: {
607
- anthropic: {
608
- models: {
609
- "my-sonnet": {
610
- id: "claude-sonnet-4-20250514",
611
- name: "My Sonnet Alias",
612
- },
613
- },
614
- },
615
- },
616
- }),
617
- )
618
- },
619
- })
620
- await Instance.provide({
621
- directory: tmp.path,
622
- init: async () => {
623
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
624
- },
625
- fn: async () => {
626
- const providers = await Provider.list()
627
- expect(providers["anthropic"].models["my-sonnet"]).toBeDefined()
628
-
629
- const model = await Provider.getModel("anthropic", "my-sonnet")
630
- expect(model).toBeDefined()
631
- expect(model.id).toBe("my-sonnet")
632
- expect(model.name).toBe("My Sonnet Alias")
633
- },
634
- })
635
- })
636
-
637
- test("provider api field sets model api.url", async () => {
638
- await using tmp = await tmpdir({
639
- init: async (dir) => {
640
- await Bun.write(
641
- path.join(dir, "opencode.json"),
642
- JSON.stringify({
643
- $schema: "https://opencode.ai/config.json",
644
- provider: {
645
- "custom-api": {
646
- name: "Custom API",
647
- npm: "@ai-sdk/openai-compatible",
648
- api: "https://api.example.com/v1",
649
- env: [],
650
- models: {
651
- "model-1": {
652
- name: "Model 1",
653
- tool_call: true,
654
- limit: { context: 8000, output: 2000 },
655
- },
656
- },
657
- options: {
658
- apiKey: "test-key",
659
- },
660
- },
661
- },
662
- }),
663
- )
664
- },
665
- })
666
- await Instance.provide({
667
- directory: tmp.path,
668
- fn: async () => {
669
- const providers = await Provider.list()
670
- // api field is stored on model.api.url, used by getSDK to set baseURL
671
- expect(providers["custom-api"].models["model-1"].api.url).toBe("https://api.example.com/v1")
672
- },
673
- })
674
- })
675
-
676
- test("explicit baseURL overrides api field", async () => {
677
- await using tmp = await tmpdir({
678
- init: async (dir) => {
679
- await Bun.write(
680
- path.join(dir, "opencode.json"),
681
- JSON.stringify({
682
- $schema: "https://opencode.ai/config.json",
683
- provider: {
684
- "custom-api": {
685
- name: "Custom API",
686
- npm: "@ai-sdk/openai-compatible",
687
- api: "https://api.example.com/v1",
688
- env: [],
689
- models: {
690
- "model-1": {
691
- name: "Model 1",
692
- tool_call: true,
693
- limit: { context: 8000, output: 2000 },
694
- },
695
- },
696
- options: {
697
- apiKey: "test-key",
698
- baseURL: "https://custom.override.com/v1",
699
- },
700
- },
701
- },
702
- }),
703
- )
704
- },
705
- })
706
- await Instance.provide({
707
- directory: tmp.path,
708
- fn: async () => {
709
- const providers = await Provider.list()
710
- expect(providers["custom-api"].options.baseURL).toBe("https://custom.override.com/v1")
711
- },
712
- })
713
- })
714
-
715
- test("model inherits properties from existing database model", async () => {
716
- await using tmp = await tmpdir({
717
- init: async (dir) => {
718
- await Bun.write(
719
- path.join(dir, "opencode.json"),
720
- JSON.stringify({
721
- $schema: "https://opencode.ai/config.json",
722
- provider: {
723
- anthropic: {
724
- models: {
725
- "claude-sonnet-4-20250514": {
726
- name: "Custom Name for Sonnet",
727
- },
728
- },
729
- },
730
- },
731
- }),
732
- )
733
- },
734
- })
735
- await Instance.provide({
736
- directory: tmp.path,
737
- init: async () => {
738
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
739
- },
740
- fn: async () => {
741
- const providers = await Provider.list()
742
- const model = providers["anthropic"].models["claude-sonnet-4-20250514"]
743
- expect(model.name).toBe("Custom Name for Sonnet")
744
- expect(model.capabilities.toolcall).toBe(true)
745
- expect(model.capabilities.attachment).toBe(true)
746
- expect(model.limit.context).toBeGreaterThan(0)
747
- },
748
- })
749
- })
750
-
751
- test("disabled_providers prevents loading even with env var", async () => {
752
- await using tmp = await tmpdir({
753
- init: async (dir) => {
754
- await Bun.write(
755
- path.join(dir, "opencode.json"),
756
- JSON.stringify({
757
- $schema: "https://opencode.ai/config.json",
758
- disabled_providers: ["openai"],
759
- }),
760
- )
761
- },
762
- })
763
- await Instance.provide({
764
- directory: tmp.path,
765
- init: async () => {
766
- Env.set("OPENAI_API_KEY", "test-openai-key")
767
- },
768
- fn: async () => {
769
- const providers = await Provider.list()
770
- expect(providers["openai"]).toBeUndefined()
771
- },
772
- })
773
- })
774
-
775
- test("enabled_providers with empty array allows no providers", async () => {
776
- await using tmp = await tmpdir({
777
- init: async (dir) => {
778
- await Bun.write(
779
- path.join(dir, "opencode.json"),
780
- JSON.stringify({
781
- $schema: "https://opencode.ai/config.json",
782
- enabled_providers: [],
783
- }),
784
- )
785
- },
786
- })
787
- await Instance.provide({
788
- directory: tmp.path,
789
- init: async () => {
790
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
791
- Env.set("OPENAI_API_KEY", "test-openai-key")
792
- },
793
- fn: async () => {
794
- const providers = await Provider.list()
795
- expect(Object.keys(providers).length).toBe(0)
796
- },
797
- })
798
- })
799
-
800
- test("whitelist and blacklist can be combined", async () => {
801
- await using tmp = await tmpdir({
802
- init: async (dir) => {
803
- await Bun.write(
804
- path.join(dir, "opencode.json"),
805
- JSON.stringify({
806
- $schema: "https://opencode.ai/config.json",
807
- provider: {
808
- anthropic: {
809
- whitelist: ["claude-sonnet-4-20250514", "claude-opus-4-20250514"],
810
- blacklist: ["claude-opus-4-20250514"],
811
- },
812
- },
813
- }),
814
- )
815
- },
816
- })
817
- await Instance.provide({
818
- directory: tmp.path,
819
- init: async () => {
820
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
821
- },
822
- fn: async () => {
823
- const providers = await Provider.list()
824
- expect(providers["anthropic"]).toBeDefined()
825
- const models = Object.keys(providers["anthropic"].models)
826
- expect(models).toContain("claude-sonnet-4-20250514")
827
- expect(models).not.toContain("claude-opus-4-20250514")
828
- expect(models.length).toBe(1)
829
- },
830
- })
831
- })
832
-
833
- test("model modalities default correctly", async () => {
834
- await using tmp = await tmpdir({
835
- init: async (dir) => {
836
- await Bun.write(
837
- path.join(dir, "opencode.json"),
838
- JSON.stringify({
839
- $schema: "https://opencode.ai/config.json",
840
- provider: {
841
- "test-provider": {
842
- name: "Test",
843
- npm: "@ai-sdk/openai-compatible",
844
- env: [],
845
- models: {
846
- "test-model": {
847
- name: "Test Model",
848
- tool_call: true,
849
- limit: { context: 8000, output: 2000 },
850
- },
851
- },
852
- options: { apiKey: "test" },
853
- },
854
- },
855
- }),
856
- )
857
- },
858
- })
859
- await Instance.provide({
860
- directory: tmp.path,
861
- fn: async () => {
862
- const providers = await Provider.list()
863
- const model = providers["test-provider"].models["test-model"]
864
- expect(model.capabilities.input.text).toBe(true)
865
- expect(model.capabilities.output.text).toBe(true)
866
- },
867
- })
868
- })
869
-
870
- test("model with custom cost values", async () => {
871
- await using tmp = await tmpdir({
872
- init: async (dir) => {
873
- await Bun.write(
874
- path.join(dir, "opencode.json"),
875
- JSON.stringify({
876
- $schema: "https://opencode.ai/config.json",
877
- provider: {
878
- "test-provider": {
879
- name: "Test",
880
- npm: "@ai-sdk/openai-compatible",
881
- env: [],
882
- models: {
883
- "test-model": {
884
- name: "Test Model",
885
- tool_call: true,
886
- limit: { context: 8000, output: 2000 },
887
- cost: {
888
- input: 5,
889
- output: 15,
890
- cache_read: 2.5,
891
- cache_write: 7.5,
892
- },
893
- },
894
- },
895
- options: { apiKey: "test" },
896
- },
897
- },
898
- }),
899
- )
900
- },
901
- })
902
- await Instance.provide({
903
- directory: tmp.path,
904
- fn: async () => {
905
- const providers = await Provider.list()
906
- const model = providers["test-provider"].models["test-model"]
907
- expect(model.cost.input).toBe(5)
908
- expect(model.cost.output).toBe(15)
909
- expect(model.cost.cache.read).toBe(2.5)
910
- expect(model.cost.cache.write).toBe(7.5)
911
- },
912
- })
913
- })
914
-
915
- test("getSmallModel returns appropriate small model", async () => {
916
- await using tmp = await tmpdir({
917
- init: async (dir) => {
918
- await Bun.write(
919
- path.join(dir, "opencode.json"),
920
- JSON.stringify({
921
- $schema: "https://opencode.ai/config.json",
922
- }),
923
- )
924
- },
925
- })
926
- await Instance.provide({
927
- directory: tmp.path,
928
- init: async () => {
929
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
930
- },
931
- fn: async () => {
932
- const model = await Provider.getSmallModel("anthropic")
933
- expect(model).toBeDefined()
934
- expect(model?.id).toContain("haiku")
935
- },
936
- })
937
- })
938
-
939
- test("getSmallModel respects config small_model override", async () => {
940
- await using tmp = await tmpdir({
941
- init: async (dir) => {
942
- await Bun.write(
943
- path.join(dir, "opencode.json"),
944
- JSON.stringify({
945
- $schema: "https://opencode.ai/config.json",
946
- small_model: "anthropic/claude-sonnet-4-20250514",
947
- }),
948
- )
949
- },
950
- })
951
- await Instance.provide({
952
- directory: tmp.path,
953
- init: async () => {
954
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
955
- },
956
- fn: async () => {
957
- const model = await Provider.getSmallModel("anthropic")
958
- expect(model).toBeDefined()
959
- expect(model?.providerID).toBe("anthropic")
960
- expect(model?.id).toBe("claude-sonnet-4-20250514")
961
- },
962
- })
963
- })
964
-
965
- test("provider.sort prioritizes preferred models", () => {
966
- const models = [
967
- { id: "random-model", name: "Random" },
968
- { id: "claude-sonnet-4-latest", name: "Claude Sonnet 4" },
969
- { id: "gpt-5-turbo", name: "GPT-5 Turbo" },
970
- { id: "other-model", name: "Other" },
971
- ] as any[]
972
-
973
- const sorted = Provider.sort(models)
974
- expect(sorted[0].id).toContain("sonnet-4")
975
- expect(sorted[0].id).toContain("latest")
976
- expect(sorted[sorted.length - 1].id).not.toContain("gpt-5")
977
- expect(sorted[sorted.length - 1].id).not.toContain("sonnet-4")
978
- })
979
-
980
- test("multiple providers can be configured simultaneously", async () => {
981
- await using tmp = await tmpdir({
982
- init: async (dir) => {
983
- await Bun.write(
984
- path.join(dir, "opencode.json"),
985
- JSON.stringify({
986
- $schema: "https://opencode.ai/config.json",
987
- provider: {
988
- anthropic: {
989
- options: { timeout: 30000 },
990
- },
991
- openai: {
992
- options: { timeout: 60000 },
993
- },
994
- },
995
- }),
996
- )
997
- },
998
- })
999
- await Instance.provide({
1000
- directory: tmp.path,
1001
- init: async () => {
1002
- Env.set("ANTHROPIC_API_KEY", "test-anthropic-key")
1003
- Env.set("OPENAI_API_KEY", "test-openai-key")
1004
- },
1005
- fn: async () => {
1006
- const providers = await Provider.list()
1007
- expect(providers["anthropic"]).toBeDefined()
1008
- expect(providers["openai"]).toBeDefined()
1009
- expect(providers["anthropic"].options.timeout).toBe(30000)
1010
- expect(providers["openai"].options.timeout).toBe(60000)
1011
- },
1012
- })
1013
- })
1014
-
1015
- test("provider with custom npm package", async () => {
1016
- await using tmp = await tmpdir({
1017
- init: async (dir) => {
1018
- await Bun.write(
1019
- path.join(dir, "opencode.json"),
1020
- JSON.stringify({
1021
- $schema: "https://opencode.ai/config.json",
1022
- provider: {
1023
- "local-llm": {
1024
- name: "Local LLM",
1025
- npm: "@ai-sdk/openai-compatible",
1026
- env: [],
1027
- models: {
1028
- "llama-3": {
1029
- name: "Llama 3",
1030
- tool_call: true,
1031
- limit: { context: 8192, output: 2048 },
1032
- },
1033
- },
1034
- options: {
1035
- apiKey: "not-needed",
1036
- baseURL: "http://localhost:11434/v1",
1037
- },
1038
- },
1039
- },
1040
- }),
1041
- )
1042
- },
1043
- })
1044
- await Instance.provide({
1045
- directory: tmp.path,
1046
- fn: async () => {
1047
- const providers = await Provider.list()
1048
- expect(providers["local-llm"]).toBeDefined()
1049
- expect(providers["local-llm"].models["llama-3"].api.npm).toBe("@ai-sdk/openai-compatible")
1050
- expect(providers["local-llm"].options.baseURL).toBe("http://localhost:11434/v1")
1051
- },
1052
- })
1053
- })
1054
-
1055
- // Edge cases for model configuration
1056
-
1057
- test("model alias name defaults to alias key when id differs", async () => {
1058
- await using tmp = await tmpdir({
1059
- init: async (dir) => {
1060
- await Bun.write(
1061
- path.join(dir, "opencode.json"),
1062
- JSON.stringify({
1063
- $schema: "https://opencode.ai/config.json",
1064
- provider: {
1065
- anthropic: {
1066
- models: {
1067
- sonnet: {
1068
- id: "claude-sonnet-4-20250514",
1069
- // no name specified - should default to "sonnet" (the key)
1070
- },
1071
- },
1072
- },
1073
- },
1074
- }),
1075
- )
1076
- },
1077
- })
1078
- await Instance.provide({
1079
- directory: tmp.path,
1080
- init: async () => {
1081
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1082
- },
1083
- fn: async () => {
1084
- const providers = await Provider.list()
1085
- expect(providers["anthropic"].models["sonnet"].name).toBe("sonnet")
1086
- },
1087
- })
1088
- })
1089
-
1090
- test("provider with multiple env var options only includes apiKey when single env", async () => {
1091
- await using tmp = await tmpdir({
1092
- init: async (dir) => {
1093
- await Bun.write(
1094
- path.join(dir, "opencode.json"),
1095
- JSON.stringify({
1096
- $schema: "https://opencode.ai/config.json",
1097
- provider: {
1098
- "multi-env": {
1099
- name: "Multi Env Provider",
1100
- npm: "@ai-sdk/openai-compatible",
1101
- env: ["MULTI_ENV_KEY_1", "MULTI_ENV_KEY_2"],
1102
- models: {
1103
- "model-1": {
1104
- name: "Model 1",
1105
- tool_call: true,
1106
- limit: { context: 8000, output: 2000 },
1107
- },
1108
- },
1109
- options: {
1110
- baseURL: "https://api.example.com/v1",
1111
- },
1112
- },
1113
- },
1114
- }),
1115
- )
1116
- },
1117
- })
1118
- await Instance.provide({
1119
- directory: tmp.path,
1120
- init: async () => {
1121
- Env.set("MULTI_ENV_KEY_1", "test-key")
1122
- },
1123
- fn: async () => {
1124
- const providers = await Provider.list()
1125
- expect(providers["multi-env"]).toBeDefined()
1126
- // When multiple env options exist, key should NOT be auto-set
1127
- expect(providers["multi-env"].key).toBeUndefined()
1128
- },
1129
- })
1130
- })
1131
-
1132
- test("provider with single env var includes apiKey automatically", async () => {
1133
- await using tmp = await tmpdir({
1134
- init: async (dir) => {
1135
- await Bun.write(
1136
- path.join(dir, "opencode.json"),
1137
- JSON.stringify({
1138
- $schema: "https://opencode.ai/config.json",
1139
- provider: {
1140
- "single-env": {
1141
- name: "Single Env Provider",
1142
- npm: "@ai-sdk/openai-compatible",
1143
- env: ["SINGLE_ENV_KEY"],
1144
- models: {
1145
- "model-1": {
1146
- name: "Model 1",
1147
- tool_call: true,
1148
- limit: { context: 8000, output: 2000 },
1149
- },
1150
- },
1151
- options: {
1152
- baseURL: "https://api.example.com/v1",
1153
- },
1154
- },
1155
- },
1156
- }),
1157
- )
1158
- },
1159
- })
1160
- await Instance.provide({
1161
- directory: tmp.path,
1162
- init: async () => {
1163
- Env.set("SINGLE_ENV_KEY", "my-api-key")
1164
- },
1165
- fn: async () => {
1166
- const providers = await Provider.list()
1167
- expect(providers["single-env"]).toBeDefined()
1168
- // Single env option should auto-set key
1169
- expect(providers["single-env"].key).toBe("my-api-key")
1170
- },
1171
- })
1172
- })
1173
-
1174
- test("model cost overrides existing cost values", async () => {
1175
- await using tmp = await tmpdir({
1176
- init: async (dir) => {
1177
- await Bun.write(
1178
- path.join(dir, "opencode.json"),
1179
- JSON.stringify({
1180
- $schema: "https://opencode.ai/config.json",
1181
- provider: {
1182
- anthropic: {
1183
- models: {
1184
- "claude-sonnet-4-20250514": {
1185
- cost: {
1186
- input: 999,
1187
- output: 888,
1188
- },
1189
- },
1190
- },
1191
- },
1192
- },
1193
- }),
1194
- )
1195
- },
1196
- })
1197
- await Instance.provide({
1198
- directory: tmp.path,
1199
- init: async () => {
1200
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1201
- },
1202
- fn: async () => {
1203
- const providers = await Provider.list()
1204
- const model = providers["anthropic"].models["claude-sonnet-4-20250514"]
1205
- expect(model.cost.input).toBe(999)
1206
- expect(model.cost.output).toBe(888)
1207
- },
1208
- })
1209
- })
1210
-
1211
- test("completely new provider not in database can be configured", async () => {
1212
- await using tmp = await tmpdir({
1213
- init: async (dir) => {
1214
- await Bun.write(
1215
- path.join(dir, "opencode.json"),
1216
- JSON.stringify({
1217
- $schema: "https://opencode.ai/config.json",
1218
- provider: {
1219
- "brand-new-provider": {
1220
- name: "Brand New",
1221
- npm: "@ai-sdk/openai-compatible",
1222
- env: [],
1223
- api: "https://new-api.com/v1",
1224
- models: {
1225
- "new-model": {
1226
- name: "New Model",
1227
- tool_call: true,
1228
- reasoning: true,
1229
- attachment: true,
1230
- temperature: true,
1231
- limit: { context: 32000, output: 8000 },
1232
- modalities: {
1233
- input: ["text", "image"],
1234
- output: ["text"],
1235
- },
1236
- },
1237
- },
1238
- options: {
1239
- apiKey: "new-key",
1240
- },
1241
- },
1242
- },
1243
- }),
1244
- )
1245
- },
1246
- })
1247
- await Instance.provide({
1248
- directory: tmp.path,
1249
- fn: async () => {
1250
- const providers = await Provider.list()
1251
- expect(providers["brand-new-provider"]).toBeDefined()
1252
- expect(providers["brand-new-provider"].name).toBe("Brand New")
1253
- const model = providers["brand-new-provider"].models["new-model"]
1254
- expect(model.capabilities.reasoning).toBe(true)
1255
- expect(model.capabilities.attachment).toBe(true)
1256
- expect(model.capabilities.input.image).toBe(true)
1257
- },
1258
- })
1259
- })
1260
-
1261
- test("disabled_providers and enabled_providers interaction", async () => {
1262
- await using tmp = await tmpdir({
1263
- init: async (dir) => {
1264
- await Bun.write(
1265
- path.join(dir, "opencode.json"),
1266
- JSON.stringify({
1267
- $schema: "https://opencode.ai/config.json",
1268
- // enabled_providers takes precedence - only these are considered
1269
- enabled_providers: ["anthropic", "openai"],
1270
- // Then disabled_providers filters from the enabled set
1271
- disabled_providers: ["openai"],
1272
- }),
1273
- )
1274
- },
1275
- })
1276
- await Instance.provide({
1277
- directory: tmp.path,
1278
- init: async () => {
1279
- Env.set("ANTHROPIC_API_KEY", "test-anthropic")
1280
- Env.set("OPENAI_API_KEY", "test-openai")
1281
- Env.set("GOOGLE_GENERATIVE_AI_API_KEY", "test-google")
1282
- },
1283
- fn: async () => {
1284
- const providers = await Provider.list()
1285
- // anthropic: in enabled, not in disabled = allowed
1286
- expect(providers["anthropic"]).toBeDefined()
1287
- // openai: in enabled, but also in disabled = NOT allowed
1288
- expect(providers["openai"]).toBeUndefined()
1289
- // google: not in enabled = NOT allowed (even though not disabled)
1290
- expect(providers["google"]).toBeUndefined()
1291
- },
1292
- })
1293
- })
1294
-
1295
- test("model with tool_call false", async () => {
1296
- await using tmp = await tmpdir({
1297
- init: async (dir) => {
1298
- await Bun.write(
1299
- path.join(dir, "opencode.json"),
1300
- JSON.stringify({
1301
- $schema: "https://opencode.ai/config.json",
1302
- provider: {
1303
- "no-tools": {
1304
- name: "No Tools Provider",
1305
- npm: "@ai-sdk/openai-compatible",
1306
- env: [],
1307
- models: {
1308
- "basic-model": {
1309
- name: "Basic Model",
1310
- tool_call: false,
1311
- limit: { context: 4000, output: 1000 },
1312
- },
1313
- },
1314
- options: { apiKey: "test" },
1315
- },
1316
- },
1317
- }),
1318
- )
1319
- },
1320
- })
1321
- await Instance.provide({
1322
- directory: tmp.path,
1323
- fn: async () => {
1324
- const providers = await Provider.list()
1325
- expect(providers["no-tools"].models["basic-model"].capabilities.toolcall).toBe(false)
1326
- },
1327
- })
1328
- })
1329
-
1330
- test("model defaults tool_call to true when not specified", async () => {
1331
- await using tmp = await tmpdir({
1332
- init: async (dir) => {
1333
- await Bun.write(
1334
- path.join(dir, "opencode.json"),
1335
- JSON.stringify({
1336
- $schema: "https://opencode.ai/config.json",
1337
- provider: {
1338
- "default-tools": {
1339
- name: "Default Tools Provider",
1340
- npm: "@ai-sdk/openai-compatible",
1341
- env: [],
1342
- models: {
1343
- model: {
1344
- name: "Model",
1345
- // tool_call not specified
1346
- limit: { context: 4000, output: 1000 },
1347
- },
1348
- },
1349
- options: { apiKey: "test" },
1350
- },
1351
- },
1352
- }),
1353
- )
1354
- },
1355
- })
1356
- await Instance.provide({
1357
- directory: tmp.path,
1358
- fn: async () => {
1359
- const providers = await Provider.list()
1360
- expect(providers["default-tools"].models["model"].capabilities.toolcall).toBe(true)
1361
- },
1362
- })
1363
- })
1364
-
1365
- test("model headers are preserved", async () => {
1366
- await using tmp = await tmpdir({
1367
- init: async (dir) => {
1368
- await Bun.write(
1369
- path.join(dir, "opencode.json"),
1370
- JSON.stringify({
1371
- $schema: "https://opencode.ai/config.json",
1372
- provider: {
1373
- "headers-provider": {
1374
- name: "Headers Provider",
1375
- npm: "@ai-sdk/openai-compatible",
1376
- env: [],
1377
- models: {
1378
- model: {
1379
- name: "Model",
1380
- tool_call: true,
1381
- limit: { context: 4000, output: 1000 },
1382
- headers: {
1383
- "X-Custom-Header": "custom-value",
1384
- Authorization: "Bearer special-token",
1385
- },
1386
- },
1387
- },
1388
- options: { apiKey: "test" },
1389
- },
1390
- },
1391
- }),
1392
- )
1393
- },
1394
- })
1395
- await Instance.provide({
1396
- directory: tmp.path,
1397
- fn: async () => {
1398
- const providers = await Provider.list()
1399
- const model = providers["headers-provider"].models["model"]
1400
- expect(model.headers).toEqual({
1401
- "X-Custom-Header": "custom-value",
1402
- Authorization: "Bearer special-token",
1403
- })
1404
- },
1405
- })
1406
- })
1407
-
1408
- test("provider env fallback - second env var used if first missing", async () => {
1409
- await using tmp = await tmpdir({
1410
- init: async (dir) => {
1411
- await Bun.write(
1412
- path.join(dir, "opencode.json"),
1413
- JSON.stringify({
1414
- $schema: "https://opencode.ai/config.json",
1415
- provider: {
1416
- "fallback-env": {
1417
- name: "Fallback Env Provider",
1418
- npm: "@ai-sdk/openai-compatible",
1419
- env: ["PRIMARY_KEY", "FALLBACK_KEY"],
1420
- models: {
1421
- model: {
1422
- name: "Model",
1423
- tool_call: true,
1424
- limit: { context: 4000, output: 1000 },
1425
- },
1426
- },
1427
- options: { baseURL: "https://api.example.com" },
1428
- },
1429
- },
1430
- }),
1431
- )
1432
- },
1433
- })
1434
- await Instance.provide({
1435
- directory: tmp.path,
1436
- init: async () => {
1437
- // Only set fallback, not primary
1438
- Env.set("FALLBACK_KEY", "fallback-api-key")
1439
- },
1440
- fn: async () => {
1441
- const providers = await Provider.list()
1442
- // Provider should load because fallback env var is set
1443
- expect(providers["fallback-env"]).toBeDefined()
1444
- },
1445
- })
1446
- })
1447
-
1448
- test("getModel returns consistent results", async () => {
1449
- await using tmp = await tmpdir({
1450
- init: async (dir) => {
1451
- await Bun.write(
1452
- path.join(dir, "opencode.json"),
1453
- JSON.stringify({
1454
- $schema: "https://opencode.ai/config.json",
1455
- }),
1456
- )
1457
- },
1458
- })
1459
- await Instance.provide({
1460
- directory: tmp.path,
1461
- init: async () => {
1462
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1463
- },
1464
- fn: async () => {
1465
- const model1 = await Provider.getModel("anthropic", "claude-sonnet-4-20250514")
1466
- const model2 = await Provider.getModel("anthropic", "claude-sonnet-4-20250514")
1467
- expect(model1.providerID).toEqual(model2.providerID)
1468
- expect(model1.id).toEqual(model2.id)
1469
- expect(model1).toEqual(model2)
1470
- },
1471
- })
1472
- })
1473
-
1474
- test("provider name defaults to id when not in database", async () => {
1475
- await using tmp = await tmpdir({
1476
- init: async (dir) => {
1477
- await Bun.write(
1478
- path.join(dir, "opencode.json"),
1479
- JSON.stringify({
1480
- $schema: "https://opencode.ai/config.json",
1481
- provider: {
1482
- "my-custom-id": {
1483
- // no name specified
1484
- npm: "@ai-sdk/openai-compatible",
1485
- env: [],
1486
- models: {
1487
- model: {
1488
- name: "Model",
1489
- tool_call: true,
1490
- limit: { context: 4000, output: 1000 },
1491
- },
1492
- },
1493
- options: { apiKey: "test" },
1494
- },
1495
- },
1496
- }),
1497
- )
1498
- },
1499
- })
1500
- await Instance.provide({
1501
- directory: tmp.path,
1502
- fn: async () => {
1503
- const providers = await Provider.list()
1504
- expect(providers["my-custom-id"].name).toBe("my-custom-id")
1505
- },
1506
- })
1507
- })
1508
-
1509
- test("ModelNotFoundError includes suggestions for typos", async () => {
1510
- await using tmp = await tmpdir({
1511
- init: async (dir) => {
1512
- await Bun.write(
1513
- path.join(dir, "opencode.json"),
1514
- JSON.stringify({
1515
- $schema: "https://opencode.ai/config.json",
1516
- }),
1517
- )
1518
- },
1519
- })
1520
- await Instance.provide({
1521
- directory: tmp.path,
1522
- init: async () => {
1523
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1524
- },
1525
- fn: async () => {
1526
- try {
1527
- await Provider.getModel("anthropic", "claude-sonet-4") // typo: sonet instead of sonnet
1528
- expect(true).toBe(false) // Should not reach here
1529
- } catch (e: any) {
1530
- expect(e.data.suggestions).toBeDefined()
1531
- expect(e.data.suggestions.length).toBeGreaterThan(0)
1532
- }
1533
- },
1534
- })
1535
- })
1536
-
1537
- test("ModelNotFoundError for provider includes suggestions", async () => {
1538
- await using tmp = await tmpdir({
1539
- init: async (dir) => {
1540
- await Bun.write(
1541
- path.join(dir, "opencode.json"),
1542
- JSON.stringify({
1543
- $schema: "https://opencode.ai/config.json",
1544
- }),
1545
- )
1546
- },
1547
- })
1548
- await Instance.provide({
1549
- directory: tmp.path,
1550
- init: async () => {
1551
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1552
- },
1553
- fn: async () => {
1554
- try {
1555
- await Provider.getModel("antropic", "claude-sonnet-4") // typo: antropic
1556
- expect(true).toBe(false) // Should not reach here
1557
- } catch (e: any) {
1558
- expect(e.data.suggestions).toBeDefined()
1559
- expect(e.data.suggestions).toContain("anthropic")
1560
- }
1561
- },
1562
- })
1563
- })
1564
-
1565
- test("getProvider returns undefined for nonexistent provider", async () => {
1566
- await using tmp = await tmpdir({
1567
- init: async (dir) => {
1568
- await Bun.write(
1569
- path.join(dir, "opencode.json"),
1570
- JSON.stringify({
1571
- $schema: "https://opencode.ai/config.json",
1572
- }),
1573
- )
1574
- },
1575
- })
1576
- await Instance.provide({
1577
- directory: tmp.path,
1578
- fn: async () => {
1579
- const provider = await Provider.getProvider("nonexistent")
1580
- expect(provider).toBeUndefined()
1581
- },
1582
- })
1583
- })
1584
-
1585
- test("getProvider returns provider info", async () => {
1586
- await using tmp = await tmpdir({
1587
- init: async (dir) => {
1588
- await Bun.write(
1589
- path.join(dir, "opencode.json"),
1590
- JSON.stringify({
1591
- $schema: "https://opencode.ai/config.json",
1592
- }),
1593
- )
1594
- },
1595
- })
1596
- await Instance.provide({
1597
- directory: tmp.path,
1598
- init: async () => {
1599
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1600
- },
1601
- fn: async () => {
1602
- const provider = await Provider.getProvider("anthropic")
1603
- expect(provider).toBeDefined()
1604
- expect(provider?.id).toBe("anthropic")
1605
- },
1606
- })
1607
- })
1608
-
1609
- test("closest returns undefined when no partial match found", async () => {
1610
- await using tmp = await tmpdir({
1611
- init: async (dir) => {
1612
- await Bun.write(
1613
- path.join(dir, "opencode.json"),
1614
- JSON.stringify({
1615
- $schema: "https://opencode.ai/config.json",
1616
- }),
1617
- )
1618
- },
1619
- })
1620
- await Instance.provide({
1621
- directory: tmp.path,
1622
- init: async () => {
1623
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1624
- },
1625
- fn: async () => {
1626
- const result = await Provider.closest("anthropic", ["nonexistent-xyz-model"])
1627
- expect(result).toBeUndefined()
1628
- },
1629
- })
1630
- })
1631
-
1632
- test("closest checks multiple query terms in order", async () => {
1633
- await using tmp = await tmpdir({
1634
- init: async (dir) => {
1635
- await Bun.write(
1636
- path.join(dir, "opencode.json"),
1637
- JSON.stringify({
1638
- $schema: "https://opencode.ai/config.json",
1639
- }),
1640
- )
1641
- },
1642
- })
1643
- await Instance.provide({
1644
- directory: tmp.path,
1645
- init: async () => {
1646
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1647
- },
1648
- fn: async () => {
1649
- // First term won't match, second will
1650
- const result = await Provider.closest("anthropic", ["nonexistent", "haiku"])
1651
- expect(result).toBeDefined()
1652
- expect(result?.modelID).toContain("haiku")
1653
- },
1654
- })
1655
- })
1656
-
1657
- test("model limit defaults to zero when not specified", async () => {
1658
- await using tmp = await tmpdir({
1659
- init: async (dir) => {
1660
- await Bun.write(
1661
- path.join(dir, "opencode.json"),
1662
- JSON.stringify({
1663
- $schema: "https://opencode.ai/config.json",
1664
- provider: {
1665
- "no-limit": {
1666
- name: "No Limit Provider",
1667
- npm: "@ai-sdk/openai-compatible",
1668
- env: [],
1669
- models: {
1670
- model: {
1671
- name: "Model",
1672
- tool_call: true,
1673
- // no limit specified
1674
- },
1675
- },
1676
- options: { apiKey: "test" },
1677
- },
1678
- },
1679
- }),
1680
- )
1681
- },
1682
- })
1683
- await Instance.provide({
1684
- directory: tmp.path,
1685
- fn: async () => {
1686
- const providers = await Provider.list()
1687
- const model = providers["no-limit"].models["model"]
1688
- expect(model.limit.context).toBe(0)
1689
- expect(model.limit.output).toBe(0)
1690
- },
1691
- })
1692
- })
1693
-
1694
- test("provider options are deeply merged", async () => {
1695
- await using tmp = await tmpdir({
1696
- init: async (dir) => {
1697
- await Bun.write(
1698
- path.join(dir, "opencode.json"),
1699
- JSON.stringify({
1700
- $schema: "https://opencode.ai/config.json",
1701
- provider: {
1702
- anthropic: {
1703
- options: {
1704
- headers: {
1705
- "X-Custom": "custom-value",
1706
- },
1707
- timeout: 30000,
1708
- },
1709
- },
1710
- },
1711
- }),
1712
- )
1713
- },
1714
- })
1715
- await Instance.provide({
1716
- directory: tmp.path,
1717
- init: async () => {
1718
- Env.set("ANTHROPIC_API_KEY", "test-api-key")
1719
- },
1720
- fn: async () => {
1721
- const providers = await Provider.list()
1722
- // Custom options should be merged
1723
- expect(providers["anthropic"].options.timeout).toBe(30000)
1724
- expect(providers["anthropic"].options.headers["X-Custom"]).toBe("custom-value")
1725
- // anthropic custom loader adds its own headers, they should coexist
1726
- expect(providers["anthropic"].options.headers["anthropic-beta"]).toBeDefined()
1727
- },
1728
- })
1729
- })
1730
-
1731
- test("custom model inherits npm package from models.dev provider config", async () => {
1732
- await using tmp = await tmpdir({
1733
- init: async (dir) => {
1734
- await Bun.write(
1735
- path.join(dir, "opencode.json"),
1736
- JSON.stringify({
1737
- $schema: "https://opencode.ai/config.json",
1738
- provider: {
1739
- openai: {
1740
- models: {
1741
- "my-custom-model": {
1742
- name: "My Custom Model",
1743
- tool_call: true,
1744
- limit: { context: 8000, output: 2000 },
1745
- },
1746
- },
1747
- },
1748
- },
1749
- }),
1750
- )
1751
- },
1752
- })
1753
- await Instance.provide({
1754
- directory: tmp.path,
1755
- init: async () => {
1756
- Env.set("OPENAI_API_KEY", "test-api-key")
1757
- },
1758
- fn: async () => {
1759
- const providers = await Provider.list()
1760
- const model = providers["openai"].models["my-custom-model"]
1761
- expect(model).toBeDefined()
1762
- expect(model.api.npm).toBe("@ai-sdk/openai")
1763
- },
1764
- })
1765
- })
1766
-
1767
- test("custom model inherits api.url from models.dev provider", async () => {
1768
- await using tmp = await tmpdir({
1769
- init: async (dir) => {
1770
- await Bun.write(
1771
- path.join(dir, "opencode.json"),
1772
- JSON.stringify({
1773
- $schema: "https://opencode.ai/config.json",
1774
- provider: {
1775
- openrouter: {
1776
- models: {
1777
- "prime-intellect/intellect-3": {},
1778
- "deepseek/deepseek-r1-0528": {
1779
- name: "DeepSeek R1",
1780
- },
1781
- },
1782
- },
1783
- },
1784
- }),
1785
- )
1786
- },
1787
- })
1788
- await Instance.provide({
1789
- directory: tmp.path,
1790
- init: async () => {
1791
- Env.set("OPENROUTER_API_KEY", "test-api-key")
1792
- },
1793
- fn: async () => {
1794
- const providers = await Provider.list()
1795
- expect(providers["openrouter"]).toBeDefined()
1796
-
1797
- // New model not in database should inherit api.url from provider
1798
- const intellect = providers["openrouter"].models["prime-intellect/intellect-3"]
1799
- expect(intellect).toBeDefined()
1800
- expect(intellect.api.url).toBe("https://openrouter.ai/api/v1")
1801
-
1802
- // Another new model should also inherit api.url
1803
- const deepseek = providers["openrouter"].models["deepseek/deepseek-r1-0528"]
1804
- expect(deepseek).toBeDefined()
1805
- expect(deepseek.api.url).toBe("https://openrouter.ai/api/v1")
1806
- expect(deepseek.name).toBe("DeepSeek R1")
1807
- },
1808
- })
1809
- })