diff --git a/packages/zcode/README.md b/packages/zcode/README.md index d728d2d..48cbc77 100644 --- a/packages/zcode/README.md +++ b/packages/zcode/README.md @@ -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); diff --git a/packages/zcode/index.mjs b/packages/zcode/index.mjs index 478985e..433e375 100644 --- a/packages/zcode/index.mjs +++ b/packages/zcode/index.mjs @@ -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 diff --git a/packages/zcode/package.json b/packages/zcode/package.json index 27d65dd..81181f3 100644 --- a/packages/zcode/package.json +++ b/packages/zcode/package.json @@ -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", diff --git a/packages/zcode/usage.test.mjs b/packages/zcode/usage.test.mjs index 1d72da7..d40d39e 100644 --- a/packages/zcode/usage.test.mjs +++ b/packages/zcode/usage.test.mjs @@ -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) })