@magpie-community/opencode-kiro-auth 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/index.mjs +23 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -240,6 +240,15 @@ the `provider.models` hook replaces it with the account's own list from
240
240
  context window, output limit and whether it takes images. Claude models
241
241
  and Auto have the thinking variants.
242
242
 
243
+ ## Usage in magpie
244
+
245
+ `auth.usage` reads `Get-Usage-Limits`: the month's credits, the Free trial
246
+ while it is active, and each bonus (`bonuses`: a first upgrade's trial
247
+ credits, a promotion's) while it is `ACTIVE` and not expired, as a window of
248
+ its own with its count and when it lapses. Bonus windows are shown only.
249
+ Kiro spends the plan's credits first, so a month used up while a bonus has
250
+ credits left is shown only too, and the account isn't taken for spent.
251
+
243
252
  ## Not included
244
253
 
245
254
  - Usage and quota (credits, the monthly window).
package/index.mjs CHANGED
@@ -419,7 +419,14 @@ function goG(x) {
419
419
  // magpie can say what is left of it when the user shows what is left
420
420
  // (#408): display alone is the vendor's text, which magpie can't turn
421
421
  // round.
422
- function usageOf(l) {
422
+ //
423
+ // Bonus credits (each allowance's bonuses: a first upgrade's trial credits,
424
+ // a promotion's) are a window each while ACTIVE and not expired, after the
425
+ // month's: their count, and when they lapse (runsOutAt), as they don't
426
+ // reset. They are shown only (aside). Kiro spends the plan's credits
427
+ // first, then these, so a month used up while a bonus has credits left
428
+ // is set aside too, and the account isn't taken for spent.
429
+ function usageOf(l, now = Date.now()) {
423
430
  const at = (secs) => (secs > 0 ? new Date(Math.trunc(secs) * 1000).toISOString() : undefined)
424
431
  const count = (used, limit) => used.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") + " / " + goG(limit)
425
432
  const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : 0)
@@ -431,11 +438,22 @@ function usageOf(l) {
431
438
  windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit),
432
439
  amount: used, limit, unit: "credits" })
433
440
  }
441
+ const bonuses = []
442
+ for (const b of Array.isArray(u?.bonuses) ? u.bonuses : []) {
443
+ const used = num(b?.currentUsage), limit = num(b?.usageLimit), expires = num(b?.expiresAt)
444
+ if (String(b?.status ?? "").toUpperCase() !== "ACTIVE" || limit <= 0 || (expires > 0 && expires * 1000 <= now)) continue
445
+ const left = Math.max(0, limit - used)
446
+ bonuses.push({ name: b?.displayName || "Bonus credits", used: (100 * used) / limit, display: count(used, limit),
447
+ amount: used, limit, unit: "credits", ...(expires > 0 && left > 0 ? { runsOutAt: at(expires), runsOut: left } : {}), aside: true })
448
+ }
434
449
  const used = num(u?.currentUsageWithPrecision), limit = num(u?.usageLimitWithPrecision)
435
- if (limit <= 0) continue
436
- const reset = num(u?.nextDateReset) || num(l?.nextDateReset)
437
- windows.push({ name: u?.displayNamePlural || u?.displayName || "Credits", used: (100 * used) / limit, resetsAt: at(reset),
438
- display: count(used, limit), amount: used, limit, unit: "credits", span: 30 * 24 * 3600 })
450
+ if (limit > 0) {
451
+ const reset = num(u?.nextDateReset) || num(l?.nextDateReset)
452
+ const carried = used >= limit && bonuses.some((b) => b.amount < b.limit)
453
+ windows.push({ name: u?.displayNamePlural || u?.displayName || "Credits", used: (100 * used) / limit, resetsAt: at(reset),
454
+ display: count(used, limit), amount: used, limit, unit: "credits", span: 30 * 24 * 3600, ...(carried ? { aside: true } : {}) })
455
+ }
456
+ windows.push(...bonuses)
439
457
  }
440
458
  const email = l?.userInfo?.email
441
459
  return { plan: planName(l?.subscriptionInfo?.subscriptionTitle), ...(typeof email === "string" && email ? { user: email } : {}), windows }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-kiro-auth",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",