@agent-inspect/langchain 6.7.2 → 6.7.4
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/README.md +11 -1
- package/dist/index.cjs +55 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +55 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,7 +51,17 @@ const handler = new AgentInspectCallback({
|
|
|
51
51
|
|
|
52
52
|
## CLI
|
|
53
53
|
|
|
54
|
-
`
|
|
54
|
+
With `persist: true`, use the same directory configured in `traceDir`:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx agent-inspect list --dir ./.agent-inspect
|
|
58
|
+
npx agent-inspect view <run-id> --dir ./.agent-inspect --summary
|
|
59
|
+
npx agent-inspect report <run-id> --dir ./.agent-inspect
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Persisted traces remain local. Before sharing an export or report, follow the
|
|
63
|
+
[safe trace sharing checklist](https://github.com/rajudandigam/agent-inspect/blob/main/docs/SAFE-TRACE-SHARING.md)
|
|
64
|
+
and review the generated artifact for sensitive metadata.
|
|
55
65
|
|
|
56
66
|
## Docs
|
|
57
67
|
|
package/dist/index.cjs
CHANGED
|
@@ -351,6 +351,11 @@ var LangChainTracePersistence = class {
|
|
|
351
351
|
#runCompleted = false;
|
|
352
352
|
#runStartTime;
|
|
353
353
|
#rootLcRunId;
|
|
354
|
+
/** Live LangChain callback runIds for standalone envelope finalization. */
|
|
355
|
+
#activeLcRunIds = /* @__PURE__ */ new Set();
|
|
356
|
+
#sawError = false;
|
|
357
|
+
#lastErrorMessage;
|
|
358
|
+
#finalizationToken = 0;
|
|
354
359
|
#lcToStepId = /* @__PURE__ */ new Map();
|
|
355
360
|
constructor(options = {}) {
|
|
356
361
|
const inContext = advanced.hasActiveContext();
|
|
@@ -371,10 +376,14 @@ var LangChainTracePersistence = class {
|
|
|
371
376
|
return this.#traceDir;
|
|
372
377
|
}
|
|
373
378
|
reset() {
|
|
379
|
+
this.#finalizationToken += 1;
|
|
374
380
|
this.#runStarted = false;
|
|
375
381
|
this.#runCompleted = false;
|
|
376
382
|
this.#runStartTime = void 0;
|
|
377
383
|
this.#rootLcRunId = void 0;
|
|
384
|
+
this.#activeLcRunIds.clear();
|
|
385
|
+
this.#sawError = false;
|
|
386
|
+
this.#lastErrorMessage = void 0;
|
|
378
387
|
this.#lcToStepId.clear();
|
|
379
388
|
}
|
|
380
389
|
noteRoot(lcRunId, parentRunId) {
|
|
@@ -388,7 +397,9 @@ var LangChainTracePersistence = class {
|
|
|
388
397
|
}
|
|
389
398
|
async onStepStart(params) {
|
|
390
399
|
try {
|
|
400
|
+
this.#finalizationToken += 1;
|
|
391
401
|
this.noteRoot(params.lcRunId, params.lcParentRunId);
|
|
402
|
+
this.#activeLcRunIds.add(params.lcRunId);
|
|
392
403
|
if (this.#standalone && !this.#runStarted) {
|
|
393
404
|
await this.#ensureRunStarted(params.startTime, params.attributes);
|
|
394
405
|
}
|
|
@@ -460,13 +471,12 @@ var LangChainTracePersistence = class {
|
|
|
460
471
|
...params.status === "error" && params.errorMessage ? { error: { message: params.errorMessage } } : {}
|
|
461
472
|
};
|
|
462
473
|
await this.#write(event);
|
|
463
|
-
if (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
params.status,
|
|
467
|
-
params.errorMessage
|
|
468
|
-
);
|
|
474
|
+
if (params.status === "error") {
|
|
475
|
+
this.#sawError = true;
|
|
476
|
+
if (params.errorMessage) this.#lastErrorMessage = params.errorMessage;
|
|
469
477
|
}
|
|
478
|
+
this.#activeLcRunIds.delete(params.lcRunId);
|
|
479
|
+
await this.#scheduleStandaloneFinalization(params.endTime);
|
|
470
480
|
} catch (err) {
|
|
471
481
|
this.#warn(err);
|
|
472
482
|
}
|
|
@@ -474,7 +484,9 @@ var LangChainTracePersistence = class {
|
|
|
474
484
|
/** Point-in-time adapter events (e.g. agent action) — writes start + completed pair. */
|
|
475
485
|
async onInstantStep(params) {
|
|
476
486
|
try {
|
|
487
|
+
this.#finalizationToken += 1;
|
|
477
488
|
this.noteRoot(params.lcRunId, params.lcParentRunId);
|
|
489
|
+
this.#activeLcRunIds.add(params.lcRunId);
|
|
478
490
|
if (this.#standalone && !this.#runStarted) {
|
|
479
491
|
await this.#ensureRunStarted(params.timestamp, params.attributes);
|
|
480
492
|
}
|
|
@@ -511,10 +523,37 @@ var LangChainTracePersistence = class {
|
|
|
511
523
|
...params.status === "error" && params.errorMessage ? { error: { message: params.errorMessage } } : {}
|
|
512
524
|
};
|
|
513
525
|
await this.#write(completed);
|
|
526
|
+
if (params.status === "error") {
|
|
527
|
+
this.#sawError = true;
|
|
528
|
+
if (params.errorMessage) this.#lastErrorMessage = params.errorMessage;
|
|
529
|
+
}
|
|
530
|
+
this.#activeLcRunIds.delete(params.lcRunId);
|
|
531
|
+
await this.#scheduleStandaloneFinalization(params.timestamp);
|
|
514
532
|
} catch (err) {
|
|
515
533
|
this.#warn(err);
|
|
516
534
|
}
|
|
517
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* When the last active LangChain callback ends, yield one microtask so a
|
|
538
|
+
* same-turn sibling start can cancel finalization, then write run_completed
|
|
539
|
+
* before the callback promise settles. Unresolved external parents do not
|
|
540
|
+
* block the envelope.
|
|
541
|
+
*/
|
|
542
|
+
async #scheduleStandaloneFinalization(endTime) {
|
|
543
|
+
if (!this.#standalone || this.#runCompleted || !this.#runStarted) return;
|
|
544
|
+
if (this.#activeLcRunIds.size > 0) return;
|
|
545
|
+
const token = ++this.#finalizationToken;
|
|
546
|
+
await Promise.resolve();
|
|
547
|
+
if (token !== this.#finalizationToken) return;
|
|
548
|
+
if (!this.#standalone || this.#runCompleted || !this.#runStarted) return;
|
|
549
|
+
if (this.#activeLcRunIds.size > 0) return;
|
|
550
|
+
const status = this.#sawError ? "error" : "success";
|
|
551
|
+
await this.#ensureRunCompleted(
|
|
552
|
+
endTime,
|
|
553
|
+
status,
|
|
554
|
+
status === "error" ? this.#lastErrorMessage : void 0
|
|
555
|
+
);
|
|
556
|
+
}
|
|
518
557
|
async #ensureRunStarted(startTime, attrs) {
|
|
519
558
|
if (this.#runStarted) return;
|
|
520
559
|
this.#runStarted = true;
|
|
@@ -575,6 +614,15 @@ function serializedLabel(s) {
|
|
|
575
614
|
if (Array.isArray(s.id) && s.id.length > 0) return s.id[s.id.length - 1];
|
|
576
615
|
return s.type;
|
|
577
616
|
}
|
|
617
|
+
function resolveToolDisplayName(tool, runName, metadata) {
|
|
618
|
+
const fromRun = typeof runName === "string" ? runName.trim() : "";
|
|
619
|
+
if (fromRun) return fromRun;
|
|
620
|
+
const metaName = metadata?.toolName;
|
|
621
|
+
if (typeof metaName === "string" && metaName.trim()) return metaName.trim();
|
|
622
|
+
const metaTool = metadata?.tool;
|
|
623
|
+
if (typeof metaTool === "string" && metaTool.trim()) return metaTool.trim();
|
|
624
|
+
return serializedLabel(tool) ?? "tool";
|
|
625
|
+
}
|
|
578
626
|
function errorShape(err) {
|
|
579
627
|
if (err instanceof Error) {
|
|
580
628
|
return { errorName: err.name, errorMessage: err.message };
|
|
@@ -1019,7 +1067,7 @@ var AgentInspectCallback = class extends base.BaseCallbackHandler {
|
|
|
1019
1067
|
async handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName, _toolCallId) {
|
|
1020
1068
|
this.#ensureRoot(runId, parentRunId);
|
|
1021
1069
|
this.#rememberStart(runId, "TOOL");
|
|
1022
|
-
const toolName =
|
|
1070
|
+
const toolName = resolveToolDisplayName(tool, runName, metadata);
|
|
1023
1071
|
const previews = {};
|
|
1024
1072
|
if (this.#opts.capture === "preview") previews.inputPreview = input;
|
|
1025
1073
|
const attrs = {
|