From ff13aac87dfe1c86b7915badef42cb9046588059 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 19 Oct 2026 18:40:42 +0800 Subject: [PATCH] cline 0.1.9: pinUpstream pins GLM models to Z.ai's own API too (sdytman on Discord) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sdytman (#feedback, 10-19): "clinepass供应商现在可以勾选deepseek模型只走deepseek官方上游,建议glm也加一个勾选选项,只走z.ai上游". With pinUpstream on, a request for a GLM model (cline-pass/glm-5.3, cline-pass/glm-5.3-flash, any non-free id whose name starts with glm) now carries "providerOptions":{"gateway":{"only":["zai"]}}, as a DeepSeek one carries ["deepseek"]. cline-free/ models, other makers' models and a body with providerOptions of its own go as sent. One option covers both: it means "the maker's own API" for each. The slug: Cline's gateway is Vercel's AI Gateway (the ProviderPin author on linux.do/t/topic/2918145: "锁在Vercel的DeepSeek官转上"; providerOptions.gateway.only is that gateway's option). ai-gateway.vercel.sh/v1/models/zai/glm-5.3/endpoints and .../zai/glm-5.3-flash/endpoints list provider_name "zai" (and deepseek/deepseek-v4-pro lists "deepseek", the slug already pinned). Not tried with a real ClinePass key (none on this machine). Run: bun test packages/cline/index.test.mjs, 75 pass; the whole suite (TMPDIR and HOME under a scratch dir) 1825 pass, 0 fail; bun scripts/check.mjs ok. Broken by hand, each goes red: no glm entry (3 tests), cline-free/ not skipped (1), every maker pinned to zai (3), the client's providerOptions overwritten (1). --- packages/cline/README.md | 9 ++++---- packages/cline/index.mjs | 23 +++++++++++++++------ packages/cline/index.test.mjs | 39 +++++++++++++++++++++++++++-------- packages/cline/package.json | 2 +- 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/packages/cline/README.md b/packages/cline/README.md index 89ee9a7..dd07535 100644 --- a/packages/cline/README.md +++ b/packages/cline/README.md @@ -67,12 +67,13 @@ the balance, and limits read are kept when the balance can't be. Cline's gateway picks among the providers that serve a model. With the `pinUpstream` option on, a request for a DeepSeek model (`cline-pass/deepseek-…`, not the `cline-free/` ones) carries `"providerOptions": {"gateway": {"only": -["deepseek"]}}`, so it is answered by DeepSeek's own API only — the same as -magpie's built-in ClinePass tick. Other models, and a request with +["deepseek"]}}`, so it is answered by DeepSeek's own API only, and one for a +GLM model (`cline-pass/glm-…`) carries `["zai"]`, so it is answered by Z.ai's +own API only — the same as magpie's built-in ClinePass tick. Other models, and a request with `providerOptions` of its own, go as sent. It is off by default. Turn it on: -- in magpie: the provider's editor › Upstream › tick "DeepSeek models only - through DeepSeek's own upstream"; +- in magpie: the provider's editor › Upstream › tick "DeepSeek and GLM + models only from their makers' own APIs"; - in OpenCode: `"provider": {"cline": {"options": {"pinUpstream": true}}}` in `opencode.json`, or the plugin's own options: `"plugin": [["@magpie-community/opencode-cline-auth", {"pinUpstream": true}]]`. diff --git a/packages/cline/index.mjs b/packages/cline/index.mjs index d8b3f5a..dcbf67a 100644 --- a/packages/cline/index.mjs +++ b/packages/cline/index.mjs @@ -774,14 +774,25 @@ function usageOf(me, balance, limits) { // ---- the plugin -------------------------------------------------------------------- -// pinned is the upstream a DeepSeek model of Cline's is pinned to when the -// pinUpstream option is on (magpie's built-in ClinePass has the same tick): -// Cline's gateway otherwise picks among the providers serving the model, and -// some answer DeepSeek's models worse than DeepSeek's own API. A cline-free/ -// model is left to Cline, as is every model that isn't DeepSeek's. +// MAKERS maps a model name's start to its maker's own upstream on Cline's +// gateway (Vercel's AI Gateway, whose provider slugs these are: +// ai-gateway.vercel.sh/v1/models//endpoints lists "deepseek" for +// deepseek/deepseek-v4-pro and "zai" for zai/glm-5.3) +const MAKERS = [ + ["deepseek", "deepseek"], + ["glm", "zai"], +] + +// pinned is the upstream a DeepSeek or GLM model of Cline's is pinned to when +// the pinUpstream option is on (magpie's built-in ClinePass has the same +// tick): DeepSeek's own API for DeepSeek's, Z.ai's for GLM. Cline's gateway +// otherwise picks among the providers serving the model, and some answer +// worse than the maker's own API, which also keeps the prompt cache. A +// cline-free/ model is left to Cline, as is every other maker's model. function pinned(on, model) { if (!on || typeof model !== "string" || model.startsWith("cline-free/")) return "" - return model.slice(model.lastIndexOf("/") + 1).toLowerCase().startsWith("deepseek") ? "deepseek" : "" + const name = model.slice(model.lastIndexOf("/") + 1).toLowerCase() + return MAKERS.find(([prefix]) => name.startsWith(prefix))?.[1] ?? "" } // pinBody is the request's body with providerOptions.gateway.only set to the diff --git a/packages/cline/index.test.mjs b/packages/cline/index.test.mjs index a7a0f89..9f1755c 100644 --- a/packages/cline/index.test.mjs +++ b/packages/cline/index.test.mjs @@ -1122,7 +1122,7 @@ test("an auth entry is read the same however it was stored", () => { expect(authOf(null).type).toBe("oauth") }) -// ---- pinUpstream: DeepSeek's models only through DeepSeek's own API ------------- +// ---- pinUpstream: DeepSeek's and GLM's models only through their makers' APIs -- test("pinBody pins a DeepSeek model to DeepSeek's API, keeping the body's prefix", () => { const { pinBody, pinned } = _internal @@ -1132,32 +1132,53 @@ test("pinBody pins a DeepSeek model to DeepSeek's API, keeping the body's prefix expect(JSON.parse(out).providerOptions).toEqual({ gateway: { only: ["deepseek"] } }) // off, another vendor's model, a free model, or the client's own options: as sent expect(pinBody(body, JSON.parse(body), false)).toBe(body) - const glm = `{"model":"cline-pass/glm-5.3"}` - expect(pinBody(glm, JSON.parse(glm), true)).toBe(glm) - const free = `{"model":"cline-free/deepseek-v4.1-flash"}` - expect(pinBody(free, JSON.parse(free), true)).toBe(free) - const own = `{"model":"deepseek/deepseek-v4-pro","providerOptions":{"gateway":{"only":["fireworks"]}}}` - expect(pinBody(own, JSON.parse(own), true)).toBe(own) + for (const m of ["cline-pass/kimi-k3", "cline-pass/qwen3.8-max", "anthropic/claude-sonnet-5.5"]) { + const other = `{"model":"${m}"}` + expect(pinBody(other, JSON.parse(other), true)).toBe(other) + } + for (const m of ["cline-free/deepseek-v4.1-flash", "cline-free/glm-5.3-flash"]) { + const free = `{"model":"${m}"}` + expect(pinBody(free, JSON.parse(free), true)).toBe(free) + } + for (const own of [ + `{"model":"deepseek/deepseek-v4-pro","providerOptions":{"gateway":{"only":["fireworks"]}}}`, + `{"model":"cline-pass/glm-5.3","providerOptions":{"gateway":{"order":["novita"]}}}`, + ]) expect(pinBody(own, JSON.parse(own), true)).toBe(own) expect(pinned(true, "DeepSeek/DeepSeek-V4-Pro")).toBe("deepseek") expect(JSON.parse(pinBody(`{}`, {}, true))).toEqual({}) }) +test("pinBody pins a GLM model to Z.ai's API, keeping the body's prefix", () => { + const { pinBody, pinned } = _internal + for (const m of ["cline-pass/glm-5.3", "cline-pass/glm-5.3-flash"]) { + const body = `{"model":"${m}","messages":[{"role":"user","content":"hi"}],"stream":true}` + const out = pinBody(body, JSON.parse(body), true) + expect(out.startsWith(body.slice(0, -1))).toBe(true) + expect(JSON.parse(out).providerOptions).toEqual({ gateway: { only: ["zai"] } }) + expect(pinBody(body, JSON.parse(body), false)).toBe(body) + } + expect(pinned(true, "z-ai/GLM-5.3")).toBe("zai") +}) + for (const [how, plugin, provider] of [ ["the plugin's own option", { pinUpstream: true }, undefined], ["OpenCode's provider.cline.options", undefined, { id: "cline", options: { pinUpstream: true } }], ]) { - test(`pinUpstream set as ${how} pins DeepSeek requests, and only them`, async () => { + test(`pinUpstream set as ${how} pins DeepSeek and GLM requests, and only them`, async () => { const { client: c } = client() const hooks = await ClinePlugin({ client: c }, plugin) serve([ [chatUrl, () => Response.json({ ok: true })], [chatUrl, () => Response.json({ ok: true })], + [chatUrl, () => Response.json({ ok: true })], ]) const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), provider) await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4-pro", messages: [] })) + await l.fetch(chatUrl, chatInit({ model: "cline-pass/glm-5.3", messages: [] })) await l.fetch(chatUrl, chatInit({ model: "cline-pass/kimi-k3", messages: [] })) expect(JSON.parse(calls[0].init.body).providerOptions).toEqual({ gateway: { only: ["deepseek"] } }) - expect(JSON.parse(calls[1].init.body).providerOptions).toBeUndefined() + expect(JSON.parse(calls[1].init.body).providerOptions).toEqual({ gateway: { only: ["zai"] } }) + expect(JSON.parse(calls[2].init.body).providerOptions).toBeUndefined() }) } diff --git a/packages/cline/package.json b/packages/cline/package.json index 4baf784..7e0b4f5 100644 --- a/packages/cline/package.json +++ b/packages/cline/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cline-auth", - "version": "0.1.8", + "version": "0.1.9", "description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie", "type": "module", "main": "./index.mjs",