@magpie-community/opencode-kiro-auth 0.1.40 → 0.1.41

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 +12 -4
  2. package/index.mjs +31 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -290,10 +290,18 @@ beside the model. Claude models and Auto have thinking budget variants. Models w
290
290
 
291
291
  `auth.usage` reads `Get-Usage-Limits`: the month's credits, the Free trial
292
292
  while it is active, and each bonus (`bonuses`: a first upgrade's trial
293
- credits, a promotion's) while it is `ACTIVE` and not expired, as a window of
294
- its own with its count and when it lapses. Bonus windows are shown only.
295
- Kiro spends the plan's credits first, so a month used up while a bonus has
296
- credits left is shown only too, and the account isn't taken for spent.
293
+ credits, a promotion's) while it is `ACTIVE` or `EXHAUSTED` (used up) and
294
+ not expired, as a window of its own with its count and when it lapses.
295
+ Bonus windows are shown only. Kiro spends the plan's credits first, then
296
+ the bonus, so a month used up while a bonus has credits left goes on on
297
+ credits (`credits: true`): magpie asks that account after the provider's
298
+ accounts that still have plan credits, since the plan's credits are lost at
299
+ the month's reset and a trial's last a year. The window is also set aside
300
+ (`aside: true`), so a magpie that doesn't read `credits` doesn't take the
301
+ account for spent. Only an `ACTIVE` bonus counts as credits left (an
302
+ `EXHAUSTED` one is shown only), and when a bonus left lapses before the
303
+ month's reset the month is only set aside, so that bonus isn't asked last
304
+ and lost.
297
305
 
298
306
  With overage on (`overageConfiguration.overageStatus` `ENABLED`), the month
299
307
  is two windows, as the Kiro IDE shows it: the plan's credits, shown only
package/index.mjs CHANGED
@@ -542,11 +542,16 @@ function goG(x) {
542
542
  // round.
543
543
  //
544
544
  // Bonus credits (each allowance's bonuses: a first upgrade's trial credits,
545
- // a promotion's) are a window each while ACTIVE and not expired, after the
546
- // month's: their count, and when they lapse (runsOutAt), as they don't
547
- // reset. They are shown only (aside). Kiro spends the plan's credits
548
- // first, then these, so a month used up while a bonus has credits left
549
- // is set aside too, and the account isn't taken for spent.
545
+ // a promotion's) are a window each while ACTIVE or EXHAUSTED (used up) and
546
+ // not expired, after the month's: their count, and when they lapse
547
+ // (runsOutAt), as they don't reset. They are shown only (aside). Kiro
548
+ // spends the plan's credits first, then these, so a month used up while a
549
+ // bonus has credits left goes on on them (credits): magpie asks the
550
+ // account after those with plan credits left, as the plan's end at the
551
+ // month's reset and a trial's run a year. It is set aside too, for a
552
+ // magpie that doesn't know credits, so the account isn't taken for spent.
553
+ // Only an ACTIVE bonus counts as credits left, and a bonus left that
554
+ // lapses before the month's reset keeps the month set aside only.
550
555
  //
551
556
  // With overage on, Kiro goes on past the plan's credits, billed as post-paid
552
557
  // credits, until those reach the overage cap. The cap counts the overage
@@ -559,6 +564,8 @@ function goG(x) {
559
564
  // still sends means nothing, and the plan's credits are the month.
560
565
  const count = (used, limit) => used.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") + " / " + goG(limit)
561
566
  const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : 0)
567
+ const BONUS_SHOWN = new Set(["ACTIVE", "EXHAUSTED"])
568
+ const ON_BONUS = { aside: true, credits: true }
562
569
  const overageOn = (l) =>
563
570
  String(l?.overageConfiguration?.overageStatus ?? "").toUpperCase() === "ENABLED" || l?.overageConfiguration?.overageEnabled === true
564
571
 
@@ -577,20 +584,28 @@ function readUsage(l, now = Date.now()) {
577
584
  windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit),
578
585
  amount: used, limit, unit: "credits" })
579
586
  }
580
- const bonuses = []
587
+ const bonuses = [], spendable = []
581
588
  for (const b of Array.isArray(u?.bonuses) ? u.bonuses : []) {
582
589
  const used = num(b?.currentUsage), limit = num(b?.usageLimit), expires = num(b?.expiresAt)
583
- if (String(b?.status ?? "").toUpperCase() !== "ACTIVE" || limit <= 0 || (expires > 0 && expires * 1000 <= now)) continue
590
+ if (!BONUS_SHOWN.has(String(b?.status ?? "").toUpperCase()) || limit <= 0 || (expires > 0 && expires * 1000 <= now)) continue
584
591
  const left = Math.max(0, limit - used)
585
592
  bonuses.push({ name: b?.displayName || "Bonus credits", used: (100 * used) / limit, display: count(used, limit),
586
593
  amount: used, limit, unit: "credits", ...(expires > 0 && left > 0 ? { runsOutAt: at(expires), runsOut: left } : {}), aside: true })
594
+ // only an ACTIVE bonus is spent: one Kiro marks EXHAUSTED has nothing
595
+ // to go on with, whatever its count says
596
+ if (left > 0 && String(b?.status ?? "").toUpperCase() === "ACTIVE") spendable.push(expires)
587
597
  }
588
598
  const used = num(u?.currentUsageWithPrecision), limit = num(u?.usageLimitWithPrecision)
589
599
  const cap = overage ? num(u?.overageCapWithPrecision) || num(u?.overageCap) : 0
590
600
  const reset = at(num(u?.nextDateReset) || num(l?.nextDateReset))
591
601
  const month = { resetsAt: reset, unit: "credits", span: 30 * 24 * 3600 }
592
602
  const name = u?.displayNamePlural || u?.displayName || "Credits"
593
- const left = bonuses.some((b) => b.amount < b.limit)
603
+ const left = spendable.length > 0
604
+ // credits only when what is left outlasts the month: a bonus that
605
+ // lapses before the reset would be lost if asked last, so then the
606
+ // month is only set aside and the account keeps its listed place
607
+ const resetMs = Date.parse(reset ?? "")
608
+ const onBonus = spendable.some((e) => e > 0 && resetMs > 0 && e * 1000 < resetMs) ? { aside: true } : ON_BONUS
594
609
  if (cap > 0) {
595
610
  // what Kiro says of the overage, else what is past the plan
596
611
  const said = typeof u?.currentOveragesWithPrecision === "number" ? u.currentOveragesWithPrecision : u?.currentOverages
@@ -598,12 +613,12 @@ function readUsage(l, now = Date.now()) {
598
613
  const inPlan = Math.min(used, limit)
599
614
  plan = limit > 0 ? { name, used: (100 * inPlan) / limit, display: count(inPlan, limit), amount: inPlan, limit, ...month, aside: true } : undefined
600
615
  stop = { name: "Overage", used: (100 * over) / cap, display: count(over, cap), amount: over, limit: cap, ...month,
601
- ...(over >= cap && left ? { aside: true } : {}) }
616
+ ...(over >= cap && left ? onBonus : {}) }
602
617
  windows.push(...(plan ? [plan] : []), stop)
603
618
  plan ??= stop
604
619
  } else if (limit > 0) {
605
620
  plan = stop = { name, used: (100 * used) / limit, display: count(used, limit), amount: used, limit, ...month,
606
- ...(used >= limit && left ? { aside: true } : {}) }
621
+ ...(used >= limit && left ? onBonus : {}) }
607
622
  windows.push(plan)
608
623
  }
609
624
  windows.push(...bonuses)
@@ -655,9 +670,11 @@ function regionsUsage(reads, now = Date.now(), only = "") {
655
670
  allOver &&= over
656
671
  }
657
672
  monthName ??= plan.name
673
+ // a region's own windows are shown only: the sum below is weighed
674
+ const own = ({ credits, ...w }, n) => ({ ...w, name: `${n} (${r.region})`, aside: true })
658
675
  if (!counted) {
659
- shown.push({ ...plan, name: `${plan.name} (${r.region})`, aside: true })
660
- if (over) shown.push({ ...stop, name: `${stop.name} (${r.region})`, aside: true })
676
+ shown.push(own(plan, plan.name))
677
+ if (over) shown.push(own(stop, stop.name))
661
678
  regions.push({ region: r.region, full: stop.amount >= stop.limit, resetsAt: Date.parse(stop.resetsAt ?? "") > 0 ? Date.parse(stop.resetsAt) : 0 })
662
679
  continue
663
680
  }
@@ -667,8 +684,8 @@ function regionsUsage(reads, now = Date.now(), only = "") {
667
684
  ofPlan += plan.limit
668
685
  const at = Date.parse(stop.resetsAt ?? "")
669
686
  if (at > 0 && (!resets || at < resets)) resets = at
670
- shown.push({ ...plan, name: `${plan.name} (${r.region})`, aside: true })
671
- if (over) shown.push({ ...stop, name: `${stop.name} (${r.region})`, aside: true })
687
+ shown.push(own(plan, plan.name))
688
+ if (over) shown.push(own(stop, stop.name))
672
689
  regions.push({ region: r.region, full: stop.amount >= stop.limit, resetsAt: at > 0 ? at : 0 })
673
690
  }
674
691
  const windows = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-kiro-auth",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",