zen-free 0.1.7: free models answer again, asked at opencode.ai/inference/v1 with stand-in tools that take a parameter (c9cu on Discord)
c9cu on magpie v0.1.1239: "opencode muse 1.3 又不行了". Every free model answered 403 FreeTierError "OpenCode's free tier can only be used from within OpenCode" through 0.1.6 and magpie's built-in alike. Found against the real upstream on 2026-10-15, with OpenCode 1.19.0's own requests captured through a local proxy under a sandbox HOME: - OpenCode now asks https://opencode.ai/inference/v1 (models.dev gives it this URL). Its own captured request, replayed word for word, is 200 there and 403 at /zen/v1. - Zen also refuses bash or read offered with no parameters, as the stand-ins here were ({"properties":{}}); one property is enough. Now: - DEFAULT_BASE is the inference API. A request still sent to a model listed at /zen/v1 is accepted and asked at the inference API. - Each stand-in takes OpenCode's own first parameter (bash command, read/edit filePath, glob/grep pattern), still "Never call this tool". Run: - bun test in packages/zen-free: 170 pass. With 0.1.6's provider.mjs put back by hand: 13 fail (the 12 tool-guard tests on the stand-ins' parameters, and the new inference-API test). - bun tools-smoke.mjs against the real Zen: big-pickle, mimo-v2.6-flash-free and muse-spark-1.3-contributor-free, streamed and not, all 200 with a Bash call. - npm shows 0.1.1 as latest: publish runs refused this package (no Trusted Publisher), so 0.1.2 to 0.1.6 never reached users; 4ef68fb's NPM_TOKEN path is what publishes this one.
This commit is contained in:
@@ -39,7 +39,7 @@ remaining-quota data.
|
||||
|
||||
## Requests
|
||||
|
||||
Requests go to `https://opencode.ai/zen/v1` using each model's native
|
||||
Requests go to `https://opencode.ai/inference/v1` using each model's native
|
||||
Chat Completions, Responses or Anthropic Messages API. Streaming and
|
||||
ordinary JSON replies are supported.
|
||||
|
||||
|
||||
@@ -119,7 +119,8 @@ for (const { protocol, path, model } of protocols) {
|
||||
const tool = protocol === "chat" ? raw.function : raw;
|
||||
assert.match(tool.description, /Not available\. Never call this tool\./);
|
||||
assert.equal((tool.parameters ?? tool.input_schema).additionalProperties, false);
|
||||
assert.deepEqual((tool.parameters ?? tool.input_schema).properties, {});
|
||||
// Zen's free tier refuses a bash or read that takes nothing
|
||||
assert.equal(Object.keys((tool.parameters ?? tool.input_schema).properties).length, 1);
|
||||
}
|
||||
// A call of a tool the agent doesn't have is left out, said in
|
||||
// the reply's text, and the turn ends as a stop rather than
|
||||
@@ -518,3 +519,42 @@ test("a Chat stream Zen closes before its [DONE] ends cut short for a streaming
|
||||
assert.notEqual(whole.status, 200);
|
||||
assert.match(await whole.text(), /without a completion marker \(reply x2, 3 events/);
|
||||
});
|
||||
|
||||
// Zen's free tier answers only at the inference API since mid-October 2026
|
||||
// (403 FreeTierError at /zen/v1 to OpenCode's own request); a model listed
|
||||
// before then, whose URL is /zen/v1, is asked there too.
|
||||
test("asks the inference API, also for a model listed at /zen/v1", async (t) => {
|
||||
const { default: plugin } = await subject;
|
||||
const realFetch = globalThis.fetch;
|
||||
const asked = [];
|
||||
globalThis.fetch = async (input, init) => {
|
||||
const url = String(input instanceof Request ? input.url : input);
|
||||
asked.push(url);
|
||||
if (url.endsWith("/models"))
|
||||
return Response.json({ data: [{ id: "big-pickle" }] });
|
||||
if (url.endsWith("/chat/completions"))
|
||||
return new Response('data: {"choices":[{"index":0,"delta":{"content":"pong"}}]}\n\ndata: [DONE]\n\n', {
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
});
|
||||
return new Response("", { status: 500 });
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.fetch = realFetch;
|
||||
});
|
||||
const hooks = await plugin.server({ project: { id: "x" } });
|
||||
const loader = await hooks.auth.loader(async () => ({ type: "api", key: "public" }));
|
||||
assert.equal(loader.baseURL, "https://opencode.ai/inference/v1");
|
||||
for (const url of [
|
||||
"https://opencode.ai/zen/v1/chat/completions",
|
||||
"https://opencode.ai/inference/v1/chat/completions",
|
||||
]) {
|
||||
const response = await loader.fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ model: "big-pickle", stream: true, messages: [] }),
|
||||
});
|
||||
assert.equal(response.status, 200);
|
||||
await response.text();
|
||||
assert.equal(asked.at(-1), "https://opencode.ai/inference/v1/chat/completions");
|
||||
}
|
||||
assert.ok(!asked.some((url) => url.startsWith("https://opencode.ai/zen/")), asked.join("\n"));
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zen-free-auth",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"description": "OpenCode Zen free models through the public credential, with native streaming protocols",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -10,12 +10,26 @@ import {
|
||||
import { collapseResponse } from "./stream.mjs";
|
||||
import { guardToolResponse } from "./tool-response.mjs";
|
||||
|
||||
const DEFAULT_BASE = "https://opencode.ai/zen/v1";
|
||||
// Zen's free models answer only at the inference API since mid-October
|
||||
// 2026: the same request OpenCode 1.19.0 sends answers 403 FreeTierError
|
||||
// at /zen/v1 and 200 here, and models.dev gives OpenCode this URL. A model
|
||||
// listed before then still names /zen/v1 (LEGACY_BASE), which is asked here.
|
||||
const DEFAULT_BASE = "https://opencode.ai/inference/v1";
|
||||
const LEGACY_BASE = "https://opencode.ai/zen/v1";
|
||||
const CATALOG = "https://models.opencode.ai/api.json";
|
||||
const DOCS =
|
||||
"https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/web/src/content/docs/zen.mdx";
|
||||
const PATHS = { chat: "/chat/completions", responses: "/responses", anthropic: "/messages" };
|
||||
const CORE_TOOLS = ["bash", "edit", "glob", "grep", "read"];
|
||||
// The parameter each stand-in takes, OpenCode's own first one: Zen's free
|
||||
// tier answers 403 FreeTierError to bash or read offered with none.
|
||||
const CORE_PARAMETER = {
|
||||
bash: "command",
|
||||
edit: "filePath",
|
||||
glob: "pattern",
|
||||
grep: "pattern",
|
||||
read: "filePath",
|
||||
};
|
||||
const OPENCODE_VERSION = "1.19.0";
|
||||
// What OpenCode 1.19.0 sends as its User-Agent, ai-sdk and Bun included.
|
||||
// Each protocol's ai-sdk package bundles its own provider-utils, so the
|
||||
@@ -76,7 +90,11 @@ function normalizeTools(body, protocol) {
|
||||
}
|
||||
for (const name of CORE_TOOLS) {
|
||||
if (present.has(name)) continue;
|
||||
const parameters = { type: "object", properties: {}, additionalProperties: false };
|
||||
const parameters = {
|
||||
type: "object",
|
||||
properties: { [CORE_PARAMETER[name]]: { type: "string" } },
|
||||
additionalProperties: false,
|
||||
};
|
||||
const definition = { name, description: "Not available. Never call this tool." };
|
||||
body.tools.push(
|
||||
protocol === "chat"
|
||||
@@ -245,7 +263,9 @@ async function server(_input, options = {}) {
|
||||
requirePublic(await getAuth());
|
||||
const request = new Request(input, init);
|
||||
const protocol = Object.keys(PATHS).find(
|
||||
(key) => request.url === `${baseURL}${PATHS[key]}`,
|
||||
(key) =>
|
||||
request.url === `${baseURL}${PATHS[key]}` ||
|
||||
(baseURL === DEFAULT_BASE && request.url === `${LEGACY_BASE}${PATHS[key]}`),
|
||||
);
|
||||
if (!protocol || request.method !== "POST")
|
||||
throw new Error("Unsupported Zen endpoint or method");
|
||||
@@ -313,7 +333,7 @@ async function server(_input, options = {}) {
|
||||
} else {
|
||||
headers.set("authorization", "Bearer public");
|
||||
}
|
||||
const response = await fetch(request.url, {
|
||||
const response = await fetch(`${baseURL}${PATHS[protocol]}`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
|
||||
Reference in New Issue
Block a user