agent-inspect 4.2.0 → 4.4.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/CHANGELOG.md +12 -0
- package/docs/API.md +3 -0
- package/docs/CLI.md +36 -0
- package/docs/SCHEMA.md +27 -1
- package/package.json +1 -1
- package/packages/cli/dist/{chunk-5VSPJEZ7.mjs → chunk-ORHDQUT6.mjs} +385 -10
- package/packages/cli/dist/chunk-ORHDQUT6.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +2548 -1567
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +2028 -1495
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-VQT7QLGV.mjs → src-FJOHPC4X.mjs} +3 -3
- package/packages/cli/dist/{src-VQT7QLGV.mjs.map → src-FJOHPC4X.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +397 -12
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.d.cts +105 -9
- package/packages/core/dist/advanced.d.ts +105 -9
- package/packages/core/dist/advanced.mjs +219 -17
- package/packages/core/dist/advanced.mjs.map +1 -1
- package/packages/core/dist/checks.cjs +117 -18
- package/packages/core/dist/checks.cjs.map +1 -1
- package/packages/core/dist/checks.d.cts +11 -3
- package/packages/core/dist/checks.d.ts +11 -3
- package/packages/core/dist/checks.mjs +42 -1
- package/packages/core/dist/checks.mjs.map +1 -1
- package/packages/core/dist/{chunk-2ZXEMWGK.mjs → chunk-3USJVBLA.mjs} +3 -3
- package/packages/core/dist/{chunk-2ZXEMWGK.mjs.map → chunk-3USJVBLA.mjs.map} +1 -1
- package/packages/core/dist/{chunk-HY7H3CQM.mjs → chunk-CAWPF22J.mjs} +4 -3
- package/packages/core/dist/chunk-CAWPF22J.mjs.map +1 -0
- package/packages/core/dist/{chunk-XUNJMAPD.mjs → chunk-KNYL56KZ.mjs} +38 -3
- package/packages/core/dist/chunk-KNYL56KZ.mjs.map +1 -0
- package/packages/core/dist/{chunk-IZBJAZGF.mjs → chunk-P366CCL2.mjs} +34 -3
- package/packages/core/dist/chunk-P366CCL2.mjs.map +1 -0
- package/packages/core/dist/{chunk-4JVGFNQH.mjs → chunk-ULCGIRTC.mjs} +95 -8
- package/packages/core/dist/chunk-ULCGIRTC.mjs.map +1 -0
- package/packages/core/dist/chunk-VFO76UH3.mjs +228 -0
- package/packages/core/dist/chunk-VFO76UH3.mjs.map +1 -0
- package/packages/core/dist/{chunk-NQZPZ2FN.mjs → chunk-WRE4CNPF.mjs} +6 -3
- package/packages/core/dist/chunk-WRE4CNPF.mjs.map +1 -0
- package/packages/core/dist/{chunk-A4V2H3YU.mjs → chunk-ZWA5RWMV.mjs} +40 -4
- package/packages/core/dist/chunk-ZWA5RWMV.mjs.map +1 -0
- package/packages/core/dist/{context-DjY-jvQk.d.cts → context-BbfkMYjz.d.cts} +5 -3
- package/packages/core/dist/{context-BDZmi53V.d.ts → context-Cp8NRbBX.d.ts} +5 -3
- package/packages/core/dist/diff.cjs.map +1 -1
- package/packages/core/dist/diff.d.cts +3 -3
- package/packages/core/dist/diff.d.ts +3 -3
- package/packages/core/dist/diff.mjs +1 -1
- package/packages/core/dist/exporters.cjs +137 -1
- package/packages/core/dist/exporters.cjs.map +1 -1
- package/packages/core/dist/exporters.d.cts +6 -3
- package/packages/core/dist/exporters.d.ts +6 -3
- package/packages/core/dist/exporters.mjs +71 -6
- package/packages/core/dist/exporters.mjs.map +1 -1
- package/packages/core/dist/index.cjs +181 -6
- package/packages/core/dist/index.cjs.map +1 -1
- package/packages/core/dist/index.d.cts +14 -7
- package/packages/core/dist/index.d.ts +14 -7
- package/packages/core/dist/index.mjs +51 -7
- package/packages/core/dist/index.mjs.map +1 -1
- package/packages/core/dist/{inspect-event-CYAV7Hxm.d.cts → inspect-event-IqwOHbGo.d.cts} +1 -1
- package/packages/core/dist/{inspect-event-CYAV7Hxm.d.ts → inspect-event-IqwOHbGo.d.ts} +1 -1
- package/packages/core/dist/{log-config-BNQ9UTmP.d.cts → log-config-CW8w5YQ9.d.cts} +1 -1
- package/packages/core/dist/{log-config-D3Yp1SZN.d.ts → log-config-SRA4xTp8.d.ts} +1 -1
- package/packages/core/dist/logs.d.cts +3 -3
- package/packages/core/dist/logs.d.ts +3 -3
- package/packages/core/dist/{persisted-inspect-event-BLvb0jSX.d.ts → persisted-inspect-event-DruwqARZ.d.ts} +1 -1
- package/packages/core/dist/{persisted-inspect-event-D5SjBz9b.d.cts → persisted-inspect-event-Gd-W8vB7.d.cts} +1 -1
- package/packages/core/dist/persisted.cjs +67 -1
- package/packages/core/dist/persisted.cjs.map +1 -1
- package/packages/core/dist/persisted.d.cts +5 -5
- package/packages/core/dist/persisted.d.ts +5 -5
- package/packages/core/dist/persisted.mjs +3 -3
- package/packages/core/dist/readers.cjs +72 -3
- package/packages/core/dist/readers.cjs.map +1 -1
- package/packages/core/dist/readers.d.cts +2 -2
- package/packages/core/dist/readers.d.ts +2 -2
- package/packages/core/dist/readers.mjs +5 -5
- package/packages/core/dist/readers.mjs.map +1 -1
- package/packages/core/dist/{types-CQun9LW6.d.ts → types-B1X87dUW.d.cts} +16 -2
- package/packages/core/dist/{types-C-llnPH0.d.cts → types-BVkjSd0q.d.ts} +16 -2
- package/packages/core/dist/types-CvsKGweN.d.cts +12 -0
- package/packages/core/dist/types-CvsKGweN.d.ts +12 -0
- package/packages/core/dist/writers.cjs +2 -1
- package/packages/core/dist/writers.cjs.map +1 -1
- package/packages/core/dist/writers.d.cts +2 -2
- package/packages/core/dist/writers.d.ts +2 -2
- package/packages/core/dist/writers.mjs +3 -4
- package/packages/core/dist/writers.mjs.map +1 -1
- package/packages/cli/dist/chunk-5VSPJEZ7.mjs.map +0 -1
- package/packages/core/dist/chunk-4JVGFNQH.mjs.map +0 -1
- package/packages/core/dist/chunk-A4V2H3YU.mjs.map +0 -1
- package/packages/core/dist/chunk-EDTQHZPM.mjs +0 -88
- package/packages/core/dist/chunk-EDTQHZPM.mjs.map +0 -1
- package/packages/core/dist/chunk-HY7H3CQM.mjs.map +0 -1
- package/packages/core/dist/chunk-IZBJAZGF.mjs.map +0 -1
- package/packages/core/dist/chunk-NQZPZ2FN.mjs.map +0 -1
- package/packages/core/dist/chunk-XUNJMAPD.mjs.map +0 -1
|
@@ -257,7 +257,8 @@ var INSPECT_KINDS = [
|
|
|
257
257
|
"RESULT",
|
|
258
258
|
"ERROR",
|
|
259
259
|
"LOGIC",
|
|
260
|
-
"LOG"
|
|
260
|
+
"LOG",
|
|
261
|
+
"OUTCOME"
|
|
261
262
|
];
|
|
262
263
|
var ATTRIBUTION_CONFIDENCES = [
|
|
263
264
|
"explicit",
|
|
@@ -585,6 +586,9 @@ function validateEvent(event) {
|
|
|
585
586
|
case "step_completed": {
|
|
586
587
|
return nonEmptyString(event.runId) && nonEmptyString(event.stepId) && (event.status === "success" || event.status === "error") && finiteNumber(event.endTime) && finiteNumber(event.durationMs) && optionalErrorInfo(event.error);
|
|
587
588
|
}
|
|
589
|
+
case "outcome_observed": {
|
|
590
|
+
return nonEmptyString(event.runId) && nonEmptyString(event.outcomeId) && nonEmptyString(event.name) && nonEmptyString(event.expectation) && (event.status === "passed" || event.status === "failed" || event.status === "unknown" || event.status === "skipped") && finiteNumber(event.observedAt);
|
|
591
|
+
}
|
|
588
592
|
default:
|
|
589
593
|
return false;
|
|
590
594
|
}
|
|
@@ -1316,9 +1320,100 @@ function createInspectorRuntime(options = {}) {
|
|
|
1316
1320
|
return runtime;
|
|
1317
1321
|
}
|
|
1318
1322
|
|
|
1323
|
+
// packages/core/src/outcomes/types.ts
|
|
1324
|
+
var OBSERVED_OUTCOME_METHODS = [
|
|
1325
|
+
"dom",
|
|
1326
|
+
"accessibility",
|
|
1327
|
+
"snapshot",
|
|
1328
|
+
"network",
|
|
1329
|
+
"storage",
|
|
1330
|
+
"filesystem",
|
|
1331
|
+
"database",
|
|
1332
|
+
"queue",
|
|
1333
|
+
"custom"
|
|
1334
|
+
];
|
|
1335
|
+
|
|
1336
|
+
// packages/core/src/outcomes/validate.ts
|
|
1337
|
+
function isRecord5(value) {
|
|
1338
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1339
|
+
}
|
|
1340
|
+
function normalizeName(name) {
|
|
1341
|
+
const trimmed = name.trim();
|
|
1342
|
+
if (trimmed === "") {
|
|
1343
|
+
throw new Error("observeOutcome requires a non-empty name.");
|
|
1344
|
+
}
|
|
1345
|
+
return trimmed.slice(0, 100);
|
|
1346
|
+
}
|
|
1347
|
+
function normalizeExpectation(value) {
|
|
1348
|
+
const trimmed = value.trim();
|
|
1349
|
+
if (trimmed === "") {
|
|
1350
|
+
throw new Error("observeOutcome requires a non-empty expectation.");
|
|
1351
|
+
}
|
|
1352
|
+
return trimmed.slice(0, 500);
|
|
1353
|
+
}
|
|
1354
|
+
function parseMethod(value) {
|
|
1355
|
+
if (value === void 0 || value.trim() === "") return void 0;
|
|
1356
|
+
const trimmed = value.trim().toLowerCase();
|
|
1357
|
+
if (OBSERVED_OUTCOME_METHODS.includes(trimmed)) {
|
|
1358
|
+
return trimmed;
|
|
1359
|
+
}
|
|
1360
|
+
throw new Error(`Unsupported observation method "${value}".`);
|
|
1361
|
+
}
|
|
1362
|
+
function parseObservedAt(value, fallback) {
|
|
1363
|
+
if (value === void 0) return fallback;
|
|
1364
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1365
|
+
if (typeof value === "string") {
|
|
1366
|
+
const parsed = Date.parse(value);
|
|
1367
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
1368
|
+
}
|
|
1369
|
+
return fallback;
|
|
1370
|
+
}
|
|
1371
|
+
function normalizeObserveOutcomeInput(name, options, nowMs = Date.now()) {
|
|
1372
|
+
return {
|
|
1373
|
+
name: normalizeName(name),
|
|
1374
|
+
expectation: normalizeExpectation(options.expectation),
|
|
1375
|
+
status: options.status,
|
|
1376
|
+
...options.method !== void 0 ? { method: parseMethod(options.method) } : {},
|
|
1377
|
+
...options.actual !== void 0 ? { actual: options.actual } : {},
|
|
1378
|
+
...options.evidence !== void 0 ? { evidence: options.evidence } : {},
|
|
1379
|
+
observedAt: parseObservedAt(options.observedAt, nowMs)
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
function boundPayload(value, opts) {
|
|
1383
|
+
if (value === void 0) return void 0;
|
|
1384
|
+
if (!isRecord5(value) && !Array.isArray(value)) {
|
|
1385
|
+
if (typeof value === "string") {
|
|
1386
|
+
return value.length > opts.maxMetadataValueLength ? `${value.slice(0, opts.maxMetadataValueLength)}\u2026` : value;
|
|
1387
|
+
}
|
|
1388
|
+
return value;
|
|
1389
|
+
}
|
|
1390
|
+
return prepareMetadataForDisk(
|
|
1391
|
+
isRecord5(value) ? value : { items: value },
|
|
1392
|
+
opts
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
function prepareOutcomeEventForDisk(event, opts) {
|
|
1396
|
+
const actual = boundPayload(event.actual, opts);
|
|
1397
|
+
const evidence = boundPayload(event.evidence, opts);
|
|
1398
|
+
const next = {
|
|
1399
|
+
...event,
|
|
1400
|
+
...actual !== void 0 ? { actual } : {},
|
|
1401
|
+
...evidence !== void 0 ? { evidence } : {}
|
|
1402
|
+
};
|
|
1403
|
+
if ("actual" in event && actual === void 0) {
|
|
1404
|
+
const { actual: _a, ...rest } = next;
|
|
1405
|
+
return rest;
|
|
1406
|
+
}
|
|
1407
|
+
if ("evidence" in event && evidence === void 0) {
|
|
1408
|
+
const { evidence: _e, ...rest } = next;
|
|
1409
|
+
return rest;
|
|
1410
|
+
}
|
|
1411
|
+
return next;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1319
1414
|
// packages/core/src/inspector.ts
|
|
1320
1415
|
var INSPECTOR_PERSISTED_SCHEMA_VERSION = "1.0";
|
|
1321
|
-
function
|
|
1416
|
+
function normalizeName2(name, fallback) {
|
|
1322
1417
|
if (typeof name !== "string" || name.trim() === "") return fallback;
|
|
1323
1418
|
return truncateName(name.trim(), 100);
|
|
1324
1419
|
}
|
|
@@ -1419,7 +1514,7 @@ function createInspector(options = {}) {
|
|
|
1419
1514
|
if (options.enabled === false) {
|
|
1420
1515
|
return Promise.resolve(fn());
|
|
1421
1516
|
}
|
|
1422
|
-
const runName =
|
|
1517
|
+
const runName = normalizeName2(name, "unnamed-run");
|
|
1423
1518
|
const runId = runOptions.runId ?? createRunId();
|
|
1424
1519
|
const traceDir = runOptions.traceDir ?? options.traceDir ?? getDefaultTraceDir();
|
|
1425
1520
|
const metadata = mergeMetadata(options.metadata, runOptions.metadata);
|
|
@@ -1499,7 +1594,7 @@ function createInspector(options = {}) {
|
|
|
1499
1594
|
return Promise.resolve(fn());
|
|
1500
1595
|
}
|
|
1501
1596
|
const context = runtime.getCurrentContext();
|
|
1502
|
-
const stepName =
|
|
1597
|
+
const stepName = normalizeName2(name, "unnamed-step");
|
|
1503
1598
|
const stepId = createStepId();
|
|
1504
1599
|
const parentId = runtime.getCurrentStepId();
|
|
1505
1600
|
const stepType = stepOptions.type ?? "logic";
|
|
@@ -1579,7 +1674,7 @@ function createInspector(options = {}) {
|
|
|
1579
1674
|
run,
|
|
1580
1675
|
step: step2,
|
|
1581
1676
|
tool(name, fn, toolOptions) {
|
|
1582
|
-
const toolName =
|
|
1677
|
+
const toolName = normalizeName2(name, "unknown-tool");
|
|
1583
1678
|
return step2(`tool:${toolName}`, fn, {
|
|
1584
1679
|
...toolOptions,
|
|
1585
1680
|
type: "tool",
|
|
@@ -1590,7 +1685,7 @@ function createInspector(options = {}) {
|
|
|
1590
1685
|
});
|
|
1591
1686
|
},
|
|
1592
1687
|
llm(name, fn, llmOptions) {
|
|
1593
|
-
const model =
|
|
1688
|
+
const model = normalizeName2(name, "unknown-model");
|
|
1594
1689
|
return step2(`llm:${model}`, fn, {
|
|
1595
1690
|
...llmOptions,
|
|
1596
1691
|
type: "llm",
|
|
@@ -1603,6 +1698,41 @@ function createInspector(options = {}) {
|
|
|
1603
1698
|
observe(name, fn, observeOptions) {
|
|
1604
1699
|
return async (...args) => step2(name, () => Promise.resolve(fn(...args)), observeOptions);
|
|
1605
1700
|
},
|
|
1701
|
+
async observeOutcome(name, outcomeOptions) {
|
|
1702
|
+
const ctx = runtime.getCurrentContext();
|
|
1703
|
+
if (!ctx) return;
|
|
1704
|
+
let normalized;
|
|
1705
|
+
try {
|
|
1706
|
+
normalized = normalizeObserveOutcomeInput(name, outcomeOptions);
|
|
1707
|
+
} catch {
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
const outcomeId = createStepId();
|
|
1711
|
+
const parentId = runtime.getCurrentStepId();
|
|
1712
|
+
await write({
|
|
1713
|
+
schemaVersion: INSPECTOR_PERSISTED_SCHEMA_VERSION,
|
|
1714
|
+
eventId: outcomeId,
|
|
1715
|
+
runId: ctx.runId,
|
|
1716
|
+
...parentId !== void 0 ? { parentId } : {},
|
|
1717
|
+
kind: "OUTCOME",
|
|
1718
|
+
name: normalized.name,
|
|
1719
|
+
status: normalized.status === "failed" ? "error" : "ok",
|
|
1720
|
+
timestamp: new Date(normalized.observedAt).toISOString(),
|
|
1721
|
+
confidence: "explicit",
|
|
1722
|
+
source: { type: "manual", name: "createInspector" },
|
|
1723
|
+
attributes: {
|
|
1724
|
+
legacyEvent: "outcome_observed",
|
|
1725
|
+
outcomeId,
|
|
1726
|
+
outcomeStatus: normalized.status,
|
|
1727
|
+
expectation: normalized.expectation,
|
|
1728
|
+
...normalized.method !== void 0 ? { method: normalized.method } : {},
|
|
1729
|
+
...normalized.actual !== void 0 ? { actual: normalized.actual } : {},
|
|
1730
|
+
...normalized.evidence !== void 0 ? { evidence: normalized.evidence } : {},
|
|
1731
|
+
observedAt: new Date(normalized.observedAt).toISOString()
|
|
1732
|
+
},
|
|
1733
|
+
...normalized.actual !== void 0 ? { outputSummary: normalized.actual } : {}
|
|
1734
|
+
});
|
|
1735
|
+
},
|
|
1606
1736
|
getDiagnostics() {
|
|
1607
1737
|
return runtime.getDiagnostics();
|
|
1608
1738
|
},
|
|
@@ -2692,11 +2822,56 @@ function observe(agent, options) {
|
|
|
2692
2822
|
}
|
|
2693
2823
|
}
|
|
2694
2824
|
|
|
2825
|
+
// packages/core/src/observe-outcome.ts
|
|
2826
|
+
async function safeWrite(label, op) {
|
|
2827
|
+
try {
|
|
2828
|
+
await op();
|
|
2829
|
+
} catch (error) {
|
|
2830
|
+
warn(`observeOutcome: ${label}`, error);
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
async function observeOutcome(name, options) {
|
|
2834
|
+
const context = getCurrentContext();
|
|
2835
|
+
if (!context) {
|
|
2836
|
+
warn("observeOutcome() called outside inspectRun(); skipping");
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2839
|
+
let normalized;
|
|
2840
|
+
try {
|
|
2841
|
+
normalized = normalizeObserveOutcomeInput(name, options);
|
|
2842
|
+
} catch (error) {
|
|
2843
|
+
warn("observeOutcome() invalid arguments", error);
|
|
2844
|
+
return;
|
|
2845
|
+
}
|
|
2846
|
+
const traceSafety = getTraceSafetyFromContext();
|
|
2847
|
+
const parentId = getParentStepId();
|
|
2848
|
+
const event = {
|
|
2849
|
+
schemaVersion: "0.1",
|
|
2850
|
+
event: "outcome_observed",
|
|
2851
|
+
timestamp: normalized.observedAt,
|
|
2852
|
+
runId: context.runId,
|
|
2853
|
+
outcomeId: createStepId(),
|
|
2854
|
+
...parentId !== void 0 ? { parentId } : {},
|
|
2855
|
+
name: normalized.name,
|
|
2856
|
+
expectation: normalized.expectation,
|
|
2857
|
+
status: normalized.status,
|
|
2858
|
+
...normalized.method !== void 0 ? { method: normalized.method } : {},
|
|
2859
|
+
...normalized.actual !== void 0 ? { actual: normalized.actual } : {},
|
|
2860
|
+
...normalized.evidence !== void 0 ? { evidence: normalized.evidence } : {},
|
|
2861
|
+
observedAt: normalized.observedAt
|
|
2862
|
+
};
|
|
2863
|
+
const prepared = traceSafety !== void 0 ? prepareOutcomeEventForDisk(event, traceSafety) : event;
|
|
2864
|
+
await safeWrite("writeTraceEvent", async () => {
|
|
2865
|
+
await writeTraceEvent(prepared, context.traceDir);
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2695
2869
|
exports.createInspector = createInspector;
|
|
2696
2870
|
exports.getCurrentCorrelationMetadata = getCurrentCorrelationMetadata;
|
|
2697
2871
|
exports.inspectRun = inspectRun;
|
|
2698
2872
|
exports.maybeInspectRun = maybeInspectRun;
|
|
2699
2873
|
exports.observe = observe;
|
|
2874
|
+
exports.observeOutcome = observeOutcome;
|
|
2700
2875
|
exports.step = step;
|
|
2701
2876
|
//# sourceMappingURL=index.cjs.map
|
|
2702
2877
|
//# sourceMappingURL=index.cjs.map
|