@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.cjs CHANGED
@@ -1000,6 +1000,8 @@ async function extractMetadata(filePath, _quickScan) {
1000
1000
  }
1001
1001
 
1002
1002
  // packages/core/src/timeline.ts
1003
+ var ROOT_TIMELINE_DEPTH = 0;
1004
+ var MAX_TIMELINE_DEPTH = 1e3;
1003
1005
  function finite(n) {
1004
1006
  return typeof n === "number" && Number.isFinite(n);
1005
1007
  }
@@ -1070,16 +1072,51 @@ function buildRunTimeline(events, options = {}) {
1070
1072
  const computeDepth = (stepId) => {
1071
1073
  const cached = depthCache.get(stepId);
1072
1074
  if (cached !== void 0) return cached;
1073
- const node = steps.get(stepId);
1074
- if (!node) return 0;
1075
- const parent = node.parentId;
1076
- if (typeof parent !== "string" || parent.trim() === "" || !steps.has(parent)) {
1077
- depthCache.set(stepId, 0);
1078
- return 0;
1075
+ const ancestry = [];
1076
+ const ancestryIndexes = /* @__PURE__ */ new Map();
1077
+ let currentStepId = stepId;
1078
+ let resolvedDepth;
1079
+ while (resolvedDepth === void 0) {
1080
+ const cachedDepth = depthCache.get(currentStepId);
1081
+ if (cachedDepth !== void 0) {
1082
+ resolvedDepth = cachedDepth;
1083
+ continue;
1084
+ }
1085
+ const cycleStart = ancestryIndexes.get(currentStepId);
1086
+ if (cycleStart !== void 0) {
1087
+ const cycleStepIds = ancestry.splice(cycleStart);
1088
+ for (const cycleStepId of cycleStepIds) {
1089
+ depthCache.set(cycleStepId, ROOT_TIMELINE_DEPTH);
1090
+ }
1091
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1092
+ continue;
1093
+ }
1094
+ const currentStep = steps.get(currentStepId);
1095
+ if (!currentStep) {
1096
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1097
+ continue;
1098
+ }
1099
+ ancestryIndexes.set(currentStepId, ancestry.length);
1100
+ ancestry.push(currentStepId);
1101
+ const parentId = currentStep.parentId;
1102
+ if (typeof parentId !== "string" || parentId.trim() === "" || !steps.has(parentId)) {
1103
+ ancestry.pop();
1104
+ depthCache.set(currentStepId, ROOT_TIMELINE_DEPTH);
1105
+ resolvedDepth = ROOT_TIMELINE_DEPTH;
1106
+ continue;
1107
+ }
1108
+ currentStepId = parentId;
1109
+ }
1110
+ ancestry.reverse();
1111
+ for (const ancestorStepId of ancestry) {
1112
+ resolvedDepth = Math.min(MAX_TIMELINE_DEPTH, resolvedDepth + 1);
1113
+ depthCache.set(ancestorStepId, resolvedDepth);
1114
+ }
1115
+ const resolvedStepDepth = depthCache.get(stepId);
1116
+ if (resolvedStepDepth === void 0) {
1117
+ throw new Error(`Failed to resolve timeline depth for step "${stepId}"`);
1079
1118
  }
1080
- const d = Math.min(1e3, computeDepth(parent) + 1);
1081
- depthCache.set(stepId, d);
1082
- return d;
1119
+ return resolvedStepDepth;
1083
1120
  };
1084
1121
  const entries = [];
1085
1122
  for (const [stepId, s] of steps.entries()) {
@@ -3820,6 +3857,23 @@ function persistedInspectEventToInspectEvent(event) {
3820
3857
  if (event.durationMs !== void 0 && Number.isFinite(event.durationMs) && event.durationMs >= 0) {
3821
3858
  out.durationMs = event.durationMs;
3822
3859
  }
3860
+ if (event.startedAt !== void 0) {
3861
+ const started = parseIsoToMs3(event.startedAt);
3862
+ if (!started.invalidTimestamp) {
3863
+ attrs.startedAtMs = started.ms;
3864
+ out.timestamp = started.ms;
3865
+ }
3866
+ }
3867
+ if (event.endedAt !== void 0) {
3868
+ const ended = parseIsoToMs3(event.endedAt);
3869
+ if (!ended.invalidTimestamp) {
3870
+ attrs.endedAtMs = ended.ms;
3871
+ if (out.durationMs === void 0 && typeof attrs.startedAtMs === "number" && ended.ms >= attrs.startedAtMs) {
3872
+ out.durationMs = ended.ms - attrs.startedAtMs;
3873
+ }
3874
+ }
3875
+ }
3876
+ out.attributes = compactAttributes2(attrs);
3823
3877
  return out;
3824
3878
  }
3825
3879
  function persistedInspectEventsToInspectEvents(events, options) {
@@ -4881,20 +4935,38 @@ function extractOtlpDocument(root) {
4881
4935
  function mapOtlpStatus(status) {
4882
4936
  if (!isRecord7(status)) return void 0;
4883
4937
  const rawCode = status.code;
4884
- if (typeof rawCode !== "string") return void 0;
4885
- switch (rawCode.toUpperCase()) {
4886
- case "STATUS_CODE_OK":
4887
- case "OK":
4888
- return "ok";
4889
- case "STATUS_CODE_ERROR":
4890
- case "ERROR":
4891
- return "error";
4892
- case "STATUS_CODE_UNSET":
4893
- case "UNSET":
4894
- return "unknown";
4895
- default:
4896
- return "unknown";
4938
+ if (typeof rawCode === "number" && Number.isFinite(rawCode)) {
4939
+ switch (rawCode) {
4940
+ case 0:
4941
+ return "unknown";
4942
+ case 1:
4943
+ return "ok";
4944
+ case 2:
4945
+ return "error";
4946
+ default:
4947
+ return "unknown";
4948
+ }
4949
+ }
4950
+ if (typeof rawCode === "string") {
4951
+ const trimmed = rawCode.trim();
4952
+ if (/^\d+$/.test(trimmed)) {
4953
+ return mapOtlpStatus({ code: Number(trimmed) });
4954
+ }
4955
+ switch (trimmed.toUpperCase()) {
4956
+ case "STATUS_CODE_OK":
4957
+ case "OK":
4958
+ return "ok";
4959
+ case "STATUS_CODE_ERROR":
4960
+ case "ERROR":
4961
+ return "error";
4962
+ case "STATUS_CODE_UNSET":
4963
+ case "UNSET":
4964
+ return "unknown";
4965
+ default:
4966
+ return "unknown";
4967
+ }
4897
4968
  }
4969
+ return void 0;
4898
4970
  }
4899
4971
  function readOtlpKind(attributes, pathPrefix) {
4900
4972
  const warnings = [];