@agent-inspect/mcp-server 6.31.7 → 6.31.8

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.cjs CHANGED
@@ -5124,8 +5124,13 @@ function persistedInspectEventsToInspectEvents(events, options) {
5124
5124
  }
5125
5125
 
5126
5126
  // packages/core/src/persisted/tree-bridge.ts
5127
+ function logicalToPersisted(event) {
5128
+ const { sourceEventIds: _sourceEventIds, projection: _projection, ...rest } = event;
5129
+ return rest;
5130
+ }
5127
5131
  function persistedInspectEventsToRunTrees(events, options) {
5128
- const inspectEvents = persistedInspectEventsToInspectEvents(events, {
5132
+ const sourceEvents = options?.coalesceLifecycle === true ? projectLogicalEvents(events).logicalEvents.map(logicalToPersisted) : events;
5133
+ const inspectEvents = persistedInspectEventsToInspectEvents(sourceEvents, {
5129
5134
  skipInvalid: options?.skipInvalid
5130
5135
  });
5131
5136
  return new TreeBuilder().build(inspectEvents);
@@ -5819,7 +5824,7 @@ function mapOpenInferenceSpan(span, index, version) {
5819
5824
  const errorMessage = isRecord10(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
5820
5825
  const event = {
5821
5826
  schemaVersion: "0.2",
5822
- eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
5827
+ eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
5823
5828
  runId: typeof rawAttributes["agent_inspect.run_id"] === "string" ? rawAttributes["agent_inspect.run_id"] : traceId,
5824
5829
  kind,
5825
5830
  name,
@@ -5870,12 +5875,16 @@ function mapOpenInferenceEvents(document) {
5870
5875
  const mapped = document.spans.map(
5871
5876
  (span, index) => mapOpenInferenceSpan(span, index, document.version)
5872
5877
  );
5873
- const spanIdToEventId = new Map(
5874
- mapped.map((span) => [span.spanId, span.event.eventId])
5878
+ const spanKeyToEventId = new Map(
5879
+ mapped.map((span) => {
5880
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5881
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
5882
+ })
5875
5883
  );
5876
5884
  for (const span of mapped) {
5877
5885
  if (span.parentSpanId === void 0) continue;
5878
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
5886
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5887
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
5879
5888
  }
5880
5889
  return {
5881
5890
  events: mapped.map((span) => span.event),
@@ -6424,7 +6433,7 @@ function mapOtlpSpan(context) {
6424
6433
  const errorMessage = isRecord10(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
6425
6434
  const event = {
6426
6435
  schemaVersion: "0.2",
6427
- eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
6436
+ eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
6428
6437
  runId: typeof parsedSpanAttributes.attributes["agent_inspect.run_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.run_id"] : traceId,
6429
6438
  kind,
6430
6439
  name: readStringField(span, ["name"]) ?? spanId,
@@ -6473,12 +6482,16 @@ function mapOtlpSpan(context) {
6473
6482
  }
6474
6483
  function mapOtlpEventsToPersisted(document) {
6475
6484
  const mapped = document.spans.map((span) => mapOtlpSpan(span));
6476
- const spanIdToEventId = new Map(
6477
- mapped.map((span) => [span.spanId, span.event.eventId])
6485
+ const spanKeyToEventId = new Map(
6486
+ mapped.map((span) => {
6487
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
6488
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
6489
+ })
6478
6490
  );
6479
6491
  for (const span of mapped) {
6480
6492
  if (span.parentSpanId === void 0) continue;
6481
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
6493
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
6494
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
6482
6495
  }
6483
6496
  return {
6484
6497
  events: mapped.map((span) => span.event),
@@ -7382,11 +7395,13 @@ function exportOpenInference(tree, options) {
7382
7395
  endNs = startNs + unixNano(ev.durationMs);
7383
7396
  }
7384
7397
  const { openInferenceKind } = mapInspectKindToOI(ev.kind, warnings);
7398
+ const meta = ev.attributes;
7399
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
7385
7400
  const attrs2 = {
7386
7401
  "openinference.span.kind": openInferenceKind,
7387
7402
  "agent_inspect.kind": ev.kind,
7388
7403
  "agent_inspect.confidence": ev.confidence,
7389
- "agent_inspect.source.type": ev.source.type,
7404
+ "agent_inspect.source.type": originalSource,
7390
7405
  "agent_inspect.run_id": tree.runId,
7391
7406
  "agent_inspect.event_id": ev.eventId,
7392
7407
  "agent_inspect.status": ev.status ?? "unset"
@@ -7394,9 +7409,9 @@ function exportOpenInference(tree, options) {
7394
7409
  if (ev.durationMs !== void 0) {
7395
7410
  attrs2["agent_inspect.duration_ms"] = ev.durationMs;
7396
7411
  }
7397
- const meta = ev.attributes;
7398
- if (meta?.model !== void 0 && typeof meta.model === "string") {
7399
- attrs2["llm.model_name"] = meta.model;
7412
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
7413
+ if (requestModel !== void 0) {
7414
+ attrs2["llm.model_name"] = requestModel;
7400
7415
  }
7401
7416
  const tokens = meta?.tokens;
7402
7417
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -7406,8 +7421,9 @@ function exportOpenInference(tree, options) {
7406
7421
  if (typeof outp === "number") attrs2["llm.token_count.completion"] = outp;
7407
7422
  }
7408
7423
  if (includeAttributes && meta && typeof meta === "object") {
7424
+ const skipKeys = /* @__PURE__ */ new Set(["tokens", "model", "modelId", "originalSourceType"]);
7409
7425
  for (const [k, v] of Object.entries(meta)) {
7410
- if (k === "tokens" || k === "model") continue;
7426
+ if (skipKeys.has(k)) continue;
7411
7427
  if (v !== void 0 && v !== null && typeof v !== "object") {
7412
7428
  attrs2[`agent_inspect.preview.${k}`] = typeof v === "string" ? v.slice(0, maxLen) : v;
7413
7429
  }
@@ -7525,24 +7541,33 @@ function exportOtlpJson(tree, options) {
7525
7541
  const spanId = hexFrom2(`${tree.runId}:${ev.eventId}`, 8);
7526
7542
  const parentSpanId = ev.parentId ? hexFrom2(`${tree.runId}:${ev.parentId}`, 8) : void 0;
7527
7543
  const { startNs, endNs } = resolveSpanTimes(ev);
7544
+ const meta = ev.attributes;
7545
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
7528
7546
  const attrs2 = [
7529
7547
  stringAttr2("agent_inspect.kind", ev.kind),
7530
7548
  stringAttr2("agent_inspect.confidence", ev.confidence),
7531
- stringAttr2("agent_inspect.source.type", ev.source.type),
7549
+ stringAttr2("agent_inspect.source.type", originalSource),
7532
7550
  stringAttr2("agent_inspect.run_id", tree.runId),
7533
7551
  stringAttr2("agent_inspect.event_id", ev.eventId),
7534
7552
  stringAttr2("agent_inspect.status", ev.status ?? "unset")
7535
7553
  ];
7536
7554
  if (ev.durationMs !== void 0) {
7537
- attrs2.push(intAttr("agent_inspect.duration_ms", ev.durationMs));
7555
+ attrs2.push(numberAttr("agent_inspect.duration_ms", ev.durationMs));
7538
7556
  }
7539
7557
  const op = genAiOperationName(ev.kind);
7540
7558
  if (op !== void 0) {
7541
7559
  attrs2.push(stringAttr2("gen_ai.operation.name", op));
7542
7560
  }
7543
- const meta = ev.attributes;
7544
- if (meta?.model !== void 0 && typeof meta.model === "string") {
7545
- attrs2.push(stringAttr2("gen_ai.request.model", meta.model.slice(0, maxLen)));
7561
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
7562
+ if (requestModel !== void 0) {
7563
+ attrs2.push(stringAttr2("gen_ai.request.model", requestModel.slice(0, maxLen)));
7564
+ }
7565
+ const responseModel = typeof meta?.responseModelId === "string" && meta.responseModelId.trim() !== "" ? meta.responseModelId : typeof meta?.responseModel === "string" && meta.responseModel.trim() !== "" ? meta.responseModel : void 0;
7566
+ if (responseModel !== void 0) {
7567
+ attrs2.push(stringAttr2("gen_ai.response.model", responseModel.slice(0, maxLen)));
7568
+ }
7569
+ if (typeof meta?.provider === "string" && meta.provider.trim() !== "") {
7570
+ attrs2.push(stringAttr2("gen_ai.provider.name", meta.provider.slice(0, maxLen)));
7546
7571
  }
7547
7572
  const tokens = meta?.tokens;
7548
7573
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -7552,8 +7577,17 @@ function exportOtlpJson(tree, options) {
7552
7577
  if (typeof outp === "number") attrs2.push(intAttr("gen_ai.usage.output_tokens", outp));
7553
7578
  }
7554
7579
  if (includeAttributes && meta && typeof meta === "object") {
7580
+ const skipKeys = /* @__PURE__ */ new Set([
7581
+ "tokens",
7582
+ "model",
7583
+ "modelId",
7584
+ "responseModel",
7585
+ "responseModelId",
7586
+ "provider",
7587
+ "originalSourceType"
7588
+ ]);
7555
7589
  for (const [k, v] of Object.entries(meta)) {
7556
- if (k === "tokens" || k === "model") continue;
7590
+ if (skipKeys.has(k)) continue;
7557
7591
  if (typeof v === "string") {
7558
7592
  attrs2.push(stringAttr2(`agent_inspect.preview.${k}`, v.slice(0, maxLen)));
7559
7593
  } else if (typeof v === "number" && Number.isFinite(v)) {