@agent-inspect/mcp-server 6.31.6 → 6.31.7

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/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { runReadOnlyMcpServer } from './chunk-P72E7RLD.mjs';
1
+ import { runReadOnlyMcpServer } from './chunk-J2LULLKC.mjs';
2
2
  import { readFileSync } from 'fs';
3
3
  import path from 'path';
4
4
  import { fileURLToPath } from 'url';
package/dist/index.cjs CHANGED
@@ -1498,6 +1498,8 @@ function filterTraces(traces, options) {
1498
1498
  }
1499
1499
 
1500
1500
  // packages/core/src/timeline.ts
1501
+ var ROOT_TIMELINE_DEPTH = 0;
1502
+ var MAX_TIMELINE_DEPTH = 1e3;
1501
1503
  function finite(n) {
1502
1504
  return typeof n === "number" && Number.isFinite(n);
1503
1505
  }
@@ -1568,16 +1570,51 @@ function buildRunTimeline(events, options = {}) {
1568
1570
  const computeDepth = (stepId) => {
1569
1571
  const cached = depthCache.get(stepId);
1570
1572
  if (cached !== void 0) return cached;
1571
- const node = steps.get(stepId);
1572
- if (!node) return 0;
1573
- const parent = node.parentId;
1574
- if (typeof parent !== "string" || parent.trim() === "" || !steps.has(parent)) {
1575
- depthCache.set(stepId, 0);
1576
- return 0;
1573
+ const ancestry = [];
1574
+ const ancestryIndexes = /* @__PURE__ */ new Map();
1575
+ let currentStepId = stepId;
1576
+ let resolvedDepth;
1577
+ while (resolvedDepth === void 0) {
1578
+ const cachedDepth = depthCache.get(currentStepId);
1579
+ if (cachedDepth !== void 0) {
1580
+ resolvedDepth = cachedDepth;
1581
+ continue;
1582
+ }
1583
+ const cycleStart = ancestryIndexes.get(currentStepId);
1584
+ if (cycleStart !== void 0) {
1585
+ const cycleStepIds = ancestry.splice(cycleStart);
1586
+ for (const cycleStepId of cycleStepIds) {
1587
+ depthCache.set(cycleStepId, ROOT_TIMELINE_DEPTH);
1588
+ }
1589
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1590
+ continue;
1591
+ }
1592
+ const currentStep = steps.get(currentStepId);
1593
+ if (!currentStep) {
1594
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1595
+ continue;
1596
+ }
1597
+ ancestryIndexes.set(currentStepId, ancestry.length);
1598
+ ancestry.push(currentStepId);
1599
+ const parentId = currentStep.parentId;
1600
+ if (typeof parentId !== "string" || parentId.trim() === "" || !steps.has(parentId)) {
1601
+ ancestry.pop();
1602
+ depthCache.set(currentStepId, ROOT_TIMELINE_DEPTH);
1603
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1604
+ continue;
1605
+ }
1606
+ currentStepId = parentId;
1607
+ }
1608
+ ancestry.reverse();
1609
+ for (const ancestorStepId of ancestry) {
1610
+ resolvedDepth = Math.min(MAX_TIMELINE_DEPTH, resolvedDepth + 1);
1611
+ depthCache.set(ancestorStepId, resolvedDepth);
1612
+ }
1613
+ const resolvedStepDepth = depthCache.get(stepId);
1614
+ if (resolvedStepDepth === void 0) {
1615
+ throw new Error(`Failed to resolve timeline depth for step "${stepId}"`);
1577
1616
  }
1578
- const d = Math.min(1e3, computeDepth(parent) + 1);
1579
- depthCache.set(stepId, d);
1580
- return d;
1617
+ return resolvedStepDepth;
1581
1618
  };
1582
1619
  const entries = [];
1583
1620
  for (const [stepId, s] of steps.entries()) {
@@ -5052,6 +5089,23 @@ function persistedInspectEventToInspectEvent(event) {
5052
5089
  if (event.durationMs !== void 0 && Number.isFinite(event.durationMs) && event.durationMs >= 0) {
5053
5090
  out.durationMs = event.durationMs;
5054
5091
  }
5092
+ if (event.startedAt !== void 0) {
5093
+ const started = parseIsoToMs3(event.startedAt);
5094
+ if (!started.invalidTimestamp) {
5095
+ attrs2.startedAtMs = started.ms;
5096
+ out.timestamp = started.ms;
5097
+ }
5098
+ }
5099
+ if (event.endedAt !== void 0) {
5100
+ const ended = parseIsoToMs3(event.endedAt);
5101
+ if (!ended.invalidTimestamp) {
5102
+ attrs2.endedAtMs = ended.ms;
5103
+ if (out.durationMs === void 0 && typeof attrs2.startedAtMs === "number" && ended.ms >= attrs2.startedAtMs) {
5104
+ out.durationMs = ended.ms - attrs2.startedAtMs;
5105
+ }
5106
+ }
5107
+ }
5108
+ out.attributes = compactAttributes3(attrs2);
5055
5109
  return out;
5056
5110
  }
5057
5111
  function persistedInspectEventsToInspectEvents(events, options) {
@@ -6113,20 +6167,38 @@ function extractOtlpDocument(root) {
6113
6167
  function mapOtlpStatus(status) {
6114
6168
  if (!isRecord10(status)) return void 0;
6115
6169
  const rawCode = status.code;
6116
- if (typeof rawCode !== "string") return void 0;
6117
- switch (rawCode.toUpperCase()) {
6118
- case "STATUS_CODE_OK":
6119
- case "OK":
6120
- return "ok";
6121
- case "STATUS_CODE_ERROR":
6122
- case "ERROR":
6123
- return "error";
6124
- case "STATUS_CODE_UNSET":
6125
- case "UNSET":
6126
- return "unknown";
6127
- default:
6128
- return "unknown";
6170
+ if (typeof rawCode === "number" && Number.isFinite(rawCode)) {
6171
+ switch (rawCode) {
6172
+ case 0:
6173
+ return "unknown";
6174
+ case 1:
6175
+ return "ok";
6176
+ case 2:
6177
+ return "error";
6178
+ default:
6179
+ return "unknown";
6180
+ }
6181
+ }
6182
+ if (typeof rawCode === "string") {
6183
+ const trimmed = rawCode.trim();
6184
+ if (/^\d+$/.test(trimmed)) {
6185
+ return mapOtlpStatus({ code: Number(trimmed) });
6186
+ }
6187
+ switch (trimmed.toUpperCase()) {
6188
+ case "STATUS_CODE_OK":
6189
+ case "OK":
6190
+ return "ok";
6191
+ case "STATUS_CODE_ERROR":
6192
+ case "ERROR":
6193
+ return "error";
6194
+ case "STATUS_CODE_UNSET":
6195
+ case "UNSET":
6196
+ return "unknown";
6197
+ default:
6198
+ return "unknown";
6199
+ }
6129
6200
  }
6201
+ return void 0;
6130
6202
  }
6131
6203
  function readOtlpKind(attributes, pathPrefix) {
6132
6204
  const warnings = [];
@@ -7378,6 +7450,10 @@ function exportOpenInference(tree, options) {
7378
7450
  warnings
7379
7451
  };
7380
7452
  }
7453
+ var OTLP_STATUS_CODE_UNSET = 0;
7454
+ var OTLP_STATUS_CODE_OK = 1;
7455
+ var OTLP_STATUS_CODE_ERROR = 2;
7456
+ var OTLP_SPAN_KIND_INTERNAL = 1;
7381
7457
  function hexFrom2(seed, byteLen) {
7382
7458
  return crypto__default.default.createHash("sha256").update(seed, "utf8").digest("hex").slice(0, byteLen * 2);
7383
7459
  }
@@ -7390,7 +7466,19 @@ function stringAttr2(key, value) {
7390
7466
  return { key, value: { stringValue: value } };
7391
7467
  }
7392
7468
  function intAttr(key, value) {
7393
- return { key, value: { intValue: String(value) } };
7469
+ return { key, value: { intValue: String(Math.trunc(value)) } };
7470
+ }
7471
+ function doubleAttr(key, value) {
7472
+ return { key, value: { doubleValue: value } };
7473
+ }
7474
+ function boolAttr(key, value) {
7475
+ return { key, value: { boolValue: value } };
7476
+ }
7477
+ function numberAttr(key, value) {
7478
+ if (Number.isFinite(value) && !Number.isInteger(value)) {
7479
+ return doubleAttr(key, value);
7480
+ }
7481
+ return intAttr(key, value);
7394
7482
  }
7395
7483
  function genAiOperationName(kind) {
7396
7484
  switch (kind) {
@@ -7404,10 +7492,27 @@ function genAiOperationName(kind) {
7404
7492
  return void 0;
7405
7493
  }
7406
7494
  }
7495
+ function resolveSpanTimes(ev) {
7496
+ const startedAtMs = typeof ev.attributes?.startedAtMs === "number" && Number.isFinite(ev.attributes.startedAtMs) ? ev.attributes.startedAtMs : void 0;
7497
+ const endedAtMs = typeof ev.attributes?.endedAtMs === "number" && Number.isFinite(ev.attributes.endedAtMs) ? ev.attributes.endedAtMs : void 0;
7498
+ const startMs = startedAtMs ?? ev.timestamp;
7499
+ const startNs = String(unixNano2(startMs));
7500
+ if (endedAtMs !== void 0) {
7501
+ return { startNs, endNs: String(unixNano2(endedAtMs)) };
7502
+ }
7503
+ if (ev.durationMs !== void 0 && Number.isFinite(ev.durationMs)) {
7504
+ return {
7505
+ startNs,
7506
+ endNs: String(unixNano2(startMs) + unixNano2(ev.durationMs))
7507
+ };
7508
+ }
7509
+ return { startNs };
7510
+ }
7407
7511
  function exportOtlpJson(tree, options) {
7408
7512
  const warnings = [
7409
7513
  "OTLP JSON export uses OTel GenAI-aligned attributes where applicable; experimental until verified against specific collectors.",
7410
- "Not OTLP gRPC/protobuf \u2014 JSON mapping only. Generated locally; no network upload."
7514
+ "Not OTLP gRPC/protobuf \u2014 JSON mapping only. Generated locally; no network upload.",
7515
+ "Status and span kind use OTLP numeric enums (StatusCode 0/1/2, SpanKind INTERNAL=1)."
7411
7516
  ];
7412
7517
  const traceId = hexFrom2(`trace:${tree.runId}`, 16);
7413
7518
  const includeAttributes = options?.includeAttributes ?? false;
@@ -7419,11 +7524,7 @@ function exportOtlpJson(tree, options) {
7419
7524
  const ev = n.event;
7420
7525
  const spanId = hexFrom2(`${tree.runId}:${ev.eventId}`, 8);
7421
7526
  const parentSpanId = ev.parentId ? hexFrom2(`${tree.runId}:${ev.parentId}`, 8) : void 0;
7422
- const startNs = String(unixNano2(ev.timestamp));
7423
- let endNs;
7424
- if (ev.durationMs !== void 0 && Number.isFinite(ev.durationMs)) {
7425
- endNs = String(unixNano2(ev.timestamp) + unixNano2(ev.durationMs));
7426
- }
7527
+ const { startNs, endNs } = resolveSpanTimes(ev);
7427
7528
  const attrs2 = [
7428
7529
  stringAttr2("agent_inspect.kind", ev.kind),
7429
7530
  stringAttr2("agent_inspect.confidence", ev.confidence),
@@ -7453,29 +7554,28 @@ function exportOtlpJson(tree, options) {
7453
7554
  if (includeAttributes && meta && typeof meta === "object") {
7454
7555
  for (const [k, v] of Object.entries(meta)) {
7455
7556
  if (k === "tokens" || k === "model") continue;
7456
- if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
7457
- attrs2.push(
7458
- stringAttr2(
7459
- `agent_inspect.preview.${k}`,
7460
- typeof v === "string" ? v.slice(0, maxLen) : String(v)
7461
- )
7462
- );
7557
+ if (typeof v === "string") {
7558
+ attrs2.push(stringAttr2(`agent_inspect.preview.${k}`, v.slice(0, maxLen)));
7559
+ } else if (typeof v === "number" && Number.isFinite(v)) {
7560
+ attrs2.push(numberAttr(`agent_inspect.preview.${k}`, v));
7561
+ } else if (typeof v === "boolean") {
7562
+ attrs2.push(boolAttr(`agent_inspect.preview.${k}`, v));
7463
7563
  }
7464
7564
  }
7465
7565
  }
7466
- let statusCode = "STATUS_CODE_UNSET";
7566
+ let statusCode = OTLP_STATUS_CODE_UNSET;
7467
7567
  let statusMessage;
7468
7568
  if (ev.status === "error") {
7469
- statusCode = "STATUS_CODE_ERROR";
7569
+ statusCode = OTLP_STATUS_CODE_ERROR;
7470
7570
  statusMessage = meta && typeof meta.error === "object" && meta.error !== null ? String(meta.error.message ?? "error").slice(0, maxLen) : "error";
7471
7571
  } else if (ev.status === "ok") {
7472
- statusCode = "STATUS_CODE_OK";
7572
+ statusCode = OTLP_STATUS_CODE_OK;
7473
7573
  }
7474
7574
  const spanJson = {
7475
7575
  traceId,
7476
7576
  spanId,
7477
7577
  name: ev.name,
7478
- kind: "SPAN_KIND_INTERNAL",
7578
+ kind: OTLP_SPAN_KIND_INTERNAL,
7479
7579
  startTimeUnixNano: startNs,
7480
7580
  attributes: attrs2,
7481
7581
  status: {