@agent-inspect/mcp-server 6.31.7 → 6.31.9

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.
@@ -1065,7 +1065,18 @@ async function readTraceEventsFromFile(filePath) {
1065
1065
  }
1066
1066
 
1067
1067
  // packages/core/src/context.ts
1068
- new AsyncLocalStorage();
1068
+ var GLOBAL_CONTEXT_ALS_KEY = "agent-inspect:execution-context-als:v1";
1069
+ function getSharedContextStorage() {
1070
+ const host = globalThis;
1071
+ const existing = host[GLOBAL_CONTEXT_ALS_KEY];
1072
+ if (existing instanceof AsyncLocalStorage) {
1073
+ return existing;
1074
+ }
1075
+ const created = new AsyncLocalStorage();
1076
+ host[GLOBAL_CONTEXT_ALS_KEY] = created;
1077
+ return created;
1078
+ }
1079
+ getSharedContextStorage();
1069
1080
 
1070
1081
  // packages/core/src/outcomes/types.ts
1071
1082
  var OBSERVED_OUTCOME_STATUSES = [
@@ -5114,8 +5125,13 @@ function persistedInspectEventsToInspectEvents(events, options) {
5114
5125
  }
5115
5126
 
5116
5127
  // packages/core/src/persisted/tree-bridge.ts
5128
+ function logicalToPersisted(event) {
5129
+ const { sourceEventIds: _sourceEventIds, projection: _projection, ...rest } = event;
5130
+ return rest;
5131
+ }
5117
5132
  function persistedInspectEventsToRunTrees(events, options) {
5118
- const inspectEvents = persistedInspectEventsToInspectEvents(events, {
5133
+ const sourceEvents = options?.coalesceLifecycle === true ? projectLogicalEvents(events).logicalEvents.map(logicalToPersisted) : events;
5134
+ const inspectEvents = persistedInspectEventsToInspectEvents(sourceEvents, {
5119
5135
  skipInvalid: options?.skipInvalid
5120
5136
  });
5121
5137
  return new TreeBuilder().build(inspectEvents);
@@ -5809,7 +5825,7 @@ function mapOpenInferenceSpan(span, index, version) {
5809
5825
  const errorMessage = isRecord10(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
5810
5826
  const event = {
5811
5827
  schemaVersion: "0.2",
5812
- eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
5828
+ eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
5813
5829
  runId: typeof rawAttributes["agent_inspect.run_id"] === "string" ? rawAttributes["agent_inspect.run_id"] : traceId,
5814
5830
  kind,
5815
5831
  name,
@@ -5860,12 +5876,16 @@ function mapOpenInferenceEvents(document) {
5860
5876
  const mapped = document.spans.map(
5861
5877
  (span, index) => mapOpenInferenceSpan(span, index, document.version)
5862
5878
  );
5863
- const spanIdToEventId = new Map(
5864
- mapped.map((span) => [span.spanId, span.event.eventId])
5879
+ const spanKeyToEventId = new Map(
5880
+ mapped.map((span) => {
5881
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5882
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
5883
+ })
5865
5884
  );
5866
5885
  for (const span of mapped) {
5867
5886
  if (span.parentSpanId === void 0) continue;
5868
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
5887
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5888
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
5869
5889
  }
5870
5890
  return {
5871
5891
  events: mapped.map((span) => span.event),
@@ -6414,7 +6434,7 @@ function mapOtlpSpan(context) {
6414
6434
  const errorMessage = isRecord10(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
6415
6435
  const event = {
6416
6436
  schemaVersion: "0.2",
6417
- eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
6437
+ eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
6418
6438
  runId: typeof parsedSpanAttributes.attributes["agent_inspect.run_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.run_id"] : traceId,
6419
6439
  kind,
6420
6440
  name: readStringField(span, ["name"]) ?? spanId,
@@ -6463,12 +6483,16 @@ function mapOtlpSpan(context) {
6463
6483
  }
6464
6484
  function mapOtlpEventsToPersisted(document) {
6465
6485
  const mapped = document.spans.map((span) => mapOtlpSpan(span));
6466
- const spanIdToEventId = new Map(
6467
- mapped.map((span) => [span.spanId, span.event.eventId])
6486
+ const spanKeyToEventId = new Map(
6487
+ mapped.map((span) => {
6488
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
6489
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
6490
+ })
6468
6491
  );
6469
6492
  for (const span of mapped) {
6470
6493
  if (span.parentSpanId === void 0) continue;
6471
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
6494
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
6495
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
6472
6496
  }
6473
6497
  return {
6474
6498
  events: mapped.map((span) => span.event),
@@ -7372,11 +7396,13 @@ function exportOpenInference(tree, options) {
7372
7396
  endNs = startNs + unixNano(ev.durationMs);
7373
7397
  }
7374
7398
  const { openInferenceKind } = mapInspectKindToOI(ev.kind, warnings);
7399
+ const meta = ev.attributes;
7400
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
7375
7401
  const attrs2 = {
7376
7402
  "openinference.span.kind": openInferenceKind,
7377
7403
  "agent_inspect.kind": ev.kind,
7378
7404
  "agent_inspect.confidence": ev.confidence,
7379
- "agent_inspect.source.type": ev.source.type,
7405
+ "agent_inspect.source.type": originalSource,
7380
7406
  "agent_inspect.run_id": tree.runId,
7381
7407
  "agent_inspect.event_id": ev.eventId,
7382
7408
  "agent_inspect.status": ev.status ?? "unset"
@@ -7384,9 +7410,9 @@ function exportOpenInference(tree, options) {
7384
7410
  if (ev.durationMs !== void 0) {
7385
7411
  attrs2["agent_inspect.duration_ms"] = ev.durationMs;
7386
7412
  }
7387
- const meta = ev.attributes;
7388
- if (meta?.model !== void 0 && typeof meta.model === "string") {
7389
- attrs2["llm.model_name"] = meta.model;
7413
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
7414
+ if (requestModel !== void 0) {
7415
+ attrs2["llm.model_name"] = requestModel;
7390
7416
  }
7391
7417
  const tokens = meta?.tokens;
7392
7418
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -7396,8 +7422,9 @@ function exportOpenInference(tree, options) {
7396
7422
  if (typeof outp === "number") attrs2["llm.token_count.completion"] = outp;
7397
7423
  }
7398
7424
  if (includeAttributes && meta && typeof meta === "object") {
7425
+ const skipKeys = /* @__PURE__ */ new Set(["tokens", "model", "modelId", "originalSourceType"]);
7399
7426
  for (const [k, v] of Object.entries(meta)) {
7400
- if (k === "tokens" || k === "model") continue;
7427
+ if (skipKeys.has(k)) continue;
7401
7428
  if (v !== void 0 && v !== null && typeof v !== "object") {
7402
7429
  attrs2[`agent_inspect.preview.${k}`] = typeof v === "string" ? v.slice(0, maxLen) : v;
7403
7430
  }
@@ -7515,24 +7542,33 @@ function exportOtlpJson(tree, options) {
7515
7542
  const spanId = hexFrom2(`${tree.runId}:${ev.eventId}`, 8);
7516
7543
  const parentSpanId = ev.parentId ? hexFrom2(`${tree.runId}:${ev.parentId}`, 8) : void 0;
7517
7544
  const { startNs, endNs } = resolveSpanTimes(ev);
7545
+ const meta = ev.attributes;
7546
+ const originalSource = typeof meta?.originalSourceType === "string" && meta.originalSourceType.trim() !== "" ? meta.originalSourceType.trim() : ev.source.type;
7518
7547
  const attrs2 = [
7519
7548
  stringAttr2("agent_inspect.kind", ev.kind),
7520
7549
  stringAttr2("agent_inspect.confidence", ev.confidence),
7521
- stringAttr2("agent_inspect.source.type", ev.source.type),
7550
+ stringAttr2("agent_inspect.source.type", originalSource),
7522
7551
  stringAttr2("agent_inspect.run_id", tree.runId),
7523
7552
  stringAttr2("agent_inspect.event_id", ev.eventId),
7524
7553
  stringAttr2("agent_inspect.status", ev.status ?? "unset")
7525
7554
  ];
7526
7555
  if (ev.durationMs !== void 0) {
7527
- attrs2.push(intAttr("agent_inspect.duration_ms", ev.durationMs));
7556
+ attrs2.push(numberAttr("agent_inspect.duration_ms", ev.durationMs));
7528
7557
  }
7529
7558
  const op = genAiOperationName(ev.kind);
7530
7559
  if (op !== void 0) {
7531
7560
  attrs2.push(stringAttr2("gen_ai.operation.name", op));
7532
7561
  }
7533
- const meta = ev.attributes;
7534
- if (meta?.model !== void 0 && typeof meta.model === "string") {
7535
- attrs2.push(stringAttr2("gen_ai.request.model", meta.model.slice(0, maxLen)));
7562
+ const requestModel = (typeof meta?.model === "string" && meta.model.trim() !== "" ? meta.model : void 0) ?? (typeof meta?.modelId === "string" && meta.modelId.trim() !== "" ? meta.modelId : void 0);
7563
+ if (requestModel !== void 0) {
7564
+ attrs2.push(stringAttr2("gen_ai.request.model", requestModel.slice(0, maxLen)));
7565
+ }
7566
+ const responseModel = typeof meta?.responseModelId === "string" && meta.responseModelId.trim() !== "" ? meta.responseModelId : typeof meta?.responseModel === "string" && meta.responseModel.trim() !== "" ? meta.responseModel : void 0;
7567
+ if (responseModel !== void 0) {
7568
+ attrs2.push(stringAttr2("gen_ai.response.model", responseModel.slice(0, maxLen)));
7569
+ }
7570
+ if (typeof meta?.provider === "string" && meta.provider.trim() !== "") {
7571
+ attrs2.push(stringAttr2("gen_ai.provider.name", meta.provider.slice(0, maxLen)));
7536
7572
  }
7537
7573
  const tokens = meta?.tokens;
7538
7574
  if (tokens && typeof tokens === "object" && tokens !== null) {
@@ -7542,8 +7578,17 @@ function exportOtlpJson(tree, options) {
7542
7578
  if (typeof outp === "number") attrs2.push(intAttr("gen_ai.usage.output_tokens", outp));
7543
7579
  }
7544
7580
  if (includeAttributes && meta && typeof meta === "object") {
7581
+ const skipKeys = /* @__PURE__ */ new Set([
7582
+ "tokens",
7583
+ "model",
7584
+ "modelId",
7585
+ "responseModel",
7586
+ "responseModelId",
7587
+ "provider",
7588
+ "originalSourceType"
7589
+ ]);
7545
7590
  for (const [k, v] of Object.entries(meta)) {
7546
- if (k === "tokens" || k === "model") continue;
7591
+ if (skipKeys.has(k)) continue;
7547
7592
  if (typeof v === "string") {
7548
7593
  attrs2.push(stringAttr2(`agent_inspect.preview.${k}`, v.slice(0, maxLen)));
7549
7594
  } else if (typeof v === "number" && Number.isFinite(v)) {
@@ -9230,5 +9275,5 @@ async function runReadOnlyMcpServer(options = {}) {
9230
9275
  }
9231
9276
 
9232
9277
  export { MCP_MAX_REQUEST_BYTES, MCP_PROTOCOL_VERSION, MCP_SERVER_INSTRUCTIONS, READ_ONLY_TOOLS, TRACE_DATA_UNTRUSTED_WARNING, callReadOnlyTool, createMcpServerContext, handleMcpProtocolLine, runReadOnlyMcpServer };
9233
- //# sourceMappingURL=chunk-J2LULLKC.mjs.map
9234
- //# sourceMappingURL=chunk-J2LULLKC.mjs.map
9278
+ //# sourceMappingURL=chunk-U3JBHSNB.mjs.map
9279
+ //# sourceMappingURL=chunk-U3JBHSNB.mjs.map