From 209afdbf6849b973c51503dc2c0317112ac84833 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 14:03:43 +0800 Subject: [PATCH] loomy 0.1.10: a refusal in a 200, or a failed read, gives the given list marked fell back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A non-OK business code in a 200 answer (the host saw an OK fetch) returned the static table unmarked; so did a throw. fake.mjs can now answer the models read with a code. Archivemylife on X (agy-cli): "配置后报存提示成功,再打开还是全部都启用". The same class as agy-cli 0.1.61: a list that isn't the account's own, handed back as if it were, makes magpie relist on it and drop the models the user picked that aren't in it. Marked with Symbol.for("magpie.fellBack"), magpie's plugin host keeps the last good list (keepListed) and the picks. Run (mote-run, HOME=mktemp -d): index.test.mjs 34 pass on this change: all pass. Red on the old code with the new test: "a refusal in a 200 gives the static table marked" fails. Not tried: a real account. --- packages/loomy/fake.mjs | 3 +++ packages/loomy/index.mjs | 13 +++++++++++-- packages/loomy/index.test.mjs | 11 +++++++++++ packages/loomy/package.json | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/loomy/fake.mjs b/packages/loomy/fake.mjs index e0769b1..a230386 100644 --- a/packages/loomy/fake.mjs +++ b/packages/loomy/fake.mjs @@ -33,6 +33,7 @@ export function fakeLoomy() { dailyBalance: 3000, // the day's first first-login refreshes it to 5000 recordsReads: 0, modelsReads: 0, + modelsCode: null, // set to a business code to answer the models read 200 with it // onboarding: done[key]=true once its complete call lands (idempotent) onboardingDone: {}, onboardingQueries: 0, @@ -48,6 +49,7 @@ export function fakeLoomy() { state.dailyBalance = 3000 state.recordsReads = 0 state.modelsReads = 0 + state.modelsCode = null state.onboardingDone = {} state.onboardingQueries = 0 state.onboardingCompletes = 0 @@ -108,6 +110,7 @@ export function fakeLoomy() { if (url.pathname === "/api/v1/models") { state.modelsReads++ + if (state.modelsCode) return json(200, { code: state.modelsCode, desc: "系统繁忙" }) return json(200, { data: [ { id: "spark-x", name: "Spark X2.5 (x0.1)", capabilities: { reasoning: true, function_calling: true, vision: false }, context_window: 128000, max_tokens: 8192 }, diff --git a/packages/loomy/index.mjs b/packages/loomy/index.mjs index 96bf411..b424030 100644 --- a/packages/loomy/index.mjs +++ b/packages/loomy/index.mjs @@ -669,7 +669,10 @@ export async function LoomyAuthPlugin({ client } = {}) { if (auth?.type !== "oauth" || !auth.access) return p.models try { const payload = await tokenRequest("GET", "/api/v1/models", auth.access) - if (codeOf(payload) && codeOf(payload) !== OK) return p.models + // a refusal in a 200 lists nothing: what was given (the static + // table at first) isn't the account's list, so magpie keeps the + // one it had and the models picked from it + if (codeOf(payload) && codeOf(payload) !== OK) return fellBack(p.models) const entries = Array.isArray(payload?.data) ? payload.data : [] for (const entry of entries) { const m = catalogModel(entry) @@ -678,13 +681,19 @@ export async function LoomyAuthPlugin({ client } = {}) { } return p.models } catch { - return p.models + return fellBack(p.models) } }, }, } } +// fellBack marks a list that isn't the account's own (magpie's plugin +// host reads Symbol.for("magpie.fellBack")) +function fellBack(models) { + return Object.defineProperty(models, Symbol.for("magpie.fellBack"), { value: true, configurable: true }) +} + // for tests export const _internal = { retryableRefusal, diff --git a/packages/loomy/index.test.mjs b/packages/loomy/index.test.mjs index 7701edb..d6fecc1 100644 --- a/packages/loomy/index.test.mjs +++ b/packages/loomy/index.test.mjs @@ -298,6 +298,17 @@ describe("models", () => { expect(list["glm-5.3-flash"].modalities).toEqual({ input: ["text", "image"], output: ["text"] }) expect(list["plain"].rate).toBeUndefined() expect(list["plain"].name).toBe("No Suffix At All") + expect(list[Symbol.for("magpie.fellBack")]).toBeUndefined() + }) + + // Archivemylife on X (agy-cli's sibling): a list that isn't the account's + // own, handed back as if it were, dropped the models the user picked + test("a refusal in a 200 gives the static table marked as not the account's", async () => { + fake.state.modelsCode = "100500" + const p = { models: { ..._internal.STATIC_MODELS } } + const list = await plugin.provider.models(p, { auth: saved }) + expect(Object.keys(list)).toEqual(Object.keys(_internal.STATIC_MODELS)) + expect(list[Symbol.for("magpie.fellBack")]).toBe(true) }) // plugins#1141: the host reads a listed model by OpenCode's shape diff --git a/packages/loomy/package.json b/packages/loomy/package.json index 2271846..0260253 100644 --- a/packages/loomy/package.json +++ b/packages/loomy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-loomy-auth", - "version": "0.1.9", + "version": "0.1.10", "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",