agent-inspect 1.0.3 → 1.1.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.
- package/CHANGELOG.md +49 -10
- package/README.md +13 -3
- package/SECURITY.md +5 -2
- package/docs/ADAPTERS.md +28 -1
- package/docs/API.md +12 -1
- package/docs/ARCHITECTURE.md +43 -8
- package/docs/EXPORTS.md +1 -1
- package/docs/GETTING-STARTED.md +14 -10
- package/docs/LIMITATIONS.md +7 -1
- package/docs/LOG-TO-TREE-QUICKSTART.md +2 -0
- package/docs/LOGS.md +3 -2
- package/docs/SCHEMA.md +8 -2
- package/package.json +12 -15
- package/packages/cli/dist/index.cjs +310 -90
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +310 -90
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/core/dist/index.cjs +385 -141
- package/packages/core/dist/index.cjs.map +1 -1
- package/packages/core/dist/index.d.cts +111 -75
- package/packages/core/dist/index.d.ts +111 -75
- package/packages/core/dist/index.mjs +379 -142
- package/packages/core/dist/index.mjs.map +1 -1
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
import { Stats } from 'node:fs';
|
|
2
2
|
|
|
3
|
+
type AttributionConfidence = "explicit" | "correlated" | "heuristic" | "unknown";
|
|
4
|
+
type InspectKind = "RUN" | "AGENT" | "LLM" | "TOOL" | "CHAIN" | "RETRIEVER" | "DECISION" | "RESULT" | "ERROR" | "LOGIC" | "LOG";
|
|
5
|
+
interface EventSource {
|
|
6
|
+
type: "manual" | "json-log" | "log4js" | "pino" | "winston" | "adapter";
|
|
7
|
+
file?: string;
|
|
8
|
+
line?: number;
|
|
9
|
+
}
|
|
10
|
+
interface InspectEvent {
|
|
11
|
+
eventId: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
parentId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
kind: InspectKind;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
status?: "running" | "ok" | "error";
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
attributes?: Record<string, unknown>;
|
|
20
|
+
confidence: AttributionConfidence;
|
|
21
|
+
source: EventSource;
|
|
22
|
+
}
|
|
23
|
+
interface InspectNode {
|
|
24
|
+
event: InspectEvent;
|
|
25
|
+
children: InspectNode[];
|
|
26
|
+
depth: number;
|
|
27
|
+
}
|
|
28
|
+
interface InspectRunTree {
|
|
29
|
+
runId: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
status?: "running" | "ok" | "error";
|
|
32
|
+
startedAt?: number;
|
|
33
|
+
endedAt?: number;
|
|
34
|
+
durationMs?: number;
|
|
35
|
+
children: InspectNode[];
|
|
36
|
+
metadata: {
|
|
37
|
+
totalEvents: number;
|
|
38
|
+
confidenceBreakdown: Record<AttributionConfidence, number>;
|
|
39
|
+
kinds: Record<InspectKind, number>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface LogEventMapping {
|
|
44
|
+
kind?: InspectKind;
|
|
45
|
+
name?: string;
|
|
46
|
+
parent?: string;
|
|
47
|
+
status?: "running" | "ok" | "error";
|
|
48
|
+
startsRun?: boolean;
|
|
49
|
+
endsRun?: boolean;
|
|
50
|
+
startsStep?: boolean;
|
|
51
|
+
endsStep?: boolean;
|
|
52
|
+
}
|
|
53
|
+
type RedactionStrategy = "full" | "prefix" | "hash";
|
|
54
|
+
type RedactionRule = string | {
|
|
55
|
+
key: string;
|
|
56
|
+
strategy: RedactionStrategy;
|
|
57
|
+
keep?: number;
|
|
58
|
+
};
|
|
59
|
+
interface LogIngestConfig {
|
|
60
|
+
runIdKeys: string[];
|
|
61
|
+
eventKey: string;
|
|
62
|
+
timestampKey?: string;
|
|
63
|
+
messageKey?: string;
|
|
64
|
+
levelKey?: string;
|
|
65
|
+
parentIdKey?: string;
|
|
66
|
+
durationKey?: string;
|
|
67
|
+
statusKey?: string;
|
|
68
|
+
mappings?: Record<string, LogEventMapping>;
|
|
69
|
+
redact?: RedactionRule[];
|
|
70
|
+
heuristicWindowMs?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
3
73
|
/**
|
|
4
74
|
* Discriminator for what kind of work a {@link Step} represents.
|
|
5
75
|
* `"decision"` captures agent branching/choices; other values cover runs, LLM calls, tools, and user-defined steps.
|
|
@@ -160,6 +230,19 @@ interface InspectRunOptions {
|
|
|
160
230
|
* Omitted or `true` preserves default tracing behavior.
|
|
161
231
|
*/
|
|
162
232
|
enabled?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Redact sensitive metadata keys before writing JSONL. Default `true` (conservative keys).
|
|
235
|
+
* Pass `false` to persist metadata as-is (explicit opt-out).
|
|
236
|
+
*/
|
|
237
|
+
redact?: boolean | {
|
|
238
|
+
rules?: RedactionRule[];
|
|
239
|
+
};
|
|
240
|
+
/** Max UTF-8 bytes for a serialized trace event line. Default 65536. */
|
|
241
|
+
maxEventBytes?: number;
|
|
242
|
+
/** Max length for string metadata values (non-preview keys). Default 2000. */
|
|
243
|
+
maxMetadataValueLength?: number;
|
|
244
|
+
/** Max length for preview-like metadata keys (contains `preview`). Default 500. */
|
|
245
|
+
maxPreviewLength?: number;
|
|
163
246
|
}
|
|
164
247
|
/** Options passed when opening a logical step (implemented in a later step). */
|
|
165
248
|
interface StepOptions {
|
|
@@ -195,76 +278,6 @@ declare function isStepStatus(value: unknown): value is StepStatus;
|
|
|
195
278
|
*/
|
|
196
279
|
declare function isTraceEvent(value: unknown): value is TraceEvent;
|
|
197
280
|
|
|
198
|
-
type AttributionConfidence = "explicit" | "correlated" | "heuristic" | "unknown";
|
|
199
|
-
type InspectKind = "RUN" | "AGENT" | "LLM" | "TOOL" | "CHAIN" | "RETRIEVER" | "DECISION" | "RESULT" | "ERROR" | "LOGIC" | "LOG";
|
|
200
|
-
interface EventSource {
|
|
201
|
-
type: "manual" | "json-log" | "log4js" | "pino" | "winston" | "adapter";
|
|
202
|
-
file?: string;
|
|
203
|
-
line?: number;
|
|
204
|
-
}
|
|
205
|
-
interface InspectEvent {
|
|
206
|
-
eventId: string;
|
|
207
|
-
runId: string;
|
|
208
|
-
parentId?: string;
|
|
209
|
-
name: string;
|
|
210
|
-
kind: InspectKind;
|
|
211
|
-
timestamp: number;
|
|
212
|
-
status?: "running" | "ok" | "error";
|
|
213
|
-
durationMs?: number;
|
|
214
|
-
attributes?: Record<string, unknown>;
|
|
215
|
-
confidence: AttributionConfidence;
|
|
216
|
-
source: EventSource;
|
|
217
|
-
}
|
|
218
|
-
interface InspectNode {
|
|
219
|
-
event: InspectEvent;
|
|
220
|
-
children: InspectNode[];
|
|
221
|
-
depth: number;
|
|
222
|
-
}
|
|
223
|
-
interface InspectRunTree {
|
|
224
|
-
runId: string;
|
|
225
|
-
name?: string;
|
|
226
|
-
status?: "running" | "ok" | "error";
|
|
227
|
-
startedAt?: number;
|
|
228
|
-
endedAt?: number;
|
|
229
|
-
durationMs?: number;
|
|
230
|
-
children: InspectNode[];
|
|
231
|
-
metadata: {
|
|
232
|
-
totalEvents: number;
|
|
233
|
-
confidenceBreakdown: Record<AttributionConfidence, number>;
|
|
234
|
-
kinds: Record<InspectKind, number>;
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
interface LogEventMapping {
|
|
239
|
-
kind?: InspectKind;
|
|
240
|
-
name?: string;
|
|
241
|
-
parent?: string;
|
|
242
|
-
status?: "running" | "ok" | "error";
|
|
243
|
-
startsRun?: boolean;
|
|
244
|
-
endsRun?: boolean;
|
|
245
|
-
startsStep?: boolean;
|
|
246
|
-
endsStep?: boolean;
|
|
247
|
-
}
|
|
248
|
-
type RedactionStrategy = "full" | "prefix" | "hash";
|
|
249
|
-
type RedactionRule = string | {
|
|
250
|
-
key: string;
|
|
251
|
-
strategy: RedactionStrategy;
|
|
252
|
-
keep?: number;
|
|
253
|
-
};
|
|
254
|
-
interface LogIngestConfig {
|
|
255
|
-
runIdKeys: string[];
|
|
256
|
-
eventKey: string;
|
|
257
|
-
timestampKey?: string;
|
|
258
|
-
messageKey?: string;
|
|
259
|
-
levelKey?: string;
|
|
260
|
-
parentIdKey?: string;
|
|
261
|
-
durationKey?: string;
|
|
262
|
-
statusKey?: string;
|
|
263
|
-
mappings?: Record<string, LogEventMapping>;
|
|
264
|
-
redact?: RedactionRule[];
|
|
265
|
-
heuristicWindowMs?: number;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
281
|
type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
|
|
269
282
|
interface ParserWarning {
|
|
270
283
|
code: ParserWarningCode;
|
|
@@ -447,6 +460,30 @@ declare function truncateName(name: string, maxLength?: number): string;
|
|
|
447
460
|
*/
|
|
448
461
|
declare function warn(message: string, error?: unknown): void;
|
|
449
462
|
|
|
463
|
+
/** Default max length for string metadata values (non-preview keys). */
|
|
464
|
+
declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
|
|
465
|
+
/** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
|
|
466
|
+
declare const DEFAULT_MAX_PREVIEW_LENGTH = 500;
|
|
467
|
+
/** Default max serialized JSONL line size in bytes (UTF-8). */
|
|
468
|
+
declare const DEFAULT_MAX_EVENT_BYTES = 65536;
|
|
469
|
+
/** Resolved trace safety settings used at write time. */
|
|
470
|
+
interface TraceSafetyOptions {
|
|
471
|
+
redactEnabled: boolean;
|
|
472
|
+
redactionRules?: RedactionRule[];
|
|
473
|
+
maxMetadataValueLength: number;
|
|
474
|
+
maxPreviewLength: number;
|
|
475
|
+
maxEventBytes: number;
|
|
476
|
+
}
|
|
477
|
+
/** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
|
|
478
|
+
declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
|
|
479
|
+
/** Redacts (when enabled) and truncates metadata values for disk persistence. */
|
|
480
|
+
declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
|
|
481
|
+
/**
|
|
482
|
+
* Applies redaction, metadata truncation, and final serialized size bounds.
|
|
483
|
+
* Never throws; returns a schema-valid event or a minimally truncated variant.
|
|
484
|
+
*/
|
|
485
|
+
declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOptions): TraceEvent;
|
|
486
|
+
|
|
450
487
|
/** Returns the active run context, without internal step fields. */
|
|
451
488
|
declare function getCurrentContext(): ExecutionContext | undefined;
|
|
452
489
|
/** Active `runId` when inside `runWithContext`, else `undefined`. */
|
|
@@ -468,11 +505,13 @@ declare function getCurrentDepth(): number;
|
|
|
468
505
|
declare function hasActiveContext(): boolean;
|
|
469
506
|
declare function getTraceDirFromContext(): string | undefined;
|
|
470
507
|
declare function isSilentContext(): boolean;
|
|
508
|
+
/** Resolved trace safety settings for the active run (redaction + size bounds). */
|
|
509
|
+
declare function getTraceSafetyFromContext(): TraceSafetyOptions | undefined;
|
|
471
510
|
/**
|
|
472
511
|
* Runs `fn` with a fresh AgentInspect run context (depth 0, no active step).
|
|
473
512
|
* Propagates sync/async results and rejections; does not swallow user errors.
|
|
474
513
|
*/
|
|
475
|
-
declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T): Promise<T>;
|
|
514
|
+
declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T, traceSafety?: TraceSafetyOptions): Promise<T>;
|
|
476
515
|
/**
|
|
477
516
|
* Runs `fn` with `stepId` as the active step (incremented depth).
|
|
478
517
|
* If no run is active, runs `fn` without altering async context.
|
|
@@ -490,9 +529,6 @@ declare function serializeEvent(event: TraceEvent): string;
|
|
|
490
529
|
* On failure, retries once under {@link FALLBACK_TRACE_DIR}.
|
|
491
530
|
*/
|
|
492
531
|
declare function initializeTraceFile(runId: string, traceDir: string): Promise<string | undefined>;
|
|
493
|
-
/**
|
|
494
|
-
* Appends one validated JSONL line for `event.runId`. Falls back to {@link FALLBACK_TRACE_DIR} on append failure.
|
|
495
|
-
*/
|
|
496
532
|
declare function writeTraceEvent(event: TraceEvent, traceDir: string): Promise<void>;
|
|
497
533
|
/**
|
|
498
534
|
* Reads raw JSONL file contents for a run, or `undefined` if missing or unreadable.
|
|
@@ -794,4 +830,4 @@ declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
|
|
|
794
830
|
declare function exportRunTree(tree: InspectRunTree, options: ExportOptions): ExportResult;
|
|
795
831
|
declare function validateExport(result: ExportResult): ExportValidationResult;
|
|
796
832
|
|
|
797
|
-
export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, 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 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, hasActiveContext, initializeTraceFile, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveTraceDir, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };
|
|
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 };
|
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
import { Stats } from 'node:fs';
|
|
2
2
|
|
|
3
|
+
type AttributionConfidence = "explicit" | "correlated" | "heuristic" | "unknown";
|
|
4
|
+
type InspectKind = "RUN" | "AGENT" | "LLM" | "TOOL" | "CHAIN" | "RETRIEVER" | "DECISION" | "RESULT" | "ERROR" | "LOGIC" | "LOG";
|
|
5
|
+
interface EventSource {
|
|
6
|
+
type: "manual" | "json-log" | "log4js" | "pino" | "winston" | "adapter";
|
|
7
|
+
file?: string;
|
|
8
|
+
line?: number;
|
|
9
|
+
}
|
|
10
|
+
interface InspectEvent {
|
|
11
|
+
eventId: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
parentId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
kind: InspectKind;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
status?: "running" | "ok" | "error";
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
attributes?: Record<string, unknown>;
|
|
20
|
+
confidence: AttributionConfidence;
|
|
21
|
+
source: EventSource;
|
|
22
|
+
}
|
|
23
|
+
interface InspectNode {
|
|
24
|
+
event: InspectEvent;
|
|
25
|
+
children: InspectNode[];
|
|
26
|
+
depth: number;
|
|
27
|
+
}
|
|
28
|
+
interface InspectRunTree {
|
|
29
|
+
runId: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
status?: "running" | "ok" | "error";
|
|
32
|
+
startedAt?: number;
|
|
33
|
+
endedAt?: number;
|
|
34
|
+
durationMs?: number;
|
|
35
|
+
children: InspectNode[];
|
|
36
|
+
metadata: {
|
|
37
|
+
totalEvents: number;
|
|
38
|
+
confidenceBreakdown: Record<AttributionConfidence, number>;
|
|
39
|
+
kinds: Record<InspectKind, number>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface LogEventMapping {
|
|
44
|
+
kind?: InspectKind;
|
|
45
|
+
name?: string;
|
|
46
|
+
parent?: string;
|
|
47
|
+
status?: "running" | "ok" | "error";
|
|
48
|
+
startsRun?: boolean;
|
|
49
|
+
endsRun?: boolean;
|
|
50
|
+
startsStep?: boolean;
|
|
51
|
+
endsStep?: boolean;
|
|
52
|
+
}
|
|
53
|
+
type RedactionStrategy = "full" | "prefix" | "hash";
|
|
54
|
+
type RedactionRule = string | {
|
|
55
|
+
key: string;
|
|
56
|
+
strategy: RedactionStrategy;
|
|
57
|
+
keep?: number;
|
|
58
|
+
};
|
|
59
|
+
interface LogIngestConfig {
|
|
60
|
+
runIdKeys: string[];
|
|
61
|
+
eventKey: string;
|
|
62
|
+
timestampKey?: string;
|
|
63
|
+
messageKey?: string;
|
|
64
|
+
levelKey?: string;
|
|
65
|
+
parentIdKey?: string;
|
|
66
|
+
durationKey?: string;
|
|
67
|
+
statusKey?: string;
|
|
68
|
+
mappings?: Record<string, LogEventMapping>;
|
|
69
|
+
redact?: RedactionRule[];
|
|
70
|
+
heuristicWindowMs?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
3
73
|
/**
|
|
4
74
|
* Discriminator for what kind of work a {@link Step} represents.
|
|
5
75
|
* `"decision"` captures agent branching/choices; other values cover runs, LLM calls, tools, and user-defined steps.
|
|
@@ -160,6 +230,19 @@ interface InspectRunOptions {
|
|
|
160
230
|
* Omitted or `true` preserves default tracing behavior.
|
|
161
231
|
*/
|
|
162
232
|
enabled?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Redact sensitive metadata keys before writing JSONL. Default `true` (conservative keys).
|
|
235
|
+
* Pass `false` to persist metadata as-is (explicit opt-out).
|
|
236
|
+
*/
|
|
237
|
+
redact?: boolean | {
|
|
238
|
+
rules?: RedactionRule[];
|
|
239
|
+
};
|
|
240
|
+
/** Max UTF-8 bytes for a serialized trace event line. Default 65536. */
|
|
241
|
+
maxEventBytes?: number;
|
|
242
|
+
/** Max length for string metadata values (non-preview keys). Default 2000. */
|
|
243
|
+
maxMetadataValueLength?: number;
|
|
244
|
+
/** Max length for preview-like metadata keys (contains `preview`). Default 500. */
|
|
245
|
+
maxPreviewLength?: number;
|
|
163
246
|
}
|
|
164
247
|
/** Options passed when opening a logical step (implemented in a later step). */
|
|
165
248
|
interface StepOptions {
|
|
@@ -195,76 +278,6 @@ declare function isStepStatus(value: unknown): value is StepStatus;
|
|
|
195
278
|
*/
|
|
196
279
|
declare function isTraceEvent(value: unknown): value is TraceEvent;
|
|
197
280
|
|
|
198
|
-
type AttributionConfidence = "explicit" | "correlated" | "heuristic" | "unknown";
|
|
199
|
-
type InspectKind = "RUN" | "AGENT" | "LLM" | "TOOL" | "CHAIN" | "RETRIEVER" | "DECISION" | "RESULT" | "ERROR" | "LOGIC" | "LOG";
|
|
200
|
-
interface EventSource {
|
|
201
|
-
type: "manual" | "json-log" | "log4js" | "pino" | "winston" | "adapter";
|
|
202
|
-
file?: string;
|
|
203
|
-
line?: number;
|
|
204
|
-
}
|
|
205
|
-
interface InspectEvent {
|
|
206
|
-
eventId: string;
|
|
207
|
-
runId: string;
|
|
208
|
-
parentId?: string;
|
|
209
|
-
name: string;
|
|
210
|
-
kind: InspectKind;
|
|
211
|
-
timestamp: number;
|
|
212
|
-
status?: "running" | "ok" | "error";
|
|
213
|
-
durationMs?: number;
|
|
214
|
-
attributes?: Record<string, unknown>;
|
|
215
|
-
confidence: AttributionConfidence;
|
|
216
|
-
source: EventSource;
|
|
217
|
-
}
|
|
218
|
-
interface InspectNode {
|
|
219
|
-
event: InspectEvent;
|
|
220
|
-
children: InspectNode[];
|
|
221
|
-
depth: number;
|
|
222
|
-
}
|
|
223
|
-
interface InspectRunTree {
|
|
224
|
-
runId: string;
|
|
225
|
-
name?: string;
|
|
226
|
-
status?: "running" | "ok" | "error";
|
|
227
|
-
startedAt?: number;
|
|
228
|
-
endedAt?: number;
|
|
229
|
-
durationMs?: number;
|
|
230
|
-
children: InspectNode[];
|
|
231
|
-
metadata: {
|
|
232
|
-
totalEvents: number;
|
|
233
|
-
confidenceBreakdown: Record<AttributionConfidence, number>;
|
|
234
|
-
kinds: Record<InspectKind, number>;
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
interface LogEventMapping {
|
|
239
|
-
kind?: InspectKind;
|
|
240
|
-
name?: string;
|
|
241
|
-
parent?: string;
|
|
242
|
-
status?: "running" | "ok" | "error";
|
|
243
|
-
startsRun?: boolean;
|
|
244
|
-
endsRun?: boolean;
|
|
245
|
-
startsStep?: boolean;
|
|
246
|
-
endsStep?: boolean;
|
|
247
|
-
}
|
|
248
|
-
type RedactionStrategy = "full" | "prefix" | "hash";
|
|
249
|
-
type RedactionRule = string | {
|
|
250
|
-
key: string;
|
|
251
|
-
strategy: RedactionStrategy;
|
|
252
|
-
keep?: number;
|
|
253
|
-
};
|
|
254
|
-
interface LogIngestConfig {
|
|
255
|
-
runIdKeys: string[];
|
|
256
|
-
eventKey: string;
|
|
257
|
-
timestampKey?: string;
|
|
258
|
-
messageKey?: string;
|
|
259
|
-
levelKey?: string;
|
|
260
|
-
parentIdKey?: string;
|
|
261
|
-
durationKey?: string;
|
|
262
|
-
statusKey?: string;
|
|
263
|
-
mappings?: Record<string, LogEventMapping>;
|
|
264
|
-
redact?: RedactionRule[];
|
|
265
|
-
heuristicWindowMs?: number;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
281
|
type ParserWarningCode = "MALFORMED_JSON" | "MISSING_RUN_ID" | "MISSING_EVENT" | "MISSING_TIMESTAMP" | "UNSUPPORTED_LOG4JS_PAYLOAD" | "CONFIG_ERROR" | "UNKNOWN";
|
|
269
282
|
interface ParserWarning {
|
|
270
283
|
code: ParserWarningCode;
|
|
@@ -447,6 +460,30 @@ declare function truncateName(name: string, maxLength?: number): string;
|
|
|
447
460
|
*/
|
|
448
461
|
declare function warn(message: string, error?: unknown): void;
|
|
449
462
|
|
|
463
|
+
/** Default max length for string metadata values (non-preview keys). */
|
|
464
|
+
declare const DEFAULT_MAX_METADATA_VALUE_LENGTH = 2000;
|
|
465
|
+
/** Default max length for preview-like metadata keys (contains `preview`, case-insensitive). */
|
|
466
|
+
declare const DEFAULT_MAX_PREVIEW_LENGTH = 500;
|
|
467
|
+
/** Default max serialized JSONL line size in bytes (UTF-8). */
|
|
468
|
+
declare const DEFAULT_MAX_EVENT_BYTES = 65536;
|
|
469
|
+
/** Resolved trace safety settings used at write time. */
|
|
470
|
+
interface TraceSafetyOptions {
|
|
471
|
+
redactEnabled: boolean;
|
|
472
|
+
redactionRules?: RedactionRule[];
|
|
473
|
+
maxMetadataValueLength: number;
|
|
474
|
+
maxPreviewLength: number;
|
|
475
|
+
maxEventBytes: number;
|
|
476
|
+
}
|
|
477
|
+
/** Resolves {@link InspectRunOptions} trace safety fields with safe defaults. */
|
|
478
|
+
declare function resolveTraceSafetyOptions(options?: Pick<InspectRunOptions, "redact" | "maxEventBytes" | "maxMetadataValueLength" | "maxPreviewLength">): TraceSafetyOptions;
|
|
479
|
+
/** Redacts (when enabled) and truncates metadata values for disk persistence. */
|
|
480
|
+
declare function prepareMetadataForDisk(metadata: Record<string, unknown> | StepMetadata, opts: TraceSafetyOptions): Record<string, unknown>;
|
|
481
|
+
/**
|
|
482
|
+
* Applies redaction, metadata truncation, and final serialized size bounds.
|
|
483
|
+
* Never throws; returns a schema-valid event or a minimally truncated variant.
|
|
484
|
+
*/
|
|
485
|
+
declare function prepareTraceEventForDisk(event: TraceEvent, opts: TraceSafetyOptions): TraceEvent;
|
|
486
|
+
|
|
450
487
|
/** Returns the active run context, without internal step fields. */
|
|
451
488
|
declare function getCurrentContext(): ExecutionContext | undefined;
|
|
452
489
|
/** Active `runId` when inside `runWithContext`, else `undefined`. */
|
|
@@ -468,11 +505,13 @@ declare function getCurrentDepth(): number;
|
|
|
468
505
|
declare function hasActiveContext(): boolean;
|
|
469
506
|
declare function getTraceDirFromContext(): string | undefined;
|
|
470
507
|
declare function isSilentContext(): boolean;
|
|
508
|
+
/** Resolved trace safety settings for the active run (redaction + size bounds). */
|
|
509
|
+
declare function getTraceSafetyFromContext(): TraceSafetyOptions | undefined;
|
|
471
510
|
/**
|
|
472
511
|
* Runs `fn` with a fresh AgentInspect run context (depth 0, no active step).
|
|
473
512
|
* Propagates sync/async results and rejections; does not swallow user errors.
|
|
474
513
|
*/
|
|
475
|
-
declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T): Promise<T>;
|
|
514
|
+
declare function runWithContext<T>(context: ExecutionContext, fn: () => Promise<T> | T, traceSafety?: TraceSafetyOptions): Promise<T>;
|
|
476
515
|
/**
|
|
477
516
|
* Runs `fn` with `stepId` as the active step (incremented depth).
|
|
478
517
|
* If no run is active, runs `fn` without altering async context.
|
|
@@ -490,9 +529,6 @@ declare function serializeEvent(event: TraceEvent): string;
|
|
|
490
529
|
* On failure, retries once under {@link FALLBACK_TRACE_DIR}.
|
|
491
530
|
*/
|
|
492
531
|
declare function initializeTraceFile(runId: string, traceDir: string): Promise<string | undefined>;
|
|
493
|
-
/**
|
|
494
|
-
* Appends one validated JSONL line for `event.runId`. Falls back to {@link FALLBACK_TRACE_DIR} on append failure.
|
|
495
|
-
*/
|
|
496
532
|
declare function writeTraceEvent(event: TraceEvent, traceDir: string): Promise<void>;
|
|
497
533
|
/**
|
|
498
534
|
* Reads raw JSONL file contents for a run, or `undefined` if missing or unreadable.
|
|
@@ -794,4 +830,4 @@ declare function mergeExportDefaults(options: ExportOptions): ExportOptions;
|
|
|
794
830
|
declare function exportRunTree(tree: InspectRunTree, options: ExportOptions): ExportResult;
|
|
795
831
|
declare function validateExport(result: ExportResult): ExportValidationResult;
|
|
796
832
|
|
|
797
|
-
export { type ActiveStepContext, type AttributionConfidence, DEFAULT_LOG_INGEST_CONFIG, 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 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, hasActiveContext, initializeTraceFile, inspectRun, isAgentInspectEnabled, isAgentInspectTrace, isSilentContext, isStepStatus, isStepType, isTraceEvent, listTraceFiles, loadLogIngestConfig, manualTraceEventsToComparableRun, manualTraceEventsToRunTree, matchMapping, maybeInspectRun, mergeExportDefaults, mergeLogIngestConfig, observe, parseDuration, parseLogLine, parseLogsToTrees, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderErrorLine, renderRunDiff, renderRunSummary, renderRunTree, renderRunTrees, renderStepLine, resolveTraceDir, runWithContext, runWithStepContext, safeString, serializeEvent, stableJson, step, summarizeTree, truncateName, validateEvent, validateExport, validateExportContent, warn, wildcardMatch, writeTraceEvent };
|
|
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 };
|