@agent-inspect/viewer 4.4.0 → 5.1.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.cjs +97 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +96 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var http = require('http');
|
|
4
|
-
var
|
|
4
|
+
var path11 = require('path');
|
|
5
5
|
var async_hooks = require('async_hooks');
|
|
6
6
|
require('crypto');
|
|
7
7
|
var promises = require('fs/promises');
|
|
@@ -10,10 +10,11 @@ require('nanoid');
|
|
|
10
10
|
require('chalk');
|
|
11
11
|
require('fs');
|
|
12
12
|
require('readline');
|
|
13
|
+
require('url');
|
|
13
14
|
|
|
14
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
+
var path11__default = /*#__PURE__*/_interopDefault(path11);
|
|
17
18
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
18
19
|
|
|
19
20
|
// packages/viewer/src/server.ts
|
|
@@ -524,7 +525,7 @@ function persistedInspectEventsToTraceEvents(events, options) {
|
|
|
524
525
|
}
|
|
525
526
|
var DEFAULT_TRACE_DIR_NAME = ".agent-inspect";
|
|
526
527
|
var RUNS_DIR_NAME = "runs";
|
|
527
|
-
var FALLBACK_TRACE_DIR =
|
|
528
|
+
var FALLBACK_TRACE_DIR = path11__default.default.join(
|
|
528
529
|
os__default.default.tmpdir(),
|
|
529
530
|
"agent-inspect",
|
|
530
531
|
RUNS_DIR_NAME
|
|
@@ -539,7 +540,7 @@ function getDefaultTraceDir() {
|
|
|
539
540
|
if (typeof home !== "string" || home.trim() === "") {
|
|
540
541
|
return FALLBACK_TRACE_DIR;
|
|
541
542
|
}
|
|
542
|
-
return
|
|
543
|
+
return path11__default.default.join(home, DEFAULT_TRACE_DIR_NAME, RUNS_DIR_NAME);
|
|
543
544
|
} catch {
|
|
544
545
|
return FALLBACK_TRACE_DIR;
|
|
545
546
|
}
|
|
@@ -748,7 +749,7 @@ var TraceDirectory = class {
|
|
|
748
749
|
this.#dir = resolveTraceDir(options);
|
|
749
750
|
}
|
|
750
751
|
getPath(filename) {
|
|
751
|
-
return filename ?
|
|
752
|
+
return filename ? path11__default.default.join(this.#dir, filename) : this.#dir;
|
|
752
753
|
}
|
|
753
754
|
async list() {
|
|
754
755
|
try {
|
|
@@ -775,7 +776,7 @@ function parseIsoToMs2(value) {
|
|
|
775
776
|
}
|
|
776
777
|
async function extractMetadata(filePath, _quickScan) {
|
|
777
778
|
const stats = await promises.stat(filePath);
|
|
778
|
-
let runIdFromFile =
|
|
779
|
+
let runIdFromFile = path11__default.default.basename(filePath);
|
|
779
780
|
if (runIdFromFile.endsWith(".jsonl")) {
|
|
780
781
|
runIdFromFile = runIdFromFile.slice(0, -".jsonl".length);
|
|
781
782
|
}
|
|
@@ -1385,12 +1386,12 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1385
1386
|
handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
|
|
1386
1387
|
);
|
|
1387
1388
|
const ordered = [...runs].sort(compareRuns);
|
|
1388
|
-
const
|
|
1389
|
+
const path12 = [];
|
|
1389
1390
|
const visited = /* @__PURE__ */ new Set();
|
|
1390
1391
|
const pushRun = (run, confidence, source) => {
|
|
1391
1392
|
if (visited.has(run.runId)) return;
|
|
1392
1393
|
visited.add(run.runId);
|
|
1393
|
-
|
|
1394
|
+
path12.push({
|
|
1394
1395
|
runId: run.runId,
|
|
1395
1396
|
name: run.name,
|
|
1396
1397
|
startedAt: run.startedAt,
|
|
@@ -1415,7 +1416,7 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1415
1416
|
const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
|
|
1416
1417
|
pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
|
|
1417
1418
|
}
|
|
1418
|
-
return
|
|
1419
|
+
return path12;
|
|
1419
1420
|
}
|
|
1420
1421
|
function metaRunIdMatches(run, token, runById) {
|
|
1421
1422
|
const meta = extractSessionWorkflowMetadata(run.metadata);
|
|
@@ -1688,7 +1689,7 @@ function summarize(findings, diagnostics) {
|
|
|
1688
1689
|
errors: diagnostics.filter((item) => item.severity === "error").length
|
|
1689
1690
|
};
|
|
1690
1691
|
}
|
|
1691
|
-
function eventEvidence(event,
|
|
1692
|
+
function eventEvidence(event, path12) {
|
|
1692
1693
|
return {
|
|
1693
1694
|
runId: event.runId,
|
|
1694
1695
|
eventId: event.eventId,
|
|
@@ -2067,6 +2068,86 @@ function traceEventsToPersistedInspectEvents(events, options) {
|
|
|
2067
2068
|
);
|
|
2068
2069
|
}
|
|
2069
2070
|
|
|
2071
|
+
// packages/core/src/logs/tree-builder.ts
|
|
2072
|
+
function inc(map, key) {
|
|
2073
|
+
map[key] = (map[key] ?? 0) + 1;
|
|
2074
|
+
}
|
|
2075
|
+
function computeRunStatus(events) {
|
|
2076
|
+
let hasRunning = false;
|
|
2077
|
+
for (const e of events) {
|
|
2078
|
+
if (e.status === "error") return "error";
|
|
2079
|
+
if (e.status === "running") hasRunning = true;
|
|
2080
|
+
}
|
|
2081
|
+
if (hasRunning) return "running";
|
|
2082
|
+
return "ok";
|
|
2083
|
+
}
|
|
2084
|
+
var TreeBuilder = class {
|
|
2085
|
+
constructor(options) {
|
|
2086
|
+
void options?.config;
|
|
2087
|
+
}
|
|
2088
|
+
build(events) {
|
|
2089
|
+
const byRun = /* @__PURE__ */ new Map();
|
|
2090
|
+
for (const e of events) {
|
|
2091
|
+
if (!byRun.has(e.runId)) byRun.set(e.runId, []);
|
|
2092
|
+
byRun.get(e.runId).push(e);
|
|
2093
|
+
}
|
|
2094
|
+
const out = [];
|
|
2095
|
+
for (const [runId, runEvents] of byRun.entries()) {
|
|
2096
|
+
const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
|
|
2097
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
2098
|
+
for (const e of sorted) {
|
|
2099
|
+
nodes.set(e.eventId, { event: e, children: [], depth: 0 });
|
|
2100
|
+
}
|
|
2101
|
+
const roots = [];
|
|
2102
|
+
for (const node of nodes.values()) {
|
|
2103
|
+
const parentId = node.event.parentId;
|
|
2104
|
+
if (parentId && nodes.has(parentId)) {
|
|
2105
|
+
nodes.get(parentId).children.push(node);
|
|
2106
|
+
} else {
|
|
2107
|
+
roots.push(node);
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
const assignDepth = (n, depth) => {
|
|
2111
|
+
n.depth = depth;
|
|
2112
|
+
for (const c of n.children) assignDepth(c, depth + 1);
|
|
2113
|
+
};
|
|
2114
|
+
for (const r of roots) assignDepth(r, 0);
|
|
2115
|
+
const confidenceBreakdown = {
|
|
2116
|
+
explicit: 0,
|
|
2117
|
+
correlated: 0,
|
|
2118
|
+
heuristic: 0,
|
|
2119
|
+
unknown: 0
|
|
2120
|
+
};
|
|
2121
|
+
const kinds = {};
|
|
2122
|
+
for (const e of sorted) {
|
|
2123
|
+
inc(confidenceBreakdown, e.confidence);
|
|
2124
|
+
kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
|
|
2125
|
+
}
|
|
2126
|
+
const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
|
|
2127
|
+
const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
|
|
2128
|
+
const status = computeRunStatus(sorted);
|
|
2129
|
+
const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
|
|
2130
|
+
const name = sorted.find((e) => e.kind === "RUN")?.name;
|
|
2131
|
+
out.push({
|
|
2132
|
+
runId,
|
|
2133
|
+
name,
|
|
2134
|
+
status,
|
|
2135
|
+
startedAt,
|
|
2136
|
+
endedAt: status === "running" ? void 0 : endedAt,
|
|
2137
|
+
durationMs,
|
|
2138
|
+
children: roots,
|
|
2139
|
+
metadata: {
|
|
2140
|
+
totalEvents: sorted.length,
|
|
2141
|
+
confidenceBreakdown,
|
|
2142
|
+
kinds
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
|
|
2147
|
+
return out;
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2070
2151
|
// packages/core/src/persisted/to-inspect-event.ts
|
|
2071
2152
|
function compactAttributes2(entries) {
|
|
2072
2153
|
const out = {};
|
|
@@ -2205,86 +2286,6 @@ function persistedInspectEventsToInspectEvents(events, options) {
|
|
|
2205
2286
|
return out;
|
|
2206
2287
|
}
|
|
2207
2288
|
|
|
2208
|
-
// packages/core/src/logs/tree-builder.ts
|
|
2209
|
-
function inc(map, key) {
|
|
2210
|
-
map[key] = (map[key] ?? 0) + 1;
|
|
2211
|
-
}
|
|
2212
|
-
function computeRunStatus(events) {
|
|
2213
|
-
let hasRunning = false;
|
|
2214
|
-
for (const e of events) {
|
|
2215
|
-
if (e.status === "error") return "error";
|
|
2216
|
-
if (e.status === "running") hasRunning = true;
|
|
2217
|
-
}
|
|
2218
|
-
if (hasRunning) return "running";
|
|
2219
|
-
return "ok";
|
|
2220
|
-
}
|
|
2221
|
-
var TreeBuilder = class {
|
|
2222
|
-
constructor(options) {
|
|
2223
|
-
void options?.config;
|
|
2224
|
-
}
|
|
2225
|
-
build(events) {
|
|
2226
|
-
const byRun = /* @__PURE__ */ new Map();
|
|
2227
|
-
for (const e of events) {
|
|
2228
|
-
if (!byRun.has(e.runId)) byRun.set(e.runId, []);
|
|
2229
|
-
byRun.get(e.runId).push(e);
|
|
2230
|
-
}
|
|
2231
|
-
const out = [];
|
|
2232
|
-
for (const [runId, runEvents] of byRun.entries()) {
|
|
2233
|
-
const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
|
|
2234
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
2235
|
-
for (const e of sorted) {
|
|
2236
|
-
nodes.set(e.eventId, { event: e, children: [], depth: 0 });
|
|
2237
|
-
}
|
|
2238
|
-
const roots = [];
|
|
2239
|
-
for (const node of nodes.values()) {
|
|
2240
|
-
const parentId = node.event.parentId;
|
|
2241
|
-
if (parentId && nodes.has(parentId)) {
|
|
2242
|
-
nodes.get(parentId).children.push(node);
|
|
2243
|
-
} else {
|
|
2244
|
-
roots.push(node);
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
const assignDepth = (n, depth) => {
|
|
2248
|
-
n.depth = depth;
|
|
2249
|
-
for (const c of n.children) assignDepth(c, depth + 1);
|
|
2250
|
-
};
|
|
2251
|
-
for (const r of roots) assignDepth(r, 0);
|
|
2252
|
-
const confidenceBreakdown = {
|
|
2253
|
-
explicit: 0,
|
|
2254
|
-
correlated: 0,
|
|
2255
|
-
heuristic: 0,
|
|
2256
|
-
unknown: 0
|
|
2257
|
-
};
|
|
2258
|
-
const kinds = {};
|
|
2259
|
-
for (const e of sorted) {
|
|
2260
|
-
inc(confidenceBreakdown, e.confidence);
|
|
2261
|
-
kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
|
|
2262
|
-
}
|
|
2263
|
-
const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
|
|
2264
|
-
const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
|
|
2265
|
-
const status = computeRunStatus(sorted);
|
|
2266
|
-
const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
|
|
2267
|
-
const name = sorted.find((e) => e.kind === "RUN")?.name;
|
|
2268
|
-
out.push({
|
|
2269
|
-
runId,
|
|
2270
|
-
name,
|
|
2271
|
-
status,
|
|
2272
|
-
startedAt,
|
|
2273
|
-
endedAt: status === "running" ? void 0 : endedAt,
|
|
2274
|
-
durationMs,
|
|
2275
|
-
children: roots,
|
|
2276
|
-
metadata: {
|
|
2277
|
-
totalEvents: sorted.length,
|
|
2278
|
-
confidenceBreakdown,
|
|
2279
|
-
kinds
|
|
2280
|
-
}
|
|
2281
|
-
});
|
|
2282
|
-
}
|
|
2283
|
-
out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
|
|
2284
|
-
return out;
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
|
|
2288
2289
|
// packages/core/src/persisted/tree-bridge.ts
|
|
2289
2290
|
function persistedInspectEventsToRunTrees(events, options) {
|
|
2290
2291
|
const inspectEvents = persistedInspectEventsToInspectEvents(events, {
|
|
@@ -2292,6 +2293,8 @@ function persistedInspectEventsToRunTrees(events, options) {
|
|
|
2292
2293
|
});
|
|
2293
2294
|
return new TreeBuilder().build(inspectEvents);
|
|
2294
2295
|
}
|
|
2296
|
+
|
|
2297
|
+
// packages/core/src/readers/index.ts
|
|
2295
2298
|
var DEFAULT_MAX_TRACE_INPUT_BYTES = 10 * 1024 * 1024;
|
|
2296
2299
|
var MIN_DETECTION_CONFIDENCE = 0.5;
|
|
2297
2300
|
var AMBIGUOUS_CONFIDENCE_DELTA = 0.05;
|
|
@@ -2414,7 +2417,7 @@ function findReaderByFormat(format, readers) {
|
|
|
2414
2417
|
}
|
|
2415
2418
|
async function jsonlFilesInDirectory(dirPath) {
|
|
2416
2419
|
const entries = await promises.readdir(dirPath, { withFileTypes: true });
|
|
2417
|
-
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) =>
|
|
2420
|
+
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => path11__default.default.join(dirPath, entry.name)).sort((a, b) => a.localeCompare(b));
|
|
2418
2421
|
}
|
|
2419
2422
|
async function resolveInput(input) {
|
|
2420
2423
|
const cached = resolvedInputCache.get(input);
|
|
@@ -3951,7 +3954,7 @@ function createViewerServer(options = {}) {
|
|
|
3951
3954
|
return sendJson(res, 200, {
|
|
3952
3955
|
ok: true,
|
|
3953
3956
|
readOnly: true,
|
|
3954
|
-
traceDir:
|
|
3957
|
+
traceDir: path11__default.default.resolve(traceDir)
|
|
3955
3958
|
});
|
|
3956
3959
|
}
|
|
3957
3960
|
const td = new TraceDirectory({ dir: traceDir });
|
|
@@ -3969,7 +3972,7 @@ function createViewerServer(options = {}) {
|
|
|
3969
3972
|
runId: meta.runId,
|
|
3970
3973
|
name: meta.name,
|
|
3971
3974
|
status: meta.status,
|
|
3972
|
-
file:
|
|
3975
|
+
file: path11__default.default.basename(meta.filePath),
|
|
3973
3976
|
startedAt: meta.startedAt,
|
|
3974
3977
|
durationMs: meta.durationMs
|
|
3975
3978
|
}))
|
|
@@ -4084,7 +4087,7 @@ function startViewerServer(options = {}) {
|
|
|
4084
4087
|
resolve({
|
|
4085
4088
|
host,
|
|
4086
4089
|
port: resolvedPort,
|
|
4087
|
-
traceDir:
|
|
4090
|
+
traceDir: path11__default.default.resolve(traceDir),
|
|
4088
4091
|
url: `http://${host}:${resolvedPort}`
|
|
4089
4092
|
});
|
|
4090
4093
|
});
|