cline 0.1.11: ClinePass's DeepSeek models are pinned to DeepSeek's own API by default, with only + has, and go once more unpinned if the pin can't be served (hy125245 on X)

hy125245 (X, 10-23) pinned Cline Pass to DeepSeek by hand with magpie's
extra body, `"!providerOptions": {"gateway": {"only": ["deepseek"],
"has": ["vision", "implicit-caching"]}}` on a plain API provider for
https://api.cline.bot/api/v1, model cline-pass/deepseek-v4.1-flash-1017.
Their finding: on ClinePass the server's virtual model config wins over
`only` alone (a fake upstream was served too); with `has` beside it the
request went to DeepSeek (finalProvider "deepseek", magpie's Requests
list "vmc/deepseek-v4p1-flash … 上游: de…", ~200-246 tok/s, 3 of 3) and
a fake upstream was refused with "no matching upstream". The bill showed
creditsUsed 0.

What changed
- A request for a cline-pass/deepseek-… model now carries
  providerOptions.gateway {only: ["deepseek"], has: [...]} by default,
  written in before the body's last } so the cached prefix is the
  client's byte for byte.
- `has` is "implicit-caching", plus "vision" only for a model that takes
  images: Cline's catalog (/ai/cline/models input_modalities, read by
  the models hook; the bundled list says so for deepseek-v4.1-flash and
  -1017 until it answers) or a request carrying an image part. The
  catalog lists deepseek-v4-pro as text-only, and asking vision of it
  would rule out every upstream.
- A request that already has provider or providerOptions (the client's,
  or the user's extra body in magpie) goes as sent, as before: magpie's
  default never overrides a value the user set.
- The default pin never fails a request that would have worked: a
  pinned request answered with no matching upstream (or "no available
  provider/endpoint") or any 5xx goes once more exactly as sent, same
  account and headers. Once only. A 400 of another kind, 401, 402, 403
  and 429 are the request's or the account's, answered as they are.
- pinUpstream: false (or "false") turns it off. pinUpstream on keeps its
  meaning ("only from the makers' own APIs"): ClinePass DeepSeek models
  get the only + has pin with no unpinned retry; other DeepSeek and GLM
  models are pinned as in 0.1.10.
- Non-DeepSeek ClinePass models, cline-free/deepseek-…, usage-billed
  deepseek/… (without pinUpstream) and every other model go as sent.

Decision (owner delegated product calls): default on for ClinePass's
DeepSeek models. The reporter measured DeepSeek's own API faster than
the private landing, credits unchanged (0), and DeepSeek's API caches by
itself; the retry removes the one downside (a pin that can't be served).
Not made per model: nothing measured says another default is right for
some users.

Run (at this commit, rebased on origin/main)
- bun test packages/cline: 93 pass (11 new).
- HOME=$(mktemp -d) bun test (whole repo, as pr.yml): 0 fail.
- bun scripts/check.mjs: all packages ok.

Broken by hand, each red:
- no default pin: 8 fail (pin, catalog vision, three fallback cases,
  retry-once, pinUpstream off/on, glm-5.3-flash table test).
- the user's providerOptions overridden: 3 fail, incl. the reporter's
  extra body kept word for word.
- no fallback: 4 fail.
- every cline-pass/ model pinned: 6 fail, incl. "other models go as sent".
- vision asked always: 2 fail.

Not tried
- No real Cline account: magpie has no Cline sign-in (plugin-auth.json
  has none, providers.json none; ~/.cline holds only other vendors'
  keys), and api.cline.bot answers 401 before routing, so none of
  finalProvider, speed, creditsUsed, caching, the text-only
  deepseek-v4-pro under has: ["implicit-caching"], or the exact wording
  of the no-upstream refusal was measured here. Built from the
  reporter's description; the fallback covers a wrong guess about
  what the gateway refuses.
- Other Pass models (GLM, Kimi, Qwen, MiMo, MiniMax) may have private
  vs official upstreams too; unmeasured, left unpinned.
- magpie's own ClinePass tick still writes `only` alone before the
  plugin sees the body; fixed in magpie separately.
This commit is contained in:
yetone
2026-10-23 22:14:18 +08:00
parent f658842089
commit 61d058f6cf
4 changed files with 304 additions and 27 deletions
+23 -3
View File
@@ -64,9 +64,29 @@ the balance, and limits read are kept when the balance can't be.
### 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":
Cline's gateway picks among the providers that serve a model. On ClinePass
its own routing for a model wins over `only` alone, so since 0.1.11 a request
for a ClinePass DeepSeek model (`cline-pass/deepseek-…`) carries, by default:
```json
"providerOptions": {"gateway": {"only": ["deepseek"], "has": ["vision", "implicit-caching"]}}
```
`has` is the gateway's capability filter: the upstream must cache a repeated
prefix by itself, and take images — `vision` is asked only of a model Cline's
catalog says takes images (or a request carrying one), never of the text-only
`deepseek-v4-pro`. With it the request is answered by DeepSeek's own API
(hy125245 on X: `finalProvider` `deepseek`, and a fake upstream in `only`
refused with "no matching upstream"). A pinned request that fails with no
upstream matching it, or with a 5xx, goes once more as sent, so the pin
never fails a request that would have worked; a refusal of the account (401,
402, 403, 429) is answered as it is. A request with `provider` or
`providerOptions` of its own — magpie's extra body, say — goes as sent. Set
`pinUpstream` to `false` to send ClinePass's DeepSeek models unpinned.
With the `pinUpstream` option on, a request for any DeepSeek model (not the
`cline-free/` ones) is pinned too, the ClinePass ones as above without the
way back, the others with `"providerOptions": {"gateway": {"only":
["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. Cline sends
+99 -17
View File
@@ -353,7 +353,8 @@ const DEFAULT_MODELS = [
{ id: "stealth/space-bunny-alpha", free: true },
{ id: "cline-free/mimo-v2.6-flash", free: true },
{ id: "cline-free/muse-spark-1.3-contributor", free: true },
{ id: "cline-pass/deepseek-v4.1-flash" },
{ id: "cline-pass/deepseek-v4.1-flash-1017", input: { text: true, image: true } },
{ id: "cline-pass/deepseek-v4.1-flash", input: { text: true, image: true } },
{ id: "cline-pass/mimo-v2.6-flash" },
{ id: "cline-pass/mimo-v2.6-pro" },
{ id: "cline-pass/glm-5.3" },
@@ -807,27 +808,76 @@ function pinned(on, model) {
return m ? { upstream: m.upstream, openRouter: !!m.openRouter } : null
}
// pinBody is the request's body with 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: providerOptions.gateway.only for a model Cline
// sends through Vercel's gateway, provider.only for one it sends through
// OpenRouter. A body that has provider or providerOptions of its own is the
// client's to keep.
function pinBody(body, chat, on) {
const pin = pinned(on, chat?.model)
if (!pin || chat.providerOptions !== undefined || chat.provider !== undefined) return body
// PASS_DEEPSEEK is a ClinePass DeepSeek model: cline-pass/deepseek-…
const PASS_DEEPSEEK = /^cline-pass\/deepseek/i
// passPin is where a ClinePass DeepSeek request is pinned by default:
// DeepSeek's own API, with the gateway's capability filter beside it
// (hy125245 on X, 10-23). On ClinePass the server's own routing for the
// model wins over gateway.only alone, and a fake upstream in only was
// served all the same; with has beside it, the request went to DeepSeek
// (finalProvider "deepseek") and a fake upstream was refused with "no
// matching upstream". has names what the upstream must do: cache a
// repeated prefix by itself ("implicit-caching") and, for a model that
// takes images, take them ("vision") — never for a text-only model
// (deepseek-v4-pro), whose upstreams it would all rule out.
const passPin = (images) => ({ gateway: { only: ["deepseek"], has: [...(images ? ["vision"] : []), "implicit-caching"] } })
// pinOf is the field a request for model is pinned by, or null: a
// ClinePass DeepSeek model always (unless pinUpstream is set off), with
// fallback true when it is magpie's default rather than the user's
// pinUpstream, so a request the pin can't be served under goes again as
// sent; and, with pinUpstream on, the makers' table above.
function pinOf(on, model, images, off = false) {
if (typeof model !== "string") return null
if (PASS_DEEPSEEK.test(model) && !off) return { key: "providerOptions", value: passPin(images), fallback: !on }
const pin = pinned(on, model)
if (!pin) return null
return pin.openRouter
? { key: "provider", value: { only: [pin.upstream] }, fallback: false }
: { key: "providerOptions", value: { gateway: { only: [pin.upstream] } }, fallback: false }
}
// withField is body with "key":value written in at the end, so the rest of
// the body — the prefix a cache matches — is the client's byte for byte
function withField(body, key, value) {
const end = body.lastIndexOf("}")
if (end < 0) return body
const head = body.slice(0, end)
const sep = /[{,]\s*$/.test(head) ? "" : ","
const field = pin.openRouter
? `"provider":${JSON.stringify({ only: [pin.upstream] })}`
: `"providerOptions":${JSON.stringify({ gateway: { only: [pin.upstream] } })}`
return head + sep + field + body.slice(end)
return head + sep + `${JSON.stringify(key)}:${JSON.stringify(value)}` + body.slice(end)
}
// ownsRouting is a body that names its own provider or providerOptions —
// the client's, or the user's extra body in magpie: theirs to keep, and
// nothing is added beside it (magpie's default never overrides a value
// the user set)
const ownsRouting = (chat) => chat?.providerOptions !== undefined || chat?.provider !== undefined
// pinBody is the request's body with its pin written in (pinOf), or the
// body as sent
function pinBody(body, chat, on, images = false, off = false) {
const pin = ownsRouting(chat) ? null : pinOf(on, chat?.model, images, off)
return pin ? withField(body, pin.key, pin.value) : body
}
// hasImages is a chat body carrying an image part (OpenAI's image_url, or
// a bare image part)
const hasImages = (body) => /"type"\s*:\s*"(?:image_url|image|input_image)"/.test(body)
// NO_UPSTREAM is the gateway saying no upstream meets the pin
const NO_UPSTREAM = /no (?:matching|available|eligible) (?:upstream|provider|endpoint)s?|no upstream/i
// unpinWorthy is a pinned request's failure that the same request unpinned
// may well not meet: no upstream matching the pin, or the pinned upstream
// failing (a 5xx). An account's refusal (401, 402, 403, 429) is the
// account's, whatever the pin.
const unpinWorthy = (status, text) => status >= 500 || NO_UPSTREAM.test(String(text ?? ""))
// isOn is whether an option is set: true, or "true" in a config written by hand
const isOn = (v) => v === true || v === "true"
// isOff is an option set off in so many words: false, or "false"
const isOff = (v) => v === false || v === "false"
export const ClinePlugin = async ({ client } = {}, options = {}) => {
// the accounts fresh renewed this run: the sign-in mark comes off on the
@@ -843,6 +893,10 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
// instance serves every account of the provider at once: one newest pair
// shared by all of them would send an account on another account's token
const held = new Map() // a spent refresh token → its chain's newest pair
// whether a model takes images, as the bundled list and then Cline's
// catalog say (the models hook): a ClinePass DeepSeek pin asks for a
// vision upstream only for a model that has one
const images = new Map(DEFAULT_MODELS.map((m) => [m.id, !!m.input?.image]))
// remember saves a refreshed pair where magpie keeps it
const remember = async (next) => {
@@ -1034,6 +1088,9 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
// 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)
// set off in so many words, nothing is pinned, ClinePass's
// DeepSeek models included
const unpinned = isOff(options?.pinUpstream) || isOff(provider?.options?.pinUpstream)
if (a?.type !== "oauth" && a?.type !== "api") return {}
return {
baseURL: API,
@@ -1045,11 +1102,19 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
if (!/\/chat\/completions$/.test(new URL(url).pathname))
return errorResponse({ status: 404, message: "only chat completions are served" })
let body
// sent is the body as the client sent it; fallback is a
// default pin's way back to it
let sent
let fallback = false
try {
body = await bodyText(input, init)
body = sent = 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)
const p = ownsRouting(chat) ? null : pinOf(pin, chat.model, images.get(chat.model) || hasImages(body), unpinned)
if (p) {
body = withField(body, p.key, p.value)
fallback = p.fallback
}
} catch {
return errorResponse({ status: 400, message: "a request that isn't a chat completion" })
}
@@ -1067,12 +1132,25 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
for (const [k, v] of Object.entries(clientHeaders(session ? taskIdOf(session) : undefined))) headers.set(k, v)
headers.delete("content-length")
headers.delete("host")
const signal = init?.signal ?? (input instanceof Request ? input.signal : undefined)
let res
try {
res = await fetch(url, { ...init, method: init?.method ?? "POST", headers, body, signal: init?.signal ?? (input instanceof Request ? input.signal : undefined) })
res = await fetch(url, { ...init, method: init?.method ?? "POST", headers, body, signal })
} catch (e) {
return signed(errorResponse({ status: 502, message: String(e?.message ?? e) }), renewed(cred))
}
// a default pin never fails a request that would have
// worked: no upstream matching it, or the pinned one
// down, and the request goes once more as sent
if (!res.ok && fallback) {
const text = (await res.text()).slice(0, 1 << 20)
if (!unpinWorthy(res.status, text)) return signed(errorResponse(failure(res.status, text)), renewed(cred))
try {
res = await fetch(url, { ...init, method: init?.method ?? "POST", headers, body: sent, signal })
} catch (e) {
return signed(errorResponse({ status: 502, message: String(e?.message ?? e) }), renewed(cred))
}
}
// a renewed token cleared the lapse mark whatever the
// request then met, a refused one included (qoder's
// renewed()): the failure is reported, the mark stays off
@@ -1096,6 +1174,7 @@ export const ClinePlugin = async ({ client } = {}, options = {}) => {
const have = provider?.models ?? {}
try {
const ms = await fetchFeed()
for (const m of ms) if (m.input) images.set(m.id, !!m.input.image)
return Object.fromEntries(ms.map((m) => [m.id, runtimeModel(m)]))
} catch {
// a list Cline couldn't give is a failure, not the few
@@ -1131,7 +1210,10 @@ export const _internal = {
errorResponse,
bodyText,
pinned,
pinOf,
pinBody,
unpinWorthy,
hasImages,
unwrapped,
clientHeaders,
deviceAuthorize,
+181 -6
View File
@@ -1126,7 +1126,7 @@ test("an auth entry is read the same however it was stored", () => {
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 body = `{"model":"deepseek/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"] } })
@@ -1176,8 +1176,8 @@ test("pinBody pins glm-5.3-flash by OpenRouter's provider.only, keeping the body
expect(pinned(true, "cline-pass/GLM-5.3-Flash")).toEqual({ upstream: "z-ai", openRouter: true })
for (const m of ["cline-pass/deepseek-v4.1-flash", "cline-pass/deepseek-v4.1-flash-1017"]) {
const ds = `{"model":"${m}"}`
const got = JSON.parse(pinBody(ds, JSON.parse(ds), true))
expect(got.providerOptions).toEqual({ gateway: { only: ["deepseek"] } })
const got = JSON.parse(pinBody(ds, JSON.parse(ds), true, true))
expect(got.providerOptions).toEqual({ gateway: { only: ["deepseek"], has: ["vision", "implicit-caching"] } })
expect(got.provider).toBeUndefined()
}
// the client's own provider or providerOptions is kept, with nothing added beside it
@@ -1202,7 +1202,7 @@ for (const [how, plugin, provider] of [
[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: "deepseek/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/glm-5.3-flash", messages: [] }))
@@ -1215,12 +1215,187 @@ for (const [how, plugin, provider] of [
})
}
test("without pinUpstream a DeepSeek request goes as sent", async () => {
test("without pinUpstream a usage-billed 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: [] }
const sent = { model: "deepseek/deepseek-v4-pro", messages: [] }
await l.fetch(chatUrl, chatInit(sent))
expect(calls[0].init.body).toBe(JSON.stringify(sent))
})
// ---- ClinePass's DeepSeek models: pinned to DeepSeek by default ------------------
//
// hy125245 on X (10-23): on ClinePass the server's own routing for a model wins
// over providerOptions.gateway.only alone (a fake upstream was served all the
// same); with the gateway's capability filter beside it, has: ["vision",
// "implicit-caching"], the request went to DeepSeek (finalProvider
// "deepseek") and a fake upstream was refused with "no matching upstream".
const PASS_PIN = (images) => ({ gateway: { only: ["deepseek"], has: [...(images ? ["vision"] : []), "implicit-caching"] } })
test("a ClinePass DeepSeek request is pinned to DeepSeek by default, vision asked only of a model that takes images", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([0, 1, 2, 3].map(() => [chatUrl, () => Response.json({ ok: true })]))
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const msgs = [{ role: "user", content: "hi" }]
for (const model of ["cline-pass/deepseek-v4.1-flash-1017", "cline-pass/deepseek-v4.1-flash", "cline-pass/deepseek-v4-pro"])
await l.fetch(chatUrl, chatInit({ model, messages: msgs, stream: true }))
// a model the plugin doesn't know takes images, sent one: vision is asked
await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v5-flash", messages: [{ role: "user", content: [{ type: "image_url", image_url: { url: "data:image/png;base64,AA" } }] }] }))
const got = calls.map((x) => JSON.parse(x.init.body).providerOptions)
expect(got).toEqual([PASS_PIN(true), PASS_PIN(true), PASS_PIN(false), PASS_PIN(true)])
// written in at the end: the prefix a cache matches is the client's
const sent = JSON.stringify({ model: "cline-pass/deepseek-v4.1-flash-1017", messages: msgs, stream: true })
expect(calls[0].init.body.startsWith(sent.slice(0, -1))).toBe(true)
})
test("the models hook's catalog says which ClinePass DeepSeek model the pin asks vision of", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([
["/ai/cline/recommended-models", () => Response.json({ clinePass: [{ id: "cline-pass/deepseek-v4.1-flash" }, { id: "cline-pass/deepseek-v4-pro" }] })],
["/ai/cline/models", () => Response.json({ data: [
// as if Cline's catalog changed its mind on both
{ id: "deepseek/deepseek-v4.1-flash", architecture: { input_modalities: ["text"] } },
{ id: "deepseek/deepseek-v4-pro", architecture: { input_modalities: ["text", "image"] } },
] })],
])
await hooks.provider.models({ models: {} })
serve([0, 1].map(() => [chatUrl, () => Response.json({ ok: true })]))
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4.1-flash", messages: [] }))
await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4-pro", messages: [] }))
expect(calls.map((x) => JSON.parse(x.init.body).providerOptions)).toEqual([PASS_PIN(false), PASS_PIN(true)])
})
test("the user's own provider or providerOptions on a ClinePass DeepSeek request is left as they set it, and never retried without it", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
const own = [
// hy125245's extra body, word for word
{ model: "cline-pass/deepseek-v4.1-flash-1017", messages: [], providerOptions: { gateway: { only: ["deepseek"], has: ["vision", "implicit-caching"] } } },
{ model: "cline-pass/deepseek-v4.1-flash-1017", messages: [], providerOptions: { gateway: { only: ["not-a-real-provider"], has: ["vision", "implicit-caching"] } } },
{ model: "cline-pass/deepseek-v4-pro", messages: [], providerOptions: { gateway: { only: ["deepseek"] } } },
{ model: "cline-pass/deepseek-v4-pro", messages: [], provider: { order: ["novita"] } },
]
serve([
[chatUrl, () => Response.json({ ok: true })],
[chatUrl, () => Response.json({ error: "no matching upstream" }, { status: 400 })],
[chatUrl, () => Response.json({ ok: true })],
[chatUrl, () => Response.json({ ok: true })],
])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const res = []
for (const b of own) res.push(await l.fetch(chatUrl, chatInit(b)))
expect(calls.length).toBe(4)
expect(calls.map((x) => x.init.body)).toEqual(own.map((b) => JSON.stringify(b)))
expect(res.map((r) => r.status)).toEqual([200, 400, 200, 200])
})
for (const [why, status, answer] of [
["no upstream matches the pin", 400, { error: "no matching upstream" }],
["no upstream matches the pin (OpenAI's error shape)", 404, { error: { message: "No matching upstream for cline-pass/deepseek-v4-pro" } }],
["DeepSeek's upstream is down", 503, { error: { message: "upstream unavailable" } }],
]) {
test(`a default pin that fails because ${why} goes once more as sent`, async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([
[chatUrl, () => Response.json(answer, { status })],
[chatUrl, () => new Response("data: {}\n\n", { headers: { "Content-Type": "text/event-stream" } })],
])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const sent = { model: "cline-pass/deepseek-v4.1-flash-1017", messages: [{ role: "user", content: "hi" }], stream: true }
const res = await l.fetch(chatUrl, chatInit(sent))
expect(res.status).toBe(200)
expect(await res.text()).toBe("data: {}\n\n")
expect(calls.length).toBe(2)
expect(JSON.parse(calls[0].init.body).providerOptions).toEqual(PASS_PIN(true))
expect(calls[1].init.body).toBe(JSON.stringify(sent))
// the retry carries the same account and Cline's headers
expect(new Headers(calls[1].init.headers).get("Authorization")).toBe("Bearer ck")
expect(new Headers(calls[1].init.headers).get("X-CLIENT-TYPE")).toBe(CLIENT.type)
})
}
test("the unpinned retry runs once: its own failure is the answer", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([
[chatUrl, () => Response.json({ error: "no matching upstream" }, { status: 400 })],
[chatUrl, () => Response.json({ error: { message: "upstream unavailable" } }, { status: 503 })],
[chatUrl, () => Response.json({ ok: true })],
])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const res = await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4-pro", messages: [] }))
expect(res.status).toBe(503)
expect(calls.length).toBe(2)
})
test("a pinned request the account was refused is not retried without the pin", async () => {
for (const [status, answer] of [
[401, { error: "Unauthorized" }],
[402, { error: { code: "insufficient_credits", message: "insufficient credits" } }],
[403, { error: { code: "ENTITLEMENT_ERROR", message: "The user is not subscribed to required model plan" } }],
[429, { error: { message: "rate limit exceeded" } }],
[400, { error: { message: "messages: field required" } }],
]) {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
serve([[chatUrl, () => Response.json(answer, { status })]])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
const res = await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4.1-flash", messages: [] }))
expect(res.ok).toBe(false)
expect(calls.length).toBe(1)
}
})
test("other models go as sent: ClinePass's non-DeepSeek, the free DeepSeek and usage-billed DeepSeek", async () => {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c })
const models = ["cline-pass/kimi-k3", "cline-pass/glm-5.3", "cline-pass/glm-5.3-flash", "cline-pass/mimo-v2.6-pro", "cline-pass/qwen3.8-max", "cline-pass/minimax-m3", "cline-free/deepseek-v4.1-flash", "deepseek/deepseek-v4.1-flash", "anthropic/claude-sonnet-5.5"]
serve([
...models.map(() => [chatUrl, () => Response.json({ error: "no matching upstream" }, { status: 400 })]),
[chatUrl, () => Response.json({ ok: true })],
])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), { id: "cline", options: {} })
for (const model of models) await l.fetch(chatUrl, chatInit({ model, messages: [] }))
expect(calls.map((x) => x.init.body)).toEqual(models.map((model) => JSON.stringify({ model, messages: [] })))
})
test("pinUpstream set off leaves ClinePass's DeepSeek models unpinned; set on, they are pinned with no way back", async () => {
for (const [plugin, provider] of [[{ pinUpstream: false }, undefined], [undefined, { id: "cline", options: { pinUpstream: "false" } }]]) {
const { client: c } = client()
const hooks = await ClinePlugin({ client: c }, plugin)
serve([[chatUrl, () => Response.json({ ok: true })]])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }), provider)
const sent = { model: "cline-pass/deepseek-v4.1-flash", messages: [] }
await l.fetch(chatUrl, chatInit(sent))
expect(calls[0].init.body).toBe(JSON.stringify(sent))
}
const { client: c } = client()
const hooks = await ClinePlugin({ client: c }, { pinUpstream: true })
serve([
[chatUrl, () => Response.json({ error: "no matching upstream" }, { status: 400 })],
[chatUrl, () => Response.json({ ok: true })],
])
const l = await hooks.auth.loader(async () => ({ type: "api", key: "ck" }))
const res = await l.fetch(chatUrl, chatInit({ model: "cline-pass/deepseek-v4.1-flash", messages: [] }))
// the user asked for DeepSeek's own API only: that is kept, not undone
expect(res.status).toBe(400)
expect(calls.length).toBe(1)
expect(JSON.parse(calls[0].init.body).providerOptions).toEqual(PASS_PIN(true))
})
test("unpinWorthy is a missing upstream or a 5xx, never an account's refusal", () => {
const { unpinWorthy, hasImages } = _internal
expect(unpinWorthy(400, `{"error":"no matching upstream"}`)).toBe(true)
expect(unpinWorthy(404, "No available providers for this model")).toBe(true)
expect(unpinWorthy(502, "")).toBe(true)
for (const s of [400, 401, 402, 403, 429]) expect(unpinWorthy(s, `{"error":"nope"}`)).toBe(false)
expect(hasImages(`{"messages":[{"content":[{"type": "image_url"}]}]}`)).toBe(true)
expect(hasImages(`{"messages":[{"content":"type image_url"}]}`)).toBe(false)
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cline-auth",
"version": "0.1.10",
"version": "0.1.11",
"description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",