zcode 0.1.19: a GLM Coding Plan's own resets show on the card, each with its end, a team's say so, and a Start Plan refusal says what to do, as the built-in did
What changed, for parity with magpie's built-in ZCode before it retires:
- Personal resets. The built-in's zcodeQuota read
/api/biz/customer-package-reset/list?targetType=PERSONAL with the plan's
key (zhipuPersonalResets, yetone/magpie#1191) and showed the count, by
window, and each reset's end. The plugin read only the team's list.
codingUsage now reads the personal list alongside the subscription list,
so a Coding Plan card (and a dual gift + Coding Plan card, built on it)
carries resets: {count, byWindow, fiveHour, weekly, until, each}.
- Team resets now carry team: true and each, as zhipuTeamResets set Team.
Both lists are read by one resetsOf: only available ones count, each
{until?, window} sorted soonest first with an endless one last
(sortResetCards), nothing on a failed read or none left.
- Start Plan refusal. A Start Plan answer that is a 405, the block page
("request has been blocked" / errors.aliyun.com) or code 3012 / "unusual
activity" now comes back, same status, as {type:"error", error:{message:
"<vendor's words, or the status for a block page> — <hint>"}}, the hint
word for word magpie's provider.ZCodeStartBlockedHint, as the built-in's
zcodeStartExplain / Provider.Explain put it. The block page's own words
are left out, so magpie's APIError no longer reads it as a network
firewall's (BlockedHint). Coding Plan and team answers are untouched.
- README: the resets and the Start Plan's hint.
What was run:
- usage.test.mjs: a new test with #1191's literal reset list (the
built-in's zhipuResetList) fails on 0.1.18 (no resets); the team test,
now expecting team and each, fails on 0.1.18 too.
- start.test.mjs: the new refusal test fails with the startBlocked line
disabled by hand (block page passed through), passes with it.
- Every packages/zcode test file under a scratch HOME: dual 25, gift 20,
models 1, moved 1, own 6, signin 3, start 11, usage 16 (83 pass).
- bun scripts/check.mjs zcode passes.
Not tried: a real account's reset list or a real Start Plan refusal.
`team` and `each` reach magpie's card from its next release; older magpie
ignores them.
This commit is contained in:
@@ -183,6 +183,57 @@ test("ZCode's Start Plan: its buckets, each for its models", async () => {
|
||||
expect(await usage(oauth({ site: "zai", jwt: jwt(now - 60) }))).toEqual({ signIn: "kept", error: "ZCode's sign-in has expired; sign in to ZCode again (or add the account again in magpie)" })
|
||||
})
|
||||
|
||||
// customer-package-reset/list?targetType=PERSONAL as the reporter of
|
||||
// yetone/magpie#1191 captured it on bigmodel.cn (the built-in's
|
||||
// zhipu_resets_test.go zhipuResetList): one run out stays listed.
|
||||
const PERSONAL_RESETS = {
|
||||
code: 200, msg: "操作成功", success: true,
|
||||
data: {
|
||||
customerId: 0, targetType: "PERSONAL", organizationId: null, projectId: null,
|
||||
lastFiveHourResetTime: "2026-10-06 21:14:03", lastWeekResetTime: null,
|
||||
fiveHourResets: [{ recordId: 0, grantType: "DIRECT", expireTime: "2026-11-02 23:59:59", available: true }],
|
||||
weekResets: [
|
||||
{ recordId: 0, grantType: "DIRECT", expireTime: "2026-10-30 23:59:59", available: true },
|
||||
{ recordId: 0, grantType: "DIRECT", expireTime: "2026-10-04 23:59:59", available: false },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
test("a Coding Plan of a person's own shows its resets, each with its end, as the built-in's zhipuPersonalResets did", async () => {
|
||||
let list = PERSONAL_RESETS
|
||||
const calls = serve(({ url, headers }) => {
|
||||
if (headers.Authorization !== "glm-key") return new Response("", { status: 401 })
|
||||
if (url.pathname === "/api/biz/subscription/list") return ok([])
|
||||
if (url.pathname === "/api/monitor/usage/quota/limit") return ok({ level: "pro", limits: [] })
|
||||
if (url.pathname === "/api/biz/customer-package-reset/list" && url.searchParams.get("targetType") === "PERSONAL")
|
||||
return typeof list === "number" ? new Response("", { status: list }) : new Response(JSON.stringify(list))
|
||||
})
|
||||
const auth = oauth({ site: "bigmodel", base: "https://open.bigmodel.cn/api/anthropic", key: "glm-key" })
|
||||
expect(await usage(auth)).toEqual({
|
||||
signIn: "kept",
|
||||
plan: "GLM Coding Pro",
|
||||
windows: [],
|
||||
resets: { count: 2, byWindow: true, fiveHour: 1, weekly: 1, until: "2026-10-30T15:59:59.000Z", each: [
|
||||
{ until: "2026-10-30T15:59:59.000Z", window: "weekly" },
|
||||
{ until: "2026-11-02T15:59:59.000Z", window: "fiveHour" },
|
||||
] },
|
||||
})
|
||||
const asked = calls.find((c) => c.url.pathname === "/api/biz/customer-package-reset/list")
|
||||
expect(asked.url.origin).toBe("https://open.bigmodel.cn")
|
||||
expect(asked.method).toBe("GET")
|
||||
// a list that can't be read shows no count, never 0; nor does one with none left
|
||||
list = 500
|
||||
expect((await usage(auth)).resets).toBeUndefined()
|
||||
list = { code: 200, data: { fiveHourResets: [], weekResets: [{ available: false, expireTime: "2026-10-04 23:59:59" }] } }
|
||||
expect((await usage(auth)).resets).toBeUndefined()
|
||||
// one with no end is listed last, with none
|
||||
list = { code: 200, data: { fiveHourResets: [{ available: true }], weekResets: [{ available: true, expireTime: "2026-10-30 23:59:59" }] } }
|
||||
expect((await usage(auth)).resets).toEqual({ count: 2, byWindow: true, fiveHour: 1, weekly: 1, until: "2026-10-30T15:59:59.000Z", each: [
|
||||
{ until: "2026-10-30T15:59:59.000Z", window: "weekly" },
|
||||
{ window: "fiveHour" },
|
||||
] })
|
||||
})
|
||||
|
||||
test("a team seat: the team plan's windows, name, end and resets, its key found and saved", async () => {
|
||||
const reset = Date.now() + 2 * 3600_000
|
||||
let made = null
|
||||
@@ -219,7 +270,13 @@ test("a team seat: the team plan's windows, name, end and resets, its key found
|
||||
expect(await usage(oauth(state), sets)).toEqual({
|
||||
signIn: "kept",
|
||||
plan: "GLM Coding Team Pro", until: "2026-12-31T15:59:59.000Z", renew: "off",
|
||||
resets: { count: 3, byWindow: true, fiveHour: 2, weekly: 1, until: new Date(1790000000 * 1000).toISOString() },
|
||||
// a team's resets say so, and each its own end, soonest first, as the
|
||||
// built-in's zhipuTeamResets did
|
||||
resets: { count: 3, byWindow: true, fiveHour: 2, weekly: 1, until: new Date(1790000000 * 1000).toISOString(), team: true, each: [
|
||||
{ until: new Date(1790000000 * 1000).toISOString(), window: "fiveHour" },
|
||||
{ until: "2026-11-30T15:59:59.000Z", window: "fiveHour" },
|
||||
{ until: "2026-12-31T15:59:59.000Z", window: "weekly" },
|
||||
] },
|
||||
windows: [
|
||||
{ name: "5 hours", used: 42, display: "420 / 1000", amount: 420, limit: 1000, resetsAt: new Date(reset).toISOString(), span: 5 * 3600 },
|
||||
{ name: "Weekly", used: 10, display: "1000 / 10000", amount: 1000, limit: 10000, resetsAt: new Date(reset + 86400000).toISOString(), span: 7 * 86400 },
|
||||
|
||||
Reference in New Issue
Block a user