cline 0.1.9: pinUpstream pins GLM models to Z.ai's own API too (sdytman on Discord)

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).
This commit is contained in:
yetone
2026-10-19 18:40:54 +08:00
parent 5f101a5447
commit ff13aac87d
4 changed files with 53 additions and 20 deletions
+5 -4
View File
@@ -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 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-…`, `pinUpstream` option on, a request for a DeepSeek model (`cline-pass/deepseek-…`,
not the `cline-free/` ones) carries `"providerOptions": {"gateway": {"only": not the `cline-free/` ones) carries `"providerOptions": {"gateway": {"only":
["deepseek"]}}`, so it is answered by DeepSeek's own API only — the same as ["deepseek"]}}`, so it is answered by DeepSeek's own API only, and one for a
magpie's built-in ClinePass tick. Other models, and a request with 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: `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 - in magpie: the provider's editor › Upstream › tick "DeepSeek and GLM
through DeepSeek's own upstream"; models only from their makers' own APIs";
- in OpenCode: `"provider": {"cline": {"options": {"pinUpstream": true}}}` in - in OpenCode: `"provider": {"cline": {"options": {"pinUpstream": true}}}` in
`opencode.json`, or the plugin's own options: `opencode.json`, or the plugin's own options:
`"plugin": [["@magpie-community/opencode-cline-auth", {"pinUpstream": true}]]`. `"plugin": [["@magpie-community/opencode-cline-auth", {"pinUpstream": true}]]`.
+17 -6
View File
@@ -774,14 +774,25 @@ function usageOf(me, balance, limits) {
// ---- the plugin -------------------------------------------------------------------- // ---- the plugin --------------------------------------------------------------------
// pinned is the upstream a DeepSeek model of Cline's is pinned to when the // MAKERS maps a model name's start to its maker's own upstream on Cline's
// pinUpstream option is on (magpie's built-in ClinePass has the same tick): // gateway (Vercel's AI Gateway, whose provider slugs these are:
// Cline's gateway otherwise picks among the providers serving the model, and // ai-gateway.vercel.sh/v1/models/<model>/endpoints lists "deepseek" for
// some answer DeepSeek's models worse than DeepSeek's own API. A cline-free/ // deepseek/deepseek-v4-pro and "zai" for zai/glm-5.3)
// model is left to Cline, as is every model that isn't DeepSeek's. 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) { function pinned(on, model) {
if (!on || typeof model !== "string" || model.startsWith("cline-free/")) return "" 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 // pinBody is the request's body with providerOptions.gateway.only set to the
+30 -9
View File
@@ -1122,7 +1122,7 @@ test("an auth entry is read the same however it was stored", () => {
expect(authOf(null).type).toBe("oauth") 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", () => { test("pinBody pins a DeepSeek model to DeepSeek's API, keeping the body's prefix", () => {
const { pinBody, pinned } = _internal 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"] } }) 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 // 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) expect(pinBody(body, JSON.parse(body), false)).toBe(body)
const glm = `{"model":"cline-pass/glm-5.3"}` for (const m of ["cline-pass/kimi-k3", "cline-pass/qwen3.8-max", "anthropic/claude-sonnet-5.5"]) {
expect(pinBody(glm, JSON.parse(glm), true)).toBe(glm) const other = `{"model":"${m}"}`
const free = `{"model":"cline-free/deepseek-v4.1-flash"}` expect(pinBody(other, JSON.parse(other), true)).toBe(other)
expect(pinBody(free, JSON.parse(free), true)).toBe(free) }
const own = `{"model":"deepseek/deepseek-v4-pro","providerOptions":{"gateway":{"only":["fireworks"]}}}` for (const m of ["cline-free/deepseek-v4.1-flash", "cline-free/glm-5.3-flash"]) {
expect(pinBody(own, JSON.parse(own), true)).toBe(own) 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(pinned(true, "DeepSeek/DeepSeek-V4-Pro")).toBe("deepseek")
expect(JSON.parse(pinBody(`{}`, {}, true))).toEqual({}) 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 [ for (const [how, plugin, provider] of [
["the plugin's own option", { pinUpstream: true }, undefined], ["the plugin's own option", { pinUpstream: true }, undefined],
["OpenCode's provider.cline.options", undefined, { id: "cline", options: { pinUpstream: true } }], ["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 { client: c } = client()
const hooks = await ClinePlugin({ client: c }, plugin) const hooks = await ClinePlugin({ client: c }, plugin)
serve([ serve([
[chatUrl, () => Response.json({ ok: true })], [chatUrl, () => Response.json({ ok: true })],
[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) 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/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: [] })) 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[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()
}) })
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@magpie-community/opencode-cline-auth", "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", "description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie",
"type": "module", "type": "module",
"main": "./index.mjs", "main": "./index.mjs",