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.
@@ -14,7 +14,7 @@ import { createServer } from 'http';
14
14
  import { createRequire } from 'module';
15
15
 
16
16
  // package.json
17
- var version = "6.31.30";
17
+ var version = "6.31.31";
18
18
 
19
19
  // packages/cli/src/trace-dir-scale.ts
20
20
  var TRACE_COUNT_WARN = 1e3;
@@ -2178,6 +2178,16 @@ function stepIdOf(event) {
2178
2178
  const value = event.attributes?.stepId;
2179
2179
  return typeof value === "string" && value.trim() !== "" ? value : void 0;
2180
2180
  }
2181
+ function attemptIdOf(event) {
2182
+ const direct = event.attributes?.attemptId;
2183
+ if (typeof direct === "string" && direct.trim() !== "") return direct;
2184
+ const meta = event.attributes?.metadata;
2185
+ if (meta && typeof meta === "object" && !Array.isArray(meta)) {
2186
+ const nested = meta.attemptId;
2187
+ if (typeof nested === "string" && nested.trim() !== "") return nested;
2188
+ }
2189
+ return void 0;
2190
+ }
2181
2191
  function lifecycleKey(event) {
2182
2192
  if (event.kind === "RUN") return `run:${event.runId}`;
2183
2193
  const stepId = stepIdOf(event);
@@ -2187,6 +2197,9 @@ function lifecycleKey(event) {
2187
2197
  function isTerminal(status) {
2188
2198
  return status === "ok" || status === "error";
2189
2199
  }
2200
+ function eventTime(event) {
2201
+ return typeof event.timestamp === "number" ? event.timestamp : 0;
2202
+ }
2190
2203
  function cloneNode(node) {
2191
2204
  return {
2192
2205
  event: {
@@ -2197,37 +2210,87 @@ function cloneNode(node) {
2197
2210
  depth: node.depth
2198
2211
  };
2199
2212
  }
2213
+ function joinOnePair(start, terminal) {
2214
+ const childMap = /* @__PURE__ */ new Map();
2215
+ if (start) {
2216
+ for (const child of start.children) {
2217
+ childMap.set(child.event.eventId, child);
2218
+ }
2219
+ }
2220
+ for (const child of terminal.children) {
2221
+ childMap.set(child.event.eventId, child);
2222
+ }
2223
+ return {
2224
+ event: {
2225
+ ...terminal.event,
2226
+ name: start?.event.name ?? terminal.event.name,
2227
+ kind: start?.event.kind ?? terminal.event.kind,
2228
+ ...start && attemptIdOf(terminal.event) === void 0 && attemptIdOf(start.event) ? {
2229
+ attributes: {
2230
+ ...terminal.event.attributes,
2231
+ attemptId: attemptIdOf(start.event)
2232
+ }
2233
+ } : {}
2234
+ },
2235
+ children: presentSiblingNodes([...childMap.values()]),
2236
+ depth: terminal.depth
2237
+ };
2238
+ }
2200
2239
  function joinSiblingGroup(group) {
2201
2240
  if (group.length <= 1) return group;
2202
- const terminals = group.filter((n) => isTerminal(n.event.status));
2203
- const runnings = group.filter((n) => n.event.status === "running");
2241
+ const terminals = group.filter((n) => isTerminal(n.event.status)).sort((a, b) => eventTime(a.event) - eventTime(b.event));
2242
+ const runnings = group.filter((n) => n.event.status === "running").sort((a, b) => eventTime(a.event) - eventTime(b.event));
2243
+ const others = group.filter(
2244
+ (n) => !isTerminal(n.event.status) && n.event.status !== "running"
2245
+ );
2204
2246
  const terminalStatuses = new Set(terminals.map((n) => n.event.status));
2205
2247
  if (terminalStatuses.size > 1) {
2206
2248
  return group;
2207
2249
  }
2208
- if (terminals.length >= 1) {
2209
- const terminal = terminals[terminals.length - 1];
2210
- const start = runnings[0];
2211
- const childMap = /* @__PURE__ */ new Map();
2212
- for (const n of group) {
2213
- for (const child of n.children) {
2214
- childMap.set(child.event.eventId, child);
2215
- }
2250
+ if (terminals.length > 1 && terminals.every((t) => attemptIdOf(t.event) === void 0) && runnings.every((r) => attemptIdOf(r.event) === void 0)) {
2251
+ return group;
2252
+ }
2253
+ const usedRunning = /* @__PURE__ */ new Set();
2254
+ const out = [];
2255
+ for (const terminal of terminals) {
2256
+ const terminalAttempt = attemptIdOf(terminal.event);
2257
+ const terminalTs = eventTime(terminal.event);
2258
+ const candidate = runnings.find((r) => {
2259
+ if (usedRunning.has(r.event.eventId)) return false;
2260
+ if (eventTime(r.event) > terminalTs) return false;
2261
+ const runningAttempt = attemptIdOf(r.event);
2262
+ if (terminalAttempt !== void 0) {
2263
+ return runningAttempt === terminalAttempt;
2264
+ }
2265
+ if (runningAttempt !== void 0) {
2266
+ return true;
2267
+ }
2268
+ return true;
2269
+ });
2270
+ if (candidate) {
2271
+ usedRunning.add(candidate.event.eventId);
2272
+ out.push(joinOnePair(candidate, terminal));
2273
+ } else {
2274
+ out.push({
2275
+ ...terminal,
2276
+ children: presentSiblingNodes(terminal.children)
2277
+ });
2216
2278
  }
2217
- return [
2218
- {
2219
- event: {
2220
- ...terminal.event,
2221
- name: start?.event.name ?? terminal.event.name,
2222
- kind: start?.event.kind ?? terminal.event.kind,
2223
- ...start?.event.timestamp !== void 0 && terminal.event.durationMs === void 0 ? {} : {}
2224
- },
2225
- children: presentSiblingNodes([...childMap.values()]),
2226
- depth: terminal.depth
2227
- }
2228
- ];
2229
2279
  }
2230
- return group;
2280
+ for (const running of runnings) {
2281
+ if (usedRunning.has(running.event.eventId)) continue;
2282
+ out.push({
2283
+ ...running,
2284
+ children: presentSiblingNodes(running.children)
2285
+ });
2286
+ }
2287
+ for (const other of others) {
2288
+ out.push({
2289
+ ...other,
2290
+ children: presentSiblingNodes(other.children)
2291
+ });
2292
+ }
2293
+ return out;
2231
2294
  }
2232
2295
  function presentSiblingNodes(nodes) {
2233
2296
  const prepared = nodes.map((n) => ({