@agent-inspect/viewer 4.4.0 → 5.0.0

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
@@ -1,5 +1,5 @@
1
1
  import { createServer } from 'http';
2
- import path7 from 'path';
2
+ import path11 from 'path';
3
3
  import { AsyncLocalStorage } from 'async_hooks';
4
4
  import 'crypto';
5
5
  import { readdir, stat, readFile } from 'fs/promises';
@@ -8,6 +8,7 @@ import 'nanoid';
8
8
  import 'chalk';
9
9
  import 'fs';
10
10
  import 'readline';
11
+ import 'url';
11
12
 
12
13
  // packages/viewer/src/server.ts
13
14
 
@@ -517,7 +518,7 @@ function persistedInspectEventsToTraceEvents(events, options) {
517
518
  }
518
519
  var DEFAULT_TRACE_DIR_NAME = ".agent-inspect";
519
520
  var RUNS_DIR_NAME = "runs";
520
- var FALLBACK_TRACE_DIR = path7.join(
521
+ var FALLBACK_TRACE_DIR = path11.join(
521
522
  os.tmpdir(),
522
523
  "agent-inspect",
523
524
  RUNS_DIR_NAME
@@ -532,7 +533,7 @@ function getDefaultTraceDir() {
532
533
  if (typeof home !== "string" || home.trim() === "") {
533
534
  return FALLBACK_TRACE_DIR;
534
535
  }
535
- return path7.join(home, DEFAULT_TRACE_DIR_NAME, RUNS_DIR_NAME);
536
+ return path11.join(home, DEFAULT_TRACE_DIR_NAME, RUNS_DIR_NAME);
536
537
  } catch {
537
538
  return FALLBACK_TRACE_DIR;
538
539
  }
@@ -741,7 +742,7 @@ var TraceDirectory = class {
741
742
  this.#dir = resolveTraceDir(options);
742
743
  }
743
744
  getPath(filename) {
744
- return filename ? path7.join(this.#dir, filename) : this.#dir;
745
+ return filename ? path11.join(this.#dir, filename) : this.#dir;
745
746
  }
746
747
  async list() {
747
748
  try {
@@ -768,7 +769,7 @@ function parseIsoToMs2(value) {
768
769
  }
769
770
  async function extractMetadata(filePath, _quickScan) {
770
771
  const stats = await stat(filePath);
771
- let runIdFromFile = path7.basename(filePath);
772
+ let runIdFromFile = path11.basename(filePath);
772
773
  if (runIdFromFile.endsWith(".jsonl")) {
773
774
  runIdFromFile = runIdFromFile.slice(0, -".jsonl".length);
774
775
  }
@@ -1378,12 +1379,12 @@ function buildCriticalPath(runs, handoffs) {
1378
1379
  handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
1379
1380
  );
1380
1381
  const ordered = [...runs].sort(compareRuns);
1381
- const path8 = [];
1382
+ const path12 = [];
1382
1383
  const visited = /* @__PURE__ */ new Set();
1383
1384
  const pushRun = (run, confidence, source) => {
1384
1385
  if (visited.has(run.runId)) return;
1385
1386
  visited.add(run.runId);
1386
- path8.push({
1387
+ path12.push({
1387
1388
  runId: run.runId,
1388
1389
  name: run.name,
1389
1390
  startedAt: run.startedAt,
@@ -1408,7 +1409,7 @@ function buildCriticalPath(runs, handoffs) {
1408
1409
  const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
1409
1410
  pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
1410
1411
  }
1411
- return path8;
1412
+ return path12;
1412
1413
  }
1413
1414
  function metaRunIdMatches(run, token, runById) {
1414
1415
  const meta = extractSessionWorkflowMetadata(run.metadata);
@@ -1681,7 +1682,7 @@ function summarize(findings, diagnostics) {
1681
1682
  errors: diagnostics.filter((item) => item.severity === "error").length
1682
1683
  };
1683
1684
  }
1684
- function eventEvidence(event, path8) {
1685
+ function eventEvidence(event, path12) {
1685
1686
  return {
1686
1687
  runId: event.runId,
1687
1688
  eventId: event.eventId,
@@ -2060,6 +2061,86 @@ function traceEventsToPersistedInspectEvents(events, options) {
2060
2061
  );
2061
2062
  }
2062
2063
 
2064
+ // packages/core/src/logs/tree-builder.ts
2065
+ function inc(map, key) {
2066
+ map[key] = (map[key] ?? 0) + 1;
2067
+ }
2068
+ function computeRunStatus(events) {
2069
+ let hasRunning = false;
2070
+ for (const e of events) {
2071
+ if (e.status === "error") return "error";
2072
+ if (e.status === "running") hasRunning = true;
2073
+ }
2074
+ if (hasRunning) return "running";
2075
+ return "ok";
2076
+ }
2077
+ var TreeBuilder = class {
2078
+ constructor(options) {
2079
+ void options?.config;
2080
+ }
2081
+ build(events) {
2082
+ const byRun = /* @__PURE__ */ new Map();
2083
+ for (const e of events) {
2084
+ if (!byRun.has(e.runId)) byRun.set(e.runId, []);
2085
+ byRun.get(e.runId).push(e);
2086
+ }
2087
+ const out = [];
2088
+ for (const [runId, runEvents] of byRun.entries()) {
2089
+ const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
2090
+ const nodes = /* @__PURE__ */ new Map();
2091
+ for (const e of sorted) {
2092
+ nodes.set(e.eventId, { event: e, children: [], depth: 0 });
2093
+ }
2094
+ const roots = [];
2095
+ for (const node of nodes.values()) {
2096
+ const parentId = node.event.parentId;
2097
+ if (parentId && nodes.has(parentId)) {
2098
+ nodes.get(parentId).children.push(node);
2099
+ } else {
2100
+ roots.push(node);
2101
+ }
2102
+ }
2103
+ const assignDepth = (n, depth) => {
2104
+ n.depth = depth;
2105
+ for (const c of n.children) assignDepth(c, depth + 1);
2106
+ };
2107
+ for (const r of roots) assignDepth(r, 0);
2108
+ const confidenceBreakdown = {
2109
+ explicit: 0,
2110
+ correlated: 0,
2111
+ heuristic: 0,
2112
+ unknown: 0
2113
+ };
2114
+ const kinds = {};
2115
+ for (const e of sorted) {
2116
+ inc(confidenceBreakdown, e.confidence);
2117
+ kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
2118
+ }
2119
+ const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
2120
+ const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
2121
+ const status = computeRunStatus(sorted);
2122
+ const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
2123
+ const name = sorted.find((e) => e.kind === "RUN")?.name;
2124
+ out.push({
2125
+ runId,
2126
+ name,
2127
+ status,
2128
+ startedAt,
2129
+ endedAt: status === "running" ? void 0 : endedAt,
2130
+ durationMs,
2131
+ children: roots,
2132
+ metadata: {
2133
+ totalEvents: sorted.length,
2134
+ confidenceBreakdown,
2135
+ kinds
2136
+ }
2137
+ });
2138
+ }
2139
+ out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
2140
+ return out;
2141
+ }
2142
+ };
2143
+
2063
2144
  // packages/core/src/persisted/to-inspect-event.ts
2064
2145
  function compactAttributes2(entries) {
2065
2146
  const out = {};
@@ -2198,86 +2279,6 @@ function persistedInspectEventsToInspectEvents(events, options) {
2198
2279
  return out;
2199
2280
  }
2200
2281
 
2201
- // packages/core/src/logs/tree-builder.ts
2202
- function inc(map, key) {
2203
- map[key] = (map[key] ?? 0) + 1;
2204
- }
2205
- function computeRunStatus(events) {
2206
- let hasRunning = false;
2207
- for (const e of events) {
2208
- if (e.status === "error") return "error";
2209
- if (e.status === "running") hasRunning = true;
2210
- }
2211
- if (hasRunning) return "running";
2212
- return "ok";
2213
- }
2214
- var TreeBuilder = class {
2215
- constructor(options) {
2216
- void options?.config;
2217
- }
2218
- build(events) {
2219
- const byRun = /* @__PURE__ */ new Map();
2220
- for (const e of events) {
2221
- if (!byRun.has(e.runId)) byRun.set(e.runId, []);
2222
- byRun.get(e.runId).push(e);
2223
- }
2224
- const out = [];
2225
- for (const [runId, runEvents] of byRun.entries()) {
2226
- const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
2227
- const nodes = /* @__PURE__ */ new Map();
2228
- for (const e of sorted) {
2229
- nodes.set(e.eventId, { event: e, children: [], depth: 0 });
2230
- }
2231
- const roots = [];
2232
- for (const node of nodes.values()) {
2233
- const parentId = node.event.parentId;
2234
- if (parentId && nodes.has(parentId)) {
2235
- nodes.get(parentId).children.push(node);
2236
- } else {
2237
- roots.push(node);
2238
- }
2239
- }
2240
- const assignDepth = (n, depth) => {
2241
- n.depth = depth;
2242
- for (const c of n.children) assignDepth(c, depth + 1);
2243
- };
2244
- for (const r of roots) assignDepth(r, 0);
2245
- const confidenceBreakdown = {
2246
- explicit: 0,
2247
- correlated: 0,
2248
- heuristic: 0,
2249
- unknown: 0
2250
- };
2251
- const kinds = {};
2252
- for (const e of sorted) {
2253
- inc(confidenceBreakdown, e.confidence);
2254
- kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
2255
- }
2256
- const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
2257
- const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
2258
- const status = computeRunStatus(sorted);
2259
- const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
2260
- const name = sorted.find((e) => e.kind === "RUN")?.name;
2261
- out.push({
2262
- runId,
2263
- name,
2264
- status,
2265
- startedAt,
2266
- endedAt: status === "running" ? void 0 : endedAt,
2267
- durationMs,
2268
- children: roots,
2269
- metadata: {
2270
- totalEvents: sorted.length,
2271
- confidenceBreakdown,
2272
- kinds
2273
- }
2274
- });
2275
- }
2276
- out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
2277
- return out;
2278
- }
2279
- };
2280
-
2281
2282
  // packages/core/src/persisted/tree-bridge.ts
2282
2283
  function persistedInspectEventsToRunTrees(events, options) {
2283
2284
  const inspectEvents = persistedInspectEventsToInspectEvents(events, {
@@ -2285,6 +2286,8 @@ function persistedInspectEventsToRunTrees(events, options) {
2285
2286
  });
2286
2287
  return new TreeBuilder().build(inspectEvents);
2287
2288
  }
2289
+
2290
+ // packages/core/src/readers/index.ts
2288
2291
  var DEFAULT_MAX_TRACE_INPUT_BYTES = 10 * 1024 * 1024;
2289
2292
  var MIN_DETECTION_CONFIDENCE = 0.5;
2290
2293
  var AMBIGUOUS_CONFIDENCE_DELTA = 0.05;
@@ -2407,7 +2410,7 @@ function findReaderByFormat(format, readers) {
2407
2410
  }
2408
2411
  async function jsonlFilesInDirectory(dirPath) {
2409
2412
  const entries = await readdir(dirPath, { withFileTypes: true });
2410
- return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => path7.join(dirPath, entry.name)).sort((a, b) => a.localeCompare(b));
2413
+ return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => path11.join(dirPath, entry.name)).sort((a, b) => a.localeCompare(b));
2411
2414
  }
2412
2415
  async function resolveInput(input) {
2413
2416
  const cached = resolvedInputCache.get(input);
@@ -3944,7 +3947,7 @@ function createViewerServer(options = {}) {
3944
3947
  return sendJson(res, 200, {
3945
3948
  ok: true,
3946
3949
  readOnly: true,
3947
- traceDir: path7.resolve(traceDir)
3950
+ traceDir: path11.resolve(traceDir)
3948
3951
  });
3949
3952
  }
3950
3953
  const td = new TraceDirectory({ dir: traceDir });
@@ -3962,7 +3965,7 @@ function createViewerServer(options = {}) {
3962
3965
  runId: meta.runId,
3963
3966
  name: meta.name,
3964
3967
  status: meta.status,
3965
- file: path7.basename(meta.filePath),
3968
+ file: path11.basename(meta.filePath),
3966
3969
  startedAt: meta.startedAt,
3967
3970
  durationMs: meta.durationMs
3968
3971
  }))
@@ -4077,7 +4080,7 @@ function startViewerServer(options = {}) {
4077
4080
  resolve({
4078
4081
  host,
4079
4082
  port: resolvedPort,
4080
- traceDir: path7.resolve(traceDir),
4083
+ traceDir: path11.resolve(traceDir),
4081
4084
  url: `http://${host}:${resolvedPort}`
4082
4085
  });
4083
4086
  });