@epoch-ai/cli 2.2.4 → 2.2.5

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