From 2caced14efb70d00e5cddced84f8f826be2b552b Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 4 Oct 2026 13:07:10 +0800 Subject: [PATCH] =?UTF-8?q?trae=200.1.6:=20the=20usage=20card=20says=20Tra?= =?UTF-8?q?e=20CN's=20credits=20in=20the=20Credits=20row,=20as=20WorkBuddy?= =?UTF-8?q?'s,=20not=20as=20an=20English=20balance=20line=20under=20it=20(?= =?UTF-8?q?yetone/magpie#694,=20Hu9956=20on=20magpie=200.1.784:=20?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E6=98=BE=E7=A4=BA=E7=9A=84=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E6=9C=89=E7=82=B9=E4=B8=8D=E4=B8=80=E6=A0=B7=20=E2=80=94=20Wor?= =?UTF-8?q?kBuddy's=20cards=20read=20"=E7=A7=AF=E5=88=86=201,689.01=20/=20?= =?UTF-8?q?2,400=20=E7=A7=AF=E5=88=86=20=C2=B7=20=E5=89=A9=E4=BD=99=2070.4?= =?UTF-8?q?%",=20Trae=20CN's=20"=E7=A7=AF=E5=88=86=20=E5=89=A9=E4=BD=99=20?= =?UTF-8?q?60.7%"=20with=20"=E4=BD=99=E9=A2=9D=202307.42=20of=203800=20cre?= =?UTF-8?q?dits=20left"=20in=20large=20type=20below)=20=E2=80=94=20usage?= =?UTF-8?q?=20gave=20the=20share=20alone=20on=20its=20Credits=20window=20a?= =?UTF-8?q?nd=20the=20count=20as=20a=20balance=20string,=20"=20of=20?= =?UTF-8?q?=20credits=20left",=20which=20magpie=20shows=20as=20a=20?= =?UTF-8?q?separate=20=E4=BD=99=E9=A2=9D=20row=20(balanceRow,=20beside=20w?= =?UTF-8?q?indows)=20in=20the=20plugin's=20own=20English=20and=20number=20?= =?UTF-8?q?format,=20and=20never=20flips=20with=20=E5=B7=B2=E7=94=A8/?= =?UTF-8?q?=E5=89=A9=E4=BD=99.=20The=20window=20now=20carries=20the=20coun?= =?UTF-8?q?t=20as=20WorkBuddy's=20does=20(amount=20=3D=20credits=20used,?= =?UTF-8?q?=20limit=20=3D=20the=20packs'=20total,=20unit=20"credits",=20ma?= =?UTF-8?q?gpie#659),=20so=20magpie's=20quotaCount=20writes=20"2,307.42=20?= =?UTF-8?q?/=203,800=20=E7=A7=AF=E5=88=86=20=C2=B7=20=E5=89=A9=E4=BD=99=20?= =?UTF-8?q?60.7%"=20(or=20"1,492.58=20/=203,800=20=E7=A7=AF=E5=88=86=20?= =?UTF-8?q?=C2=B7=20=E5=B7=B2=E7=94=A8=2039.3%";=20"credits"=20in=20Englis?= =?UTF-8?q?h)=20in=20the=20row=20itself,=20and=20the=20balance=20is=20left?= =?UTF-8?q?=20out;=20an=20unlimited=20account=20still=20says=20"unlimited"?= =?UTF-8?q?=20as=20its=20balance.=20No=20magpie=20change=20needed:=20plugi?= =?UTF-8?q?n=5Fusage.go=20already=20passes=20a=20plugin=20window's=20amoun?= =?UTF-8?q?t,=20limit=20and=20unit=20to=20the=20card.=20usage.test.mjs=20n?= =?UTF-8?q?ow=20expects=20the=20window's=20amount/limit/unit=20and=20no=20?= =?UTF-8?q?balance=20(fails=20on=200.1.5);=20HOME=3D$(mktemp=20-d)=20bun?= =?UTF-8?q?=20test=20(465=20pass)=20and=20bun=20scripts/check.mjs=20trae?= =?UTF-8?q?=20pass.=20Checked=20in=20magpie's=20Usage=20page=20(webkit,=20?= =?UTF-8?q?zh=20and=20en,=20API=20faked=20with=20the=20old=20and=20new=20s?= =?UTF-8?q?hapes=20beside=20WorkBuddy=20and=20WorkBuddy=20AI=20cards):=20t?= =?UTF-8?q?he=20Trae=20CN=20card's=20row=20reads=20like=20WorkBuddy's=20an?= =?UTF-8?q?d=20the=20=E4=BD=99=E9=A2=9D=20line=20is=20gone.=20Not=20tried?= =?UTF-8?q?=20with=20a=20real=20Trae=20CN=20account.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/trae/README.md | 5 +++-- packages/trae/index.mjs | 7 +++++-- packages/trae/package.json | 2 +- packages/trae/usage.test.mjs | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/trae/README.md b/packages/trae/README.md index 5e4d264..5843e6c 100644 --- a/packages/trae/README.md +++ b/packages/trae/README.md @@ -105,8 +105,9 @@ magpie's usage card shows the account's credits: - **Source:** `api.trae.cn/trae/api/v2/pay/ide_user_ent_usage`. - **What it adds up:** each entitlement pack's `credits_limit` (-1 means unlimited) and what the pack has used. -- **What it shows:** credits left as the balance, and the share used as a - window. +- **What it shows:** one Credits window: the credits used of the packs' + total, with the share, which magpie shows as used or left like + WorkBuddy's. ## Daily check-in diff --git a/packages/trae/index.mjs b/packages/trae/index.mjs index 11ad04f..2ce6e2b 100644 --- a/packages/trae/index.mjs +++ b/packages/trae/index.mjs @@ -881,8 +881,11 @@ export const TraeCNAuthPlugin = async ({ client }) => { const out = { plan: r.v.is_credits_billing ? "Credits" : "Free", user: a.name || a.uid, signIn } if (c.unlimited) out.balance = "unlimited" else if (c.limit > 0) { - out.balance = `${round(Math.max(0, c.limit - c.used))} of ${round(c.limit)} credits left` - const w = { name: "Credits", used: Math.max(0, Math.min(100, (c.used / c.limit) * 100)) } + // the count rides on the window (amount of limit, in credits), as + // WorkBuddy's does, so magpie says it in the window's row, used or + // left, in its own words and number format, rather than as an + // English balance line beside it (yetone/magpie#694) + const w = { name: "Credits", used: Math.max(0, Math.min(100, (c.used / c.limit) * 100)), amount: round(c.used), limit: round(c.limit), unit: "credits" } if (c.until) w.resetsAt = new Date(c.until).toISOString() out.windows = [w] } diff --git a/packages/trae/package.json b/packages/trae/package.json index e9637ff..de8a813 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-trae-auth", - "version": "0.1.5", + "version": "0.1.6", "description": "OpenCode provider plugin for Trae CN (trae.cn): your Trae CN account's models, free tier included, with Trae's own browser sign-in", "type": "module", "main": "./index.mjs", diff --git a/packages/trae/usage.test.mjs b/packages/trae/usage.test.mjs index 2fcbd74..b52c71e 100644 --- a/packages/trae/usage.test.mjs +++ b/packages/trae/usage.test.mjs @@ -22,8 +22,8 @@ test("credits are the packs' limits and what they used", async () => { expect(u.plan).toBe("Free") expect(u.user).toBe("Ann") expect(u.signIn).toBe("kept") - expect(u.balance).toBe("300 of 400 credits left") - expect(u.windows).toEqual([{ name: "Credits", used: 25, resetsAt: new Date(1790000000 * 1000).toISOString() }]) + expect(u.balance).toBeUndefined() // the window carries the count (yetone/magpie#694) + expect(u.windows).toEqual([{ name: "Credits", used: 25, amount: 100, limit: 400, unit: "credits", resetsAt: new Date(1790000000 * 1000).toISOString() }]) }) test("unlimited packs say so", () => {