Skip to content

Commit 2c9fd1e

Browse files
committed
BREAKING CHANGE: the config structure has changed, custom providers have an npm field now to specify which npm package to load. see examples in README.md
1 parent 63996c4 commit 2c9fd1e

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ You can use opencode with any provider listed at [here](https://ai-sdk.dev/provi
8484
{
8585
"$schema": "https://opencode.ai/config.json",
8686
"provider": {
87-
"@ai-sdk/openai-compatible": {
88-
"name": "ollama",
87+
"ollama": {
88+
"npm": "@ai-sdk/openai-compatible",
8989
"options": {
9090
"baseURL": "http://localhost:11434/v1"
9191
},
@@ -124,7 +124,8 @@ OpenRouter is not yet in the models.dev database, but you can configure it manua
124124
{
125125
"$schema": "https://opencode.ai/config.json",
126126
"provider": {
127-
"@openrouter/ai-sdk-provider": {
127+
"openrouter": {
128+
"npm": "@openrouter/ai-sdk-provider",
128129
"name": "OpenRouter",
129130
"options": {
130131
"apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

opencode.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "https://opencode.ai/config.json",
33
"provider": {
4-
"@ai-sdk/openai-compatible": {
5-
"name": "ollama",
4+
"ollama": {
5+
"npm": "@ai-sdk/openai-compatible",
66
"options": {
77
"baseURL": "http://localhost:11434/v1"
88
},

packages/opencode/config.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"id": {
2222
"type": "string"
2323
},
24+
"npm": {
25+
"type": "string"
26+
},
2427
"models": {
2528
"type": "object",
2629
"additionalProperties": {

packages/opencode/src/auth/anthropic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { generatePKCE } from "@openauthjs/openauth/pkce"
2-
import fs from "fs/promises"
32
import { Auth } from "./index"
43

54
export namespace AuthAnthropic {

packages/opencode/src/bun/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export namespace BunProc {
4343
version: z.string(),
4444
}),
4545
)
46+
4647
export async function install(pkg: string, version = "latest") {
4748
const mod = path.join(Global.Path.cache, "node_modules", pkg)
4849
const pkgjson = Bun.file(path.join(Global.Path.cache, "package.json"))

packages/opencode/src/cli/cmd/auth.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as prompts from "@clack/prompts"
55
import open from "open"
66
import { UI } from "../ui"
77
import { ModelsDev } from "../../provider/models"
8-
import { map, pipe, sort, sortBy, values } from "remeda"
8+
import { map, pipe, sortBy, values } from "remeda"
99

1010
export const AuthCommand = cmd({
1111
command: "auth",
@@ -16,7 +16,7 @@ export const AuthCommand = cmd({
1616
.command(AuthLogoutCommand)
1717
.command(AuthListCommand)
1818
.demandCommand(),
19-
async handler(args) {},
19+
async handler() {},
2020
})
2121

2222
export const AuthListCommand = cmd({
@@ -78,8 +78,10 @@ export const AuthLoginCommand = cmd({
7878

7979
if (provider === "other") {
8080
provider = await prompts.text({
81-
message: "Enter provider - must match @ai-sdk/<provider>",
81+
message:
82+
"Enter provider - must be package name from https://ai-sdk.dev/providers",
8283
})
84+
provider = provider.replace(/^@ai-sdk\//, "")
8385
if (prompts.isCancel(provider)) throw new UI.CancelledError()
8486
}
8587

@@ -115,7 +117,9 @@ export const AuthLoginCommand = cmd({
115117
try {
116118
await open(url)
117119
} catch (e) {
118-
prompts.log.error("Failed to open browser perhaps you are running without a display or X server, please open the following URL in your browser:")
120+
prompts.log.error(
121+
"Failed to open browser perhaps you are running without a display or X server, please open the following URL in your browser:",
122+
)
119123
}
120124
prompts.log.info(url)
121125

packages/opencode/src/provider/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export namespace ModelsDev {
3636
name: z.string(),
3737
env: z.array(z.string()),
3838
id: z.string(),
39+
npm: z.string().optional(),
3940
models: z.record(Model),
4041
})
4142
.openapi({

packages/opencode/src/provider/provider.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export namespace Provider {
108108
const existing = database[providerID]
109109
const parsed: ModelsDev.Provider = {
110110
id: providerID,
111+
npm: provider.npm ?? existing?.npm,
111112
name: provider.name ?? existing?.name ?? providerID,
112113
env: provider.env ?? existing?.env ?? [],
113114
models: existing?.models ?? {},
@@ -181,22 +182,22 @@ export namespace Provider {
181182
return state().then((state) => state.providers)
182183
}
183184

184-
async function getSDK(providerID: string) {
185+
async function getSDK(provider: ModelsDev.Provider) {
185186
return (async () => {
186187
using _ = log.time("getSDK", {
187-
providerID,
188+
providerID: provider.id,
188189
})
189190
const s = await state()
190-
const existing = s.sdk.get(providerID)
191+
const existing = s.sdk.get(provider.id)
191192
if (existing) return existing
192-
const [pkg, version] = await ModelsDev.pkg(providerID)
193+
const [pkg, version] = await ModelsDev.pkg(provider.npm ?? provider.id)
193194
const mod = await import(await BunProc.install(pkg, version))
194195
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
195-
const loaded = fn(s.providers[providerID]?.options)
196-
s.sdk.set(providerID, loaded)
196+
const loaded = fn(s.providers[provider.id]?.options)
197+
s.sdk.set(provider.id, loaded)
197198
return loaded as SDK
198199
})().catch((e) => {
199-
throw new InitError({ providerID: providerID }, { cause: e })
200+
throw new InitError({ providerID: provider.id }, { cause: e })
200201
})
201202
}
202203

@@ -214,8 +215,7 @@ export namespace Provider {
214215
if (!provider) throw new ModelNotFoundError({ providerID, modelID })
215216
const info = provider.info.models[modelID]
216217
if (!info) throw new ModelNotFoundError({ providerID, modelID })
217-
218-
const sdk = await getSDK(providerID)
218+
const sdk = await getSDK(provider.info)
219219

220220
try {
221221
const language =

0 commit comments

Comments
 (0)