@magpie-community/opencode-kiro-auth 0.1.33 → 0.1.35
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 +12 -3
- package/index.mjs +50 -11
- 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.
|
|
@@ -237,8 +243,10 @@ own search used instead.
|
|
|
237
243
|
The `config` hook declares `auto` (Kiro picks the model). Once signed in,
|
|
238
244
|
the `provider.models` hook replaces it with the account's own list from
|
|
239
245
|
`List-Available-Models`, with the default first. Each model carries its
|
|
240
|
-
context window, output limit and whether it takes images
|
|
241
|
-
|
|
246
|
+
context window, output limit and whether it takes images, and its credit
|
|
247
|
+
multiplier as `rate` (Kiro's `rateMultiplier` when `rateUnit` is `Credit`:
|
|
248
|
+
1.3 for claude-sonnet-4.5, 0.4 for claude-haiku-4.5), which magpie shows
|
|
249
|
+
beside the model. Claude models and Auto have the thinking variants.
|
|
242
250
|
|
|
243
251
|
## Usage in magpie
|
|
244
252
|
|
|
@@ -254,7 +262,8 @@ month's window counts against the overage cap (`overageCap`), which is the
|
|
|
254
262
|
month's whole limit; with it off, against the plan's credits.
|
|
255
263
|
|
|
256
264
|
Each request's cost is what Kiro's `meteringEvent`s say, in credits, summed
|
|
257
|
-
over the request (a web search's turns included).
|
|
265
|
+
over the request (a web search's turns included). Kiro has already applied
|
|
266
|
+
the model's multiplier to it, so it isn't multiplied again. It goes on as
|
|
258
267
|
`usage.credit` in the last `message_delta`, or in the message's `usage`, for
|
|
259
268
|
magpie's ledger (yetone/magpie#4328). Kiro gives no token counts, so the
|
|
260
269
|
input is reckoned from how full the context is, and the cache is unknown
|
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
|
|
|
@@ -782,6 +799,8 @@ function configModel(m) {
|
|
|
782
799
|
? { reasoning: true, variants: Object.fromEntries(Object.entries(BUDGETS).map(([k, b]) => [k, { thinking: { type: "enabled", budgetTokens: b } }])) }
|
|
783
800
|
: {}),
|
|
784
801
|
tool_call: true,
|
|
802
|
+
// magpie's own: the credit multiplier Kiro lists for the model
|
|
803
|
+
...(m.rate ? { rate: m.rate } : {}),
|
|
785
804
|
}
|
|
786
805
|
}
|
|
787
806
|
|
|
@@ -807,6 +826,8 @@ function runtimeModel(m) {
|
|
|
807
826
|
interleaved: false,
|
|
808
827
|
},
|
|
809
828
|
release_date: "",
|
|
829
|
+
// magpie's own: the credit multiplier Kiro lists for the model
|
|
830
|
+
...(m.rate ? { rate: m.rate } : {}),
|
|
810
831
|
variants: thinks(m.id) ? Object.fromEntries(Object.entries(BUDGETS).map(([k, b]) => [k, { thinking: { type: "enabled", budgetTokens: b } }])) : {},
|
|
811
832
|
}
|
|
812
833
|
}
|
|
@@ -831,6 +852,21 @@ async function keyModels(a) {
|
|
|
831
852
|
return out
|
|
832
853
|
}
|
|
833
854
|
|
|
855
|
+
// rateOf is the credits a model's request costs as a multiple, as Kiro's
|
|
856
|
+
// list says it (rateMultiplier with rateUnit "Credit": on 11-09 a Free
|
|
857
|
+
// account's list had auto 1, claude-sonnet-4.5 1.3, claude-haiku-4.5 0.4,
|
|
858
|
+
// glm-5 0.5, deepseek-3.2 and minimax-m2.5 0.25, minimax-m2.1 0.15 and
|
|
859
|
+
// qwen3-coder-next 0.05, which kiro-cli 2.x reads as its rate_multiplier).
|
|
860
|
+
// Nothing is the rate when Kiro gives none, or gives it in another unit.
|
|
861
|
+
// It is only shown: what a request cost is the meteringEvent's credits,
|
|
862
|
+
// which Kiro has already multiplied (the same prompt metered 0.00535 on
|
|
863
|
+
// claude-haiku-4.5 and 0.01739 on claude-sonnet-4.5, 0.4 to 1.3).
|
|
864
|
+
function rateOf(m) {
|
|
865
|
+
const n = m?.rateMultiplier
|
|
866
|
+
if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) return undefined
|
|
867
|
+
return String(m.rateUnit ?? "").toLowerCase() === "credit" ? n : undefined
|
|
868
|
+
}
|
|
869
|
+
|
|
834
870
|
// listModels is List-Available-Models, the default first.
|
|
835
871
|
async function listModels(a) {
|
|
836
872
|
const out = a.tokenType === "API_KEY" ? await keyModels(a) : await managementCall(a.region, a, "List-Available-Models", { origin: "KIRO_CLI", profileArn: a.profile })
|
|
@@ -839,8 +875,9 @@ async function listModels(a) {
|
|
|
839
875
|
if (!m?.modelId) continue
|
|
840
876
|
let name = m.modelName
|
|
841
877
|
if (!name || name === m.modelId) name = m.modelId === "auto" ? "Auto" : m.modelId
|
|
878
|
+
const rate = rateOf(m)
|
|
842
879
|
const model = { id: m.modelId, name, context: m.tokenLimits?.maxInputTokens ?? 0, output: m.tokenLimits?.maxOutputTokens ?? 0,
|
|
843
|
-
images: (m.supportedInputTypes ?? []).some((t) => String(t).toUpperCase() === "IMAGE") }
|
|
880
|
+
images: (m.supportedInputTypes ?? []).some((t) => String(t).toUpperCase() === "IMAGE"), ...(rate ? { rate } : {}) }
|
|
844
881
|
if (m.modelId === out?.defaultModel?.modelId) list.unshift(model)
|
|
845
882
|
else list.push(model)
|
|
846
883
|
}
|
|
@@ -3083,22 +3120,24 @@ export async function KiroAuthPlugin({ client } = {}) {
|
|
|
3083
3120
|
return { error: e.message, signIn: e.gone ? "expired" : "kept" }
|
|
3084
3121
|
}
|
|
3085
3122
|
},
|
|
3123
|
+
// labels, messages and hints are magpie's own fields: the same words
|
|
3124
|
+
// by the window's language (OpenCode shows the English)
|
|
3086
3125
|
methods: [
|
|
3087
|
-
{ type: "oauth", label: "Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)",
|
|
3088
|
-
prompts: [{ type: "select", key: "loginMethod", message: "Choose a sign-in method", options: [
|
|
3089
|
-
{ label: "IAM Identity Center (organization Start URL)", value: "enterprise", hint: "Sign in to your organization with its AWS Start URL" },
|
|
3090
|
-
{ label: "AWS Builder ID", value: "builderid", hint: "Open AWS sign-in directly; one callback to paste on a remote server" },
|
|
3091
|
-
{ label: "Kiro sign-in page", value: "portal", hint: "Google, GitHub, IAM Identity Center or other Kiro sign-in methods" },
|
|
3126
|
+
{ type: "oauth", label: "Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)", labels: WORDS.browser,
|
|
3127
|
+
prompts: [{ type: "select", key: "loginMethod", message: "Choose a sign-in method", messages: WORDS.choose, options: [
|
|
3128
|
+
{ 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 },
|
|
3129
|
+
{ label: "AWS Builder ID", value: "builderid", hint: "Open AWS sign-in directly; one callback to paste on a remote server", hints: WORDS.builderidHint },
|
|
3130
|
+
{ 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 },
|
|
3092
3131
|
] },
|
|
3093
|
-
{ type: "text", key: "startUrl", message: "Organization Start URL", placeholder: "https://d-xxxxxxxxxx.awsapps.com/start",
|
|
3132
|
+
{ type: "text", key: "startUrl", message: "Organization Start URL", messages: WORDS.startUrl, placeholder: "https://d-xxxxxxxxxx.awsapps.com/start",
|
|
3094
3133
|
condition: (inputs) => inputs.loginMethod === "enterprise",
|
|
3095
3134
|
validate: (value) => httpsURL(String(value || "").trim()) ? undefined : "Enter an HTTPS Start URL" },
|
|
3096
|
-
{ type: "text", key: "region", message: "AWS region (blank uses us-east-1)", placeholder: "us-east-1",
|
|
3135
|
+
{ type: "text", key: "region", message: "AWS region (blank uses us-east-1)", messages: WORDS.region, placeholder: "us-east-1",
|
|
3097
3136
|
condition: (inputs) => inputs.loginMethod === "enterprise",
|
|
3098
3137
|
validate: (value) => !value || AWS_REGION.test(value.trim()) ? undefined : "Enter a valid AWS region" },
|
|
3099
3138
|
], authorize: browserSignIn },
|
|
3100
|
-
{ type: "oauth", label: "Kiro CLI's or Kiro IDE's sign-in", authorize: ownSignIn },
|
|
3101
|
-
{ type: "api", label: "Kiro API key (ksk_…)" },
|
|
3139
|
+
{ type: "oauth", label: "Kiro CLI's or Kiro IDE's sign-in", labels: WORDS.own, authorize: ownSignIn },
|
|
3140
|
+
{ type: "api", label: "Kiro API key (ksk_…)", labels: WORDS.key, placeholder: "ksk_…" },
|
|
3102
3141
|
],
|
|
3103
3142
|
},
|
|
3104
3143
|
async config(config) {
|
|
@@ -3133,4 +3172,4 @@ export async function KiroAuthPlugin({ client } = {}) {
|
|
|
3133
3172
|
}
|
|
3134
3173
|
|
|
3135
3174
|
// for tests
|
|
3136
|
-
export const _internal = { generate, responsesBody, crMessages, crRefusal, features, FEATURES, featureKey, waitOf, timing, TRIES, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
|
|
3175
|
+
export const _internal = { generate, responsesBody, crMessages, crRefusal, features, FEATURES, featureKey, waitOf, timing, TRIES, refresh, usageOf, buildKiro, kiroBody, IMAGE_LIMIT, events, reply, failure, toolID, toolName, toolNames, thinking, nativeFields, listModels, rateOf, contextFirst, configModel, runtimeModel, readCLI, readIDE, regionOf, planName, frames }
|