diff --git a/packages/commandcode/CHANGELOG.md b/packages/commandcode/CHANGELOG.md index 5ba908d..0c7c5b6 100644 --- a/packages/commandcode/CHANGELOG.md +++ b/packages/commandcode/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.1.24 + +- A Go, GOAT or Pro account's Credits window tells its count as well as + its share: the credits used of the month's, in credits (amount, limit, + unit). magpie adds several accounts' credits up where it puts them + together, as the Usage page's "All N accounts" strip and a folded + Routing fold of accounts, "16.40 / 30 credits", instead of a mean of + their shares (chen2652 on magpie's Discord). Bought and free credits, + dollars at model cost, are the account's balance, a row of their own + under the windows, no longer "+ $5.00 extra" after the count. + ## 0.1.22 - Reflection's Beam (`reflection/beam:free`) is sent each earlier assistant diff --git a/packages/commandcode/index.mjs b/packages/commandcode/index.mjs index 4187c01..3208187 100644 --- a/packages/commandcode/index.mjs +++ b/packages/commandcode/index.mjs @@ -616,8 +616,12 @@ function limits(c) { // never there (01huadalang on Discord). On a plan whose credits are // usage-value units (Go, GOAT, Pro) the bar is the month's credits alone, // said as credits, and the bought and free ones, dollars at model cost -// (the docs: "Buy extra credits at model cost"), are said beside it, not -// added to a pool of another unit (plugins #556). A reply with neither +// (the docs: "Buy extra credits at model cost"), are the account's +// balance beside it, not added to a pool of another unit (plugins #556). +// Its count goes as amount of limit in credits, so magpie adds several +// accounts' credits up ("16.40 / 30 credits") where it puts them together, +// as it does the Usage page's strip and a Routing fold (chen2652 on +// magpie's Discord), rather than a mean of their shares. A reply with neither // windows nor a plan tells a balance: a key's money, not an allowance. The // month's credits come back at until, the end of the plan's period // (billing/subscriptions' currentPeriodEnd), when it is known @@ -641,8 +645,10 @@ function allowanceOf(c, until) { if (known && planMonthly > 0 && unit === "units") { const pool = Math.max(planMonthly, monthly) const extra = left - monthly - const display = credits(pool - monthly) + " / " + credits(pool) + " credits" + (extra > 0 ? " + " + money(extra) + " extra" : "") - out.windows.splice(1, 0, { name: "Credits", used: Math.min(100, (100 * (pool - monthly)) / pool), display, ...reset }) + const spent = credits(pool - monthly) + const display = spent + " / " + credits(pool) + " credits" + out.windows.splice(1, 0, { name: "Credits", used: Math.min(100, (100 * (pool - monthly)) / pool), display, amount: Number(spent), limit: pool, unit: "credits", ...reset }) + if (extra > 0) out.balance = money(extra) } else if (known && planMonthly > 0) { const pool = Math.max(planMonthly, monthly) + left - monthly out.windows.splice(1, 0, { name: "Credits", used: Math.min(100, (100 * (pool - left)) / pool), display: money(pool - left) + " / " + money(pool), ...reset }) diff --git a/packages/commandcode/package.json b/packages/commandcode/package.json index ca739aa..67d9114 100644 --- a/packages/commandcode/package.json +++ b/packages/commandcode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-commandcode-auth", - "version": "0.1.23", + "version": "0.1.24", "description": "Command Code plans (Pro, GOAT, Max, Ultra, Go, Teams) in OpenCode and magpie", "type": "module", "main": "./opencode.mjs", diff --git a/packages/commandcode/parity.test.mjs b/packages/commandcode/parity.test.mjs index 61f13ef..78c2995 100644 --- a/packages/commandcode/parity.test.mjs +++ b/packages/commandcode/parity.test.mjs @@ -35,7 +35,7 @@ test("the Credits window renews when the plan's period ends", async () => { } const hooks = await CommandCodePlugin() const u = await hooks.auth.usage(async () => ({ type: "api", key: "k" })) - expect(u.windows).toEqual([{ name: "Credits", used: 60, display: "18.00 / 30.00 credits", resetsAt: "2026-11-02T08:00:00.000Z" }]) + expect(u.windows).toEqual([{ name: "Credits", used: 60, display: "18.00 / 30.00 credits", amount: 18, limit: 30, unit: "credits", resetsAt: "2026-11-02T08:00:00.000Z" }]) expect(u.until).toBe("2026-11-02T08:00:00.000Z") }) @@ -48,7 +48,7 @@ test("no period end, no reset on the Credits window", async () => { } const hooks = await CommandCodePlugin() const u = await hooks.auth.usage(async () => ({ type: "api", key: "k" })) - expect(u.windows).toEqual([{ name: "Credits", used: 60, display: "6.00 / 10.00 credits" }]) + expect(u.windows).toEqual([{ name: "Credits", used: 60, display: "6.00 / 10.00 credits", amount: 6, limit: 10, unit: "credits" }]) }) // a list of every free id and two paid ones, as the Provider API gives it diff --git a/packages/commandcode/plan-credits.test.mjs b/packages/commandcode/plan-credits.test.mjs index b2fa4ea..497063c 100644 --- a/packages/commandcode/plan-credits.test.mjs +++ b/packages/commandcode/plan-credits.test.mjs @@ -40,7 +40,7 @@ test("a real GOAT reply: its month is 70 credits, the units its windows count in const sub = fixture("subscriptions-goat.json") const u = await usage(sub, credits) const month = u.windows.find((w) => w.name === "Credits") - expect(month).toEqual({ name: "Credits", used: (100 * (70 - 69.8033399)) / 70, display: "0.20 / 70.00 credits", resetsAt: "2026-10-28T16:16:42.000Z" }) + expect(month).toEqual({ name: "Credits", used: (100 * (70 - 69.8033399)) / 70, display: "0.20 / 70.00 credits", amount: 0.2, limit: 70, unit: "credits", resetsAt: "2026-10-28T16:16:42.000Z" }) // the docs' GOAT windows: 14 and 35 credits for up to $20 and $50, and // the month up to $100: 70 credits, the same units expect(credits.windowLimits.fiveHour.cap).toBe(14) @@ -59,9 +59,10 @@ test("Pro, Go and the old Pro say credits; Max, Ultra and Teams Pro, whose credi expect(await shown("teams-pro", 10)).toBe("$30.00 / $40.00") }) -test("GOAT: bought and free credits, dollars at model cost, are said beside the month, not added to it", async () => { +test("GOAT: bought and free credits, dollars at model cost, are the balance beside the month, not added to it", async () => { const u = await usage(plan("individual-goat"), { credits: { monthlyCredits: 35, purchasedCredits: 4, freeCredits: 1 } }) - expect(u.windows).toEqual([{ name: "Credits", used: 50, display: "35.00 / 70.00 credits + $5.00 extra" }]) + expect(u.windows).toEqual([{ name: "Credits", used: 50, display: "35.00 / 70.00 credits", amount: 35, limit: 70, unit: "credits" }]) + expect(u.balance).toBe("$5.00") }) test("Max keeps the CLI's pool, the month and the bought credits together, in dollars", async () => { diff --git a/packages/commandcode/usage.test.mjs b/packages/commandcode/usage.test.mjs index 9208d17..0827c91 100644 --- a/packages/commandcode/usage.test.mjs +++ b/packages/commandcode/usage.test.mjs @@ -69,7 +69,7 @@ test("Go: the month's $10 is the pool", async () => { "/alpha/billing/subscriptions": { data: { planId: "individual-go", status: "active" } }, "/alpha/billing/credits": { credits: { monthlyCredits: 4 } }, }) - expect(u).toEqual({ signIn: "renewed", plan: "Go", windows: [{ name: "Credits", used: 60, display: "6.00 / 10.00 credits" }] }) + expect(u).toEqual({ signIn: "renewed", plan: "Go", windows: [{ name: "Credits", used: 60, display: "6.00 / 10.00 credits", amount: 6, limit: 10, unit: "credits" }] }) }) test("credits that can't be read keep the plan and say why", async () => { @@ -99,7 +99,7 @@ test("seconds and string amounts read as magpie reads them; a half cent goes to signIn: "renewed", plan: "Pro", until: new Date(1790000000 * 1000).toISOString(), - windows: [{ name: "Weekly", used: 100, span: 604800 }, { name: "Credits", used: 0.4166666666666667, display: "0.12 / 30.00 credits", resetsAt: new Date(1790000000 * 1000).toISOString() }], + windows: [{ name: "Weekly", used: 100, span: 604800 }, { name: "Credits", used: 0.4166666666666667, display: "0.12 / 30.00 credits", amount: 0.12, limit: 30, unit: "credits", resetsAt: new Date(1790000000 * 1000).toISOString() }], }) }) @@ -126,7 +126,7 @@ test("a slow subscription: the windows go without it, and the next card has it", answer() await new Promise((r) => setTimeout(r, 20)) const next = await hooks.auth.usage(async () => api) - expect(next).toEqual({ signIn: "renewed", plan: "GOAT", renew: "off", windows: [{ name: "5 hours", used: 1, span: 18000 }, { name: "Credits", used: 50, display: "35.00 / 70.00 credits" }] }) + expect(next).toEqual({ signIn: "renewed", plan: "GOAT", renew: "off", windows: [{ name: "5 hours", used: 1, span: 18000 }, { name: "Credits", used: 50, display: "35.00 / 70.00 credits", amount: 35, limit: 70, unit: "credits" }] }) }) test("a plan read is saved with the key, once", async () => { @@ -159,7 +159,7 @@ test("a plan saved stands in for a subscription slow to read: waited for a momen const t = Date.now() const u = await hooks.auth.usage(async () => ({ ...api, metadata: { plan: "GOAT", planId: "individual-goat" } })) expect(Date.now() - t).toBeLessThan(3_000) - expect(u).toEqual({ signIn: "renewed", plan: "GOAT", windows: [{ name: "Credits", used: 50, display: "35.00 / 70.00 credits" }] }) + expect(u).toEqual({ signIn: "renewed", plan: "GOAT", windows: [{ name: "Credits", used: 50, display: "35.00 / 70.00 credits", amount: 35, limit: 70, unit: "credits" }] }) answer() })