diff --git a/packages/opendesign/README.md b/packages/opendesign/README.md index 1a73752..e195e21 100644 --- a/packages/opendesign/README.md +++ b/packages/opendesign/README.md @@ -60,7 +60,11 @@ magpie calls the plugin's `provider.models`, which reads `amr-link`'s live `/v1/models` at that account's key on every listing, so what a signed-in account is offered is what its plan entitles it to right now. Limits and input modalities come from that same catalog; the quota multiplier (`rate`) -comes from `rates.mjs`, the plan's own table (below). +comes from `rates.mjs`, the plan's own table (below). What the catalog leaves +out of a model `models.mjs` knows is the seed's: its limits, and every input +kind the seed declares (#829: the catalog left image out of DeepSeek V4.1 +Flash Eco, which takes images). A kind the catalog adds is added; a kind is +removed only by changing `models.mjs`. Reasoning levels are not in the catalog, so `models.mjs` records the ones measured against `amr-link` (#137): every model took `reasoning_effort` @@ -105,8 +109,9 @@ bun refresh-models.mjs # or OPENDESIGN_KEY=sk-amr-… bun … ``` The script keeps the names and measured levels already there — the catalog -carries neither — and reads nothing else: no secret is written to the file or -printed. +carries neither — and, as the plugin does, the input kinds, limits and words +the catalog leaves out. It prints each kind it kept that way. It reads nothing +else: no secret is written to the file or printed. Requests go to `https://amr-link.open-design.ai/v1`, each model on the API amr-link answers its thinking on (measured, plugins#141): chat completions diff --git a/packages/opendesign/index.mjs b/packages/opendesign/index.mjs index 1da8e11..6d9d38c 100644 --- a/packages/opendesign/index.mjs +++ b/packages/opendesign/index.mjs @@ -366,16 +366,48 @@ function seed() { return Object.fromEntries(Object.entries(MODELS).map(([id, m]) => [id, modelOf(id, m)])) } +// withSeed() is a catalog entry's facts with the seed's filling what the +// entry leaves out: a limit, a cost or capability word the catalog doesn't +// give is the seed's, not modelOf's 200K/32K fallback or no word at all. +// +// input is the seed's and the catalog's together (#829). The seed's input is +// what amr-link's own catalog listed when models.mjs was last refreshed +// (refresh-models.mjs writes only what is listed), and DeepSeek V4.1 Flash +// Eco took an image on amr-link while the live entry left image out. The two +// mistakes don't cost the same: a kind listed that the model refuses is the +// vendor's visible error, while a kind dropped is silent, as magpie hands the +// image to another model for a description, at that account's cost, and +// sends this one text. So a catalog that lists text only takes nothing away +// from a kind the seed declares; refresh-models.mjs says when it does, and +// removing a kind is a change to models.mjs. A model the seed doesn't know, +// or a kind it doesn't declare, is the catalog's alone. +function withSeed(id, f) { + const s = MODELS[id] ?? {} + const positive = (n) => Number.isFinite(n) && n > 0 + const seedInput = Array.isArray(s.input) ? s.input.filter((x) => typeof x === "string" && x !== "text") : [] + return { + ...f, + context: positive(f.context) ? f.context : s.context, + output: positive(f.output) ? f.output : s.output, + input: [...new Set([...seedInput, ...f.input])], + cost: f.cost || text(s.cost), + capability: f.capability || text(s.capability), + name: s.name ?? id, + efforts: s.efforts, + } +} + // modelsOf() shapes amr-link's live catalog as magpie's models: the list an // account's plan entitles it to right now, as provider.models gives them. A -// model the seed knows keeps its name and its measured levels; the catalog -// carries ids only. +// model the seed knows keeps its name and its measured levels, which the +// catalog doesn't carry, and what the seed says of it that the catalog +// doesn't (withSeed). function modelsOf(catalog) { const out = {} for (const m of catalog?.data ?? []) { const id = text(m?.id) if (!id) continue - out[id] = servedOf(id, { ...facts(m), name: MODELS[id]?.name ?? id, efforts: MODELS[id]?.efforts }) + out[id] = servedOf(id, withSeed(id, facts(m))) } return out } diff --git a/packages/opendesign/index.test.mjs b/packages/opendesign/index.test.mjs index 16860db..5a6ca8d 100644 --- a/packages/opendesign/index.test.mjs +++ b/packages/opendesign/index.test.mjs @@ -284,6 +284,37 @@ 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") }) +// #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 +test("a kind the seed declares stays when the catalog leaves it out (#829)", () => { + const models = I.modelsOf({ + data: [ + // listed, text only + { id: "deepseek-v4.1-flash-eco", architecture: { input_modalities: ["text"] }, metadata: { cost: "low", capability: "advanced", context_limit: 1048000, context_budget: 232000 } }, + // no architecture at all, nor limits or words + { id: "glm-5.3-flashx" }, + // the catalog's own kinds add to the seed's + { id: "kimi-k2.7-code", architecture: { input_modalities: ["text", "image", "video"] } }, + // a model the seed says takes text only stays text only + { id: "deepseek-v4-pro", architecture: { input_modalities: ["text"] } }, + // a model the seed doesn't know is the catalog's alone + { id: "brand-new-9", architecture: { input_modalities: ["text"] } }, + ], + }) + const input = (id) => Object.entries(models[id].capabilities.input).filter(([, on]) => on).map(([k]) => k) + expect(asMagpieReads(models["deepseek-v4.1-flash-eco"]).image).toBe(true) + expect(input("deepseek-v4.1-flash-eco")).toEqual(["text", "image"]) + expect(input("glm-5.3-flashx")).toEqual(["text", "image", "video"]) + expect(input("kimi-k2.7-code")).toEqual(["text", "image", "video"]) + expect(input("deepseek-v4-pro")).toEqual(["text"]) + expect(input("brand-new-9")).toEqual(["text"]) + // the limits and words the catalog leaves out are the seed's, not 200K/32K + expect(models["glm-5.3-flashx"].limit).toEqual({ context: 1000000, output: 232000 }) + expect(models["glm-5.3-flashx"].rate).toBe("x2") + expect(models["brand-new-9"].limit).toEqual({ context: 200000, output: 32000 }) +}) + test("an empty catalog is no models", () => { expect(I.modelsOf({ data: [] })).toEqual({}) expect(I.modelsOf(null)).toEqual({}) diff --git a/packages/opendesign/package.json b/packages/opendesign/package.json index 78832b2..39756e3 100644 --- a/packages/opendesign/package.json +++ b/packages/opendesign/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-opendesign-auth", - "version": "0.1.9", + "version": "0.1.10", "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", diff --git a/packages/opendesign/refresh-models.mjs b/packages/opendesign/refresh-models.mjs index 6e7783c..787db1b 100644 --- a/packages/opendesign/refresh-models.mjs +++ b/packages/opendesign/refresh-models.mjs @@ -64,23 +64,35 @@ try { ;({ MODELS: before } = await import(pathToFileURL(TARGET).href)) } catch {} -const input = (m) => { - const said = Array.isArray(m?.architecture?.input_modalities) ? m.architecture.input_modalities : [] - return said.filter((x) => typeof x === "string" && x !== "text") +// input is the catalog's kinds and the seed's together, as the plugin serves +// them (withSeed in index.mjs, #829): a catalog entry that leaves image out +// doesn't take it from a model the seed declares it for. A kind kept that way +// is printed, so removing it is a choice made in models.mjs, not a refresh's. +const kinds = (l) => (Array.isArray(l) ? l.filter((x) => typeof x === "string" && x !== "text") : []) +const input = (id, m) => { + const said = kinds(m?.architecture?.input_modalities) + const kept = kinds(before[id]?.input).filter((x) => !said.includes(x)) + if (kept.length) console.log(`${id}: kept ${kept.join(", ")} from models.mjs; the catalog doesn't list it`) + return [...new Set([...kinds(before[id]?.input), ...said])] } +const positive = (n) => Number.isFinite(n) && n > 0 const lines = [] for (const m of catalog) { const id = m.id.trim() const meta = m.metadata ?? {} const facts = [] - const context = Number(meta.context_limit) - const output = Number(meta.context_budget) - if (Number.isFinite(context) && context > 0) facts.push(`context: ${context}`) - if (Number.isFinite(output) && output > 0) facts.push(`output: ${output}`) - const extra = input(m) + // what the catalog leaves out is the seed's, as the plugin serves it + const was = before[id] ?? {} + const context = positive(Number(meta.context_limit)) ? Number(meta.context_limit) : Number(was.context) + const output = positive(Number(meta.context_budget)) ? Number(meta.context_budget) : Number(was.output) + if (positive(context)) facts.push(`context: ${context}`) + if (positive(output)) facts.push(`output: ${output}`) + const extra = input(id, m) if (extra.length) facts.push(`input: [${extra.map((x) => JSON.stringify(x)).join(", ")}]`) - if (typeof meta.cost === "string") facts.push(`cost: ${JSON.stringify(meta.cost)}`) - if (typeof meta.capability === "string") facts.push(`capability: ${JSON.stringify(meta.capability)}`) + const cost = typeof meta.cost === "string" && meta.cost.trim() ? meta.cost : was.cost + const capability = typeof meta.capability === "string" && meta.capability.trim() ? meta.capability : was.capability + if (typeof cost === "string") facts.push(`cost: ${JSON.stringify(cost)}`) + if (typeof capability === "string") facts.push(`capability: ${JSON.stringify(capability)}`) const efforts = before[id]?.efforts if (Array.isArray(efforts)) facts.push(`efforts: [${efforts.map((x) => JSON.stringify(x)).join(", ")}]`) const name = before[id]?.name ?? id diff --git a/packages/opendesign/refresh.test.mjs b/packages/opendesign/refresh.test.mjs new file mode 100644 index 0000000..e31ada5 --- /dev/null +++ b/packages/opendesign/refresh.test.mjs @@ -0,0 +1,52 @@ +// refresh-models.mjs rewrites models.mjs from amr-link's catalog. A kind, a +// limit or a word the catalog leaves out is kept from the seed, as the plugin +// serves it (#829), so a refresh doesn't take image from DeepSeek V4.1 Flash +// Eco. The script runs on a copy of the package, with fetch stubbed. +import { test, expect } from "bun:test" +import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { pathToFileURL } from "node:url" + +const CATALOG = { + data: [ + { id: "deepseek-v4.1-flash-eco", architecture: { input_modalities: ["text"] }, metadata: { cost: "low", capability: "advanced", context_limit: 1048000, context_budget: 232000 } }, + { id: "glm-5.3-flashx" }, + { id: "kimi-k2.7-code", architecture: { input_modalities: ["text", "image", "video"] }, metadata: { context_limit: 262000 } }, + { id: "deepseek-v4-pro", architecture: { input_modalities: ["text"] }, metadata: { cost: "high" } }, + { id: "brand-new-9", architecture: { input_modalities: ["text"] } }, + ], +} + +test("a refresh keeps what the catalog leaves out of a seed model (#829)", async () => { + const dir = mkdtempSync(join(tmpdir(), "opendesign-refresh-")) + try { + for (const f of ["refresh-models.mjs", "models.mjs"]) copyFileSync(join(import.meta.dir, f), join(dir, f)) + writeFileSync( + join(dir, "stub.mjs"), + `globalThis.fetch = async (url) => { + if (String(url) !== "https://amr-link.open-design.ai/v1/models") throw new Error("unexpected fetch " + url) + return Response.json(${JSON.stringify(CATALOG)}) + }\n`, + ) + const run = Bun.spawnSync([process.execPath, "--preload", join(dir, "stub.mjs"), join(dir, "refresh-models.mjs")], { + cwd: dir, + env: { PATH: process.env.PATH ?? "", HOME: dir, XDG_CONFIG_HOME: dir, OPENDESIGN_KEY: "sk-amr-test" }, + }) + const out = run.stdout.toString() + expect([run.exitCode, run.stderr.toString()]).toEqual([0, ""]) + expect(out).toContain("deepseek-v4.1-flash-eco: kept image from models.mjs") + // a fresh URL, so this isn't the copy's import from before the write + const { MODELS } = await import(pathToFileURL(join(dir, "models.mjs")).href + "?after") + expect(Object.keys(MODELS)).toEqual(CATALOG.data.map((m) => m.id)) + expect(MODELS["deepseek-v4.1-flash-eco"]).toEqual({ name: "DeepSeek V4.1 Flash Eco", context: 1048000, output: 232000, input: ["image"], cost: "low", capability: "advanced", efforts: ["low", "high", "max"] }) + expect(MODELS["glm-5.3-flashx"]).toEqual({ name: "GLM 5.3 FlashX", context: 1000000, output: 232000, input: ["image", "file", "video"], cost: "medium", capability: "advanced", efforts: ["low", "high", "max"] }) + expect(MODELS["kimi-k2.7-code"].input).toEqual(["image", "video"]) + expect(MODELS["deepseek-v4-pro"].input).toBeUndefined() + expect(MODELS["brand-new-9"]).toEqual({ name: "brand-new-9" }) + // the package's own seed is untouched + expect(readFileSync(join(import.meta.dir, "models.mjs"), "utf8")).toContain('"deepseek-v4.1-flash-eco"') + } finally { + rmSync(dir, { recursive: true, force: true }) + } +})