@agent-inspect/viewer 6.14.0 → 6.14.2
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 +155 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +155 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -2
package/dist/index.mjs
CHANGED
|
@@ -2216,6 +2216,28 @@ async function resolveSuiteCaseTrace(suiteCase, options) {
|
|
|
2216
2216
|
};
|
|
2217
2217
|
}
|
|
2218
2218
|
|
|
2219
|
+
// packages/core/src/safety/sensitive-key.ts
|
|
2220
|
+
function normalizeSensitiveKey(value) {
|
|
2221
|
+
return value.toLowerCase().replace(/[^a-z0-9_]/g, "");
|
|
2222
|
+
}
|
|
2223
|
+
new Set(
|
|
2224
|
+
[
|
|
2225
|
+
"tokens",
|
|
2226
|
+
"max_tokens",
|
|
2227
|
+
"min_tokens",
|
|
2228
|
+
"ls_max_tokens",
|
|
2229
|
+
"token_count",
|
|
2230
|
+
"token_limit",
|
|
2231
|
+
"token_budget",
|
|
2232
|
+
"input_tokens",
|
|
2233
|
+
"output_tokens",
|
|
2234
|
+
"total_tokens",
|
|
2235
|
+
"cached_tokens",
|
|
2236
|
+
"prompt_tokens",
|
|
2237
|
+
"completion_tokens"
|
|
2238
|
+
].map(normalizeSensitiveKey)
|
|
2239
|
+
);
|
|
2240
|
+
|
|
2219
2241
|
// packages/core/src/checks/logical-events.ts
|
|
2220
2242
|
function isRecord5(value) {
|
|
2221
2243
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -2411,6 +2433,23 @@ function projectLogicalEvents(events) {
|
|
|
2411
2433
|
}
|
|
2412
2434
|
}
|
|
2413
2435
|
if (!remapped) {
|
|
2436
|
+
if (originalParentId === event.eventId) {
|
|
2437
|
+
diagnostics.push({
|
|
2438
|
+
code: "AI_LOGICAL_SELF_PARENT_REMOVED",
|
|
2439
|
+
message: `Removed self-parent edge on ${event.eventId}.`,
|
|
2440
|
+
eventIds: [event.eventId]
|
|
2441
|
+
});
|
|
2442
|
+
const { parentId: _drop, ...rest } = event;
|
|
2443
|
+
normalized.push({
|
|
2444
|
+
...rest,
|
|
2445
|
+
projection: {
|
|
2446
|
+
...event.projection,
|
|
2447
|
+
parentNormalized: true,
|
|
2448
|
+
originalParentId
|
|
2449
|
+
}
|
|
2450
|
+
});
|
|
2451
|
+
continue;
|
|
2452
|
+
}
|
|
2414
2453
|
if (!logicalById.has(originalParentId) && !logicalByRawId.has(originalParentId)) {
|
|
2415
2454
|
const mapping = event.attributes?.parentMapping;
|
|
2416
2455
|
const unresolved = mapping === "unresolved" || event.attributes?.parentUnresolved === true || event.attributes?.unresolvedParent === true || // LangGraph/framework scaffolding sentinel labels are not event ids.
|
|
@@ -2426,6 +2465,23 @@ function projectLogicalEvents(events) {
|
|
|
2426
2465
|
normalized.push(event);
|
|
2427
2466
|
continue;
|
|
2428
2467
|
}
|
|
2468
|
+
if (nextParent === event.eventId) {
|
|
2469
|
+
diagnostics.push({
|
|
2470
|
+
code: "AI_LOGICAL_SELF_PARENT_REMOVED",
|
|
2471
|
+
message: `Removed self-parent edge on ${event.eventId} (was ${originalParentId}).`,
|
|
2472
|
+
eventIds: [event.eventId]
|
|
2473
|
+
});
|
|
2474
|
+
const { parentId: _drop, ...rest } = event;
|
|
2475
|
+
normalized.push({
|
|
2476
|
+
...rest,
|
|
2477
|
+
projection: {
|
|
2478
|
+
...event.projection,
|
|
2479
|
+
parentNormalized: true,
|
|
2480
|
+
originalParentId
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
continue;
|
|
2484
|
+
}
|
|
2429
2485
|
diagnostics.push({
|
|
2430
2486
|
code: "AI_LOGICAL_PARENT_REMAPPED",
|
|
2431
2487
|
message: `Remapped parent ${originalParentId} \u2192 ${nextParent} for ${event.eventId}.`,
|
|
@@ -2819,7 +2875,7 @@ function createToolUsageRule(options) {
|
|
|
2819
2875
|
}
|
|
2820
2876
|
}
|
|
2821
2877
|
const forbidden = new Set(options.forbidden ?? []);
|
|
2822
|
-
const allowed = options.allowed ? new Set(options.allowed) : void 0;
|
|
2878
|
+
const allowed = options.allowed?.length ? new Set(options.allowed) : void 0;
|
|
2823
2879
|
for (const event of tools) {
|
|
2824
2880
|
const name = toolName(event);
|
|
2825
2881
|
if (forbidden.has(name)) {
|
|
@@ -2855,9 +2911,9 @@ function createLlmUsageRule(options) {
|
|
|
2855
2911
|
evaluate(context) {
|
|
2856
2912
|
const llms = finishedEvents(context, "LLM");
|
|
2857
2913
|
const findings = [];
|
|
2858
|
-
const allowedModels = options.allowedModels ? new Set(options.allowedModels) : void 0;
|
|
2859
|
-
const allowedProviders = options.allowedProviders ? new Set(options.allowedProviders) : void 0;
|
|
2860
|
-
const finishReasons = options.finishReasons ? new Set(options.finishReasons) : void 0;
|
|
2914
|
+
const allowedModels = options.allowedModels?.length ? new Set(options.allowedModels) : void 0;
|
|
2915
|
+
const allowedProviders = options.allowedProviders?.length ? new Set(options.allowedProviders) : void 0;
|
|
2916
|
+
const finishReasons = options.finishReasons?.length ? new Set(options.finishReasons) : void 0;
|
|
2861
2917
|
if (options.maxCalls !== void 0 && llms.length > options.maxCalls) {
|
|
2862
2918
|
findings.push(
|
|
2863
2919
|
failFinding(
|
|
@@ -3272,6 +3328,20 @@ function traceEventsToPersistedInspectEvents(events, options) {
|
|
|
3272
3328
|
function inc(map, key) {
|
|
3273
3329
|
map[key] = (map[key] ?? 0) + 1;
|
|
3274
3330
|
}
|
|
3331
|
+
function confidenceRank(confidence) {
|
|
3332
|
+
switch (confidence) {
|
|
3333
|
+
case "unknown":
|
|
3334
|
+
return 0;
|
|
3335
|
+
case "heuristic":
|
|
3336
|
+
return 1;
|
|
3337
|
+
case "correlated":
|
|
3338
|
+
return 2;
|
|
3339
|
+
case "explicit":
|
|
3340
|
+
return 3;
|
|
3341
|
+
default:
|
|
3342
|
+
return 0;
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3275
3345
|
function computeRunStatus(events) {
|
|
3276
3346
|
let runTerminal;
|
|
3277
3347
|
let sawRunEvent = false;
|
|
@@ -3292,6 +3362,84 @@ function computeRunStatus(events) {
|
|
|
3292
3362
|
}
|
|
3293
3363
|
return hasRunning ? "running" : "ok";
|
|
3294
3364
|
}
|
|
3365
|
+
function linkNodesVisibilityFirst(nodes) {
|
|
3366
|
+
let selfParentCount = 0;
|
|
3367
|
+
let unresolvedParentCount = 0;
|
|
3368
|
+
let normalizedEdgeCount = 0;
|
|
3369
|
+
let cycleCount = 0;
|
|
3370
|
+
const pending = [];
|
|
3371
|
+
for (const node of nodes.values()) {
|
|
3372
|
+
const parentId = node.event.parentId;
|
|
3373
|
+
if (!parentId) continue;
|
|
3374
|
+
if (parentId === node.event.eventId) {
|
|
3375
|
+
selfParentCount += 1;
|
|
3376
|
+
normalizedEdgeCount += 1;
|
|
3377
|
+
continue;
|
|
3378
|
+
}
|
|
3379
|
+
if (!nodes.has(parentId)) {
|
|
3380
|
+
unresolvedParentCount += 1;
|
|
3381
|
+
continue;
|
|
3382
|
+
}
|
|
3383
|
+
pending.push({
|
|
3384
|
+
childId: node.event.eventId,
|
|
3385
|
+
parentId,
|
|
3386
|
+
childTimestamp: node.event.timestamp,
|
|
3387
|
+
childConfidence: node.event.confidence
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
pending.sort((a, b) => {
|
|
3391
|
+
const conf = confidenceRank(b.childConfidence) - confidenceRank(a.childConfidence);
|
|
3392
|
+
if (conf !== 0) return conf;
|
|
3393
|
+
return a.childTimestamp - b.childTimestamp;
|
|
3394
|
+
});
|
|
3395
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
3396
|
+
for (const edge of pending) {
|
|
3397
|
+
parentOf.set(edge.childId, edge.parentId);
|
|
3398
|
+
let cursor = edge.parentId;
|
|
3399
|
+
const seen = /* @__PURE__ */ new Set([edge.childId]);
|
|
3400
|
+
let cyclic = false;
|
|
3401
|
+
while (cursor) {
|
|
3402
|
+
if (seen.has(cursor)) {
|
|
3403
|
+
cyclic = true;
|
|
3404
|
+
break;
|
|
3405
|
+
}
|
|
3406
|
+
seen.add(cursor);
|
|
3407
|
+
cursor = parentOf.get(cursor);
|
|
3408
|
+
}
|
|
3409
|
+
if (cyclic) {
|
|
3410
|
+
parentOf.delete(edge.childId);
|
|
3411
|
+
cycleCount += 1;
|
|
3412
|
+
normalizedEdgeCount += 1;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
for (const [childId, parentId] of parentOf) {
|
|
3416
|
+
nodes.get(parentId).children.push(nodes.get(childId));
|
|
3417
|
+
}
|
|
3418
|
+
const roots = [];
|
|
3419
|
+
for (const node of nodes.values()) {
|
|
3420
|
+
if (!parentOf.has(node.event.eventId)) {
|
|
3421
|
+
roots.push(node);
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
const assignDepth = (n, depth, stack) => {
|
|
3425
|
+
if (stack.has(n.event.eventId)) return;
|
|
3426
|
+
n.depth = depth;
|
|
3427
|
+
stack.add(n.event.eventId);
|
|
3428
|
+
for (const c of n.children) assignDepth(c, depth + 1, stack);
|
|
3429
|
+
stack.delete(n.event.eventId);
|
|
3430
|
+
};
|
|
3431
|
+
for (const r of roots) assignDepth(r, 0, /* @__PURE__ */ new Set());
|
|
3432
|
+
return {
|
|
3433
|
+
roots,
|
|
3434
|
+
summary: {
|
|
3435
|
+
rootCount: roots.length,
|
|
3436
|
+
selfParentCount,
|
|
3437
|
+
cycleCount,
|
|
3438
|
+
unresolvedParentCount,
|
|
3439
|
+
normalizedEdgeCount
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
}
|
|
3295
3443
|
var TreeBuilder = class {
|
|
3296
3444
|
constructor(options) {
|
|
3297
3445
|
void options?.config;
|
|
@@ -3309,20 +3457,7 @@ var TreeBuilder = class {
|
|
|
3309
3457
|
for (const e of sorted) {
|
|
3310
3458
|
nodes.set(e.eventId, { event: e, children: [], depth: 0 });
|
|
3311
3459
|
}
|
|
3312
|
-
const roots =
|
|
3313
|
-
for (const node of nodes.values()) {
|
|
3314
|
-
const parentId = node.event.parentId;
|
|
3315
|
-
if (parentId && nodes.has(parentId)) {
|
|
3316
|
-
nodes.get(parentId).children.push(node);
|
|
3317
|
-
} else {
|
|
3318
|
-
roots.push(node);
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
const assignDepth = (n, depth) => {
|
|
3322
|
-
n.depth = depth;
|
|
3323
|
-
for (const c of n.children) assignDepth(c, depth + 1);
|
|
3324
|
-
};
|
|
3325
|
-
for (const r of roots) assignDepth(r, 0);
|
|
3460
|
+
const { roots, summary } = linkNodesVisibilityFirst(nodes);
|
|
3326
3461
|
const confidenceBreakdown = {
|
|
3327
3462
|
explicit: 0,
|
|
3328
3463
|
correlated: 0,
|
|
@@ -3350,7 +3485,8 @@ var TreeBuilder = class {
|
|
|
3350
3485
|
metadata: {
|
|
3351
3486
|
totalEvents: sorted.length,
|
|
3352
3487
|
confidenceBreakdown,
|
|
3353
|
-
kinds
|
|
3488
|
+
kinds,
|
|
3489
|
+
relationshipSummary: summary
|
|
3354
3490
|
}
|
|
3355
3491
|
});
|
|
3356
3492
|
}
|