agent-inspect 6.31.30 → 6.31.31

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.
@@ -831,6 +831,16 @@ function stepIdOf(event) {
831
831
  const value = event.attributes?.stepId;
832
832
  return typeof value === "string" && value.trim() !== "" ? value : void 0;
833
833
  }
834
+ function attemptIdOf(event) {
835
+ const direct = event.attributes?.attemptId;
836
+ if (typeof direct === "string" && direct.trim() !== "") return direct;
837
+ const meta = event.attributes?.metadata;
838
+ if (meta && typeof meta === "object" && !Array.isArray(meta)) {
839
+ const nested = meta.attemptId;
840
+ if (typeof nested === "string" && nested.trim() !== "") return nested;
841
+ }
842
+ return void 0;
843
+ }
834
844
  function lifecycleKey(event) {
835
845
  if (event.kind === "RUN") return `run:${event.runId}`;
836
846
  const stepId = stepIdOf(event);
@@ -840,6 +850,9 @@ function lifecycleKey(event) {
840
850
  function isTerminal(status) {
841
851
  return status === "ok" || status === "error";
842
852
  }
853
+ function eventTime(event) {
854
+ return typeof event.timestamp === "number" ? event.timestamp : 0;
855
+ }
843
856
  function cloneNode(node) {
844
857
  return {
845
858
  event: {
@@ -850,37 +863,87 @@ function cloneNode(node) {
850
863
  depth: node.depth
851
864
  };
852
865
  }
866
+ function joinOnePair(start, terminal) {
867
+ const childMap = /* @__PURE__ */ new Map();
868
+ if (start) {
869
+ for (const child of start.children) {
870
+ childMap.set(child.event.eventId, child);
871
+ }
872
+ }
873
+ for (const child of terminal.children) {
874
+ childMap.set(child.event.eventId, child);
875
+ }
876
+ return {
877
+ event: {
878
+ ...terminal.event,
879
+ name: start?.event.name ?? terminal.event.name,
880
+ kind: start?.event.kind ?? terminal.event.kind,
881
+ ...start && attemptIdOf(terminal.event) === void 0 && attemptIdOf(start.event) ? {
882
+ attributes: {
883
+ ...terminal.event.attributes,
884
+ attemptId: attemptIdOf(start.event)
885
+ }
886
+ } : {}
887
+ },
888
+ children: presentSiblingNodes([...childMap.values()]),
889
+ depth: terminal.depth
890
+ };
891
+ }
853
892
  function joinSiblingGroup(group) {
854
893
  if (group.length <= 1) return group;
855
- const terminals = group.filter((n) => isTerminal(n.event.status));
856
- const runnings = group.filter((n) => n.event.status === "running");
894
+ const terminals = group.filter((n) => isTerminal(n.event.status)).sort((a, b) => eventTime(a.event) - eventTime(b.event));
895
+ const runnings = group.filter((n) => n.event.status === "running").sort((a, b) => eventTime(a.event) - eventTime(b.event));
896
+ const others = group.filter(
897
+ (n) => !isTerminal(n.event.status) && n.event.status !== "running"
898
+ );
857
899
  const terminalStatuses = new Set(terminals.map((n) => n.event.status));
858
900
  if (terminalStatuses.size > 1) {
859
901
  return group;
860
902
  }
861
- if (terminals.length >= 1) {
862
- const terminal = terminals[terminals.length - 1];
863
- const start = runnings[0];
864
- const childMap = /* @__PURE__ */ new Map();
865
- for (const n of group) {
866
- for (const child of n.children) {
867
- childMap.set(child.event.eventId, child);
903
+ if (terminals.length > 1 && terminals.every((t) => attemptIdOf(t.event) === void 0) && runnings.every((r) => attemptIdOf(r.event) === void 0)) {
904
+ return group;
905
+ }
906
+ const usedRunning = /* @__PURE__ */ new Set();
907
+ const out = [];
908
+ for (const terminal of terminals) {
909
+ const terminalAttempt = attemptIdOf(terminal.event);
910
+ const terminalTs = eventTime(terminal.event);
911
+ const candidate = runnings.find((r) => {
912
+ if (usedRunning.has(r.event.eventId)) return false;
913
+ if (eventTime(r.event) > terminalTs) return false;
914
+ const runningAttempt = attemptIdOf(r.event);
915
+ if (terminalAttempt !== void 0) {
916
+ return runningAttempt === terminalAttempt;
868
917
  }
869
- }
870
- return [
871
- {
872
- event: {
873
- ...terminal.event,
874
- name: start?.event.name ?? terminal.event.name,
875
- kind: start?.event.kind ?? terminal.event.kind,
876
- ...start?.event.timestamp !== void 0 && terminal.event.durationMs === void 0 ? {} : {}
877
- },
878
- children: presentSiblingNodes([...childMap.values()]),
879
- depth: terminal.depth
918
+ if (runningAttempt !== void 0) {
919
+ return true;
880
920
  }
881
- ];
921
+ return true;
922
+ });
923
+ if (candidate) {
924
+ usedRunning.add(candidate.event.eventId);
925
+ out.push(joinOnePair(candidate, terminal));
926
+ } else {
927
+ out.push({
928
+ ...terminal,
929
+ children: presentSiblingNodes(terminal.children)
930
+ });
931
+ }
932
+ }
933
+ for (const running of runnings) {
934
+ if (usedRunning.has(running.event.eventId)) continue;
935
+ out.push({
936
+ ...running,
937
+ children: presentSiblingNodes(running.children)
938
+ });
939
+ }
940
+ for (const other of others) {
941
+ out.push({
942
+ ...other,
943
+ children: presentSiblingNodes(other.children)
944
+ });
882
945
  }
883
- return group;
946
+ return out;
884
947
  }
885
948
  function presentSiblingNodes(nodes) {
886
949
  const prepared = nodes.map((n) => ({