zcode 0.1.13: the claim line's name is a sentence magpie translates; its count and plan name are the display (#43)

The claim line was a window named after the plan and displaying
"1 to claim · claim it in the ZCode app". magpie shows a window's
display as it came — quotaCount (internal/gui/assets/app.js) returns
w.display when the window has no limit — and translates only the name
(t(w.name), on the card, the tips and the chart), so the line stayed
English on a Chinese interface (yetone/magpie#1001). The plugin cannot
know the interface's language (host.js and provider.Provider hand it no
locale) and magpie's translation is keyed by the string, so the
sentence has to be the name.

The window is now named "Gift plans to claim in the ZCode app" and its
display is "1 · ZCode Trust Build": the count and the plan's own name,
which are data and stay as they came, and one name for any number, so
no plural forms are needed. aside, the placement after every real
window, and the failure handling (nothing to claim, a failed preview or
an error card add no line) are unchanged. magpie adds the zh/ja/de
entries for that name alongside this.

usage.test.mjs: the fixtures carry the new name and display, and the
names list of "a coding account's line goes after its coding and gift
windows". Four of them fail on 0.1.12; bun test packages/zcode (73
pass) and bun scripts/check.mjs zcode pass.
This commit is contained in:
如是
2026-10-08 11:52:36 +08:00
committed by GitHub
parent e2c01edc83
commit f06dacd1ec
4 changed files with 23 additions and 12 deletions
+4 -2
View File
@@ -96,9 +96,11 @@ showing.
trust-build / gift plans (a day's ZCode Trust Build, say) that are not
on the account until the ZCode app claims them. The plugin reads the
app's own list of them (`GET /api/v1/zcode-plan/billing/preview`) with
the card and names them there — "1 to claim · claim it in the ZCode app"
the card and names them there — the window is named "Gift plans to
claim in the ZCode app" and the display shows "1 · ZCode Trust Build"
— set aside, so the line stops nothing and routing, usage caps and the
menu bar pass it over. The plugin never claims one: the claim needs the
menu bar pass it over. The name is a fixed sentence magpie can
translate; the count and the plan's own name are the display. The plugin never claims one: the claim needs the
Aliyun captcha attestation only the app's renderer can make. A preview
that fails, or lists nothing, adds no line at all, and a card that is an
error keeps its error. Claim the plan in the ZCode app (open it once);
+13 -5
View File
@@ -541,15 +541,23 @@ async function giftOf(s) {
return out
}
// CLAIM_HINT is the claim line's name: a fixed sentence, so magpie
// translates it with the interface's own language (the plan's name and
// the count are data, and go in the display, which is shown as it came).
const CLAIM_HINT = "Gift plans to claim in the ZCode app"
// claimHint is the card's line for gift plans ZCode is holding for the
// account but has not put on it: GET /billing/preview lists them, and
// only the ZCode app claims one — its claim takes the Aliyun captcha
// attestation the app's own renderer makes, so the plugin reads the list
// and asks the user to claim it there. A window, set aside (it is no
// allowance: using it up stops nothing), so the card shows it and
// routing, caps and the menu bar pass it over. null when there is
// nothing to claim, the preview failing or listing none among it: a
// failed read is no line at all, never a card or a refusal of its own.
// routing, caps and the menu bar pass it over. The window's name is a
// fixed sentence, so magpie can translate it (a display is shown as it
// came); the count and the plan's own name go in the display. null when
// there is nothing to claim, the preview failing or listing none among
// it: a failed read is no line at all, never a card or a refusal of its
// own.
async function claimHint(s) {
if (!s.jwt || jwtExpired(s.jwt)) return null
let d
@@ -561,8 +569,8 @@ async function claimHint(s) {
const plans = (Array.isArray(d?.plans) ? d.plans : []).filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
if (!plans.length) return null
const n = plans.length
const name = first(...plans.map((p) => (typeof p?.name === "string" ? p.name : "")), "ZCode gift plan")
return { name, used: 0, aside: true, display: `${n} to claim · claim ${n === 1 ? "it" : "them"} in the ZCode app` }
const plan = first(...plans.map((p) => (typeof p?.name === "string" ? p.name : "")), "ZCode gift plan")
return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
}
// startUsage is a gift-only account's card: its buckets, or the words
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zcode-auth",
"version": "0.1.12",
"version": "0.1.13",
"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",
+5 -4
View File
@@ -276,7 +276,8 @@ test("a model ZCode's config gives no limits has none made up", () => {
// the app's captcha attestation, see claimHint). Both fixtures are real
// responses: one account's preview while the day's ZCode Trust Build was
// still unclaimed, and one after it had claimed it. The plugin never asks
// the claim endpoint.
// the claim endpoint. The window's name is the fixed sentence magpie
// translates; the count and the plan's own name are the display.
const PREVIEW_CLAIMABLE = {
server_time: 1791216750,
plans: [{
@@ -287,7 +288,7 @@ const PREVIEW_CLAIMABLE = {
}],
}
const PREVIEW_CLAIMED = { server_time: 1791276990, plans: [] }
const TRUST_BUILD = { name: "ZCode Trust Build", used: 0, aside: true, display: "1 to claim · claim it in the ZCode app" }
const TRUST_BUILD = { name: "Gift plans to claim in the ZCode app", used: 0, aside: true, display: "1 · ZCode Trust Build" }
// the Start Plan's own card, with the preview answering what preview says
async function startCard(now, token, preview) {
@@ -364,7 +365,7 @@ test("several claimable plans are counted", async () => {
const now = Math.trunc(Date.now() / 1000)
const two = { ...PREVIEW_CLAIMABLE, plans: [PREVIEW_CLAIMABLE.plans[0], { plan_id: "zcode-v3-start-plan-trust-1007", name: "ZCode Trust Build", status: "active" }] }
const { u } = await startCard(now, jwt(now + 86400), () => ok(two))
expect(u.windows.at(-1)).toEqual({ name: "ZCode Trust Build", used: 0, aside: true, display: "2 to claim · claim them in the ZCode app" })
expect(u.windows.at(-1)).toEqual({ name: "Gift plans to claim in the ZCode app", used: 0, aside: true, display: "2 · ZCode Trust Build" })
})
// a coding account with gift plans: the line goes last, after both allowances
@@ -380,7 +381,7 @@ test("a coding account's line goes after its coding and gift windows", async ()
const auth = oauth({ site: "zai", key: "k", jwt: token, device: "d" })
const u = await usage(auth)
expect(u.plan).toBe("GLM Coding Pro")
expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "GLM-5.1-Trial", "ZCode Trust Build"])
expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "GLM-5.1-Trial", "Gift plans to claim in the ZCode app"])
expect(u.windows.at(-1)).toEqual(TRUST_BUILD)
expect(calls.filter((c) => c.url.pathname.endsWith("/preview"))).toHaveLength(1)
})