@agent-inspect/viewer 6.31.12 → 6.31.14

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
@@ -3948,18 +3948,16 @@ var TreeBuilder = class {
3948
3948
  inc(confidenceBreakdown, e.confidence);
3949
3949
  kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
3950
3950
  }
3951
- const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
3952
- const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
3953
- const status = computeRunStatus(sorted);
3954
- const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
3955
3951
  const name = sorted.find((e) => e.kind === "RUN")?.name;
3952
+ const status = computeRunStatus(sorted);
3953
+ const timing = resolveRunTiming(sorted, status);
3956
3954
  out.push({
3957
3955
  runId,
3958
3956
  name,
3959
3957
  status,
3960
- startedAt,
3961
- endedAt: status === "running" ? void 0 : endedAt,
3962
- durationMs,
3958
+ startedAt: timing.startedAt,
3959
+ endedAt: timing.endedAt,
3960
+ durationMs: timing.durationMs,
3963
3961
  children: roots,
3964
3962
  metadata: {
3965
3963
  totalEvents: sorted.length,
@@ -3973,6 +3971,57 @@ var TreeBuilder = class {
3973
3971
  return out;
3974
3972
  }
3975
3973
  };
3974
+ function resolveRunTiming(sorted, status) {
3975
+ let startedAtMs;
3976
+ let endedAtMs;
3977
+ let explicitDurationMs;
3978
+ for (const event of sorted) {
3979
+ if (event.kind !== "RUN") continue;
3980
+ const attrs = event.attributes ?? {};
3981
+ if (typeof attrs.startedAtMs === "number" && Number.isFinite(attrs.startedAtMs)) {
3982
+ startedAtMs = startedAtMs === void 0 ? attrs.startedAtMs : Math.min(startedAtMs, attrs.startedAtMs);
3983
+ }
3984
+ if (typeof attrs.endedAtMs === "number" && Number.isFinite(attrs.endedAtMs)) {
3985
+ endedAtMs = endedAtMs === void 0 ? attrs.endedAtMs : Math.max(endedAtMs, attrs.endedAtMs);
3986
+ }
3987
+ if ((event.status === "ok" || event.status === "error") && typeof event.durationMs === "number" && Number.isFinite(event.durationMs) && event.durationMs >= 0) {
3988
+ explicitDurationMs = event.durationMs;
3989
+ if (endedAtMs === void 0 && startedAtMs !== void 0) {
3990
+ endedAtMs = startedAtMs + event.durationMs;
3991
+ } else if (endedAtMs === void 0 && Number.isFinite(event.timestamp)) {
3992
+ endedAtMs = event.timestamp + event.durationMs;
3993
+ if (startedAtMs === void 0) {
3994
+ startedAtMs = event.timestamp;
3995
+ }
3996
+ }
3997
+ }
3998
+ if (startedAtMs === void 0 && event.status === "running" && Number.isFinite(event.timestamp)) {
3999
+ startedAtMs = event.timestamp;
4000
+ }
4001
+ }
4002
+ if (startedAtMs !== void 0 && endedAtMs !== void 0 && Number.isFinite(startedAtMs) && Number.isFinite(endedAtMs) && endedAtMs >= startedAtMs && status !== "running") {
4003
+ return {
4004
+ startedAt: startedAtMs,
4005
+ endedAt: endedAtMs,
4006
+ durationMs: endedAtMs - startedAtMs
4007
+ };
4008
+ }
4009
+ if (startedAtMs !== void 0 && explicitDurationMs !== void 0 && status !== "running") {
4010
+ return {
4011
+ startedAt: startedAtMs,
4012
+ endedAt: startedAtMs + explicitDurationMs,
4013
+ durationMs: explicitDurationMs
4014
+ };
4015
+ }
4016
+ const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
4017
+ const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
4018
+ const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
4019
+ return {
4020
+ startedAt,
4021
+ endedAt: status === "running" ? void 0 : endedAt,
4022
+ durationMs
4023
+ };
4024
+ }
3976
4025
 
3977
4026
  // packages/core/src/persisted/to-inspect-event.ts
3978
4027
  function compactAttributes2(entries) {