@magpie-community/opencode-kiro-auth 0.1.15 → 0.1.17
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/index.mjs +23 -10
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -414,7 +414,10 @@ function goG(x) {
|
|
|
414
414
|
|
|
415
415
|
// usageOf is the allowance Get-Usage-Limits tells, as magpie's built-in
|
|
416
416
|
// said it: the account's email, the credits of each allowance, the month's and a free trial's
|
|
417
|
-
// while it runs.
|
|
417
|
+
// while it runs. Each window carries its count (amount, limit, unit), so
|
|
418
|
+
// magpie can say what is left of it when the user shows what is left
|
|
419
|
+
// (#408): display alone is the vendor's text, which magpie can't turn
|
|
420
|
+
// round.
|
|
418
421
|
function usageOf(l) {
|
|
419
422
|
const at = (secs) => (secs > 0 ? new Date(Math.trunc(secs) * 1000).toISOString() : undefined)
|
|
420
423
|
const count = (used, limit) => used.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") + " / " + goG(limit)
|
|
@@ -424,13 +427,14 @@ function usageOf(l) {
|
|
|
424
427
|
const t = u?.freeTrialInfo
|
|
425
428
|
if (t && String(t.freeTrialStatus ?? "").toUpperCase() === "ACTIVE" && num(t.usageLimitWithPrecision) > 0) {
|
|
426
429
|
const used = num(t.currentUsageWithPrecision), limit = num(t.usageLimitWithPrecision)
|
|
427
|
-
windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit)
|
|
430
|
+
windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit),
|
|
431
|
+
amount: used, limit, unit: "credits" })
|
|
428
432
|
}
|
|
429
433
|
const used = num(u?.currentUsageWithPrecision), limit = num(u?.usageLimitWithPrecision)
|
|
430
434
|
if (limit <= 0) continue
|
|
431
435
|
const reset = num(u?.nextDateReset) || num(l?.nextDateReset)
|
|
432
436
|
windows.push({ name: u?.displayNamePlural || u?.displayName || "Credits", used: (100 * used) / limit, resetsAt: at(reset),
|
|
433
|
-
display: count(used, limit), span: 30 * 24 * 3600 })
|
|
437
|
+
display: count(used, limit), amount: used, limit, unit: "credits", span: 30 * 24 * 3600 })
|
|
434
438
|
}
|
|
435
439
|
const email = l?.userInfo?.email
|
|
436
440
|
return { plan: planName(l?.subscriptionInfo?.subscriptionTitle), ...(typeof email === "string" && email ? { user: email } : {}), windows }
|
|
@@ -1097,7 +1101,12 @@ async function* events(body, model, budget) {
|
|
|
1097
1101
|
let tool = ""
|
|
1098
1102
|
let tools = 0
|
|
1099
1103
|
let stop = ""
|
|
1100
|
-
|
|
1104
|
+
// reported: Kiro sent a tokenUsage. It doesn't today: a reply has a
|
|
1105
|
+
// contextUsageEvent and a meteringEvent (credits) and nothing more, and
|
|
1106
|
+
// kiro-cli 2.32's own trace log shows its MetadataEvent with every token
|
|
1107
|
+
// count None, while a repeated prompt is billed about half the credits,
|
|
1108
|
+
// so Kiro does cache and doesn't say how much
|
|
1109
|
+
const usage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reported: false }
|
|
1101
1110
|
let pct = 0
|
|
1102
1111
|
let said = 0
|
|
1103
1112
|
let failed = ""
|
|
@@ -1147,6 +1156,7 @@ async function* events(body, model, budget) {
|
|
|
1147
1156
|
if (m.stopReason) stop = m.stopReason
|
|
1148
1157
|
const tu = m.tokenUsage
|
|
1149
1158
|
if (tu && typeof tu === "object") {
|
|
1159
|
+
usage.reported = true
|
|
1150
1160
|
usage.input += tu.uncachedInputTokens || tu.inputTokens || 0
|
|
1151
1161
|
usage.output += tu.outputTokens || 0
|
|
1152
1162
|
usage.cacheRead += tu.cacheReadInputTokens || 0
|
|
@@ -1192,12 +1202,15 @@ function finished(content) {
|
|
|
1192
1202
|
return content
|
|
1193
1203
|
}
|
|
1194
1204
|
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1205
|
+
// anthropicUsage is the usage in Messages' words. With no tokenUsage from
|
|
1206
|
+
// Kiro the input is reckoned from how full the context is, and what of it
|
|
1207
|
+
// Kiro read from its cache is unknown, not 0: the cache fields are left
|
|
1208
|
+
// out and magpie is told so (magpie_cache_unknown), so it shows no hit
|
|
1209
|
+
// rate rather than 0%.
|
|
1210
|
+
const anthropicUsage = (u) =>
|
|
1211
|
+
u.reported
|
|
1212
|
+
? { input_tokens: u.input, output_tokens: u.output, cache_read_input_tokens: u.cacheRead, cache_creation_input_tokens: u.cacheWrite }
|
|
1213
|
+
: { input_tokens: u.input, output_tokens: u.output, magpie_cache_unknown: true }
|
|
1201
1214
|
|
|
1202
1215
|
// quotaWords are magpie's (internal/gateway/fallback.go): how a vendor says
|
|
1203
1216
|
// "out of quota" or "slow down".
|