zen-free 0.1.9: a free model Zen lists is offered the hour it lists it, before OpenCode's catalog or docs describe it, and a list read with them out of reach isn't said as fallen back (yetone/magpie#2385)

Zen made deepseek-v4.1-flash-free free (in its /models as the public key
reads it, 2026-10-15) and the plugin never offered it. Two causes:

- buildModels left out a listed model that neither the catalog
  (models.opencode.ai) nor the docs' endpoint table described: a free
  model Zen lists before they catch up, or every model but the snapshot's
  when either can't be read. A listed id ending in -free with no word from
  either is now asked through the provider's own package
  (openai-compatible, chat), as OpenCode asks a model with no package of
  its own. A paid or unknown id that doesn't say -free still needs the
  catalog; the docs saying SystemOne still keep one out.
- A discovery with the catalog or the docs unread was marked
  magpie.fellBack, though Zen's own list was read. magpie answers a
  fallen-back list by keeping the last list read in full
  (plugin.keepListed), so a user who can't reach GitHub's raw host or the
  catalog kept that old list, and every model Zen made free since stayed
  out. Only a failed read of Zen's /models is fallen back now; models
  verified before are still kept while Zen lists them.

Tests (no network; the fixture server serves
fixtures/zen-models-2026-10-15.json, Zen's /models byte for byte):
- "a free model Zen lists that the catalog and the docs don't describe is
  offered, on chat (#2385)": catalog 503, docs 404 -> the ten free models
  Zen lists (Jev, "test" and the paid ones out), deepseek-v4.1-flash-free
  on chat, muse-spark-1.3 on Responses, not fallen back; a request for it
  goes to /chat/completions
- "... before the catalog has it is offered with the catalog read (#2385)"
- models.test: an unknown -free id is offered on the provider's package,
  "unknown-paid", "freebie" and "free-model" aren't, SystemOne stays out
  (replaces "unknown models require a known protocol rather than a
  guessed chat endpoint")
- two partial-discovery tests now expect no fellBack
Broken by hand: models.mjs back to 0.1.8's -> 3 fail; provider.mjs back
to 0.1.8's -> 3 fail; both fixed: bun test 174 pass, 0 fail (bun 1.4.2).
bun scripts/check.mjs zen-free: ok.

Not tried: a live request to deepseek-v4.1-flash-free through the plugin
(one GET of Zen's /models was the only network used). A future free
model Zen serves on Responses or Messages that the catalog doesn't
describe yet would be offered on chat and refused by Zen until the
catalog has it.

No magpie mover to raise: zen-free isn't a moved built-in, and magpie
updates @magpie-community plugins by itself within the hour.
This commit is contained in:
yetone
2026-10-15 19:46:57 +08:00
parent c59ee33efe
commit da27b4ce6b
7 changed files with 109 additions and 9 deletions
+4 -1
View File
@@ -31,7 +31,10 @@ windows and reasoning levels. Use `opencode-zen-free/<model>`, for example
Retired models and SystemOne models are excluded. The list is asked
again each time the host lists models (magpie does this on start and every
hour): a model Zen no longer gives free leaves it, and a new free one joins
it. When Zen's list can't be read, the last list is kept. A request for a
it. A model Zen lists as `-free` that OpenCode's catalog and docs don't
describe yet (or can't be read) is offered too, on Chat Completions, as
OpenCode asks a model with no package of its own. When Zen's list can't be
read, the last list is kept. A request for a
model that isn't free now gets a 404 naming the free ones; one made free
since the last list is served after the list is asked again (at most once a
minute). Availability and rate limits are set by Zen; the plugin has no
File diff suppressed because one or more lines are too long
+63 -3
View File
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { createServer } from "node:http";
import { once } from "node:events";
import { readFileSync } from "node:fs";
import test from "node:test";
import { protocols, declaredTools, toolReply } from "./tool-fixtures.mjs";
@@ -18,7 +19,10 @@ async function fixture(t, input = {}) {
state.onDiscovery?.();
return;
}
if (req.url === "/v1/models") {
if (req.url === "/v1/models" && state.listing) {
res.writeHead(state.modelsStatus, { "content-type": "application/json" });
res.end(state.listing);
} else if (req.url === "/v1/models") {
res.writeHead(state.modelsStatus, { "content-type": "application/json" });
res.end(
JSON.stringify({
@@ -304,7 +308,9 @@ test("partial catalog failure retains previously verified models rather than dro
state.docsStatus = 503;
const fallback = await plugin.provider.models({ models }, { auth: await publicAuth() });
assert.deepEqual(Object.keys(fallback).sort(), ["chat-free", "messages-free", "responses-free"]);
assert.equal(fallback[Symbol.for("magpie.fellBack")], true);
// Zen's own list was read: not fallen back, so magpie takes this list
// and not the last one read in full (yetone/magpie#2385)
assert.equal(fallback[Symbol.for("magpie.fellBack")], undefined);
});
// The reporter of #2305 (yetone/magpie) saw only the three models the
@@ -322,7 +328,61 @@ test("listed free models are offered when the catalog and the docs can't be read
assert.equal(models["step-5-preview-free"].api.npm, "@ai-sdk/openai-compatible");
assert.equal(models["step-5-preview-free"].name, "Step 5 Preview Free");
assert.equal(models["step-5-preview-free"].limit.context, 1000000);
assert.equal(models[Symbol.for("magpie.fellBack")], true);
assert.equal(models[Symbol.for("magpie.fellBack")], undefined);
});
// yetone/magpie#2385: Zen made deepseek-v4.1-flash-free free, and it was
// never offered. Zen's /models as the public key read it on 2026-10-15,
// byte for byte. Neither the plugin's snapshot nor an unreachable catalog
// or docs describe it, and the list it was in was said as fallen back,
// which magpie answers by keeping the last list read in full.
const zenListing = readFileSync(
new URL("./fixtures/zen-models-2026-10-15.json", import.meta.url),
"utf8",
);
const zenFree = [
"big-pickle",
"cat-jam-free",
"deepseek-v4.1-flash-free",
"longcat-2.5-preview-free",
"mimo-v2.6-flash-free",
"muse-spark-1.2-contributor-free",
"muse-spark-1.3-contributor-free",
"nemotron-3.5-lightning-free",
"space-bunny-free",
"step-5-preview-free",
];
test("a free model Zen lists that the catalog and the docs don't describe is offered, on chat (#2385)", async (t) => {
const { plugin, state } = await fixture(t);
state.listing = zenListing;
state.catalogStatus = 503;
state.docsStatus = 404;
const models = await plugin.provider.models({ models: {} }, { auth: await publicAuth() });
assert.deepEqual(Object.keys(models).sort(), zenFree);
assert.equal(models["deepseek-v4.1-flash-free"].api.npm, "@ai-sdk/openai-compatible");
assert.equal(models["deepseek-v4.1-flash-free"].free, true);
assert.equal(models["muse-spark-1.3-contributor-free"].api.npm, "@ai-sdk/openai");
assert.equal(models[Symbol.for("magpie.fellBack")], undefined);
// a request for it goes to Zen, at chat completions
const options = await plugin.auth.loader(publicAuth);
const response = await options.fetch(`${options.baseURL}/chat/completions`, {
method: "POST",
body: JSON.stringify({ model: "deepseek-v4.1-flash-free", messages: [], stream: true }),
});
assert.equal(response.status, 200);
assert.equal(state.calls.at(-1).url, "/v1/chat/completions");
assert.equal(state.calls.at(-1).body.model, "deepseek-v4.1-flash-free");
});
test("a free model Zen lists before the catalog has it is offered with the catalog read (#2385)", async (t) => {
const { plugin, state } = await fixture(t);
state.listing = zenListing;
const models = await plugin.provider.models({ models: {} }, { auth: await publicAuth() });
assert.equal(models["deepseek-v4.1-flash-free"].api.npm, "@ai-sdk/openai-compatible");
// the fixture's catalog prices "paid" and names nothing of Zen's: no
// paid model Zen lists is offered for being unknown
for (const id of Object.keys(models)) assert.ok(zenFree.includes(id), id);
});
test("forces upstream streaming, preserves existing tools and returns the SSE body unbuffered", async (t) => {
+19 -1
View File
@@ -41,13 +41,31 @@ export function isFree(id, model = {}) {
);
}
// A model Zen lists whose id says it is free (Zen names them "-free"), and
// that neither the catalog nor the docs describe yet: Zen made it free
// after they were last written (deepseek-v4.1-flash-free, yetone/magpie#2385),
// or they couldn't be read. It is asked as OpenCode asks a model with no
// package of its own, through the provider's (openai-compatible, chat), so
// a new free model is offered the hour Zen lists it, not when the catalog
// or this plugin catch up. A paid or zero-cost id the id doesn't call free
// still needs the catalog's word.
function listedFree(id) {
return /-free$/.test(id);
}
export function buildModels(ids, provider, protocols, baseURL) {
const result = {};
for (const id of ids) {
if (typeof id !== "string" || !id || id === "__proto__") continue;
const raw = provider.models?.[id];
const model = raw ?? {};
const protocol = protocols[id] ?? (raw && sdkProtocol(model.provider?.npm ?? provider.npm));
const protocol =
protocols[id] ??
(raw
? sdkProtocol(model.provider?.npm ?? provider.npm)
: listedFree(id)
? (sdkProtocol(provider.npm) ?? "chat")
: undefined);
if (!isFree(id, model) || !Object.hasOwn(SDK, protocol)) continue;
const input = model.modalities?.input ?? ["text"];
const output = model.modalities?.output ?? ["text"];
+16 -2
View File
@@ -60,10 +60,24 @@ test("endpoint documentation overrides inherited SDK and excludes SystemOne", as
assert.equal(models["decision-free"], undefined);
});
test("unknown models require a known protocol rather than a guessed chat endpoint", async () => {
// A model Zen lists as -free before the catalog or the docs describe it is
// asked as the provider's own package asks (chat), as OpenCode asks a model
// with no package of its own (yetone/magpie#2385); anything else unknown
// still needs their word.
test("an unknown -free model is offered on the provider's package; another unknown model is not", async () => {
const { buildModels } = await subject;
assert.equal(typeof buildModels, "function", "model discovery must be implemented");
assert.deepEqual(Object.keys(buildModels(["new-free", "unknown-paid"], {}, {}, baseURL)), []);
assert.deepEqual(
Object.keys(buildModels(["new-free", "unknown-paid", "freebie", "free-model"], {}, {}, baseURL)),
["new-free"],
);
assert.equal(buildModels(["new-free"], {}, {}, baseURL)["new-free"].api.npm, "@ai-sdk/openai-compatible");
assert.equal(
buildModels(["new-free"], { npm: "@ai-sdk/openai" }, {}, baseURL)["new-free"].api.npm,
"@ai-sdk/openai",
);
// the docs saying SystemOne keep it out
assert.deepEqual(Object.keys(buildModels(["new-free"], {}, { "new-free": "systemone" }, baseURL)), []);
const models = buildModels(["new-free"], {}, { "new-free": "chat" }, baseURL);
assert.equal(models["new-free"].api.url, baseURL);
assert.equal(models["new-free"].cost.input, 0);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zen-free-auth",
"version": "0.1.8",
"version": "0.1.9",
"description": "OpenCode Zen free models through the public credential, with native streaming protocols",
"type": "module",
"main": "./index.mjs",
+5 -1
View File
@@ -228,7 +228,11 @@ async function server(_input, options = {}) {
discovered[id] = known[id];
}
}
discovered[Symbol.for("magpie.fellBack")] = true;
// Not said as fallen back: Zen's own list was read, and what it
// lists is what is offered. Said so, magpie kept the last list read
// in full instead, and a user who can't reach the catalog or the
// docs (GitHub's raw host, from mainland China) never saw a model
// Zen made free since (yetone/magpie#2385).
}
known = discovered;
listed = true;