@magpie-community/opencode-kiro-auth 0.1.34 → 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 +16 -5
- package/index.mjs +94 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,12 @@ Callback URL field. The page need not load on the browser's computer. Local
|
|
|
22
22
|
browsers that can reach the plugin's listener finish automatically. Direct
|
|
23
23
|
AWS sign-in still uses authorization code + PKCE, not device authorization.
|
|
24
24
|
|
|
25
|
+
In magpie, each way, question and choice shows in the window's language
|
|
26
|
+
(Chinese, Traditional Chinese, Japanese, German): `labels`, `messages` and
|
|
27
|
+
`hints` beside the English, which OpenCode shows. A Kiro subscription in
|
|
28
|
+
magpie opens the question above first; its other ways, the API key among
|
|
29
|
+
them, are under "Other ways to sign in…".
|
|
30
|
+
|
|
25
31
|
|
|
26
32
|
- **Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)**: the Kiro
|
|
27
33
|
IDE's own sign-in.
|
|
@@ -251,9 +257,13 @@ its own with its count and when it lapses. Bonus windows are shown only.
|
|
|
251
257
|
Kiro spends the plan's credits first, so a month used up while a bonus has
|
|
252
258
|
credits left is shown only too, and the account isn't taken for spent.
|
|
253
259
|
|
|
254
|
-
With overage on (`overageConfiguration.overageStatus` `ENABLED`), the
|
|
255
|
-
|
|
256
|
-
|
|
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.
|
|
257
267
|
|
|
258
268
|
Each request's cost is what Kiro's `meteringEvent`s say, in credits, summed
|
|
259
269
|
over the request (a web search's turns included). Kiro has already applied
|
|
@@ -281,8 +291,9 @@ again.
|
|
|
281
291
|
- With every enabled region used up, the answer is a 429 naming them, and a
|
|
282
292
|
region not enabled, so magpie goes on to another account.
|
|
283
293
|
- `auth.usage` reads both regions: a window for each, shown only, and their
|
|
284
|
-
sum, which magpie weighs the account by.
|
|
285
|
-
|
|
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.
|
|
286
297
|
|
|
287
298
|
Builder ID, Google, GitHub and API key sign-ins keep one region.
|
|
288
299
|
|
package/index.mjs
CHANGED
|
@@ -27,6 +27,23 @@ import { homedir, hostname, platform, release } from "node:os"
|
|
|
27
27
|
import { delimiter, join } from "node:path"
|
|
28
28
|
|
|
29
29
|
const ID = "kiro"
|
|
30
|
+
|
|
31
|
+
// WORDS are the sign-in's words in magpie's other languages, beside the
|
|
32
|
+
// English each method, question and choice has (magpie's labels, messages
|
|
33
|
+
// and hints; OpenCode ignores them). Product names stay as written.
|
|
34
|
+
const WORDS = {
|
|
35
|
+
browser: { zh: "Kiro 登录(Google、GitHub、AWS Builder ID、IAM Identity Center)", "zh-TW": "Kiro 登入(Google、GitHub、AWS Builder ID、IAM Identity Center)", ja: "Kiro にサインイン(Google、GitHub、AWS Builder ID、IAM Identity Center)", de: "Kiro-Anmeldung (Google, GitHub, AWS Builder ID, IAM Identity Center)" },
|
|
36
|
+
choose: { zh: "选择登录方式", "zh-TW": "選擇登入方式", ja: "サインイン方法を選択", de: "Anmeldemethode wählen" },
|
|
37
|
+
enterprise: { zh: "IAM Identity Center(组织 Start URL)", "zh-TW": "IAM Identity Center(組織 Start URL)", ja: "IAM Identity Center(組織の Start URL)", de: "IAM Identity Center (Start-URL der Organisation)" },
|
|
38
|
+
enterpriseHint: { zh: "用组织的 AWS Start URL 登录", "zh-TW": "用組織的 AWS Start URL 登入", ja: "組織の AWS Start URL でサインイン", de: "Mit der AWS-Start-URL Ihrer Organisation anmelden" },
|
|
39
|
+
builderidHint: { zh: "直接打开 AWS 登录;在远程服务器上只需粘贴一次回调地址", "zh-TW": "直接開啟 AWS 登入;在遠端伺服器上只需貼上一次回呼網址", ja: "AWS のサインインを直接開きます。リモートサーバーではコールバックを 1 回貼り付けるだけです", de: "Öffnet die AWS-Anmeldung direkt; auf einem entfernten Server wird ein Callback einmal eingefügt" },
|
|
40
|
+
portal: { zh: "Kiro 登录页", "zh-TW": "Kiro 登入頁", ja: "Kiro のサインインページ", de: "Kiro-Anmeldeseite" },
|
|
41
|
+
portalHint: { zh: "Google、GitHub、IAM Identity Center 或 Kiro 的其他登录方式", "zh-TW": "Google、GitHub、IAM Identity Center 或 Kiro 的其他登入方式", ja: "Google、GitHub、IAM Identity Center など Kiro のサインイン方法", de: "Google, GitHub, IAM Identity Center oder andere Kiro-Anmeldemethoden" },
|
|
42
|
+
startUrl: { zh: "组织 Start URL", "zh-TW": "組織 Start URL", ja: "組織の Start URL", de: "Start-URL der Organisation" },
|
|
43
|
+
region: { zh: "AWS 区域(留空为 us-east-1)", "zh-TW": "AWS 區域(留空為 us-east-1)", ja: "AWS リージョン(空欄なら us-east-1)", de: "AWS-Region (leer: us-east-1)" },
|
|
44
|
+
own: { zh: "Kiro CLI 或 Kiro IDE 已登录的账号", "zh-TW": "Kiro CLI 或 Kiro IDE 已登入的帳號", ja: "Kiro CLI または Kiro IDE のサインイン", de: "Anmeldung von Kiro CLI oder Kiro IDE" },
|
|
45
|
+
key: { zh: "Kiro API Key(ksk_…)", "zh-TW": "Kiro API Key(ksk_…)", ja: "Kiro API キー(ksk_…)", de: "Kiro-API-Schlüssel (ksk_…)" },
|
|
46
|
+
}
|
|
30
47
|
const MESSAGES = "@ai-sdk/anthropic"
|
|
31
48
|
const BASE = "https://runtime.us-east-1.kiro.dev" // what OpenCode is given; the fetch sends each request to the account's region
|
|
32
49
|
|
|
@@ -477,18 +494,28 @@ function goG(x) {
|
|
|
477
494
|
// first, then these, so a month used up while a bonus has credits left
|
|
478
495
|
// is set aside too, and the account isn't taken for spent.
|
|
479
496
|
//
|
|
480
|
-
// With overage on, Kiro goes on past the plan's credits
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
//
|
|
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.
|
|
484
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)
|
|
485
508
|
const overageOn = (l) =>
|
|
486
509
|
String(l?.overageConfiguration?.overageStatus ?? "").toUpperCase() === "ENABLED" || l?.overageConfiguration?.overageEnabled === true
|
|
487
|
-
|
|
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()) {
|
|
488
515
|
const at = (secs) => (secs > 0 ? new Date(Math.trunc(secs) * 1000).toISOString() : undefined)
|
|
489
|
-
const num = (x) => (typeof x === "number" && Number.isFinite(x) ? x : 0)
|
|
490
516
|
const overage = overageOn(l)
|
|
491
517
|
const windows = []
|
|
518
|
+
let plan, stop
|
|
492
519
|
for (const u of l?.usageBreakdownList ?? []) {
|
|
493
520
|
const t = u?.freeTrialInfo
|
|
494
521
|
if (t && String(t.freeTrialStatus ?? "").toUpperCase() === "ACTIVE" && num(t.usageLimitWithPrecision) > 0) {
|
|
@@ -504,36 +531,53 @@ function usageOf(l, now = Date.now()) {
|
|
|
504
531
|
bonuses.push({ name: b?.displayName || "Bonus credits", used: (100 * used) / limit, display: count(used, limit),
|
|
505
532
|
amount: used, limit, unit: "credits", ...(expires > 0 && left > 0 ? { runsOutAt: at(expires), runsOut: left } : {}), aside: true })
|
|
506
533
|
}
|
|
507
|
-
const used = num(u?.currentUsageWithPrecision)
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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)
|
|
514
554
|
}
|
|
515
555
|
windows.push(...bonuses)
|
|
516
556
|
}
|
|
517
557
|
const email = l?.userInfo?.email
|
|
518
|
-
|
|
558
|
+
const usage = { plan: planName(l?.subscriptionInfo?.subscriptionTitle), ...(typeof email === "string" && email ? { user: email } : {}), windows }
|
|
559
|
+
return { usage, plan, stop }
|
|
519
560
|
}
|
|
520
561
|
|
|
562
|
+
const usageOf = (l, now = Date.now()) => readUsage(l, now).usage
|
|
563
|
+
|
|
521
564
|
// regionsUsage is an Identity Center account's credits from each region's
|
|
522
565
|
// read (reads: { region, l } read, { region, error } not, { region,
|
|
523
566
|
// missing } with no profile, not enabled): each region's month shown only,
|
|
524
567
|
// and their sum the window magpie weighs the account by, used up only when
|
|
525
|
-
// every region read is.
|
|
526
|
-
//
|
|
527
|
-
//
|
|
528
|
-
//
|
|
529
|
-
//
|
|
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.
|
|
530
574
|
function regionsUsage(reads, now = Date.now()) {
|
|
531
575
|
const shown = []
|
|
532
576
|
const failed = []
|
|
533
577
|
const off = []
|
|
534
578
|
const regions = []
|
|
535
579
|
const missing = []
|
|
536
|
-
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
|
|
537
581
|
for (const r of reads) {
|
|
538
582
|
const name = `Credits (${r.region})`
|
|
539
583
|
if (r.error) {
|
|
@@ -545,23 +589,32 @@ function regionsUsage(reads, now = Date.now()) {
|
|
|
545
589
|
off.push({ name, display: "not enabled", aside: true })
|
|
546
590
|
continue
|
|
547
591
|
}
|
|
548
|
-
const u =
|
|
592
|
+
const { usage: u, plan, stop } = readUsage(r.l, now)
|
|
549
593
|
first ??= u
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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 ?? "")
|
|
556
604
|
if (at > 0 && (!resets || at < resets)) resets = at
|
|
557
|
-
shown.push({ ...
|
|
558
|
-
|
|
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 })
|
|
559
608
|
}
|
|
560
609
|
const windows = []
|
|
610
|
+
const resetsAt = resets ? { resetsAt: new Date(resets).toISOString() } : {}
|
|
561
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 })
|
|
562
615
|
let display = count(amount, limit)
|
|
563
616
|
if (missing.length && (100 * amount) / limit >= REMIND_SHARE) display += ` · ${missing.join(", ")} not enabled: ask your admin to enable it`
|
|
564
|
-
windows.push({ name: monthName, used: (100 * amount) / limit, ...
|
|
617
|
+
windows.push({ name: allOver ? "Overage" : monthName, used: (100 * amount) / limit, ...resetsAt,
|
|
565
618
|
display, amount, limit, unit: "credits", span: 30 * 24 * 3600 })
|
|
566
619
|
}
|
|
567
620
|
windows.push(...shown, ...failed, ...off, ...(first?.windows ?? []).filter((w) => !w.span))
|
|
@@ -3103,22 +3156,24 @@ export async function KiroAuthPlugin({ client } = {}) {
|
|
|
3103
3156
|
return { error: e.message, signIn: e.gone ? "expired" : "kept" }
|
|
3104
3157
|
}
|
|
3105
3158
|
},
|
|
3159
|
+
// labels, messages and hints are magpie's own fields: the same words
|
|
3160
|
+
// by the window's language (OpenCode shows the English)
|
|
3106
3161
|
methods: [
|
|
3107
|
-
{ type: "oauth", label: "Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)",
|
|
3108
|
-
prompts: [{ type: "select", key: "loginMethod", message: "Choose a sign-in method", options: [
|
|
3109
|
-
{ label: "IAM Identity Center (organization Start URL)", value: "enterprise", hint: "Sign in to your organization with its AWS Start URL" },
|
|
3110
|
-
{ label: "AWS Builder ID", value: "builderid", hint: "Open AWS sign-in directly; one callback to paste on a remote server" },
|
|
3111
|
-
{ label: "Kiro sign-in page", value: "portal", hint: "Google, GitHub, IAM Identity Center or other Kiro sign-in methods" },
|
|
3162
|
+
{ type: "oauth", label: "Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)", labels: WORDS.browser,
|
|
3163
|
+
prompts: [{ type: "select", key: "loginMethod", message: "Choose a sign-in method", messages: WORDS.choose, options: [
|
|
3164
|
+
{ label: "IAM Identity Center (organization Start URL)", value: "enterprise", hint: "Sign in to your organization with its AWS Start URL", labels: WORDS.enterprise, hints: WORDS.enterpriseHint },
|
|
3165
|
+
{ label: "AWS Builder ID", value: "builderid", hint: "Open AWS sign-in directly; one callback to paste on a remote server", hints: WORDS.builderidHint },
|
|
3166
|
+
{ label: "Kiro sign-in page", value: "portal", hint: "Google, GitHub, IAM Identity Center or other Kiro sign-in methods", labels: WORDS.portal, hints: WORDS.portalHint },
|
|
3112
3167
|
] },
|
|
3113
|
-
{ type: "text", key: "startUrl", message: "Organization Start URL", placeholder: "https://d-xxxxxxxxxx.awsapps.com/start",
|
|
3168
|
+
{ type: "text", key: "startUrl", message: "Organization Start URL", messages: WORDS.startUrl, placeholder: "https://d-xxxxxxxxxx.awsapps.com/start",
|
|
3114
3169
|
condition: (inputs) => inputs.loginMethod === "enterprise",
|
|
3115
3170
|
validate: (value) => httpsURL(String(value || "").trim()) ? undefined : "Enter an HTTPS Start URL" },
|
|
3116
|
-
{ type: "text", key: "region", message: "AWS region (blank uses us-east-1)", placeholder: "us-east-1",
|
|
3171
|
+
{ type: "text", key: "region", message: "AWS region (blank uses us-east-1)", messages: WORDS.region, placeholder: "us-east-1",
|
|
3117
3172
|
condition: (inputs) => inputs.loginMethod === "enterprise",
|
|
3118
3173
|
validate: (value) => !value || AWS_REGION.test(value.trim()) ? undefined : "Enter a valid AWS region" },
|
|
3119
3174
|
], authorize: browserSignIn },
|
|
3120
|
-
{ type: "oauth", label: "Kiro CLI's or Kiro IDE's sign-in", authorize: ownSignIn },
|
|
3121
|
-
{ type: "api", label: "Kiro API key (ksk_…)" },
|
|
3175
|
+
{ type: "oauth", label: "Kiro CLI's or Kiro IDE's sign-in", labels: WORDS.own, authorize: ownSignIn },
|
|
3176
|
+
{ type: "api", label: "Kiro API key (ksk_…)", labels: WORDS.key, placeholder: "ksk_…" },
|
|
3122
3177
|
],
|
|
3123
3178
|
},
|
|
3124
3179
|
async config(config) {
|