agent-inspect 1.1.0 → 1.3.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.
@@ -220,8 +220,17 @@ interface StepCompletedEvent extends TraceEventBase {
220
220
  }
221
221
  /** Discriminated union of all MVP trace events written as JSONL lines. */
222
222
  type TraceEvent = RunStartedEvent | RunCompletedEvent | StepStartedEvent | StepCompletedEvent;
223
+ /** Named redaction presets for trace writing and share-safe exports (v1.3.0+). */
224
+ type RedactionProfile = "local" | "share" | "strict";
225
+ /** Optional correlation fields for grouping and cross-run tracing (v1.3.0+). */
226
+ interface TraceCorrelationMetadata {
227
+ correlationId?: string;
228
+ requestId?: string;
229
+ decisionId?: string;
230
+ groupId?: string;
231
+ }
223
232
  /** Options for `inspectRun()` and `maybeInspectRun()`. */
224
- interface InspectRunOptions {
233
+ interface InspectRunOptions extends TraceCorrelationMetadata {
225
234
  traceDir?: string;
226
235
  silent?: boolean;
227
236
  metadata?: Record<string, unknown>;
@@ -237,6 +246,12 @@ interface InspectRunOptions {
237
246
  redact?: boolean | {
238
247
  rules?: RedactionRule[];
239
248
  };
249
+ /**
250
+ * Redaction preset for trace metadata. Default `local` (same keys as default redaction).
251
+ * `share` and `strict` add extra key-based redaction and tighter string bounds.
252
+ * Ignored when `redact: false`.
253
+ */
254
+ redactionProfile?: RedactionProfile;
240
255
  /** Max UTF-8 bytes for a serialized trace event line. Default 65536. */
241
256
  maxEventBytes?: number;
242
257
  /** Max length for string metadata values (non-preview keys). Default 2000. */
@@ -278,6 +293,145 @@ declare function isStepStatus(value: unknown): value is StepStatus;
278
293
  */
279
294
  declare function isTraceEvent(value: unknown): value is TraceEvent;
280
295
 
296
+ type PersistedSchemaVersion = "0.2";
297
+ type PersistedEventSourceType = "manual" | "json-log" | "log4js" | "adapter" | "ai-sdk" | "otel";
298
+ interface PersistedEventSource {
299
+ type: PersistedEventSourceType;
300
+ name?: string;
301
+ version?: string;
302
+ }
303
+ type PersistedEventStatus = "running" | "ok" | "error" | "unknown";
304
+ interface PersistedInspectError {
305
+ name?: string;
306
+ message: string;
307
+ code?: string;
308
+ }
309
+ interface PersistedTokenUsage {
310
+ input?: number;
311
+ output?: number;
312
+ total?: number;
313
+ }
314
+ interface PersistedTraceContext {
315
+ traceId?: string;
316
+ spanId?: string;
317
+ parentSpanId?: string;
318
+ }
319
+ interface PersistedInspectEvent {
320
+ schemaVersion: PersistedSchemaVersion;
321
+ eventId: string;
322
+ runId: string;
323
+ parentId?: string;
324
+ kind: InspectKind;
325
+ name: string;
326
+ status?: PersistedEventStatus;
327
+ timestamp: string;
328
+ startedAt?: string;
329
+ endedAt?: string;
330
+ durationMs?: number;
331
+ confidence: AttributionConfidence;
332
+ source: PersistedEventSource;
333
+ attributes?: Record<string, unknown>;
334
+ inputSummary?: unknown;
335
+ outputSummary?: unknown;
336
+ error?: PersistedInspectError;
337
+ tokenUsage?: PersistedTokenUsage;
338
+ trace?: PersistedTraceContext;
339
+ }
340
+ /**
341
+ * Runtime guard for a v0.2 {@link PersistedInspectEvent} JSON object.
342
+ *
343
+ * Timestamp fields (`timestamp`, `startedAt`, `endedAt`) are validated as
344
+ * non-empty strings only — stricter ISO-8601 parsing may be added later.
345
+ */
346
+ declare function isPersistedInspectEvent(value: unknown): value is PersistedInspectEvent;
347
+
348
+ interface TraceEventToPersistedOptions {
349
+ /**
350
+ * Stable index within the source event list.
351
+ * Used only to make synthetic eventId deterministic when v0.1 has no eventId.
352
+ */
353
+ eventIndex?: number;
354
+ /**
355
+ * Optional source name override.
356
+ * Default: "trace-event"
357
+ */
358
+ sourceName?: string;
359
+ /**
360
+ * Optional source version override.
361
+ * Default: "0.1"
362
+ */
363
+ sourceVersion?: string;
364
+ }
365
+ /**
366
+ * Maps one v0.1 {@link TraceEvent} to a v0.2 {@link PersistedInspectEvent}.
367
+ * Does not mutate `event`.
368
+ */
369
+ declare function traceEventToPersistedInspectEvent(event: TraceEvent, options?: TraceEventToPersistedOptions): PersistedInspectEvent;
370
+ /**
371
+ * Maps a v0.1 trace event list to persisted v0.2 events (one output per input).
372
+ */
373
+ declare function traceEventsToPersistedInspectEvents(events: readonly TraceEvent[], options?: Omit<TraceEventToPersistedOptions, "eventIndex">): PersistedInspectEvent[];
374
+
375
+ interface InspectEventToPersistedOptions {
376
+ /**
377
+ * Optional source name override.
378
+ * If omitted, derived from event.source.type.
379
+ */
380
+ sourceName?: string;
381
+ /**
382
+ * Optional source version override.
383
+ */
384
+ sourceVersion?: string;
385
+ /**
386
+ * Stable index for deterministic fallback IDs if needed.
387
+ */
388
+ eventIndex?: number;
389
+ }
390
+ /**
391
+ * Maps one in-memory {@link InspectEvent} to a v0.2 {@link PersistedInspectEvent}.
392
+ * Does not mutate `event`.
393
+ */
394
+ declare function inspectEventToPersistedInspectEvent(event: InspectEvent, options?: InspectEventToPersistedOptions): PersistedInspectEvent;
395
+ /**
396
+ * Maps in-memory {@link InspectEvent} rows to persisted v0.2 events.
397
+ */
398
+ declare function inspectEventsToPersistedInspectEvents(events: readonly InspectEvent[], options?: Omit<InspectEventToPersistedOptions, "eventIndex">): PersistedInspectEvent[];
399
+
400
+ interface PersistedToInspectEventOptions {
401
+ /**
402
+ * If true, invalid persisted events are skipped by batch conversion.
403
+ * If false or omitted, invalid events throw.
404
+ */
405
+ skipInvalid?: boolean;
406
+ }
407
+ /**
408
+ * Maps one v0.2 {@link PersistedInspectEvent} to in-memory {@link InspectEvent}.
409
+ * Throws if `event` fails {@link isPersistedInspectEvent}.
410
+ */
411
+ declare function persistedInspectEventToInspectEvent(event: PersistedInspectEvent): InspectEvent;
412
+ /**
413
+ * Maps persisted v0.2 events to in-memory {@link InspectEvent} rows.
414
+ */
415
+ declare function persistedInspectEventsToInspectEvents(events: readonly PersistedInspectEvent[], options?: PersistedToInspectEventOptions): InspectEvent[];
416
+
417
+ interface PersistedTreeBridgeOptions {
418
+ /**
419
+ * If true, invalid persisted events are skipped.
420
+ * If false or omitted, invalid persisted events throw.
421
+ */
422
+ skipInvalid?: boolean;
423
+ }
424
+ /**
425
+ * Builds {@link InspectRunTree} rows from v0.2 {@link PersistedInspectEvent} input.
426
+ * Uses {@link TreeBuilder} as the canonical tree builder. Does not mutate `events`.
427
+ */
428
+ declare function persistedInspectEventsToRunTrees(events: readonly PersistedInspectEvent[], options?: PersistedTreeBridgeOptions): InspectRunTree[];
429
+ /**
430
+ * Builds {@link InspectRunTree} rows from legacy v0.1 {@link TraceEvent} input
431
+ * via the persisted-event model. Does not mutate `events`.
432
+ */
433
+ declare function traceEventsToPersistedRunTrees(events: readonly TraceEvent[]): InspectRunTree[];
434
+
281
435
  type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
282
436
  interface ParserWarning {
283
437
  code: ParserWarningCode;
@@ -318,6 +472,8 @@ declare function matchMapping(eventName: string, mappings?: Record<string, LogEv
318
472
  declare const DEFAULT_REDACT_KEYS: readonly ["authorization", "cookie", "token", "apiKey", "password", "secret", "email"];
319
473
  interface RedactorOptions {
320
474
  rules?: RedactionRule[];
475
+ /** Additional exact keys (case-insensitive) to redact in addition to defaults. */
476
+ extraKeys?: readonly string[];
321
477
  }
322
478
  declare class Redactor {
323
479
  #private;
@@ -460,6 +616,15 @@ declare function truncateName(name: string, maxLength?: number): string;
460
616
  */
461
617
  declare function warn(message: string, error?: unknown): void;
462
618
 
619
+ interface ResolvedRedactionProfile {
620
+ profile: RedactionProfile;
621
+ extraKeys: readonly string[];
622
+ maxMetadataValueLengthCap?: number;
623
+ maxPreviewLengthCap?: number;
624
+ }
625
+ /** Resolves named profile behavior (keys + metadata string caps). */
626
+ declare function resolveRedactionProfile(profile?: RedactionProfile): ResolvedRedactionProfile;
627
+
463
628
  /** Default max length for string metadata values (non-preview keys). */
464
629
  declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
465
630
  /** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
@@ -470,12 +635,15 @@ declare const DEFAULT_MAX_EVENT_BYTES = 65536;
470
635
  interface TraceSafetyOptions {
471
636
  redactEnabled: boolean;
472
637
  redactionRules?: RedactionRule[];
638
+ redactionProfile: RedactionProfile;
639
+ profileExtraKeys: readonly string[];
473
640
  maxMetadataValueLength: number;
474
641
  maxPreviewLength: number;
475
642
  maxEventBytes: number;
476
643
  }
644
+
477
645
  /** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
478
- declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
646
+ declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "redactionProfile" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
479
647
  /** Redacts (when enabled) and truncates metadata values for disk persistence. */
480
648
  declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
481
649
  /**
@@ -488,6 +656,11 @@ declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOp
488
656
  declare function getCurrentContext(): ExecutionContext | undefined;
489
657
  /** Active `runId` when inside `runWithContext`, else `undefined`. */
490
658
  declare function getCurrentRunId(): string | undefined;
659
+ /**
660
+ * Correlation metadata for the active run (`correlationId`, `requestId`, `decisionId`, `groupId`).
661
+ * `undefined` outside `inspectRun` / `maybeInspectRun` or when no correlation fields were set.
662
+ */
663
+ declare function getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
491
664
  /** Active `runName` when inside `runWithContext`, else `undefined`. */
492
665
  declare function getCurrentRunName(): string | undefined;
493
666
  /**
@@ -748,6 +921,11 @@ interface ExportOptions {
748
921
  pretty?: boolean;
749
922
  redacted?: boolean;
750
923
  maxAttributeLength?: number;
924
+ /**
925
+ * Redaction preset for exported copies. Default `local`.
926
+ * `share` and `strict` apply stronger key-based redaction before rendering.
927
+ */
928
+ redactionProfile?: RedactionProfile;
751
929
  }
752
930
  interface ExportResult {
753
931
  format: ExportFormat;
@@ -822,6 +1000,15 @@ declare function exportOtlpJson(tree: InspectRunTree, options?: Partial<ExportOp
822
1000
 
823
1001
  declare function validateExportContent(format: ExportFormat, content: string): ExportValidationResult;
824
1002
 
1003
+ interface RedactRunTreeForExportOptions {
1004
+ redactionProfile?: RedactionProfile;
1005
+ }
1006
+ /**
1007
+ * Returns a deep copy of `tree` with profile-based redaction applied to event attributes.
1008
+ * Does not mutate the input tree.
1009
+ */
1010
+ declare function redactRunTreeForExport(tree: InspectRunTree, options?: RedactRunTreeForExportOptions): InspectRunTree;
1011
+
825
1012
  declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
826
1013
  /**
827
1014
  * @experimental Compatibility-oriented export API. Exports are local-only and do not upload anywhere.
@@ -830,4 +1017,4 @@ declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
830
1017
  declare function exportRunTree(tree: InspectRunTree, options: ExportOptions): ExportResult;
831
1018
  declare function validateExport(result: ExportResult): ExportValidationResult;
832
1019
 
833
- export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_REDACT_KEYS, DEFAULT_TRACE_DIR_NAME, type DiffKind, type DiffOptions, type DiffPath, type DiffPathSegment, type DiffSeverity, EXPORT_PAYLOAD_VERSION, type ErrorInfo, EventNormalizer, type EventSource, type ExecutionContext, type ExportFormat, type ExportOptions, type ExportResult, type ExportValidationResult, FALLBACK_TRACE_DIR, type InspectEvent, type InspectKind, type InspectNode, type InspectRunOptions, type InspectRunTree, JsonLogParser, LiveLogAccumulator, type LiveLogAccumulatorOptions, type LiveLogUpdate, Log4jsParser, type LogEventMapping, type LogIngestConfig, type LogSourceFormat, type LogToTreeResult, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type NormalizeOptions, type ObserveOptions, type OpenInferenceExport, type OpenInferenceSpan, type ParseLogLineOptions, type ParseLogsOptions, type ParseResult, type ParserWarning, type ParserWarningCode, RUNS_DIR_NAME, type RawLogRecord, type RedactionRule, type RedactionStrategy, Redactor, type RedactorOptions, type RenderDiffOptions, type RenderTreeOptions, type Run, type RunComparable, type RunCompletedEvent, type RunDiffItem, type RunDiffResult, type RunDiffSummary, type RunStartedEvent, type RunStatus, type RunSummary, type Step, type StepComparable, type StepCompletedEvent, type StepMetadata, type StepOptions, type StepStartedEvent, type StepStatus, type StepType, TERMINAL_INDENT, type TokenMetadata, TraceDirectory, type TraceDirectoryOptions, type TraceEvent, type TraceEventBase, type TraceExporter, type TraceFilterOptions, type TraceMetadata, type TraceMetadataStatus, type TraceSafetyOptions, type TraceSchemaVersion, TreeBuilder, type TreeBuilderOptions, buildRunSummary, compactAttributes, createRunId, createStepId, diffRuns, diffTraceEvents, ensureTraceDir, escapeHtml, escapeMarkdown, exportHtml, exportMarkdown, exportOpenInference, exportOtlpJson, exportRunTree, extractMetadata, filterTraces, flattenTree, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getRunIdFromTraceFileName, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, initializeTraceFile, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveTraceDir, resolveTraceSafetyOptions, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };
1020
+ export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_REDACT_KEYS, DEFAULT_TRACE_DIR_NAME, type DiffKind, type DiffOptions, type DiffPath, type DiffPathSegment, type DiffSeverity, EXPORT_PAYLOAD_VERSION, type ErrorInfo, EventNormalizer, type EventSource, type ExecutionContext, type ExportFormat, type ExportOptions, type ExportResult, type ExportValidationResult, FALLBACK_TRACE_DIR, type InspectEvent, type InspectEventToPersistedOptions, type InspectKind, type InspectNode, type InspectRunOptions, type InspectRunTree, JsonLogParser, LiveLogAccumulator, type LiveLogAccumulatorOptions, type LiveLogUpdate, Log4jsParser, type LogEventMapping, type LogIngestConfig, type LogSourceFormat, type LogToTreeResult, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type NormalizeOptions, type ObserveOptions, type OpenInferenceExport, type OpenInferenceSpan, type ParseLogLineOptions, type ParseLogsOptions, type ParseResult, type ParserWarning, type ParserWarningCode, type PersistedEventSource, type PersistedEventSourceType, type PersistedEventStatus, type PersistedInspectError, type PersistedInspectEvent, type PersistedSchemaVersion, type PersistedToInspectEventOptions, type PersistedTokenUsage, type PersistedTraceContext, type PersistedTreeBridgeOptions, RUNS_DIR_NAME, type RawLogRecord, type RedactionProfile, type RedactionRule, type RedactionStrategy, Redactor, type RedactorOptions, type RenderDiffOptions, type RenderTreeOptions, type ResolvedRedactionProfile, type Run, type RunComparable, type RunCompletedEvent, type RunDiffItem, type RunDiffResult, type RunDiffSummary, type RunStartedEvent, type RunStatus, type RunSummary, type Step, type StepComparable, type StepCompletedEvent, type StepMetadata, type StepOptions, type StepStartedEvent, type StepStatus, type StepType, TERMINAL_INDENT, type TokenMetadata, type TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, type TraceEvent, type TraceEventBase, type TraceEventToPersistedOptions, type TraceExporter, type TraceFilterOptions, type TraceMetadata, type TraceMetadataStatus, type TraceSafetyOptions, type TraceSchemaVersion, TreeBuilder, type TreeBuilderOptions, buildRunSummary, compactAttributes, createRunId, createStepId, diffRuns, diffTraceEvents, ensureTraceDir, escapeHtml, escapeMarkdown, exportHtml, exportMarkdown, exportOpenInference, exportOtlpJson, exportRunTree, extractMetadata, filterTraces, flattenTree, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getRunIdFromTraceFileName, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, initializeTraceFile, inspectEventToPersistedInspectEvent, inspectEventsToPersistedInspectEvents, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isPersistedInspectEvent, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, persistedInspectEventToInspectEvent, persistedInspectEventsToInspectEvents, persistedInspectEventsToRunTrees, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, redactRunTreeForExport, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveRedactionProfile, resolveTraceDir, resolveTraceSafetyOptions, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, traceEventToPersistedInspectEvent, traceEventsToPersistedInspectEvents, traceEventsToPersistedRunTrees, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };
@@ -220,8 +220,17 @@ interface StepCompletedEvent extends TraceEventBase {
220
220
  }
221
221
  /** Discriminated union of all MVP trace events written as JSONL lines. */
222
222
  type TraceEvent = RunStartedEvent | RunCompletedEvent | StepStartedEvent | StepCompletedEvent;
223
+ /** Named redaction presets for trace writing and share-safe exports (v1.3.0+). */
224
+ type RedactionProfile = "local" | "share" | "strict";
225
+ /** Optional correlation fields for grouping and cross-run tracing (v1.3.0+). */
226
+ interface TraceCorrelationMetadata {
227
+ correlationId?: string;
228
+ requestId?: string;
229
+ decisionId?: string;
230
+ groupId?: string;
231
+ }
223
232
  /** Options for `inspectRun()` and `maybeInspectRun()`. */
224
- interface InspectRunOptions {
233
+ interface InspectRunOptions extends TraceCorrelationMetadata {
225
234
  traceDir?: string;
226
235
  silent?: boolean;
227
236
  metadata?: Record<string, unknown>;
@@ -237,6 +246,12 @@ interface InspectRunOptions {
237
246
  redact?: boolean | {
238
247
  rules?: RedactionRule[];
239
248
  };
249
+ /**
250
+ * Redaction preset for trace metadata. Default `local` (same keys as default redaction).
251
+ * `share` and `strict` add extra key-based redaction and tighter string bounds.
252
+ * Ignored when `redact: false`.
253
+ */
254
+ redactionProfile?: RedactionProfile;
240
255
  /** Max UTF-8 bytes for a serialized trace event line. Default 65536. */
241
256
  maxEventBytes?: number;
242
257
  /** Max length for string metadata values (non-preview keys). Default 2000. */
@@ -278,6 +293,145 @@ declare function isStepStatus(value: unknown): value is StepStatus;
278
293
  */
279
294
  declare function isTraceEvent(value: unknown): value is TraceEvent;
280
295
 
296
+ type PersistedSchemaVersion = "0.2";
297
+ type PersistedEventSourceType = "manual" | "json-log" | "log4js" | "adapter" | "ai-sdk" | "otel";
298
+ interface PersistedEventSource {
299
+ type: PersistedEventSourceType;
300
+ name?: string;
301
+ version?: string;
302
+ }
303
+ type PersistedEventStatus = "running" | "ok" | "error" | "unknown";
304
+ interface PersistedInspectError {
305
+ name?: string;
306
+ message: string;
307
+ code?: string;
308
+ }
309
+ interface PersistedTokenUsage {
310
+ input?: number;
311
+ output?: number;
312
+ total?: number;
313
+ }
314
+ interface PersistedTraceContext {
315
+ traceId?: string;
316
+ spanId?: string;
317
+ parentSpanId?: string;
318
+ }
319
+ interface PersistedInspectEvent {
320
+ schemaVersion: PersistedSchemaVersion;
321
+ eventId: string;
322
+ runId: string;
323
+ parentId?: string;
324
+ kind: InspectKind;
325
+ name: string;
326
+ status?: PersistedEventStatus;
327
+ timestamp: string;
328
+ startedAt?: string;
329
+ endedAt?: string;
330
+ durationMs?: number;
331
+ confidence: AttributionConfidence;
332
+ source: PersistedEventSource;
333
+ attributes?: Record<string, unknown>;
334
+ inputSummary?: unknown;
335
+ outputSummary?: unknown;
336
+ error?: PersistedInspectError;
337
+ tokenUsage?: PersistedTokenUsage;
338
+ trace?: PersistedTraceContext;
339
+ }
340
+ /**
341
+ * Runtime guard for a v0.2 {@link PersistedInspectEvent} JSON object.
342
+ *
343
+ * Timestamp fields (`timestamp`, `startedAt`, `endedAt`) are validated as
344
+ * non-empty strings only — stricter ISO-8601 parsing may be added later.
345
+ */
346
+ declare function isPersistedInspectEvent(value: unknown): value is PersistedInspectEvent;
347
+
348
+ interface TraceEventToPersistedOptions {
349
+ /**
350
+ * Stable index within the source event list.
351
+ * Used only to make synthetic eventId deterministic when v0.1 has no eventId.
352
+ */
353
+ eventIndex?: number;
354
+ /**
355
+ * Optional source name override.
356
+ * Default: "trace-event"
357
+ */
358
+ sourceName?: string;
359
+ /**
360
+ * Optional source version override.
361
+ * Default: "0.1"
362
+ */
363
+ sourceVersion?: string;
364
+ }
365
+ /**
366
+ * Maps one v0.1 {@link TraceEvent} to a v0.2 {@link PersistedInspectEvent}.
367
+ * Does not mutate `event`.
368
+ */
369
+ declare function traceEventToPersistedInspectEvent(event: TraceEvent, options?: TraceEventToPersistedOptions): PersistedInspectEvent;
370
+ /**
371
+ * Maps a v0.1 trace event list to persisted v0.2 events (one output per input).
372
+ */
373
+ declare function traceEventsToPersistedInspectEvents(events: readonly TraceEvent[], options?: Omit<TraceEventToPersistedOptions, "eventIndex">): PersistedInspectEvent[];
374
+
375
+ interface InspectEventToPersistedOptions {
376
+ /**
377
+ * Optional source name override.
378
+ * If omitted, derived from event.source.type.
379
+ */
380
+ sourceName?: string;
381
+ /**
382
+ * Optional source version override.
383
+ */
384
+ sourceVersion?: string;
385
+ /**
386
+ * Stable index for deterministic fallback IDs if needed.
387
+ */
388
+ eventIndex?: number;
389
+ }
390
+ /**
391
+ * Maps one in-memory {@link InspectEvent} to a v0.2 {@link PersistedInspectEvent}.
392
+ * Does not mutate `event`.
393
+ */
394
+ declare function inspectEventToPersistedInspectEvent(event: InspectEvent, options?: InspectEventToPersistedOptions): PersistedInspectEvent;
395
+ /**
396
+ * Maps in-memory {@link InspectEvent} rows to persisted v0.2 events.
397
+ */
398
+ declare function inspectEventsToPersistedInspectEvents(events: readonly InspectEvent[], options?: Omit<InspectEventToPersistedOptions, "eventIndex">): PersistedInspectEvent[];
399
+
400
+ interface PersistedToInspectEventOptions {
401
+ /**
402
+ * If true, invalid persisted events are skipped by batch conversion.
403
+ * If false or omitted, invalid events throw.
404
+ */
405
+ skipInvalid?: boolean;
406
+ }
407
+ /**
408
+ * Maps one v0.2 {@link PersistedInspectEvent} to in-memory {@link InspectEvent}.
409
+ * Throws if `event` fails {@link isPersistedInspectEvent}.
410
+ */
411
+ declare function persistedInspectEventToInspectEvent(event: PersistedInspectEvent): InspectEvent;
412
+ /**
413
+ * Maps persisted v0.2 events to in-memory {@link InspectEvent} rows.
414
+ */
415
+ declare function persistedInspectEventsToInspectEvents(events: readonly PersistedInspectEvent[], options?: PersistedToInspectEventOptions): InspectEvent[];
416
+
417
+ interface PersistedTreeBridgeOptions {
418
+ /**
419
+ * If true, invalid persisted events are skipped.
420
+ * If false or omitted, invalid persisted events throw.
421
+ */
422
+ skipInvalid?: boolean;
423
+ }
424
+ /**
425
+ * Builds {@link InspectRunTree} rows from v0.2 {@link PersistedInspectEvent} input.
426
+ * Uses {@link TreeBuilder} as the canonical tree builder. Does not mutate `events`.
427
+ */
428
+ declare function persistedInspectEventsToRunTrees(events: readonly PersistedInspectEvent[], options?: PersistedTreeBridgeOptions): InspectRunTree[];
429
+ /**
430
+ * Builds {@link InspectRunTree} rows from legacy v0.1 {@link TraceEvent} input
431
+ * via the persisted-event model. Does not mutate `events`.
432
+ */
433
+ declare function traceEventsToPersistedRunTrees(events: readonly TraceEvent[]): InspectRunTree[];
434
+
281
435
  type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
282
436
  interface ParserWarning {
283
437
  code: ParserWarningCode;
@@ -318,6 +472,8 @@ declare function matchMapping(eventName: string, mappings?: Record<string, LogEv
318
472
  declare const DEFAULT_REDACT_KEYS: readonly ["authorization", "cookie", "token", "apiKey", "password", "secret", "email"];
319
473
  interface RedactorOptions {
320
474
  rules?: RedactionRule[];
475
+ /** Additional exact keys (case-insensitive) to redact in addition to defaults. */
476
+ extraKeys?: readonly string[];
321
477
  }
322
478
  declare class Redactor {
323
479
  #private;
@@ -460,6 +616,15 @@ declare function truncateName(name: string, maxLength?: number): string;
460
616
  */
461
617
  declare function warn(message: string, error?: unknown): void;
462
618
 
619
+ interface ResolvedRedactionProfile {
620
+ profile: RedactionProfile;
621
+ extraKeys: readonly string[];
622
+ maxMetadataValueLengthCap?: number;
623
+ maxPreviewLengthCap?: number;
624
+ }
625
+ /** Resolves named profile behavior (keys + metadata string caps). */
626
+ declare function resolveRedactionProfile(profile?: RedactionProfile): ResolvedRedactionProfile;
627
+
463
628
  /** Default max length for string metadata values (non-preview keys). */
464
629
  declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
465
630
  /** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
@@ -470,12 +635,15 @@ declare const DEFAULT_MAX_EVENT_BYTES = 65536;
470
635
  interface TraceSafetyOptions {
471
636
  redactEnabled: boolean;
472
637
  redactionRules?: RedactionRule[];
638
+ redactionProfile: RedactionProfile;
639
+ profileExtraKeys: readonly string[];
473
640
  maxMetadataValueLength: number;
474
641
  maxPreviewLength: number;
475
642
  maxEventBytes: number;
476
643
  }
644
+
477
645
  /** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
478
- declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
646
+ declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "redactionProfile" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
479
647
  /** Redacts (when enabled) and truncates metadata values for disk persistence. */
480
648
  declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
481
649
  /**
@@ -488,6 +656,11 @@ declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOp
488
656
  declare function getCurrentContext(): ExecutionContext | undefined;
489
657
  /** Active `runId` when inside `runWithContext`, else `undefined`. */
490
658
  declare function getCurrentRunId(): string | undefined;
659
+ /**
660
+ * Correlation metadata for the active run (`correlationId`, `requestId`, `decisionId`, `groupId`).
661
+ * `undefined` outside `inspectRun` / `maybeInspectRun` or when no correlation fields were set.
662
+ */
663
+ declare function getCurrentCorrelationMetadata(): TraceCorrelationMetadata | undefined;
491
664
  /** Active `runName` when inside `runWithContext`, else `undefined`. */
492
665
  declare function getCurrentRunName(): string | undefined;
493
666
  /**
@@ -748,6 +921,11 @@ interface ExportOptions {
748
921
  pretty?: boolean;
749
922
  redacted?: boolean;
750
923
  maxAttributeLength?: number;
924
+ /**
925
+ * Redaction preset for exported copies. Default `local`.
926
+ * `share` and `strict` apply stronger key-based redaction before rendering.
927
+ */
928
+ redactionProfile?: RedactionProfile;
751
929
  }
752
930
  interface ExportResult {
753
931
  format: ExportFormat;
@@ -822,6 +1000,15 @@ declare function exportOtlpJson(tree: InspectRunTree, options?: Partial<ExportOp
822
1000
 
823
1001
  declare function validateExportContent(format: ExportFormat, content: string): ExportValidationResult;
824
1002
 
1003
+ interface RedactRunTreeForExportOptions {
1004
+ redactionProfile?: RedactionProfile;
1005
+ }
1006
+ /**
1007
+ * Returns a deep copy of `tree` with profile-based redaction applied to event attributes.
1008
+ * Does not mutate the input tree.
1009
+ */
1010
+ declare function redactRunTreeForExport(tree: InspectRunTree, options?: RedactRunTreeForExportOptions): InspectRunTree;
1011
+
825
1012
  declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
826
1013
  /**
827
1014
  * @experimental Compatibility-oriented export API. Exports are local-only and do not upload anywhere.
@@ -830,4 +1017,4 @@ declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
830
1017
  declare function exportRunTree(tree: InspectRunTree, options: ExportOptions): ExportResult;
831
1018
  declare function validateExport(result: ExportResult): ExportValidationResult;
832
1019
 
833
- export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_REDACT_KEYS, DEFAULT_TRACE_DIR_NAME, type DiffKind, type DiffOptions, type DiffPath, type DiffPathSegment, type DiffSeverity, EXPORT_PAYLOAD_VERSION, type ErrorInfo, EventNormalizer, type EventSource, type ExecutionContext, type ExportFormat, type ExportOptions, type ExportResult, type ExportValidationResult, FALLBACK_TRACE_DIR, type InspectEvent, type InspectKind, type InspectNode, type InspectRunOptions, type InspectRunTree, JsonLogParser, LiveLogAccumulator, type LiveLogAccumulatorOptions, type LiveLogUpdate, Log4jsParser, type LogEventMapping, type LogIngestConfig, type LogSourceFormat, type LogToTreeResult, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type NormalizeOptions, type ObserveOptions, type OpenInferenceExport, type OpenInferenceSpan, type ParseLogLineOptions, type ParseLogsOptions, type ParseResult, type ParserWarning, type ParserWarningCode, RUNS_DIR_NAME, type RawLogRecord, type RedactionRule, type RedactionStrategy, Redactor, type RedactorOptions, type RenderDiffOptions, type RenderTreeOptions, type Run, type RunComparable, type RunCompletedEvent, type RunDiffItem, type RunDiffResult, type RunDiffSummary, type RunStartedEvent, type RunStatus, type RunSummary, type Step, type StepComparable, type StepCompletedEvent, type StepMetadata, type StepOptions, type StepStartedEvent, type StepStatus, type StepType, TERMINAL_INDENT, type TokenMetadata, TraceDirectory, type TraceDirectoryOptions, type TraceEvent, type TraceEventBase, type TraceExporter, type TraceFilterOptions, type TraceMetadata, type TraceMetadataStatus, type TraceSafetyOptions, type TraceSchemaVersion, TreeBuilder, type TreeBuilderOptions, buildRunSummary, compactAttributes, createRunId, createStepId, diffRuns, diffTraceEvents, ensureTraceDir, escapeHtml, escapeMarkdown, exportHtml, exportMarkdown, exportOpenInference, exportOtlpJson, exportRunTree, extractMetadata, filterTraces, flattenTree, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getRunIdFromTraceFileName, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, initializeTraceFile, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveTraceDir, resolveTraceSafetyOptions, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };
1020
+ export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, DEFAULT_REDACT_KEYS, DEFAULT_TRACE_DIR_NAME, type DiffKind, type DiffOptions, type DiffPath, type DiffPathSegment, type DiffSeverity, EXPORT_PAYLOAD_VERSION, type ErrorInfo, EventNormalizer, type EventSource, type ExecutionContext, type ExportFormat, type ExportOptions, type ExportResult, type ExportValidationResult, FALLBACK_TRACE_DIR, type InspectEvent, type InspectEventToPersistedOptions, type InspectKind, type InspectNode, type InspectRunOptions, type InspectRunTree, JsonLogParser, LiveLogAccumulator, type LiveLogAccumulatorOptions, type LiveLogUpdate, Log4jsParser, type LogEventMapping, type LogIngestConfig, type LogSourceFormat, type LogToTreeResult, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type NormalizeOptions, type ObserveOptions, type OpenInferenceExport, type OpenInferenceSpan, type ParseLogLineOptions, type ParseLogsOptions, type ParseResult, type ParserWarning, type ParserWarningCode, type PersistedEventSource, type PersistedEventSourceType, type PersistedEventStatus, type PersistedInspectError, type PersistedInspectEvent, type PersistedSchemaVersion, type PersistedToInspectEventOptions, type PersistedTokenUsage, type PersistedTraceContext, type PersistedTreeBridgeOptions, RUNS_DIR_NAME, type RawLogRecord, type RedactionProfile, type RedactionRule, type RedactionStrategy, Redactor, type RedactorOptions, type RenderDiffOptions, type RenderTreeOptions, type ResolvedRedactionProfile, type Run, type RunComparable, type RunCompletedEvent, type RunDiffItem, type RunDiffResult, type RunDiffSummary, type RunStartedEvent, type RunStatus, type RunSummary, type Step, type StepComparable, type StepCompletedEvent, type StepMetadata, type StepOptions, type StepStartedEvent, type StepStatus, type StepType, TERMINAL_INDENT, type TokenMetadata, type TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, type TraceEvent, type TraceEventBase, type TraceEventToPersistedOptions, type TraceExporter, type TraceFilterOptions, type TraceMetadata, type TraceMetadataStatus, type TraceSafetyOptions, type TraceSchemaVersion, TreeBuilder, type TreeBuilderOptions, buildRunSummary, compactAttributes, createRunId, createStepId, diffRuns, diffTraceEvents, ensureTraceDir, escapeHtml, escapeMarkdown, exportHtml, exportMarkdown, exportOpenInference, exportOtlpJson, exportRunTree, extractMetadata, filterTraces, flattenTree, formatDuration, formatError, formatTerminalName, formatTimestamp, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getDefaultTraceDir, getIndent, getParentStepId, getRunIdFromTraceFileName, getTraceDirFromContext, getTraceFilePath, getTraceSafetyFromContext, hasActiveContext, initializeTraceFile, inspectEventToPersistedInspectEvent, inspectEventsToPersistedInspectEvents, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isPersistedInspectEvent, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, persistedInspectEventToInspectEvent, persistedInspectEventsToInspectEvents, persistedInspectEventsToRunTrees, prepareMetadataForDisk, prepareTraceEventForDisk, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, redactRunTreeForExport, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveRedactionProfile, resolveTraceDir, resolveTraceSafetyOptions, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, traceEventToPersistedInspectEvent, traceEventsToPersistedInspectEvents, traceEventsToPersistedRunTrees, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };