@agent-inspect/viewer 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/index.cjs CHANGED
@@ -3892,8 +3892,13 @@ function persistedInspectEventsToInspectEvents(events, options) {
3892
3892
  }
3893
3893
 
3894
3894
  // packages/core/src/persisted/tree-bridge.ts
3895
+ function logicalToPersisted(event) {
3896
+ const { sourceEventIds: _sourceEventIds, projection: _projection, ...rest } = event;
3897
+ return rest;
3898
+ }
3895
3899
  function persistedInspectEventsToRunTrees(events, options) {
3896
- const inspectEvents = persistedInspectEventsToInspectEvents(events, {
3900
+ const sourceEvents = options?.coalesceLifecycle === true ? projectLogicalEvents(events).logicalEvents.map(logicalToPersisted) : events;
3901
+ const inspectEvents = persistedInspectEventsToInspectEvents(sourceEvents, {
3897
3902
  skipInvalid: options?.skipInvalid
3898
3903
  });
3899
3904
  return new TreeBuilder().build(inspectEvents);
@@ -4587,7 +4592,7 @@ function mapOpenInferenceSpan(span, index, version) {
4587
4592
  const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
4588
4593
  const event = {
4589
4594
  schemaVersion: "0.2",
4590
- eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
4595
+ eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
4591
4596
  runId: typeof rawAttributes["agent_inspect.run_id"] === "string" ? rawAttributes["agent_inspect.run_id"] : traceId,
4592
4597
  kind,
4593
4598
  name,
@@ -4638,12 +4643,16 @@ function mapOpenInferenceEvents(document) {
4638
4643
  const mapped = document.spans.map(
4639
4644
  (span, index) => mapOpenInferenceSpan(span, index, document.version)
4640
4645
  );
4641
- const spanIdToEventId = new Map(
4642
- mapped.map((span) => [span.spanId, span.event.eventId])
4646
+ const spanKeyToEventId = new Map(
4647
+ mapped.map((span) => {
4648
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
4649
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
4650
+ })
4643
4651
  );
4644
4652
  for (const span of mapped) {
4645
4653
  if (span.parentSpanId === void 0) continue;
4646
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
4654
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
4655
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
4647
4656
  }
4648
4657
  return {
4649
4658
  events: mapped.map((span) => span.event),
@@ -5192,7 +5201,7 @@ function mapOtlpSpan(context) {
5192
5201
  const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
5193
5202
  const event = {
5194
5203
  schemaVersion: "0.2",
5195
- eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
5204
+ eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
5196
5205
  runId: typeof parsedSpanAttributes.attributes["agent_inspect.run_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.run_id"] : traceId,
5197
5206
  kind,
5198
5207
  name: readStringField(span, ["name"]) ?? spanId,
@@ -5241,12 +5250,16 @@ function mapOtlpSpan(context) {
5241
5250
  }
5242
5251
  function mapOtlpEventsToPersisted(document) {
5243
5252
  const mapped = document.spans.map((span) => mapOtlpSpan(span));
5244
- const spanIdToEventId = new Map(
5245
- mapped.map((span) => [span.spanId, span.event.eventId])
5253
+ const spanKeyToEventId = new Map(
5254
+ mapped.map((span) => {
5255
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5256
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
5257
+ })
5246
5258
  );
5247
5259
  for (const span of mapped) {
5248
5260
  if (span.parentSpanId === void 0) continue;
5249
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
5261
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5262
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
5250
5263
  }
5251
5264
  return {
5252
5265
  events: mapped.map((span) => span.event),