diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index 4eb6d1d..a28ba4c 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -1457,7 +1457,8 @@ function userStatus(key, server) { // and end, the daily and weekly quotas a quota-billed plan has (the share // left of each, and when it comes back), the ACUs a plan with a limit has // used this cycle, and the extra usage balance. JSON leaves out what is -// zero, so a quota with a reset and no share left is used up. magpie's +// zero, so a quota-billed plan's quota with a reset and no share is used +// up. magpie's // built-in Devin account showed none of this. async function usage(key, server) { const res = await userStatus(key, server) @@ -1472,14 +1473,18 @@ async function usage(key, server) { // ("Devin Pro"), as magpie's built-in row said it, not planName's "Pro" const out = { windows: [] } if (st.planEnd) out.until = st.planEnd - // a quota's window is shown when Devin says what is left of it; one it - // leaves out is not taken for used up + // a quota's window is shown when Devin says what is left of it. JSON + // leaves a 0 out, so on a quota-billed plan a window with a reset and no + // share left is used up: a week at 0% left came as no weeklyQuota- + // RemainingPercent beside the day's 100, and the day alone was shown + // (面条 on magpie's Discord). Billed otherwise, a missing share is no quota. + const quota = info.billingStrategy === "BILLING_STRATEGY_QUOTA" for (const [name, span, left, reset, hide] of [ ["1 day", 24 * 3600, st.dailyQuotaRemainingPercent, st.dailyQuotaResetAtUnix, info.hideDailyQuota], ["7 days", 7 * 24 * 3600, st.weeklyQuotaRemainingPercent, st.weeklyQuotaResetAtUnix, info.hideWeeklyQuota], ]) { - if (hide || left === undefined || left === null) continue const at = num(reset) + if (hide || ((left === undefined || left === null) && !(quota && at > 0))) continue out.windows.push({ name, used: Math.min(100, Math.max(0, 100 - num(left))), span, ...(at > 0 ? { resetsAt: at } : {}) }) } const limit = num(st.acuLimit) diff --git a/packages/devin/package.json b/packages/devin/package.json index d95b9ec..f38ded3 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.13", + "version": "0.1.14", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/devin/usage.test.mjs b/packages/devin/usage.test.mjs index beed05f..4c25c58 100644 --- a/packages/devin/usage.test.mjs +++ b/packages/devin/usage.test.mjs @@ -56,8 +56,24 @@ test("a Teams plan: its end, its day and week, the extra usage balance", async ( expect(seen[0].body.metadata).toMatchObject({ ideName: "devin-cli", extensionName: "devin-cli", apiKey: "devin-key", locale: "en" }) }) -test("a quota Devin says nothing left of isn't taken for used up; a hidden one isn't shown; ACUs with a limit are", async () => { - const s = status({ dailyQuotaRemainingPercent: undefined, overageBalanceMicros: undefined, acuConsumed: 12.5, acuLimit: 50 }) +// 面条 on magpie's Discord: Devin has a daily and a weekly quota; with the +// week used up only the day showed, at 0%, and routing kept sending to the +// account. JSON leaves a 0 out, so the week came as no +// weeklyQuotaRemainingPercent beside the day's 100. +test("a week used up, its share left out, shows at 100% and holds until its reset", async () => { + const s = status({ weeklyQuotaRemainingPercent: undefined }) + const { u } = await run(auth, () => new Response(JSON.stringify(s))) + expect(u.windows).toEqual([ + { name: "1 day", used: 0, span: 86400, resetsAt: 1790841600 }, + { name: "7 days", used: 100, span: 604800, resetsAt: 1791100800 }, + ]) + // both used up: both are left out + const both = status({ dailyQuotaRemainingPercent: undefined, weeklyQuotaRemainingPercent: undefined }) + expect((await run(auth, () => Response.json(both))).u.windows.map((w) => w.used)).toEqual([100, 100]) +}) + +test("a hidden quota isn't shown, nor one with no reset; ACUs with a limit are", async () => { + const s = status({ dailyQuotaResetAtUnix: undefined, dailyQuotaRemainingPercent: undefined, weeklyQuotaRemainingPercent: undefined, overageBalanceMicros: undefined, acuConsumed: 12.5, acuLimit: 50 }) s.userStatus.planStatus.planInfo.hideWeeklyQuota = true const { u } = await run({ ...auth, metadata: { ...auth.metadata, server: "https://eu.example" } }, () => Response.json(s)) expect(u).toEqual({