diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index 8404a59..62a0c9a 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -1598,9 +1598,11 @@ const compact = (n) => (Number.isInteger(n) ? String(n) : n.toFixed(2).replace(/ // usageOf is the account's credits, from its resource summary: the plan's // credits used against what the cycle grants, as magpie's built-in said — // the count itself too (amount of limit, in credits), for magpie to say it -// as used or left beside the share (magpie#659). +// as used or left beside the share (magpie#659). The free plan is said as a +// plan: "Free" alone beside the account read as the model being free, and +// routing as preferring it for that (#337). function usageOf(sum, plan) { - const out = { plan: plan || (sum?.IsPaidUser ? "Pro" : "Free"), windows: [] } + const out = { plan: plan || (sum?.IsPaidUser ? "Pro" : "Free plan"), windows: [] } let total = 0, used = 0 for (const p of sum?.Packages ?? []) { total += capacity(p?.CycleTotalCapacity) diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index cdaf3d7..87742ce 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-workbuddy-auth", - "version": "0.1.33", + "version": "0.1.34", "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)", "type": "module", "main": "./index.mjs", diff --git a/packages/workbuddy/usage.test.mjs b/packages/workbuddy/usage.test.mjs index 285076d..83a0091 100644 --- a/packages/workbuddy/usage.test.mjs +++ b/packages/workbuddy/usage.test.mjs @@ -64,7 +64,7 @@ test("a free WorkBuddy AI account, at its own site and domain", async () => { const calls = serve({ "/billing/meter/get-user-resource-summary": () => ok({ IsPaidUser: false, Packages: [{ CycleTotalCapacity: "1000", CycleUsedCapacity: "100" }] }) }) const auth = { type: "oauth", access: "ai-access", expires: later(), uid: "ai2", domain: "www.codebuddy.ai" } - expect(await usageOf(WorkBuddyAIAuthPlugin, auth)).toEqual({ signIn: "kept", plan: "Free", windows: [{ name: "Credits", used: 10, display: "100 / 1000", amount: 100, limit: 1000, unit: "credits" }] }) + expect(await usageOf(WorkBuddyAIAuthPlugin, auth)).toEqual({ signIn: "kept", plan: "Free plan", windows: [{ name: "Credits", used: 10, display: "100 / 1000", amount: 100, limit: 1000, unit: "credits" }] }) expect(calls[0].url.origin).toBe("https://www.workbuddy.ai") expect(calls[0].headers.get("x-domain")).toBe("www.codebuddy.ai") }) @@ -74,7 +74,7 @@ test("counts and plans as Go says them", () => { .toEqual({ plan: "Team", windows: [{ name: "Credits", used: (100 * 438.88000002) / 3300, display: "438.88 / 3300", amount: 438.88000002, limit: 3300, unit: "credits" }] }) // no capacity, no window expect(_internal.usageOf({ IsPaidUser: false, Packages: [{ CycleTotalCapacity: "", CycleUsedCapacity: null }] }, "")) - .toEqual({ plan: "Free", windows: [] }) + .toEqual({ plan: "Free plan", windows: [] }) expect(() => _internal.usageOf({ Packages: [{ CycleTotalCapacity: "lots" }] })).toThrow('strconv.ParseFloat: parsing "lots": invalid syntax') }) @@ -364,7 +364,7 @@ test("a personal account with no credits isn't given the enterprise's, and its r "/billing/meter/get-enterprise-user-usage": () => new Response(PERSONAL_ENT, { status: 400 }), }) const auth = { type: "oauth", access: "a", refresh: "r", expires: later(), uid: "u" } - expect(await usageOf(WorkBuddyAuthPlugin, auth)).toEqual({ signIn: "kept", plan: "Free", windows: [] }) + expect(await usageOf(WorkBuddyAuthPlugin, auth)).toEqual({ signIn: "kept", plan: "Free plan", windows: [] }) }) test("a personal account with credits never asks the enterprise meter", async () => { @@ -402,7 +402,7 @@ test("credits used up don't count the free models (plugins#138, hheei)", async ( for (const plugin of [WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin]) { serve({ "/billing/meter/get-user-resource-summary": () => ok(SPENT), "/v3/config": FREE_CFG }) const auth = { type: "oauth", access: "a", refresh: "r", expires: later(), uid: "u", domain: "" } - expect(await usageOf(plugin, auth)).toEqual({ signIn: "kept", plan: "Free", windows: [{ + expect(await usageOf(plugin, auth)).toEqual({ signIn: "kept", plan: "Free plan", windows: [{ name: "Credits", used: 100, display: "560 / 560", amount: 560, limit: 560, unit: "credits", notModels: ["deepseek-v4.1-flash"] }] }) } })