diff --git a/packages/loomy/index.mjs b/packages/loomy/index.mjs index 885bc59..34c03d7 100644 --- a/packages/loomy/index.mjs +++ b/packages/loomy/index.mjs @@ -341,6 +341,32 @@ function catalogModel(entry) { return { id, config } } +// listedModel is the vendor's entry as the models hook gives it: the +// config's fields, and the capabilities OpenCode (and magpie's host) read +// a listed model by. The config's fields alone left the vendor's vision, +// reasoning and tool calls unread, so deepseek-v4-flash-1017, which +// models.dev doesn't know, went as a text-only model of no known +// vision (plugins#1141). What the vendor doesn't say keeps what was known +// of the model (models.dev, the static table). +function listedModel(was, m, entry) { + const caps = entry?.capabilities ?? {} + const had = was?.capabilities ?? { temperature: true, toolcall: true, input: { text: true }, output: { text: true } } + const capabilities = { ...had, input: { ...(had.input ?? { text: true }) } } + if (typeof caps.reasoning === "boolean") capabilities.reasoning = caps.reasoning + if (typeof caps.function_calling === "boolean") capabilities.toolcall = caps.function_calling + if (typeof caps.vision === "boolean") { + capabilities.input.image = caps.vision + capabilities.attachment = caps.vision + } + return { + ...(was ?? {}), + ...m.config, + id: m.id, + limit: { ...(was?.limit ?? {}), ...(m.config.limit ?? {}) }, + capabilities, + } +} + // ── the plugin ───────────────────────────────────────────────────────────── export async function LoomyAuthPlugin({ client } = {}) { @@ -641,7 +667,7 @@ export async function LoomyAuthPlugin({ client } = {}) { for (const entry of entries) { const m = catalogModel(entry) if (!m) continue - p.models[m.id] = m.config + p.models[m.id] = listedModel(p.models[m.id], m, entry) } return p.models } catch { diff --git a/packages/loomy/index.test.mjs b/packages/loomy/index.test.mjs index a9146b2..8c64346 100644 --- a/packages/loomy/index.test.mjs +++ b/packages/loomy/index.test.mjs @@ -299,6 +299,23 @@ describe("models", () => { expect(list["plain"].rate).toBeUndefined() expect(list["plain"].name).toBe("No Suffix At All") }) + + // plugins#1141: the host reads a listed model by OpenCode's shape + // (capabilities.input.image, capabilities.reasoning, capabilities.toolcall), + // so the vendor's vision and reasoning go there too. + test("the vendor's capabilities, in the shape the host reads", async () => { + const p = { models: { "deepseek-v4-flash": { id: "deepseek-v4-flash", name: "DS", limit: { context: 1000000, output: 64000 }, capabilities: { temperature: true, reasoning: false, attachment: false, toolcall: true, input: { text: true, image: false }, output: { text: true } }, api: { id: "deepseek-v4-flash", npm: "@ai-sdk/openai-compatible" } } } } + const list = await plugin.provider.models(p, { auth: saved }) + expect(list["glm-5.3-flash"].capabilities.input.image).toBe(true) + expect(list["glm-5.3-flash"].capabilities.attachment).toBe(true) + expect(list["spark-x"].capabilities.reasoning).toBe(true) + expect(list["spark-x"].capabilities.toolcall).toBe(true) + expect(list["spark-x"].capabilities.input.image).toBe(false) + // what the vendor doesn't say keeps what was known of the model + expect(list["deepseek-v4-flash"].limit.context).toBe(1000000) + expect(list["deepseek-v4-flash"].api.npm).toBe("@ai-sdk/openai-compatible") + expect(list["deepseek-v4-flash"].rate).toBe("x3.0") + }) }) describe("usage", () => { diff --git a/packages/loomy/package.json b/packages/loomy/package.json index 755ae04..3c7d442 100644 --- a/packages/loomy/package.json +++ b/packages/loomy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-loomy-auth", - "version": "0.1.7", + "version": "0.1.8", "description": "OpenCode & Magpie provider plugin for Loomy (讯飞, loomyad.xunfei.cn): SMS sign-in, chat, models, the two point wallets and the daily first-login grant", "type": "module", "main": "./opencode.mjs",