@agent-inspect/langchain 6.17.7 → 6.18.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/dist/index.cjs +18 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.mjs +19 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -32,6 +32,42 @@ type RedactionRule = string | {
|
|
|
32
32
|
keep?: number;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/** Named redaction presets for trace writing and share-safe exports (v1.3.0+). */
|
|
36
|
+
type RedactionProfile = "local" | "share" | "strict";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Capture policy shared by the official adapters.
|
|
40
|
+
*
|
|
41
|
+
* `metadata-only` is the default everywhere and never persists framework
|
|
42
|
+
* payload content. `preview` opts into bounded, redacted previews.
|
|
43
|
+
*/
|
|
44
|
+
type AdapterCaptureMode = "metadata-only" | "preview";
|
|
45
|
+
/** Stable diagnostic codes emitted by shared preview capture. */
|
|
46
|
+
declare const ADAPTER_CAPTURE_DIAGNOSTIC_CODES: readonly ["AI_CAPTURE_FIELD_UNAVAILABLE", "AI_CAPTURE_PREVIEW_TRUNCATED", "AI_CAPTURE_PREVIEW_REDACTED"];
|
|
47
|
+
type AdapterCaptureDiagnosticCode = (typeof ADAPTER_CAPTURE_DIAGNOSTIC_CODES)[number];
|
|
48
|
+
/** One bounded diagnostic. Never contains preview content or filesystem paths. */
|
|
49
|
+
interface AdapterCaptureDiagnostic {
|
|
50
|
+
readonly code: AdapterCaptureDiagnosticCode;
|
|
51
|
+
readonly message: string;
|
|
52
|
+
/** Persisted attribute name the diagnostic refers to (e.g. `inputPreview`). */
|
|
53
|
+
readonly field: string;
|
|
54
|
+
readonly capture: AdapterCaptureMode;
|
|
55
|
+
}
|
|
56
|
+
/** Optional consumer hook for adapter capture diagnostics. */
|
|
57
|
+
type AdapterDiagnosticListener = (diagnostic: AdapterCaptureDiagnostic) => void;
|
|
58
|
+
/** Bounded capture counters for adapter `getDiagnostics()` surfaces. */
|
|
59
|
+
interface AdapterCaptureDiagnostics {
|
|
60
|
+
readonly capture: AdapterCaptureMode;
|
|
61
|
+
readonly redactionProfile: RedactionProfile;
|
|
62
|
+
readonly maxPreviewChars: number;
|
|
63
|
+
readonly previewFieldsCaptured: number;
|
|
64
|
+
readonly previewFieldsUnavailable: number;
|
|
65
|
+
readonly previewFieldsTruncated: number;
|
|
66
|
+
readonly previewFieldsRedacted: number;
|
|
67
|
+
readonly lastDiagnosticCode?: AdapterCaptureDiagnosticCode;
|
|
68
|
+
readonly lastDiagnosticMessage?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
35
71
|
type CaptureMode = "none" | "metadata-only" | "preview";
|
|
36
72
|
interface LangChainStreamingOptions {
|
|
37
73
|
/**
|
|
@@ -53,6 +89,20 @@ interface AgentInspectCallbackOptions extends LangChainStreamingOptions {
|
|
|
53
89
|
capture?: CaptureMode;
|
|
54
90
|
redact?: RedactionRule[];
|
|
55
91
|
maxPreviewChars?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Redaction profile applied to preview attributes before persistence.
|
|
94
|
+
* `share` and `strict` also cap `maxPreviewChars`.
|
|
95
|
+
*
|
|
96
|
+
* @experimental Effective only when `capture: "preview"`.
|
|
97
|
+
*/
|
|
98
|
+
redactionProfile?: RedactionProfile;
|
|
99
|
+
/**
|
|
100
|
+
* Receives bounded capture diagnostics such as
|
|
101
|
+
* `AI_CAPTURE_FIELD_UNAVAILABLE`. Listener failures are isolated.
|
|
102
|
+
*
|
|
103
|
+
* @experimental
|
|
104
|
+
*/
|
|
105
|
+
onDiagnostic?: AdapterDiagnosticListener;
|
|
56
106
|
/**
|
|
57
107
|
* Persist callback lifecycle as schemaVersion "0.1" JSONL.
|
|
58
108
|
* When omitted: enabled if `traceDir` is set, otherwise in-memory only.
|
|
@@ -106,6 +156,7 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
106
156
|
hasTerminalError: boolean;
|
|
107
157
|
inMemoryEventCount: number;
|
|
108
158
|
deferredPersistStartCount: number;
|
|
159
|
+
capture: AdapterCaptureDiagnostics;
|
|
109
160
|
};
|
|
110
161
|
/**
|
|
111
162
|
* Drain deferred completion work (microtask finalization).
|
|
@@ -189,7 +240,12 @@ interface TokenUsage {
|
|
|
189
240
|
declare function extractTokenUsage(output: unknown): TokenUsage | undefined;
|
|
190
241
|
/** Best-effort model name from serialized LLM / chat model or provider metadata. */
|
|
191
242
|
declare function extractModelName(serializedOrOutput: unknown): string | undefined;
|
|
192
|
-
/**
|
|
243
|
+
/**
|
|
244
|
+
* Safe truncated string preview for logging-style fields.
|
|
245
|
+
*
|
|
246
|
+
* Delegates to the shared adapter preview serializer so every official adapter
|
|
247
|
+
* bounds and escapes preview values identically.
|
|
248
|
+
*/
|
|
193
249
|
declare function safePreview(value: unknown, maxChars: number): string | undefined;
|
|
194
250
|
/** Shallow plain metadata: drops functions/symbols; avoids deep nesting. Never throws. */
|
|
195
251
|
declare function toPlainMetadata(value: unknown): Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,42 @@ type RedactionRule = string | {
|
|
|
32
32
|
keep?: number;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/** Named redaction presets for trace writing and share-safe exports (v1.3.0+). */
|
|
36
|
+
type RedactionProfile = "local" | "share" | "strict";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Capture policy shared by the official adapters.
|
|
40
|
+
*
|
|
41
|
+
* `metadata-only` is the default everywhere and never persists framework
|
|
42
|
+
* payload content. `preview` opts into bounded, redacted previews.
|
|
43
|
+
*/
|
|
44
|
+
type AdapterCaptureMode = "metadata-only" | "preview";
|
|
45
|
+
/** Stable diagnostic codes emitted by shared preview capture. */
|
|
46
|
+
declare const ADAPTER_CAPTURE_DIAGNOSTIC_CODES: readonly ["AI_CAPTURE_FIELD_UNAVAILABLE", "AI_CAPTURE_PREVIEW_TRUNCATED", "AI_CAPTURE_PREVIEW_REDACTED"];
|
|
47
|
+
type AdapterCaptureDiagnosticCode = (typeof ADAPTER_CAPTURE_DIAGNOSTIC_CODES)[number];
|
|
48
|
+
/** One bounded diagnostic. Never contains preview content or filesystem paths. */
|
|
49
|
+
interface AdapterCaptureDiagnostic {
|
|
50
|
+
readonly code: AdapterCaptureDiagnosticCode;
|
|
51
|
+
readonly message: string;
|
|
52
|
+
/** Persisted attribute name the diagnostic refers to (e.g. `inputPreview`). */
|
|
53
|
+
readonly field: string;
|
|
54
|
+
readonly capture: AdapterCaptureMode;
|
|
55
|
+
}
|
|
56
|
+
/** Optional consumer hook for adapter capture diagnostics. */
|
|
57
|
+
type AdapterDiagnosticListener = (diagnostic: AdapterCaptureDiagnostic) => void;
|
|
58
|
+
/** Bounded capture counters for adapter `getDiagnostics()` surfaces. */
|
|
59
|
+
interface AdapterCaptureDiagnostics {
|
|
60
|
+
readonly capture: AdapterCaptureMode;
|
|
61
|
+
readonly redactionProfile: RedactionProfile;
|
|
62
|
+
readonly maxPreviewChars: number;
|
|
63
|
+
readonly previewFieldsCaptured: number;
|
|
64
|
+
readonly previewFieldsUnavailable: number;
|
|
65
|
+
readonly previewFieldsTruncated: number;
|
|
66
|
+
readonly previewFieldsRedacted: number;
|
|
67
|
+
readonly lastDiagnosticCode?: AdapterCaptureDiagnosticCode;
|
|
68
|
+
readonly lastDiagnosticMessage?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
35
71
|
type CaptureMode = "none" | "metadata-only" | "preview";
|
|
36
72
|
interface LangChainStreamingOptions {
|
|
37
73
|
/**
|
|
@@ -53,6 +89,20 @@ interface AgentInspectCallbackOptions extends LangChainStreamingOptions {
|
|
|
53
89
|
capture?: CaptureMode;
|
|
54
90
|
redact?: RedactionRule[];
|
|
55
91
|
maxPreviewChars?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Redaction profile applied to preview attributes before persistence.
|
|
94
|
+
* `share` and `strict` also cap `maxPreviewChars`.
|
|
95
|
+
*
|
|
96
|
+
* @experimental Effective only when `capture: "preview"`.
|
|
97
|
+
*/
|
|
98
|
+
redactionProfile?: RedactionProfile;
|
|
99
|
+
/**
|
|
100
|
+
* Receives bounded capture diagnostics such as
|
|
101
|
+
* `AI_CAPTURE_FIELD_UNAVAILABLE`. Listener failures are isolated.
|
|
102
|
+
*
|
|
103
|
+
* @experimental
|
|
104
|
+
*/
|
|
105
|
+
onDiagnostic?: AdapterDiagnosticListener;
|
|
56
106
|
/**
|
|
57
107
|
* Persist callback lifecycle as schemaVersion "0.1" JSONL.
|
|
58
108
|
* When omitted: enabled if `traceDir` is set, otherwise in-memory only.
|
|
@@ -106,6 +156,7 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
106
156
|
hasTerminalError: boolean;
|
|
107
157
|
inMemoryEventCount: number;
|
|
108
158
|
deferredPersistStartCount: number;
|
|
159
|
+
capture: AdapterCaptureDiagnostics;
|
|
109
160
|
};
|
|
110
161
|
/**
|
|
111
162
|
* Drain deferred completion work (microtask finalization).
|
|
@@ -189,7 +240,12 @@ interface TokenUsage {
|
|
|
189
240
|
declare function extractTokenUsage(output: unknown): TokenUsage | undefined;
|
|
190
241
|
/** Best-effort model name from serialized LLM / chat model or provider metadata. */
|
|
191
242
|
declare function extractModelName(serializedOrOutput: unknown): string | undefined;
|
|
192
|
-
/**
|
|
243
|
+
/**
|
|
244
|
+
* Safe truncated string preview for logging-style fields.
|
|
245
|
+
*
|
|
246
|
+
* Delegates to the shared adapter preview serializer so every official adapter
|
|
247
|
+
* bounds and escapes preview values identically.
|
|
248
|
+
*/
|
|
193
249
|
declare function safePreview(value: unknown, maxChars: number): string | undefined;
|
|
194
250
|
/** Shallow plain metadata: drops functions/symbols; avoids deep nesting. Never throws. */
|
|
195
251
|
declare function toPlainMetadata(value: unknown): Record<string, unknown>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
3
|
-
import { getCurrentCorrelationMetadata, hasActiveContext, getTraceDirFromContext, resolveTraceDir, getCurrentRunId, createRunId, resolveTraceSafetyOptions, createStepId, initializeTraceFile, prepareTraceEventForDisk, writeTraceEvent } from 'agent-inspect/advanced';
|
|
3
|
+
import { serializeAdapterPreview, createAdapterPreviewCapture, getCurrentCorrelationMetadata, hasActiveContext, getTraceDirFromContext, resolveTraceDir, getCurrentRunId, createRunId, resolveTraceSafetyOptions, createStepId, initializeTraceFile, prepareTraceEventForDisk, writeTraceEvent } from 'agent-inspect/advanced';
|
|
4
4
|
import { Redactor } from 'agent-inspect/logs';
|
|
5
5
|
|
|
6
6
|
// packages/langchain/src/agent-inspect-callback.ts
|
|
7
|
-
|
|
8
|
-
// packages/langchain/src/metadata.ts
|
|
9
7
|
function isRecord(v) {
|
|
10
8
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
11
9
|
}
|
|
@@ -85,30 +83,7 @@ function extractModelName(serializedOrOutput) {
|
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
function safePreview(value, maxChars) {
|
|
88
|
-
|
|
89
|
-
if (maxChars <= 0) return void 0;
|
|
90
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
91
|
-
const json = JSON.stringify(value, (_k, v) => {
|
|
92
|
-
if (typeof v === "bigint") return v.toString();
|
|
93
|
-
if (typeof v === "function" || typeof v === "symbol") return void 0;
|
|
94
|
-
if (typeof v === "object" && v !== null) {
|
|
95
|
-
if (seen.has(v)) return "[Circular]";
|
|
96
|
-
seen.add(v);
|
|
97
|
-
}
|
|
98
|
-
return v;
|
|
99
|
-
});
|
|
100
|
-
if (json === void 0) return void 0;
|
|
101
|
-
if (json.length <= maxChars) return json;
|
|
102
|
-
return `${json.slice(0, maxChars)}\u2026`;
|
|
103
|
-
} catch {
|
|
104
|
-
try {
|
|
105
|
-
const s = String(value);
|
|
106
|
-
if (s.length <= maxChars) return s;
|
|
107
|
-
return `${s.slice(0, maxChars)}\u2026`;
|
|
108
|
-
} catch {
|
|
109
|
-
return void 0;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
86
|
+
return serializeAdapterPreview(value, maxChars);
|
|
112
87
|
}
|
|
113
88
|
var MAX_METADATA_KEYS = 40;
|
|
114
89
|
var LANGGRAPH_ALIASES = [
|
|
@@ -660,7 +635,8 @@ var LangChainTracePersistence = class {
|
|
|
660
635
|
this.#runName = options.runName ?? "langchain-agent";
|
|
661
636
|
this.#safety = resolveTraceSafetyOptions({
|
|
662
637
|
redact: options.redact ? { rules: options.redact } : true,
|
|
663
|
-
maxPreviewLength: options.maxPreviewChars
|
|
638
|
+
maxPreviewLength: options.maxPreviewChars,
|
|
639
|
+
...options.redactionProfile ? { redactionProfile: options.redactionProfile } : {}
|
|
664
640
|
});
|
|
665
641
|
this.#lifecycle = createInvocationState(this.#runId);
|
|
666
642
|
}
|
|
@@ -1233,6 +1209,7 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1233
1209
|
awaitHandlers = true;
|
|
1234
1210
|
#opts;
|
|
1235
1211
|
#redactor;
|
|
1212
|
+
#capture;
|
|
1236
1213
|
#persistence;
|
|
1237
1214
|
#events = [];
|
|
1238
1215
|
#starts = /* @__PURE__ */ new Map();
|
|
@@ -1251,6 +1228,13 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1251
1228
|
persist: intent.persist
|
|
1252
1229
|
};
|
|
1253
1230
|
this.#redactor = new Redactor({ rules: this.#opts.redact });
|
|
1231
|
+
this.#capture = createAdapterPreviewCapture({
|
|
1232
|
+
capture: this.#opts.capture === "preview" ? "preview" : "metadata-only",
|
|
1233
|
+
redactionProfile: this.#opts.redactionProfile,
|
|
1234
|
+
maxPreviewChars: this.#opts.maxPreviewChars,
|
|
1235
|
+
redact: this.#opts.redact,
|
|
1236
|
+
onDiagnostic: this.#opts.onDiagnostic
|
|
1237
|
+
});
|
|
1254
1238
|
if (intent.contradictory && !this.#opts.silent) {
|
|
1255
1239
|
console.error(
|
|
1256
1240
|
"[agent-inspect:langchain] persist:false with traceDir set \u2014 traces stay in-memory; remove traceDir or set persist:true"
|
|
@@ -1263,7 +1247,8 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1263
1247
|
runId: this.#opts.runId,
|
|
1264
1248
|
redact: this.#opts.redact,
|
|
1265
1249
|
silent: this.#opts.silent,
|
|
1266
|
-
maxPreviewChars: this.#
|
|
1250
|
+
maxPreviewChars: this.#capture.maxPreviewChars,
|
|
1251
|
+
redactionProfile: this.#opts.redactionProfile
|
|
1267
1252
|
});
|
|
1268
1253
|
}
|
|
1269
1254
|
}
|
|
@@ -1306,7 +1291,8 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1306
1291
|
return {
|
|
1307
1292
|
...base,
|
|
1308
1293
|
inMemoryEventCount: this.#events.length,
|
|
1309
|
-
deferredPersistStartCount: this.#deferredPersistStart.size
|
|
1294
|
+
deferredPersistStartCount: this.#deferredPersistStart.size,
|
|
1295
|
+
capture: this.#capture.getDiagnostics()
|
|
1310
1296
|
};
|
|
1311
1297
|
}
|
|
1312
1298
|
/**
|
|
@@ -1370,8 +1356,8 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1370
1356
|
persistence.beginNewInvocation();
|
|
1371
1357
|
}
|
|
1372
1358
|
#streamPreviewLimit() {
|
|
1373
|
-
if (this.#
|
|
1374
|
-
return this.#opts.maxStreamPreviewChars ?? this.#
|
|
1359
|
+
if (!this.#capture.previewEnabled) return 0;
|
|
1360
|
+
return this.#opts.maxStreamPreviewChars ?? this.#capture.maxPreviewChars;
|
|
1375
1361
|
}
|
|
1376
1362
|
#attachStreamMetadata(attrs, lcRunId) {
|
|
1377
1363
|
const meta = streamMetadataFromState(this.#streamState.get(lcRunId), {
|
|
@@ -1479,12 +1465,7 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1479
1465
|
if (langGraph) attrs.langGraph = this.#redactor.redactRecord(langGraph);
|
|
1480
1466
|
}
|
|
1481
1467
|
#applyPreview(attrs, previews) {
|
|
1482
|
-
|
|
1483
|
-
const max = this.#opts.maxPreviewChars;
|
|
1484
|
-
for (const [k, v] of Object.entries(previews)) {
|
|
1485
|
-
const p = safePreview(v, max);
|
|
1486
|
-
if (p !== void 0) attrs[k] = p;
|
|
1487
|
-
}
|
|
1468
|
+
this.#capture.applyPreviewFields(attrs, previews);
|
|
1488
1469
|
}
|
|
1489
1470
|
#pushEvent(ev) {
|
|
1490
1471
|
try {
|