@agent-inspect/viewer 6.28.0 → 6.29.1

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/dist/index.d.cts CHANGED
@@ -43,7 +43,12 @@ interface TokenMetadata {
43
43
  input?: number;
44
44
  output?: number;
45
45
  total?: number;
46
+ /** Cache-read tokens (informational; never added to total). */
46
47
  cached?: number;
48
+ /** Cache-write / cache-creation tokens (informational). */
49
+ cacheWrite?: number;
50
+ /** Reasoning / thinking tokens when reported separately. */
51
+ reasoning?: number;
47
52
  }
48
53
  /** Arbitrary structured fields for a step; safe extensions use string keys. */
49
54
  interface StepMetadata {
package/dist/index.d.ts CHANGED
@@ -43,7 +43,12 @@ interface TokenMetadata {
43
43
  input?: number;
44
44
  output?: number;
45
45
  total?: number;
46
+ /** Cache-read tokens (informational; never added to total). */
46
47
  cached?: number;
48
+ /** Cache-write / cache-creation tokens (informational). */
49
+ cacheWrite?: number;
50
+ /** Reasoning / thinking tokens when reported separately. */
51
+ reasoning?: number;
47
52
  }
48
53
  /** Arbitrary structured fields for a step; safe extensions use string keys. */
49
54
  interface StepMetadata {
package/dist/index.mjs CHANGED
@@ -165,6 +165,8 @@ function isPersistedTokenUsage(value) {
165
165
  if (!isOptionalNonNegativeNumber(value.output)) return false;
166
166
  if (!isOptionalNonNegativeNumber(value.total)) return false;
167
167
  if (!isOptionalNonNegativeNumber(value.cached)) return false;
168
+ if (!isOptionalNonNegativeNumber(value.cacheWrite)) return false;
169
+ if (!isOptionalNonNegativeNumber(value.reasoning)) return false;
168
170
  return true;
169
171
  }
170
172
  function isPersistedTraceContext(value) {
@@ -3236,16 +3238,20 @@ function normalizeTokenUsage(value) {
3236
3238
  const output = nonNegativeFinite(value.output);
3237
3239
  const suppliedTotal = nonNegativeFinite(value.total);
3238
3240
  const cached = nonNegativeFinite(value.cached);
3241
+ const cacheWrite = nonNegativeFinite(value.cacheWrite);
3242
+ const reasoning = nonNegativeFinite(value.reasoning);
3239
3243
  const derivedTotal = input !== void 0 && output !== void 0 && Number.isFinite(input + output) ? input + output : void 0;
3240
3244
  const total = suppliedTotal ?? derivedTotal;
3241
- if (input === void 0 && output === void 0 && total === void 0 && cached === void 0) {
3245
+ if (input === void 0 && output === void 0 && total === void 0 && cached === void 0 && cacheWrite === void 0 && reasoning === void 0) {
3242
3246
  return void 0;
3243
3247
  }
3244
3248
  return {
3245
3249
  ...input !== void 0 ? { input } : {},
3246
3250
  ...output !== void 0 ? { output } : {},
3247
3251
  ...total !== void 0 ? { total } : {},
3248
- ...cached !== void 0 ? { cached } : {}
3252
+ ...cached !== void 0 ? { cached } : {},
3253
+ ...cacheWrite !== void 0 ? { cacheWrite } : {},
3254
+ ...reasoning !== void 0 ? { reasoning } : {}
3249
3255
  };
3250
3256
  }
3251
3257
 
@@ -4404,6 +4410,8 @@ function readOpenInferenceTokenUsage(attributes) {
4404
4410
  const completion = attributes["llm.token_count.completion"];
4405
4411
  const total = attributes["llm.token_count.total"];
4406
4412
  const cached = attributes["llm.token_count.prompt_details.cache_read"];
4413
+ const cacheWrite = attributes["llm.token_count.prompt_details.cache_write"] ?? attributes["llm.token_count.prompt_details.cache_creation"];
4414
+ const reasoning = attributes["llm.token_count.completion_details.reasoning"] ?? attributes["llm.token_count.completion_details.reasoning_tokens"];
4407
4415
  const usage = {};
4408
4416
  if (typeof prompt === "number" && Number.isFinite(prompt) && prompt >= 0) {
4409
4417
  usage.input = prompt;
@@ -4417,6 +4425,12 @@ function readOpenInferenceTokenUsage(attributes) {
4417
4425
  if (typeof cached === "number" && Number.isFinite(cached) && cached >= 0) {
4418
4426
  usage.cached = cached;
4419
4427
  }
4428
+ if (typeof cacheWrite === "number" && Number.isFinite(cacheWrite) && cacheWrite >= 0) {
4429
+ usage.cacheWrite = cacheWrite;
4430
+ }
4431
+ if (typeof reasoning === "number" && Number.isFinite(reasoning) && reasoning >= 0) {
4432
+ usage.reasoning = reasoning;
4433
+ }
4420
4434
  if (usage.total === void 0 && usage.input !== void 0 && usage.output !== void 0) {
4421
4435
  usage.total = usage.input + usage.output;
4422
4436
  }