@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.mjs CHANGED
@@ -3885,8 +3885,13 @@ function persistedInspectEventsToInspectEvents(events, options) {
3885
3885
  }
3886
3886
 
3887
3887
  // packages/core/src/persisted/tree-bridge.ts
3888
+ function logicalToPersisted(event) {
3889
+ const { sourceEventIds: _sourceEventIds, projection: _projection, ...rest } = event;
3890
+ return rest;
3891
+ }
3888
3892
  function persistedInspectEventsToRunTrees(events, options) {
3889
- const inspectEvents = persistedInspectEventsToInspectEvents(events, {
3893
+ const sourceEvents = options?.coalesceLifecycle === true ? projectLogicalEvents(events).logicalEvents.map(logicalToPersisted) : events;
3894
+ const inspectEvents = persistedInspectEventsToInspectEvents(sourceEvents, {
3890
3895
  skipInvalid: options?.skipInvalid
3891
3896
  });
3892
3897
  return new TreeBuilder().build(inspectEvents);
@@ -4580,7 +4585,7 @@ function mapOpenInferenceSpan(span, index, version) {
4580
4585
  const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
4581
4586
  const event = {
4582
4587
  schemaVersion: "0.2",
4583
- eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
4588
+ eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
4584
4589
  runId: typeof rawAttributes["agent_inspect.run_id"] === "string" ? rawAttributes["agent_inspect.run_id"] : traceId,
4585
4590
  kind,
4586
4591
  name,
@@ -4631,12 +4636,16 @@ function mapOpenInferenceEvents(document) {
4631
4636
  const mapped = document.spans.map(
4632
4637
  (span, index) => mapOpenInferenceSpan(span, index, document.version)
4633
4638
  );
4634
- const spanIdToEventId = new Map(
4635
- mapped.map((span) => [span.spanId, span.event.eventId])
4639
+ const spanKeyToEventId = new Map(
4640
+ mapped.map((span) => {
4641
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
4642
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
4643
+ })
4636
4644
  );
4637
4645
  for (const span of mapped) {
4638
4646
  if (span.parentSpanId === void 0) continue;
4639
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
4647
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
4648
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
4640
4649
  }
4641
4650
  return {
4642
4651
  events: mapped.map((span) => span.event),
@@ -5185,7 +5194,7 @@ function mapOtlpSpan(context) {
5185
5194
  const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
5186
5195
  const event = {
5187
5196
  schemaVersion: "0.2",
5188
- eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
5197
+ eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : `${traceId}:${spanId}`,
5189
5198
  runId: typeof parsedSpanAttributes.attributes["agent_inspect.run_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.run_id"] : traceId,
5190
5199
  kind,
5191
5200
  name: readStringField(span, ["name"]) ?? spanId,
@@ -5234,12 +5243,16 @@ function mapOtlpSpan(context) {
5234
5243
  }
5235
5244
  function mapOtlpEventsToPersisted(document) {
5236
5245
  const mapped = document.spans.map((span) => mapOtlpSpan(span));
5237
- const spanIdToEventId = new Map(
5238
- mapped.map((span) => [span.spanId, span.event.eventId])
5246
+ const spanKeyToEventId = new Map(
5247
+ mapped.map((span) => {
5248
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5249
+ return [`${traceId}:${span.spanId}`, span.event.eventId];
5250
+ })
5239
5251
  );
5240
5252
  for (const span of mapped) {
5241
5253
  if (span.parentSpanId === void 0) continue;
5242
- span.event.parentId = spanIdToEventId.get(span.parentSpanId) ?? span.parentSpanId;
5254
+ const traceId = typeof span.event.trace?.traceId === "string" ? span.event.trace.traceId : "";
5255
+ span.event.parentId = spanKeyToEventId.get(`${traceId}:${span.parentSpanId}`) ?? span.parentSpanId;
5243
5256
  }
5244
5257
  return {
5245
5258
  events: mapped.map((span) => span.event),