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