@agent-inspect/langchain 6.17.8 → 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 CHANGED
@@ -10,8 +10,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
10
  var path__default = /*#__PURE__*/_interopDefault(path);
11
11
 
12
12
  // packages/langchain/src/agent-inspect-callback.ts
13
-
14
- // packages/langchain/src/metadata.ts
15
13
  function isRecord(v) {
16
14
  return typeof v === "object" && v !== null && !Array.isArray(v);
17
15
  }
@@ -91,30 +89,7 @@ function extractModelName(serializedOrOutput) {
91
89
  }
92
90
  }
93
91
  function safePreview(value, maxChars) {
94
- try {
95
- if (maxChars <= 0) return void 0;
96
- const seen = /* @__PURE__ */ new WeakSet();
97
- const json = JSON.stringify(value, (_k, v) => {
98
- if (typeof v === "bigint") return v.toString();
99
- if (typeof v === "function" || typeof v === "symbol") return void 0;
100
- if (typeof v === "object" && v !== null) {
101
- if (seen.has(v)) return "[Circular]";
102
- seen.add(v);
103
- }
104
- return v;
105
- });
106
- if (json === void 0) return void 0;
107
- if (json.length <= maxChars) return json;
108
- return `${json.slice(0, maxChars)}\u2026`;
109
- } catch {
110
- try {
111
- const s = String(value);
112
- if (s.length <= maxChars) return s;
113
- return `${s.slice(0, maxChars)}\u2026`;
114
- } catch {
115
- return void 0;
116
- }
117
- }
92
+ return advanced.serializeAdapterPreview(value, maxChars);
118
93
  }
119
94
  var MAX_METADATA_KEYS = 40;
120
95
  var LANGGRAPH_ALIASES = [
@@ -666,7 +641,8 @@ var LangChainTracePersistence = class {
666
641
  this.#runName = options.runName ?? "langchain-agent";
667
642
  this.#safety = advanced.resolveTraceSafetyOptions({
668
643
  redact: options.redact ? { rules: options.redact } : true,
669
- maxPreviewLength: options.maxPreviewChars
644
+ maxPreviewLength: options.maxPreviewChars,
645
+ ...options.redactionProfile ? { redactionProfile: options.redactionProfile } : {}
670
646
  });
671
647
  this.#lifecycle = createInvocationState(this.#runId);
672
648
  }
@@ -1239,6 +1215,7 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1239
1215
  awaitHandlers = true;
1240
1216
  #opts;
1241
1217
  #redactor;
1218
+ #capture;
1242
1219
  #persistence;
1243
1220
  #events = [];
1244
1221
  #starts = /* @__PURE__ */ new Map();
@@ -1257,6 +1234,13 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1257
1234
  persist: intent.persist
1258
1235
  };
1259
1236
  this.#redactor = new logs.Redactor({ rules: this.#opts.redact });
1237
+ this.#capture = advanced.createAdapterPreviewCapture({
1238
+ capture: this.#opts.capture === "preview" ? "preview" : "metadata-only",
1239
+ redactionProfile: this.#opts.redactionProfile,
1240
+ maxPreviewChars: this.#opts.maxPreviewChars,
1241
+ redact: this.#opts.redact,
1242
+ onDiagnostic: this.#opts.onDiagnostic
1243
+ });
1260
1244
  if (intent.contradictory && !this.#opts.silent) {
1261
1245
  console.error(
1262
1246
  "[agent-inspect:langchain] persist:false with traceDir set \u2014 traces stay in-memory; remove traceDir or set persist:true"
@@ -1269,7 +1253,8 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1269
1253
  runId: this.#opts.runId,
1270
1254
  redact: this.#opts.redact,
1271
1255
  silent: this.#opts.silent,
1272
- maxPreviewChars: this.#opts.maxPreviewChars
1256
+ maxPreviewChars: this.#capture.maxPreviewChars,
1257
+ redactionProfile: this.#opts.redactionProfile
1273
1258
  });
1274
1259
  }
1275
1260
  }
@@ -1312,7 +1297,8 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1312
1297
  return {
1313
1298
  ...base,
1314
1299
  inMemoryEventCount: this.#events.length,
1315
- deferredPersistStartCount: this.#deferredPersistStart.size
1300
+ deferredPersistStartCount: this.#deferredPersistStart.size,
1301
+ capture: this.#capture.getDiagnostics()
1316
1302
  };
1317
1303
  }
1318
1304
  /**
@@ -1376,8 +1362,8 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1376
1362
  persistence.beginNewInvocation();
1377
1363
  }
1378
1364
  #streamPreviewLimit() {
1379
- if (this.#opts.capture !== "preview") return 0;
1380
- return this.#opts.maxStreamPreviewChars ?? this.#opts.maxPreviewChars ?? 200;
1365
+ if (!this.#capture.previewEnabled) return 0;
1366
+ return this.#opts.maxStreamPreviewChars ?? this.#capture.maxPreviewChars;
1381
1367
  }
1382
1368
  #attachStreamMetadata(attrs, lcRunId) {
1383
1369
  const meta = streamMetadataFromState(this.#streamState.get(lcRunId), {
@@ -1485,12 +1471,7 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
1485
1471
  if (langGraph) attrs.langGraph = this.#redactor.redactRecord(langGraph);
1486
1472
  }
1487
1473
  #applyPreview(attrs, previews) {
1488
- if (this.#opts.capture !== "preview") return;
1489
- const max = this.#opts.maxPreviewChars;
1490
- for (const [k, v] of Object.entries(previews)) {
1491
- const p = safePreview(v, max);
1492
- if (p !== void 0) attrs[k] = p;
1493
- }
1474
+ this.#capture.applyPreviewFields(attrs, previews);
1494
1475
  }
1495
1476
  #pushEvent(ev) {
1496
1477
  try {