From c0a0fd1955b32a1cedf828f5d8efa262af1d9747 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 12:34:30 +0800 Subject: [PATCH] qoder 0.2.45: a free account with no credits shows none left, not nothing Ariel on Discord: an international free Qoder account signed in fine but showed no credits. A free account (userType personal_standard, Qoder's "Experience" plan) has a plan pool of 0 and, until it gets add-on credits, nothing else. parseUsage drops every pool whose total is 0, so such an account came out with no window at all and magpie had nothing to show. Qoder's own client (Qoder.app's buildUsageItemGroups) shows every pool present, 0/0 included, and counts the account out of credits when what the pools have left adds up to 0. Now, when no pool gives a window and the plan, add-on or shared pool reads a total of 0, the account has one "Credits" window, "0 credits left", used up. A pool that can't be read (a string total) or no pools at all still say nothing. An account with credits in any pool is shown as before (the owner's free account: plan 0, add-on 7 / 600, one Add-on window, unchanged). Same parser for qoder-cn. Run: HOME=$(mktemp -d) bun test in packages/qoder on mote (299 pass) and bun scripts/check.mjs qoder (ok). Broken by hand: the new test against origin/main's index.mjs, red (it reads no windows). Read-only real read of the owner's intl account's /sash/api/v2/me/usage for the envelope's shape (personal_standard, usageType credits, plan 0/0). Not tried: Ariel's own account; the fixture is the owner's free envelope with the add-on pool at 0 or absent, since the owner's has add-on credits. --- packages/qoder/index.mjs | 9 +++++++++ packages/qoder/package.json | 2 +- packages/qoder/usage.test.mjs | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index c3e2850..58ae58b 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -2179,6 +2179,15 @@ function parseUsage(env) { } const dedicated = field("dedicatedResourcePackages", "dedicated_resource_packages") for (const b of Array.isArray(dedicated) ? dedicated : []) add(b, "Dedicated credits") + // A free account (personal_standard) with no add-on credits has a plan of + // 0 and nothing else: Qoder's client shows that pool as 0/0 and counts the + // account as out of credits. Without a window of its own magpie showed no + // credits at all (Ariel on Discord), so it reads as none left. + if (out.windows.length === 0) { + const zero = (b) => b !== null && typeof b === "object" && !Array.isArray(b) && (b.total ?? b.cap) === 0 + const pools = [field("userQuota", "user_quota"), field("addOnQuota", "add_on_quota"), field("orgResourcePackage", "org_resource_package")] + if (pools.some(zero)) out.windows.push({ name: "Credits", used: 100, display: "0 credits left" }) + } return out } diff --git a/packages/qoder/package.json b/packages/qoder/package.json index eaefb35..aad1e1d 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.44", + "version": "0.2.45", "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)", "type": "module", "main": "./index.mjs", diff --git a/packages/qoder/usage.test.mjs b/packages/qoder/usage.test.mjs index f8e4bfd..3042bb1 100644 --- a/packages/qoder/usage.test.mjs +++ b/packages/qoder/usage.test.mjs @@ -527,3 +527,29 @@ test("a job token the models hook renewed is said renewed by the next answer", a const again = await l.fetch(API_CHAT, { method: "POST", body: JSON.stringify({ model: "nomodel", messages: [] }) }) expect(again.headers.get("X-Magpie-Sign-In")).toBe(null) }) + +// Ariel on Discord: an international free account (personal_standard) signed +// in but showed no credits. Its envelope is the owner's free account's +// (2026-10-28, read-only) with no add-on credits: a plan of 0 beside add-on +// credits of 0, or none at all. Qoder's client shows it 0/0, out of credits. +test("a free account with no credits shows none left, not nothing", () => { + const free = (extra) => ({ + displayMode: "qoder", + qoderUsage: { + userType: "personal_standard", + usageType: "credits", + totalUsagePercentage: 0, + isQuotaExceeded: true, + expiresAt: 253402214400000, + userQuota: { total: 0, used: 0, remaining: 0, percentage: 0, unit: "credits" }, + ...extra, + isPlanQuotaProrated: false, + }, + }) + const none = [{ name: "Credits", used: 100, display: "0 credits left" }] + expect(_internal.parseUsage(free({})).windows).toEqual(none) + expect(_internal.parseUsage(free({ addOnQuota: { total: 0, used: 0, remaining: 0, percentage: 0, unit: "credits" } })).windows).toEqual(none) + // a pool that can't be read is no word that the account has none + expect(_internal.parseUsage({ displayMode: "qoder", qoderUsage: { userType: "personal_standard", userQuota: { total: "0" } } }).windows).toEqual([]) + expect(_internal.parseUsage({ displayMode: "qoder", qoderUsage: { userType: "personal_standard" } }).windows).toEqual([]) +})