diff --git a/packages/zed/README.md b/packages/zed/README.md index b9120eb..a81ec61 100644 --- a/packages/zed/README.md +++ b/packages/zed/README.md @@ -72,9 +72,25 @@ GitHub login. (Claude Sonnet 5, Opus 5.5, Haiku 4.5, GPT-5.5, Gemini 3.5 Flash, Grok 4.7), which the account's list replaces. -## Not included +## Usage -- magpie's plan display: plan name, billing period, overdue invoices. Zed - doesn't report how much of the allowance is spent. -- Several Zed accounts at once. OpenCode keeps one sign-in per provider. -- magpie's web-search stand-in. +magpie's `auth.usage` hook shows what Zed tells its editor of the plan, +as magpie's built-in Zed account did. Zed doesn't report how much of the +allowance is spent, so there are no windows: + +- the plan's name (Pro, Pro Trial, Business, Student, VIP). A free + account's card says "No plan"; its account row still names it Free; +- when the billing period ends; +- an overdue invoice, as the card's error ("its models are paused"); +- a sign-in Zed refuses (`/users/me` or the model list answering 401) + marks the account as needing to sign in again. A plan that changed is + saved with the sign-in. + +## In magpie, not the plugin + +These come from magpie itself, as they did for the built-in: + +- Several Zed accounts at once. magpie keeps a sign-in per account and + switches between them; plain OpenCode keeps one sign-in per provider. +- Web search. A model that can't search is given magpie's web-search + stand-in, when a search API is set up in magpie. diff --git a/packages/zed/index.mjs b/packages/zed/index.mjs index 364cbb5..dc08ad3 100644 --- a/packages/zed/index.mjs +++ b/packages/zed/index.mjs @@ -988,7 +988,12 @@ async function usage(auth, save) { } const end = me.plan?.subscription_period?.ended_at if (typeof end === "string" && RFC3339.test(end) && !isNaN(Date.parse(end))) out.until = end + // the account's row keeps naming a free plan "Free" (planName, saved + // above); its card says "No plan", which magpie's card knows and + // translates, unless an overdue invoice is what it says, as the + // built-in's zedLoginQuota did if (me.plan?.has_overdue_invoices) out.error = "Zed: this account has an overdue invoice, so its models are paused (see zed.dev/account)" + else if (plan === "zed_free" || plan === "") out.plan = "No plan" return out } diff --git a/packages/zed/package.json b/packages/zed/package.json index bc314d2..17262c4 100644 --- a/packages/zed/package.json +++ b/packages/zed/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zed-auth", - "version": "0.1.7", + "version": "0.1.8", "description": "Sign in to a Zed subscription (Zed Pro, trial, student, business) from OpenCode or magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/zed/usage.test.mjs b/packages/zed/usage.test.mjs index 8a2aed5..e1b5da9 100644 --- a/packages/zed/usage.test.mjs +++ b/packages/zed/usage.test.mjs @@ -43,11 +43,16 @@ test("a Pro account: its plan and its period's end, no windows", async () => { expect(saved).toEqual([]) }) -test("a free account reads Free, as the built-in's row names it, and the plan it moved to is kept", async () => { +test("a free account's card says No plan, as the built-in's zedLoginQuota did; its row keeps Free, and the plan it moved to is kept", async () => { const { u, saved } = await run(auth(), () => new Response(me("zed_free"))) - expect(u).toEqual({ plan: "Free", until: "2026-10-01T00:00:00Z", signIn: "kept" }) + expect(u).toEqual({ plan: "No plan", until: "2026-10-01T00:00:00Z", signIn: "kept" }) expect(saved.length).toBe(1) expect(JSON.parse(saved[0].body.refresh)).toMatchObject({ plan: "zed_free", planName: "Free" }) + // an account that names no plan at all is free too + expect((await run(auth(), () => new Response(me("")))).u.plan).toBe("No plan") + // an overdue invoice is what a free card says, its plan named as the row names it + expect((await run(auth(), () => new Response(me("zed_free", true)))).u).toEqual({ plan: "Free", until: "2026-10-01T00:00:00Z", + error: "Zed: this account has an overdue invoice, so its models are paused (see zed.dev/account)", signIn: "kept" }) }) test("an overdue invoice is the error it is", async () => {