|
|
@@ -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,
|