@ls-stack/agent-eval 0.55.0 → 0.55.1
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/{app-CunZ8Dku.mjs → app-BD0D9-7k.mjs} +87 -4
- package/dist/bin.mjs +1 -1
- package/dist/caseChild.mjs +167 -0
- package/dist/{cli-rvPrUj6S.mjs → cli-BR3wMZMx.mjs} +4 -3
- package/dist/index.d.mts +115 -115
- package/dist/index.mjs +3 -3
- package/dist/runChild.mjs +3 -1
- package/dist/{runOrchestration-BWyE5lRX.mjs → runExecution-Sw38bCaq.mjs} +31 -1495
- package/dist/runOrchestration-DJsdLYeZ.mjs +1596 -0
- package/dist/{runner-CFQ8LZmY.mjs → runner-72rsqJRq.mjs} +2 -2
- package/dist/{runner-C2fvjKZP.mjs → runner-dB69WsnM.mjs} +1 -1
- package/dist/{src-DEENkbkn.mjs → src-hBGtzWuA.mjs} +2 -2
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
10
10
|
import { getCompositeKey } from "@ls-stack/utils/getCompositeKey";
|
|
11
11
|
import { existsSync } from "node:fs";
|
|
12
12
|
import { brotliCompressSync, brotliDecompressSync } from "node:zlib";
|
|
13
|
-
import {
|
|
13
|
+
import { resultify } from "t-result";
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
15
|
//#region ../sdk/src/defineEval.ts
|
|
16
16
|
const evalRegistry = /* @__PURE__ */ new Map();
|
|
@@ -1692,10 +1692,10 @@ function evaluateTagExpression(expression, tags) {
|
|
|
1692
1692
|
}
|
|
1693
1693
|
function tagMatchesPattern(tag, pattern) {
|
|
1694
1694
|
if (!pattern.includes("*")) return tag === pattern;
|
|
1695
|
-
const source = pattern.split("*").map(escapeRegex
|
|
1695
|
+
const source = pattern.split("*").map(escapeRegex).join(".*");
|
|
1696
1696
|
return new RegExp(`^${source}$`).test(tag);
|
|
1697
1697
|
}
|
|
1698
|
-
function escapeRegex
|
|
1698
|
+
function escapeRegex(value) {
|
|
1699
1699
|
return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
1700
1700
|
}
|
|
1701
1701
|
//#endregion
|
|
@@ -4928,6 +4928,9 @@ const externalJsonCacheSerializationMarker = "v1:ExternalJson";
|
|
|
4928
4928
|
const externalJsonBlobExtension = ".json.br";
|
|
4929
4929
|
const cacheEntryExtension = ".json.br";
|
|
4930
4930
|
const debugEntryExtension = ".json";
|
|
4931
|
+
async function commitPendingCacheWrites(params) {
|
|
4932
|
+
for (const pendingWrite of params.pendingWrites) await params.backingStore.write(pendingWrite.entry, pendingWrite.debugKey);
|
|
4933
|
+
}
|
|
4931
4934
|
/**
|
|
4932
4935
|
* Create a filesystem-backed cache adapter rooted at `<workspaceRoot>/<dir>`.
|
|
4933
4936
|
*
|
|
@@ -5068,10 +5071,16 @@ function createBufferedCacheStore(backingStore) {
|
|
|
5068
5071
|
return Promise.resolve();
|
|
5069
5072
|
},
|
|
5070
5073
|
async commit() {
|
|
5071
|
-
|
|
5074
|
+
await commitPendingCacheWrites({
|
|
5075
|
+
backingStore,
|
|
5076
|
+
pendingWrites: [...pendingEntries.values()].map((pending) => ({ ...pending }))
|
|
5077
|
+
});
|
|
5072
5078
|
},
|
|
5073
5079
|
getPendingEntries() {
|
|
5074
5080
|
return [...pendingEntries.values()].map((pending) => pending.entry);
|
|
5081
|
+
},
|
|
5082
|
+
getPendingWrites() {
|
|
5083
|
+
return [...pendingEntries.values()].map((pending) => ({ ...pending }));
|
|
5075
5084
|
}
|
|
5076
5085
|
};
|
|
5077
5086
|
}
|
|
@@ -5412,80 +5421,6 @@ function isRecordLike(value) {
|
|
|
5412
5421
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5413
5422
|
}
|
|
5414
5423
|
//#endregion
|
|
5415
|
-
//#region ../runner/src/chartValidation.ts
|
|
5416
|
-
function isValidColumnMetric(metric, columnsByKey, evalId, warnings) {
|
|
5417
|
-
const columnDef = columnsByKey.get(metric.key);
|
|
5418
|
-
if (!columnDef) {
|
|
5419
|
-
warnings.push(`[${evalId}] chart metric references unknown column "${metric.key}" — dropped`);
|
|
5420
|
-
return false;
|
|
5421
|
-
}
|
|
5422
|
-
if (metric.aggregate === "passThresholdRate") {
|
|
5423
|
-
if (columnDef.isScore !== true || typeof columnDef.passThreshold !== "number") {
|
|
5424
|
-
warnings.push(`[${evalId}] chart metric "${metric.key}" uses "passThresholdRate" but the column is not a score with passThreshold — dropped`);
|
|
5425
|
-
return false;
|
|
5426
|
-
}
|
|
5427
|
-
}
|
|
5428
|
-
return true;
|
|
5429
|
-
}
|
|
5430
|
-
function isValidTooltipExtra(extra, columnsByKey, evalId, warnings) {
|
|
5431
|
-
const columnDef = columnsByKey.get(extra.key);
|
|
5432
|
-
if (!columnDef) {
|
|
5433
|
-
warnings.push(`[${evalId}] chart tooltip extra references unknown column "${extra.key}" — dropped`);
|
|
5434
|
-
return false;
|
|
5435
|
-
}
|
|
5436
|
-
if (extra.aggregate === "passThresholdRate") {
|
|
5437
|
-
if (columnDef.isScore !== true || typeof columnDef.passThreshold !== "number") {
|
|
5438
|
-
warnings.push(`[${evalId}] chart tooltip extra "${extra.key}" uses "passThresholdRate" but the column is not a score with passThreshold — dropped`);
|
|
5439
|
-
return false;
|
|
5440
|
-
}
|
|
5441
|
-
}
|
|
5442
|
-
return true;
|
|
5443
|
-
}
|
|
5444
|
-
function sanitizeChart(chart, columnsByKey, evalId, warnings) {
|
|
5445
|
-
const metrics = chart.metrics.filter((metric) => {
|
|
5446
|
-
if (metric.source === "builtin") return true;
|
|
5447
|
-
return isValidColumnMetric(metric, columnsByKey, evalId, warnings);
|
|
5448
|
-
});
|
|
5449
|
-
if (metrics.length === 0) {
|
|
5450
|
-
warnings.push(`[${evalId}] chart had no valid metrics after validation — chart dropped`);
|
|
5451
|
-
return null;
|
|
5452
|
-
}
|
|
5453
|
-
const tooltipExtras = chart.tooltipExtras?.filter((extra) => {
|
|
5454
|
-
if (extra.source === "builtin") return true;
|
|
5455
|
-
return isValidTooltipExtra(extra, columnsByKey, evalId, warnings);
|
|
5456
|
-
});
|
|
5457
|
-
return {
|
|
5458
|
-
...chart,
|
|
5459
|
-
metrics,
|
|
5460
|
-
tooltipExtras: tooltipExtras?.length ? tooltipExtras : void 0
|
|
5461
|
-
};
|
|
5462
|
-
}
|
|
5463
|
-
/**
|
|
5464
|
-
* Validate and sanitize an authored `charts` config against the eval's
|
|
5465
|
-
* declared columns. Drops metrics/extras that reference unknown columns or
|
|
5466
|
-
* misuse `passThresholdRate`, and drops entire charts whose metrics are all
|
|
5467
|
-
* invalid. Returns `charts: undefined` when nothing valid remains so the UI
|
|
5468
|
-
* falls back to rendering no chart (matching the opt-in default).
|
|
5469
|
-
*/
|
|
5470
|
-
function validateCharts(params) {
|
|
5471
|
-
const { charts, columnDefs, evalId } = params;
|
|
5472
|
-
if (!charts || charts.length === 0) return {
|
|
5473
|
-
charts: void 0,
|
|
5474
|
-
warnings: []
|
|
5475
|
-
};
|
|
5476
|
-
const columnsByKey = new Map(columnDefs.map((def) => [def.key, def]));
|
|
5477
|
-
const warnings = [];
|
|
5478
|
-
const sanitized = [];
|
|
5479
|
-
for (const chart of charts) {
|
|
5480
|
-
const result = sanitizeChart(chart, columnsByKey, evalId, warnings);
|
|
5481
|
-
if (result) sanitized.push(result);
|
|
5482
|
-
}
|
|
5483
|
-
return {
|
|
5484
|
-
charts: sanitized.length > 0 ? sanitized : void 0,
|
|
5485
|
-
warnings
|
|
5486
|
-
};
|
|
5487
|
-
}
|
|
5488
|
-
//#endregion
|
|
5489
5424
|
//#region ../runner/src/columnBuilder.ts
|
|
5490
5425
|
/**
|
|
5491
5426
|
* Normalize a user-provided score definition (either a function or an
|
|
@@ -5991,112 +5926,6 @@ function addDefaultOutputs(params) {
|
|
|
5991
5926
|
});
|
|
5992
5927
|
}
|
|
5993
5928
|
//#endregion
|
|
5994
|
-
//#region ../runner/src/discovery.ts
|
|
5995
|
-
const evalIdMatchRegex = /\bid\s*:\s*['"]([^'"]+)['"]/;
|
|
5996
|
-
const evalTitleMatchRegex = /\btitle\s*:\s*['"]([^'"]+)['"]/;
|
|
5997
|
-
/** Parse static eval metadata and discovery issues from one eval file. */
|
|
5998
|
-
function parseEvalDiscovery(filePath, content) {
|
|
5999
|
-
const metas = [];
|
|
6000
|
-
let searchIndex = 0;
|
|
6001
|
-
while (searchIndex < content.length) {
|
|
6002
|
-
const defineEvalIndex = content.indexOf("defineEval", searchIndex);
|
|
6003
|
-
if (defineEvalIndex === -1) break;
|
|
6004
|
-
const extracted = extractDefineEvalObject(content, defineEvalIndex);
|
|
6005
|
-
if (!extracted) {
|
|
6006
|
-
searchIndex = defineEvalIndex + 10;
|
|
6007
|
-
continue;
|
|
6008
|
-
}
|
|
6009
|
-
const id = evalIdMatchRegex.exec(extracted.objectText)?.[1];
|
|
6010
|
-
if (id !== void 0) {
|
|
6011
|
-
const result = {
|
|
6012
|
-
filePath,
|
|
6013
|
-
id
|
|
6014
|
-
};
|
|
6015
|
-
const title = evalTitleMatchRegex.exec(extracted.objectText)?.[1];
|
|
6016
|
-
if (title !== void 0) result.title = title;
|
|
6017
|
-
metas.push(result);
|
|
6018
|
-
}
|
|
6019
|
-
searchIndex = extracted.nextIndex;
|
|
6020
|
-
}
|
|
6021
|
-
const countsById = /* @__PURE__ */ new Map();
|
|
6022
|
-
for (const meta of metas) countsById.set(meta.id, (countsById.get(meta.id) ?? 0) + 1);
|
|
6023
|
-
const duplicateIds = new Set([...countsById].filter(([, count]) => count > 1).map(([id]) => id));
|
|
6024
|
-
const issues = [...duplicateIds].map((evalId) => ({
|
|
6025
|
-
type: "duplicate-eval-id",
|
|
6026
|
-
severity: "error",
|
|
6027
|
-
filePath,
|
|
6028
|
-
evalId,
|
|
6029
|
-
message: `Duplicate eval id "${evalId}" in ${filePath}. Eval ids must be unique within one file.`
|
|
6030
|
-
}));
|
|
6031
|
-
return {
|
|
6032
|
-
metas: metas.filter((meta) => !duplicateIds.has(meta.id)),
|
|
6033
|
-
issues
|
|
6034
|
-
};
|
|
6035
|
-
}
|
|
6036
|
-
function extractDefineEvalObject(content, defineEvalIndex) {
|
|
6037
|
-
const openParenIndex = content.indexOf("(", defineEvalIndex);
|
|
6038
|
-
if (openParenIndex === -1) return void 0;
|
|
6039
|
-
const objectStartIndex = content.indexOf("{", openParenIndex);
|
|
6040
|
-
if (objectStartIndex === -1) return void 0;
|
|
6041
|
-
let depth = 0;
|
|
6042
|
-
let quote;
|
|
6043
|
-
let inBlockComment = false;
|
|
6044
|
-
let inLineComment = false;
|
|
6045
|
-
let isEscaped = false;
|
|
6046
|
-
for (let index = objectStartIndex; index < content.length; index++) {
|
|
6047
|
-
const currentChar = content[index];
|
|
6048
|
-
const nextChar = content[index + 1];
|
|
6049
|
-
if (inLineComment) {
|
|
6050
|
-
if (currentChar === "\n") inLineComment = false;
|
|
6051
|
-
continue;
|
|
6052
|
-
}
|
|
6053
|
-
if (inBlockComment) {
|
|
6054
|
-
if (currentChar === "*" && nextChar === "/") {
|
|
6055
|
-
inBlockComment = false;
|
|
6056
|
-
index++;
|
|
6057
|
-
}
|
|
6058
|
-
continue;
|
|
6059
|
-
}
|
|
6060
|
-
if (quote) {
|
|
6061
|
-
if (isEscaped) {
|
|
6062
|
-
isEscaped = false;
|
|
6063
|
-
continue;
|
|
6064
|
-
}
|
|
6065
|
-
if (currentChar === "\\") {
|
|
6066
|
-
isEscaped = true;
|
|
6067
|
-
continue;
|
|
6068
|
-
}
|
|
6069
|
-
if (currentChar === quote) quote = void 0;
|
|
6070
|
-
continue;
|
|
6071
|
-
}
|
|
6072
|
-
if (currentChar === "/" && nextChar === "/") {
|
|
6073
|
-
inLineComment = true;
|
|
6074
|
-
index++;
|
|
6075
|
-
continue;
|
|
6076
|
-
}
|
|
6077
|
-
if (currentChar === "/" && nextChar === "*") {
|
|
6078
|
-
inBlockComment = true;
|
|
6079
|
-
index++;
|
|
6080
|
-
continue;
|
|
6081
|
-
}
|
|
6082
|
-
if (currentChar === "\"" || currentChar === "'" || currentChar === "`") {
|
|
6083
|
-
quote = currentChar;
|
|
6084
|
-
continue;
|
|
6085
|
-
}
|
|
6086
|
-
if (currentChar === "{") {
|
|
6087
|
-
depth++;
|
|
6088
|
-
continue;
|
|
6089
|
-
}
|
|
6090
|
-
if (currentChar === "}") {
|
|
6091
|
-
depth--;
|
|
6092
|
-
if (depth === 0) return {
|
|
6093
|
-
nextIndex: index + 1,
|
|
6094
|
-
objectText: content.slice(objectStartIndex, index + 1)
|
|
6095
|
-
};
|
|
6096
|
-
}
|
|
6097
|
-
}
|
|
6098
|
-
}
|
|
6099
|
-
//#endregion
|
|
6100
5929
|
//#region ../runner/src/evalModuleLoader.ts
|
|
6101
5930
|
/**
|
|
6102
5931
|
* Import one eval module with a cache key derived from its current source so
|
|
@@ -6121,6 +5950,7 @@ const agentPackageUrlBySpecifier = new Map([
|
|
|
6121
5950
|
"@agent-evals/sdk",
|
|
6122
5951
|
"@agent-evals/shared",
|
|
6123
5952
|
"@agent-evals/runner",
|
|
5953
|
+
"@agent-evals/runner/case-child",
|
|
6124
5954
|
"@agent-evals/runner/run-child"
|
|
6125
5955
|
].flatMap((specifier) => {
|
|
6126
5956
|
try {
|
|
@@ -6146,7 +5976,8 @@ function isIsolatableFilePath(filePath, workspaceRoot) {
|
|
|
6146
5976
|
if (isAgentEvalsPackageFilePath(filePath)) return false;
|
|
6147
5977
|
const relativePath = relative(workspaceRoot, filePath);
|
|
6148
5978
|
if (relativePath === "" || relativePath.startsWith("..") || isAbsolute(relativePath)) return false;
|
|
6149
|
-
|
|
5979
|
+
const segments = relativePath.split(pathSegmentSeparatorPattern);
|
|
5980
|
+
return !segments.includes(".agent-evals") && !segments.includes("node_modules");
|
|
6150
5981
|
}
|
|
6151
5982
|
function isAgentEvalsPackageFilePath(filePath) {
|
|
6152
5983
|
return agentPackageDirectoryPaths.some((packageDirectoryPath) => {
|
|
@@ -6184,6 +6015,9 @@ function registerModuleIsolationHooks() {
|
|
|
6184
6015
|
};
|
|
6185
6016
|
} });
|
|
6186
6017
|
}
|
|
6018
|
+
function registerAgentEvalsPackageResolutionHooks() {
|
|
6019
|
+
registerModuleIsolationHooks();
|
|
6020
|
+
}
|
|
6187
6021
|
function clearWorkspaceRequireCacheOnce(context) {
|
|
6188
6022
|
if (clearedRequireCacheKeys.has(context.key)) return;
|
|
6189
6023
|
clearedRequireCacheKeys.add(context.key);
|
|
@@ -6205,432 +6039,6 @@ async function runWithModuleIsolation(context, fn) {
|
|
|
6205
6039
|
return await isolationStorage.run(context, fn);
|
|
6206
6040
|
}
|
|
6207
6041
|
//#endregion
|
|
6208
|
-
//#region ../runner/src/evalRegistryLoader.ts
|
|
6209
|
-
async function loadIsolatedEvalRegistry(params) {
|
|
6210
|
-
return await runWithEvalRegistry(async (registry) => {
|
|
6211
|
-
await runWithModuleIsolation(params.moduleIsolation, async () => {
|
|
6212
|
-
await runInEvalRuntimeScope(params.runtimeScope, async () => {
|
|
6213
|
-
await loadEvalModule(params.evalFilePath, params.sourceFingerprint);
|
|
6214
|
-
});
|
|
6215
|
-
});
|
|
6216
|
-
return registry;
|
|
6217
|
-
});
|
|
6218
|
-
}
|
|
6219
|
-
async function useIsolatedEvalDefinition(params) {
|
|
6220
|
-
const entry = (await loadIsolatedEvalRegistry(params)).get(params.evalId);
|
|
6221
|
-
if (entry === void 0) throw new Error(`Eval "${params.evalId}" was not registered after importing ${params.evalFilePath}`);
|
|
6222
|
-
return await entry.use(async (evalDef) => {
|
|
6223
|
-
return await params.use(evalDef);
|
|
6224
|
-
});
|
|
6225
|
-
}
|
|
6226
|
-
//#endregion
|
|
6227
|
-
//#region ../runner/src/freshness.ts
|
|
6228
|
-
/**
|
|
6229
|
-
* Derive eval freshness from the latest run, current eval-file fingerprint,
|
|
6230
|
-
* current git commit, and an age threshold.
|
|
6231
|
-
*/
|
|
6232
|
-
function deriveEvalFreshness(params) {
|
|
6233
|
-
const { latestRun, gitState, currentEvalSourceFingerprint, staleAfterDays, now = /* @__PURE__ */ new Date() } = params;
|
|
6234
|
-
const stale = latestRun?.evalSourceFingerprint !== void 0 && latestRun.evalSourceFingerprint !== null && currentEvalSourceFingerprint !== null && currentEvalSourceFingerprint !== latestRun.evalSourceFingerprint;
|
|
6235
|
-
const latestRunCommitSha = latestRun?.commitSha;
|
|
6236
|
-
if (latestRunCommitSha === void 0 || latestRunCommitSha === null) return {
|
|
6237
|
-
freshnessStatus: stale ? "stale" : "fresh",
|
|
6238
|
-
stale,
|
|
6239
|
-
outdated: false
|
|
6240
|
-
};
|
|
6241
|
-
if (gitState.commitSha === null) return {
|
|
6242
|
-
freshnessStatus: stale ? "stale" : "fresh",
|
|
6243
|
-
stale,
|
|
6244
|
-
outdated: false
|
|
6245
|
-
};
|
|
6246
|
-
if (latestRunCommitSha === gitState.commitSha) return {
|
|
6247
|
-
freshnessStatus: stale ? "stale" : "fresh",
|
|
6248
|
-
stale,
|
|
6249
|
-
outdated: false
|
|
6250
|
-
};
|
|
6251
|
-
const latestRunStartedAt = new Date(latestRun?.startedAt ?? "").getTime();
|
|
6252
|
-
if (!Number.isFinite(latestRunStartedAt)) return {
|
|
6253
|
-
freshnessStatus: stale ? "stale" : "fresh",
|
|
6254
|
-
stale,
|
|
6255
|
-
outdated: false
|
|
6256
|
-
};
|
|
6257
|
-
const outdated = now.getTime() - latestRunStartedAt >= staleAfterDays * 24 * 60 * 60 * 1e3;
|
|
6258
|
-
return {
|
|
6259
|
-
freshnessStatus: stale ? "stale" : outdated ? "outdated" : "fresh",
|
|
6260
|
-
stale,
|
|
6261
|
-
outdated
|
|
6262
|
-
};
|
|
6263
|
-
}
|
|
6264
|
-
/** Return the timestamp used when ordering and displaying a run recency. */
|
|
6265
|
-
function getRunFreshnessTimestamp(manifest) {
|
|
6266
|
-
return manifest.endedAt ?? manifest.startedAt;
|
|
6267
|
-
}
|
|
6268
|
-
//#endregion
|
|
6269
|
-
//#region ../runner/src/manualInput/walker.ts
|
|
6270
|
-
function isObject(value) {
|
|
6271
|
-
return typeof value === "object" && value !== null;
|
|
6272
|
-
}
|
|
6273
|
-
function getZodDef(schema) {
|
|
6274
|
-
if (!isObject(schema)) return null;
|
|
6275
|
-
const zodHolder = schema._zod;
|
|
6276
|
-
if (!isObject(zodHolder)) return null;
|
|
6277
|
-
const def = zodHolder.def;
|
|
6278
|
-
if (!isObject(def)) return null;
|
|
6279
|
-
if (typeof def.type !== "string") return null;
|
|
6280
|
-
return {
|
|
6281
|
-
...def,
|
|
6282
|
-
type: def.type
|
|
6283
|
-
};
|
|
6284
|
-
}
|
|
6285
|
-
function getDescription(schema) {
|
|
6286
|
-
if (!isObject(schema)) return void 0;
|
|
6287
|
-
const description = schema.description;
|
|
6288
|
-
return typeof description === "string" ? description : void 0;
|
|
6289
|
-
}
|
|
6290
|
-
function getInnerSchema(def) {
|
|
6291
|
-
return def.innerType;
|
|
6292
|
-
}
|
|
6293
|
-
function getChecks(def) {
|
|
6294
|
-
const checks = def.checks;
|
|
6295
|
-
if (!Array.isArray(checks)) return [];
|
|
6296
|
-
const out = [];
|
|
6297
|
-
for (const check of checks) {
|
|
6298
|
-
if (!isObject(check)) continue;
|
|
6299
|
-
const zodHolder = check._zod;
|
|
6300
|
-
if (!isObject(zodHolder)) continue;
|
|
6301
|
-
const checkDef = zodHolder.def;
|
|
6302
|
-
if (!isObject(checkDef)) continue;
|
|
6303
|
-
if (typeof checkDef.check !== "string") continue;
|
|
6304
|
-
out.push({
|
|
6305
|
-
...checkDef,
|
|
6306
|
-
check: checkDef.check
|
|
6307
|
-
});
|
|
6308
|
-
}
|
|
6309
|
-
return out;
|
|
6310
|
-
}
|
|
6311
|
-
function findCheck(checks, name) {
|
|
6312
|
-
return checks.find((check) => check.check === name);
|
|
6313
|
-
}
|
|
6314
|
-
function unwrap(schema) {
|
|
6315
|
-
let current = schema;
|
|
6316
|
-
let required = true;
|
|
6317
|
-
let defaultValue = void 0;
|
|
6318
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
6319
|
-
const def = getZodDef(current);
|
|
6320
|
-
if (!def) return null;
|
|
6321
|
-
if (def.type === "optional" || def.type === "nullable") {
|
|
6322
|
-
required = false;
|
|
6323
|
-
current = getInnerSchema(def);
|
|
6324
|
-
continue;
|
|
6325
|
-
}
|
|
6326
|
-
if (def.type === "nullish") {
|
|
6327
|
-
required = false;
|
|
6328
|
-
current = getInnerSchema(def);
|
|
6329
|
-
continue;
|
|
6330
|
-
}
|
|
6331
|
-
if (def.type === "default" || def.type === "prefault") {
|
|
6332
|
-
const raw = def.defaultValue;
|
|
6333
|
-
if (typeof raw === "function") defaultValue = Reflect.apply(raw, void 0, []);
|
|
6334
|
-
else defaultValue = raw;
|
|
6335
|
-
current = getInnerSchema(def);
|
|
6336
|
-
continue;
|
|
6337
|
-
}
|
|
6338
|
-
if (def.type === "readonly" || def.type === "pipe") {
|
|
6339
|
-
current = getInnerSchema(def) ?? def.in;
|
|
6340
|
-
continue;
|
|
6341
|
-
}
|
|
6342
|
-
return {
|
|
6343
|
-
schema: current,
|
|
6344
|
-
def,
|
|
6345
|
-
required,
|
|
6346
|
-
defaultValue
|
|
6347
|
-
};
|
|
6348
|
-
}
|
|
6349
|
-
return null;
|
|
6350
|
-
}
|
|
6351
|
-
function humaniseKey(key) {
|
|
6352
|
-
const spaced = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim();
|
|
6353
|
-
if (!spaced) return key;
|
|
6354
|
-
const lowered = spaced.toLowerCase();
|
|
6355
|
-
return lowered.charAt(0).toUpperCase() + lowered.slice(1);
|
|
6356
|
-
}
|
|
6357
|
-
function normaliseSelectOptions(raw) {
|
|
6358
|
-
if (!raw) return void 0;
|
|
6359
|
-
return raw.map((entry) => {
|
|
6360
|
-
if (typeof entry === "string") return {
|
|
6361
|
-
value: entry,
|
|
6362
|
-
label: entry
|
|
6363
|
-
};
|
|
6364
|
-
return {
|
|
6365
|
-
value: entry.value,
|
|
6366
|
-
label: entry.label ?? entry.value
|
|
6367
|
-
};
|
|
6368
|
-
});
|
|
6369
|
-
}
|
|
6370
|
-
function enumOptionsFromEntries(def) {
|
|
6371
|
-
const entries = def.entries;
|
|
6372
|
-
if (!isObject(entries)) return null;
|
|
6373
|
-
const out = [];
|
|
6374
|
-
for (const [label, value] of Object.entries(entries)) if (typeof value === "string") out.push({
|
|
6375
|
-
value,
|
|
6376
|
-
label
|
|
6377
|
-
});
|
|
6378
|
-
else if (typeof value === "number") out.push({
|
|
6379
|
-
value: String(value),
|
|
6380
|
-
label
|
|
6381
|
-
});
|
|
6382
|
-
else return null;
|
|
6383
|
-
return out;
|
|
6384
|
-
}
|
|
6385
|
-
function literalUnionOptions(def) {
|
|
6386
|
-
const options = def.options;
|
|
6387
|
-
if (!Array.isArray(options)) return null;
|
|
6388
|
-
const out = [];
|
|
6389
|
-
for (const option of options) {
|
|
6390
|
-
const optDef = getZodDef(option);
|
|
6391
|
-
if (optDef?.type !== "literal") return null;
|
|
6392
|
-
const values = optDef.values;
|
|
6393
|
-
if (!Array.isArray(values) || values.length !== 1) return null;
|
|
6394
|
-
const value = values[0];
|
|
6395
|
-
if (typeof value === "string") out.push({
|
|
6396
|
-
value,
|
|
6397
|
-
label: value
|
|
6398
|
-
});
|
|
6399
|
-
else if (typeof value === "number") {
|
|
6400
|
-
const stringValue = String(value);
|
|
6401
|
-
out.push({
|
|
6402
|
-
value: stringValue,
|
|
6403
|
-
label: stringValue
|
|
6404
|
-
});
|
|
6405
|
-
} else return null;
|
|
6406
|
-
}
|
|
6407
|
-
return out.length > 0 ? out : null;
|
|
6408
|
-
}
|
|
6409
|
-
function literalSelectOptions(def) {
|
|
6410
|
-
const values = def.values;
|
|
6411
|
-
if (!Array.isArray(values)) return null;
|
|
6412
|
-
const out = [];
|
|
6413
|
-
for (const value of values) if (typeof value === "string") out.push({
|
|
6414
|
-
value,
|
|
6415
|
-
label: value
|
|
6416
|
-
});
|
|
6417
|
-
else if (typeof value === "number") {
|
|
6418
|
-
const stringValue = String(value);
|
|
6419
|
-
out.push({
|
|
6420
|
-
value: stringValue,
|
|
6421
|
-
label: stringValue
|
|
6422
|
-
});
|
|
6423
|
-
} else return null;
|
|
6424
|
-
return out;
|
|
6425
|
-
}
|
|
6426
|
-
function readStringChecks(def) {
|
|
6427
|
-
const checks = getChecks(def);
|
|
6428
|
-
const out = {};
|
|
6429
|
-
const min = findCheck(checks, "min_length");
|
|
6430
|
-
if (min && typeof min.minimum === "number") out.minLength = min.minimum;
|
|
6431
|
-
const max = findCheck(checks, "max_length");
|
|
6432
|
-
if (max && typeof max.maximum === "number") out.maxLength = max.maximum;
|
|
6433
|
-
return out;
|
|
6434
|
-
}
|
|
6435
|
-
const integerNumberFormats = new Set([
|
|
6436
|
-
"int",
|
|
6437
|
-
"safeint",
|
|
6438
|
-
"int32",
|
|
6439
|
-
"uint32",
|
|
6440
|
-
"int64",
|
|
6441
|
-
"uint64"
|
|
6442
|
-
]);
|
|
6443
|
-
function readNumberChecks(def) {
|
|
6444
|
-
const checks = getChecks(def);
|
|
6445
|
-
const out = {};
|
|
6446
|
-
const gt = findCheck(checks, "greater_than");
|
|
6447
|
-
if (gt && typeof gt.value === "number" && gt.inclusive === true) out.min = gt.value;
|
|
6448
|
-
const lt = findCheck(checks, "less_than");
|
|
6449
|
-
if (lt && typeof lt.value === "number" && lt.inclusive === true) out.max = lt.value;
|
|
6450
|
-
const format = findCheck(checks, "number_format");
|
|
6451
|
-
if (format && typeof format.format === "string" && integerNumberFormats.has(format.format)) out.integer = true;
|
|
6452
|
-
return out;
|
|
6453
|
-
}
|
|
6454
|
-
function buildField(key, fieldSchema, override) {
|
|
6455
|
-
const unwrapped = unwrap(fieldSchema);
|
|
6456
|
-
if (!unwrapped) return Result.err(/* @__PURE__ */ new Error(`manualInput: field "${key}" uses an unsupported Zod schema (could not introspect)`));
|
|
6457
|
-
const inner = unwrapped.def;
|
|
6458
|
-
const description = override?.description ?? getDescription(unwrapped.schema);
|
|
6459
|
-
const base = {
|
|
6460
|
-
key,
|
|
6461
|
-
label: override?.label ?? humaniseKey(key),
|
|
6462
|
-
description,
|
|
6463
|
-
placeholder: override?.placeholder,
|
|
6464
|
-
required: unwrapped.required,
|
|
6465
|
-
defaultValue: override?.defaultValue !== void 0 ? override.defaultValue : unwrapped.defaultValue
|
|
6466
|
-
};
|
|
6467
|
-
if (override?.asJson === true) {
|
|
6468
|
-
const rows = override.rows;
|
|
6469
|
-
return Result.ok({
|
|
6470
|
-
...base,
|
|
6471
|
-
kind: "json",
|
|
6472
|
-
rows
|
|
6473
|
-
});
|
|
6474
|
-
}
|
|
6475
|
-
if (override?.asFile === true) return Result.ok({
|
|
6476
|
-
...base,
|
|
6477
|
-
kind: "file",
|
|
6478
|
-
accept: override.accept,
|
|
6479
|
-
maxSizeBytes: override.maxSizeBytes
|
|
6480
|
-
});
|
|
6481
|
-
const overrideOptions = normaliseSelectOptions(override?.options);
|
|
6482
|
-
if (overrideOptions) return Result.ok({
|
|
6483
|
-
...base,
|
|
6484
|
-
kind: "select",
|
|
6485
|
-
options: overrideOptions
|
|
6486
|
-
});
|
|
6487
|
-
switch (inner.type) {
|
|
6488
|
-
case "string": {
|
|
6489
|
-
const checks = readStringChecks(inner);
|
|
6490
|
-
if (override?.multiline === true) return Result.ok({
|
|
6491
|
-
...base,
|
|
6492
|
-
kind: "multiline",
|
|
6493
|
-
rows: override.rows,
|
|
6494
|
-
minLength: checks.minLength,
|
|
6495
|
-
maxLength: checks.maxLength
|
|
6496
|
-
});
|
|
6497
|
-
return Result.ok({
|
|
6498
|
-
...base,
|
|
6499
|
-
kind: "text",
|
|
6500
|
-
minLength: checks.minLength,
|
|
6501
|
-
maxLength: checks.maxLength
|
|
6502
|
-
});
|
|
6503
|
-
}
|
|
6504
|
-
case "number":
|
|
6505
|
-
case "int":
|
|
6506
|
-
case "bigint": {
|
|
6507
|
-
const checks = readNumberChecks(inner);
|
|
6508
|
-
return Result.ok({
|
|
6509
|
-
...base,
|
|
6510
|
-
kind: "number",
|
|
6511
|
-
min: checks.min,
|
|
6512
|
-
max: checks.max,
|
|
6513
|
-
integer: checks.integer
|
|
6514
|
-
});
|
|
6515
|
-
}
|
|
6516
|
-
case "boolean": return Result.ok({
|
|
6517
|
-
...base,
|
|
6518
|
-
kind: "boolean"
|
|
6519
|
-
});
|
|
6520
|
-
case "enum": {
|
|
6521
|
-
const options = enumOptionsFromEntries(inner);
|
|
6522
|
-
if (options) return Result.ok({
|
|
6523
|
-
...base,
|
|
6524
|
-
kind: "select",
|
|
6525
|
-
options
|
|
6526
|
-
});
|
|
6527
|
-
return Result.ok({
|
|
6528
|
-
...base,
|
|
6529
|
-
kind: "json",
|
|
6530
|
-
rows: override?.rows
|
|
6531
|
-
});
|
|
6532
|
-
}
|
|
6533
|
-
case "literal": {
|
|
6534
|
-
const options = literalSelectOptions(inner);
|
|
6535
|
-
if (options && options.length > 0) return Result.ok({
|
|
6536
|
-
...base,
|
|
6537
|
-
kind: "select",
|
|
6538
|
-
options
|
|
6539
|
-
});
|
|
6540
|
-
return Result.ok({
|
|
6541
|
-
...base,
|
|
6542
|
-
kind: "json",
|
|
6543
|
-
rows: override?.rows
|
|
6544
|
-
});
|
|
6545
|
-
}
|
|
6546
|
-
case "union": {
|
|
6547
|
-
const options = literalUnionOptions(inner);
|
|
6548
|
-
if (options) return Result.ok({
|
|
6549
|
-
...base,
|
|
6550
|
-
kind: "select",
|
|
6551
|
-
options
|
|
6552
|
-
});
|
|
6553
|
-
return Result.ok({
|
|
6554
|
-
...base,
|
|
6555
|
-
kind: "json",
|
|
6556
|
-
rows: override?.rows
|
|
6557
|
-
});
|
|
6558
|
-
}
|
|
6559
|
-
default: return Result.ok({
|
|
6560
|
-
...base,
|
|
6561
|
-
kind: "json",
|
|
6562
|
-
rows: override?.rows
|
|
6563
|
-
});
|
|
6564
|
-
}
|
|
6565
|
-
}
|
|
6566
|
-
function getObjectShape(schema) {
|
|
6567
|
-
const def = getZodDef(schema);
|
|
6568
|
-
if (!def) return null;
|
|
6569
|
-
if (def.type !== "object") return null;
|
|
6570
|
-
const shape = def.shape;
|
|
6571
|
-
if (!isObject(shape)) return null;
|
|
6572
|
-
return shape;
|
|
6573
|
-
}
|
|
6574
|
-
/**
|
|
6575
|
-
* Walk an eval's `manualInput` configuration and produce the wire-format
|
|
6576
|
-
* descriptor consumed by the web UI. The schema must resolve to a top-level
|
|
6577
|
-
* `z.object(...)`; nested objects, arrays, unions, and other unsupported
|
|
6578
|
-
* shapes inside fields fall back to the JSON textarea widget.
|
|
6579
|
-
*
|
|
6580
|
-
* Returns a `Result` so the caller (eval discovery) can surface a discovery
|
|
6581
|
-
* issue without throwing when the schema is incompatible.
|
|
6582
|
-
*/
|
|
6583
|
-
function buildManualInputDescriptor(config) {
|
|
6584
|
-
const shape = getObjectShape(config.schema);
|
|
6585
|
-
if (!shape) return Result.err(/* @__PURE__ */ new Error("manualInput.schema must be a top-level z.object(...). Wrap nested types in an object schema."));
|
|
6586
|
-
const overrides = {};
|
|
6587
|
-
const rawOverrides = config.fields;
|
|
6588
|
-
if (rawOverrides) {
|
|
6589
|
-
for (const [key, override] of Object.entries(rawOverrides)) if (override) overrides[key] = override;
|
|
6590
|
-
}
|
|
6591
|
-
const fields = [];
|
|
6592
|
-
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
6593
|
-
const fieldResult = buildField(key, fieldSchema, overrides[key]);
|
|
6594
|
-
if (fieldResult.error) return fieldResult.errorResult();
|
|
6595
|
-
fields.push(fieldResult.value);
|
|
6596
|
-
}
|
|
6597
|
-
return Result.ok({
|
|
6598
|
-
title: config.title,
|
|
6599
|
-
description: config.description,
|
|
6600
|
-
submitLabel: config.submitLabel,
|
|
6601
|
-
fields
|
|
6602
|
-
});
|
|
6603
|
-
}
|
|
6604
|
-
/**
|
|
6605
|
-
* Resolve an eval's `manualInput` Zod schema against a raw user submission.
|
|
6606
|
-
* Returns the parsed value typed against the eval's `TInput` generic, or a
|
|
6607
|
-
* structured `Error` carrying the Zod issues for the caller to surface.
|
|
6608
|
-
*/
|
|
6609
|
-
function parseManualInputValues(config, raw) {
|
|
6610
|
-
const parsed = config.schema.safeParse(raw);
|
|
6611
|
-
if (!parsed.success) return Result.err(new ManualInputValidationError(parsed.error.issues.map(formatIssue)));
|
|
6612
|
-
return Result.ok(parsed.data);
|
|
6613
|
-
}
|
|
6614
|
-
/**
|
|
6615
|
-
* Error thrown / returned when manual-input values fail validation against
|
|
6616
|
-
* the eval's `manualInput.schema`. Carries the structured Zod issues so the
|
|
6617
|
-
* CLI and HTTP layers can surface them per-field.
|
|
6618
|
-
*/
|
|
6619
|
-
var ManualInputValidationError = class extends Error {
|
|
6620
|
-
issues;
|
|
6621
|
-
constructor(issues) {
|
|
6622
|
-
super(issues.length === 0 ? "manualInput validation failed" : `manualInput validation failed: ${issues.map((issue) => issue.path ? `${issue.path}: ${issue.message}` : issue.message).join("; ")}`);
|
|
6623
|
-
this.name = "ManualInputValidationError";
|
|
6624
|
-
this.issues = issues;
|
|
6625
|
-
}
|
|
6626
|
-
};
|
|
6627
|
-
function formatIssue(issue) {
|
|
6628
|
-
return {
|
|
6629
|
-
path: issue.path.map((segment) => typeof segment === "string" || typeof segment === "number" ? String(segment) : "").filter((segment) => segment !== "").join("."),
|
|
6630
|
-
message: issue.message
|
|
6631
|
-
};
|
|
6632
|
-
}
|
|
6633
|
-
//#endregion
|
|
6634
6042
|
//#region ../runner/src/outputArtifacts.ts
|
|
6635
6043
|
const mimeTypeExtensionMap = {
|
|
6636
6044
|
"application/json": ".json",
|
|
@@ -6776,254 +6184,23 @@ function resolveTracePresentation(spans, globalTraceDisplay, evalTraceDisplay) {
|
|
|
6776
6184
|
};
|
|
6777
6185
|
}
|
|
6778
6186
|
//#endregion
|
|
6779
|
-
//#region ../runner/src/runMaintenance.ts
|
|
6780
|
-
async function persistRunState(runState) {
|
|
6781
|
-
await writeFile(join(runState.runDir, "summary.json"), JSON.stringify(runState.summary, null, 2));
|
|
6782
|
-
await writeFile(join(runState.runDir, "run.json"), JSON.stringify(runState.manifest, null, 2));
|
|
6783
|
-
const casesJsonl = runState.cases.map((c) => JSON.stringify(c)).join("\n");
|
|
6784
|
-
await writeFile(join(runState.runDir, "cases.jsonl"), casesJsonl);
|
|
6785
|
-
}
|
|
6786
|
-
/**
|
|
6787
|
-
* Recompute a persisted case's status after score definitions changed.
|
|
6788
|
-
*
|
|
6789
|
-
* Pass/fail gates are per-score: a case fails when any score with a declared
|
|
6790
|
-
* `passThreshold` reports a numeric value below that threshold. Scores
|
|
6791
|
-
* without a threshold are informational and never gate. Cancelled and
|
|
6792
|
-
* errored cases retain their terminal status.
|
|
6793
|
-
*/
|
|
6794
|
-
function recomputePersistedCaseStatus(caseRow, caseDetail, scoreThresholds) {
|
|
6795
|
-
if (caseRow.status === "cancelled") return "cancelled";
|
|
6796
|
-
if (caseDetail?.error !== null && caseDetail?.error !== void 0) return "error";
|
|
6797
|
-
if ((caseDetail?.assertionFailures.length ?? 0) > 0) return "fail";
|
|
6798
|
-
for (const [key, passThreshold] of scoreThresholds) {
|
|
6799
|
-
const rawValue = caseRow.columns[key] ?? caseDetail?.columns[key];
|
|
6800
|
-
if (typeof rawValue !== "number") continue;
|
|
6801
|
-
if (rawValue < passThreshold) return "fail";
|
|
6802
|
-
}
|
|
6803
|
-
return caseRow.status === "error" ? "error" : "pass";
|
|
6804
|
-
}
|
|
6805
|
-
function runTouchesEval(params) {
|
|
6806
|
-
if (params.caseRows.some((caseRow) => caseRow.evalKey === params.evalKey)) return true;
|
|
6807
|
-
if (params.target.mode === "all") return params.evalExists;
|
|
6808
|
-
if (params.target.mode === "evalIds") return params.target.evalKeys?.includes(params.evalKey) ?? false;
|
|
6809
|
-
return false;
|
|
6810
|
-
}
|
|
6811
|
-
async function deleteTemporaryRuns(params) {
|
|
6812
|
-
let deletedRuns = 0;
|
|
6813
|
-
for (const [runId, run] of [...params.runs]) {
|
|
6814
|
-
if (run.manifest.temporary !== true) continue;
|
|
6815
|
-
if (run.manifest.status === "running") {
|
|
6816
|
-
const endedAt = /* @__PURE__ */ new Date();
|
|
6817
|
-
run.manifest.status = "cancelled";
|
|
6818
|
-
run.manifest.endedAt = endedAt.toISOString();
|
|
6819
|
-
run.summary.status = "cancelled";
|
|
6820
|
-
run.summary.totalDurationMs = endedAt.getTime() - new Date(run.manifest.startedAt).getTime();
|
|
6821
|
-
params.cancelRunningRun(run);
|
|
6822
|
-
}
|
|
6823
|
-
params.runs.delete(runId);
|
|
6824
|
-
await rm(run.runDir, {
|
|
6825
|
-
recursive: true,
|
|
6826
|
-
force: true
|
|
6827
|
-
});
|
|
6828
|
-
deletedRuns += 1;
|
|
6829
|
-
}
|
|
6830
|
-
return deletedRuns;
|
|
6831
|
-
}
|
|
6832
|
-
async function recomputeEvalStatusesInRuns(params) {
|
|
6833
|
-
let updatedRuns = 0;
|
|
6834
|
-
for (const run of params.runs) {
|
|
6835
|
-
if (!runTouchesEval({
|
|
6836
|
-
target: run.manifest.target,
|
|
6837
|
-
caseRows: run.cases,
|
|
6838
|
-
evalKey: params.evalKey,
|
|
6839
|
-
evalExists: params.evalExists
|
|
6840
|
-
})) continue;
|
|
6841
|
-
if (run.manifest.status === "running") continue;
|
|
6842
|
-
let changed = false;
|
|
6843
|
-
for (const caseRow of run.cases) {
|
|
6844
|
-
if (caseRow.evalKey !== params.evalKey) continue;
|
|
6845
|
-
const caseDetail = run.caseDetails.get(getCaseRowCaseKey(caseRow));
|
|
6846
|
-
const nextStatus = recomputePersistedCaseStatus(caseRow, caseDetail, params.scoreThresholds);
|
|
6847
|
-
if (caseRow.status === nextStatus) continue;
|
|
6848
|
-
caseRow.status = nextStatus;
|
|
6849
|
-
if (caseDetail) {
|
|
6850
|
-
caseDetail.status = nextStatus;
|
|
6851
|
-
await params.persistCaseDetail(run.runDir, caseDetail);
|
|
6852
|
-
}
|
|
6853
|
-
changed = true;
|
|
6854
|
-
}
|
|
6855
|
-
if (!changed) continue;
|
|
6856
|
-
const derivedSummary = deriveScopedSummaryFromCases({ caseRows: run.cases });
|
|
6857
|
-
run.summary.totalCases = derivedSummary.totalCases;
|
|
6858
|
-
run.summary.passedCases = derivedSummary.passedCases;
|
|
6859
|
-
run.summary.failedCases = derivedSummary.failedCases;
|
|
6860
|
-
run.summary.errorCases = derivedSummary.errorCases;
|
|
6861
|
-
run.summary.cancelledCases = derivedSummary.cancelledCases;
|
|
6862
|
-
await persistRunState(run);
|
|
6863
|
-
updatedRuns += 1;
|
|
6864
|
-
}
|
|
6865
|
-
return updatedRuns;
|
|
6866
|
-
}
|
|
6867
|
-
//#endregion
|
|
6868
|
-
//#region ../runner/src/runPersistence.ts
|
|
6869
|
-
const SHORT_ID_PATTERN = /^r(\d+)$/;
|
|
6870
|
-
/**
|
|
6871
|
-
* Generate a filesystem-safe, sortable run id combining a UTC timestamp
|
|
6872
|
-
* with a short random suffix.
|
|
6873
|
-
*/
|
|
6874
|
-
function generateRunId() {
|
|
6875
|
-
const now = /* @__PURE__ */ new Date();
|
|
6876
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
6877
|
-
return `${`${String(now.getUTCFullYear())}-${pad(now.getUTCMonth() + 1)}-${pad(now.getUTCDate())}T${pad(now.getUTCHours())}-${pad(now.getUTCMinutes())}-${pad(now.getUTCSeconds())}Z`}_${Math.random().toString(36).slice(2, 8)}`;
|
|
6878
|
-
}
|
|
6879
|
-
function parseShortIdNum(shortId) {
|
|
6880
|
-
if (shortId === void 0) return null;
|
|
6881
|
-
const match = SHORT_ID_PATTERN.exec(shortId);
|
|
6882
|
-
if (!match) return null;
|
|
6883
|
-
const num = Number(match[1]);
|
|
6884
|
-
if (!Number.isFinite(num)) return null;
|
|
6885
|
-
return num;
|
|
6886
|
-
}
|
|
6887
|
-
/**
|
|
6888
|
-
* Return the next `shortId` number to assign based on the existing
|
|
6889
|
-
* loaded snapshots. Legacy runs that don't match the `r\d+` format are
|
|
6890
|
-
* ignored.
|
|
6891
|
-
*/
|
|
6892
|
-
function nextShortIdFromSnapshots(snapshots) {
|
|
6893
|
-
let maxNum = -1;
|
|
6894
|
-
for (const snapshot of snapshots) {
|
|
6895
|
-
const num = parseShortIdNum(snapshot.manifest.shortId);
|
|
6896
|
-
if (num !== null && num > maxNum) maxNum = num;
|
|
6897
|
-
}
|
|
6898
|
-
return maxNum + 1;
|
|
6899
|
-
}
|
|
6900
|
-
async function loadPersistedRunSnapshots(localStateDir) {
|
|
6901
|
-
const runsDir = join(localStateDir, "runs");
|
|
6902
|
-
const entriesResult = await resultify(() => readdir(runsDir, { withFileTypes: true }));
|
|
6903
|
-
if (entriesResult.error) return [];
|
|
6904
|
-
const snapshots = [];
|
|
6905
|
-
const runDirs = entriesResult.value.filter((entry) => entry.isDirectory()).map((entry) => join(runsDir, entry.name)).toSorted();
|
|
6906
|
-
for (const runDir of runDirs) {
|
|
6907
|
-
const snapshot = await loadPersistedRunSnapshot(runDir);
|
|
6908
|
-
if (!snapshot) continue;
|
|
6909
|
-
snapshots.push(snapshot);
|
|
6910
|
-
}
|
|
6911
|
-
return snapshots;
|
|
6912
|
-
}
|
|
6913
|
-
async function persistCaseDetail(runDir, caseDetail, fileId = caseDetail.caseId) {
|
|
6914
|
-
await writeFile(join(runDir, "case-details", `${encodeCaseDetailFileName(fileId)}.json`), JSON.stringify(caseDetail, null, 2));
|
|
6915
|
-
}
|
|
6916
|
-
function getLastRunStatuses(params) {
|
|
6917
|
-
const latestRunInfos = getLatestRunInfos(params);
|
|
6918
|
-
return new Map([...latestRunInfos].map(([evalId, info]) => [evalId, info.status]));
|
|
6919
|
-
}
|
|
6920
|
-
/**
|
|
6921
|
-
* Return the latest scoped run metadata for each eval based on persisted and
|
|
6922
|
-
* in-memory runs.
|
|
6923
|
-
*/
|
|
6924
|
-
function getLatestRunInfos(params) {
|
|
6925
|
-
const { runs, knownEvals } = params;
|
|
6926
|
-
const knownEvalMetas = [...knownEvals];
|
|
6927
|
-
const manualScoreKeysByEval = new Map(knownEvalMetas.map((evalMeta) => [evalMeta.key, evalMeta.columnDefs.filter((columnDef) => columnDef.isManualScore === true).map((columnDef) => columnDef.key)]));
|
|
6928
|
-
const orderedRuns = [...runs].toSorted((a, b) => new Date(getRunFreshnessTimestamp(a.manifest)).getTime() - new Date(getRunFreshnessTimestamp(b.manifest)).getTime());
|
|
6929
|
-
const latestRunInfos = /* @__PURE__ */ new Map();
|
|
6930
|
-
for (const run of orderedRuns) for (const evalKey of getRunEvalKeys(run, knownEvalMetas)) latestRunInfos.set(evalKey, {
|
|
6931
|
-
status: getEvalStatusForRun(run, evalKey, manualScoreKeysByEval.get(evalKey) ?? []),
|
|
6932
|
-
startedAt: getRunFreshnessTimestamp(run.manifest),
|
|
6933
|
-
commitSha: run.manifest.commitSha ?? null,
|
|
6934
|
-
evalSourceFingerprint: run.manifest.evalSourceFingerprints[evalKey] ?? null
|
|
6935
|
-
});
|
|
6936
|
-
return latestRunInfos;
|
|
6937
|
-
}
|
|
6938
|
-
function toLastRunStatus$1(status) {
|
|
6939
|
-
return status === "pending" ? null : status;
|
|
6940
|
-
}
|
|
6941
|
-
async function loadPersistedRunSnapshot(runDir) {
|
|
6942
|
-
const manifest = await readParsedJsonFile(join(runDir, "run.json"), { safeParse: runManifestSchema.safeParse.bind(runManifestSchema) });
|
|
6943
|
-
if (!manifest) return null;
|
|
6944
|
-
const summary = await readParsedJsonFile(join(runDir, "summary.json"), { safeParse: runSummarySchema.safeParse.bind(runSummarySchema) });
|
|
6945
|
-
if (!summary) return null;
|
|
6946
|
-
return {
|
|
6947
|
-
runDir,
|
|
6948
|
-
manifest,
|
|
6949
|
-
summary,
|
|
6950
|
-
cases: await readCaseRows(runDir),
|
|
6951
|
-
caseDetails: await readCaseDetails(runDir)
|
|
6952
|
-
};
|
|
6953
|
-
}
|
|
6954
|
-
async function readParsedJsonFile(filePath, schema) {
|
|
6955
|
-
const fileResult = await resultify(() => readFile(filePath, "utf-8"));
|
|
6956
|
-
if (fileResult.error) return null;
|
|
6957
|
-
const jsonResult = resultify(() => JSON.parse(fileResult.value));
|
|
6958
|
-
if (jsonResult.error) return null;
|
|
6959
|
-
const parsed = schema.safeParse(jsonResult.value);
|
|
6960
|
-
if (!parsed.success) return null;
|
|
6961
|
-
return parsed.data;
|
|
6962
|
-
}
|
|
6963
|
-
async function readCaseRows(runDir) {
|
|
6964
|
-
const fileResult = await resultify(() => readFile(join(runDir, "cases.jsonl"), "utf-8"));
|
|
6965
|
-
if (fileResult.error) return [];
|
|
6966
|
-
const rows = [];
|
|
6967
|
-
for (const rawLine of fileResult.value.split("\n")) {
|
|
6968
|
-
const line = rawLine.trim();
|
|
6969
|
-
if (line.length === 0) continue;
|
|
6970
|
-
const jsonResult = resultify(() => JSON.parse(line));
|
|
6971
|
-
if (jsonResult.error) continue;
|
|
6972
|
-
const parsed = caseRowSchema.safeParse(jsonResult.value);
|
|
6973
|
-
if (!parsed.success) continue;
|
|
6974
|
-
rows.push(parsed.data);
|
|
6975
|
-
}
|
|
6976
|
-
return rows;
|
|
6977
|
-
}
|
|
6978
|
-
async function readCaseDetails(runDir) {
|
|
6979
|
-
const detailsDir = join(runDir, "case-details");
|
|
6980
|
-
const entriesResult = await resultify(() => readdir(detailsDir, { withFileTypes: true }));
|
|
6981
|
-
if (entriesResult.error) return /* @__PURE__ */ new Map();
|
|
6982
|
-
const caseDetails = /* @__PURE__ */ new Map();
|
|
6983
|
-
for (const entry of entriesResult.value) {
|
|
6984
|
-
if (!entry.isFile() || !entry.name.endsWith(".json")) continue;
|
|
6985
|
-
const detail = await readParsedJsonFile(join(detailsDir, entry.name), { safeParse: caseDetailSchema.safeParse.bind(caseDetailSchema) });
|
|
6986
|
-
if (!detail) continue;
|
|
6987
|
-
caseDetails.set(detail.caseKey ?? detail.caseId, detail);
|
|
6988
|
-
}
|
|
6989
|
-
return caseDetails;
|
|
6990
|
-
}
|
|
6991
|
-
function getRunEvalKeys(run, knownEvals) {
|
|
6992
|
-
const knownEvalMetas = [...knownEvals];
|
|
6993
|
-
const evalKeys = /* @__PURE__ */ new Set();
|
|
6994
|
-
for (const caseRow of run.cases) if (caseRow.evalKey !== void 0) evalKeys.add(caseRow.evalKey);
|
|
6995
|
-
if (run.manifest.target.mode === "evalIds") for (const evalKey of run.manifest.target.evalKeys ?? []) evalKeys.add(evalKey);
|
|
6996
|
-
else if (run.manifest.target.mode === "all" && evalKeys.size === 0) for (const evalMeta of knownEvalMetas) evalKeys.add(evalMeta.key);
|
|
6997
|
-
return [...evalKeys];
|
|
6998
|
-
}
|
|
6999
|
-
function getEvalStatusForRun(run, evalKey, manualScoreKeys) {
|
|
7000
|
-
const evalCases = run.cases.filter((caseRow) => caseRow.evalKey === evalKey);
|
|
7001
|
-
if (evalCases.length > 0) {
|
|
7002
|
-
if (hasPendingManualScores(evalCases, manualScoreKeys)) return "unscored";
|
|
7003
|
-
return toLastRunStatus$1(deriveStatusFromCaseRows({ caseRows: evalCases }));
|
|
7004
|
-
}
|
|
7005
|
-
return toLastRunStatus$1(deriveStatusFromChildStatuses({
|
|
7006
|
-
statuses: [],
|
|
7007
|
-
lifecycleStatus: run.manifest.status
|
|
7008
|
-
}));
|
|
7009
|
-
}
|
|
7010
|
-
function hasPendingManualScores(caseRows, manualScoreKeys) {
|
|
7011
|
-
if (manualScoreKeys.length === 0) return false;
|
|
7012
|
-
return caseRows.some((caseRow) => manualScoreKeys.some((key) => {
|
|
7013
|
-
const value = caseRow.columns[key];
|
|
7014
|
-
return typeof value !== "number" || !Number.isFinite(value);
|
|
7015
|
-
}));
|
|
7016
|
-
}
|
|
7017
|
-
function encodeCaseDetailFileName(caseId) {
|
|
7018
|
-
return encodeURIComponent(caseId);
|
|
7019
|
-
}
|
|
7020
|
-
//#endregion
|
|
7021
6187
|
//#region ../runner/src/stackFormatting.ts
|
|
7022
6188
|
const orphanedAnsiSgrPattern = /\[(?:\d{1,3}(?:;\d{1,3})*)?m/g;
|
|
7023
6189
|
function stripTerminalControlCodes(value) {
|
|
7024
6190
|
return stripVTControlCharacters(value).replaceAll(orphanedAnsiSgrPattern, "");
|
|
7025
6191
|
}
|
|
7026
6192
|
//#endregion
|
|
6193
|
+
//#region ../runner/src/caseChildProtocol.ts
|
|
6194
|
+
function isCaseChildParentMessage(value) {
|
|
6195
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "start" && "context" in value;
|
|
6196
|
+
}
|
|
6197
|
+
function isCaseChildMessage(value) {
|
|
6198
|
+
if (typeof value !== "object" || value === null) return false;
|
|
6199
|
+
if (!("type" in value) || typeof value.type !== "string") return false;
|
|
6200
|
+
if (value.type === "done") return "result" in value;
|
|
6201
|
+
return value.type === "error" && "message" in value;
|
|
6202
|
+
}
|
|
6203
|
+
//#endregion
|
|
7027
6204
|
//#region ../runner/src/runExecution.ts
|
|
7028
6205
|
function filterEvalCases(cases, caseIds) {
|
|
7029
6206
|
if (!caseIds || caseIds.length === 0) return cases;
|
|
@@ -7335,645 +6512,4 @@ function toAssertionFailure(message, error = void 0, nameOverride = void 0) {
|
|
|
7335
6512
|
};
|
|
7336
6513
|
}
|
|
7337
6514
|
//#endregion
|
|
7338
|
-
|
|
7339
|
-
async function executeQueuedCases(params) {
|
|
7340
|
-
const { queuedCases, concurrency, globalTraceDisplay } = params;
|
|
7341
|
-
let nextCaseIndex = 0;
|
|
7342
|
-
let workerError = void 0;
|
|
7343
|
-
const workerCount = Math.min(concurrency, queuedCases.length);
|
|
7344
|
-
const workers = Array.from({ length: workerCount }, async () => {
|
|
7345
|
-
while (workerError === void 0) {
|
|
7346
|
-
const queuedCase = queuedCases[nextCaseIndex];
|
|
7347
|
-
nextCaseIndex += 1;
|
|
7348
|
-
if (queuedCase === void 0) return;
|
|
7349
|
-
try {
|
|
7350
|
-
await executeQueuedCase({
|
|
7351
|
-
queuedCase,
|
|
7352
|
-
globalTraceDisplay
|
|
7353
|
-
});
|
|
7354
|
-
} catch (error) {
|
|
7355
|
-
workerError = error instanceof Error ? error : new Error(String(error));
|
|
7356
|
-
return;
|
|
7357
|
-
}
|
|
7358
|
-
}
|
|
7359
|
-
});
|
|
7360
|
-
await Promise.all(workers);
|
|
7361
|
-
if (workerError instanceof Error) throw workerError;
|
|
7362
|
-
if (workerError !== void 0) throw new Error(typeof workerError === "string" ? workerError : typeof workerError === "number" || typeof workerError === "boolean" || typeof workerError === "bigint" ? String(workerError) : workerError === null ? "null" : "Unknown queue worker error");
|
|
7363
|
-
}
|
|
7364
|
-
async function executeQueuedCase(params) {
|
|
7365
|
-
const { queuedCase, globalTraceDisplay } = params;
|
|
7366
|
-
const startTime = Date.now();
|
|
7367
|
-
const result = await queuedCase.execute({
|
|
7368
|
-
globalTraceDisplay,
|
|
7369
|
-
startTime
|
|
7370
|
-
});
|
|
7371
|
-
await queuedCase.onComplete(result);
|
|
7372
|
-
}
|
|
7373
|
-
//#endregion
|
|
7374
|
-
//#region ../runner/src/tags.ts
|
|
7375
|
-
function getInvalidTagMessages(params) {
|
|
7376
|
-
return (params.tags ?? []).flatMap((tag) => {
|
|
7377
|
-
const validation = validateEvalTagName(tag);
|
|
7378
|
-
return validation.ok ? [] : [`${params.source} tag "${tag}" is invalid: ${validation.message}`];
|
|
7379
|
-
});
|
|
7380
|
-
}
|
|
7381
|
-
/** Resolve effective eval-level tags and discovery issues for one eval. */
|
|
7382
|
-
function resolveEvalTags(params) {
|
|
7383
|
-
const configTags = params.configTags ?? [];
|
|
7384
|
-
const removeTags = params.evalDef.removeTags ?? [];
|
|
7385
|
-
const messages = [
|
|
7386
|
-
...getInvalidTagMessages({
|
|
7387
|
-
tags: configTags,
|
|
7388
|
-
source: "config"
|
|
7389
|
-
}),
|
|
7390
|
-
...getInvalidTagMessages({
|
|
7391
|
-
tags: params.evalDef.tags,
|
|
7392
|
-
source: "eval"
|
|
7393
|
-
}),
|
|
7394
|
-
...getInvalidTagMessages({
|
|
7395
|
-
tags: removeTags,
|
|
7396
|
-
source: "removeTags"
|
|
7397
|
-
})
|
|
7398
|
-
];
|
|
7399
|
-
const globalTagSet = new Set(configTags);
|
|
7400
|
-
for (const tag of removeTags) if (!globalTagSet.has(tag)) messages.push(`removeTags tag "${tag}" is not defined in AgentEvalsConfig.tags.`);
|
|
7401
|
-
const removeTagSet = new Set(removeTags);
|
|
7402
|
-
return {
|
|
7403
|
-
tags: dedupeEvalTags([...configTags.filter((tag) => !removeTagSet.has(tag)), ...params.evalDef.tags ?? []]),
|
|
7404
|
-
issues: messages.map((message) => ({
|
|
7405
|
-
type: "invalid-tags",
|
|
7406
|
-
severity: "error",
|
|
7407
|
-
filePath: params.filePath,
|
|
7408
|
-
evalId: params.evalId,
|
|
7409
|
-
message: `Invalid tags for eval "${params.evalId}" in ${params.filePath}: ${message}`
|
|
7410
|
-
}))
|
|
7411
|
-
};
|
|
7412
|
-
}
|
|
7413
|
-
/** Return effective case tags or throw when authored case tags are invalid. */
|
|
7414
|
-
function resolveCaseTags(params) {
|
|
7415
|
-
const messages = getInvalidTagMessages({
|
|
7416
|
-
tags: params.evalCase.tags,
|
|
7417
|
-
source: `case "${params.evalCase.id}"`
|
|
7418
|
-
});
|
|
7419
|
-
if (messages.length > 0) throw new Error(`Invalid tags for case "${params.evalCase.id}" in ${params.filePath}#${params.evalId}: ${messages.join("; ")}`);
|
|
7420
|
-
return dedupeEvalTags([...params.evalTags, ...params.evalCase.tags ?? []]);
|
|
7421
|
-
}
|
|
7422
|
-
/** Validate CLI/API tags filters and return the first error message. */
|
|
7423
|
-
function validateTagsFilters(filters) {
|
|
7424
|
-
for (const filter of filters ?? []) {
|
|
7425
|
-
const error = validateTagsFilterExpression(filter);
|
|
7426
|
-
if (error !== null) return `Invalid --tags-filter "${filter}": ${error}`;
|
|
7427
|
-
}
|
|
7428
|
-
return null;
|
|
7429
|
-
}
|
|
7430
|
-
/** Filter cases by Vitest-style tag expressions. */
|
|
7431
|
-
function filterEvalCasesByTags(cases, tagsFilter) {
|
|
7432
|
-
if (tagsFilter === void 0 || tagsFilter.length === 0) return [...cases];
|
|
7433
|
-
return cases.filter((evalCase) => matchesTagsFilter({
|
|
7434
|
-
tags: evalCase.tags,
|
|
7435
|
-
filters: tagsFilter
|
|
7436
|
-
}));
|
|
7437
|
-
}
|
|
7438
|
-
/** Return whether eval-level tags alone satisfy the run's tag filters. */
|
|
7439
|
-
function evalTagsMatchFilter(params) {
|
|
7440
|
-
return matchesTagsFilter({
|
|
7441
|
-
tags: params.tags,
|
|
7442
|
-
filters: params.tagsFilter
|
|
7443
|
-
});
|
|
7444
|
-
}
|
|
7445
|
-
//#endregion
|
|
7446
|
-
//#region ../runner/src/targeting.ts
|
|
7447
|
-
function escapeRegex(value) {
|
|
7448
|
-
return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
7449
|
-
}
|
|
7450
|
-
function globToRegex(pattern) {
|
|
7451
|
-
const normalized = pattern.replaceAll("\\", "/");
|
|
7452
|
-
let regex = "^";
|
|
7453
|
-
for (let i = 0; i < normalized.length; i++) {
|
|
7454
|
-
const char = normalized[i];
|
|
7455
|
-
const next = normalized[i + 1];
|
|
7456
|
-
if (char === "*" && next === "*") {
|
|
7457
|
-
regex += ".*";
|
|
7458
|
-
i++;
|
|
7459
|
-
} else if (char === "*") regex += "[^/]*";
|
|
7460
|
-
else if (char === "?") regex += "[^/]";
|
|
7461
|
-
else regex += escapeRegex(char ?? "");
|
|
7462
|
-
}
|
|
7463
|
-
regex += "$";
|
|
7464
|
-
return new RegExp(regex);
|
|
7465
|
-
}
|
|
7466
|
-
function fileMatches(pattern, filePath) {
|
|
7467
|
-
const normalizedPattern = pattern.replaceAll("\\", "/");
|
|
7468
|
-
if (normalizedPattern === filePath) return true;
|
|
7469
|
-
return globToRegex(normalizedPattern).test(filePath);
|
|
7470
|
-
}
|
|
7471
|
-
function matchesFiles(evalMeta, files) {
|
|
7472
|
-
if (files === void 0 || files.length === 0) return true;
|
|
7473
|
-
return files.some((file) => fileMatches(file, evalMeta.filePath));
|
|
7474
|
-
}
|
|
7475
|
-
function matchesEvalIds(evalMeta, evalIds) {
|
|
7476
|
-
if (evalIds === void 0 || evalIds.length === 0) return true;
|
|
7477
|
-
return evalIds.includes(evalMeta.id);
|
|
7478
|
-
}
|
|
7479
|
-
function matchesEvalKeys(evalMeta, evalKeys) {
|
|
7480
|
-
if (evalKeys === void 0 || evalKeys.length === 0) return true;
|
|
7481
|
-
return evalKeys.includes(evalMeta.key);
|
|
7482
|
-
}
|
|
7483
|
-
/** Return the discovered evals selected by a run target. */
|
|
7484
|
-
function getTargetEvals(params) {
|
|
7485
|
-
const { target } = params.request;
|
|
7486
|
-
return [...params.evals].filter((evalMeta) => matchesEvalKeys(evalMeta, target.evalKeys)).filter((evalMeta) => matchesEvalIds(evalMeta, target.evalIds)).filter((evalMeta) => matchesFiles(evalMeta, target.files)).toSorted((a, b) => a.filePath.localeCompare(b.filePath));
|
|
7487
|
-
}
|
|
7488
|
-
/** Resolve which exact eval keys a run request can affect. */
|
|
7489
|
-
function getTargetEvalKeys(params) {
|
|
7490
|
-
return getTargetEvals({
|
|
7491
|
-
evals: params.sortedEvals,
|
|
7492
|
-
request: params.request
|
|
7493
|
-
}).map((evalMeta) => evalMeta.key);
|
|
7494
|
-
}
|
|
7495
|
-
//#endregion
|
|
7496
|
-
//#region ../runner/src/runOrchestration.ts
|
|
7497
|
-
function toOptionalSourceFingerprint(sourceFingerprint) {
|
|
7498
|
-
return sourceFingerprint.length > 0 ? sourceFingerprint : void 0;
|
|
7499
|
-
}
|
|
7500
|
-
function buildCaseModuleIsolation(params) {
|
|
7501
|
-
return {
|
|
7502
|
-
key: [
|
|
7503
|
-
params.runId,
|
|
7504
|
-
params.evalKey,
|
|
7505
|
-
params.caseId,
|
|
7506
|
-
`trial-${String(params.trial)}`
|
|
7507
|
-
].join(":"),
|
|
7508
|
-
workspaceRoot: params.workspaceRoot
|
|
7509
|
-
};
|
|
7510
|
-
}
|
|
7511
|
-
function buildEvalPreparationModuleIsolation(params) {
|
|
7512
|
-
return {
|
|
7513
|
-
key: [
|
|
7514
|
-
params.runId,
|
|
7515
|
-
params.evalKey,
|
|
7516
|
-
"prepare"
|
|
7517
|
-
].join(":"),
|
|
7518
|
-
workspaceRoot: params.workspaceRoot
|
|
7519
|
-
};
|
|
7520
|
-
}
|
|
7521
|
-
/**
|
|
7522
|
-
* Ranks case statuses from worst to best. Used to order trial attempts so the
|
|
7523
|
-
* pessimistic (`lowestScore`) strategy can pick the worst attempt. Any
|
|
7524
|
-
* non-terminal status outside `pass`/`fail`/`error` is treated as indistinct
|
|
7525
|
-
* from `fail` for comparison purposes.
|
|
7526
|
-
*/
|
|
7527
|
-
function statusRank(status) {
|
|
7528
|
-
if (status === "pass") return 2;
|
|
7529
|
-
if (status === "error") return 0;
|
|
7530
|
-
return 1;
|
|
7531
|
-
}
|
|
7532
|
-
/**
|
|
7533
|
-
* Returns the minimum numeric value across the declared score columns for a
|
|
7534
|
-
* trial, or `-Infinity` when no score has a numeric value. Used as a
|
|
7535
|
-
* tiebreaker between trials that share the same status.
|
|
7536
|
-
*/
|
|
7537
|
-
function minScoreValue(caseRow, scoreKeys) {
|
|
7538
|
-
let min = Number.POSITIVE_INFINITY;
|
|
7539
|
-
for (const key of scoreKeys) {
|
|
7540
|
-
const v = caseRow.columns[key];
|
|
7541
|
-
if (typeof v === "number" && Number.isFinite(v)) {
|
|
7542
|
-
if (v < min) min = v;
|
|
7543
|
-
}
|
|
7544
|
-
}
|
|
7545
|
-
return Number.isFinite(min) ? min : Number.NEGATIVE_INFINITY;
|
|
7546
|
-
}
|
|
7547
|
-
function compareTrialResults(left, right, scoreKeys) {
|
|
7548
|
-
const statusDiff = statusRank(left.caseRow.status) - statusRank(right.caseRow.status);
|
|
7549
|
-
if (statusDiff !== 0) return statusDiff;
|
|
7550
|
-
const scoreDiff = minScoreValue(left.caseRow, scoreKeys) - minScoreValue(right.caseRow, scoreKeys);
|
|
7551
|
-
if (scoreDiff !== 0) return scoreDiff;
|
|
7552
|
-
return left.caseRow.trial - right.caseRow.trial;
|
|
7553
|
-
}
|
|
7554
|
-
function pickWinningTrial(params) {
|
|
7555
|
-
const orderedAttempts = [...params.attempts].toSorted((left, right) => compareTrialResults(left, right, params.scoreKeys));
|
|
7556
|
-
if (params.strategy === "lowestScore") {
|
|
7557
|
-
const [lowestAttempt] = orderedAttempts;
|
|
7558
|
-
if (lowestAttempt === void 0) throw new Error("Expected at least one trial attempt");
|
|
7559
|
-
return lowestAttempt;
|
|
7560
|
-
}
|
|
7561
|
-
const medianAttempt = orderedAttempts[Math.floor((orderedAttempts.length - 1) / 2)];
|
|
7562
|
-
if (medianAttempt === void 0) throw new Error("Expected at least one trial attempt");
|
|
7563
|
-
return medianAttempt;
|
|
7564
|
-
}
|
|
7565
|
-
function formatUnknownErrorDetails(error) {
|
|
7566
|
-
if (error instanceof Error) return error.stack ?? error.message;
|
|
7567
|
-
if (typeof error === "string") return error;
|
|
7568
|
-
return String(error);
|
|
7569
|
-
}
|
|
7570
|
-
function findDuplicateCaseIds(cases) {
|
|
7571
|
-
const counts = /* @__PURE__ */ new Map();
|
|
7572
|
-
for (const evalCase of cases) counts.set(evalCase.id, (counts.get(evalCase.id) ?? 0) + 1);
|
|
7573
|
-
return [...counts].filter(([, count]) => count > 1).map(([caseId]) => caseId).toSorted();
|
|
7574
|
-
}
|
|
7575
|
-
function throwIfDiscoveryIssues(issues) {
|
|
7576
|
-
if (issues.length === 0) return;
|
|
7577
|
-
throw new Error(issues.map((issue) => issue.message).join("\n"));
|
|
7578
|
-
}
|
|
7579
|
-
function findAmbiguousTargetCaseIds(preparedEvals) {
|
|
7580
|
-
const ownersByCaseId = /* @__PURE__ */ new Map();
|
|
7581
|
-
for (const preparedEval of preparedEvals) for (const preparedCase of preparedEval.preparedCases) {
|
|
7582
|
-
const owners = ownersByCaseId.get(preparedCase.caseId) ?? /* @__PURE__ */ new Set();
|
|
7583
|
-
owners.add(`${preparedEval.evalMeta.filePath}#${preparedEval.evalMeta.id}`);
|
|
7584
|
-
ownersByCaseId.set(preparedCase.caseId, owners);
|
|
7585
|
-
}
|
|
7586
|
-
return [...ownersByCaseId].filter(([, owners]) => owners.size > 1).map(([caseId, owners]) => `${caseId} (${[...owners].join(", ")})`);
|
|
7587
|
-
}
|
|
7588
|
-
function buildRunErrorMessage(errors) {
|
|
7589
|
-
return errors.map((entry) => {
|
|
7590
|
-
const [firstLine, ...detailLines] = entry.details.split("\n");
|
|
7591
|
-
const messageLine = firstLine?.trim() ?? "Unknown error";
|
|
7592
|
-
const details = detailLines.join("\n").trim();
|
|
7593
|
-
if (details.length === 0) return `[${entry.evalId}] ${messageLine}`;
|
|
7594
|
-
return `[${entry.evalId}] ${messageLine}\n${details}`;
|
|
7595
|
-
}).join("\n");
|
|
7596
|
-
}
|
|
7597
|
-
async function finalizePreparedCase(params) {
|
|
7598
|
-
const { runState, runDir, preparedEval, preparedCase, onCaseFinished, emitEvent } = params;
|
|
7599
|
-
if (preparedCase.finalized || preparedCase.trialResults.length === 0) return;
|
|
7600
|
-
preparedCase.finalized = true;
|
|
7601
|
-
const winningTrial = pickWinningTrial({
|
|
7602
|
-
strategy: runState.manifest.trialSelection,
|
|
7603
|
-
attempts: preparedCase.trialResults,
|
|
7604
|
-
scoreKeys: preparedEval.scoreKeys
|
|
7605
|
-
});
|
|
7606
|
-
if (winningTrial.bufferedCacheStore !== null) await winningTrial.bufferedCacheStore.commit();
|
|
7607
|
-
const artifactFileId = getCaseArtifactFileId(runState, winningTrial.caseRow);
|
|
7608
|
-
runState.cases.push(winningTrial.caseRow);
|
|
7609
|
-
runState.caseDetails.set(getCaseRowCaseKey(winningTrial.caseRow), winningTrial.caseDetail);
|
|
7610
|
-
if (winningTrial.caseRow.status === "pass") runState.summary.passedCases++;
|
|
7611
|
-
else if (winningTrial.caseRow.status === "error") runState.summary.errorCases++;
|
|
7612
|
-
else runState.summary.failedCases++;
|
|
7613
|
-
await writeFile(join(runDir, "traces", `${encodeURIComponent(artifactFileId)}.json`), JSON.stringify(winningTrial.caseDetail.trace, null, 2));
|
|
7614
|
-
await persistCaseDetail(runDir, winningTrial.caseDetail, artifactFileId);
|
|
7615
|
-
onCaseFinished?.(winningTrial.caseDetail, winningTrial.caseRow);
|
|
7616
|
-
emitEvent(runState, {
|
|
7617
|
-
type: "case.finished",
|
|
7618
|
-
runId: runState.manifest.id,
|
|
7619
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7620
|
-
payload: winningTrial.caseRow
|
|
7621
|
-
});
|
|
7622
|
-
preparedEval.evalCaseRows.push(winningTrial.caseRow);
|
|
7623
|
-
}
|
|
7624
|
-
function getPreparedCaseOrderKey(caseRow) {
|
|
7625
|
-
return `${caseRow.evalKey ?? caseRow.evalId}\u0000${caseRow.caseId}`;
|
|
7626
|
-
}
|
|
7627
|
-
function getCaseArtifactFileId(runState, caseRow) {
|
|
7628
|
-
const caseKey = getCaseRowCaseKey(caseRow);
|
|
7629
|
-
return runState.cases.some((existing) => existing.caseId === caseRow.caseId && getCaseRowCaseKey(existing) !== caseKey) ? caseKey : caseRow.caseId;
|
|
7630
|
-
}
|
|
7631
|
-
function sortCaseRowsByPreparedOrder(caseRows, preparedEvals) {
|
|
7632
|
-
const orderByCase = /* @__PURE__ */ new Map();
|
|
7633
|
-
let order = 0;
|
|
7634
|
-
for (const preparedEval of preparedEvals) for (const preparedCase of preparedEval.preparedCases) {
|
|
7635
|
-
orderByCase.set(`${preparedEval.evalMeta.key}\u0000${preparedCase.caseId}`, order);
|
|
7636
|
-
order++;
|
|
7637
|
-
}
|
|
7638
|
-
caseRows.sort((left, right) => {
|
|
7639
|
-
return (orderByCase.get(getPreparedCaseOrderKey(left)) ?? Number.MAX_SAFE_INTEGER) - (orderByCase.get(getPreparedCaseOrderKey(right)) ?? Number.MAX_SAFE_INTEGER);
|
|
7640
|
-
});
|
|
7641
|
-
}
|
|
7642
|
-
async function executeRun({ runState, request, runDir, config, cacheStore, lastRunStatusMap, latestRunInfoMap, emitEvent, emitDiscoveryEvent, workspaceRoot, getSourceFingerprint, getConfiguredConcurrency, getSortedEvalMetas, getTargetEvals, onCaseFinished }) {
|
|
7643
|
-
try {
|
|
7644
|
-
const tagsFilterError = validateTagsFilters(request.target.tagsFilter);
|
|
7645
|
-
if (tagsFilterError !== null) throw new Error(tagsFilterError);
|
|
7646
|
-
const targetEvals = getTargetEvals(request);
|
|
7647
|
-
emitEvent(runState, {
|
|
7648
|
-
type: "run.started",
|
|
7649
|
-
runId: runState.manifest.id,
|
|
7650
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7651
|
-
payload: runState.manifest
|
|
7652
|
-
});
|
|
7653
|
-
const evalErrors = [];
|
|
7654
|
-
const queuedCases = [];
|
|
7655
|
-
const preparedEvals = [];
|
|
7656
|
-
const cacheMode = runState.manifest.cacheMode ?? "use";
|
|
7657
|
-
const cacheEnabled = config.cache?.enabled !== false;
|
|
7658
|
-
const llmCallsConfig = resolveLlmCallsConfig(config.llmCalls);
|
|
7659
|
-
const apiCallsConfig = resolveApiCallsConfig(config.apiCalls);
|
|
7660
|
-
for (const evalMeta of targetEvals) {
|
|
7661
|
-
const evalFilePath = evalMeta.sourceFilePath;
|
|
7662
|
-
const evalModuleIsolation = buildEvalPreparationModuleIsolation({
|
|
7663
|
-
runId: runState.manifest.id,
|
|
7664
|
-
evalKey: evalMeta.key,
|
|
7665
|
-
workspaceRoot
|
|
7666
|
-
});
|
|
7667
|
-
let sourceFingerprint = "";
|
|
7668
|
-
try {
|
|
7669
|
-
sourceFingerprint = getSourceFingerprint(await readFile(evalFilePath, "utf-8"));
|
|
7670
|
-
} catch {
|
|
7671
|
-
sourceFingerprint = "";
|
|
7672
|
-
}
|
|
7673
|
-
if (sourceFingerprint.length > 0) {
|
|
7674
|
-
runState.manifest.evalSourceFingerprints[evalMeta.key] = sourceFingerprint;
|
|
7675
|
-
evalMeta.sourceFingerprint = sourceFingerprint;
|
|
7676
|
-
} else {
|
|
7677
|
-
delete runState.manifest.evalSourceFingerprints[evalMeta.key];
|
|
7678
|
-
evalMeta.sourceFingerprint = null;
|
|
7679
|
-
}
|
|
7680
|
-
try {
|
|
7681
|
-
const entry = (await loadIsolatedEvalRegistry({
|
|
7682
|
-
evalFilePath,
|
|
7683
|
-
sourceFingerprint: toOptionalSourceFingerprint(sourceFingerprint),
|
|
7684
|
-
moduleIsolation: evalModuleIsolation,
|
|
7685
|
-
runtimeScope: "env"
|
|
7686
|
-
})).get(evalMeta.id);
|
|
7687
|
-
if (!entry) {
|
|
7688
|
-
evalErrors.push({
|
|
7689
|
-
evalId: evalMeta.id,
|
|
7690
|
-
details: `Eval "${evalMeta.id}" was not registered after importing ${evalFilePath}`
|
|
7691
|
-
});
|
|
7692
|
-
continue;
|
|
7693
|
-
}
|
|
7694
|
-
await runWithModuleIsolation(evalModuleIsolation, async () => {
|
|
7695
|
-
await runInEvalRuntimeScope("cases", async () => {
|
|
7696
|
-
await entry.use(async (evalDef) => {
|
|
7697
|
-
const evalTagsResult = resolveEvalTags({
|
|
7698
|
-
configTags: config.tags,
|
|
7699
|
-
evalDef,
|
|
7700
|
-
evalId: evalMeta.id,
|
|
7701
|
-
filePath: evalMeta.filePath
|
|
7702
|
-
});
|
|
7703
|
-
throwIfDiscoveryIssues(evalTagsResult.issues);
|
|
7704
|
-
evalMeta.tags = evalTagsResult.tags;
|
|
7705
|
-
if (evalDef.manualInput && evalDef.cases !== void 0) throw new Error(`Eval "${evalMeta.id}" cannot declare both "cases" and "manualInput". Remove one of them.`);
|
|
7706
|
-
let manualInputCase = null;
|
|
7707
|
-
if (evalDef.manualInput) {
|
|
7708
|
-
const manualTags = evalTagsResult.tags;
|
|
7709
|
-
if (!filterEvalCasesByTags([{
|
|
7710
|
-
id: `${evalMeta.id}-manual`,
|
|
7711
|
-
input: {},
|
|
7712
|
-
tags: manualTags
|
|
7713
|
-
}], request.target.tagsFilter).length) {
|
|
7714
|
-
evalMeta.caseCount = 1;
|
|
7715
|
-
evalMeta.caseIds = [`${evalMeta.id}-manual`];
|
|
7716
|
-
return;
|
|
7717
|
-
}
|
|
7718
|
-
const rawValue = request.manualInputs?.[evalMeta.key];
|
|
7719
|
-
if (rawValue === void 0) throw new Error(`Eval "${evalMeta.id}" requires manual input. Provide it via the run modal in the web UI or "--input" / "--input-file" on the CLI.`);
|
|
7720
|
-
const parsed = parseManualInputValues(evalDef.manualInput, rawValue);
|
|
7721
|
-
if (parsed.error) {
|
|
7722
|
-
const formatted = parsed.error.issues.map((issue) => issue.path ? `${issue.path}: ${issue.message}` : issue.message).join("; ");
|
|
7723
|
-
throw new Error(`Invalid manual input for eval "${evalMeta.id}": ${formatted}`);
|
|
7724
|
-
}
|
|
7725
|
-
manualInputCase = {
|
|
7726
|
-
id: `${evalMeta.id}-manual`,
|
|
7727
|
-
input: parsed.value,
|
|
7728
|
-
tags: manualTags
|
|
7729
|
-
};
|
|
7730
|
-
}
|
|
7731
|
-
const evalCases = manualInputCase ? [manualInputCase] : typeof evalDef.cases === "function" && !evalTagsMatchFilter({
|
|
7732
|
-
tags: evalTagsResult.tags,
|
|
7733
|
-
tagsFilter: request.target.tagsFilter
|
|
7734
|
-
}) ? [] : await runWithEvalClock(evalDef.startTime, async () => typeof evalDef.cases === "function" ? await evalDef.cases() : evalDef.cases ?? [], { freezeTime: evalDef.freezeTime });
|
|
7735
|
-
const runnableCases = (manualInputCase ? evalCases : resolveRunnableEvalCases({
|
|
7736
|
-
cases: evalCases,
|
|
7737
|
-
evalId: evalMeta.id
|
|
7738
|
-
})).map((evalCase) => ({
|
|
7739
|
-
...evalCase,
|
|
7740
|
-
tags: resolveCaseTags({
|
|
7741
|
-
evalTags: evalTagsResult.tags,
|
|
7742
|
-
evalCase,
|
|
7743
|
-
evalId: evalMeta.id,
|
|
7744
|
-
filePath: evalMeta.filePath
|
|
7745
|
-
})
|
|
7746
|
-
}));
|
|
7747
|
-
const duplicateCaseIds = findDuplicateCaseIds(runnableCases);
|
|
7748
|
-
if (duplicateCaseIds.length > 0) throw new Error(`Duplicate case id${duplicateCaseIds.length === 1 ? "" : "s"} in ${evalMeta.filePath}#${evalMeta.id}: ${duplicateCaseIds.join(", ")}`);
|
|
7749
|
-
const cases = filterEvalCasesByTags(filterEvalCases(runnableCases, request.target.caseIds), request.target.tagsFilter);
|
|
7750
|
-
evalMeta.caseCount = runnableCases.length;
|
|
7751
|
-
evalMeta.caseIds = runnableCases.map((evalCase) => evalCase.id);
|
|
7752
|
-
runState.summary.totalCases += cases.length;
|
|
7753
|
-
const defaultConfig = resolveEvalDefaultConfig({
|
|
7754
|
-
evalDef,
|
|
7755
|
-
globalColumns: config.columns,
|
|
7756
|
-
globalStats: config.stats,
|
|
7757
|
-
globalDefaultStatAggregate: config.defaultStatAggregate,
|
|
7758
|
-
globalRemove: config.removeDefaultConfig
|
|
7759
|
-
});
|
|
7760
|
-
const declaredColumnDefs = buildDeclaredColumnDefs(defaultConfig.columns, evalDef.scores, evalDef.manualScores);
|
|
7761
|
-
const validatedCharts = validateCharts({
|
|
7762
|
-
charts: defaultConfig.charts,
|
|
7763
|
-
columnDefs: declaredColumnDefs,
|
|
7764
|
-
evalId: evalMeta.id
|
|
7765
|
-
});
|
|
7766
|
-
for (const warning of validatedCharts.warnings) console.warn(warning);
|
|
7767
|
-
evalMeta.columnDefs = declaredColumnDefs;
|
|
7768
|
-
evalMeta.stats = defaultConfig.stats;
|
|
7769
|
-
evalMeta.defaultStatAggregate = defaultConfig.defaultStatAggregate;
|
|
7770
|
-
evalMeta.charts = validatedCharts.charts;
|
|
7771
|
-
const evalCaseRows = [];
|
|
7772
|
-
const preparedCases = [];
|
|
7773
|
-
const scoreKeys = Object.freeze(Object.keys(evalDef.scores ?? {}));
|
|
7774
|
-
const manualScoreKeys = Object.freeze(Object.keys(evalDef.manualScores ?? {}));
|
|
7775
|
-
const preparedEval = {
|
|
7776
|
-
evalMeta,
|
|
7777
|
-
evalCaseRows,
|
|
7778
|
-
preparedCases,
|
|
7779
|
-
scoreKeys: Object.freeze([...scoreKeys, ...manualScoreKeys])
|
|
7780
|
-
};
|
|
7781
|
-
preparedEvals.push(preparedEval);
|
|
7782
|
-
for (const evalCase of cases) {
|
|
7783
|
-
const trialResults = [];
|
|
7784
|
-
const preparedCase = {
|
|
7785
|
-
caseId: evalCase.id,
|
|
7786
|
-
trialResults,
|
|
7787
|
-
finalized: false
|
|
7788
|
-
};
|
|
7789
|
-
preparedCases.push(preparedCase);
|
|
7790
|
-
for (let trial = 0; trial < request.trials; trial++) {
|
|
7791
|
-
const bufferedCacheStore = cacheEnabled && cacheMode !== "bypass" ? createBufferedCacheStore(cacheStore) : null;
|
|
7792
|
-
const caseModuleIsolation = buildCaseModuleIsolation({
|
|
7793
|
-
runId: runState.manifest.id,
|
|
7794
|
-
evalKey: evalMeta.key,
|
|
7795
|
-
caseId: evalCase.id,
|
|
7796
|
-
trial,
|
|
7797
|
-
workspaceRoot
|
|
7798
|
-
});
|
|
7799
|
-
queuedCases.push({
|
|
7800
|
-
execute: async ({ startTime, globalTraceDisplay }) => {
|
|
7801
|
-
const { caseDetail, caseRowUpdate } = await useIsolatedEvalDefinition({
|
|
7802
|
-
evalId: evalMeta.id,
|
|
7803
|
-
evalFilePath,
|
|
7804
|
-
sourceFingerprint: toOptionalSourceFingerprint(sourceFingerprint),
|
|
7805
|
-
moduleIsolation: caseModuleIsolation,
|
|
7806
|
-
runtimeScope: "env",
|
|
7807
|
-
use: async (isolatedEvalDef) => await runCase({
|
|
7808
|
-
evalDef: isolatedEvalDef,
|
|
7809
|
-
evalId: evalMeta.id,
|
|
7810
|
-
evalKey: evalMeta.key,
|
|
7811
|
-
evalCase,
|
|
7812
|
-
globalTraceDisplay,
|
|
7813
|
-
globalColumns: config.columns,
|
|
7814
|
-
globalDeriveFromTracing: config.deriveFromTracing,
|
|
7815
|
-
llmCallsConfig,
|
|
7816
|
-
apiCallsConfig,
|
|
7817
|
-
globalRemoveDefaultConfig: config.removeDefaultConfig,
|
|
7818
|
-
trial,
|
|
7819
|
-
startTime,
|
|
7820
|
-
cacheAdapter: bufferedCacheStore ?? (cacheEnabled ? cacheStore : null),
|
|
7821
|
-
cacheMode,
|
|
7822
|
-
moduleIsolation: caseModuleIsolation,
|
|
7823
|
-
evalFilePath,
|
|
7824
|
-
evalFileRelativePath: evalMeta.filePath,
|
|
7825
|
-
workspaceRoot,
|
|
7826
|
-
artifactDir: join(runDir, "artifacts"),
|
|
7827
|
-
runId: runState.manifest.id
|
|
7828
|
-
})
|
|
7829
|
-
});
|
|
7830
|
-
return {
|
|
7831
|
-
caseDetail,
|
|
7832
|
-
caseRow: {
|
|
7833
|
-
caseId: evalCase.id,
|
|
7834
|
-
evalId: evalMeta.id,
|
|
7835
|
-
evalKey: evalMeta.key,
|
|
7836
|
-
caseKey: caseDetail.caseKey,
|
|
7837
|
-
tags: caseDetail.tags,
|
|
7838
|
-
status: caseRowUpdate.status ?? "pending",
|
|
7839
|
-
durationMs: caseRowUpdate.durationMs ?? null,
|
|
7840
|
-
cacheHits: caseRowUpdate.cacheHits ?? 0,
|
|
7841
|
-
cacheOperations: caseRowUpdate.cacheOperations ?? 0,
|
|
7842
|
-
columns: caseRowUpdate.columns ?? {},
|
|
7843
|
-
trial
|
|
7844
|
-
}
|
|
7845
|
-
};
|
|
7846
|
-
},
|
|
7847
|
-
onComplete: async ({ caseDetail, caseRow }) => {
|
|
7848
|
-
trialResults.push({
|
|
7849
|
-
caseDetail,
|
|
7850
|
-
caseRow,
|
|
7851
|
-
bufferedCacheStore
|
|
7852
|
-
});
|
|
7853
|
-
if (trialResults.length !== request.trials) return;
|
|
7854
|
-
await finalizePreparedCase({
|
|
7855
|
-
runState,
|
|
7856
|
-
runDir,
|
|
7857
|
-
preparedEval,
|
|
7858
|
-
preparedCase,
|
|
7859
|
-
onCaseFinished,
|
|
7860
|
-
emitEvent
|
|
7861
|
-
});
|
|
7862
|
-
}
|
|
7863
|
-
});
|
|
7864
|
-
}
|
|
7865
|
-
}
|
|
7866
|
-
});
|
|
7867
|
-
});
|
|
7868
|
-
});
|
|
7869
|
-
} catch (error) {
|
|
7870
|
-
console.error(`Error running eval ${evalMeta.id}:`, error);
|
|
7871
|
-
evalErrors.push({
|
|
7872
|
-
evalId: evalMeta.id,
|
|
7873
|
-
details: formatUnknownErrorDetails(error)
|
|
7874
|
-
});
|
|
7875
|
-
lastRunStatusMap.set(evalMeta.key, "error");
|
|
7876
|
-
latestRunInfoMap.set(evalMeta.key, {
|
|
7877
|
-
status: "error",
|
|
7878
|
-
startedAt: runState.manifest.endedAt ?? runState.manifest.startedAt,
|
|
7879
|
-
commitSha: runState.manifest.commitSha ?? null,
|
|
7880
|
-
evalSourceFingerprint: runState.manifest.evalSourceFingerprints[evalMeta.key] ?? null
|
|
7881
|
-
});
|
|
7882
|
-
}
|
|
7883
|
-
}
|
|
7884
|
-
const ambiguousCaseTargets = request.target.caseIds && request.target.caseIds.length > 0 ? findAmbiguousTargetCaseIds(preparedEvals) : [];
|
|
7885
|
-
if (ambiguousCaseTargets.length > 0) {
|
|
7886
|
-
queuedCases.length = 0;
|
|
7887
|
-
evalErrors.push({
|
|
7888
|
-
evalId: "target",
|
|
7889
|
-
details: `Ambiguous --case target. Narrow it with --file and/or --eval: ${ambiguousCaseTargets.join("; ")}`
|
|
7890
|
-
});
|
|
7891
|
-
} else await executeQueuedCases({
|
|
7892
|
-
queuedCases,
|
|
7893
|
-
concurrency: getConfiguredConcurrency(),
|
|
7894
|
-
globalTraceDisplay: config.traceDisplay
|
|
7895
|
-
});
|
|
7896
|
-
for (const preparedEval of preparedEvals) {
|
|
7897
|
-
for (const preparedCase of preparedEval.preparedCases) await finalizePreparedCase({
|
|
7898
|
-
runState,
|
|
7899
|
-
runDir,
|
|
7900
|
-
preparedEval,
|
|
7901
|
-
preparedCase,
|
|
7902
|
-
onCaseFinished,
|
|
7903
|
-
emitEvent
|
|
7904
|
-
});
|
|
7905
|
-
lastRunStatusMap.set(preparedEval.evalMeta.key, toLastRunStatus(deriveStatusFromCaseRows({ caseRows: preparedEval.evalCaseRows })));
|
|
7906
|
-
const latestStatus = lastRunStatusMap.get(preparedEval.evalMeta.key) ?? null;
|
|
7907
|
-
latestRunInfoMap.set(preparedEval.evalMeta.key, {
|
|
7908
|
-
status: latestStatus,
|
|
7909
|
-
startedAt: runState.manifest.endedAt ?? runState.manifest.startedAt,
|
|
7910
|
-
commitSha: runState.manifest.commitSha ?? null,
|
|
7911
|
-
evalSourceFingerprint: runState.manifest.evalSourceFingerprints[preparedEval.evalMeta.key] ?? null
|
|
7912
|
-
});
|
|
7913
|
-
}
|
|
7914
|
-
sortCaseRowsByPreparedOrder(runState.cases, preparedEvals);
|
|
7915
|
-
for (const preparedEval of preparedEvals) sortCaseRowsByPreparedOrder(preparedEval.evalCaseRows, preparedEvals);
|
|
7916
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
7917
|
-
runState.summary.totalDurationMs = endTime.getTime() - new Date(runState.manifest.startedAt).getTime();
|
|
7918
|
-
const finalStatus = evalErrors.length > 0 ? "error" : "completed";
|
|
7919
|
-
runState.summary.status = finalStatus;
|
|
7920
|
-
runState.manifest.status = finalStatus;
|
|
7921
|
-
const completedRunAt = endTime.toISOString();
|
|
7922
|
-
runState.manifest.endedAt = completedRunAt;
|
|
7923
|
-
runState.summary.errorMessage = evalErrors.length > 0 ? buildRunErrorMessage(evalErrors) : null;
|
|
7924
|
-
for (const evalKey of getTargetEvalKeys({
|
|
7925
|
-
request,
|
|
7926
|
-
sortedEvals: getSortedEvalMetas()
|
|
7927
|
-
})) {
|
|
7928
|
-
const latestStatus = lastRunStatusMap.get(evalKey) ?? toLastRunStatus(deriveStatusFromCaseRows({
|
|
7929
|
-
caseRows: [],
|
|
7930
|
-
lifecycleStatus: runState.manifest.status
|
|
7931
|
-
}));
|
|
7932
|
-
latestRunInfoMap.set(evalKey, {
|
|
7933
|
-
status: latestStatus,
|
|
7934
|
-
startedAt: completedRunAt,
|
|
7935
|
-
commitSha: runState.manifest.commitSha ?? null,
|
|
7936
|
-
evalSourceFingerprint: runState.manifest.evalSourceFingerprints[evalKey] ?? null
|
|
7937
|
-
});
|
|
7938
|
-
}
|
|
7939
|
-
await persistRunState(runState);
|
|
7940
|
-
emitEvent(runState, {
|
|
7941
|
-
type: "run.summary",
|
|
7942
|
-
runId: runState.manifest.id,
|
|
7943
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7944
|
-
payload: runState.summary
|
|
7945
|
-
});
|
|
7946
|
-
if (finalStatus === "error") emitEvent(runState, {
|
|
7947
|
-
type: "run.error",
|
|
7948
|
-
runId: runState.manifest.id,
|
|
7949
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7950
|
-
payload: { message: buildRunErrorMessage(evalErrors) }
|
|
7951
|
-
});
|
|
7952
|
-
else emitEvent(runState, {
|
|
7953
|
-
type: "run.finished",
|
|
7954
|
-
runId: runState.manifest.id,
|
|
7955
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7956
|
-
payload: runState.summary
|
|
7957
|
-
});
|
|
7958
|
-
emitDiscoveryEvent();
|
|
7959
|
-
} catch (error) {
|
|
7960
|
-
const message = formatUnknownErrorDetails(error);
|
|
7961
|
-
runState.manifest.status = "error";
|
|
7962
|
-
runState.manifest.endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7963
|
-
runState.summary.status = "error";
|
|
7964
|
-
runState.summary.errorMessage = message;
|
|
7965
|
-
await persistRunState(runState);
|
|
7966
|
-
emitEvent(runState, {
|
|
7967
|
-
type: "run.error",
|
|
7968
|
-
runId: runState.manifest.id,
|
|
7969
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7970
|
-
payload: { message }
|
|
7971
|
-
});
|
|
7972
|
-
emitDiscoveryEvent();
|
|
7973
|
-
}
|
|
7974
|
-
}
|
|
7975
|
-
function toLastRunStatus(status) {
|
|
7976
|
-
return status === "pending" ? null : status;
|
|
7977
|
-
}
|
|
7978
|
-
//#endregion
|
|
7979
|
-
export { getCurrentScope as $, validateCharts as A, buildEvalKey as At, deserializeCacheValue as B, deriveEvalFreshness as C, getEvalDisplayStatus as Ct, loadConfig as D, runSummarySchema as Dt, resolveEvalDefaultConfig as E, runManifestSchema as Et, evalSpan as F, evalChartsConfigSchema as Ft, readManualInputFile as G, serializeCacheValue as H, evalTracer as I, columnDefSchema as It, appendToEvalOutput as J, evalExpect as K, hashCacheKey as L, defineEval as Lt, z$1 as M, evalStatAggregateSchema as Mt, buildTraceTree as N, evalStatsConfigSchema as Nt, buildDeclaredColumnDefs as O, resolveApiCallsConfig as Ot, captureEvalSpanError as P, manualInputDescriptorSchema as Pt, evalTime as Q, hashCacheKeySync as R, getEvalRegistry as Rt, parseManualInputValues as S, getEvalTitle as St, parseEvalDiscovery as T, matchesTagsFilter as Tt, repoFile as U, serializeCacheRecording as V, manualInputFileValueSchema as W, evalAssert as X, configureEvalRunLogs as Y, evalLog as Z, recomputePersistedCaseStatus as _, extractLlmCalls as _t, validateTagsFilters as a, nextEvalId as at, resolveArtifactPath as b, applyDerivedCallAttributes as bt, getLastRunStatuses as c, runInExistingEvalScope as ct, loadPersistedRunSnapshots as d, startEvalBackgroundJob as dt, getEvalCaseInput as et, nextShortIdFromSnapshots as f, createRunRequestSchema as ft, recomputeEvalStatusesInRuns as g, extractApiCalls as gt, persistRunState as h, extractCacheHits as ht, resolveEvalTags as i, mergeEvalOutput as it, createFsCacheStore as j, getCaseRowCaseKey as jt, normalizeScoreDef as k, resolveLlmCallsConfig as kt, getLatestRunInfos as l, setEvalOutput as lt, deleteTemporaryRuns as m, extractCacheEntries as mt, getTargetEvalKeys as n, isInEvalScope as nt, stripTerminalControlCodes as o, runInEvalRuntimeScope as ot, persistCaseDetail as p, updateManualScoreRequestSchema as pt, EvalAssertionError as q, getTargetEvals as r, matchesEvalTags as rt, generateRunId as s, runInEvalScope as st, executeRun as t, incrementEvalOutput as tt, loadPersistedRunSnapshot as u, setScopeCacheContext as ut, runTouchesEval as v, simulateLlmCallCost as vt, loadIsolatedEvalRegistry as w, deriveScopedSummaryFromCases as wt, buildManualInputDescriptor as x, getNestedAttribute as xt, resolveTracePresentation as y, simulateTokenAllocation as yt, deserializeCacheRecording as z };
|
|
6515
|
+
export { startEvalBackgroundJob as $, repoFile as A, evalChartsConfigSchema as At, getCurrentScope as B, evalTracer as C, buildEvalKey as Ct, deserializeCacheValue as D, evalStatAggregateSchema as Dt, deserializeCacheRecording as E, caseRowSchema as Et, appendToEvalOutput as F, mergeEvalOutput as G, incrementEvalOutput as H, configureEvalRunLogs as I, runInEvalScope as J, nextEvalId as K, evalAssert as L, readManualInputFile as M, defineEval as Mt, evalExpect as N, getEvalRegistry as Nt, serializeCacheRecording as O, evalStatsConfigSchema as Ot, EvalAssertionError as P, runWithEvalRegistry as Pt, setScopeCacheContext as Q, evalLog as R, evalSpan as S, resolveLlmCallsConfig as St, hashCacheKeySync as T, caseDetailSchema as Tt, isInEvalScope as U, getEvalCaseInput as V, matchesEvalTags as W, runWithEvalClock as X, runInExistingEvalScope as Y, setEvalOutput as Z, createBufferedCacheStore as _, validateEvalTagName as _t, isCaseChildParentMessage as a, extractLlmCalls as at, buildTraceTree as b, runSummarySchema as bt, resolveArtifactPath as c, applyDerivedCallAttributes as ct, loadEvalModule as d, getEvalDisplayStatus as dt, createRunRequestSchema as et, resolveEvalDefaultConfig as f, deriveScopedSummaryFromCases as ft, commitPendingCacheWrites as g, matchesTagsFilter as gt, normalizeScoreDef as h, dedupeEvalTags as ht, isCaseChildMessage as i, extractApiCalls as it, manualInputFileValueSchema as j, columnDefSchema as jt, serializeCacheValue as k, manualInputDescriptorSchema as kt, registerAgentEvalsPackageResolutionHooks as l, getNestedAttribute as lt, buildDeclaredColumnDefs as m, deriveStatusFromChildStatuses as mt, resolveRunnableEvalCases as n, extractCacheEntries as nt, stripTerminalControlCodes as o, simulateLlmCallCost as ot, loadConfig as p, deriveStatusFromCaseRows as pt, runInEvalRuntimeScope as q, runCase as r, extractCacheHits as rt, resolveTracePresentation as s, simulateTokenAllocation as st, filterEvalCases as t, updateManualScoreRequestSchema as tt, runWithModuleIsolation as u, getEvalTitle as ut, createFsCacheStore as v, validateTagsFilterExpression as vt, hashCacheKey as w, getCaseRowCaseKey as wt, captureEvalSpanError as x, resolveApiCallsConfig as xt, z$1 as y, runManifestSchema as yt, evalTime as z };
|