From b6a996478f0de5e26cfb40625c33dec457197ce8 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 14:03:43 +0800 Subject: [PATCH] cloudflare-workers-ai 0.0.6: provider.models keeps the fell-back mark of a list kept after a failed read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit discovery.forDisplay marks the kept list, but the (Paid) renaming rebuilt it with Object.fromEntries and lost the mark. 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): node --test 24 pass on this change: all pass. Red on the old code with the new test: "provider.models after a failed read keeps the fell-back mark" fails. Not tried: a real account. Plugins root bun test (HOME=mktemp -d) at this head, rebased on 13a6f4c2, on Linux (wsl-run, magpie-desktop), covering the five commits above and agy-cli 0.1.61: 8775 pass, 0 fail. --- packages/cloudflare-workers-ai/package.json | 2 +- packages/cloudflare-workers-ai/src/index.mjs | 6 +++++- .../cloudflare-workers-ai/test/plugin.test.mjs | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare-workers-ai/package.json b/packages/cloudflare-workers-ai/package.json index 8ffa8f1..5a78ff0 100644 --- a/packages/cloudflare-workers-ai/package.json +++ b/packages/cloudflare-workers-ai/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cloudflare-workers-ai-auth", - "version": "0.0.5", + "version": "0.0.6", "private": false, "type": "module", "main": "./opencode.mjs", diff --git a/packages/cloudflare-workers-ai/src/index.mjs b/packages/cloudflare-workers-ai/src/index.mjs index 306fc6f..55673d6 100644 --- a/packages/cloudflare-workers-ai/src/index.mjs +++ b/packages/cloudflare-workers-ai/src/index.mjs @@ -461,12 +461,16 @@ export async function CloudflareWorkersAIPlugin(_input, options = {}) { // Name-flag the models Cloudflare serves only behind Workers Paid / AI // Gateway credits. No `free` flag: shared daily Neurons allowance is not // the same thing as a free model. - return Object.fromEntries( + const out = Object.fromEntries( Object.entries(models).map(([id, m]) => [ id, PAID_ONLY_MODELS.has(id) ? { ...m, name: paidName(id, m.name) } : m, ]), ); + // a list kept from before a failed read says so still, so magpie + // keeps the account's last good list and the models picked from it + if (models[Symbol.for("magpie.fellBack")] === true) out[Symbol.for("magpie.fellBack")] = true; + return out; }, }, }; diff --git a/packages/cloudflare-workers-ai/test/plugin.test.mjs b/packages/cloudflare-workers-ai/test/plugin.test.mjs index 372c4a4..ae528e3 100644 --- a/packages/cloudflare-workers-ai/test/plugin.test.mjs +++ b/packages/cloudflare-workers-ai/test/plugin.test.mjs @@ -523,3 +523,21 @@ test("any other 429 keeps its own words: no Retry-After is added", async () => { assert.equal(resp.headers.get("retry-after"), null, "only a 3036 may name the midnight rest"); assert.equal(JSON.parse(await resp.text()).errors[0].code, 700003, "body preserved"); }); + +// Archivemylife on X (agy-cli's sibling): a list handed back as the +// account's own after a failed read dropped the models the user picked +test("provider.models after a failed read keeps the fell-back mark", async () => { + let fail = false; + const o = opts(); + o.discoveryTTLMs = 0; + o.fetchImpl = async () => (fail ? new Response("boom", { status: 502 }) : new Response(JSON.stringify(fakeCatalog()))); + const plugin = await CloudflareWorkersAIPlugin({}, o); + const auth = { type: "api", key: "tok", metadata: { accountId: ACCOUNT_ID } }; + const good = await plugin.provider.models({ models: {} }, { auth }); + assert.ok(good["@cf/meta/llama-3-8b-instruct"]); + assert.equal(good[Symbol.for("magpie.fellBack")], undefined); + fail = true; + const kept = await plugin.provider.models({ models: {} }, { auth }); + assert.deepEqual(Object.keys(kept), Object.keys(good)); + assert.equal(kept[Symbol.for("magpie.fellBack")], true); +});