From 466d06ce5586849af4163ee0f312179a125e00ce Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 07:04:59 +0800 Subject: [PATCH] =?UTF-8?q?zcode=200.1.5:=20the=20month's=20MCP=20tool=20c?= =?UTF-8?q?alls=20are=20set=20aside=20as=20'MCP=20=C2=B7=20Month',=20as=20?= =?UTF-8?q?the=20built-in's=20quota=20did,=20not=20counted=20as=20a=20wind?= =?UTF-8?q?ow=20=E2=80=94=20an=20older=20plan=20reports=20that=20uncapped?= =?UTF-8?q?=20month=20as=20100%=20used,=20which=20read=20the=20account=20a?= =?UTF-8?q?s=20out=20of=20quota=20and=20skipped=20it;=20a=20limit=20whose?= =?UTF-8?q?=20whole=20is=200=20is=20set=20aside=20too.=20The=20new=20test?= =?UTF-8?q?=20in=20usage.test.mjs=20fails=20against=200.1.4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/zcode/index.mjs | 7 ++++++- packages/zcode/package.json | 2 +- packages/zcode/usage.test.mjs | 28 +++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/zcode/index.mjs b/packages/zcode/index.mjs index fa6e383..f024bfa 100644 --- a/packages/zcode/index.mjs +++ b/packages/zcode/index.mjs @@ -282,13 +282,18 @@ const isNum = (v) => typeof v === "number" && Number.isFinite(v) // limitWindows are /api/monitor/usage/quota/limit's limits as windows: what // is used of the whole when both are told (the whole less what remains, or -// the current value), else the percentage given. +// the current value), else the percentage given. TIME_LIMIT is the month's +// MCP tool calls, which ZCode shows but never stops the models on, so it is +// set aside, as is a limit whose whole is told as 0: no cap (an older +// plan's), which the vendor may still give as 100% used. function limitWindows(d) { const out = [] for (const x of d?.limits ?? []) { const span = spanOf(Math.trunc(Number(x?.unit) || 0), x?.number) const w = { name: windowName(span), used: 0 } + if (String(x?.type ?? "").toUpperCase() === "TIME_LIMIT") (w.name = "MCP · Month"), (w.aside = true) if (isNum(x?.percentage)) w.used = x.percentage + if (x?.usage === 0) (w.used = 0), (w.aside = true) if (isNum(x?.usage) && x.usage > 0) { const total = x.usage if (isNum(x.remaining)) { diff --git a/packages/zcode/package.json b/packages/zcode/package.json index 4b72977..21fbb0a 100644 --- a/packages/zcode/package.json +++ b/packages/zcode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zcode-auth", - "version": "0.1.4", + "version": "0.1.5", "description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan", "type": "module", "main": "./index.mjs", diff --git a/packages/zcode/usage.test.mjs b/packages/zcode/usage.test.mjs index 402dce4..e63b4a2 100644 --- a/packages/zcode/usage.test.mjs +++ b/packages/zcode/usage.test.mjs @@ -78,7 +78,7 @@ test("windows, names and terms as Go reads them", () => { { name: "Weekly", used: 25, display: "200 / 800", span: 604800 }, { name: "0 hours", used: 7.5, span: 1800 }, { name: "3 days", used: 0, span: 3 * 86400 }, - { name: "Monthly", used: 0, span: 30 * 86400 }, + { name: "Monthly", used: 0, aside: true, span: 30 * 86400 }, // a whole of 0: no cap { name: "Credits", used: 0 }, ]) // Beijing times: the next renewal, auto or not; else the valid span's end @@ -91,6 +91,32 @@ test("windows, names and terms as Go reads them", () => { expect(_internal.termOf([{ status: "VALID", valid: "2026-09-18 - 2026-10-18" }])).toEqual({ until: "2026-10-17T16:00:00.000Z", renew: "off" }) }) +// Go's TestZCodeNoMonthlyCap (#366): the month's MCP tool calls are named +// and set aside as the built-in's are, so an older plan's uncapped month, +// told as 100% used, never reads as the account run out +test("the month's MCP calls: named and set aside, an uncapped month nothing used", () => { + const reset = Date.now() + 3 * 3600_000 + const month = Date.now() + 20 * 86400_000 + expect(_internal.limitWindows({ level: "pro", limits: [ + { type: "TOKENS_LIMIT", unit: 3, number: 5, percentage: 0, nextResetTime: reset }, + { type: "TIME_LIMIT", unit: 5, number: 1, usage: 0, currentValue: 0, remaining: 0, percentage: 100, nextResetTime: month }, + ] })).toEqual([ + { name: "5 hours", used: 0, resetsAt: new Date(reset).toISOString(), span: 5 * 3600 }, + { name: "MCP · Month", used: 0, aside: true, resetsAt: new Date(month).toISOString(), span: 30 * 86400 }, + ]) + // capped and used up: still shown as used, still aside + const ws = _internal.limitWindows({ limits: [ + { type: "TOKENS_LIMIT", unit: 3, number: 5, percentage: 10, nextResetTime: reset }, + { type: "TOKENS_LIMIT", unit: 6, number: 1, percentage: 30, nextResetTime: month }, + { type: "TIME_LIMIT", unit: 5, number: 1, usage: 100, currentValue: 100, remaining: 0, percentage: 100, nextResetTime: month }, + ] }) + expect(ws.map((w) => [w.name, w.used, !!w.aside, w.display])).toEqual([ + ["5 hours", 10, false, undefined], + ["Weekly", 30, false, undefined], + ["MCP · Month", 100, true, "100 / 100"], + ]) +}) + // a Start Plan with one bucket, GLM-5.1's tokens for the day, a quarter used function startBalance(now, status) { return { server_time: now, plans: [{ plan_id: "zai-start-plan", user_plan_id: "up1", name: "Start Plan", status, ends_at: now + 7 * 86400,