cloudflare-workers-ai 0.0.6: provider.models keeps the fell-back mark of a list kept after a failed read
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.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user