qoder 0.2.43: the check-in says when to ask again, as the 10:00 (UTC+8) campaign opens

sdytman on Discord: Qoder's daily credits start at 10:00, can the plugin's
check-in follow it? Qoder's /me/campaigns lists each day's CLAIM_BENEFIT
campaign with startAt 10:00 and endAt 09:59 the next day, both UTC+8
("Daily reset: 10:00 (UTC+8)"), read with a real account at 09:27 CST on
10-28. Qoder.app 0.4.3 polls that list every 5 minutes and treats
startAt <= now < endAt as active; there is no next-time field. A check-in
before 10:00 met yesterday's campaign, and magpie settled for the Beijing
day, so today's campaign waited until tomorrow, or was lost.

checkin now returns until: the next campaign's opening (the later of
endAt and startAt + 1 day, or the next startAt in the gap) plus a minute,
on done, claimed and "not offered yet". All in epoch time, so the
machine's zone doesn't matter; qoder and qoder-cn share the code. magpie
asks again at until once it reads it (yetone/magpie, next release).

Run (mote): checkin-window, native-checkin and checkin tests under
TZ=UTC, Etc/GMT+8 and Asia/Shanghai, 66 pass each; HOME=$(mktemp -d)
bun test, 2938 pass 0 fail 8 skip; bun scripts/check.mjs. A real qoder
account at 09:35 CST: claimed 100, until 2026-10-28T02:01:00Z.
Broken by hand: nextOpens returning endAt only, 11 of 13 checkin-window
tests red; askAgain returning {}, 12 of 13 red.
Not tried: a real Qoder CN account (none here); the server's list in the
09:59-10:00 gap.
This commit is contained in:
yetone
2026-10-28 19:16:54 +08:00
parent f2b0dacdb7
commit b7bbc9dc06
4 changed files with 137 additions and 3 deletions
+13
View File
@@ -472,6 +472,19 @@ the plugin factory and its pieces, for another service on this same
protocol (QwenWork ships here; a future one can too). Its shape is not a protocol (QwenWork ships here; a future one can too). Its shape is not a
stable API — it changes as the packages on it need. stable API — it changes as the packages on it need.
## Free models when the credits run out
Qoder serves its free models after the credits are used up: "When Credits
run out, you can continue using free basic models, subject to daily and
monthly limits" ([docs.qoder.com/Credits](https://docs.qoder.com/Credits);
the zh page says the same). So the credit windows the usage hook gives
(Qoder and Qoder CN, since 0.2.46) name the account's free models in
`notModels`: a model listed at 0× (not a discount's 0 for a while), from the
account's own model list. magpie then doesn't count those models as spent
on a used-up account, or on a free account's "0 credits left". A list that
can't be read leaves every model counted. QwenWork reads its usage
elsewhere and is not changed.
## Not here ## Not here
- Qoder's usage and quota display. - Qoder's usage and quota display.
+22 -2
View File
@@ -2515,6 +2515,26 @@ const makePlugin = (site) => async ({ client }) => {
return dt.token return dt.token
}) })
// spareFree has the credit windows not count the models that cost none
// (notModels): Qoder's own docs say "When Credits run out, you can
// continue using free basic models, subject to daily and monthly limits"
// (docs.qoder.com/Credits; the zh page the same: "Credits 用尽后,仍可使用
// 免费基础模型"). Counted, a plan used up (or a free account's "0 credits
// left") put the account last for Qwen3.8-Flash and DeepSeek-Flash too,
// which it still serves (coeo91 on Discord). Free is the listing's own
// price (freeOf: 0×, not a discount's 0 for a while). A listing that can't
// be read leaves every model counted, as before. Qoder and Qoder CN only:
// QwenWork reads its usage elsewhere and says nothing of free models.
const spareFree = async (cred, out) => {
if (!out?.windows?.length) return out
let free = []
try {
free = (await models(cred)).filter((m) => m.free).map((m) => m.key)
} catch {}
if (free.length) for (const w of out.windows) w.notModels = free
return out
}
// usage is the account's allowance, magpie's own hook. signIn is what the read means for the sign-in, as the built-in's did: // usage is the account's allowance, magpie's own hook. signIn is what the read means for the sign-in, as the built-in's did:
// a refused job refresh marks it, a renewed one clears it, and nothing // a refused job refresh marks it, a renewed one clears it, and nothing
// else does — not a clean read, nor a refused device token, which serves // else does — not a clean read, nor a refused device token, which serves
@@ -2562,7 +2582,7 @@ const makePlugin = (site) => async ({ client }) => {
// no second token here to rotate and retry with. // no second token here to rotate and retry with.
if (cred.patAuth && !cred.deviceToken) { if (cred.patAuth && !cred.deviceToken) {
const env = await fetchUsage(siteOf(site, cred), cred.access) const env = await fetchUsage(siteOf(site, cred), cred.access)
return { ...parseUsage(env), signIn } return { ...(await spareFree(cred, parseUsage(env))), signIn }
} }
let env let env
try { try {
@@ -2571,7 +2591,7 @@ const makePlugin = (site) => async ({ client }) => {
if (!(e instanceof UsageStatus) || (e.status !== 401 && e.status !== 403)) throw e if (!(e instanceof UsageStatus) || (e.status !== 401 && e.status !== 403)) throw e
env = await fetchUsage(siteOf(site, cred), await deviceToken(getAuth, cred.deviceToken)) env = await fetchUsage(siteOf(site, cred), await deviceToken(getAuth, cred.deviceToken))
} }
return { ...parseUsage(env), signIn } return { ...(await spareFree(cred, parseUsage(env))), signIn }
} catch (e) { } catch (e) {
return { error: e?.message ?? String(e), signIn: e?.expired ? "expired" : signIn } return { error: e?.message ?? String(e), signIn: e?.expired ? "expired" : signIn }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@magpie-community/opencode-qoder-auth", "name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.45", "version": "0.2.46",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)", "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
"type": "module", "type": "module",
"main": "./index.mjs", "main": "./index.mjs",
+101
View File
@@ -0,0 +1,101 @@
// coeo91 on Discord: a Qoder account whose credits are used up still serves
// its free models — Qoder's docs: "When Credits run out, you can continue
// using free basic models" — but its usage counted them on the credits
// window at 100%, so magpie put the account last for them too. Each credit
// window now names the free models it doesn't count (notModels). Every
// fetch here is a fake; nothing reaches the network.
import { afterEach, expect, test } from "bun:test"
import { QoderAuthPlugin, QoderCNAuthPlugin } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const json = (v, status = 200) => new Response(JSON.stringify(v), { status })
// a free account's envelope as Qoder gives it (plan 0, no add-on: "0
// credits left"), and a paid one used up beside add-on credits
const FREE = { displayMode: "qoder", qoderUsage: { userType: "personal_standard", userQuota: { total: 0, used: 0, remaining: 0, unit: "credits" } } }
const SPENT = {
displayMode: "qoder",
qoderUsage: {
userType: "personal_professional",
userQuota: { total: 300, used: 300, remaining: 0, unit: "credits" },
addOnQuota: { total: 100, used: 100, remaining: 0, unit: "credits" },
},
}
// the listing's prices: 0× is free, a discount's 0 for a while isn't, a
// listing with no price says it with is_free
const LISTING = {
app: [
{ key: "qfmodel", display_name: "Qwen3.8-Flash", enable: true, price_factor: 0.0, original_price_factor: 0.1, is_free: true },
{ key: "dfmodel", display_name: "DeepSeek-Flash", enable: true, price_factor: 0 },
{ key: "qmodel_38max", display_name: "Qwen3.8-Max", enable: true, price_factor: 0.5, is_free: true },
{ key: "window", display_name: "W", enable: true, price_factor: 0, promotion: { active: true, discount_factor: 0.0001, before_promotion_price_factor: 0.5 } },
{ key: "kmodel_latest", display_name: "Kimi-K3", enable: true, price_factor: 1.4 },
],
}
const account = () => ({
type: "oauth",
access: "jt-one",
refresh: "rt-one",
expires: Date.now() + 3_600_000,
accountId: "one@x",
uid: "u1",
machineId: "m1",
deviceToken: "dt-one",
deviceRefresh: "drt-one",
})
async function usageOf(make, envelope, listing = () => json(LISTING)) {
const seen = []
globalThis.fetch = async (url) => {
const path = new URL(String(url)).pathname
seen.push(path)
if (path.endsWith("/me/usage")) return json(envelope)
if (path.endsWith("/model/list")) return listing()
return new Response("", { status: 404 })
}
const auth = account()
const hooks = await make({ client: { auth: { set: async () => {} } } })
return { u: await hooks.auth.usage(async () => auth), seen, hooks, auth }
}
for (const [make, site] of [[QoderAuthPlugin, "qoder"], [QoderCNAuthPlugin, "qoder-cn"]]) {
test(`${site}: a free account's "0 credits left" doesn't count its free models`, async () => {
const { u } = await usageOf(make, FREE)
expect(u.windows).toEqual([{ name: "Credits", used: 100, display: "0 credits left", notModels: ["qfmodel", "dfmodel"] }])
})
test(`${site}: credits used up leave the free models out of every credit window`, async () => {
const { u } = await usageOf(make, SPENT)
expect(u.windows.map((w) => [w.name, w.used, w.notModels])).toEqual([
["Total credits", 100, ["qfmodel", "dfmodel"]],
["Credits", 100, ["qfmodel", "dfmodel"]],
["Add-on credits", 100, ["qfmodel", "dfmodel"]],
])
})
test(`${site}: a listing that can't be read counts every model, as before`, async () => {
const { u } = await usageOf(make, SPENT, () => new Response("down", { status: 502 }))
expect(u.windows.length).toBe(3)
for (const w of u.windows) expect(w.notModels).toBeUndefined()
expect(u.error).toBeUndefined()
})
test(`${site}: a listing with no free model counts every model`, async () => {
const { u } = await usageOf(make, SPENT, () => json({ app: [LISTING.app[4]] }))
for (const w of u.windows) expect(w.notModels).toBeUndefined()
})
test(`${site}: the listing the models hook read is the one used, not asked again`, async () => {
let lists = 0
const { hooks, auth } = await usageOf(make, FREE, () => (lists++, json(LISTING)))
expect(lists).toBe(1)
await hooks.provider.models({ models: {} }, { auth })
expect(lists).toBe(2)
expect((await hooks.auth.usage(async () => auth)).windows[0].notModels).toEqual(["qfmodel", "dfmodel"])
expect(lists).toBe(2)
})
}