refactor(core): refine provider config schema

This commit is contained in:
Dax Raad 2026-05-28 11:14:53 -04:00
commit a747013bf6
7 changed files with 179 additions and 122 deletions

View file

@ -181,8 +181,7 @@ describe("Config", () => {
variant: "high",
options: {
headers: { "x-agent": "reviewer" },
body: {},
aisdk: { provider: {}, request: { reasoningEffort: "high" } },
aisdk: { request: { reasoningEffort: "high" } },
},
description: "Review changes for correctness",
system: "Find regressions.",
@ -260,8 +259,7 @@ describe("Config", () => {
variant: "high",
options: {
headers: { "x-agent": "reviewer" },
body: {},
aisdk: { provider: {}, request: { reasoningEffort: "high" } },
aisdk: { request: { reasoningEffort: "high" } },
},
description: "Review changes for correctness",
system: "Find regressions.",

View file

@ -2,7 +2,7 @@ import { describe, expect } from "bun:test"
import { Effect, Schema } from "effect"
import { Catalog } from "@opencode-ai/core/catalog"
import { Config } from "@opencode-ai/core/config"
import { ConfigProvider } from "@opencode-ai/core/config/provider"
import { ConfigProviderPlugin } from "@opencode-ai/core/config/plugin/provider"
import { ModelV2 } from "@opencode-ai/core/model"
import { PluginV2 } from "@opencode-ai/core/plugin"
import { ProviderV2 } from "@opencode-ai/core/provider"
@ -11,18 +11,13 @@ import { it } from "../plugin/provider-helper"
function options(headers: Record<string, string>, variant?: string) {
return {
headers,
body: {},
aisdk: {
provider: {},
request: {},
},
variant,
}
}
const decode = Schema.decodeUnknownSync(Config.Info)
describe("ConfigProvider.Plugin", () => {
describe("ConfigProviderPlugin.Plugin", () => {
it.effect("loads configured providers and applies later model overrides", () =>
Effect.gen(function* () {
const catalog = yield* Catalog.Service
@ -39,6 +34,7 @@ describe("ConfigProvider.Plugin", () => {
providers: {
custom: {
name: "Configured",
env: ["CUSTOM_API_KEY"],
endpoint: { type: "unknown" },
options: options({ first: "first", shared: "first" }),
models: {
@ -47,13 +43,12 @@ describe("ConfigProvider.Plugin", () => {
capabilities: { tools: true, input: ["text"], output: ["text"] },
disabled: true,
limit: { context: 100, output: 50 },
cost: { input: 1, output: 2 },
options: options({ first: "first", shared: "first" }, "retained"),
variants: [
{
id: "fast",
headers: { first: "first", shared: "first" },
body: {},
aisdk: { provider: {}, request: {} },
},
],
},
@ -71,21 +66,18 @@ describe("ConfigProvider.Plugin", () => {
options: options({ last: "last", shared: "last" }),
models: {
chat: {
apiID: "api-chat",
api_id: "api-chat",
name: "Last",
limit: { output: 75 },
options: options({ last: "last", shared: "last" }),
variants: [
{
id: "fast",
headers: { last: "last", shared: "last" },
body: {},
aisdk: { provider: {}, request: {} },
},
{
id: "slow",
headers: { slow: "slow" },
body: {},
aisdk: { provider: {}, request: {} },
},
],
},
@ -106,8 +98,8 @@ describe("ConfigProvider.Plugin", () => {
})
yield* plugin.add({
...ConfigProvider.Plugin,
effect: ConfigProvider.Plugin.effect.pipe(
...ConfigProviderPlugin.Plugin,
effect: ConfigProviderPlugin.Plugin.effect.pipe(
Effect.provideService(Config.Service, config),
Effect.provideService(Catalog.Service, catalog),
),
@ -116,6 +108,7 @@ describe("ConfigProvider.Plugin", () => {
const provider = yield* catalog.provider.get(providerID)
const model = yield* catalog.model.get(providerID, modelID)
expect(provider.name).toBe("Renamed")
expect(provider.env).toEqual(["CUSTOM_API_KEY"])
expect(provider.enabled).toEqual({ via: "custom", data: {} })
expect(provider.endpoint).toEqual({ type: "aisdk", package: "custom-sdk", url: "https://example.test" })
expect(provider.options.headers).toEqual({ first: "first", shared: "last", last: "last" })
@ -123,7 +116,8 @@ describe("ConfigProvider.Plugin", () => {
expect(model.name).toBe("Last")
expect(model.capabilities).toEqual({ tools: true, input: ["text"], output: ["text"] })
expect(model.enabled).toBe(false)
expect(model.limit).toEqual({ context: 100, output: 50 })
expect(model.limit).toEqual({ context: 100, output: 75 })
expect(model.cost).toEqual([{ input: 1, output: 2, cache: { read: 0, write: 0 }, tier: undefined }])
expect(model.options.headers).toEqual({ first: "first", shared: "last", last: "last" })
expect(model.options.variant).toBe("retained")
expect(model.variants.map((variant) => variant.id)).toEqual([