diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index 51ca2e9..5785a7c 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -1478,6 +1478,15 @@ function modelConfig(m, thinking) { } } +// The business record also names the model: Qoder's CLI (qodercli 1.1.82, +// qoder-worker-runtime v3 → snn + model_key) puts the chosen model's key +// there when a prompt starts, and the server attributes the call's billing +// from it. Without it Qoder and Qoder CN booked the call as Auto whatever +// model_config named (plugins#692, chansee97; the same shape as #638, where +// the model_config fix of 0.2.54 did not change the billing). Qoder.app +// 0.4.3 and QwenWork 1.0.46 build their record without it, so a site that +// ships such a client says businessModelKey: false. +// // qoderBody is the plaintext agent_chat_generation takes for a chat // completion request, for model m, in the session the agent named (named, // "" when none) and the task it is a call of (taskOf's, a new one when @@ -1505,7 +1514,7 @@ function qoderBody(chat, m, named = "", task, site) { chat_record_id: request, session_id: session, parameters: params, - business: { product: site?.businessProduct ?? "app", version: site?.cosyVersion ?? COSY_VERSION, type: "agent", id: task.id, name: task.name ?? "", begin_at: task.begin, stage: task.answered ? "processing" : "start" }, + business: { product: site?.businessProduct ?? "app", version: site?.cosyVersion ?? COSY_VERSION, type: "agent", id: task.id, name: task.name ?? "", begin_at: task.begin, stage: task.answered ? "processing" : "start", ...(site?.businessModelKey === false ? {} : { model_key: m.key }) }, agent_id: "agent_common", task_id: "common", session_type: site?.sessionType ?? "app", @@ -2872,7 +2881,7 @@ const QWENWORK_COMMON = { deviceRefreshTarget: "c", clientHeaders: qwenworkClientHeaders, modelScene: "qwork", listAllModels: true, - clientType: "6", businessProduct: "qoder_work", sessionType: "qoder_work", + clientType: "6", businessProduct: "qoder_work", sessionType: "qoder_work", businessModelKey: false, userInfoPath: "/api/v1/adapter/user/account-context?include=user,plan,quota,page,data_sharing", normalizeUser: v => (v?.data ?? v)?.user ?? (v?.data ?? v), pat: false, // no /api/v1/jobToken/exchange on gateway.qwenwork.cn diff --git a/packages/qoder/model-config.test.mjs b/packages/qoder/model-config.test.mjs index 63c6716..5d2209d 100644 --- a/packages/qoder/model-config.test.mjs +++ b/packages/qoder/model-config.test.mjs @@ -87,3 +87,38 @@ test("a model the listing doesn't have is answered 400, with nothing sent", asyn expect(res.status).toBe(400) expect(sent).toHaveLength(0) }) + +// The business record names the model (plugins#692, chansee97; #638 again +// after 0.2.54): qodercli 1.1.82 sends business.model_key beside the +// product, version, type, id, name, begin_at and stage, and Qoder books the +// call from it. Without it Qoder and Qoder CN billed every model as Auto. +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}: business.model_key is ${key}, the model the request names`, async () => { + const { res, sent } = await chatOn(create, paid(read(file)), key) + expect(res.status).toBe(200) + const b = sent.at(-1).business + expect(b.model_key).toBe(key) + expect(b.model_key).toBe(sent.at(-1).model_config.key) + expect(Object.keys(b)).toEqual(expect.arrayContaining(["product", "version", "type", "id", "name", "begin_at", "stage"])) + }) + } +} + +test("one task's calls on two models each name their own model", () => { + const listing = read("cn-listing-free-view.json") + const chat = { messages: [{ role: "user", content: "hi" }] } + const task = _internal.taskOf("s", chat) + const a = _internal.qoderBody({ ...chat, model: "dfmodel" }, _internal.modelInfo(listing.chat.find((e) => e.key === "dfmodel")), "s", task) + const b = _internal.qoderBody({ ...chat, model: "kmodel_latest" }, _internal.modelInfo(listing.chat.find((e) => e.key === "kmodel_latest")), "s", task) + expect(a.business.id).toBe(b.business.id) + expect([a.business.model_key, b.business.model_key]).toEqual(["dfmodel", "kmodel_latest"]) +}) + +test("QwenWork's record stays as its own client builds it, with no model_key", () => { + const listing = read("cn-listing-free-view.json") + const df = _internal.modelInfo(listing.chat.find((e) => e.key === "dfmodel")) + const chat = { model: "dfmodel", messages: [{ role: "user", content: "hi" }] } + expect(_internal.qoderBody(chat, df, "", undefined, _internal.SITES.qwenwork).business).not.toHaveProperty("model_key") + expect(_internal.qoderBody(chat, df, "", undefined, _internal.SITES.qoder).business.model_key).toBe("dfmodel") +})