agent-inspect 1.5.0 → 1.6.0

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 (85) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +12 -4
  3. package/docs/API.md +124 -9
  4. package/docs/ARCHITECTURE.md +4 -0
  5. package/docs/CLI.md +41 -12
  6. package/docs/KNOWN-ISSUES.md +8 -1
  7. package/docs/LIMITATIONS.md +11 -2
  8. package/docs/SCHEMA.md +16 -6
  9. package/package.json +21 -1
  10. package/packages/cli/dist/index.cjs +2449 -157
  11. package/packages/cli/dist/index.cjs.map +1 -1
  12. package/packages/cli/dist/index.mjs +2450 -158
  13. package/packages/cli/dist/index.mjs.map +1 -1
  14. package/packages/core/dist/advanced.cjs +839 -18
  15. package/packages/core/dist/advanced.cjs.map +1 -1
  16. package/packages/core/dist/advanced.d.cts +98 -3
  17. package/packages/core/dist/advanced.d.ts +98 -3
  18. package/packages/core/dist/advanced.mjs +7 -4
  19. package/packages/core/dist/chunk-57S5D6HR.mjs +655 -0
  20. package/packages/core/dist/chunk-57S5D6HR.mjs.map +1 -0
  21. package/packages/core/dist/chunk-6QSLZCBJ.mjs +743 -0
  22. package/packages/core/dist/chunk-6QSLZCBJ.mjs.map +1 -0
  23. package/packages/core/dist/chunk-6SZPTECC.mjs +342 -0
  24. package/packages/core/dist/chunk-6SZPTECC.mjs.map +1 -0
  25. package/packages/core/dist/{chunk-QX3ZMPUF.mjs → chunk-74XZ6N7Q.mjs} +13 -55
  26. package/packages/core/dist/chunk-74XZ6N7Q.mjs.map +1 -0
  27. package/packages/core/dist/{chunk-QPAU2TPA.mjs → chunk-HR7G62IE.mjs} +4 -4
  28. package/packages/core/dist/{chunk-QPAU2TPA.mjs.map → chunk-HR7G62IE.mjs.map} +1 -1
  29. package/packages/core/dist/chunk-S4YWKV4G.mjs +48 -0
  30. package/packages/core/dist/chunk-S4YWKV4G.mjs.map +1 -0
  31. package/packages/core/dist/chunk-TFLPUZ56.mjs +1571 -0
  32. package/packages/core/dist/chunk-TFLPUZ56.mjs.map +1 -0
  33. package/packages/core/dist/{chunk-Q6EPNB3V.mjs → chunk-TZISEVLQ.mjs} +34 -183
  34. package/packages/core/dist/chunk-TZISEVLQ.mjs.map +1 -0
  35. package/packages/core/dist/chunk-U2BGPESY.mjs +150 -0
  36. package/packages/core/dist/chunk-U2BGPESY.mjs.map +1 -0
  37. package/packages/core/dist/chunk-VTIB5MDK.mjs +304 -0
  38. package/packages/core/dist/chunk-VTIB5MDK.mjs.map +1 -0
  39. package/packages/core/dist/{chunk-5EMIZZXD.mjs → chunk-Y56BPA3B.mjs} +87 -4
  40. package/packages/core/dist/chunk-Y56BPA3B.mjs.map +1 -0
  41. package/packages/core/dist/diff.d.cts +3 -2
  42. package/packages/core/dist/diff.d.ts +3 -2
  43. package/packages/core/dist/exporters.cjs.map +1 -1
  44. package/packages/core/dist/exporters.d.cts +3 -2
  45. package/packages/core/dist/exporters.d.ts +3 -2
  46. package/packages/core/dist/exporters.mjs +2 -2
  47. package/packages/core/dist/index.cjs +2975 -229
  48. package/packages/core/dist/index.cjs.map +1 -1
  49. package/packages/core/dist/index.d.cts +27 -6
  50. package/packages/core/dist/index.d.ts +27 -6
  51. package/packages/core/dist/index.mjs +113 -60
  52. package/packages/core/dist/index.mjs.map +1 -1
  53. package/packages/core/dist/{log-config-BzGmDYum.d.cts → inspect-event-Des4JDHo.d.cts} +1 -31
  54. package/packages/core/dist/{log-config-BzGmDYum.d.ts → inspect-event-Des4JDHo.d.ts} +1 -31
  55. package/packages/core/dist/log-config-BnH8Ykcb.d.cts +33 -0
  56. package/packages/core/dist/log-config-C1GcJPIM.d.ts +33 -0
  57. package/packages/core/dist/logs.d.cts +3 -2
  58. package/packages/core/dist/logs.d.ts +3 -2
  59. package/packages/core/dist/logs.mjs +3 -3
  60. package/packages/core/dist/persisted-inspect-event-0kaRADsp.d.cts +56 -0
  61. package/packages/core/dist/persisted-inspect-event-DiFto0K2.d.ts +56 -0
  62. package/packages/core/dist/persisted.cjs +38 -40
  63. package/packages/core/dist/persisted.cjs.map +1 -1
  64. package/packages/core/dist/persisted.d.cts +6 -55
  65. package/packages/core/dist/persisted.d.ts +6 -55
  66. package/packages/core/dist/persisted.mjs +4 -2
  67. package/packages/core/dist/readers.cjs +2590 -0
  68. package/packages/core/dist/readers.cjs.map +1 -0
  69. package/packages/core/dist/readers.d.cts +80 -0
  70. package/packages/core/dist/readers.d.ts +80 -0
  71. package/packages/core/dist/readers.mjs +9 -0
  72. package/packages/core/dist/readers.mjs.map +1 -0
  73. package/packages/core/dist/{types-CNbheSdk.d.cts → types-DB8jB6Jg.d.cts} +7 -1
  74. package/packages/core/dist/{types-Bkt7LS01.d.ts → types-tSix7tfv.d.ts} +7 -1
  75. package/packages/core/dist/writers.cjs +997 -0
  76. package/packages/core/dist/writers.cjs.map +1 -0
  77. package/packages/core/dist/writers.d.cts +62 -0
  78. package/packages/core/dist/writers.d.ts +62 -0
  79. package/packages/core/dist/writers.mjs +9 -0
  80. package/packages/core/dist/writers.mjs.map +1 -0
  81. package/packages/core/dist/chunk-5EMIZZXD.mjs.map +0 -1
  82. package/packages/core/dist/chunk-Q6EPNB3V.mjs.map +0 -1
  83. package/packages/core/dist/chunk-QX3ZMPUF.mjs.map +0 -1
  84. package/packages/core/dist/chunk-XDBND27A.mjs +0 -975
  85. package/packages/core/dist/chunk-XDBND27A.mjs.map +0 -1
@@ -38,34 +38,4 @@ interface InspectRunTree {
38
38
  };
39
39
  }
40
40
 
41
- interface LogEventMapping {
42
- kind?: InspectKind;
43
- name?: string;
44
- parent?: string;
45
- status?: "running" | "ok" | "error";
46
- startsRun?: boolean;
47
- endsRun?: boolean;
48
- startsStep?: boolean;
49
- endsStep?: boolean;
50
- }
51
- type RedactionStrategy = "full" | "prefix" | "hash";
52
- type RedactionRule = string | {
53
- key: string;
54
- strategy: RedactionStrategy;
55
- keep?: number;
56
- };
57
- interface LogIngestConfig {
58
- runIdKeys: string[];
59
- eventKey: string;
60
- timestampKey?: string;
61
- messageKey?: string;
62
- levelKey?: string;
63
- parentIdKey?: string;
64
- durationKey?: string;
65
- statusKey?: string;
66
- mappings?: Record<string, LogEventMapping>;
67
- redact?: RedactionRule[];
68
- heuristicWindowMs?: number;
69
- }
70
-
71
- export type { AttributionConfidence as A, EventSource as E, InspectEvent as I, LogEventMapping as L, RedactionRule as R, InspectKind as a, InspectNode as b, InspectRunTree as c, LogIngestConfig as d, RedactionStrategy as e };
41
+ export type { AttributionConfidence as A, EventSource as E, InspectKind as I, InspectEvent as a, InspectNode as b, InspectRunTree as c };
@@ -38,34 +38,4 @@ interface InspectRunTree {
38
38
  };
39
39
  }
40
40
 
41
- interface LogEventMapping {
42
- kind?: InspectKind;
43
- name?: string;
44
- parent?: string;
45
- status?: "running" | "ok" | "error";
46
- startsRun?: boolean;
47
- endsRun?: boolean;
48
- startsStep?: boolean;
49
- endsStep?: boolean;
50
- }
51
- type RedactionStrategy = "full" | "prefix" | "hash";
52
- type RedactionRule = string | {
53
- key: string;
54
- strategy: RedactionStrategy;
55
- keep?: number;
56
- };
57
- interface LogIngestConfig {
58
- runIdKeys: string[];
59
- eventKey: string;
60
- timestampKey?: string;
61
- messageKey?: string;
62
- levelKey?: string;
63
- parentIdKey?: string;
64
- durationKey?: string;
65
- statusKey?: string;
66
- mappings?: Record<string, LogEventMapping>;
67
- redact?: RedactionRule[];
68
- heuristicWindowMs?: number;
69
- }
70
-
71
- export type { AttributionConfidence as A, EventSource as E, InspectEvent as I, LogEventMapping as L, RedactionRule as R, InspectKind as a, InspectNode as b, InspectRunTree as c, LogIngestConfig as d, RedactionStrategy as e };
41
+ export type { AttributionConfidence as A, EventSource as E, InspectKind as I, InspectEvent as a, InspectNode as b, InspectRunTree as c };
@@ -0,0 +1,33 @@
1
+ import { I as InspectKind } from './inspect-event-Des4JDHo.cjs';
2
+
3
+ interface LogEventMapping {
4
+ kind?: InspectKind;
5
+ name?: string;
6
+ parent?: string;
7
+ status?: "running" | "ok" | "error";
8
+ startsRun?: boolean;
9
+ endsRun?: boolean;
10
+ startsStep?: boolean;
11
+ endsStep?: boolean;
12
+ }
13
+ type RedactionStrategy = "full" | "prefix" | "hash";
14
+ type RedactionRule = string | {
15
+ key: string;
16
+ strategy: RedactionStrategy;
17
+ keep?: number;
18
+ };
19
+ interface LogIngestConfig {
20
+ runIdKeys: string[];
21
+ eventKey: string;
22
+ timestampKey?: string;
23
+ messageKey?: string;
24
+ levelKey?: string;
25
+ parentIdKey?: string;
26
+ durationKey?: string;
27
+ statusKey?: string;
28
+ mappings?: Record<string, LogEventMapping>;
29
+ redact?: RedactionRule[];
30
+ heuristicWindowMs?: number;
31
+ }
32
+
33
+ export type { LogEventMapping as L, RedactionRule as R, LogIngestConfig as a, RedactionStrategy as b };
@@ -0,0 +1,33 @@
1
+ import { I as InspectKind } from './inspect-event-Des4JDHo.js';
2
+
3
+ interface LogEventMapping {
4
+ kind?: InspectKind;
5
+ name?: string;
6
+ parent?: string;
7
+ status?: "running" | "ok" | "error";
8
+ startsRun?: boolean;
9
+ endsRun?: boolean;
10
+ startsStep?: boolean;
11
+ endsStep?: boolean;
12
+ }
13
+ type RedactionStrategy = "full" | "prefix" | "hash";
14
+ type RedactionRule = string | {
15
+ key: string;
16
+ strategy: RedactionStrategy;
17
+ keep?: number;
18
+ };
19
+ interface LogIngestConfig {
20
+ runIdKeys: string[];
21
+ eventKey: string;
22
+ timestampKey?: string;
23
+ messageKey?: string;
24
+ levelKey?: string;
25
+ parentIdKey?: string;
26
+ durationKey?: string;
27
+ statusKey?: string;
28
+ mappings?: Record<string, LogEventMapping>;
29
+ redact?: RedactionRule[];
30
+ heuristicWindowMs?: number;
31
+ }
32
+
33
+ export type { LogEventMapping as L, RedactionRule as R, LogIngestConfig as a, RedactionStrategy as b };
@@ -1,5 +1,6 @@
1
- import { d as LogIngestConfig, L as LogEventMapping, R as RedactionRule, I as InspectEvent, c as InspectRunTree } from './log-config-BzGmDYum.cjs';
2
- export { e as RedactionStrategy } from './log-config-BzGmDYum.cjs';
1
+ import { a as LogIngestConfig, L as LogEventMapping, R as RedactionRule } from './log-config-BnH8Ykcb.cjs';
2
+ export { b as RedactionStrategy } from './log-config-BnH8Ykcb.cjs';
3
+ import { a as InspectEvent, c as InspectRunTree } from './inspect-event-Des4JDHo.cjs';
3
4
 
4
5
  type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
5
6
  interface ParserWarning {
@@ -1,5 +1,6 @@
1
- import { d as LogIngestConfig, L as LogEventMapping, R as RedactionRule, I as InspectEvent, c as InspectRunTree } from './log-config-BzGmDYum.js';
2
- export { e as RedactionStrategy } from './log-config-BzGmDYum.js';
1
+ import { a as LogIngestConfig, L as LogEventMapping, R as RedactionRule } from './log-config-C1GcJPIM.js';
2
+ export { b as RedactionStrategy } from './log-config-C1GcJPIM.js';
3
+ import { a as InspectEvent, c as InspectRunTree } from './inspect-event-Des4JDHo.js';
3
4
 
4
5
  type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
5
6
  interface ParserWarning {
@@ -1,6 +1,6 @@
1
- export { DEFAULT_LOG_INGEST_CONFIG, EventNormalizer, JsonLogParser, LiveLogAccumulator, Log4jsParser, loadLogIngestConfig, matchMapping, mergeLogIngestConfig, parseLogLine, parseLogsToTrees, renderRunTree, renderRunTrees, wildcardMatch } from './chunk-QPAU2TPA.mjs';
2
- import './chunk-7TGZLWEE.mjs';
3
- export { TreeBuilder } from './chunk-E5F2LQCX.mjs';
1
+ export { DEFAULT_LOG_INGEST_CONFIG, EventNormalizer, JsonLogParser, LiveLogAccumulator, Log4jsParser, loadLogIngestConfig, matchMapping, mergeLogIngestConfig, parseLogLine, parseLogsToTrees, renderRunTree, renderRunTrees, wildcardMatch } from './chunk-HR7G62IE.mjs';
4
2
  export { DEFAULT_REDACT_KEYS, Redactor } from './chunk-VU6O5QAH.mjs';
3
+ export { TreeBuilder } from './chunk-E5F2LQCX.mjs';
4
+ import './chunk-7TGZLWEE.mjs';
5
5
  //# sourceMappingURL=logs.mjs.map
6
6
  //# sourceMappingURL=logs.mjs.map
@@ -0,0 +1,56 @@
1
+ import { I as InspectKind, A as AttributionConfidence } from './inspect-event-Des4JDHo.cjs';
2
+
3
+ type PersistedSchemaVersion = "0.2";
4
+ type PersistedEventSourceType = "manual" | "json-log" | "log4js" | "adapter" | "ai-sdk" | "otel";
5
+ interface PersistedEventSource {
6
+ type: PersistedEventSourceType;
7
+ name?: string;
8
+ version?: string;
9
+ }
10
+ type PersistedEventStatus = "running" | "ok" | "error" | "unknown";
11
+ interface PersistedInspectError {
12
+ name?: string;
13
+ message: string;
14
+ code?: string;
15
+ }
16
+ interface PersistedTokenUsage {
17
+ input?: number;
18
+ output?: number;
19
+ total?: number;
20
+ cached?: number;
21
+ }
22
+ interface PersistedTraceContext {
23
+ traceId?: string;
24
+ spanId?: string;
25
+ parentSpanId?: string;
26
+ }
27
+ interface PersistedInspectEvent {
28
+ schemaVersion: PersistedSchemaVersion;
29
+ eventId: string;
30
+ runId: string;
31
+ parentId?: string;
32
+ kind: InspectKind;
33
+ name: string;
34
+ status?: PersistedEventStatus;
35
+ timestamp: string;
36
+ startedAt?: string;
37
+ endedAt?: string;
38
+ durationMs?: number;
39
+ confidence: AttributionConfidence;
40
+ source: PersistedEventSource;
41
+ attributes?: Record<string, unknown>;
42
+ inputSummary?: unknown;
43
+ outputSummary?: unknown;
44
+ error?: PersistedInspectError;
45
+ tokenUsage?: PersistedTokenUsage;
46
+ trace?: PersistedTraceContext;
47
+ }
48
+ /**
49
+ * Runtime guard for a v0.2 {@link PersistedInspectEvent} JSON object.
50
+ *
51
+ * Timestamp fields (`timestamp`, `startedAt`, `endedAt`) are validated as
52
+ * non-empty strings only — stricter ISO-8601 parsing may be added later.
53
+ */
54
+ declare function isPersistedInspectEvent(value: unknown): value is PersistedInspectEvent;
55
+
56
+ export { type PersistedInspectEvent as P, type PersistedEventSource as a, type PersistedEventSourceType as b, type PersistedEventStatus as c, type PersistedInspectError as d, type PersistedSchemaVersion as e, type PersistedTokenUsage as f, type PersistedTraceContext as g, isPersistedInspectEvent as i };
@@ -0,0 +1,56 @@
1
+ import { I as InspectKind, A as AttributionConfidence } from './inspect-event-Des4JDHo.js';
2
+
3
+ type PersistedSchemaVersion = "0.2";
4
+ type PersistedEventSourceType = "manual" | "json-log" | "log4js" | "adapter" | "ai-sdk" | "otel";
5
+ interface PersistedEventSource {
6
+ type: PersistedEventSourceType;
7
+ name?: string;
8
+ version?: string;
9
+ }
10
+ type PersistedEventStatus = "running" | "ok" | "error" | "unknown";
11
+ interface PersistedInspectError {
12
+ name?: string;
13
+ message: string;
14
+ code?: string;
15
+ }
16
+ interface PersistedTokenUsage {
17
+ input?: number;
18
+ output?: number;
19
+ total?: number;
20
+ cached?: number;
21
+ }
22
+ interface PersistedTraceContext {
23
+ traceId?: string;
24
+ spanId?: string;
25
+ parentSpanId?: string;
26
+ }
27
+ interface PersistedInspectEvent {
28
+ schemaVersion: PersistedSchemaVersion;
29
+ eventId: string;
30
+ runId: string;
31
+ parentId?: string;
32
+ kind: InspectKind;
33
+ name: string;
34
+ status?: PersistedEventStatus;
35
+ timestamp: string;
36
+ startedAt?: string;
37
+ endedAt?: string;
38
+ durationMs?: number;
39
+ confidence: AttributionConfidence;
40
+ source: PersistedEventSource;
41
+ attributes?: Record<string, unknown>;
42
+ inputSummary?: unknown;
43
+ outputSummary?: unknown;
44
+ error?: PersistedInspectError;
45
+ tokenUsage?: PersistedTokenUsage;
46
+ trace?: PersistedTraceContext;
47
+ }
48
+ /**
49
+ * Runtime guard for a v0.2 {@link PersistedInspectEvent} JSON object.
50
+ *
51
+ * Timestamp fields (`timestamp`, `startedAt`, `endedAt`) are validated as
52
+ * non-empty strings only — stricter ISO-8601 parsing may be added later.
53
+ */
54
+ declare function isPersistedInspectEvent(value: unknown): value is PersistedInspectEvent;
55
+
56
+ export { type PersistedInspectEvent as P, type PersistedEventSource as a, type PersistedEventSourceType as b, type PersistedEventStatus as c, type PersistedInspectError as d, type PersistedSchemaVersion as e, type PersistedTokenUsage as f, type PersistedTraceContext as g, isPersistedInspectEvent as i };
@@ -83,6 +83,7 @@ function isPersistedTokenUsage(value) {
83
83
  if (!isOptionalNonNegativeNumber(value.input)) return false;
84
84
  if (!isOptionalNonNegativeNumber(value.output)) return false;
85
85
  if (!isOptionalNonNegativeNumber(value.total)) return false;
86
+ if (!isOptionalNonNegativeNumber(value.cached)) return false;
86
87
  return true;
87
88
  }
88
89
  function isPersistedTraceContext(value) {
@@ -154,6 +155,32 @@ function extractCorrelationMetadata(record) {
154
155
  return found ? out : void 0;
155
156
  }
156
157
 
158
+ // packages/core/src/persisted/token-usage.ts
159
+ function isRecord2(value) {
160
+ return typeof value === "object" && value !== null && !Array.isArray(value);
161
+ }
162
+ function nonNegativeFinite(value) {
163
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
164
+ }
165
+ function normalizeTokenUsage(value) {
166
+ if (!isRecord2(value)) return void 0;
167
+ const input = nonNegativeFinite(value.input);
168
+ const output = nonNegativeFinite(value.output);
169
+ const suppliedTotal = nonNegativeFinite(value.total);
170
+ const cached = nonNegativeFinite(value.cached);
171
+ const derivedTotal = input !== void 0 && output !== void 0 && Number.isFinite(input + output) ? input + output : void 0;
172
+ const total = suppliedTotal ?? derivedTotal;
173
+ if (input === void 0 && output === void 0 && total === void 0 && cached === void 0) {
174
+ return void 0;
175
+ }
176
+ return {
177
+ ...input !== void 0 ? { input } : {},
178
+ ...output !== void 0 ? { output } : {},
179
+ ...total !== void 0 ? { total } : {},
180
+ ...cached !== void 0 ? { cached } : {}
181
+ };
182
+ }
183
+
157
184
  // packages/core/src/persisted/from-trace-event.ts
158
185
  function sanitizeIdPart(value) {
159
186
  return value.replace(/[^a-zA-Z0-9_-]/g, "_");
@@ -226,22 +253,7 @@ function mapErrorInfo(error) {
226
253
  return out;
227
254
  }
228
255
  function mapTokenUsageFromMetadata(metadata) {
229
- const tokens = metadata?.tokens;
230
- if (!tokens || typeof tokens !== "object") {
231
- return void 0;
232
- }
233
- const input = typeof tokens.input === "number" && Number.isFinite(tokens.input) && tokens.input >= 0 ? tokens.input : void 0;
234
- const output = typeof tokens.output === "number" && Number.isFinite(tokens.output) && tokens.output >= 0 ? tokens.output : void 0;
235
- if (input === void 0 && output === void 0) {
236
- return void 0;
237
- }
238
- const usage = {};
239
- if (input !== void 0) usage.input = input;
240
- if (output !== void 0) usage.output = output;
241
- if (input !== void 0 && output !== void 0) {
242
- usage.total = input + output;
243
- }
244
- return usage;
256
+ return normalizeTokenUsage(metadata?.tokens);
245
257
  }
246
258
  function compactAttributes(entries) {
247
259
  const out = {};
@@ -445,23 +457,7 @@ function mapInspectSourceToPersisted(source, options) {
445
457
  }
446
458
  }
447
459
  function mapTokenUsageFromAttributes(attributes) {
448
- const tokens = attributes?.tokens;
449
- if (!tokens || typeof tokens !== "object" || Array.isArray(tokens)) {
450
- return void 0;
451
- }
452
- const rec = tokens;
453
- const input = typeof rec.input === "number" && Number.isFinite(rec.input) && rec.input >= 0 ? rec.input : void 0;
454
- const output = typeof rec.output === "number" && Number.isFinite(rec.output) && rec.output >= 0 ? rec.output : void 0;
455
- if (input === void 0 && output === void 0) {
456
- return void 0;
457
- }
458
- const usage = {};
459
- if (input !== void 0) usage.input = input;
460
- if (output !== void 0) usage.output = output;
461
- if (input !== void 0 && output !== void 0) {
462
- usage.total = input + output;
463
- }
464
- return usage;
460
+ return normalizeTokenUsage(attributes?.tokens);
465
461
  }
466
462
  function mapErrorFromAttributes(event) {
467
463
  if (event.status !== "error" || !event.attributes) {
@@ -718,10 +714,10 @@ function mapPersistedStatusToRunStatus(status) {
718
714
  return void 0;
719
715
  }
720
716
  }
721
- function mapPersistedError(error) {
717
+ function mapPersistedError(error, attributes) {
722
718
  if (!error?.message) return void 0;
723
719
  const out = { message: error.message };
724
- const stack = typeof error.name === "string" && error.name.length > 0 ? error.name : void 0;
720
+ const stack = typeof attributes?.errorStack === "string" && attributes.errorStack.length > 0 ? attributes.errorStack : void 0;
725
721
  if (stack) {
726
722
  out.stack = stack;
727
723
  }
@@ -735,7 +731,9 @@ function mapTokenUsageToMetadata(tokenUsage, attributes) {
735
731
  if (tokenUsage) {
736
732
  metadata.tokens = {
737
733
  ...tokenUsage.input !== void 0 ? { input: tokenUsage.input } : {},
738
- ...tokenUsage.output !== void 0 ? { output: tokenUsage.output } : {}
734
+ ...tokenUsage.output !== void 0 ? { output: tokenUsage.output } : {},
735
+ ...tokenUsage.total !== void 0 ? { total: tokenUsage.total } : {},
736
+ ...tokenUsage.cached !== void 0 ? { cached: tokenUsage.cached } : {}
739
737
  };
740
738
  }
741
739
  return Object.keys(metadata).length > 0 ? metadata : void 0;
@@ -808,7 +806,7 @@ function fromLegacyRunCompleted(event) {
808
806
  endTime,
809
807
  durationMs: event.durationMs ?? Math.max(0, endTime - timestamp)
810
808
  };
811
- const error = mapPersistedError(event.error);
809
+ const error = mapPersistedError(event.error, event.attributes);
812
810
  if (error) out.error = error;
813
811
  return out;
814
812
  }
@@ -842,7 +840,7 @@ function fromLegacyStepCompleted(event) {
842
840
  endTime,
843
841
  durationMs: event.durationMs ?? Math.max(0, endTime - timestamp)
844
842
  };
845
- const error = mapPersistedError(event.error);
843
+ const error = mapPersistedError(event.error, event.attributes);
846
844
  if (error) out.error = error;
847
845
  return out;
848
846
  }
@@ -873,7 +871,7 @@ function fromNativeRun(event) {
873
871
  endTime,
874
872
  durationMs: event.durationMs ?? Math.max(0, endTime - startTime)
875
873
  };
876
- const error = mapPersistedError(event.error);
874
+ const error = mapPersistedError(event.error, event.attributes);
877
875
  if (error) completed.error = error;
878
876
  out.push(completed);
879
877
  }
@@ -915,7 +913,7 @@ function fromNativeStep(event) {
915
913
  endTime,
916
914
  durationMs: event.durationMs ?? Math.max(0, endTime - startTime)
917
915
  };
918
- const error = mapPersistedError(event.error);
916
+ const error = mapPersistedError(event.error, event.attributes);
919
917
  if (error) completed.error = error;
920
918
  out.push(completed);
921
919
  }