@aragon-agent/core 0.2.31 → 0.2.32

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.
@@ -226,6 +226,24 @@ export class AnthropicProvider {
226
226
  const u = data.usage;
227
227
  if (u) {
228
228
  usage.outputTokens = u.output_tokens ?? usage.outputTokens;
229
+ // Anthropic-COMPATIBLE relays (context-usage-zero-input-tokens A)
230
+ // commonly disclose the real input token count only here, with
231
+ // `message_start` carrying 0 or nothing. FIRST-PARTY streams never
232
+ // put input-side fields in `message_delta`, so the takeover below is
233
+ // dead code on api.anthropic.com and official behaviour stays
234
+ // byte-identical; across several deltas the last non-zero wins.
235
+ const inputTokens = u.input_tokens ?? 0;
236
+ if (inputTokens > 0) {
237
+ // TAKE OVER, NEVER SUM. A delta that discloses input may report
238
+ // an INCLUSIVE total; keeping `message_start`'s additive cache
239
+ // fields on top of it double-counts the cached tokens and fires
240
+ // compaction early (P1-10). The input side is re-derived from
241
+ // this event alone: the delta's own cache terms when present,
242
+ // cleared when absent.
243
+ usage.inputTokens = inputTokens;
244
+ usage.cacheReadTokens = u.cache_read_input_tokens;
245
+ usage.cacheWriteTokens = u.cache_creation_input_tokens;
246
+ }
229
247
  }
230
248
  break;
231
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aragon-agent/core",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "AragonAgent core engine — LLM provider adapters, streaming, tool registry/execution, steering, idle watchdog, and an optional isolated-vm sandbox.",
5
5
  "license": "MIT",
6
6
  "author": "AragonAgent contributors",