fix(core): build provider variants after package normalization (#57075)

This commit is contained in:
Victor Navarro
2026-10-20 14:55:22 +02:00
committed by GitHub
Unverified
parent 81b2d7a1b9
commit e9ac459c2e
4 changed files with 98 additions and 2 deletions
@@ -131,6 +131,9 @@ export const Plugin = define({
if (config.capabilities !== undefined)
model.capabilities = Model.mergeCapabilities(config.capabilities, model.capabilities)
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
})
// Variants are spelled for the final package, which the update above normalizes from `aisdk:*`.
models.update(providerID, id, (model) => {
// Configured reasoning replaces the base variants; configured variants still overlay them below.
if (config.capabilities?.reasoning !== undefined)
model.variants = [
@@ -302,6 +302,9 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
model.headers = Provider.mergeHeaders(model.headers, config.headers)
model.body = Provider.mergeOverlay(model.body, config.body)
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
})
// Variants are spelled for the final package, which the update above normalizes from `aisdk:*`.
providers.models.update(providerID, modelID, (model) => {
// The Console's reasoning replaces the base variants; its variants still overlay them below.
if (config.capabilities?.reasoning !== undefined)
model.variants = [
+46 -1
View File
@@ -787,7 +787,7 @@ describe("ConfigProviderPlugin.Plugin", () => {
}),
)
it.effect("builds variants from configured reasoning and overlays configured variants", () =>
it.effect("builds configured reasoning variants after provider and model package normalization", () =>
Effect.gen(function* () {
const models = yield* Model.Service
const providerID = Provider.ID.make("custom")
@@ -803,6 +803,24 @@ describe("ConfigProviderPlugin.Plugin", () => {
capabilities: { reasoning: { supported: true, effort: ["default", "low", "high"] } },
variants: [{ id: "high", headers: { "x-tier": "high" } }],
},
gpt: {
package: "aisdk:@ai-sdk/openai",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
variants: [{ id: "high", headers: { "x-tier": "high" } }],
},
"claude-sonnet-4-5": {
package: "aisdk:@ai-sdk/anthropic",
capabilities: { reasoning: { supported: true, budget: { min: 1024 } } },
limit: { output: 64_000 },
},
"gemini-3.1-pro": {
package: "aisdk:@ai-sdk/google",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
},
"magistral-medium": {
package: "aisdk:@ai-sdk/mistral",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
},
fixed: { capabilities: { reasoning: { supported: true } } },
plain: { capabilities: { reasoning: { supported: false } } },
},
@@ -824,6 +842,33 @@ describe("ConfigProviderPlugin.Plugin", () => {
headers: { "x-tier": "high" },
},
])
const gpt = required(yield* models.get(providerID, Model.ID.make("gpt")))
expect(gpt.package).toBe("@opencode/ai/providers/openai")
expect(gpt.variants).toEqual(effort.variants)
const claude = required(yield* models.get(providerID, Model.ID.make("claude-sonnet-4-5")))
expect(claude.package).toBe("@opencode/ai/providers/anthropic")
expect(claude.variants).toEqual([
{ id: Model.VariantID.make("high"), settings: { thinking: { type: "enabled", budgetTokens: 16_000 } } },
{ id: Model.VariantID.make("max"), settings: { thinking: { type: "enabled", budgetTokens: 31_999 } } },
])
const gemini = required(yield* models.get(providerID, Model.ID.make("gemini-3.1-pro")))
expect(gemini.package).toBe("@opencode/ai/providers/google")
expect(gemini.variants).toEqual([
{
id: Model.VariantID.make("low"),
settings: { thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } },
},
{
id: Model.VariantID.make("high"),
settings: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
},
])
const magistral = required(yield* models.get(providerID, Model.ID.make("magistral-medium")))
expect(magistral.package).toBe("@opencode/ai/providers/mistral")
expect(magistral.variants).toEqual([
{ id: Model.VariantID.make("low"), settings: { reasoningEffort: "low" } },
{ id: Model.VariantID.make("high"), settings: { reasoningEffort: "high" } },
])
expect(required(yield* models.get(providerID, Model.ID.make("fixed"))).variants).toEqual([])
expect(required(yield* models.get(providerID, Model.ID.make("plain"))).variants).toEqual([])
}),
@@ -583,7 +583,7 @@ describe("OpencodePlugin", () => {
),
)
it.live("builds Console model variants from its reasoning and applies its release date", () =>
it.live("builds Console reasoning variants after provider and model package normalization", () =>
Effect.acquireUseRelease(
Effect.sync(() =>
Bun.serve({
@@ -600,6 +600,24 @@ describe("OpencodePlugin", () => {
capabilities: { reasoning: { supported: true, effort: ["default", "low", "high"] } },
variants: [{ id: "high", headers: { "x-tier": "high" } }],
},
gpt: {
package: "aisdk:@ai-sdk/openai",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
variants: [{ id: "high", headers: { "x-tier": "high" } }],
},
"claude-sonnet-4-5": {
package: "aisdk:@ai-sdk/anthropic",
capabilities: { reasoning: { supported: true, budget: { min: 1024 } } },
limit: { output: 64_000 },
},
"gemini-3.1-pro": {
package: "aisdk:@ai-sdk/google",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
},
"magistral-medium": {
package: "aisdk:@ai-sdk/mistral",
capabilities: { reasoning: { supported: true, effort: ["low", "high"] } },
},
},
},
},
@@ -630,6 +648,33 @@ describe("OpencodePlugin", () => {
headers: { "x-tier": "high" },
},
])
const gpt = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("gpt")))
expect(gpt.package).toBe("@opencode/ai/providers/openai")
expect(gpt.variants).toEqual(reasoner.variants)
const claude = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("claude-sonnet-4-5")))
expect(claude.package).toBe("@opencode/ai/providers/anthropic")
expect(claude.variants).toEqual([
{ id: Model.VariantID.make("high"), settings: { thinking: { type: "enabled", budgetTokens: 16_000 } } },
{ id: Model.VariantID.make("max"), settings: { thinking: { type: "enabled", budgetTokens: 31_999 } } },
])
const gemini = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("gemini-3.1-pro")))
expect(gemini.package).toBe("@opencode/ai/providers/google")
expect(gemini.variants).toEqual([
{
id: Model.VariantID.make("low"),
settings: { thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } },
},
{
id: Model.VariantID.make("high"),
settings: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
},
])
const magistral = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("magistral-medium")))
expect(magistral.package).toBe("@opencode/ai/providers/mistral")
expect(magistral.variants).toEqual([
{ id: Model.VariantID.make("low"), settings: { reasoningEffort: "low" } },
{ id: Model.VariantID.make("high"), settings: { reasoningEffort: "high" } },
])
}),
(server) => Effect.promise(() => server.stop(true)),
),