cline 0.1.3: a pinUpstream option sends DeepSeek's models through DeepSeek's own API only, as magpie's built-in ClinePass tick does (ARNO on magpie's Discord) — with it on (the plugin's own options, or OpenCode's provider.cline.options.pinUpstream), a chat request for a DeepSeek model (cline-pass/deepseek-…, not cline-free/) carries "providerOptions":{"gateway":{"only":["deepseek"]}}, written in before the body's last } so the cached prefix is the client's byte for byte. Other models, and a request with providerOptions of its own, go as sent; off by default. README says how to turn it on in magpie and OpenCode. 5 new tests fail on 0.1.2; bun test (63 pass) and bun scripts/check.mjs cline pass.

This commit is contained in:
yetone
2026-10-05 12:42:21 +08:00
parent 4c4e91689e
commit 98ce4a8dc0
4 changed files with 100 additions and 3 deletions
+15
View File
@@ -53,6 +53,21 @@ apart too. The model list is read from
needs a sign-in); usage reads `/api/v1/users/me` and the account's `/balance`
(its balance is counted in millionths of a dollar).
### DeepSeek models only through DeepSeek's own API
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
`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 OpenCode: `"provider": {"cline": {"options": {"pinUpstream": true}}}` in
`opencode.json`, or the plugin's own options:
`"plugin": [["@magpie-community/opencode-cline-auth", {"pinUpstream": true}]]`.
## Models
The list is Cline's own, merged from the two feeds its clients read: the
+35 -2
View File
@@ -674,7 +674,34 @@ function usageOf(me, balance) {
// ---- the plugin --------------------------------------------------------------------
export const ClinePlugin = async ({ client } = {}) => {
// 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.
function pinned(on, model) {
if (!on || typeof model !== "string" || model.startsWith("cline-free/")) return ""
return model.slice(model.lastIndexOf("/") + 1).toLowerCase().startsWith("deepseek") ? "deepseek" : ""
}
// pinBody is the request's body with providerOptions.gateway.only set to the
// pinned upstream, written in at the end so the rest of the body — the
// prefix a cache matches — is the client's byte for byte. A body that has
// providerOptions of its own is the client's to keep.
function pinBody(body, chat, on) {
const up = pinned(on, chat?.model)
if (!up || chat.providerOptions !== undefined) return body
const end = body.lastIndexOf("}")
if (end < 0) return body
const head = body.slice(0, end)
const sep = /[{,]\s*$/.test(head) ? "" : ","
return head + sep + `"providerOptions":${JSON.stringify({ gateway: { only: [up] } })}` + body.slice(end)
}
// isOn is whether an option is set: true, or "true" in a config written by hand
const isOn = (v) => v === true || v === "true"
export const ClinePlugin = async ({ client } = {}, options = {}) => {
// the accounts fresh renewed this run: the sign-in mark comes off on the
// renewed token, whatever the request then met
const renewals = new WeakSet()
@@ -845,8 +872,11 @@ export const ClinePlugin = async ({ client } = {}) => {
return out
}),
async loader(getAuth) {
async loader(getAuth, provider) {
const a = await getAuth()
// pinUpstream: the plugin's own option, or the provider's in
// OpenCode's config (provider.cline.options.pinUpstream)
const pin = isOn(options?.pinUpstream) || isOn(provider?.options?.pinUpstream)
if (a?.type !== "oauth" && a?.type !== "api") return {}
return {
baseURL: API,
@@ -862,6 +892,7 @@ export const ClinePlugin = async ({ client } = {}) => {
body = await bodyText(input, init)
const chat = JSON.parse(body)
if (!chat || typeof chat !== "object" || Array.isArray(chat)) throw new Error("not a chat completion")
body = pinBody(body, chat, pin)
} catch {
return errorResponse({ status: 400, message: "a request that isn't a chat completion" })
}
@@ -939,6 +970,8 @@ export const _internal = {
failure,
errorResponse,
bodyText,
pinned,
pinBody,
unwrapped,
clientHeaders,
deviceAuthorize,
+49
View File
@@ -885,3 +885,52 @@ test("an auth entry is read the same however it was stored", () => {
expect(authOf({ type: "api", key: "k" }).type).toBe("api")
expect(authOf(null).type).toBe("oauth")
})
// ---- pinUpstream: DeepSeek's models only through DeepSeek's own API -------------
test("pinBody pins a DeepSeek model to DeepSeek's API, keeping the body's prefix", () => {
const { pinBody, pinned } = _internal
const body = `{"model":"cline-pass/deepseek-v4.1-flash","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: ["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)
expect(pinned(true, "DeepSeek/DeepSeek-V4-Pro")).toBe("deepseek")
expect(JSON.parse(pinBody(`{}`, {}, true))).toEqual({})
})
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 () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c }, plugin)
serve([
[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/kimi-k3", messages: [] }))
expect(JSON.parse(calls[0].init.body).providerOptions).toEqual({ gateway: { only: ["deepseek"] } })
expect(JSON.parse(calls[1].init.body).providerOptions).toBeUndefined()
})
}
test("without pinUpstream a DeepSeek request goes as sent", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([[chatUrl, () => Response.json({ ok: true })]])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const sent = { model: "cline-pass/deepseek-v4-pro", messages: [] }
await l.fetch(chatUrl, chatInit(sent))
expect(calls[0].init.body).toBe(JSON.stringify(sent))
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cline-auth",
"version": "0.1.2",
"version": "0.1.3",
"description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",