From e9ac459c2e62e3e5b04c13e2322ded2dc2680f65 Mon Sep 17 00:00:00 2001 From: Victor Navarro Date: Tue, 20 Oct 2026 14:55:22 +0200 Subject: [PATCH] fix(core): build provider variants after package normalization (#57075) --- packages/core/src/config/plugin/provider.ts | 3 ++ packages/core/src/plugin/provider/opencode.ts | 3 ++ packages/core/test/config/provider.test.ts | 47 ++++++++++++++++++- .../test/plugin/provider-opencode.test.ts | 47 ++++++++++++++++++- 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/packages/core/src/config/plugin/provider.ts b/packages/core/src/config/plugin/provider.ts index 0c485c42280..5ea1c70a58e 100644 --- a/packages/core/src/config/plugin/provider.ts +++ b/packages/core/src/config/plugin/provider.ts @@ -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 = [ diff --git a/packages/core/src/plugin/provider/opencode.ts b/packages/core/src/plugin/provider/opencode.ts index 8b7105f64f6..48f47caa3ad 100644 --- a/packages/core/src/plugin/provider/opencode.ts +++ b/packages/core/src/plugin/provider/opencode.ts @@ -302,6 +302,9 @@ export const OpencodePlugin = define { // The Console's reasoning replaces the base variants; its variants still overlay them below. if (config.capabilities?.reasoning !== undefined) model.variants = [ diff --git a/packages/core/test/config/provider.test.ts b/packages/core/test/config/provider.test.ts index 54e0ad4eebf..a4bab665fc2 100644 --- a/packages/core/test/config/provider.test.ts +++ b/packages/core/test/config/provider.test.ts @@ -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([]) }), diff --git a/packages/core/test/plugin/provider-opencode.test.ts b/packages/core/test/plugin/provider-opencode.test.ts index b3a80b9345e..832acaa71e1 100644 --- a/packages/core/test/plugin/provider-opencode.test.ts +++ b/packages/core/test/plugin/provider-opencode.test.ts @@ -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)), ),