Commit Graph
2 Commits
Author SHA1 Message Date
caozhenyuan 4200fed099 kiro 0.1.29: what Kiro's meteringEvents say a request cost goes on as usage.credit (#823)
Kiro gives no token counts, only what each request cost in credits: a
meteringEvent ({"unit": "credit", "usage": 0.091}) near the end of its
reply. The plugin read past it, so magpie's Usage page reckoned Kiro's
cost from estimated tokens with no cache (yetone/magpie#4328, #3761).

The credits of a request's meteringEvents are now summed (a hosted web
search's turns are one request) and said as usage.credit in the last
message_delta, streamed, or in the message's usage, as WorkBuddy's
usage.credit is said on the Chat path. A reply with none says no credit;
one Kiro says cost 0 says 0. An event in another unit, or with a usage
that isn't a number of at least 0, is left out. magpie reads the field on
/v1/messages once the host half of yetone/magpie#4328 is in; until then
it is passed over.

Run at 57a4d35e on mote (Bun 1.4.2, HOME a temp dir): bun test
packages/kiro 144 pass, 0 fail; bun scripts/check.mjs kiro ok; bun test
(whole repo) 6679 pass, 0 fail. Merged onto main e7004d93: kiro 144 pass,
check ok. CI pr run 42349117220 green, attempt 1. npm had 0.1.28.
Broken by hand, each red: meteringEvent ignored (4 tests), last event
kept instead of summed, any unit taken, a negative taken, a string usage
taken, a search's turns not summed, a search keeping only its last turn,
a stated 0 dropped.
Not tried: magpie's ledger with the host half (not merged); a real Kiro
reply with more than one meteringEvent.
2026-11-07 15:27:27 +08:00
yetone 9f6c4e8861 kiro 0.1.16: a reply with no token counts says its cache is unknown, not 0 (zeewell on X)
zeewell on X: every Kiro request in magpie's Routing page shows cache 0%
(Claude Code through group/wf-coding-*, claude-sonnet-5.5 and
claude-opus-5.5, 150-180k tokens, consecutive calls seconds apart).

Cause, from real requests (Google sign-in through kiro-cli, 2026-10-24):
Kiro caches, but reports no token counts at all. A
generateAssistantResponse reply ends with metadataEvent {stopReason},
contextUsageEvent {contextUsagePercentage} and meteringEvent {credits};
no tokenUsage. The same 9k-token prompt sent twice was billed 0.091
then 0.048 credits, the same with or without cachePoints and with a
fresh or a fixed conversationId. kiro-cli 2.32's own trace log
(KIRO_LOG_LEVEL=trace) shows its MetadataEvent with total_tokens,
uncached_input_tokens, cache_read_input_tokens and
cache_write_input_tokens all None, and kiro-cli sends no cachePoint.
So nothing the plugin sends or drops keeps Kiro from caching (#110's
reading that only cachePoints make it cache was wrong); the plugin said
cache_read_input_tokens 0 for a number Kiro never gave.

Now, with no tokenUsage, the reply's usage leaves both cache fields out
and says magpie_cache_unknown: true, which magpie reads as no hit rate
instead of 0%. A tokenUsage, if Kiro sends one, is told as before.
cache-points.test.mjs's comment is corrected; the marks stay.

Run: cache-unknown.test.mjs (the real reply's events, streamed and not)
fails on 0.1.15's index.mjs (1 fail) and passes; bun test in
packages/kiro 57 pass under a scratch HOME/TMPDIR; scripts/check.mjs
kiro ok. The patched loader's fetch against real Kiro (source "kiro",
claude-sonnet-4.5, twice): 200, message_delta usage
{"output_tokens":1,"magpie_cache_unknown":true}. Not tried: an IDE or
Builder ID sign-in, other models' replies.
2026-10-24 17:03:48 +08:00