usage: a GLM Coding Plan key's card on bigmodel.cn or Z.ai shows its reset cards, five-hour and weekly, counted from customer-package-reset/list (targetType=PERSONAL) as the vendor's usage page counts them: only those still available; a list that can't be read shows none, never 0. Read only, never spent from magpie (#1191)

The list is asked with the plan's key, bare in Authorization, at the host its
term (subscription/list) is asked at, so open.bigmodel.cn and api.z.ai alike;
a ZCode account on the built-in gets the same. The tooltip says "The plan's
resets" for a person's own, "The team plan's" for a team's (ResetCredits.Team).

Tested: the reporter's literal reply (ids and times filled in, same shape)
in TestZhipuPersonalResets, TestPlanQuotas and TestZCodeAccounts, each
failing with the change reverted; reset-each-title in Chromium and WebKit,
en/zh/ja/de; a real Z.ai key through zhipuPersonalResets (1 five-hour,
1 weekly). Not tried: a real bigmodel.cn key.
This commit is contained in:
yetone
2026-10-08 05:57:48 +08:00
parent 7855efc7fd
commit b69b0e8100
10 changed files with 185 additions and 10 deletions
+2 -1
View File
@@ -13857,7 +13857,8 @@ function resetsWords(r, q) {
if (r.fiveHour) parts.push(t(r.fiveHour === 1 ? "1 five-hour reset" : "{n} five-hour resets", { n: r.fiveHour }));
if (r.weekly) parts.push(t(r.weekly === 1 ? "1 weekly reset" : "{n} weekly resets", { n: r.weekly }));
w.append(el("span", "resets-n", "↺ " + parts.join(" · ")));
w.title = t("The team plan's resets, used on bigmodel.cn or z.ai");
// a GLM Coding plan's resets, a team's or the person's own (#1191)
w.title = r.team ? t("The team plan's resets, used on bigmodel.cn or z.ai") : t("The plan's resets, used on bigmodel.cn or z.ai");
if (r.until) {
const at = new Date(r.until);
w.append(el("span", "resets-until", " · " + t("until {when}", { when: resetClock(at) })));
+4
View File
@@ -1393,6 +1393,7 @@ const I18N = {
"1 weekly reset": "1 张每周重置卡",
"{n} weekly resets": "{n} 张每周重置卡",
"The team plan's resets, used on bigmodel.cn or z.ai": "团队套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
"The plan's resets, used on bigmodel.cn or z.ai": "套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
"until {when}": "{when}前有效",
"The first runs out {when}": "最早的一张 {when} 到期",
"Reset {n} runs out {when}": "第 {n} 张 {when} 到期",
@@ -5107,6 +5108,7 @@ const I18N = {
"1 weekly reset": "1 張每週重置卡",
"{n} weekly resets": "{n} 張每週重置卡",
"The team plan's resets, used on bigmodel.cn or z.ai": "團隊套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
"The plan's resets, used on bigmodel.cn or z.ai": "套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
"until {when}": "{when}前有效",
"The first runs out {when}": "最早的一張 {when} 到期",
"Reset {n} runs out {when}": "第 {n} 張 {when} 到期",
@@ -8797,6 +8799,7 @@ const I18N = {
"1 weekly reset": "週次リセット1回分",
"{n} weekly resets": "週次リセット{n}回分",
"The team plan's resets, used on bigmodel.cn or z.ai": "チームプランのリセット。bigmodel.cn または z.ai で使用します",
"The plan's resets, used on bigmodel.cn or z.ai": "プランのリセット。bigmodel.cn または z.ai で使用します",
"until {when}": "{when}まで",
"The first runs out {when}": "最初のものは{when}に期限切れ",
"Reset {n} runs out {when}": "{n}つ目のリセットは{when}に期限切れ",
@@ -12506,6 +12509,7 @@ const I18N = {
"1 weekly reset": "1 Wochen-Reset",
"{n} weekly resets": "{n} Wochen-Resets",
"The team plan's resets, used on bigmodel.cn or z.ai": "Die Resets des Team-Tarifs, einlösbar auf bigmodel.cn oder z.ai",
"The plan's resets, used on bigmodel.cn or z.ai": "Die Resets des Tarifs, einlösbar auf bigmodel.cn oder z.ai",
"until {when}": "bis {when}",
"The first runs out {when}": "Der erste läuft {when} ab",
"Reset {n} runs out {when}": "Reset {n} läuft {when} ab",
+23 -7
View File
@@ -2,8 +2,9 @@
// A card's resets, hovered, list each one left and when it runs out, a line
// each, soonest first (#960, Magixyne: the tooltip only restated the first
// one's date the card already shows). A Codex account's are numbered, one
// that never runs out last; a GLM team's say which window each resets; a
// plugin's, whose list isn't told, keep the one line. The Usage page's card
// that never runs out last; a GLM team's say which window each resets,
// and so do a GLM Coding Plan key's own (#1191), each named for whose plan
// it is; a plugin's, whose list isn't told, keep the one line. The Usage page's card
// and the menu bar panel's, at 900px and 440px. English, Chinese, Japanese
// and German, Chromium and WebKit; no backend, the API is faked here.
const assert = require("node:assert/strict");
@@ -21,14 +22,18 @@ const quotas = [
resets: { count: 3, until: a, each: [{ until: a }, { until: c }, {}] } },
{ provider: "zhipu", name: "GLM Coding", icon: "zhipu-color", user: "team@example.com", plan: "Team",
windows: [{ name: "5 hours", used: 30 }],
resets: { count: 3, byWindow: true, fiveHour: 2, weekly: 1, until: a,
resets: { count: 3, byWindow: true, team: true, fiveHour: 2, weekly: 1, until: a,
each: [{ until: a, window: "fiveHour" }, { until: b, window: "weekly" }, { until: c, window: "fiveHour" }] } },
{ provider: "codex-plugin", name: "Codex (plugin)", user: "p@example.com", plan: "Plus",
windows: [{ name: "7 days", used: 10, resetsAt: b }], resets: { count: 2, until: b } },
{ provider: "glm", name: "GLM", icon: "zhipu-color", user: "work", plan: "pro",
windows: [{ name: "5 hours", used: 20 }],
resets: { count: 2, byWindow: true, fiveHour: 1, weekly: 1, until: b,
each: [{ until: b, window: "weekly" }, { until: c, window: "fiveHour" }] } },
];
function serve(lang) {
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", trayUsages: ["codex", "zhipu", "codex-plugin"], trayUsageEvery: 3 };
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", trayUsages: ["codex", "zhipu", "codex-plugin", "glm"], trayUsageEvery: 3 };
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
@@ -51,21 +56,29 @@ const words = {
nth: (n, w) => `Reset ${n} runs out ${w}`, never: (n) => `Reset ${n} never runs out`,
five: (w) => `Five-hour reset runs out ${w}`, week: (w) => `Weekly reset runs out ${w}`,
first: (w) => `The first runs out ${w}`,
team: "The team plan's resets, used on bigmodel.cn or z.ai",
own: "The plan's resets, used on bigmodel.cn or z.ai",
},
zh: {
nth: (n, w) => `第 ${n} 张 ${w} 到期`, never: (n) => `第 ${n} 张永不过期`,
five: (w) => `5 小时重置卡 ${w} 到期`, week: (w) => `每周重置卡 ${w} 到期`,
first: (w) => `最早的一张 ${w} 到期`,
team: "团队套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
own: "套餐的重置卡,在 bigmodel.cn 或 z.ai 上使用",
},
ja: {
nth: (n, w) => `${n}つ目のリセットは${w}に期限切れ`, never: (n) => `${n}つ目のリセットは期限なし`,
five: (w) => `5時間リセットは${w}に期限切れ`, week: (w) => `週次リセットは${w}に期限切れ`,
first: (w) => `最初のものは${w}に期限切れ`,
team: "チームプランのリセット。bigmodel.cn または z.ai で使用します",
own: "プランのリセット。bigmodel.cn または z.ai で使用します",
},
de: {
nth: (n, w) => `Reset ${n} läuft ${w} ab`, never: (n) => `Reset ${n} läuft nie ab`,
five: (w) => `Fünf-Stunden-Reset läuft ${w} ab`, week: (w) => `Wochen-Reset läuft ${w} ab`,
first: (w) => `Der erste läuft ${w} ab`,
team: "Die Resets des Team-Tarifs, einlösbar auf bigmodel.cn oder z.ai",
own: "Die Resets des Tarifs, einlösbar auf bigmodel.cn oder z.ai",
},
};
@@ -91,22 +104,25 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
codex: [w.nth(1, wa), w.nth(2, wc), w.never(3)],
team: [w.five(wa), w.week(wb), w.five(wc)],
plugin: w.first(wb),
own: [w.week(wb), w.five(wc)],
};
};
const check = async (page, sel) => {
await page.locator(sel).first().waitFor();
const titles = await page.locator(sel + " .resets-words").evaluateAll((es) => es.map((e) => e.title));
assert.equal(titles.length, 3, "every card's resets are told");
assert.equal(titles.length, 4, "every card's resets are told");
const ww = await want(page);
const [codex, team, plugin] = titles.map((s) => s.split("\n"));
const [codex, team, plugin, own] = titles.map((s) => s.split("\n"));
assert.deepEqual(codex.slice(0, 3), ww.codex, "a Codex account's, numbered, soonest first, the one that never runs out last");
assert.equal(codex.length, 4, "the Auto-use line follows them");
assert.equal(team.length, 4, "the team plan's line, then each reset");
assert.deepEqual(team.slice(1), ww.team, "a team's, each its window, soonest first");
assert.deepEqual(plugin, [ww.plugin], "a plugin's, not listed, keeps the one line");
assert.equal(team[0], w.team, "a team's say they are the team plan's");
assert.deepEqual(own, [w.own, ...ww.own], "a GLM key's own say they are the plan's, then each, soonest first");
// the card itself says what it did
const shown = await page.locator(sel + " .resets-words .resets-n").allTextContents();
assert.equal(shown.length, 3);
assert.equal(shown.length, 4);
// nothing cut off: the resets' words stay inside their card
const fits = await page.locator(sel + " .resets-words").evaluateAll((es) => es.every((e) => {
const card = e.closest(".pq-card, .subscription-card, .subscription-account") || document.body;
+2
View File
@@ -32,6 +32,8 @@ type ResetCredits struct {
ByWindow bool `json:"byWindow,omitempty"`
FiveHour int `json:"fiveHour,omitempty"`
Weekly int `json:"weekly,omitempty"`
// Team: the resets are a GLM Coding team plan's, not the person's own
Team bool `json:"team,omitempty"`
// Each is every reset still to be used and when it runs out, the
// soonest first, one that never does last (#960: the card's tooltip
// lists them, where it only said the first). Empty when the vendor
+6 -1
View File
@@ -526,7 +526,12 @@ func PlanQuotas(ctx context.Context) []SubscriptionQuota {
k.Key = j.key
noteKeyAllowance(k, ws, time.Now())
if strings.HasSuffix(j.src.url, "/api/monitor/usage/quota/limit") && !team { // Zhipu, Z.ai
q.Until, q.Renew = zhipuTerm(ctx, zcodeRoot(j.src.url), j.key)
// the plan's term and its resets (#1191), asked together
root := zcodeRoot(j.src.url)
resets := make(chan *ResetCredits, 1)
go func() { resets <- zhipuPersonalResets(ctx, root, j.key) }()
q.Until, q.Renew = zhipuTerm(ctx, root, j.key)
q.Resets = <-resets
}
}
q = keepReading(ctx, q, tag)
+14
View File
@@ -251,6 +251,13 @@ func TestPlanQuotas(t *testing.T) {
w.Write([]byte(`{"code":200,"success":true,"data":[{"productName":"GLM Coding Pro","status":"VALID","autoRenew":1,"nextRenewTime":"2026-10-18 10:00:00"}]}`))
case "open.bigmodel.cn/api/biz/subscription/list glm-b":
w.WriteHeader(http.StatusInternalServerError)
case "open.bigmodel.cn/api/biz/customer-package-reset/list glm-a":
if r.URL.Query().Get("targetType") != "PERSONAL" {
t.Errorf("resets asked as %s", r.URL)
}
w.Write([]byte(zhipuResetList))
case "open.bigmodel.cn/api/biz/customer-package-reset/list glm-b":
w.Write([]byte(`{"code":1000,"msg":"身份验证失败。","success":false}`))
case "api.minimaxi.com/v1/token_plan/remains Bearer sk-cp-k":
w.Write([]byte(`{"model_remains":[{"model_name":"general","current_interval_remaining_percent":75,"current_interval_status":1,
"current_weekly_remaining_percent":96,"current_weekly_status":1}],"base_resp":{"status_code":0,"status_msg":"success"}}`))
@@ -299,6 +306,13 @@ func TestPlanQuotas(t *testing.T) {
if q := got["glm/home"]; q.Plan != "lite" || q.Windows[0].Used != 90 || q.Until != nil || q.Error != "" {
t.Errorf("second key: %+v", q)
}
// its resets (#1191): a list read is counted, one refused shows none
if r := got["glm/work"].Resets; r == nil || r.Count != 2 || r.FiveHour != 1 || r.Weekly != 1 {
t.Errorf("first key's resets: %+v", r)
}
if r := got["glm/home"].Resets; r != nil {
t.Errorf("second key's resets: %+v", r)
}
if q := got["go/"]; q.Name != "OpenCode Go" || len(q.Windows) != 1 || q.Windows[0].Name != "5 hours" {
t.Errorf("go: %+v", q)
}
+3
View File
@@ -391,7 +391,10 @@ func zcodeQuota(ctx context.Context, l Login, k zcodeKey) SubscriptionQuota {
q.Plan = "GLM Coding " + strings.ToUpper(data.Level[:1]) + data.Level[1:]
}
q.Windows = data.windows()
resets := make(chan *ResetCredits, 1)
go func() { resets <- zhipuPersonalResets(ctx, zcodeRoot(k.Base), k.Key) }()
q.Until, q.Renew = zhipuTerm(ctx, zcodeRoot(k.Base), k.Key)
q.Resets = <-resets
return q
}
+22 -1
View File
@@ -340,6 +340,27 @@ func zhipuTeamWindows(ctx context.Context, root, key, base, org, project string)
// hours and of the week: those of customer-package-reset/list still
// available. nil when it can't be told or there are none.
func zhipuTeamResets(ctx context.Context, root, auth, base, org, project string) *ResetCredits {
r := zhipuResets(ctx, root+"/api/biz/customer-package-reset/list?targetType=TEAM", auth, zcodeTeamHeaders(base, org, project))
if r != nil {
r.Team = true
}
return r
}
// zhipuPersonalResets is how many resets a GLM Coding Plan of a person's
// own holds, as bigmodel.cn's usage page lists them (#1191), asked with
// the plan's key where its term is (zhipuTerm). Only read: a reset is
// spent on the vendor's own page, never from magpie.
func zhipuPersonalResets(ctx context.Context, root, key string) *ResetCredits {
return zhipuResets(ctx, root+"/api/biz/customer-package-reset/list?targetType=PERSONAL", key, nil)
}
// zhipuResets reads customer-package-reset/list: the resets of the five
// hours and of the week, of which only those still available count (one
// run out stays listed a week, available false). nil when the list
// can't be read, so no count is shown rather than 0, and when it holds
// none.
func zhipuResets(ctx context.Context, u, auth string, hdr map[string]string) *ResetCredits {
type reset struct {
Available bool `json:"available"`
Expire any `json:"expireTime"`
@@ -348,7 +369,7 @@ func zhipuTeamResets(ctx context.Context, root, auth, base, org, project string)
FiveHour []reset `json:"fiveHourResets"`
Week []reset `json:"weekResets"`
}
if err := zcodeCallH(ctx, http.MethodGet, root+"/api/biz/customer-package-reset/list?targetType=TEAM", auth, zcodeTeamHeaders(base, org, project), nil, &data); err != nil {
if err := zcodeCallH(ctx, http.MethodGet, u, auth, hdr, nil, &data); err != nil {
return nil
}
r := &ResetCredits{ByWindow: true}
+10
View File
@@ -90,6 +90,13 @@ func TestZCodeAccounts(t *testing.T) {
return
}
ok([]any{map[string]any{"productName": "GLM Coding Pro", "status": "VALID"}})
case r.URL.Path == "/api/biz/customer-package-reset/list":
// the account's own resets, asked with its key (#1191)
if auth != "two.secret2" || r.URL.Query().Get("targetType") != "PERSONAL" {
w.WriteHeader(401)
return
}
w.Write([]byte(zhipuResetList))
case r.URL.Path == "/api/monitor/usage/quota/limit":
if auth != "two.secret2" && auth != "own.secret" {
w.WriteHeader(401)
@@ -161,6 +168,9 @@ func TestZCodeAccounts(t *testing.T) {
q.Windows[1].Name != "Weekly" || q.Windows[1].Used != 10 || q.Windows[0].ResetsAt == nil {
t.Fatalf("usage: %+v", q)
}
if r := q.Resets; r == nil || r.Count != 2 || r.FiveHour != 1 || r.Weekly != 1 || r.Team {
t.Fatalf("resets: %+v", r)
}
if err := SwitchLogin("zcode", "two@example.com"); err != nil {
t.Fatal(err)
+99
View File
@@ -0,0 +1,99 @@
package provider
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
// zhipuResetList is customer-package-reset/list?targetType=PERSONAL as the
// reporter of #1191 captured it on bigmodel.cn, the account and record ids
// and times redacted there and filled in here with the reply's own shape:
// numeric ids, times as "YYYY-MM-DD HH:mm:ss".
const zhipuResetList = `{
"code": 200,
"msg": "操作成功",
"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
}
]
},
"success": true
}`
// #1191: a GLM Coding Plan's resets are counted from the list the vendor's
// usage page reads, only those still available (one run out stays listed),
// and a list that can't be read shows no count, never 0.
func TestZhipuPersonalResets(t *testing.T) {
body := ""
var asked *http.Request
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
asked = r
w.Write([]byte(body))
}))
defer srv.Close()
read := func(b string) *ResetCredits {
body = b
return zhipuPersonalResets(context.Background(), srv.URL, "glm-key")
}
r := read(zhipuResetList)
if asked.URL.Path != "/api/biz/customer-package-reset/list" || asked.URL.Query().Get("targetType") != "PERSONAL" ||
asked.Method != http.MethodGet || asked.Header.Get("Authorization") != "glm-key" {
t.Fatalf("asked %s %s with %q", asked.Method, asked.URL, asked.Header.Get("Authorization"))
}
if r == nil || r.Count != 2 || r.FiveHour != 1 || r.Weekly != 1 || !r.ByWindow || r.Team {
t.Fatalf("resets: %+v", r)
}
cst := time.FixedZone("CST", 8*3600)
if want := time.Date(2026, 10, 30, 23, 59, 59, 0, cst); r.Until == nil || !r.Until.Equal(want) {
t.Fatalf("until %v, want %v", r.Until, want)
}
if len(r.Each) != 2 || r.Each[0].Window != "weekly" || r.Each[1].Window != "fiveHour" {
t.Fatalf("each: %+v", r.Each)
}
if w := r.Words(); w != "1 five-hour reset · 1 weekly reset" {
t.Fatalf("words: %q", w)
}
for name, b := range map[string]string{
// api.z.ai's and bigmodel.cn's answer to a key they don't take
"refused": `{"code":1000,"msg":"身份验证失败。","success":false}`,
"not json": `<html>502 Bad Gateway</html>`,
"cut off": zhipuResetList[:200],
"none left": `{"code":200,"msg":"操作成功","data":{"targetType":"PERSONAL","fiveHourResets":[],"weekResets":[
{"recordId":0,"grantType":"DIRECT","expireTime":"2026-10-04 23:59:59","available":false}]},"success":true}`,
"no data": `{"code":200,"msg":"操作成功","data":null,"success":true}`,
} {
if r := read(b); r != nil {
t.Errorf("%s: %+v, want no count", name, r)
}
}
}