square-235 (plugins#638): on Qoder CN, magpie's DeepSeek-Flash (dfmodel)
calls show in QoderCN's billing as "Auto", charged at Auto's rate, while
Kimi-K3.1-Pro (kmodel_latest) calls are billed as themselves. Their
screenshots show magpie asking qoder-cn/dfmodel, and the billing rows at
those times saying Auto.
The model id did map: X-Model-Key and model_config.key were dfmodel. What
differed from Qoder's own client was model_config. The plugin sent the
model's listing entry whole. Qoder's client (CN CLI @qodercn-ai/qoderclicn
1.1.81 Pcu, desktop 0.4.3 nzc, the qoder-agent-sdk worker) sends a trimmed
object: key, display_name, model "" (or outer_provider), format, is_vl,
is_reasoning (false when thinking is off), api_key "", url "", source,
max_input_tokens (2e5 when missing). dfmodel's entry carries a
minimal_version (on qoder.com {"cli":"0.1.25","jb_plugin":"0.15.0",
"ide":"0.3.0"}; in the CN listing {"vsc":"999.999.999"}) and kmodel_latest's
on qoder.com has none, which matches the one billed wrong. Likely cause,
not confirmed: no Qoder CN account was used.
- modelConfig(m, thinking) builds the client's object, and qoderBody sends
it in place of m.config.
- The class: a model whose entry has no key, or key auto/default, or a key
other than the one asked for, is refused. ask answers 400 with the
reason and sends nothing. The worker reads a missing key as "auto". A
model id the listing doesn't have was already a 400 before any send.
- README: the Models section says what model_config carries now.
Not changed: the worker also sends chat_context.extra.modelConfig {key,
is_reasoning}; the plugin still doesn't. X-Model-Key/X-Model-Source stay.
Run (mote, bun 1.4.2), at this tree: packages/qoder `bun test`, 363 pass,
0 fail, with the new model-config.test.mjs (8 tests built from the real
testdata/listing.json and cn-listing-free-view.json bytes; the CN listing
is a free account's, so its entries are turned on in the test and nothing
else is changed). `bun scripts/check.mjs` passes.
Broken by hand: with model_config back to m.config, 6 of the 8 went red
(the four dfmodel/kmodel_latest shape tests on qoder and qoder-cn,
is_reasoning off, the key refusal). With the key guard removed, the
refusal test went red.
Not tried: a real Qoder CN chat with dfmodel, and whether the billing row
now says DeepSeek-Flash. The upstream SSE "model" is "auto" for every
model (seen on a real qoder.com kmodel_latest call), so it can't tell.
QwenWork and QwenWork Enterprise get the same model_config and were not
tried.
90 lines
5.2 KiB
JavaScript
90 lines
5.2 KiB
JavaScript
// The model_config a chat sends (plugins#638, square-235): Qoder CN billed
|
|
// DeepSeek-Flash (dfmodel) as Auto while the plugin sent the model's listing
|
|
// entry whole, with its minimal_version, strategies, prices and
|
|
// thinking_config. Qoder's own client (CN CLI 1.1.81, desktop 0.4.3) sends
|
|
// only the fields below, in this order. The listings are the real bytes
|
|
// Qoder (testdata/listing.json) and Qoder CN (testdata/cn-listing-free-view.json)
|
|
// answered.
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { readFileSync } from "node:fs"
|
|
import { QoderAuthPlugin, QoderCNAuthPlugin, _internal } from "./index.mjs"
|
|
|
|
const real = globalThis.fetch
|
|
afterEach(() => { globalThis.fetch = real })
|
|
|
|
const CLIENT_KEYS = ["key", "display_name", "model", "format", "is_vl", "is_reasoning", "api_key", "url", "source", "max_input_tokens"]
|
|
const read = (f) => JSON.parse(readFileSync(new URL(`./testdata/${f}`, import.meta.url), "utf8"))
|
|
// The CN listing was read on a free account, which has every paid model off
|
|
// (enable false); the reporter's paid account has them on, so they are
|
|
// turned on here and nothing else is changed.
|
|
const paid = (listing) => Object.fromEntries(Object.entries(listing).map(([s, v]) => [s, Array.isArray(v) ? v.map((e) => ({ ...e, enable: true })) : v]))
|
|
|
|
async function chatOn(create, listing, model, extra = {}) {
|
|
const sent = []
|
|
globalThis.fetch = async (url, init) => {
|
|
if (new URL(String(url)).pathname.endsWith("/model/list")) return Response.json(listing)
|
|
if (String(url).includes("agent_chat_generation")) {
|
|
sent.push(JSON.parse(_internal.decodeBody(init.body)))
|
|
const chunk = { model: "auto", choices: [{ delta: { content: "OK" }, finish_reason: "stop" }], usage: { prompt_tokens: 1, completion_tokens: 1 } }
|
|
return new Response(`data: ${JSON.stringify({ body: JSON.stringify(chunk) })}\n\ndata: ${JSON.stringify({ body: "[DONE]" })}\n\n`, { headers: { "content-type": "text/event-stream" } })
|
|
}
|
|
throw new Error(`unexpected upstream ${url}`)
|
|
}
|
|
const auth = { type: "oauth", access: "t", refresh: "r", expires: Date.now() + 3600000, uid: "u", machineId: "m" }
|
|
const hooks = await create({ client: { auth: { set: async () => {} } } })
|
|
const loader = await hooks.auth.loader(async () => auth)
|
|
const res = await loader.fetch("https://test.invalid/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "hi" }], ...extra }) })
|
|
return { res, sent }
|
|
}
|
|
|
|
for (const [site, create, file] of [["qoder", QoderAuthPlugin, "listing.json"], ["qoder-cn", QoderCNAuthPlugin, "cn-listing-free-view.json"]]) {
|
|
for (const key of ["dfmodel", "kmodel_latest"]) {
|
|
test(`${site}: ${key}'s model_config is the client's, not the listing entry`, async () => {
|
|
const listing = paid(read(file))
|
|
const entry = Object.values(listing).flat().find((e) => e?.key === key)
|
|
expect(entry).toBeTruthy()
|
|
const { res, sent } = await chatOn(create, listing, key)
|
|
expect(res.status).toBe(200)
|
|
const mc = sent.at(-1).model_config
|
|
expect(Object.keys(mc)).toEqual(CLIENT_KEYS)
|
|
expect(mc).toMatchObject({ key, display_name: entry.display_name, model: "", api_key: "", url: "", format: entry.format, source: entry.source, max_input_tokens: entry.max_input_tokens, is_vl: !!entry.is_vl })
|
|
for (const k of ["minimal_version", "strategies", "price_factor", "thinking_config", "context_config", "enable", "is_default"]) expect(mc).not.toHaveProperty(k)
|
|
})
|
|
}
|
|
}
|
|
|
|
test("dfmodel's listing entries carry a minimal_version, which no client sends", () => {
|
|
for (const file of ["listing.json", "cn-listing-free-view.json"]) {
|
|
const df = Object.values(read(file)).flat().filter((e) => e?.key === "dfmodel")
|
|
expect(df.length).toBeGreaterThan(0)
|
|
expect(df.every((e) => e.minimal_version)).toBe(true)
|
|
}
|
|
})
|
|
|
|
test("is_reasoning is sent off when the request turns thinking off", async () => {
|
|
const listing = read("cn-listing-free-view.json")
|
|
const thinker = listing.chat.find((e) => e.enable && e.is_reasoning && e.thinking_config?.disabled)
|
|
expect(thinker).toBeTruthy()
|
|
const { sent } = await chatOn(QoderCNAuthPlugin, listing, thinker.key, { reasoning_effort: "none" })
|
|
expect(sent.at(-1).model_config.is_reasoning).toBe(false)
|
|
const on = await chatOn(QoderCNAuthPlugin, listing, thinker.key, { reasoning_effort: "high" })
|
|
expect(on.sent.at(-1).model_config.is_reasoning).toBe(true)
|
|
})
|
|
|
|
test("a model with no key of its own is refused, never sent as Auto", () => {
|
|
const listing = read("cn-listing-free-view.json")
|
|
const df = listing.chat.find((e) => e.key === "dfmodel")
|
|
const chat = { model: "dfmodel", messages: [{ role: "user", content: "hi" }] }
|
|
for (const config of [{ ...df, key: "" }, { ...df, key: "auto" }, { ...df, key: "kmodel_latest" }]) {
|
|
const m = { ..._internal.modelInfo(df), config }
|
|
expect(() => _internal.qoderBody(chat, m)).toThrow(/no Qoder model key/)
|
|
}
|
|
expect(_internal.qoderBody(chat, _internal.modelInfo(df)).model_config.key).toBe("dfmodel")
|
|
})
|
|
|
|
test("a model the listing doesn't have is answered 400, with nothing sent", async () => {
|
|
const { res, sent } = await chatOn(QoderCNAuthPlugin, read("cn-listing-free-view.json"), "Deepseek-Flash")
|
|
expect(res.status).toBe(400)
|
|
expect(sent).toHaveLength(0)
|
|
})
|