mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(core): keep each model's reasoning levels when respelling
This commit is contained in:
parent
665dcb9806
commit
a5a46c53e3
2 changed files with 57 additions and 7 deletions
|
|
@ -158,7 +158,8 @@ export const Plugin = define({
|
|||
((config.variants === undefined && !source?.base && !hadVariants) || repackaged)
|
||||
)
|
||||
models.update(providerID, id, (model) => {
|
||||
model.variants = [...Variant.resolve({ ...model, package: model.package ?? providerPackage })]
|
||||
const target = { ...model, package: model.package ?? providerPackage }
|
||||
model.variants = source?.base ? respell(target, source.base.variants) : [...Variant.resolve(target)]
|
||||
// Configured variants overlay the respelled defaults.
|
||||
for (const variants of configured.get(key) ?? []) overlayVariants(model, variants)
|
||||
})
|
||||
|
|
@ -169,7 +170,7 @@ export const Plugin = define({
|
|||
// Leave models whose variants or package an earlier model transform replaced.
|
||||
if (!model || model.package !== undefined || !isDeepStrictEqual(model.variants, variants)) continue
|
||||
models.update(providerID, id, (model) => {
|
||||
model.variants = [...Variant.resolve({ ...model, package: providerPackage })]
|
||||
model.variants = respell({ ...model, package: providerPackage }, variants)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -299,6 +300,18 @@ function overlay(
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Spells the reasoning levels a model already offers for the package it now runs with. Models don't keep the
|
||||
* catalog's reasoning support, so the current variant ids stand in for it; a level the package can't spell is dropped.
|
||||
*/
|
||||
function respell(model: Model.Info, previous: Model.Info["variants"]) {
|
||||
const spelled = [
|
||||
...(previous.some((variant) => variant.id === "thinking") ? Variant.resolve(model, [{ type: "toggle" }]) : []),
|
||||
...Variant.resolve(model),
|
||||
]
|
||||
return previous.flatMap((variant) => spelled.find((item) => item.id === variant.id) ?? [])
|
||||
}
|
||||
|
||||
type ConfigVariants = NonNullable<NonNullable<ConfigProvider.Info["models"]>[string]["variants"]>
|
||||
|
||||
function overlayVariants(model: Model.MutableInfo, variants: ConfigVariants) {
|
||||
|
|
|
|||
|
|
@ -1012,7 +1012,7 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
])
|
||||
|
||||
const model = required(yield* models.get(Provider.ID.make("google-ix"), Model.ID.make("gemini-4-argon")))
|
||||
expect(model.variants).toEqual(interactions(["low", "medium", "high"]))
|
||||
expect(model.variants).toEqual(interactions(["low", "high"]))
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -1036,8 +1036,8 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
|
||||
const variants = (id: string) =>
|
||||
models.get(Provider.ID.make("google"), Model.ID.make(id)).pipe(Effect.map((model) => required(model).variants))
|
||||
expect(yield* variants("gemini-4-argon")).toEqual(interactions(["low", "medium", "high"]))
|
||||
expect(yield* variants("gemini-4-flash")).toEqual(interactions(["low", "medium", "high"]))
|
||||
expect(yield* variants("gemini-4-argon")).toEqual(interactions(["low", "high"]))
|
||||
expect(yield* variants("gemini-4-flash")).toEqual(interactions(["low", "high"]))
|
||||
// Its own package still applies, so its variants stay as they were.
|
||||
expect((yield* variants("gemini-4-routed")).map((variant) => variant.settings)).toEqual([
|
||||
{ thinkingConfig: { includeThoughts: true, thinkingLevel: "low" } },
|
||||
|
|
@ -1046,6 +1046,44 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("keeps each model's reasoning levels when a package switch respells them", () =>
|
||||
Effect.gen(function* () {
|
||||
const providers = yield* Provider.Service
|
||||
const models = yield* Model.Service
|
||||
const providerID = Provider.ID.make("zai")
|
||||
yield* providers.transform((editor) => {
|
||||
editor.update(providerID, (provider) => {
|
||||
provider.package = "@opencode/ai/providers/openai-compatible"
|
||||
})
|
||||
const levels = { "glm-5": ["none", "thinking"], "glm-4.7": ["low", "high", "ultra"] }
|
||||
for (const [id, ids] of Object.entries(levels))
|
||||
editor.models.update(providerID, Model.ID.make(id), (model) => {
|
||||
model.variants = ids.map((variant) => ({ id: Model.VariantID.make(variant), body: { level: variant } }))
|
||||
})
|
||||
})
|
||||
yield* addPlugin([
|
||||
new Document({
|
||||
type: "document",
|
||||
info: decode({ providers: { zai: { package: "@opencode/ai/providers/anthropic" } } }),
|
||||
}),
|
||||
])
|
||||
|
||||
const variants = (id: string) =>
|
||||
models.get(providerID, Model.ID.make(id)).pipe(Effect.map((model) => required(model).variants))
|
||||
expect(yield* variants("glm-5")).toEqual([
|
||||
{ id: Model.VariantID.make("none"), settings: { thinking: { type: "disabled" } } },
|
||||
{ id: Model.VariantID.make("thinking"), settings: { thinking: { type: "adaptive", display: "summarized" } } },
|
||||
])
|
||||
// A level the new package can't spell is dropped rather than kept in the old spelling.
|
||||
expect(yield* variants("glm-4.7")).toEqual(
|
||||
["low", "high"].map((effort) => ({
|
||||
id: Model.VariantID.make(effort),
|
||||
settings: { thinking: { type: "adaptive", display: "summarized" }, effort },
|
||||
})),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("overlays configured variants on the variants respelled for a package switch", () =>
|
||||
Effect.gen(function* () {
|
||||
const models = yield* Model.Service
|
||||
|
|
@ -1073,10 +1111,9 @@ describe("ConfigProviderPlugin.Plugin", () => {
|
|||
])
|
||||
|
||||
const model = required(yield* models.get(Provider.ID.make("google-ix"), Model.ID.make("gemini-4-argon")))
|
||||
const [low, medium, high] = interactions(["low", "medium", "high"])
|
||||
const [low, high] = interactions(["low", "high"])
|
||||
expect(model.variants).toEqual([
|
||||
{ ...low, settings: { thinkingLevel: "low", thinkingSummaries: "none" } },
|
||||
medium,
|
||||
{ ...high, headers: { "x-tier": "high" } },
|
||||
])
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue