@magpie-community/opencode-kiro-auth 0.1.15 → 0.1.16

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 (2) hide show
  1. package/index.mjs +16 -7
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1097,7 +1097,12 @@ async function* events(body, model, budget) {
1097
1097
  let tool = ""
1098
1098
  let tools = 0
1099
1099
  let stop = ""
1100
- const usage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
1100
+ // reported: Kiro sent a tokenUsage. It doesn't today: a reply has a
1101
+ // contextUsageEvent and a meteringEvent (credits) and nothing more, and
1102
+ // kiro-cli 2.32's own trace log shows its MetadataEvent with every token
1103
+ // count None, while a repeated prompt is billed about half the credits,
1104
+ // so Kiro does cache and doesn't say how much
1105
+ const usage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reported: false }
1101
1106
  let pct = 0
1102
1107
  let said = 0
1103
1108
  let failed = ""
@@ -1147,6 +1152,7 @@ async function* events(body, model, budget) {
1147
1152
  if (m.stopReason) stop = m.stopReason
1148
1153
  const tu = m.tokenUsage
1149
1154
  if (tu && typeof tu === "object") {
1155
+ usage.reported = true
1150
1156
  usage.input += tu.uncachedInputTokens || tu.inputTokens || 0
1151
1157
  usage.output += tu.outputTokens || 0
1152
1158
  usage.cacheRead += tu.cacheReadInputTokens || 0
@@ -1192,12 +1198,15 @@ function finished(content) {
1192
1198
  return content
1193
1199
  }
1194
1200
 
1195
- const anthropicUsage = (u) => ({
1196
- input_tokens: u.input,
1197
- output_tokens: u.output,
1198
- cache_read_input_tokens: u.cacheRead,
1199
- cache_creation_input_tokens: u.cacheWrite,
1200
- })
1201
+ // anthropicUsage is the usage in Messages' words. With no tokenUsage from
1202
+ // Kiro the input is reckoned from how full the context is, and what of it
1203
+ // Kiro read from its cache is unknown, not 0: the cache fields are left
1204
+ // out and magpie is told so (magpie_cache_unknown), so it shows no hit
1205
+ // rate rather than 0%.
1206
+ const anthropicUsage = (u) =>
1207
+ u.reported
1208
+ ? { input_tokens: u.input, output_tokens: u.output, cache_read_input_tokens: u.cacheRead, cache_creation_input_tokens: u.cacheWrite }
1209
+ : { input_tokens: u.input, output_tokens: u.output, magpie_cache_unknown: true }
1201
1210
 
1202
1211
  // quotaWords are magpie's (internal/gateway/fallback.go): how a vendor says
1203
1212
  // "out of quota" or "slow down".
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-kiro-auth",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",