@agent-inspect/langchain 1.0.3

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.mjs ADDED
@@ -0,0 +1,617 @@
1
+ import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
2
+ import { Redactor } from 'agent-inspect';
3
+
4
+ // packages/langchain/src/agent-inspect-callback.ts
5
+
6
+ // packages/langchain/src/metadata.ts
7
+ function isRecord(v) {
8
+ return typeof v === "object" && v !== null && !Array.isArray(v);
9
+ }
10
+ function num(v) {
11
+ if (typeof v === "number" && Number.isFinite(v)) return v;
12
+ if (typeof v === "string" && v.trim() !== "") {
13
+ const n = Number(v);
14
+ if (Number.isFinite(n)) return n;
15
+ }
16
+ return void 0;
17
+ }
18
+ function normalizeTokenShape(raw) {
19
+ const input = num(raw.promptTokens) ?? num(raw.inputTokens) ?? num(raw.input_tokens) ?? num(raw.prompt_tokens);
20
+ const output = num(raw.completionTokens) ?? num(raw.outputTokens) ?? num(raw.output_tokens) ?? num(raw.completion_tokens);
21
+ let total = num(raw.totalTokens) ?? num(raw.total_tokens);
22
+ if (total === void 0 && input !== void 0 && output !== void 0) {
23
+ total = input + output;
24
+ }
25
+ if (input === void 0 && output === void 0 && total === void 0) {
26
+ return void 0;
27
+ }
28
+ const out = {};
29
+ if (input !== void 0) out.input = input;
30
+ if (output !== void 0) out.output = output;
31
+ if (total !== void 0) out.total = total;
32
+ return out;
33
+ }
34
+ function extractTokenUsage(output) {
35
+ try {
36
+ if (!isRecord(output)) return void 0;
37
+ const candidates = [
38
+ isRecord(output.llmOutput) ? output.llmOutput.tokenUsage : void 0,
39
+ isRecord(output.llmOutput) ? output.llmOutput.estimatedTokenUsage : void 0,
40
+ output.usage_metadata,
41
+ isRecord(output.response_metadata) ? output.response_metadata.tokenUsage : void 0,
42
+ isRecord(output.response_metadata) ? output.response_metadata.token_usage : void 0
43
+ ];
44
+ for (const c of candidates) {
45
+ if (!isRecord(c)) continue;
46
+ const norm = normalizeTokenShape(c);
47
+ if (norm) return norm;
48
+ }
49
+ return void 0;
50
+ } catch {
51
+ return void 0;
52
+ }
53
+ }
54
+ function readLcKwargs(serializedOrOutput) {
55
+ if (!isRecord(serializedOrOutput)) return void 0;
56
+ const lc = serializedOrOutput.lc_kwargs ?? serializedOrOutput.kwargs;
57
+ return isRecord(lc) ? lc : void 0;
58
+ }
59
+ function extractModelName(serializedOrOutput) {
60
+ try {
61
+ const lc = readLcKwargs(serializedOrOutput);
62
+ const fromLc = lc?.model ?? lc?.modelName ?? lc?.model_name;
63
+ if (typeof fromLc === "string" && fromLc.trim()) return fromLc;
64
+ if (isRecord(serializedOrOutput)) {
65
+ for (const k of ["model", "modelName", "model_name"]) {
66
+ const v = serializedOrOutput[k];
67
+ if (typeof v === "string" && v.trim()) return v;
68
+ }
69
+ const rm = serializedOrOutput.response_metadata;
70
+ if (isRecord(rm)) {
71
+ const m = rm.model_name ?? rm.model;
72
+ if (typeof m === "string" && m.trim()) return m;
73
+ }
74
+ const lo = serializedOrOutput.llmOutput;
75
+ if (isRecord(lo)) {
76
+ const m = lo.model_name;
77
+ if (typeof m === "string" && m.trim()) return m;
78
+ }
79
+ }
80
+ return void 0;
81
+ } catch {
82
+ return void 0;
83
+ }
84
+ }
85
+ function safePreview(value, maxChars) {
86
+ try {
87
+ if (maxChars <= 0) return void 0;
88
+ const seen = /* @__PURE__ */ new WeakSet();
89
+ const json = JSON.stringify(value, (_k, v) => {
90
+ if (typeof v === "bigint") return v.toString();
91
+ if (typeof v === "function" || typeof v === "symbol") return void 0;
92
+ if (typeof v === "object" && v !== null) {
93
+ if (seen.has(v)) return "[Circular]";
94
+ seen.add(v);
95
+ }
96
+ return v;
97
+ });
98
+ if (json === void 0) return void 0;
99
+ if (json.length <= maxChars) return json;
100
+ return `${json.slice(0, maxChars)}\u2026`;
101
+ } catch {
102
+ try {
103
+ const s = String(value);
104
+ if (s.length <= maxChars) return s;
105
+ return `${s.slice(0, maxChars)}\u2026`;
106
+ } catch {
107
+ return void 0;
108
+ }
109
+ }
110
+ }
111
+ var MAX_METADATA_KEYS = 40;
112
+ function toPlainMetadata(value) {
113
+ try {
114
+ if (!isRecord(value)) return {};
115
+ const out = {};
116
+ let n = 0;
117
+ for (const [k, v] of Object.entries(value)) {
118
+ if (n >= MAX_METADATA_KEYS) break;
119
+ if (typeof v === "function" || typeof v === "symbol") continue;
120
+ if (v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
121
+ out[k] = v;
122
+ n++;
123
+ continue;
124
+ }
125
+ if (typeof v === "bigint") {
126
+ out[k] = v.toString();
127
+ n++;
128
+ continue;
129
+ }
130
+ if (Array.isArray(v)) {
131
+ out[k] = `array(${v.length})`;
132
+ n++;
133
+ continue;
134
+ }
135
+ if (isRecord(v)) {
136
+ out[k] = "[object]";
137
+ n++;
138
+ continue;
139
+ }
140
+ out[k] = String(v);
141
+ n++;
142
+ }
143
+ return out;
144
+ } catch {
145
+ return {};
146
+ }
147
+ }
148
+
149
+ // packages/langchain/src/agent-inspect-callback.ts
150
+ function serializedLabel(s) {
151
+ if (typeof s.name === "string" && s.name.trim()) return s.name;
152
+ if (Array.isArray(s.id) && s.id.length > 0) return s.id[s.id.length - 1];
153
+ return s.type;
154
+ }
155
+ function errorShape(err) {
156
+ if (err instanceof Error) {
157
+ return { errorName: err.name, errorMessage: err.message };
158
+ }
159
+ return { errorMessage: String(err) };
160
+ }
161
+ var AgentInspectCallback = class extends BaseCallbackHandler {
162
+ name = "agent-inspect";
163
+ #opts;
164
+ #redactor;
165
+ #events = [];
166
+ #starts = /* @__PURE__ */ new Map();
167
+ #rootRunId;
168
+ constructor(options = {}) {
169
+ super({});
170
+ this.#opts = {
171
+ capture: options.capture ?? "metadata-only",
172
+ silent: options.silent ?? false,
173
+ maxPreviewChars: options.maxPreviewChars ?? 200,
174
+ ...options
175
+ };
176
+ this.#redactor = new Redactor({ rules: this.#opts.redact });
177
+ }
178
+ getEvents() {
179
+ return this.#events.map((e) => ({
180
+ ...e,
181
+ attributes: e.attributes ? { ...e.attributes } : void 0,
182
+ source: { ...e.source }
183
+ }));
184
+ }
185
+ clear() {
186
+ this.#events = [];
187
+ this.#starts.clear();
188
+ this.#rootRunId = void 0;
189
+ }
190
+ #ensureRoot(lcRunId, parentRunId) {
191
+ if (parentRunId) return;
192
+ if (!this.#rootRunId) this.#rootRunId = lcRunId;
193
+ }
194
+ #traceRunId(lcRunId) {
195
+ return this.#rootRunId ?? lcRunId;
196
+ }
197
+ #durationFor(lcRunId) {
198
+ const s = this.#starts.get(lcRunId);
199
+ if (!s) return void 0;
200
+ return Date.now() - s.ts;
201
+ }
202
+ #rememberStart(lcRunId, kind) {
203
+ this.#starts.set(lcRunId, { ts: Date.now(), kind });
204
+ }
205
+ #clearStart(lcRunId) {
206
+ this.#starts.delete(lcRunId);
207
+ }
208
+ #baseAttrs(lcRunId, parentRunId, tags, runNameArg) {
209
+ const out = {
210
+ langchainRunId: lcRunId
211
+ };
212
+ if (parentRunId) out.parentRunId = parentRunId;
213
+ if (this.#opts.runName) out.adapterRunName = this.#opts.runName;
214
+ if (runNameArg) out.runName = runNameArg;
215
+ if (this.#opts.traceDir) out.traceDir = this.#opts.traceDir;
216
+ const cap = this.#opts.capture;
217
+ if (cap !== "none" && tags?.length) out.tags = [...tags];
218
+ return out;
219
+ }
220
+ #mergeMetadata(attrs, metadata) {
221
+ if (this.#opts.capture === "none" || !metadata) return;
222
+ attrs.metadata = this.#redactor.redactRecord(toPlainMetadata(metadata));
223
+ }
224
+ #applyPreview(attrs, previews) {
225
+ if (this.#opts.capture !== "preview") return;
226
+ const max = this.#opts.maxPreviewChars;
227
+ for (const [k, v] of Object.entries(previews)) {
228
+ const p = safePreview(v, max);
229
+ if (p !== void 0) attrs[k] = p;
230
+ }
231
+ }
232
+ #pushEvent(ev) {
233
+ try {
234
+ const attributes = ev.attributes ? this.#redactor.redactRecord({ ...ev.attributes }) : void 0;
235
+ this.#events.push({ ...ev, attributes });
236
+ } catch (err) {
237
+ if (!this.#opts.silent) {
238
+ console.error("[agent-inspect:langchain]", err);
239
+ }
240
+ }
241
+ }
242
+ async handleChainStart(chain, inputs, runId, runType, tags, metadata, runName, parentRunId, _extra) {
243
+ this.#ensureRoot(runId, parentRunId);
244
+ this.#rememberStart(runId, "CHAIN");
245
+ const label = serializedLabel(chain) ?? "chain";
246
+ const previews = {};
247
+ if (this.#opts.capture === "preview") previews.inputPreview = inputs;
248
+ const attrs = {
249
+ ...this.#baseAttrs(runId, parentRunId, tags, runName)
250
+ };
251
+ this.#mergeMetadata(attrs, metadata);
252
+ this.#applyPreview(attrs, previews);
253
+ this.#pushEvent({
254
+ eventId: `${runId}:CHAIN:start`,
255
+ runId: this.#traceRunId(runId),
256
+ parentId: parentRunId,
257
+ name: `chain:${runName ?? label}`,
258
+ kind: "CHAIN",
259
+ timestamp: Date.now(),
260
+ status: "running",
261
+ attributes: attrs,
262
+ confidence: "explicit",
263
+ source: { type: "adapter" }
264
+ });
265
+ }
266
+ async handleChainEnd(outputs, runId, parentRunId, tags, _kwargs) {
267
+ this.#ensureRoot(runId, parentRunId);
268
+ const durationMs = this.#durationFor(runId);
269
+ this.#clearStart(runId);
270
+ const previews = {};
271
+ if (this.#opts.capture === "preview") previews.outputPreview = outputs;
272
+ const attrs = {
273
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0)
274
+ };
275
+ this.#applyPreview(attrs, previews);
276
+ this.#pushEvent({
277
+ eventId: `${runId}:CHAIN:end`,
278
+ runId: this.#traceRunId(runId),
279
+ parentId: parentRunId,
280
+ name: "chain:end",
281
+ kind: "CHAIN",
282
+ timestamp: Date.now(),
283
+ status: "ok",
284
+ durationMs,
285
+ attributes: attrs,
286
+ confidence: "explicit",
287
+ source: { type: "adapter" }
288
+ });
289
+ }
290
+ async handleChainError(err, runId, parentRunId, tags, _kwargs) {
291
+ this.#ensureRoot(runId, parentRunId);
292
+ const durationMs = this.#durationFor(runId);
293
+ this.#clearStart(runId);
294
+ const { errorName, errorMessage } = errorShape(err);
295
+ const attrs = {
296
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
297
+ errorName,
298
+ errorMessage
299
+ };
300
+ this.#pushEvent({
301
+ eventId: `${runId}:CHAIN:error`,
302
+ runId: this.#traceRunId(runId),
303
+ parentId: parentRunId,
304
+ name: "chain:error",
305
+ kind: "CHAIN",
306
+ timestamp: Date.now(),
307
+ status: "error",
308
+ durationMs,
309
+ attributes: attrs,
310
+ confidence: "explicit",
311
+ source: { type: "adapter" }
312
+ });
313
+ }
314
+ async handleLLMStart(llm, prompts, runId, parentRunId, _extraParams, tags, metadata, runName) {
315
+ this.#ensureRoot(runId, parentRunId);
316
+ this.#rememberStart(runId, "LLM");
317
+ const model = extractModelName(llm);
318
+ const previews = {};
319
+ if (this.#opts.capture === "preview") {
320
+ previews.promptPreview = prompts.length === 1 ? prompts[0] : prompts;
321
+ }
322
+ const attrs = {
323
+ ...this.#baseAttrs(runId, parentRunId, tags, runName)
324
+ };
325
+ if (model && this.#opts.capture !== "none") attrs.model = model;
326
+ this.#mergeMetadata(attrs, metadata);
327
+ this.#applyPreview(attrs, previews);
328
+ this.#pushEvent({
329
+ eventId: `${runId}:LLM:start`,
330
+ runId: this.#traceRunId(runId),
331
+ parentId: parentRunId,
332
+ name: `llm:${model ?? "llm"}`,
333
+ kind: "LLM",
334
+ timestamp: Date.now(),
335
+ status: "running",
336
+ attributes: attrs,
337
+ confidence: "explicit",
338
+ source: { type: "adapter" }
339
+ });
340
+ }
341
+ async handleChatModelStart(llm, messages, runId, parentRunId, _extraParams, tags, metadata, runName) {
342
+ this.#ensureRoot(runId, parentRunId);
343
+ this.#rememberStart(runId, "LLM");
344
+ const model = extractModelName(llm);
345
+ const previews = {};
346
+ if (this.#opts.capture === "preview") previews.inputPreview = messages;
347
+ const attrs = {
348
+ ...this.#baseAttrs(runId, parentRunId, tags, runName)
349
+ };
350
+ if (model && this.#opts.capture !== "none") attrs.model = model;
351
+ this.#mergeMetadata(attrs, metadata);
352
+ this.#applyPreview(attrs, previews);
353
+ this.#pushEvent({
354
+ eventId: `${runId}:CHAT:start`,
355
+ runId: this.#traceRunId(runId),
356
+ parentId: parentRunId,
357
+ name: `llm:${model ?? "llm"}`,
358
+ kind: "LLM",
359
+ timestamp: Date.now(),
360
+ status: "running",
361
+ attributes: attrs,
362
+ confidence: "explicit",
363
+ source: { type: "adapter" }
364
+ });
365
+ }
366
+ async handleLLMEnd(output, runId, parentRunId, tags, _extraParams) {
367
+ this.#ensureRoot(runId, parentRunId);
368
+ const durationMs = this.#durationFor(runId);
369
+ this.#clearStart(runId);
370
+ const tokens = extractTokenUsage(output);
371
+ const model = extractModelName(output);
372
+ const previews = {};
373
+ if (this.#opts.capture === "preview") previews.outputPreview = output;
374
+ const attrs = {
375
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0)
376
+ };
377
+ if (model && this.#opts.capture !== "none") attrs.model = model;
378
+ if (tokens && this.#opts.capture !== "none") attrs.tokens = tokens;
379
+ this.#applyPreview(attrs, previews);
380
+ this.#pushEvent({
381
+ eventId: `${runId}:LLM:end`,
382
+ runId: this.#traceRunId(runId),
383
+ parentId: parentRunId,
384
+ name: `llm:${model ?? "llm"}`,
385
+ kind: "LLM",
386
+ timestamp: Date.now(),
387
+ status: "ok",
388
+ durationMs,
389
+ attributes: attrs,
390
+ confidence: "explicit",
391
+ source: { type: "adapter" }
392
+ });
393
+ }
394
+ async handleLLMError(err, runId, parentRunId, tags, _extraParams) {
395
+ this.#ensureRoot(runId, parentRunId);
396
+ const durationMs = this.#durationFor(runId);
397
+ this.#clearStart(runId);
398
+ const { errorName, errorMessage } = errorShape(err);
399
+ const attrs = {
400
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
401
+ errorName,
402
+ errorMessage
403
+ };
404
+ this.#pushEvent({
405
+ eventId: `${runId}:LLM:error`,
406
+ runId: this.#traceRunId(runId),
407
+ parentId: parentRunId,
408
+ name: "llm:error",
409
+ kind: "LLM",
410
+ timestamp: Date.now(),
411
+ status: "error",
412
+ durationMs,
413
+ attributes: attrs,
414
+ confidence: "explicit",
415
+ source: { type: "adapter" }
416
+ });
417
+ }
418
+ async handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName, _toolCallId) {
419
+ this.#ensureRoot(runId, parentRunId);
420
+ this.#rememberStart(runId, "TOOL");
421
+ const toolName = serializedLabel(tool) ?? "tool";
422
+ const previews = {};
423
+ if (this.#opts.capture === "preview") previews.inputPreview = input;
424
+ const attrs = {
425
+ ...this.#baseAttrs(runId, parentRunId, tags, runName),
426
+ tool: toolName
427
+ };
428
+ this.#mergeMetadata(attrs, metadata);
429
+ this.#applyPreview(attrs, previews);
430
+ this.#pushEvent({
431
+ eventId: `${runId}:TOOL:start`,
432
+ runId: this.#traceRunId(runId),
433
+ parentId: parentRunId,
434
+ name: `tool:${toolName}`,
435
+ kind: "TOOL",
436
+ timestamp: Date.now(),
437
+ status: "running",
438
+ attributes: attrs,
439
+ confidence: "explicit",
440
+ source: { type: "adapter" }
441
+ });
442
+ }
443
+ async handleToolEnd(output, runId, parentRunId, tags) {
444
+ this.#ensureRoot(runId, parentRunId);
445
+ const durationMs = this.#durationFor(runId);
446
+ this.#clearStart(runId);
447
+ const previews = {};
448
+ if (this.#opts.capture === "preview") previews.outputPreview = output;
449
+ const attrs = {
450
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0)
451
+ };
452
+ this.#applyPreview(attrs, previews);
453
+ this.#pushEvent({
454
+ eventId: `${runId}:TOOL:end`,
455
+ runId: this.#traceRunId(runId),
456
+ parentId: parentRunId,
457
+ name: "tool:end",
458
+ kind: "TOOL",
459
+ timestamp: Date.now(),
460
+ status: "ok",
461
+ durationMs,
462
+ attributes: attrs,
463
+ confidence: "explicit",
464
+ source: { type: "adapter" }
465
+ });
466
+ }
467
+ async handleToolError(err, runId, parentRunId, tags) {
468
+ this.#ensureRoot(runId, parentRunId);
469
+ const durationMs = this.#durationFor(runId);
470
+ this.#clearStart(runId);
471
+ const { errorName, errorMessage } = errorShape(err);
472
+ const attrs = {
473
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
474
+ errorName,
475
+ errorMessage
476
+ };
477
+ this.#pushEvent({
478
+ eventId: `${runId}:TOOL:error`,
479
+ runId: this.#traceRunId(runId),
480
+ parentId: parentRunId,
481
+ name: "tool:error",
482
+ kind: "TOOL",
483
+ timestamp: Date.now(),
484
+ status: "error",
485
+ durationMs,
486
+ attributes: attrs,
487
+ confidence: "explicit",
488
+ source: { type: "adapter" }
489
+ });
490
+ }
491
+ async handleRetrieverStart(retriever, _query, runId, parentRunId, tags, metadata, name) {
492
+ this.#ensureRoot(runId, parentRunId);
493
+ this.#rememberStart(runId, "RETRIEVER");
494
+ const rname = name ?? serializedLabel(retriever) ?? "retriever";
495
+ const attrs = {
496
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
497
+ retriever: rname
498
+ };
499
+ this.#mergeMetadata(attrs, metadata);
500
+ this.#pushEvent({
501
+ eventId: `${runId}:RETRIEVER:start`,
502
+ runId: this.#traceRunId(runId),
503
+ parentId: parentRunId,
504
+ name: `retriever:${rname}`,
505
+ kind: "RETRIEVER",
506
+ timestamp: Date.now(),
507
+ status: "running",
508
+ attributes: attrs,
509
+ confidence: "explicit",
510
+ source: { type: "adapter" }
511
+ });
512
+ }
513
+ async handleRetrieverEnd(documents, runId, parentRunId, tags) {
514
+ this.#ensureRoot(runId, parentRunId);
515
+ const durationMs = this.#durationFor(runId);
516
+ this.#clearStart(runId);
517
+ const previews = {};
518
+ if (this.#opts.capture === "preview" && documents.length > 0) {
519
+ previews.documentPreview = documents.slice(0, 3);
520
+ }
521
+ const attrs = {
522
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
523
+ documentCount: documents.length
524
+ };
525
+ this.#applyPreview(attrs, previews);
526
+ this.#pushEvent({
527
+ eventId: `${runId}:RETRIEVER:end`,
528
+ runId: this.#traceRunId(runId),
529
+ parentId: parentRunId,
530
+ name: "retriever:end",
531
+ kind: "RETRIEVER",
532
+ timestamp: Date.now(),
533
+ status: "ok",
534
+ durationMs,
535
+ attributes: attrs,
536
+ confidence: "explicit",
537
+ source: { type: "adapter" }
538
+ });
539
+ }
540
+ async handleRetrieverError(err, runId, parentRunId, tags) {
541
+ this.#ensureRoot(runId, parentRunId);
542
+ const durationMs = this.#durationFor(runId);
543
+ this.#clearStart(runId);
544
+ const { errorName, errorMessage } = errorShape(err);
545
+ const attrs = {
546
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
547
+ errorName,
548
+ errorMessage
549
+ };
550
+ this.#pushEvent({
551
+ eventId: `${runId}:RETRIEVER:error`,
552
+ runId: this.#traceRunId(runId),
553
+ parentId: parentRunId,
554
+ name: "retriever:error",
555
+ kind: "RETRIEVER",
556
+ timestamp: Date.now(),
557
+ status: "error",
558
+ durationMs,
559
+ attributes: attrs,
560
+ confidence: "explicit",
561
+ source: { type: "adapter" }
562
+ });
563
+ }
564
+ async handleAgentAction(action, runId, parentRunId, tags) {
565
+ this.#ensureRoot(runId, parentRunId);
566
+ const attrs = {
567
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0),
568
+ tool: action.tool
569
+ };
570
+ if (this.#opts.capture === "preview") {
571
+ this.#applyPreview(attrs, {
572
+ toolInputPreview: action.toolInput,
573
+ logPreview: action.log
574
+ });
575
+ }
576
+ this.#pushEvent({
577
+ eventId: `${runId}:AGENT:action:${Date.now()}`,
578
+ runId: this.#traceRunId(runId),
579
+ parentId: parentRunId,
580
+ name: "agent:action",
581
+ kind: "DECISION",
582
+ timestamp: Date.now(),
583
+ status: "ok",
584
+ attributes: attrs,
585
+ confidence: "explicit",
586
+ source: { type: "adapter" }
587
+ });
588
+ }
589
+ async handleAgentEnd(finish, runId, parentRunId, tags) {
590
+ this.#ensureRoot(runId, parentRunId);
591
+ const attrs = {
592
+ ...this.#baseAttrs(runId, parentRunId, tags, void 0)
593
+ };
594
+ if (this.#opts.capture === "preview") {
595
+ this.#applyPreview(attrs, {
596
+ outputPreview: finish.returnValues,
597
+ logPreview: finish.log
598
+ });
599
+ }
600
+ this.#pushEvent({
601
+ eventId: `${runId}:AGENT:end:${Date.now()}`,
602
+ runId: this.#traceRunId(runId),
603
+ parentId: parentRunId,
604
+ name: "agent:end",
605
+ kind: "AGENT",
606
+ timestamp: Date.now(),
607
+ status: "ok",
608
+ attributes: attrs,
609
+ confidence: "explicit",
610
+ source: { type: "adapter" }
611
+ });
612
+ }
613
+ };
614
+
615
+ export { AgentInspectCallback, extractModelName, extractTokenUsage, safePreview, toPlainMetadata };
616
+ //# sourceMappingURL=index.mjs.map
617
+ //# sourceMappingURL=index.mjs.map