summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-17 12:10:44 -0400
committerDax Raad <[email protected]>2025-06-17 12:10:44 -0400
commitd579c5e8aae4d18b9d6409ebb3ebd40146345d97 (patch)
tree74dcd564da58f537ed6405656d7614480f35486b /packages
parentee91f31313655e8282d4d19b1c67deb249153b5d (diff)
downloadopencode-d579c5e8aae4d18b9d6409ebb3ebd40146345d97.tar.gz
opencode-d579c5e8aae4d18b9d6409ebb3ebd40146345d97.zip
support global config for providers
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/global/index.ts14
-rw-r--r--packages/opencode/src/provider/provider.ts34
2 files changed, 39 insertions, 9 deletions
diff --git a/packages/opencode/src/global/index.ts b/packages/opencode/src/global/index.ts
index e15e0bcc8..50e06548e 100644
--- a/packages/opencode/src/global/index.ts
+++ b/packages/opencode/src/global/index.ts
@@ -8,17 +8,19 @@ const data = path.join(xdgData!, app)
const cache = path.join(xdgCache!, app)
const config = path.join(xdgConfig!, app)
-await Promise.all([
- fs.mkdir(data, { recursive: true }),
- fs.mkdir(config, { recursive: true }),
- fs.mkdir(cache, { recursive: true }),
-])
-
export namespace Global {
export const Path = {
data,
bin: path.join(data, "bin"),
+ providers: path.join(config, "providers"),
cache,
config,
} as const
}
+
+await Promise.all([
+ fs.mkdir(data, { recursive: true }),
+ fs.mkdir(config, { recursive: true }),
+ fs.mkdir(cache, { recursive: true }),
+ fs.mkdir(Global.Path.providers, { recursive: true }),
+])
diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts
index 84d5e31de..975af5e31 100644
--- a/packages/opencode/src/provider/provider.ts
+++ b/packages/opencode/src/provider/provider.ts
@@ -1,4 +1,5 @@
import z from "zod"
+import path from "path"
import { App } from "../app/app"
import { Config } from "../config/config"
import { mergeDeep, sortBy } from "remeda"
@@ -24,6 +25,7 @@ import { NamedError } from "../util/error"
import { Auth } from "../auth"
import { TaskTool } from "../tool/task"
import { GlobalConfig } from "../global/config"
+import { Global } from "../global"
export namespace Provider {
const log = Log.create({ service: "provider" })
@@ -103,9 +105,35 @@ export namespace Provider {
provider.source = source
}
- for (const [providerID, provider] of Object.entries(
- config.provider ?? {},
- )) {
+ const configProviders = Object.entries(config.provider ?? {})
+ for await (const providerPath of new Bun.Glob("*/provider.toml").scan({
+ cwd: Global.Path.providers,
+ })) {
+ const [providerID] = providerPath.split("/")
+ const toml = await import(
+ path.join(Global.Path.providers, providerPath),
+ {
+ with: {
+ type: "toml",
+ },
+ }
+ ).then((mod) => mod.default)
+ toml.models = {}
+ const modelsPath = path.join(Global.Path.providers, providerID, "models")
+ for await (const modelPath of new Bun.Glob("**/*.toml").scan({
+ cwd: modelsPath,
+ })) {
+ const modelID = modelPath.slice(0, -5)
+ toml.models[modelID] = await import(path.join(modelsPath, modelPath), {
+ with: {
+ type: "toml",
+ },
+ })
+ }
+ configProviders.unshift([providerID, toml])
+ }
+
+ for (const [providerID, provider] of configProviders) {
const existing = database[providerID]
const parsed: ModelsDev.Provider = {
id: providerID,