@magpie-community/opencode-kiro-auth 0.1.35 → 0.1.36
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.
- package/README.md +10 -5
- package/index.mjs +66 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,9 +257,13 @@ its own with its count and when it lapses. Bonus windows are shown only.
|
|
|
257
257
|
Kiro spends the plan's credits first, so a month used up while a bonus has
|
|
258
258
|
credits left is shown only too, and the account isn't taken for spent.
|
|
259
259
|
|
|
260
|
-
With overage on (`overageConfiguration.overageStatus` `ENABLED`), the
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
With overage on (`overageConfiguration.overageStatus` `ENABLED`), the month
|
|
261
|
+
is two windows, as the Kiro IDE shows it: the plan's credits, shown only
|
|
262
|
+
(using them up doesn't stop the account), then the overage
|
|
263
|
+
(`currentOveragesWithPrecision`) against the overage cap (`overageCap`),
|
|
264
|
+
which counts the overage alone, not the plan's credits with it. A Power
|
|
265
|
+
account that used 12589.24 shows `10000 / 10000` and `2589.24 / 37500`.
|
|
266
|
+
With overage off, the plan's credits are the month.
|
|
263
267
|
|
|
264
268
|
Each request's cost is what Kiro's `meteringEvent`s say, in credits, summed
|
|
265
269
|
over the request (a web search's turns included). Kiro has already applied
|
|
@@ -287,8 +291,9 @@ again.
|
|
|
287
291
|
- With every enabled region used up, the answer is a 429 naming them, and a
|
|
288
292
|
region not enabled, so magpie goes on to another account.
|
|
289
293
|
- `auth.usage` reads both regions: a window for each, shown only, and their
|
|
290
|
-
sum, which magpie weighs the account by.
|
|
291
|
-
|
|
294
|
+
sum, which magpie weighs the account by. With overage on, the plans' sum
|
|
295
|
+
comes first, shown only, and the overages' sum is the one magpie weighs.
|
|
296
|
+
From 80% of the sum, a region not enabled is pointed out in its text.
|
|
292
297
|
|
|
293
298
|
Builder ID, Google, GitHub and API key sign-ins keep one region.
|
|
294
299
|
|
package/index.mjs
CHANGED
|
@@ -494,18 +494,28 @@ function goG(x) {
|
|
|
494
494
|
// first, then these, so a month used up while a bonus has credits left
|
|
495
495
|
// is set aside too, and the account isn't taken for spent.
|
|
496
496
|
//
|
|
497
|
-
// With overage on, Kiro goes on past the plan's credits
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
497
|
+
// With overage on, Kiro goes on past the plan's credits, billed as post-paid
|
|
498
|
+
// credits, until those reach the overage cap. The cap counts the overage
|
|
499
|
+
// alone, not the plan's credits with it: it is the profile's "maximum
|
|
500
|
+
// allowed overage" quota (in USD, $0.04 a credit; $400 is 10000 credits).
|
|
501
|
+
// So with overage on the month is two windows, as the Kiro IDE shows it:
|
|
502
|
+
// the plan's credits (12589.24 used of a 10000 plan is "10000 / 10000"),
|
|
503
|
+
// shown only, as using them up doesn't stop the account, and the overage
|
|
504
|
+
// (2589.24 / 37500), which does (wizcheu on X). With overage off the cap Kiro
|
|
505
|
+
// still sends means nothing, and the plan's credits are the month.
|
|
501
506
|
const count = (used, limit) => used.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") + " / " + goG(limit)
|
|
507
|
+
const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : 0)
|
|
502
508
|
const overageOn = (l) =>
|
|
503
509
|
String(l?.overageConfiguration?.overageStatus ?? "").toUpperCase() === "ENABLED" || l?.overageConfiguration?.overageEnabled === true
|
|
504
|
-
|
|
510
|
+
|
|
511
|
+
// readUsage is usageOf with the month's windows named: plan, the plan's
|
|
512
|
+
// credits, and stop, the window that stops the account (the overage's
|
|
513
|
+
// with overage on, else plan itself).
|
|
514
|
+
function readUsage(l, now = Date.now()) {
|
|
505
515
|
const at = (secs) => (secs > 0 ? new Date(Math.trunc(secs) * 1000).toISOString() : undefined)
|
|
506
|
-
const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : 0)
|
|
507
516
|
const overage = overageOn(l)
|
|
508
517
|
const windows = []
|
|
518
|
+
let plan, stop
|
|
509
519
|
for (const u of l?.usageBreakdownList ?? []) {
|
|
510
520
|
const t = u?.freeTrialInfo
|
|
511
521
|
if (t && String(t.freeTrialStatus ?? "").toUpperCase() === "ACTIVE" && num(t.usageLimitWithPrecision) > 0) {
|
|
@@ -521,36 +531,53 @@ function usageOf(l, now = Date.now()) {
|
|
|
521
531
|
bonuses.push({ name: b?.displayName || "Bonus credits", used: (100 * used) / limit, display: count(used, limit),
|
|
522
532
|
amount: used, limit, unit: "credits", ...(expires > 0 && left > 0 ? { runsOutAt: at(expires), runsOut: left } : {}), aside: true })
|
|
523
533
|
}
|
|
524
|
-
const used = num(u?.currentUsageWithPrecision)
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
534
|
+
const used = num(u?.currentUsageWithPrecision), limit = num(u?.usageLimitWithPrecision)
|
|
535
|
+
const cap = overage ? num(u?.overageCapWithPrecision) || num(u?.overageCap) : 0
|
|
536
|
+
const reset = at(num(u?.nextDateReset) || num(l?.nextDateReset))
|
|
537
|
+
const month = { resetsAt: reset, unit: "credits", span: 30 * 24 * 3600 }
|
|
538
|
+
const name = u?.displayNamePlural || u?.displayName || "Credits"
|
|
539
|
+
const left = bonuses.some((b) => b.amount < b.limit)
|
|
540
|
+
if (cap > 0) {
|
|
541
|
+
// what Kiro says of the overage, else what is past the plan
|
|
542
|
+
const said = typeof u?.currentOveragesWithPrecision === "number" ? u.currentOveragesWithPrecision : u?.currentOverages
|
|
543
|
+
const over = typeof said === "number" && Number.isFinite(said) ? said : Math.max(0, used - limit)
|
|
544
|
+
const inPlan = Math.min(used, limit)
|
|
545
|
+
plan = limit > 0 ? { name, used: (100 * inPlan) / limit, display: count(inPlan, limit), amount: inPlan, limit, ...month, aside: true } : undefined
|
|
546
|
+
stop = { name: "Overage", used: (100 * over) / cap, display: count(over, cap), amount: over, limit: cap, ...month,
|
|
547
|
+
...(over >= cap && left ? { aside: true } : {}) }
|
|
548
|
+
windows.push(...(plan ? [plan] : []), stop)
|
|
549
|
+
plan ??= stop
|
|
550
|
+
} else if (limit > 0) {
|
|
551
|
+
plan = stop = { name, used: (100 * used) / limit, display: count(used, limit), amount: used, limit, ...month,
|
|
552
|
+
...(used >= limit && left ? { aside: true } : {}) }
|
|
553
|
+
windows.push(plan)
|
|
531
554
|
}
|
|
532
555
|
windows.push(...bonuses)
|
|
533
556
|
}
|
|
534
557
|
const email = l?.userInfo?.email
|
|
535
|
-
|
|
558
|
+
const usage = { plan: planName(l?.subscriptionInfo?.subscriptionTitle), ...(typeof email === "string" && email ? { user: email } : {}), windows }
|
|
559
|
+
return { usage, plan, stop }
|
|
536
560
|
}
|
|
537
561
|
|
|
562
|
+
const usageOf = (l, now = Date.now()) => readUsage(l, now).usage
|
|
563
|
+
|
|
538
564
|
// regionsUsage is an Identity Center account's credits from each region's
|
|
539
565
|
// read (reads: { region, l } read, { region, error } not, { region,
|
|
540
566
|
// missing } with no profile, not enabled): each region's month shown only,
|
|
541
567
|
// and their sum the window magpie weighs the account by, used up only when
|
|
542
|
-
// every region read is.
|
|
543
|
-
//
|
|
544
|
-
//
|
|
545
|
-
//
|
|
546
|
-
//
|
|
568
|
+
// every region read is. With overage on, the plans' sum comes first, shown
|
|
569
|
+
// only, then the overages' sum weighs the account. A free trial or bonus
|
|
570
|
+
// credits are the first read region's. regions says, of each region read,
|
|
571
|
+
// whether it is used up and when it resets. Regions read come first, then
|
|
572
|
+
// those that couldn't be read, then those not enabled: a card that shows
|
|
573
|
+
// only the first few windows then shows the credits an account has.
|
|
547
574
|
function regionsUsage(reads, now = Date.now()) {
|
|
548
575
|
const shown = []
|
|
549
576
|
const failed = []
|
|
550
577
|
const off = []
|
|
551
578
|
const regions = []
|
|
552
579
|
const missing = []
|
|
553
|
-
let amount = 0, limit = 0, resets = 0, first, monthName
|
|
580
|
+
let amount = 0, limit = 0, inPlan = 0, ofPlan = 0, resets = 0, first, monthName, anyOver = false, allOver = true
|
|
554
581
|
for (const r of reads) {
|
|
555
582
|
const name = `Credits (${r.region})`
|
|
556
583
|
if (r.error) {
|
|
@@ -562,23 +589,32 @@ function regionsUsage(reads, now = Date.now()) {
|
|
|
562
589
|
off.push({ name, display: "not enabled", aside: true })
|
|
563
590
|
continue
|
|
564
591
|
}
|
|
565
|
-
const u =
|
|
592
|
+
const { usage: u, plan, stop } = readUsage(r.l, now)
|
|
566
593
|
first ??= u
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
594
|
+
if (!stop) continue
|
|
595
|
+
const over = stop !== plan
|
|
596
|
+
anyOver ||= over
|
|
597
|
+
allOver &&= over
|
|
598
|
+
monthName ??= plan.name
|
|
599
|
+
amount += stop.amount
|
|
600
|
+
limit += stop.limit
|
|
601
|
+
inPlan += plan.amount
|
|
602
|
+
ofPlan += plan.limit
|
|
603
|
+
const at = Date.parse(stop.resetsAt ?? "")
|
|
573
604
|
if (at > 0 && (!resets || at < resets)) resets = at
|
|
574
|
-
shown.push({ ...
|
|
575
|
-
|
|
605
|
+
shown.push({ ...plan, name: `${plan.name} (${r.region})`, aside: true })
|
|
606
|
+
if (over) shown.push({ ...stop, name: `${stop.name} (${r.region})`, aside: true })
|
|
607
|
+
regions.push({ region: r.region, full: stop.amount >= stop.limit, resetsAt: at > 0 ? at : 0 })
|
|
576
608
|
}
|
|
577
609
|
const windows = []
|
|
610
|
+
const resetsAt = resets ? { resetsAt: new Date(resets).toISOString() } : {}
|
|
578
611
|
if (limit > 0) {
|
|
612
|
+
if (anyOver && ofPlan > 0)
|
|
613
|
+
windows.push({ name: monthName, used: (100 * inPlan) / ofPlan, ...resetsAt, display: count(inPlan, ofPlan), amount: inPlan, limit: ofPlan,
|
|
614
|
+
unit: "credits", span: 30 * 24 * 3600, aside: true })
|
|
579
615
|
let display = count(amount, limit)
|
|
580
616
|
if (missing.length && (100 * amount) / limit >= REMIND_SHARE) display += ` · ${missing.join(", ")} not enabled: ask your admin to enable it`
|
|
581
|
-
windows.push({ name: monthName, used: (100 * amount) / limit, ...
|
|
617
|
+
windows.push({ name: allOver ? "Overage" : monthName, used: (100 * amount) / limit, ...resetsAt,
|
|
582
618
|
display, amount, limit, unit: "credits", span: 30 * 24 * 3600 })
|
|
583
619
|
}
|
|
584
620
|
windows.push(...shown, ...failed, ...off, ...(first?.windows ?? []).filter((w) => !w.span))
|