Files
plugins/packages/zen-free/models.test.mjs
T
yetone cbff94eb43 zen-free 0.1.8: the free models Zen lists are offered again when OpenCode's docs or catalog can't be read, and the docs are read from where they moved (yetone/magpie#2305, MiniFullC)
The reporter, on 0.1.7 with the public key, saw only Big Pickle, Space
Bunny Free and Muse Spark 1.3 Free: the three models the plugin knows
offline. Two causes:

- DOCS pointed at packages/web/src/content/docs/zen.mdx, which OpenCode
  removed on 2026-10-12 (anomalyco/opencode#54761, "replace old Zen and Go
  pages with V2 console docs"). It answers 404, so every discovery since
  was partial. The endpoint table now lives in
  services/www/src/docs/content/console/models.mdx; parseProtocolDocs
  reads its rows as they are.
- A listed model the catalog (models.opencode.ai) didn't describe and the
  docs didn't name was left out. When the catalog can't be read, that is
  every listed model but the three in bootstrapProvider, which is the
  reporter's list exactly. bootstrapProtocols is now a snapshot of the
  console docs' free rows (2026-10-15), used under whatever the docs say,
  and bootstrapProvider gains the catalog's metadata for Cat Jam, Step 5
  Preview, LongCat 2.5 Preview, MiMo-V2.6-Flash and Nemotron 3.5
  Lightning Free.

Not changed, on purpose: jev-1.13-free is a SystemOne decision model
(docs: endpoint /v1/systemone, no AI SDK package), which can't answer a
chat, so it stays out as SystemOne models always have. exo-free is
"deprecated" in the catalog and not in Zen's /models list now.

Tests (no network; the fixture server): "listed free models are offered
when the catalog and the docs can't be read" (catalog 503, docs 404,
listing big-pickle, step-5-preview-free, cat-jam-free, jev-1.13-free,
paid -> the three free chat models only) and "reads the console docs'
endpoint table, and Jev stays out as SystemOne" (literal rows from the new
page). Both fail on 0.1.7's models.mjs/provider.mjs (2 fail, 170 pass)
and pass with the change; bun test: 172 pass. bun scripts/check.mjs ok.

Real use (live Zen, public key, this checkout): discovery now lists
big-pickle cat-jam-free longcat-2.5-preview-free mimo-v2.6-flash-free
muse-spark-1.3-contributor-free nemotron-3.5-lightning-free
space-bunny-free step-5-preview-free, not fallen back (0.1.7: the same
eight with the docs 404 marking it partial). A request to cat-jam-free
through the plugin's fetch streamed 200; step-5-preview-free answered
Zen's own 429 "Upstream request failed: Endpoint is unavailable." twice.
The reporter's catalog failure itself wasn't reproduced from here.
2026-10-15 12:08:28 +08:00

102 lines
5.3 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
const subject = import("./models.mjs").catch(() => ({}));
const provider = {
npm: "@ai-sdk/openai-compatible",
models: {
"coder-free": {
name: "Coder Free",
cost: { input: 0, output: 0 },
limit: { context: 200000, input: 160000, output: 32000 },
reasoning: true,
tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
reasoning_options: [{ type: "effort", values: ["low", "high"] }],
},
"zero-cost": { cost: { input: 0, output: 0 } },
paid: { cost: { input: 1, output: 3 } },
"old-free": { status: "deprecated", cost: { input: 0, output: 0 } },
"decision-free": { provider: { npm: "@vendor/systemone" } },
"responses-free": { provider: { npm: "@ai-sdk/openai" } },
"messages-free": { provider: { npm: "@ai-sdk/anthropic" } },
"gone-free": {},
},
};
const ids = Object.keys(provider.models).filter((id) => id !== "gone-free");
const baseURL = "https://opencode.ai/zen/v1";
test("lists only live free models with supported protocols and excludes retired models", async () => {
const { buildModels } = await subject;
assert.equal(typeof buildModels, "function", "model discovery must be implemented");
const models = buildModels(ids, provider, {}, baseURL);
assert.deepEqual(Object.keys(models).sort(), [
"coder-free",
"messages-free",
"responses-free",
"zero-cost",
]);
assert.equal(models["coder-free"].free, true);
assert.equal(models["coder-free"].providerID, "opencode-zen-free");
assert.deepEqual(models["coder-free"].limit, { context: 200000, input: 160000, output: 32000 });
assert.equal(models["coder-free"].capabilities.input.image, true);
assert.equal(models["coder-free"].capabilities.toolcall, true);
assert.deepEqual(Object.keys(models["coder-free"].variants), ["low", "high"]);
assert.equal(models["responses-free"].api.npm, "@ai-sdk/openai");
assert.equal(models["messages-free"].api.npm, "@ai-sdk/anthropic");
});
test("endpoint documentation overrides inherited SDK and excludes SystemOne", async () => {
const { buildModels, parseProtocolDocs } = await subject;
assert.equal(typeof parseProtocolDocs, "function", "protocol parsing must be implemented");
const protocols = parseProtocolDocs(
[
"| Coder | coder-free | `https://opencode.ai/zen/v1/messages` | sdk |",
"| Decision | decision-free | `https://opencode.ai/zen/v1/systemone` | - |",
].join("\n"),
);
const models = buildModels(ids, provider, protocols, baseURL);
assert.equal(models["coder-free"].api.npm, "@ai-sdk/anthropic");
assert.equal(models["decision-free"], undefined);
});
test("unknown models require a known protocol rather than a guessed chat endpoint", 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)), []);
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);
});
// Rows as OpenCode's console docs have them since 2026-10-12
// (services/www/src/docs/content/console/models.mdx), and the pricing
// table beside it that names no endpoint (#2305 on yetone/magpie).
const consoleDocs = [
"| Claude Haiku 4.5 | claude-haiku-4-5 | `https://opencode.ai/inference/v1/messages` | `@ai-sdk/anthropic` |",
"| Gemini 3 Flash | gemini-3-flash | `https://opencode.ai/inference/v1/models/gemini-3-flash` | `@ai-sdk/google` |",
"| Jev 1.13 Free | jev-1.13-free | `https://opencode.ai/inference/v1/systemone` | - |",
"| Big Pickle | big-pickle | `https://opencode.ai/inference/v1/chat/completions` | `@ai-sdk/openai-compatible` |",
"| Step 5 Preview Free | step-5-preview-free | `https://opencode.ai/inference/v1/chat/completions` | `@ai-sdk/openai-compatible` |",
"| Muse Spark 1.3 Contributor Free | muse-spark-1.3-contributor-free | `https://opencode.ai/inference/v1/responses` | `@ai-sdk/openai` |",
"| Step 5 Preview Free | Free | Free | Free | - |",
].join("\n");
test("reads the console docs' endpoint table, and Jev stays out as SystemOne", async () => {
const { buildModels, parseProtocolDocs, bootstrapProtocols } = await subject;
const protocols = parseProtocolDocs(consoleDocs);
assert.deepEqual(protocols, {
"claude-haiku-4-5": "anthropic",
"jev-1.13-free": "systemone",
"big-pickle": "chat",
"step-5-preview-free": "chat",
"muse-spark-1.3-contributor-free": "responses",
});
// the snapshot kept for when the docs can't be read says the same
for (const [id, protocol] of Object.entries(protocols)) {
if (bootstrapProtocols[id]) assert.equal(bootstrapProtocols[id], protocol, id);
}
const models = buildModels(["jev-1.13-free", "step-5-preview-free"], {}, protocols, baseURL);
assert.deepEqual(Object.keys(models), ["step-5-preview-free"]);
});