easc-cli 1.1.37 → 1.1.40

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 (412) hide show
  1. package/bin/{opencode → opencode.cjs} +4 -6
  2. package/package.json +15 -120
  3. package/AGENTS.md +0 -27
  4. package/Dockerfile +0 -18
  5. package/README.md +0 -15
  6. package/bunfig.toml +0 -7
  7. package/charity-website/README.md +0 -252
  8. package/charity-website/admin/index.html +0 -299
  9. package/charity-website/package.json +0 -40
  10. package/charity-website/public/index.html +0 -265
  11. package/charity-website/src/css/admin.css +0 -710
  12. package/charity-website/src/css/style.css +0 -741
  13. package/charity-website/src/js/admin.js +0 -743
  14. package/charity-website/src/js/app.js +0 -444
  15. package/parsers-config.ts +0 -253
  16. package/script/build.ts +0 -172
  17. package/script/deploy.ts +0 -96
  18. package/script/publish-registries.ts +0 -187
  19. package/script/publish.ts +0 -70
  20. package/script/schema.ts +0 -47
  21. package/script/seed-e2e.ts +0 -50
  22. package/src/acp/README.md +0 -164
  23. package/src/acp/agent.ts +0 -1285
  24. package/src/acp/session.ts +0 -105
  25. package/src/acp/types.ts +0 -22
  26. package/src/agent/agent.ts +0 -332
  27. package/src/agent/generate.txt +0 -75
  28. package/src/agent/prompt/compaction.txt +0 -12
  29. package/src/agent/prompt/explore.txt +0 -18
  30. package/src/agent/prompt/summary.txt +0 -11
  31. package/src/agent/prompt/title.txt +0 -43
  32. package/src/auth/eliseart.ts +0 -76
  33. package/src/auth/index.ts +0 -73
  34. package/src/bun/index.ts +0 -134
  35. package/src/bus/bus-event.ts +0 -43
  36. package/src/bus/global.ts +0 -10
  37. package/src/bus/index.ts +0 -105
  38. package/src/cli/bootstrap.ts +0 -17
  39. package/src/cli/cmd/account.ts +0 -81
  40. package/src/cli/cmd/acp.ts +0 -69
  41. package/src/cli/cmd/agent.ts +0 -257
  42. package/src/cli/cmd/auth.ts +0 -427
  43. package/src/cli/cmd/cmd.ts +0 -7
  44. package/src/cli/cmd/debug/agent.ts +0 -166
  45. package/src/cli/cmd/debug/config.ts +0 -16
  46. package/src/cli/cmd/debug/file.ts +0 -97
  47. package/src/cli/cmd/debug/index.ts +0 -48
  48. package/src/cli/cmd/debug/lsp.ts +0 -52
  49. package/src/cli/cmd/debug/ripgrep.ts +0 -87
  50. package/src/cli/cmd/debug/scrap.ts +0 -16
  51. package/src/cli/cmd/debug/skill.ts +0 -16
  52. package/src/cli/cmd/debug/snapshot.ts +0 -52
  53. package/src/cli/cmd/export.ts +0 -88
  54. package/src/cli/cmd/generate.ts +0 -38
  55. package/src/cli/cmd/github.ts +0 -1548
  56. package/src/cli/cmd/import.ts +0 -98
  57. package/src/cli/cmd/mcp.ts +0 -827
  58. package/src/cli/cmd/models.ts +0 -77
  59. package/src/cli/cmd/pr.ts +0 -112
  60. package/src/cli/cmd/run.ts +0 -407
  61. package/src/cli/cmd/serve.ts +0 -20
  62. package/src/cli/cmd/session.ts +0 -135
  63. package/src/cli/cmd/stats.ts +0 -402
  64. package/src/cli/cmd/tui/app.tsx +0 -774
  65. package/src/cli/cmd/tui/attach.ts +0 -31
  66. package/src/cli/cmd/tui/component/border.tsx +0 -21
  67. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  68. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
  69. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  70. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -234
  71. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -256
  72. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -114
  73. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  74. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
  75. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -164
  76. package/src/cli/cmd/tui/component/dialog-supabase.tsx +0 -102
  77. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  78. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  79. package/src/cli/cmd/tui/component/logo.tsx +0 -88
  80. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -653
  81. package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
  82. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  83. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1182
  84. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  85. package/src/cli/cmd/tui/component/spinner.tsx +0 -16
  86. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  87. package/src/cli/cmd/tui/component/tips.tsx +0 -153
  88. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  89. package/src/cli/cmd/tui/context/args.tsx +0 -14
  90. package/src/cli/cmd/tui/context/directory.ts +0 -13
  91. package/src/cli/cmd/tui/context/exit.tsx +0 -23
  92. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  93. package/src/cli/cmd/tui/context/keybind.tsx +0 -101
  94. package/src/cli/cmd/tui/context/kv.tsx +0 -52
  95. package/src/cli/cmd/tui/context/local.tsx +0 -402
  96. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  97. package/src/cli/cmd/tui/context/route.tsx +0 -46
  98. package/src/cli/cmd/tui/context/sdk.tsx +0 -94
  99. package/src/cli/cmd/tui/context/sync.tsx +0 -445
  100. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  101. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  102. package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
  103. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  104. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  105. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  106. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  107. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  108. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  109. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  110. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  111. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  112. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
  113. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  114. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
  115. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  116. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  117. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  118. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  119. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  120. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  121. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  122. package/src/cli/cmd/tui/context/theme/orng.json +0 -249
  123. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  124. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  125. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  126. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  127. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  128. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  129. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  130. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  131. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  132. package/src/cli/cmd/tui/context/theme.tsx +0 -1152
  133. package/src/cli/cmd/tui/event.ts +0 -48
  134. package/src/cli/cmd/tui/routes/home.tsx +0 -140
  135. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
  136. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
  137. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  138. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  139. package/src/cli/cmd/tui/routes/session/dialog-tool.tsx +0 -63
  140. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -129
  141. package/src/cli/cmd/tui/routes/session/header.tsx +0 -136
  142. package/src/cli/cmd/tui/routes/session/index.tsx +0 -2132
  143. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -495
  144. package/src/cli/cmd/tui/routes/session/question.tsx +0 -435
  145. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -313
  146. package/src/cli/cmd/tui/thread.ts +0 -165
  147. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
  148. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
  149. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
  150. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
  151. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
  152. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -376
  153. package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
  154. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  155. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  156. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  157. package/src/cli/cmd/tui/util/clipboard.ts +0 -160
  158. package/src/cli/cmd/tui/util/editor.ts +0 -32
  159. package/src/cli/cmd/tui/util/signal.ts +0 -7
  160. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  161. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  162. package/src/cli/cmd/tui/worker.ts +0 -152
  163. package/src/cli/cmd/uninstall.ts +0 -357
  164. package/src/cli/cmd/upgrade.ts +0 -73
  165. package/src/cli/cmd/web.ts +0 -81
  166. package/src/cli/error.ts +0 -57
  167. package/src/cli/network.ts +0 -53
  168. package/src/cli/ui.ts +0 -84
  169. package/src/cli/upgrade.ts +0 -25
  170. package/src/command/index.ts +0 -131
  171. package/src/command/template/initialize.txt +0 -10
  172. package/src/command/template/review.txt +0 -99
  173. package/src/config/config.ts +0 -1361
  174. package/src/config/markdown.ts +0 -93
  175. package/src/env/index.ts +0 -26
  176. package/src/file/ignore.ts +0 -83
  177. package/src/file/index.ts +0 -411
  178. package/src/file/ripgrep.ts +0 -407
  179. package/src/file/time.ts +0 -64
  180. package/src/file/watcher.ts +0 -127
  181. package/src/flag/flag.ts +0 -54
  182. package/src/format/formatter.ts +0 -342
  183. package/src/format/index.ts +0 -137
  184. package/src/global/index.ts +0 -55
  185. package/src/id/id.ts +0 -83
  186. package/src/ide/index.ts +0 -76
  187. package/src/index.ts +0 -162
  188. package/src/installation/index.ts +0 -246
  189. package/src/lsp/client.ts +0 -252
  190. package/src/lsp/index.ts +0 -485
  191. package/src/lsp/language.ts +0 -119
  192. package/src/lsp/server.ts +0 -2046
  193. package/src/mcp/auth.ts +0 -135
  194. package/src/mcp/index.ts +0 -931
  195. package/src/mcp/oauth-callback.ts +0 -200
  196. package/src/mcp/oauth-provider.ts +0 -154
  197. package/src/patch/index.ts +0 -680
  198. package/src/permission/arity.ts +0 -163
  199. package/src/permission/index.ts +0 -210
  200. package/src/permission/next.ts +0 -269
  201. package/src/plugin/codex.ts +0 -493
  202. package/src/plugin/copilot.ts +0 -269
  203. package/src/plugin/index.ts +0 -136
  204. package/src/project/bootstrap.ts +0 -35
  205. package/src/project/instance.ts +0 -91
  206. package/src/project/project.ts +0 -339
  207. package/src/project/state.ts +0 -66
  208. package/src/project/vcs.ts +0 -76
  209. package/src/provider/auth.ts +0 -147
  210. package/src/provider/models-macro.ts +0 -11
  211. package/src/provider/models.ts +0 -112
  212. package/src/provider/provider.ts +0 -1435
  213. package/src/provider/sdk/openai-compatible/src/README.md +0 -5
  214. package/src/provider/sdk/openai-compatible/src/index.ts +0 -2
  215. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +0 -100
  216. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +0 -303
  217. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +0 -22
  218. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +0 -18
  219. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +0 -22
  220. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +0 -207
  221. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +0 -1732
  222. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +0 -177
  223. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +0 -1
  224. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +0 -88
  225. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +0 -128
  226. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +0 -115
  227. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +0 -65
  228. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +0 -104
  229. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +0 -103
  230. package/src/provider/transform.ts +0 -733
  231. package/src/pty/index.ts +0 -232
  232. package/src/question/index.ts +0 -171
  233. package/src/scheduler/index.ts +0 -61
  234. package/src/server/error.ts +0 -36
  235. package/src/server/event.ts +0 -7
  236. package/src/server/mdns.ts +0 -59
  237. package/src/server/routes/config.ts +0 -92
  238. package/src/server/routes/experimental.ts +0 -208
  239. package/src/server/routes/file.ts +0 -197
  240. package/src/server/routes/global.ts +0 -135
  241. package/src/server/routes/mcp.ts +0 -361
  242. package/src/server/routes/permission.ts +0 -68
  243. package/src/server/routes/project.ts +0 -82
  244. package/src/server/routes/provider.ts +0 -165
  245. package/src/server/routes/pty.ts +0 -169
  246. package/src/server/routes/question.ts +0 -98
  247. package/src/server/routes/session.ts +0 -935
  248. package/src/server/routes/tui.ts +0 -379
  249. package/src/server/server.ts +0 -573
  250. package/src/session/compaction.ts +0 -225
  251. package/src/session/index.ts +0 -488
  252. package/src/session/llm.ts +0 -279
  253. package/src/session/message-v2.ts +0 -702
  254. package/src/session/message.ts +0 -189
  255. package/src/session/processor.ts +0 -406
  256. package/src/session/prompt/anthropic-20250930.txt +0 -166
  257. package/src/session/prompt/anthropic.txt +0 -105
  258. package/src/session/prompt/anthropic_spoof.txt +0 -1
  259. package/src/session/prompt/beast.txt +0 -147
  260. package/src/session/prompt/build-switch.txt +0 -5
  261. package/src/session/prompt/codex_header.txt +0 -79
  262. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  263. package/src/session/prompt/gemini.txt +0 -155
  264. package/src/session/prompt/max-steps.txt +0 -16
  265. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  266. package/src/session/prompt/plan.txt +0 -26
  267. package/src/session/prompt/qwen.txt +0 -109
  268. package/src/session/prompt.ts +0 -1820
  269. package/src/session/retry.ts +0 -90
  270. package/src/session/revert.ts +0 -108
  271. package/src/session/status.ts +0 -76
  272. package/src/session/summary.ts +0 -150
  273. package/src/session/system.ts +0 -152
  274. package/src/session/todo.ts +0 -37
  275. package/src/share/share-next.ts +0 -200
  276. package/src/share/share.ts +0 -92
  277. package/src/shell/shell.ts +0 -67
  278. package/src/skill/index.ts +0 -1
  279. package/src/skill/skill.ts +0 -136
  280. package/src/snapshot/index.ts +0 -236
  281. package/src/storage/storage.ts +0 -227
  282. package/src/tool/apply_patch.ts +0 -269
  283. package/src/tool/apply_patch.txt +0 -33
  284. package/src/tool/bash.ts +0 -259
  285. package/src/tool/bash.txt +0 -115
  286. package/src/tool/batch.ts +0 -175
  287. package/src/tool/batch.txt +0 -24
  288. package/src/tool/codesearch.ts +0 -132
  289. package/src/tool/codesearch.txt +0 -12
  290. package/src/tool/edit.ts +0 -645
  291. package/src/tool/edit.txt +0 -10
  292. package/src/tool/external-directory.ts +0 -32
  293. package/src/tool/glob.ts +0 -77
  294. package/src/tool/glob.txt +0 -6
  295. package/src/tool/grep.ts +0 -154
  296. package/src/tool/grep.txt +0 -8
  297. package/src/tool/invalid.ts +0 -17
  298. package/src/tool/ls.ts +0 -121
  299. package/src/tool/ls.txt +0 -1
  300. package/src/tool/lsp.ts +0 -96
  301. package/src/tool/lsp.txt +0 -19
  302. package/src/tool/multiedit.ts +0 -46
  303. package/src/tool/multiedit.txt +0 -41
  304. package/src/tool/plan-enter.txt +0 -14
  305. package/src/tool/plan-exit.txt +0 -13
  306. package/src/tool/plan.ts +0 -130
  307. package/src/tool/question.ts +0 -33
  308. package/src/tool/question.txt +0 -10
  309. package/src/tool/read.ts +0 -202
  310. package/src/tool/read.txt +0 -12
  311. package/src/tool/registry.ts +0 -164
  312. package/src/tool/skill.ts +0 -75
  313. package/src/tool/task.ts +0 -188
  314. package/src/tool/task.txt +0 -60
  315. package/src/tool/todo.ts +0 -53
  316. package/src/tool/todoread.txt +0 -14
  317. package/src/tool/todowrite.txt +0 -167
  318. package/src/tool/tool.ts +0 -88
  319. package/src/tool/truncation.ts +0 -106
  320. package/src/tool/webfetch.ts +0 -182
  321. package/src/tool/webfetch.txt +0 -13
  322. package/src/tool/websearch.ts +0 -150
  323. package/src/tool/websearch.txt +0 -14
  324. package/src/tool/write.ts +0 -80
  325. package/src/tool/write.txt +0 -8
  326. package/src/util/archive.ts +0 -16
  327. package/src/util/color.ts +0 -19
  328. package/src/util/context.ts +0 -25
  329. package/src/util/defer.ts +0 -12
  330. package/src/util/eventloop.ts +0 -20
  331. package/src/util/filesystem.ts +0 -93
  332. package/src/util/fn.ts +0 -11
  333. package/src/util/format.ts +0 -20
  334. package/src/util/iife.ts +0 -3
  335. package/src/util/keybind.ts +0 -103
  336. package/src/util/lazy.ts +0 -18
  337. package/src/util/locale.ts +0 -81
  338. package/src/util/lock.ts +0 -98
  339. package/src/util/log.ts +0 -180
  340. package/src/util/queue.ts +0 -32
  341. package/src/util/rpc.ts +0 -66
  342. package/src/util/scrap.ts +0 -10
  343. package/src/util/signal.ts +0 -12
  344. package/src/util/timeout.ts +0 -14
  345. package/src/util/token.ts +0 -7
  346. package/src/util/wildcard.ts +0 -56
  347. package/src/worktree/index.ts +0 -424
  348. package/sst-env.d.ts +0 -9
  349. package/test/acp/event-subscription.test.ts +0 -436
  350. package/test/agent/agent.test.ts +0 -638
  351. package/test/bun.test.ts +0 -53
  352. package/test/cli/github-action.test.ts +0 -129
  353. package/test/cli/github-remote.test.ts +0 -80
  354. package/test/cli/tui/transcript.test.ts +0 -297
  355. package/test/config/agent-color.test.ts +0 -66
  356. package/test/config/config.test.ts +0 -1414
  357. package/test/config/fixtures/empty-frontmatter.md +0 -4
  358. package/test/config/fixtures/frontmatter.md +0 -28
  359. package/test/config/fixtures/no-frontmatter.md +0 -1
  360. package/test/config/markdown.test.ts +0 -192
  361. package/test/file/ignore.test.ts +0 -10
  362. package/test/file/path-traversal.test.ts +0 -198
  363. package/test/fixture/fixture.ts +0 -45
  364. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  365. package/test/ide/ide.test.ts +0 -82
  366. package/test/keybind.test.ts +0 -421
  367. package/test/lsp/client.test.ts +0 -95
  368. package/test/mcp/headers.test.ts +0 -153
  369. package/test/mcp/oauth-browser.test.ts +0 -261
  370. package/test/patch/patch.test.ts +0 -348
  371. package/test/permission/arity.test.ts +0 -33
  372. package/test/permission/next.test.ts +0 -652
  373. package/test/permission-task.test.ts +0 -319
  374. package/test/plugin/codex.test.ts +0 -123
  375. package/test/preload.ts +0 -65
  376. package/test/project/project.test.ts +0 -120
  377. package/test/provider/amazon-bedrock.test.ts +0 -268
  378. package/test/provider/gitlab-duo.test.ts +0 -286
  379. package/test/provider/provider.test.ts +0 -2149
  380. package/test/provider/transform.test.ts +0 -1596
  381. package/test/question/question.test.ts +0 -300
  382. package/test/scheduler.test.ts +0 -73
  383. package/test/server/session-list.test.ts +0 -39
  384. package/test/server/session-select.test.ts +0 -78
  385. package/test/session/compaction.test.ts +0 -293
  386. package/test/session/llm.test.ts +0 -90
  387. package/test/session/message-v2.test.ts +0 -662
  388. package/test/session/retry.test.ts +0 -131
  389. package/test/session/revert-compact.test.ts +0 -285
  390. package/test/session/session.test.ts +0 -71
  391. package/test/skill/skill.test.ts +0 -185
  392. package/test/snapshot/snapshot.test.ts +0 -939
  393. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  394. package/test/tool/apply_patch.test.ts +0 -499
  395. package/test/tool/bash.test.ts +0 -320
  396. package/test/tool/external-directory.test.ts +0 -126
  397. package/test/tool/fixtures/large-image.png +0 -0
  398. package/test/tool/fixtures/models-api.json +0 -33453
  399. package/test/tool/grep.test.ts +0 -109
  400. package/test/tool/question.test.ts +0 -105
  401. package/test/tool/read.test.ts +0 -332
  402. package/test/tool/registry.test.ts +0 -76
  403. package/test/tool/truncation.test.ts +0 -159
  404. package/test/util/filesystem.test.ts +0 -39
  405. package/test/util/format.test.ts +0 -59
  406. package/test/util/iife.test.ts +0 -36
  407. package/test/util/lazy.test.ts +0 -50
  408. package/test/util/lock.test.ts +0 -72
  409. package/test/util/timeout.test.ts +0 -21
  410. package/test/util/wildcard.test.ts +0 -75
  411. package/tsconfig.json +0 -16
  412. /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
@@ -1,1435 +0,0 @@
1
- import z from "zod"
2
- import { pathToFileURL } from "url"
3
- import fuzzysort from "fuzzysort"
4
- import { Config } from "../config/config"
5
- import { mapValues, mergeDeep, omit, pickBy, sortBy } from "remeda"
6
- import { NoSuchModelError, type Provider as SDK } from "ai"
7
- import { Log } from "../util/log"
8
- import { BunProc } from "../bun"
9
- import { Plugin } from "../plugin"
10
- import { ModelsDev } from "./models"
11
- import { NamedError } from "@eliseart.ai/util/error"
12
- import { Auth } from "../auth"
13
- import { Env } from "../env"
14
- import { Instance } from "../project/instance"
15
- import { Flag } from "../flag/flag"
16
- import { iife } from "@/util/iife"
17
-
18
- // Direct imports for bundled providers
19
- import { createAmazonBedrock, type AmazonBedrockProviderSettings } from "@ai-sdk/amazon-bedrock"
20
- import { createAnthropic } from "@ai-sdk/anthropic"
21
- import { createAzure } from "@ai-sdk/azure"
22
- import { createGoogleGenerativeAI } from "@ai-sdk/google"
23
- import { createVertex } from "@ai-sdk/google-vertex"
24
- import { createVertexAnthropic } from "@ai-sdk/google-vertex/anthropic"
25
- import { createOpenAI } from "@ai-sdk/openai"
26
- import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
27
- import { createOpenRouter, type LanguageModelV2 } from "@openrouter/ai-sdk-provider"
28
- import { createOpenaiCompatible as createGitHubCopilotOpenAICompatible } from "./sdk/openai-compatible/src"
29
- import { createXai } from "@ai-sdk/xai"
30
- import { createMistral } from "@ai-sdk/mistral"
31
- import { createGroq } from "@ai-sdk/groq"
32
- import { createDeepInfra } from "@ai-sdk/deepinfra"
33
- import { createCerebras } from "@ai-sdk/cerebras"
34
- import { createCohere } from "@ai-sdk/cohere"
35
- import { createGateway } from "@ai-sdk/gateway"
36
- import { createTogetherAI } from "@ai-sdk/togetherai"
37
- import { createPerplexity } from "@ai-sdk/perplexity"
38
- import { createVercel } from "@ai-sdk/vercel"
39
- import { createGitLab } from "@gitlab/gitlab-ai-provider"
40
- import { ProviderTransform } from "./transform"
41
- import { EliseArtAuth, ELISEART_SUPABASE_URL } from "../auth/eliseart"
42
-
43
- export namespace Provider {
44
- const log = Log.create({ service: "provider" })
45
-
46
- function isGpt5OrLater(modelID: string): boolean {
47
- const match = /^gpt-(\d+)/.exec(modelID)
48
- if (!match) {
49
- return false
50
- }
51
- return Number(match[1]) >= 5
52
- }
53
-
54
- function shouldUseCopilotResponsesApi(modelID: string): boolean {
55
- return isGpt5OrLater(modelID) && !modelID.startsWith("gpt-5-mini")
56
- }
57
-
58
- const BUNDLED_PROVIDERS: Record<string, (options: any) => SDK> = {
59
- "@ai-sdk/amazon-bedrock": createAmazonBedrock,
60
- "@ai-sdk/anthropic": createAnthropic,
61
- "@ai-sdk/azure": createAzure,
62
- "@ai-sdk/google": createGoogleGenerativeAI,
63
- "@ai-sdk/google-vertex": createVertex,
64
- "@ai-sdk/google-vertex/anthropic": createVertexAnthropic,
65
- "@ai-sdk/openai": createOpenAI,
66
- "@ai-sdk/openai-compatible": createOpenAICompatible,
67
- "@openrouter/ai-sdk-provider": createOpenRouter,
68
- "@ai-sdk/xai": createXai,
69
- "@ai-sdk/mistral": createMistral,
70
- "@ai-sdk/groq": createGroq,
71
- "@ai-sdk/deepinfra": createDeepInfra,
72
- "@ai-sdk/cerebras": createCerebras,
73
- "@ai-sdk/cohere": createCohere,
74
- "@ai-sdk/gateway": createGateway,
75
- "@ai-sdk/togetherai": createTogetherAI,
76
- "@ai-sdk/perplexity": createPerplexity,
77
- "@ai-sdk/vercel": createVercel,
78
- "@gitlab/gitlab-ai-provider": createGitLab,
79
- // @ts-ignore (TODO: kill this code so we dont have to maintain it)
80
- "@ai-sdk/github-copilot": createGitHubCopilotOpenAICompatible,
81
- }
82
-
83
- type CustomModelLoader = (sdk: any, modelID: string, options?: Record<string, any>) => Promise<any>
84
- type CustomLoader = (provider: Info) => Promise<{
85
- autoload: boolean
86
- getModel?: CustomModelLoader
87
- options?: Record<string, any>
88
- }>
89
-
90
- const CUSTOM_LOADERS: Record<string, CustomLoader> = {
91
- async anthropic() {
92
- return {
93
- autoload: false,
94
- options: {
95
- headers: {
96
- "anthropic-beta":
97
- "claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",
98
- },
99
- },
100
- }
101
- },
102
- async opencode(input) {
103
- const hasKey = await (async () => {
104
- const env = Env.all()
105
- if (input.env.some((item) => env[item])) return true
106
- if (await Auth.get(input.id)) return true
107
- const config = await Config.get()
108
- if (config.provider?.["opencode"]?.options?.apiKey) return true
109
- return false
110
- })()
111
-
112
- if (!hasKey) {
113
- for (const [key, value] of Object.entries(input.models)) {
114
- if (value.cost.input === 0) continue
115
- delete input.models[key]
116
- }
117
- }
118
-
119
- return {
120
- autoload: Object.keys(input.models).length > 0,
121
- options: hasKey ? {} : { apiKey: "public" },
122
- }
123
- },
124
- async eliseart(input) {
125
- const session = await EliseArtAuth.getSession();
126
- const hasKey = !!session;
127
-
128
- return {
129
- autoload: true,
130
- options: {
131
- baseURL: `${ELISEART_SUPABASE_URL}/functions/v1/chat-completion`,
132
- headers: {
133
- ...(await EliseArtAuth.getAuthHeaders())
134
- },
135
- // Custom fetch to intercept credit exhaustion responses
136
- fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
137
- const response = await fetch(input, init);
138
-
139
- // Check for upgrade_required in non-streaming responses
140
- const contentType = response.headers.get("content-type") || "";
141
- if (contentType.includes("application/json") && response.status === 200) {
142
- const clonedResponse = response.clone();
143
- try {
144
- const json = await clonedResponse.json();
145
- if (json.upgrade_required) {
146
- throw new Error(
147
- `\n🚀 AI Credits Exhausted!\n\n` +
148
- `You've used all your AI credits. Upgrade your EliseArt plan to continue:\n` +
149
- ` ✨ Little Gummy - $1/month for 20 credits\n` +
150
- ` 👑 Premium - $15/month for 500 credits + offline downloads\n\n` +
151
- `Upgrade at: https://elise-art.web.app/subscription\n` +
152
- `Remaining credits: ${json.remaining_credits ?? 0}`
153
- );
154
- }
155
- } catch (e: any) {
156
- // If it's our custom error, rethrow it
157
- if (e.message?.includes("AI Credits Exhausted")) {
158
- throw e;
159
- }
160
- // Otherwise ignore JSON parse errors and return original response
161
- }
162
- }
163
-
164
- return response;
165
- }
166
- },
167
- async getModel(sdk: any, modelID: string) {
168
- return sdk.languageModel(modelID);
169
- }
170
- };
171
- },
172
- openai: async () => {
173
- return {
174
- autoload: false,
175
- async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
176
- return sdk.responses(modelID)
177
- },
178
- options: {},
179
- }
180
- },
181
- "github-copilot": async () => {
182
- return {
183
- autoload: false,
184
- async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
185
- return shouldUseCopilotResponsesApi(modelID) ? sdk.responses(modelID) : sdk.chat(modelID)
186
- },
187
- options: {},
188
- }
189
- },
190
- "github-copilot-enterprise": async () => {
191
- return {
192
- autoload: false,
193
- async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
194
- return shouldUseCopilotResponsesApi(modelID) ? sdk.responses(modelID) : sdk.chat(modelID)
195
- },
196
- options: {},
197
- }
198
- },
199
- azure: async () => {
200
- return {
201
- autoload: false,
202
- async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
203
- if (options?.["useCompletionUrls"]) {
204
- return sdk.chat(modelID)
205
- } else {
206
- return sdk.responses(modelID)
207
- }
208
- },
209
- options: {},
210
- }
211
- },
212
- "azure-cognitive-services": async () => {
213
- const resourceName = Env.get("AZURE_COGNITIVE_SERVICES_RESOURCE_NAME")
214
- return {
215
- autoload: false,
216
- async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
217
- if (options?.["useCompletionUrls"]) {
218
- return sdk.chat(modelID)
219
- } else {
220
- return sdk.responses(modelID)
221
- }
222
- },
223
- options: {
224
- baseURL: resourceName ? `https://${resourceName}.cognitiveservices.azure.com/openai` : undefined,
225
- },
226
- }
227
- },
228
- "amazon-bedrock": async () => {
229
- const config = await Config.get()
230
- const providerConfig = config.provider?.["amazon-bedrock"]
231
-
232
- const auth = await Auth.get("amazon-bedrock")
233
-
234
- // Region precedence: 1) config file, 2) env var, 3) default
235
- const configRegion = providerConfig?.options?.region
236
- const envRegion = Env.get("AWS_REGION")
237
- const defaultRegion = configRegion ?? envRegion ?? "us-east-1"
238
-
239
- // Profile: config file takes precedence over env var
240
- const configProfile = providerConfig?.options?.profile
241
- const envProfile = Env.get("AWS_PROFILE")
242
- const profile = configProfile ?? envProfile
243
-
244
- const awsAccessKeyId = Env.get("AWS_ACCESS_KEY_ID")
245
-
246
- const awsBearerToken = iife(() => {
247
- const envToken = Env.get("AWS_BEARER_TOKEN_BEDROCK")
248
- if (envToken) return envToken
249
- if (auth?.type === "api") {
250
- Env.set("AWS_BEARER_TOKEN_BEDROCK", auth.key)
251
- return auth.key
252
- }
253
- return undefined
254
- })
255
-
256
- const awsWebIdentityTokenFile = Env.get("AWS_WEB_IDENTITY_TOKEN_FILE")
257
-
258
- if (!profile && !awsAccessKeyId && !awsBearerToken && !awsWebIdentityTokenFile) return { autoload: false }
259
-
260
- const providerOptions: AmazonBedrockProviderSettings = {
261
- region: defaultRegion,
262
- }
263
-
264
- // Only use credential chain if no bearer token exists
265
- // Bearer token takes precedence over credential chain (profiles, access keys, IAM roles, web identity tokens)
266
- if (!awsBearerToken) {
267
- const { fromNodeProviderChain } = await import(pathToFileURL(await BunProc.install("@aws-sdk/credential-providers")).href)
268
-
269
- // Build credential provider options (only pass profile if specified)
270
- const credentialProviderOptions = profile ? { profile } : {}
271
-
272
- providerOptions.credentialProvider = fromNodeProviderChain(credentialProviderOptions)
273
- }
274
-
275
- // Add custom endpoint if specified (endpoint takes precedence over baseURL)
276
- const endpoint = providerConfig?.options?.endpoint ?? providerConfig?.options?.baseURL
277
- if (endpoint) {
278
- providerOptions.baseURL = endpoint
279
- }
280
-
281
- return {
282
- autoload: true,
283
- options: providerOptions,
284
- async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
285
- // Skip region prefixing if model already has a cross-region inference profile prefix
286
- if (modelID.startsWith("global.") || modelID.startsWith("jp.")) {
287
- return sdk.languageModel(modelID)
288
- }
289
-
290
- // Region resolution precedence (highest to lowest):
291
- // 1. options.region from opencode.json provider config
292
- // 2. defaultRegion from AWS_REGION environment variable
293
- // 3. Default "us-east-1" (baked into defaultRegion)
294
- const region = options?.region ?? defaultRegion
295
-
296
- let regionPrefix = region.split("-")[0]
297
-
298
- switch (regionPrefix) {
299
- case "us": {
300
- const modelRequiresPrefix = [
301
- "nova-micro",
302
- "nova-lite",
303
- "nova-pro",
304
- "nova-premier",
305
- "nova-2",
306
- "claude",
307
- "deepseek",
308
- ].some((m) => modelID.includes(m))
309
- const isGovCloud = region.startsWith("us-gov")
310
- if (modelRequiresPrefix && !isGovCloud) {
311
- modelID = `${regionPrefix}.${modelID}`
312
- }
313
- break
314
- }
315
- case "eu": {
316
- const regionRequiresPrefix = [
317
- "eu-west-1",
318
- "eu-west-2",
319
- "eu-west-3",
320
- "eu-north-1",
321
- "eu-central-1",
322
- "eu-south-1",
323
- "eu-south-2",
324
- ].some((r) => region.includes(r))
325
- const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "llama3", "pixtral"].some((m) =>
326
- modelID.includes(m),
327
- )
328
- if (regionRequiresPrefix && modelRequiresPrefix) {
329
- modelID = `${regionPrefix}.${modelID}`
330
- }
331
- break
332
- }
333
- case "ap": {
334
- const isAustraliaRegion = ["ap-southeast-2", "ap-southeast-4"].includes(region)
335
- const isTokyoRegion = region === "ap-northeast-1"
336
- if (
337
- isAustraliaRegion &&
338
- ["anthropic.claude-sonnet-4-5", "anthropic.claude-haiku"].some((m) => modelID.includes(m))
339
- ) {
340
- regionPrefix = "au"
341
- modelID = `${regionPrefix}.${modelID}`
342
- } else if (isTokyoRegion) {
343
- // Tokyo region uses jp. prefix for cross-region inference
344
- const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
345
- modelID.includes(m),
346
- )
347
- if (modelRequiresPrefix) {
348
- regionPrefix = "jp"
349
- modelID = `${regionPrefix}.${modelID}`
350
- }
351
- } else {
352
- // Other APAC regions use apac. prefix
353
- const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
354
- modelID.includes(m),
355
- )
356
- if (modelRequiresPrefix) {
357
- regionPrefix = "apac"
358
- modelID = `${regionPrefix}.${modelID}`
359
- }
360
- }
361
- break
362
- }
363
- }
364
-
365
- return sdk.languageModel(modelID)
366
- },
367
- }
368
- },
369
- openrouter: async () => {
370
- return {
371
- autoload: false,
372
- options: {
373
- headers: {
374
- "HTTP-Referer": "https://eliseart.ai/",
375
- "X-Title": "opencode",
376
- },
377
- },
378
- }
379
- },
380
- vercel: async () => {
381
- return {
382
- autoload: false,
383
- options: {
384
- headers: {
385
- "http-referer": "https://eliseart.ai/",
386
- "x-title": "opencode",
387
- },
388
- },
389
- }
390
- },
391
- "google-vertex": async () => {
392
- const project = Env.get("GOOGLE_CLOUD_PROJECT") ?? Env.get("GCP_PROJECT") ?? Env.get("GCLOUD_PROJECT")
393
- const location = Env.get("GOOGLE_CLOUD_LOCATION") ?? Env.get("VERTEX_LOCATION") ?? "us-east5"
394
- const autoload = Boolean(project)
395
- if (!autoload) return { autoload: false }
396
- return {
397
- autoload: true,
398
- options: {
399
- project,
400
- location,
401
- },
402
- async getModel(sdk: any, modelID: string) {
403
- const id = String(modelID).trim()
404
- return sdk.languageModel(id)
405
- },
406
- }
407
- },
408
- "google-vertex-anthropic": async () => {
409
- const project = Env.get("GOOGLE_CLOUD_PROJECT") ?? Env.get("GCP_PROJECT") ?? Env.get("GCLOUD_PROJECT")
410
- const location = Env.get("GOOGLE_CLOUD_LOCATION") ?? Env.get("VERTEX_LOCATION") ?? "global"
411
- const autoload = Boolean(project)
412
- if (!autoload) return { autoload: false }
413
- return {
414
- autoload: true,
415
- options: {
416
- project,
417
- location,
418
- },
419
- async getModel(sdk: any, modelID) {
420
- const id = String(modelID).trim()
421
- return sdk.languageModel(id)
422
- },
423
- }
424
- },
425
- "sap-ai-core": async () => {
426
- const auth = await Auth.get("sap-ai-core")
427
- const envServiceKey = iife(() => {
428
- const envAICoreServiceKey = Env.get("AICORE_SERVICE_KEY")
429
- if (envAICoreServiceKey) return envAICoreServiceKey
430
- if (auth?.type === "api") {
431
- Env.set("AICORE_SERVICE_KEY", auth.key)
432
- return auth.key
433
- }
434
- return undefined
435
- })
436
- const deploymentId = Env.get("AICORE_DEPLOYMENT_ID")
437
- const resourceGroup = Env.get("AICORE_RESOURCE_GROUP")
438
-
439
- return {
440
- autoload: !!envServiceKey,
441
- options: envServiceKey ? { deploymentId, resourceGroup } : {},
442
- async getModel(sdk: any, modelID: string) {
443
- return sdk(modelID)
444
- },
445
- }
446
- },
447
- zenmux: async () => {
448
- return {
449
- autoload: false,
450
- options: {
451
- headers: {
452
- "HTTP-Referer": "https://eliseart.ai/",
453
- "X-Title": "opencode",
454
- },
455
- },
456
- }
457
- },
458
- gitlab: async (input) => {
459
- const instanceUrl = Env.get("GITLAB_INSTANCE_URL") || "https://gitlab.com"
460
-
461
- const auth = await Auth.get(input.id)
462
- const apiKey = await (async () => {
463
- if (auth?.type === "oauth") return auth.access
464
- if (auth?.type === "api") return auth.key
465
- return Env.get("GITLAB_TOKEN")
466
- })()
467
-
468
- const config = await Config.get()
469
- const providerConfig = config.provider?.["gitlab"]
470
-
471
- return {
472
- autoload: !!apiKey,
473
- options: {
474
- instanceUrl,
475
- apiKey,
476
- featureFlags: {
477
- duo_agent_platform_agentic_chat: true,
478
- duo_agent_platform: true,
479
- ...(providerConfig?.options?.featureFlags || {}),
480
- },
481
- },
482
- async getModel(sdk: ReturnType<typeof createGitLab>, modelID: string) {
483
- return sdk.agenticChat(modelID, {
484
- featureFlags: {
485
- duo_agent_platform_agentic_chat: true,
486
- duo_agent_platform: true,
487
- ...(providerConfig?.options?.featureFlags || {}),
488
- },
489
- })
490
- },
491
- }
492
- },
493
- "cloudflare-ai-gateway": async (input) => {
494
- const accountId = Env.get("CLOUDFLARE_ACCOUNT_ID")
495
- const gateway = Env.get("CLOUDFLARE_GATEWAY_ID")
496
-
497
- if (!accountId || !gateway) return { autoload: false }
498
-
499
- // Get API token from env or auth prompt
500
- const apiToken = await (async () => {
501
- const envToken = Env.get("CLOUDFLARE_API_TOKEN")
502
- if (envToken) return envToken
503
- const auth = await Auth.get(input.id)
504
- if (auth?.type === "api") return auth.key
505
- return undefined
506
- })()
507
-
508
- return {
509
- autoload: true,
510
- async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
511
- return sdk.languageModel(modelID)
512
- },
513
- options: {
514
- baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gateway}/compat`,
515
- headers: {
516
- // Cloudflare AI Gateway uses cf-aig-authorization for authenticated gateways
517
- // This enables Unified Billing where Cloudflare handles upstream provider auth
518
- ...(apiToken ? { "cf-aig-authorization": `Bearer ${apiToken}` } : {}),
519
- "HTTP-Referer": "https://eliseart.ai/",
520
- "X-Title": "opencode",
521
- },
522
- // Custom fetch to handle parameter transformation and auth
523
- fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
524
- const headers = new Headers(init?.headers)
525
- // Strip Authorization header - AI Gateway uses cf-aig-authorization instead
526
- headers.delete("Authorization")
527
-
528
- /*
529
- console.log(`\x1b[36m│\x1b[0m Plan: ${plan.toUpperCase().padEnd(22)} \x1b[36m│\x1b[0m`)
530
- const formattedBalance = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(aiCredits)
531
- console.log(`\x1b[36m│\x1b[0m AI Balance: ${formattedBalance.padEnd(22)} \x1b[36m│\x1b[0m`)
532
- if (planExpiresAt) {
533
- const expires = new Date(planExpiresAt).toLocaleDateString()
534
- console.log(`\x1b[36m│\x1b[0m Renews: ${expires.padEnd(22)} \x1b[36m│\x1b[0m`)
535
- }
536
- */
537
-
538
- // Transform max_tokens to max_completion_tokens for newer models
539
- if (init?.body && init.method === "POST") {
540
- try {
541
- const body = JSON.parse(init.body as string)
542
- if (body.max_tokens !== undefined && !body.max_completion_tokens) {
543
- body.max_completion_tokens = body.max_tokens
544
- delete body.max_tokens
545
- init = { ...init, body: JSON.stringify(body) }
546
- }
547
- } catch (e) {
548
- // If body parsing fails, continue with original request
549
- }
550
- }
551
-
552
- return fetch(input, { ...init, headers })
553
- },
554
- },
555
- }
556
- },
557
- cerebras: async () => {
558
- return {
559
- autoload: false,
560
- options: {
561
- headers: {
562
- "X-Cerebras-3rd-Party-Integration": "opencode",
563
- },
564
- },
565
- }
566
- },
567
- }
568
-
569
- export const Model = z
570
- .object({
571
- id: z.string(),
572
- providerID: z.string(),
573
- api: z.object({
574
- id: z.string(),
575
- url: z.string(),
576
- npm: z.string(),
577
- }),
578
- name: z.string(),
579
- family: z.string().optional(),
580
- capabilities: z.object({
581
- temperature: z.boolean(),
582
- reasoning: z.boolean(),
583
- attachment: z.boolean(),
584
- toolcall: z.boolean(),
585
- input: z.object({
586
- text: z.boolean(),
587
- audio: z.boolean(),
588
- image: z.boolean(),
589
- video: z.boolean(),
590
- pdf: z.boolean(),
591
- }),
592
- output: z.object({
593
- text: z.boolean(),
594
- audio: z.boolean(),
595
- image: z.boolean(),
596
- video: z.boolean(),
597
- pdf: z.boolean(),
598
- }),
599
- interleaved: z.union([
600
- z.boolean(),
601
- z.object({
602
- field: z.enum(["reasoning_content", "reasoning_details"]),
603
- }),
604
- ]),
605
- }),
606
- cost: z.object({
607
- input: z.number(),
608
- output: z.number(),
609
- cache: z.object({
610
- read: z.number(),
611
- write: z.number(),
612
- }),
613
- experimentalOver200K: z
614
- .object({
615
- input: z.number(),
616
- output: z.number(),
617
- cache: z.object({
618
- read: z.number(),
619
- write: z.number(),
620
- }),
621
- })
622
- .optional(),
623
- }),
624
- limit: z.object({
625
- context: z.number(),
626
- input: z.number().optional(),
627
- output: z.number(),
628
- }),
629
- status: z.enum(["alpha", "beta", "deprecated", "active"]),
630
- options: z.record(z.string(), z.any()),
631
- headers: z.record(z.string(), z.string()),
632
- release_date: z.string(),
633
- variants: z.record(z.string(), z.record(z.string(), z.any())).optional(),
634
- })
635
- .meta({
636
- ref: "Model",
637
- })
638
- export type Model = z.infer<typeof Model>
639
-
640
- export const Info = z
641
- .object({
642
- id: z.string(),
643
- name: z.string(),
644
- source: z.enum(["env", "config", "custom", "api"]),
645
- env: z.string().array(),
646
- key: z.string().optional(),
647
- options: z.record(z.string(), z.any()),
648
- models: z.record(z.string(), Model),
649
- })
650
- .meta({
651
- ref: "Provider",
652
- })
653
- export type Info = z.infer<typeof Info>
654
-
655
- function fromModelsDevModel(provider: ModelsDev.Provider, model: ModelsDev.Model): Model {
656
- const m: Model = {
657
- id: model.id,
658
- providerID: provider.id,
659
- name: model.name,
660
- family: model.family,
661
- api: {
662
- id: model.id,
663
- url: provider.api!,
664
- npm: iife(() => {
665
- if (provider.id.startsWith("github-copilot")) return "@ai-sdk/github-copilot"
666
- return model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible"
667
- }),
668
- },
669
- status: model.status ?? "active",
670
- headers: model.headers ?? {},
671
- options: model.options ?? {},
672
- cost: {
673
- input: model.cost?.input ?? 0,
674
- output: model.cost?.output ?? 0,
675
- cache: {
676
- read: model.cost?.cache_read ?? 0,
677
- write: model.cost?.cache_write ?? 0,
678
- },
679
- experimentalOver200K: model.cost?.context_over_200k
680
- ? {
681
- cache: {
682
- read: model.cost.context_over_200k.cache_read ?? 0,
683
- write: model.cost.context_over_200k.cache_write ?? 0,
684
- },
685
- input: model.cost.context_over_200k.input,
686
- output: model.cost.context_over_200k.output,
687
- }
688
- : undefined,
689
- },
690
- limit: {
691
- context: model.limit.context,
692
- input: model.limit.input,
693
- output: model.limit.output,
694
- },
695
- capabilities: {
696
- temperature: model.temperature,
697
- reasoning: model.reasoning,
698
- attachment: model.attachment,
699
- toolcall: model.tool_call,
700
- input: {
701
- text: model.modalities?.input?.includes("text") ?? false,
702
- audio: model.modalities?.input?.includes("audio") ?? false,
703
- image: model.modalities?.input?.includes("image") ?? false,
704
- video: model.modalities?.input?.includes("video") ?? false,
705
- pdf: model.modalities?.input?.includes("pdf") ?? false,
706
- },
707
- output: {
708
- text: model.modalities?.output?.includes("text") ?? false,
709
- audio: model.modalities?.output?.includes("audio") ?? false,
710
- image: model.modalities?.output?.includes("image") ?? false,
711
- video: model.modalities?.output?.includes("video") ?? false,
712
- pdf: model.modalities?.output?.includes("pdf") ?? false,
713
- },
714
- interleaved: model.interleaved ?? false,
715
- },
716
- release_date: model.release_date,
717
- variants: {},
718
- }
719
-
720
- m.variants = mapValues(ProviderTransform.variants(m), (v) => v)
721
-
722
- return m
723
- }
724
-
725
- export function fromModelsDevProvider(provider: ModelsDev.Provider): Info {
726
- return {
727
- id: provider.id,
728
- source: "custom",
729
- name: provider.name,
730
- env: provider.env ?? [],
731
- options: {},
732
- models: mapValues(provider.models, (model) => fromModelsDevModel(provider, model)),
733
- }
734
- }
735
-
736
- const state = Instance.state(async () => {
737
- using _ = log.time("state")
738
- const config = await Config.get()
739
- const modelsDev = await ModelsDev.get()
740
- const database = mapValues(modelsDev, fromModelsDevProvider)
741
-
742
- // Manually inject EliseArt provider and models
743
- const eliseartBaseModel = (id: string, name: string, options: Partial<Model> = {}): Model => ({
744
- id,
745
- providerID: "eliseart",
746
- name,
747
- api: {
748
- id,
749
- url: `${ELISEART_SUPABASE_URL}/functions/v1/chat-completion`,
750
- npm: "@ai-sdk/openai-compatible",
751
- },
752
- status: "active",
753
- headers: {},
754
- options: {},
755
- cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
756
- limit: { context: 128000, output: 4096 },
757
- capabilities: {
758
- temperature: true,
759
- reasoning: false,
760
- attachment: false,
761
- toolcall: true,
762
- input: { text: true, audio: false, image: false, video: false, pdf: false },
763
- output: { text: true, audio: false, image: false, video: false, pdf: false },
764
- interleaved: false,
765
- },
766
- release_date: new Date().toISOString(),
767
- variants: {},
768
- ...options,
769
- });
770
-
771
- database["eliseart"] = {
772
- id: "eliseart",
773
- name: "EliseArt",
774
- source: "custom",
775
- env: [],
776
- options: {},
777
- models: {
778
- // Free tier models (low cost)
779
- "meta-llama/llama-3.2-3b-instruct:free": eliseartBaseModel(
780
- "meta-llama/llama-3.2-3b-instruct:free",
781
- "Llama 3.2 3B (Free)",
782
- { cost: { input: 0.015, output: 0.06, cache: { read: 0, write: 0 } } }
783
- ),
784
- "google/gemini-2.0-flash-exp:free": eliseartBaseModel(
785
- "google/gemini-2.0-flash-exp:free",
786
- "Gemini 2.0 Flash (Free)",
787
- {
788
- cost: { input: 0.135, output: 0.54, cache: { read: 0, write: 0 } },
789
- capabilities: { temperature: true, reasoning: false, attachment: true, toolcall: true, input: { text: true, audio: false, image: true, video: false, pdf: false }, output: { text: true, audio: false, image: false, video: false, pdf: false }, interleaved: false }
790
- }
791
- ),
792
- "cognitivecomputations/dolphin-mistral-24b-venice-edition:free": eliseartBaseModel(
793
- "cognitivecomputations/dolphin-mistral-24b-venice-edition:free",
794
- "Dolphin Mistral 24B (Free)",
795
- { cost: { input: 0.10, output: 0.40, cache: { read: 0, write: 0 } } }
796
- ),
797
- "z-ai/glm-4.5-air:free": eliseartBaseModel(
798
- "z-ai/glm-4.5-air:free",
799
- "GLM 4.5 Air (Free)",
800
- { cost: { input: 0.25, output: 1.50, cache: { read: 0, write: 0 } } }
801
- ),
802
- "deepseek/deepseek-chat:free": eliseartBaseModel(
803
- "deepseek/deepseek-chat:free",
804
- "DeepSeek Chat (Free)",
805
- { cost: { input: 0.54, output: 1.53, cache: { read: 0, write: 0 } } }
806
- ),
807
- "mistralai/mistral-7b-instruct:free": eliseartBaseModel(
808
- "mistralai/mistral-7b-instruct:free",
809
- "Mistral 7B (Free)",
810
- { cost: { input: 0.025, output: 0.10, cache: { read: 0, write: 0 } } }
811
- ),
812
- "google/gemma-2-9b-it:free": eliseartBaseModel(
813
- "google/gemma-2-9b-it:free",
814
- "Gemma 2 9B (Free)",
815
- { cost: { input: 0.025, output: 0.10, cache: { read: 0, write: 0 } } }
816
- ),
817
- "gryphe/mythomax-l2-13b:free": eliseartBaseModel(
818
- "gryphe/mythomax-l2-13b:free",
819
- "MythoMax 13B (Free)",
820
- { cost: { input: 0.05, output: 0.20, cache: { read: 0, write: 0 } } }
821
- ),
822
- "qwen/qwen-2.5-coder-32b-instruct:free": eliseartBaseModel(
823
- "qwen/qwen-2.5-coder-32b-instruct:free",
824
- "Qwen 2.5 Coder 32B (Free)",
825
- { cost: { input: 0.165, output: 1.35, cache: { read: 0, write: 0 } } }
826
- ),
827
- "mistralai/pixtral-large-2411:free": eliseartBaseModel(
828
- "mistralai/pixtral-large-2411:free",
829
- "Pixtral Large (Free)",
830
- {
831
- cost: { input: 0.20, output: 1.20, cache: { read: 0, write: 0 } },
832
- capabilities: { temperature: true, reasoning: false, attachment: true, toolcall: true, input: { text: true, audio: false, image: true, video: false, pdf: false }, output: { text: true, audio: false, image: false, video: false, pdf: false }, interleaved: false }
833
- }
834
- ),
835
- "mistralai/codestral-2501:free": eliseartBaseModel(
836
- "mistralai/codestral-2501:free",
837
- "Codestral (Free)",
838
- { cost: { input: 0.30, output: 0.90, cache: { read: 0, write: 0 } } }
839
- ),
840
- "meta-llama/llama-3.3-70b-instruct:free": eliseartBaseModel(
841
- "meta-llama/llama-3.3-70b-instruct:free",
842
- "Llama 3.3 70B (Free)",
843
- { cost: { input: 0.50, output: 2.00, cache: { read: 0, write: 0 } } }
844
- ),
845
- // Premium MaaS models via Vertex AI
846
- "google/gemini-3-pro-preview": eliseartBaseModel(
847
- "google/gemini-3-pro-preview",
848
- "Gemini 3 Pro Preview",
849
- {
850
- cost: { input: 1.80, output: 10.80, cache: { read: 0, write: 0 } },
851
- limit: { context: 1000000, output: 65536 },
852
- capabilities: { temperature: true, reasoning: true, attachment: true, toolcall: true, input: { text: true, audio: false, image: true, video: true, pdf: true }, output: { text: true, audio: false, image: false, video: false, pdf: false }, interleaved: false }
853
- }
854
- ),
855
- "zai-org/glm-4.7-maas": eliseartBaseModel(
856
- "zai-org/glm-4.7-maas",
857
- "GLM 4.7 (MaaS)",
858
- { cost: { input: 0.25, output: 1.50, cache: { read: 0, write: 0 } } }
859
- ),
860
- "moonshotai/kimi-k2-thinking-maas": eliseartBaseModel(
861
- "moonshotai/kimi-k2-thinking-maas",
862
- "Kimi K2 Thinking (MaaS)",
863
- {
864
- cost: { input: 1.00, output: 5.00, cache: { read: 0, write: 0 } },
865
- capabilities: { temperature: true, reasoning: true, attachment: false, toolcall: true, input: { text: true, audio: false, image: false, video: false, pdf: false }, output: { text: true, audio: false, image: false, video: false, pdf: false }, interleaved: false }
866
- }
867
- ),
868
- "deepseek-ai/deepseek-v3.2-maas": eliseartBaseModel(
869
- "deepseek-ai/deepseek-v3.2-maas",
870
- "DeepSeek V3.2 (MaaS)",
871
- {
872
- cost: { input: 0.54, output: 1.53, cache: { read: 0, write: 0 } },
873
- capabilities: { temperature: true, reasoning: true, attachment: false, toolcall: true, input: { text: true, audio: false, image: false, video: false, pdf: false }, output: { text: true, audio: false, image: false, video: false, pdf: false }, interleaved: false }
874
- }
875
- ),
876
- "openai/gpt-oss-120b-maas": eliseartBaseModel(
877
- "openai/gpt-oss-120b-maas",
878
- "GPT OSS 120B (MaaS)",
879
- { cost: { input: 1.00, output: 3.00, cache: { read: 0, write: 0 } } }
880
- ),
881
- "meta/llama-3.1-405b-instruct-maas": eliseartBaseModel(
882
- "meta/llama-3.1-405b-instruct-maas",
883
- "Llama 3.1 405B (MaaS)",
884
- {
885
- cost: { input: 4.50, output: 14.40, cache: { read: 0, write: 0 } },
886
- limit: { context: 128000, output: 4096 }
887
- }
888
- ),
889
- }
890
- }
891
-
892
- const disabled = new Set(config.disabled_providers ?? [])
893
- const enabled = config.enabled_providers ? new Set(config.enabled_providers) : null
894
-
895
- function isProviderAllowed(providerID: string): boolean {
896
- if (enabled && !enabled.has(providerID)) return false
897
- if (disabled.has(providerID)) return false
898
- return true
899
- }
900
-
901
- const providers: { [providerID: string]: Info } = {}
902
- const languages = new Map<string, LanguageModelV2>()
903
- const modelLoaders: {
904
- [providerID: string]: CustomModelLoader
905
- } = {}
906
- const sdk = new Map<number, SDK>()
907
-
908
- log.info("init")
909
-
910
- const configProviders = Object.entries(config.provider ?? {})
911
-
912
- // Add GitHub Copilot Enterprise provider that inherits from GitHub Copilot
913
- if (database["github-copilot"]) {
914
- const githubCopilot = database["github-copilot"]
915
- database["github-copilot-enterprise"] = {
916
- ...githubCopilot,
917
- id: "github-copilot-enterprise",
918
- name: "GitHub Copilot Enterprise",
919
- models: mapValues(githubCopilot.models, (model) => ({
920
- ...model,
921
- providerID: "github-copilot-enterprise",
922
- })),
923
- }
924
- }
925
-
926
- function mergeProvider(providerID: string, provider: Partial<Info>) {
927
- const existing = providers[providerID]
928
- if (existing) {
929
- // @ts-expect-error
930
- providers[providerID] = mergeDeep(existing, provider)
931
- return
932
- }
933
- const match = database[providerID]
934
- if (!match) return
935
- // @ts-expect-error
936
- providers[providerID] = mergeDeep(match, provider)
937
- }
938
-
939
- // extend database from config
940
- for (const [providerID, provider] of configProviders) {
941
- const existing = database[providerID]
942
- const parsed: Info = {
943
- id: providerID,
944
- name: provider.name ?? existing?.name ?? providerID,
945
- env: provider.env ?? existing?.env ?? [],
946
- options: mergeDeep(existing?.options ?? {}, provider.options ?? {}),
947
- source: "config",
948
- models: existing?.models ?? {},
949
- }
950
-
951
- for (const [modelID, model] of Object.entries(provider.models ?? {})) {
952
- const existingModel = parsed.models[model.id ?? modelID]
953
- const name = iife(() => {
954
- if (model.name) return model.name
955
- if (model.id && model.id !== modelID) return modelID
956
- return existingModel?.name ?? modelID
957
- })
958
- const parsedModel: Model = {
959
- id: modelID,
960
- api: {
961
- id: model.id ?? existingModel?.api.id ?? modelID,
962
- npm:
963
- model.provider?.npm ??
964
- provider.npm ??
965
- existingModel?.api.npm ??
966
- modelsDev[providerID]?.npm ??
967
- "@ai-sdk/openai-compatible",
968
- url: provider?.api ?? existingModel?.api.url ?? modelsDev[providerID]?.api,
969
- },
970
- status: model.status ?? existingModel?.status ?? "active",
971
- name,
972
- providerID,
973
- capabilities: {
974
- temperature: model.temperature ?? existingModel?.capabilities.temperature ?? false,
975
- reasoning: model.reasoning ?? existingModel?.capabilities.reasoning ?? false,
976
- attachment: model.attachment ?? existingModel?.capabilities.attachment ?? false,
977
- toolcall: model.tool_call ?? existingModel?.capabilities.toolcall ?? true,
978
- input: {
979
- text: model.modalities?.input?.includes("text") ?? existingModel?.capabilities.input.text ?? true,
980
- audio: model.modalities?.input?.includes("audio") ?? existingModel?.capabilities.input.audio ?? false,
981
- image: model.modalities?.input?.includes("image") ?? existingModel?.capabilities.input.image ?? false,
982
- video: model.modalities?.input?.includes("video") ?? existingModel?.capabilities.input.video ?? false,
983
- pdf: model.modalities?.input?.includes("pdf") ?? existingModel?.capabilities.input.pdf ?? false,
984
- },
985
- output: {
986
- text: model.modalities?.output?.includes("text") ?? existingModel?.capabilities.output.text ?? true,
987
- audio: model.modalities?.output?.includes("audio") ?? existingModel?.capabilities.output.audio ?? false,
988
- image: model.modalities?.output?.includes("image") ?? existingModel?.capabilities.output.image ?? false,
989
- video: model.modalities?.output?.includes("video") ?? existingModel?.capabilities.output.video ?? false,
990
- pdf: model.modalities?.output?.includes("pdf") ?? existingModel?.capabilities.output.pdf ?? false,
991
- },
992
- interleaved: model.interleaved ?? false,
993
- },
994
- cost: {
995
- input: model?.cost?.input ?? existingModel?.cost?.input ?? 0,
996
- output: model?.cost?.output ?? existingModel?.cost?.output ?? 0,
997
- cache: {
998
- read: model?.cost?.cache_read ?? existingModel?.cost?.cache.read ?? 0,
999
- write: model?.cost?.cache_write ?? existingModel?.cost?.cache.write ?? 0,
1000
- },
1001
- },
1002
- options: mergeDeep(existingModel?.options ?? {}, model.options ?? {}),
1003
- limit: {
1004
- context: model.limit?.context ?? existingModel?.limit?.context ?? 0,
1005
- output: model.limit?.output ?? existingModel?.limit?.output ?? 0,
1006
- },
1007
- headers: mergeDeep(existingModel?.headers ?? {}, model.headers ?? {}),
1008
- family: model.family ?? existingModel?.family ?? "",
1009
- release_date: model.release_date ?? existingModel?.release_date ?? "",
1010
- variants: {},
1011
- }
1012
- const merged = mergeDeep(ProviderTransform.variants(parsedModel), model.variants ?? {})
1013
- parsedModel.variants = mapValues(
1014
- pickBy(merged, (v) => !v.disabled),
1015
- (v) => omit(v, ["disabled"]),
1016
- )
1017
- parsed.models[modelID] = parsedModel
1018
- }
1019
- database[providerID] = parsed
1020
- }
1021
-
1022
- // load env
1023
- const env = Env.all()
1024
- for (const [providerID, provider] of Object.entries(database)) {
1025
- if (disabled.has(providerID)) continue
1026
- const apiKey = provider.env.map((item) => env[item]).find(Boolean)
1027
- if (!apiKey) continue
1028
- mergeProvider(providerID, {
1029
- source: "env",
1030
- key: provider.env.length === 1 ? apiKey : undefined,
1031
- })
1032
- }
1033
-
1034
- // load apikeys
1035
- for (const [providerID, provider] of Object.entries(await Auth.all())) {
1036
- if (disabled.has(providerID)) continue
1037
- if (provider.type === "api") {
1038
- mergeProvider(providerID, {
1039
- source: "api",
1040
- key: provider.key,
1041
- })
1042
- }
1043
- }
1044
-
1045
- for (const plugin of await Plugin.list()) {
1046
- if (!plugin.auth) continue
1047
- const providerID = plugin.auth.provider
1048
- if (disabled.has(providerID)) continue
1049
-
1050
- // For github-copilot plugin, check if auth exists for either github-copilot or github-copilot-enterprise
1051
- let hasAuth = false
1052
- const auth = await Auth.get(providerID)
1053
- if (auth) hasAuth = true
1054
-
1055
- // Special handling for github-copilot: also check for enterprise auth
1056
- if (providerID === "github-copilot" && !hasAuth) {
1057
- const enterpriseAuth = await Auth.get("github-copilot-enterprise")
1058
- if (enterpriseAuth) hasAuth = true
1059
- }
1060
-
1061
- if (!hasAuth) continue
1062
- if (!plugin.auth.loader) continue
1063
-
1064
- // Load for the main provider if auth exists
1065
- if (auth) {
1066
- const options = await plugin.auth.loader(() => Auth.get(providerID) as any, database[plugin.auth.provider])
1067
- mergeProvider(plugin.auth.provider, {
1068
- source: "custom",
1069
- options: options,
1070
- })
1071
- }
1072
-
1073
- // If this is github-copilot plugin, also register for github-copilot-enterprise if auth exists
1074
- if (providerID === "github-copilot") {
1075
- const enterpriseProviderID = "github-copilot-enterprise"
1076
- if (!disabled.has(enterpriseProviderID)) {
1077
- const enterpriseAuth = await Auth.get(enterpriseProviderID)
1078
- if (enterpriseAuth) {
1079
- const enterpriseOptions = await plugin.auth.loader(
1080
- () => Auth.get(enterpriseProviderID) as any,
1081
- database[enterpriseProviderID],
1082
- )
1083
- mergeProvider(enterpriseProviderID, {
1084
- source: "custom",
1085
- options: enterpriseOptions,
1086
- })
1087
- }
1088
- }
1089
- }
1090
- }
1091
-
1092
- for (const [providerID, fn] of Object.entries(CUSTOM_LOADERS)) {
1093
- if (disabled.has(providerID)) continue
1094
- const data = database[providerID]
1095
- if (!data) {
1096
- log.error("Provider does not exist in model list " + providerID)
1097
- continue
1098
- }
1099
- const result = await fn(data)
1100
- if (result && (result.autoload || providers[providerID])) {
1101
- if (result.getModel) modelLoaders[providerID] = result.getModel
1102
- mergeProvider(providerID, {
1103
- source: "custom",
1104
- options: result.options,
1105
- })
1106
- }
1107
- }
1108
-
1109
- // load config
1110
- for (const [providerID, provider] of configProviders) {
1111
- const partial: Partial<Info> = { source: "config" }
1112
- if (provider.env) partial.env = provider.env
1113
- if (provider.name) partial.name = provider.name
1114
- if (provider.options) partial.options = provider.options
1115
- mergeProvider(providerID, partial)
1116
- }
1117
-
1118
- for (const [providerID, provider] of Object.entries(providers)) {
1119
- if (!isProviderAllowed(providerID)) {
1120
- delete providers[providerID]
1121
- continue
1122
- }
1123
-
1124
- const configProvider = config.provider?.[providerID]
1125
-
1126
- for (const [modelID, model] of Object.entries(provider.models)) {
1127
- model.api.id = model.api.id ?? model.id ?? modelID
1128
- if (modelID === "gpt-5-chat-latest" || (providerID === "openrouter" && modelID === "openai/gpt-5-chat"))
1129
- delete provider.models[modelID]
1130
- if (model.status === "alpha" && !Flag.EASC_ENABLE_EXPERIMENTAL_MODELS) delete provider.models[modelID]
1131
- if (model.status === "deprecated") delete provider.models[modelID]
1132
- if (
1133
- (configProvider?.blacklist && configProvider.blacklist.includes(modelID)) ||
1134
- (configProvider?.whitelist && !configProvider.whitelist.includes(modelID))
1135
- )
1136
- delete provider.models[modelID]
1137
-
1138
- // Filter out disabled variants from config
1139
- const configVariants = configProvider?.models?.[modelID]?.variants
1140
- if (configVariants && model.variants) {
1141
- const merged = mergeDeep(model.variants, configVariants)
1142
- model.variants = mapValues(
1143
- pickBy(merged, (v) => !v.disabled),
1144
- (v) => omit(v, ["disabled"]),
1145
- )
1146
- }
1147
- }
1148
-
1149
- if (Object.keys(provider.models).length === 0) {
1150
- delete providers[providerID]
1151
- continue
1152
- }
1153
-
1154
- log.info("found", { providerID })
1155
- }
1156
-
1157
- return {
1158
- models: languages,
1159
- providers,
1160
- sdk,
1161
- modelLoaders,
1162
- }
1163
- })
1164
-
1165
- export async function list() {
1166
- return state().then((state) => state.providers)
1167
- }
1168
-
1169
- async function getSDK(model: Model) {
1170
- try {
1171
- using _ = log.time("getSDK", {
1172
- providerID: model.providerID,
1173
- })
1174
- const s = await state()
1175
- const provider = s.providers[model.providerID]
1176
- const options = { ...provider.options }
1177
-
1178
- if (model.api.npm.includes("@ai-sdk/openai-compatible") && options["includeUsage"] !== false) {
1179
- options["includeUsage"] = true
1180
- }
1181
-
1182
- if (!options["baseURL"]) options["baseURL"] = model.api.url
1183
- if (options["apiKey"] === undefined && provider.key) options["apiKey"] = provider.key
1184
- if (model.headers)
1185
- options["headers"] = {
1186
- ...options["headers"],
1187
- ...model.headers,
1188
- }
1189
-
1190
- const key = Bun.hash.xxHash32(JSON.stringify({ npm: model.api.npm, options }))
1191
- const existing = s.sdk.get(key)
1192
- if (existing) return existing
1193
-
1194
- const customFetch = options["fetch"]
1195
-
1196
- options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
1197
- // Preserve custom fetch if it exists, wrap it with timeout logic
1198
- const fetchFn = customFetch ?? fetch
1199
- const opts = init ?? {}
1200
-
1201
- if (options["timeout"] !== undefined && options["timeout"] !== null) {
1202
- const signals: AbortSignal[] = []
1203
- if (opts.signal) signals.push(opts.signal)
1204
- if (options["timeout"] !== false) signals.push(AbortSignal.timeout(options["timeout"]))
1205
-
1206
- const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0]
1207
-
1208
- opts.signal = combined
1209
- }
1210
-
1211
- // Strip openai itemId metadata following what codex does
1212
- // Codex uses #[serde(skip_serializing)] on id fields for all item types:
1213
- // Message, Reasoning, FunctionCall, LocalShellCall, CustomToolCall, WebSearchCall
1214
- // IDs are only re-attached for Azure with store=true
1215
- if (model.api.npm === "@ai-sdk/openai" && opts.body && opts.method === "POST") {
1216
- const body = JSON.parse(opts.body as string)
1217
- const isAzure = model.providerID.includes("azure")
1218
- const keepIds = isAzure && body.store === true
1219
- if (!keepIds && Array.isArray(body.input)) {
1220
- for (const item of body.input) {
1221
- if ("id" in item) {
1222
- delete item.id
1223
- }
1224
- }
1225
- opts.body = JSON.stringify(body)
1226
- }
1227
- }
1228
-
1229
- return fetchFn(input, {
1230
- ...opts,
1231
- // @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
1232
- timeout: false,
1233
- })
1234
- }
1235
-
1236
- // Special case: google-vertex-anthropic uses a subpath import
1237
- const bundledKey =
1238
- model.providerID === "google-vertex-anthropic" ? "@ai-sdk/google-vertex/anthropic" : model.api.npm
1239
- const bundledFn = BUNDLED_PROVIDERS[bundledKey]
1240
- if (bundledFn) {
1241
- log.info("using bundled provider", { providerID: model.providerID, pkg: bundledKey })
1242
- const loaded = bundledFn({
1243
- name: model.providerID,
1244
- ...options,
1245
- })
1246
- s.sdk.set(key, loaded)
1247
- return loaded as SDK
1248
- }
1249
-
1250
- let installedPath: string
1251
- if (!model.api.npm.startsWith("file://")) {
1252
- installedPath = await BunProc.install(model.api.npm, "latest")
1253
- } else {
1254
- log.info("loading local provider", { pkg: model.api.npm })
1255
- installedPath = model.api.npm
1256
- }
1257
-
1258
- const mod = await import(pathToFileURL(installedPath).href)
1259
-
1260
- const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
1261
- const loaded = fn({
1262
- name: model.providerID,
1263
- ...options,
1264
- })
1265
- s.sdk.set(key, loaded)
1266
- return loaded as SDK
1267
- } catch (e) {
1268
- throw new InitError({ providerID: model.providerID }, { cause: e })
1269
- }
1270
- }
1271
-
1272
- export async function getProvider(providerID: string) {
1273
- return state().then((s) => s.providers[providerID])
1274
- }
1275
-
1276
- export async function getModel(providerID: string, modelID: string) {
1277
- const s = await state()
1278
- const provider = s.providers[providerID]
1279
- if (!provider) {
1280
- const availableProviders = Object.keys(s.providers)
1281
- const matches = fuzzysort.go(providerID, availableProviders, { limit: 3, threshold: -10000 })
1282
- const suggestions = matches.map((m) => m.target)
1283
- throw new ModelNotFoundError({ providerID, modelID, suggestions })
1284
- }
1285
-
1286
- const info = provider.models[modelID]
1287
- if (!info) {
1288
- const availableModels = Object.keys(provider.models)
1289
- const matches = fuzzysort.go(modelID, availableModels, { limit: 3, threshold: -10000 })
1290
- const suggestions = matches.map((m) => m.target)
1291
- throw new ModelNotFoundError({ providerID, modelID, suggestions })
1292
- }
1293
- return info
1294
- }
1295
-
1296
- export async function getLanguage(model: Model): Promise<LanguageModelV2> {
1297
- const s = await state()
1298
- const key = `${model.providerID}/${model.id}`
1299
- if (s.models.has(key)) return s.models.get(key)!
1300
-
1301
- const provider = s.providers[model.providerID]
1302
- const sdk = await getSDK(model)
1303
-
1304
- try {
1305
- const language = s.modelLoaders[model.providerID]
1306
- ? await s.modelLoaders[model.providerID](sdk, model.api.id, provider.options)
1307
- : sdk.languageModel(model.api.id)
1308
- s.models.set(key, language)
1309
- return language
1310
- } catch (e) {
1311
- if (e instanceof NoSuchModelError)
1312
- throw new ModelNotFoundError(
1313
- {
1314
- modelID: model.id,
1315
- providerID: model.providerID,
1316
- },
1317
- { cause: e },
1318
- )
1319
- throw e
1320
- }
1321
- }
1322
-
1323
- export async function closest(providerID: string, query: string[]) {
1324
- const s = await state()
1325
- const provider = s.providers[providerID]
1326
- if (!provider) return undefined
1327
- for (const item of query) {
1328
- for (const modelID of Object.keys(provider.models)) {
1329
- if (modelID.includes(item))
1330
- return {
1331
- providerID,
1332
- modelID,
1333
- }
1334
- }
1335
- }
1336
- }
1337
-
1338
- export async function getSmallModel(providerID: string) {
1339
- const cfg = await Config.get()
1340
-
1341
- if (cfg.small_model) {
1342
- const parsed = parseModel(cfg.small_model)
1343
- return getModel(parsed.providerID, parsed.modelID)
1344
- }
1345
-
1346
- const provider = await state().then((state) => state.providers[providerID])
1347
- if (provider) {
1348
- let priority = [
1349
- "gemini-2.0-flash",
1350
- "claude-haiku-4-5",
1351
- "claude-haiku-4.5",
1352
- "3-5-haiku",
1353
- "3.5-haiku",
1354
- "gemini-3-flash",
1355
- "gemini-2.5-flash",
1356
- "gpt-5-nano",
1357
- ]
1358
- if (providerID.startsWith("eliseart")) {
1359
- priority = ["gemini-2.0-flash"]
1360
- }
1361
- if (providerID.startsWith("github-copilot")) {
1362
- // prioritize free models for github copilot
1363
- priority = ["gpt-5-mini", "claude-haiku-4.5", ...priority]
1364
- }
1365
- for (const item of priority) {
1366
- for (const model of Object.keys(provider.models)) {
1367
- if (model.includes(item)) return getModel(providerID, model)
1368
- }
1369
- }
1370
- }
1371
-
1372
- // Check if eliseart provider is available before using it
1373
- const eliseartProvider = await state().then((state) => state.providers["eliseart"])
1374
- if (eliseartProvider && eliseartProvider.models["gemini-2.0-flash"]) {
1375
- return getModel("eliseart", "gemini-2.0-flash")
1376
- }
1377
-
1378
- return undefined
1379
- }
1380
-
1381
- const priority = ["gemini-2.0-flash", "gpt-5", "claude-sonnet-4", "big-pickle", "gemini-3-pro"]
1382
- export function sort(models: Model[]) {
1383
- return sortBy(
1384
- models,
1385
- [(model) => priority.findIndex((filter) => model.id.includes(filter)), "desc"],
1386
- [(model) => (model.id.includes("latest") ? 0 : 1), "asc"],
1387
- [(model) => model.id, "desc"],
1388
- )
1389
- }
1390
-
1391
- export async function defaultModel() {
1392
- const cfg = await Config.get()
1393
- if (cfg.model) return parseModel(cfg.model)
1394
-
1395
- const provider = await list()
1396
- .then((val) => Object.values(val))
1397
- .then((x) => {
1398
- // Favor eliseart as the default provider if available
1399
- const eliseart = x.find((p) => p.id === "eliseart")
1400
- if (eliseart) return eliseart
1401
- return x.find((p) => !cfg.provider || Object.keys(cfg.provider).includes(p.id))
1402
- })
1403
- if (!provider) throw new Error("no providers found")
1404
- const [model] = sort(Object.values(provider.models))
1405
- if (!model) throw new Error("no models found")
1406
- return {
1407
- providerID: provider.id,
1408
- modelID: model.id,
1409
- }
1410
- }
1411
-
1412
- export function parseModel(model: string) {
1413
- const [providerID, ...rest] = model.split("/")
1414
- return {
1415
- providerID: providerID,
1416
- modelID: rest.join("/"),
1417
- }
1418
- }
1419
-
1420
- export const ModelNotFoundError = NamedError.create(
1421
- "ProviderModelNotFoundError",
1422
- z.object({
1423
- providerID: z.string(),
1424
- modelID: z.string(),
1425
- suggestions: z.array(z.string()).optional(),
1426
- }),
1427
- )
1428
-
1429
- export const InitError = NamedError.create(
1430
- "ProviderInitError",
1431
- z.object({
1432
- providerID: z.string(),
1433
- }),
1434
- )
1435
- }