diff --git a/packages/opendesign/index.mjs b/packages/opendesign/index.mjs index 6d9d38c..9e3a451 100644 --- a/packages/opendesign/index.mjs +++ b/packages/opendesign/index.mjs @@ -280,6 +280,18 @@ function levelsOf(m) { return Array.isArray(m?.efforts) ? m.efforts.filter((e) => typeof e === "string" && e) : [] } +// CAP is the most output a model may be asked for where amr-link's catalog +// (metadata.context_budget) says more than its API takes. Asking for more is +// a 400 "Open Design: The request could not be completed." that names no +// field, so nothing can lower it and retry. A client that names no limit +// (Codex) is given the published one by magpie, so every turn would fail +// (#827, Gitleonan, measured 2026-11-09 on two accounts): glm-5.3-flash took +// 131072 and refused 132000 (one account took 232000), and gemini-3.8-flash +// took 65536 and refused 65537 on both. The cap is applied here, not in +// models.mjs: the live catalog's number overrides the seed's (withSeed), and +// refresh-models.mjs writes the vendor's number back into the seed. +const CAP = { "glm-5.3-flash": 131072, "gemini-3.8-flash": 65536 } + // modelOf turns one model's facts — models.mjs's, or amr-link's catalog // read again — into the model magpie shows, as the provider's config has // it. A model reasons when it has levels, or else when the vendor calls it @@ -305,7 +317,7 @@ function modelOf(id, m) { ...(rate && { rate }), limit: { context: Number.isFinite(context) && context > 0 ? context : 200_000, - output: Number.isFinite(output) && output > 0 ? output : 32_000, + output: Math.min(Number.isFinite(output) && output > 0 ? output : 32_000, CAP[id] ?? Infinity), }, modalities: { input: ["text", ...input], output: ["text"] }, } @@ -480,7 +492,11 @@ export const OpenDesignAuthPlugin = async () => { const models = { ...seed(), ...(was.models ?? {}) } for (const [id, m] of Object.entries(models)) { const rate = RATES[id] === undefined ? undefined : "x" + RATES[id] - models[id] = { ...m, api: { ...(m.api ?? {}), npm: wireOf(id) }, provider: { ...(m.provider ?? {}), npm: wireOf(id) }, ...(rate && { rate }) } + // a kept copy's limit is capped too: an earlier version wrote the + // catalog's 232000 for glm-5.3-flash, which amr-link refuses (CAP) + const out = Number(m.limit?.output) + const limit = CAP[id] && !(out > 0 && out <= CAP[id]) ? { limit: { ...(m.limit ?? {}), output: CAP[id] } } : {} + models[id] = { ...m, ...limit, api: { ...(m.api ?? {}), npm: wireOf(id) }, provider: { ...(m.provider ?? {}), npm: wireOf(id) }, ...(rate && { rate }) } } cfg.provider[ID] = { name: "Open Design", diff --git a/packages/opendesign/index.test.mjs b/packages/opendesign/index.test.mjs index 5a6ca8d..03c2c8b 100644 --- a/packages/opendesign/index.test.mjs +++ b/packages/opendesign/index.test.mjs @@ -284,6 +284,34 @@ test("a kept model's rate is re-declared, so a charge an earlier version wrote c expect(models["brand-new-9"].rate).toBe("x1") }) +// #827 (Gitleonan): amr-link's catalog publishes more output than its API +// takes for two models, and asking for the published number is a 400 that +// names no field. The catalog entries are the reporter's numbers; the caps +// are what they measured on 2026-11-09 (131072 and 65536 taken, one more +// refused). +test("a model's output is capped where amr-link takes less than its catalog says (#827)", async () => { + const models = I.modelsOf({ + data: [ + { id: "glm-5.3-flash", architecture: { input_modalities: ["text", "image", "video"] }, metadata: { cost: "low", capability: "advanced", context_limit: 1048000, context_budget: 232000 } }, + { id: "gemini-3.8-flash", architecture: { input_modalities: ["text"] }, metadata: { cost: "low", capability: "standard", context_limit: 1048576, context_budget: 264000 } }, + // a catalog that says less than the cap is taken as it says + { id: "deepseek-v4.1-flash", metadata: { context_limit: 1048000, context_budget: 232000 } }, + ], + }) + expect(models["glm-5.3-flash"].limit).toEqual({ context: 1048000, output: 131072 }) + expect(models["gemini-3.8-flash"].limit).toEqual({ context: 1048576, output: 65536 }) + expect(models["deepseek-v4.1-flash"].limit.output).toBe(232000) + expect(I.modelsOf({ data: [{ id: "glm-5.3-flash", metadata: { context_budget: 100000 } }] })["glm-5.3-flash"].limit.output).toBe(100000) + + // the seed, and a copy an earlier version kept with the catalog's number + const cfg = { provider: { opendesign: { models: { "gemini-3.8-flash": { id: "gemini-3.8-flash", name: "gemini-3.8-flash", limit: { context: 1048576, output: 264000 } } } } } } + await (await OpenDesignAuthPlugin({})).config(cfg) + const served = cfg.provider.opendesign.models + expect(served["glm-5.3-flash"].limit.output).toBe(131072) + expect(served["gemini-3.8-flash"].limit).toEqual({ context: 1048576, output: 65536 }) + expect(served["deepseek-v4.1-flash"].limit.output).toBe(232000) +}) + // #829 (exposir): the signed-in catalog's DeepSeek V4.1 Flash Eco entry // left image out, so it was served text-only and magpie sent another model's // description of the image instead, while amr-link took the image itself diff --git a/packages/opendesign/package.json b/packages/opendesign/package.json index 39756e3..acd6b4f 100644 --- a/packages/opendesign/package.json +++ b/packages/opendesign/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-opendesign-auth", - "version": "0.1.10", + "version": "0.1.11", "description": "Open Design Cloud (Design Plan) in OpenCode and magpie: the account's device sign-in, its models, and the plan's 5-hour and 7-day allowance", "type": "module", "main": "./opencode.mjs",