@agent-inspect/viewer 6.31.5 → 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/index.mjs CHANGED
@@ -993,6 +993,8 @@ async function extractMetadata(filePath, _quickScan) {
993
993
  }
994
994
 
995
995
  // packages/core/src/timeline.ts
996
+ var ROOT_TIMELINE_DEPTH = 0;
997
+ var MAX_TIMELINE_DEPTH = 1e3;
996
998
  function finite(n) {
997
999
  return typeof n === "number" && Number.isFinite(n);
998
1000
  }
@@ -1063,16 +1065,51 @@ function buildRunTimeline(events, options = {}) {
1063
1065
  const computeDepth = (stepId) => {
1064
1066
  const cached = depthCache.get(stepId);
1065
1067
  if (cached !== void 0) return cached;
1066
- const node = steps.get(stepId);
1067
- if (!node) return 0;
1068
- const parent = node.parentId;
1069
- if (typeof parent !== "string" || parent.trim() === "" || !steps.has(parent)) {
1070
- depthCache.set(stepId, 0);
1071
- return 0;
1068
+ const ancestry = [];
1069
+ const ancestryIndexes = /* @__PURE__ */ new Map();
1070
+ let currentStepId = stepId;
1071
+ let resolvedDepth;
1072
+ while (resolvedDepth === void 0) {
1073
+ const cachedDepth = depthCache.get(currentStepId);
1074
+ if (cachedDepth !== void 0) {
1075
+ resolvedDepth = cachedDepth;
1076
+ continue;
1077
+ }
1078
+ const cycleStart = ancestryIndexes.get(currentStepId);
1079
+ if (cycleStart !== void 0) {
1080
+ const cycleStepIds = ancestry.splice(cycleStart);
1081
+ for (const cycleStepId of cycleStepIds) {
1082
+ depthCache.set(cycleStepId, ROOT_TIMELINE_DEPTH);
1083
+ }
1084
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1085
+ continue;
1086
+ }
1087
+ const currentStep = steps.get(currentStepId);
1088
+ if (!currentStep) {
1089
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1090
+ continue;
1091
+ }
1092
+ ancestryIndexes.set(currentStepId, ancestry.length);
1093
+ ancestry.push(currentStepId);
1094
+ const parentId = currentStep.parentId;
1095
+ if (typeof parentId !== "string" || parentId.trim() === "" || !steps.has(parentId)) {
1096
+ ancestry.pop();
1097
+ depthCache.set(currentStepId, ROOT_TIMELINE_DEPTH);
1098
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1099
+ continue;
1100
+ }
1101
+ currentStepId = parentId;
1102
+ }
1103
+ ancestry.reverse();
1104
+ for (const ancestorStepId of ancestry) {
1105
+ resolvedDepth = Math.min(MAX_TIMELINE_DEPTH, resolvedDepth + 1);
1106
+ depthCache.set(ancestorStepId, resolvedDepth);
1107
+ }
1108
+ const resolvedStepDepth = depthCache.get(stepId);
1109
+ if (resolvedStepDepth === void 0) {
1110
+ throw new Error(`Failed to resolve timeline depth for step "${stepId}"`);
1072
1111
  }
1073
- const d = Math.min(1e3, computeDepth(parent) + 1);
1074
- depthCache.set(stepId, d);
1075
- return d;
1112
+ return resolvedStepDepth;
1076
1113
  };
1077
1114
  const entries = [];
1078
1115
  for (const [stepId, s] of steps.entries()) {
@@ -3813,6 +3850,23 @@ function persistedInspectEventToInspectEvent(event) {
3813
3850
  if (event.durationMs !== void 0 && Number.isFinite(event.durationMs) && event.durationMs >= 0) {
3814
3851
  out.durationMs = event.durationMs;
3815
3852
  }
3853
+ if (event.startedAt !== void 0) {
3854
+ const started = parseIsoToMs3(event.startedAt);
3855
+ if (!started.invalidTimestamp) {
3856
+ attrs.startedAtMs = started.ms;
3857
+ out.timestamp = started.ms;
3858
+ }
3859
+ }
3860
+ if (event.endedAt !== void 0) {
3861
+ const ended = parseIsoToMs3(event.endedAt);
3862
+ if (!ended.invalidTimestamp) {
3863
+ attrs.endedAtMs = ended.ms;
3864
+ if (out.durationMs === void 0 && typeof attrs.startedAtMs === "number" && ended.ms >= attrs.startedAtMs) {
3865
+ out.durationMs = ended.ms - attrs.startedAtMs;
3866
+ }
3867
+ }
3868
+ }
3869
+ out.attributes = compactAttributes2(attrs);
3816
3870
  return out;
3817
3871
  }
3818
3872
  function persistedInspectEventsToInspectEvents(events, options) {
@@ -4874,20 +4928,38 @@ function extractOtlpDocument(root) {
4874
4928
  function mapOtlpStatus(status) {
4875
4929
  if (!isRecord7(status)) return void 0;
4876
4930
  const rawCode = status.code;
4877
- if (typeof rawCode !== "string") return void 0;
4878
- switch (rawCode.toUpperCase()) {
4879
- case "STATUS_CODE_OK":
4880
- case "OK":
4881
- return "ok";
4882
- case "STATUS_CODE_ERROR":
4883
- case "ERROR":
4884
- return "error";
4885
- case "STATUS_CODE_UNSET":
4886
- case "UNSET":
4887
- return "unknown";
4888
- default:
4889
- return "unknown";
4931
+ if (typeof rawCode === "number" && Number.isFinite(rawCode)) {
4932
+ switch (rawCode) {
4933
+ case 0:
4934
+ return "unknown";
4935
+ case 1:
4936
+ return "ok";
4937
+ case 2:
4938
+ return "error";
4939
+ default:
4940
+ return "unknown";
4941
+ }
4942
+ }
4943
+ if (typeof rawCode === "string") {
4944
+ const trimmed = rawCode.trim();
4945
+ if (/^\d+$/.test(trimmed)) {
4946
+ return mapOtlpStatus({ code: Number(trimmed) });
4947
+ }
4948
+ switch (trimmed.toUpperCase()) {
4949
+ case "STATUS_CODE_OK":
4950
+ case "OK":
4951
+ return "ok";
4952
+ case "STATUS_CODE_ERROR":
4953
+ case "ERROR":
4954
+ return "error";
4955
+ case "STATUS_CODE_UNSET":
4956
+ case "UNSET":
4957
+ return "unknown";
4958
+ default:
4959
+ return "unknown";
4960
+ }
4890
4961
  }
4962
+ return void 0;
4891
4963
  }
4892
4964
  function readOtlpKind(attributes, pathPrefix) {
4893
4965
  const warnings = [];