mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
fix(core): keep a mode's ID on the service tier it asks for (#65989)
This commit is contained in:
parent
7dd39a70b6
commit
e4cd9c2bc5
2 changed files with 74 additions and 6 deletions
|
|
@ -290,16 +290,23 @@ const normalize = Effect.fnUntraced(function* (
|
|||
return [
|
||||
{ ...base, variants },
|
||||
...tiers.flatMap((tier) => {
|
||||
// "priority" is the tier people know as fast.
|
||||
const name = tier === "priority" && !tiers.includes("fast") ? "fast" : tier
|
||||
const mode = modes.find(([key, options]) => (options.service_tier ?? key) === tier)
|
||||
// A mode for the tier keeps its ID, so a saved session asks for the same tier, unless another model already
|
||||
// has that ID. Otherwise "priority" is the tier people know as fast.
|
||||
const name =
|
||||
mode && !ids.has(Model.ID.make(`${source.model.id}-${mode[0]}`))
|
||||
? mode[0]
|
||||
: tier === "priority" && !tiers.includes("fast")
|
||||
? "fast"
|
||||
: tier
|
||||
const speedID = Model.ID.make(`${source.model.id}-${name}`)
|
||||
if (ids.has(speedID)) return []
|
||||
// Until every tier has a multiplier, a mode for the tier may still carry its price.
|
||||
const mode = modes.find(([key, options]) => (options.service_tier ?? key) === tier)?.[1]
|
||||
// A mode's ID stays with the tier it asks for, even when another tier has that name.
|
||||
if (ids.has(speedID) || (!mode && modes.some(([key]) => key === name))) return []
|
||||
return [
|
||||
modelInfo(providerID, { packageName, baseURL }, speedID, source, {
|
||||
...speed(name, tier),
|
||||
cost: modeCost(source.model, baseCost, tier, { cost: mode?.cost }),
|
||||
// Until every tier has a multiplier, a mode for the tier may still carry its price.
|
||||
cost: modeCost(source.model, baseCost, tier, { cost: mode?.[1].cost }),
|
||||
request: tierRequest(source.route.protocol, tier),
|
||||
}),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -735,6 +735,67 @@ describe("ModelsDev Service", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("keeps a mode's ID on the tier the mode asks for", () =>
|
||||
Effect.gen(function* () {
|
||||
const [acme] = yield* ModelsDev.decodeSnapshot(
|
||||
JSON.stringify({
|
||||
acme: {
|
||||
...fixture.acme,
|
||||
models: {
|
||||
"acme-1": sourceModel("acme-1", {
|
||||
capabilities: {
|
||||
tools: { supported: true },
|
||||
reasoning: { supported: false },
|
||||
service_tier: ["priority", "fast"],
|
||||
},
|
||||
// Saved sessions hold "acme-1-fast", which has always asked for the priority tier. The "fast" tier
|
||||
// would take that ID, so it isn't offered as a second choice next to it.
|
||||
experimental: { modes: { fast: { service_tier: "priority", body: { service_tier: "priority" } } } },
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
false,
|
||||
true,
|
||||
)
|
||||
expect(acme?.models.map((item) => [item.id, item.settings?.serviceTier])).toEqual([
|
||||
["acme-1", undefined],
|
||||
["acme-1-fast", "priority"],
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("names a mode's tier after the tier when another model already has the mode's ID", () =>
|
||||
Effect.gen(function* () {
|
||||
const [acme] = yield* ModelsDev.decodeSnapshot(
|
||||
JSON.stringify({
|
||||
acme: {
|
||||
...fixture.acme,
|
||||
models: {
|
||||
"acme-1": sourceModel("acme-1", {
|
||||
capabilities: {
|
||||
tools: { supported: true },
|
||||
reasoning: { supported: false },
|
||||
service_tier: ["priority", "fast"],
|
||||
},
|
||||
experimental: { modes: { fast: { service_tier: "priority", body: { service_tier: "priority" } } } },
|
||||
}),
|
||||
// A separate model already holds "acme-1-fast", so the priority tier keeps its own name.
|
||||
"acme-1-fast": sourceModel("acme-1-fast"),
|
||||
},
|
||||
},
|
||||
}),
|
||||
false,
|
||||
true,
|
||||
)
|
||||
expect(acme?.models.map((item) => [item.id, item.settings?.serviceTier])).toEqual([
|
||||
["acme-1", undefined],
|
||||
["acme-1-priority", "priority"],
|
||||
["acme-1-fast", undefined],
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("skips non-chat models whose only opencode package serves another type", () =>
|
||||
Effect.gen(function* () {
|
||||
const api = (opencodeai: string) => ({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue