@tangle-network/agent-eval 0.120.1 → 0.120.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/dist/analyst/index.d.ts +0 -3111
- package/dist/analyst/index.js +0 -403
- package/dist/analyst/index.js.map +0 -1
- package/dist/authenticity/index.d.ts +0 -161
- package/dist/authenticity/index.js +0 -215
- package/dist/authenticity/index.js.map +0 -1
- package/dist/belief-state/index.d.ts +0 -1301
- package/dist/belief-state/index.js +0 -2152
- package/dist/belief-state/index.js.map +0 -1
- package/dist/benchmarks/index.d.ts +0 -974
- package/dist/benchmarks/index.js +0 -60
- package/dist/benchmarks/index.js.map +0 -1
- package/dist/builder-eval/index.d.ts +0 -695
- package/dist/builder-eval/index.js +0 -366
- package/dist/builder-eval/index.js.map +0 -1
- package/dist/campaign/index.d.ts +0 -7454
- package/dist/campaign/index.js +0 -272
- package/dist/campaign/index.js.map +0 -1
- package/dist/chunk-32BZXMSO.js +0 -3878
- package/dist/chunk-32BZXMSO.js.map +0 -1
- package/dist/chunk-3A246TSA.js +0 -998
- package/dist/chunk-3A246TSA.js.map +0 -1
- package/dist/chunk-3RF76KTD.js +0 -84
- package/dist/chunk-3RF76KTD.js.map +0 -1
- package/dist/chunk-3YYRZDON.js +0 -45
- package/dist/chunk-3YYRZDON.js.map +0 -1
- package/dist/chunk-4I2E3LLO.js +0 -1030
- package/dist/chunk-4I2E3LLO.js.map +0 -1
- package/dist/chunk-ARU2PZFM.js +0 -312
- package/dist/chunk-ARU2PZFM.js.map +0 -1
- package/dist/chunk-BOD4O7OF.js +0 -40
- package/dist/chunk-BOD4O7OF.js.map +0 -1
- package/dist/chunk-DPZAEKA6.js +0 -880
- package/dist/chunk-DPZAEKA6.js.map +0 -1
- package/dist/chunk-DTJ6QUQB.js +0 -131
- package/dist/chunk-DTJ6QUQB.js.map +0 -1
- package/dist/chunk-GGE4NNQT.js +0 -65
- package/dist/chunk-GGE4NNQT.js.map +0 -1
- package/dist/chunk-H5UD2323.js +0 -286
- package/dist/chunk-H5UD2323.js.map +0 -1
- package/dist/chunk-HHWE3POT.js +0 -94
- package/dist/chunk-HHWE3POT.js.map +0 -1
- package/dist/chunk-HKUCJ437.js +0 -787
- package/dist/chunk-HKUCJ437.js.map +0 -1
- package/dist/chunk-JHCHEVET.js +0 -274
- package/dist/chunk-JHCHEVET.js.map +0 -1
- package/dist/chunk-JHOJHHU7.js +0 -867
- package/dist/chunk-JHOJHHU7.js.map +0 -1
- package/dist/chunk-JM2SKQMS.js +0 -750
- package/dist/chunk-JM2SKQMS.js.map +0 -1
- package/dist/chunk-JN2FCO5W.js +0 -7958
- package/dist/chunk-JN2FCO5W.js.map +0 -1
- package/dist/chunk-K4DBDHLK.js +0 -158
- package/dist/chunk-K4DBDHLK.js.map +0 -1
- package/dist/chunk-K6N6XJJX.js +0 -306
- package/dist/chunk-K6N6XJJX.js.map +0 -1
- package/dist/chunk-MA6HLL3S.js +0 -65
- package/dist/chunk-MA6HLL3S.js.map +0 -1
- package/dist/chunk-MAZ26DC7.js +0 -99
- package/dist/chunk-MAZ26DC7.js.map +0 -1
- package/dist/chunk-MOXWMGPC.js +0 -577
- package/dist/chunk-MOXWMGPC.js.map +0 -1
- package/dist/chunk-NJC7U437.js +0 -626
- package/dist/chunk-NJC7U437.js.map +0 -1
- package/dist/chunk-NPCTHQIO.js +0 -91
- package/dist/chunk-NPCTHQIO.js.map +0 -1
- package/dist/chunk-ONWEPEDO.js +0 -57
- package/dist/chunk-ONWEPEDO.js.map +0 -1
- package/dist/chunk-OYZAPX5G.js +0 -1526
- package/dist/chunk-OYZAPX5G.js.map +0 -1
- package/dist/chunk-PC4UYEBM.js +0 -166
- package/dist/chunk-PC4UYEBM.js.map +0 -1
- package/dist/chunk-PICTDURQ.js +0 -766
- package/dist/chunk-PICTDURQ.js.map +0 -1
- package/dist/chunk-PJQFMIOX.js +0 -1182
- package/dist/chunk-PJQFMIOX.js.map +0 -1
- package/dist/chunk-PXD6ZFNY.js +0 -1107
- package/dist/chunk-PXD6ZFNY.js.map +0 -1
- package/dist/chunk-PXE2VKMX.js +0 -140
- package/dist/chunk-PXE2VKMX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QBRSJK47.js +0 -622
- package/dist/chunk-QBRSJK47.js.map +0 -1
- package/dist/chunk-QWMPPZ3X.js +0 -550
- package/dist/chunk-QWMPPZ3X.js.map +0 -1
- package/dist/chunk-S3UZOQ5Y.js +0 -328
- package/dist/chunk-S3UZOQ5Y.js.map +0 -1
- package/dist/chunk-S5TT5R3L.js +0 -2668
- package/dist/chunk-S5TT5R3L.js.map +0 -1
- package/dist/chunk-T4SQEITX.js +0 -95
- package/dist/chunk-T4SQEITX.js.map +0 -1
- package/dist/chunk-TT4KNT67.js +0 -124
- package/dist/chunk-TT4KNT67.js.map +0 -1
- package/dist/chunk-U5CHZ5M3.js +0 -357
- package/dist/chunk-U5CHZ5M3.js.map +0 -1
- package/dist/chunk-ULOKLHIQ.js +0 -1937
- package/dist/chunk-ULOKLHIQ.js.map +0 -1
- package/dist/chunk-VI2UW6B6.js +0 -162
- package/dist/chunk-VI2UW6B6.js.map +0 -1
- package/dist/chunk-VQMK5FMP.js +0 -247
- package/dist/chunk-VQMK5FMP.js.map +0 -1
- package/dist/chunk-VSMTAMNK.js +0 -53
- package/dist/chunk-VSMTAMNK.js.map +0 -1
- package/dist/chunk-VZSRQ272.js +0 -149
- package/dist/chunk-VZSRQ272.js.map +0 -1
- package/dist/chunk-WW2A73HW.js +0 -159
- package/dist/chunk-WW2A73HW.js.map +0 -1
- package/dist/chunk-X4UCIOTZ.js +0 -136
- package/dist/chunk-X4UCIOTZ.js.map +0 -1
- package/dist/chunk-XDIRG3TO.js +0 -1266
- package/dist/chunk-XDIRG3TO.js.map +0 -1
- package/dist/chunk-XJYR7XFV.js +0 -317
- package/dist/chunk-XJYR7XFV.js.map +0 -1
- package/dist/chunk-ZET2UAYW.js +0 -89
- package/dist/chunk-ZET2UAYW.js.map +0 -1
- package/dist/chunk-ZZUXHH3R.js +0 -99
- package/dist/chunk-ZZUXHH3R.js.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -112
- package/dist/cli.js.map +0 -1
- package/dist/contract/index.d.ts +0 -4972
- package/dist/contract/index.js +0 -1654
- package/dist/contract/index.js.map +0 -1
- package/dist/control.d.ts +0 -1013
- package/dist/control.js +0 -34
- package/dist/control.js.map +0 -1
- package/dist/fuzz.d.ts +0 -759
- package/dist/fuzz.js +0 -714
- package/dist/fuzz.js.map +0 -1
- package/dist/hosted/index.d.ts +0 -730
- package/dist/hosted/index.js +0 -14
- package/dist/hosted/index.js.map +0 -1
- package/dist/index.d.ts +0 -16780
- package/dist/index.js +0 -12168
- package/dist/index.js.map +0 -1
- package/dist/matrix/index.d.ts +0 -155
- package/dist/matrix/index.js +0 -8
- package/dist/matrix/index.js.map +0 -1
- package/dist/meta-eval/index.d.ts +0 -1030
- package/dist/meta-eval/index.js +0 -417
- package/dist/meta-eval/index.js.map +0 -1
- package/dist/multishot/index.d.ts +0 -579
- package/dist/multishot/index.js +0 -589
- package/dist/multishot/index.js.map +0 -1
- package/dist/openapi.json +0 -992
- package/dist/pipelines/index.d.ts +0 -567
- package/dist/pipelines/index.js +0 -515
- package/dist/pipelines/index.js.map +0 -1
- package/dist/reporting.d.ts +0 -1277
- package/dist/reporting.js +0 -48
- package/dist/reporting.js.map +0 -1
- package/dist/rl.d.ts +0 -4092
- package/dist/rl.js +0 -1724
- package/dist/rl.js.map +0 -1
- package/dist/run-campaign-HNFPJET4.js +0 -14
- package/dist/run-campaign-HNFPJET4.js.map +0 -1
- package/dist/storyboard/index.d.ts +0 -279
- package/dist/storyboard/index.js +0 -767
- package/dist/storyboard/index.js.map +0 -1
- package/dist/trace-attributes.d.ts +0 -52
- package/dist/trace-attributes.js +0 -62
- package/dist/trace-attributes.js.map +0 -1
- package/dist/traces.d.ts +0 -2343
- package/dist/traces.js +0 -249
- package/dist/traces.js.map +0 -1
- package/dist/wire/index.d.ts +0 -1252
- package/dist/wire/index.js +0 -81
- package/dist/wire/index.js.map +0 -1
package/dist/chunk-T4SQEITX.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// src/runtime-trajectory.ts
|
|
2
|
-
var DEFAULT_SPLIT_TAG = "search";
|
|
3
|
-
function projectRuntimeTrajectoryEvidence(options) {
|
|
4
|
-
const diagnostics = [];
|
|
5
|
-
const runsById = /* @__PURE__ */ new Map();
|
|
6
|
-
const events = [];
|
|
7
|
-
let recordWithRuntimeEventsCount = 0;
|
|
8
|
-
let defaultedSplitCount = 0;
|
|
9
|
-
for (let recordIndex = 0; recordIndex < options.records.length; recordIndex += 1) {
|
|
10
|
-
const record = options.records[recordIndex];
|
|
11
|
-
const key = runtimeTrajectoryRecordKey(record, recordIndex, options.recordIdOf);
|
|
12
|
-
const splitTag = record.splitTag ?? options.defaultSplitTag ?? DEFAULT_SPLIT_TAG;
|
|
13
|
-
if (record.splitTag === void 0) defaultedSplitCount += 1;
|
|
14
|
-
const rawEvents = record.runtimeEvents;
|
|
15
|
-
if (!Array.isArray(rawEvents)) {
|
|
16
|
-
diagnostics.push(
|
|
17
|
-
`${key}: runtimeEvents is not an array; no runtime run join can be extracted`
|
|
18
|
-
);
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
if (rawEvents.length === 0) {
|
|
22
|
-
diagnostics.push(`${key}: no runtimeEvents; no runtime run join can be extracted`);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
recordWithRuntimeEventsCount += 1;
|
|
26
|
-
for (let index = 0; index < rawEvents.length; index += 1) {
|
|
27
|
-
const event = parseRuntimeTrajectoryHookEvent(rawEvents[index]);
|
|
28
|
-
if (!event) {
|
|
29
|
-
diagnostics.push(`${key}: runtimeEvents[${index}] is not a RuntimeHookEvent`);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
events.push(event);
|
|
33
|
-
const scenarioId = event.scenarioId ?? stringOrUndefined(options.scenarioIdOf?.(record, recordIndex)) ?? stringOrUndefined(record.scenarioId);
|
|
34
|
-
const prior = runsById.get(event.runId);
|
|
35
|
-
if (!prior) {
|
|
36
|
-
runsById.set(event.runId, { runId: event.runId, scenarioId, splitTag });
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (prior.scenarioId !== scenarioId || prior.splitTag !== splitTag) {
|
|
40
|
-
diagnostics.push(`${key}: runId ${event.runId} has conflicting scenario/split metadata`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const runs = [...runsById.values()];
|
|
45
|
-
return {
|
|
46
|
-
runs,
|
|
47
|
-
events,
|
|
48
|
-
summary: {
|
|
49
|
-
recordCount: options.records.length,
|
|
50
|
-
recordWithRuntimeEventsCount,
|
|
51
|
-
runtimeRunCount: runs.length,
|
|
52
|
-
lifecycleEventCount: events.length,
|
|
53
|
-
defaultedSplitCount
|
|
54
|
-
},
|
|
55
|
-
diagnostics
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function parseRuntimeTrajectoryHookEvent(input) {
|
|
59
|
-
if (!isRecord(input)) return null;
|
|
60
|
-
if (typeof input.id !== "string" || input.id.length === 0) return null;
|
|
61
|
-
if (typeof input.runId !== "string" || input.runId.length === 0) return null;
|
|
62
|
-
if (typeof input.target !== "string" || input.target.length === 0) return null;
|
|
63
|
-
if (typeof input.phase !== "string" || input.phase.length === 0) return null;
|
|
64
|
-
if (typeof input.timestamp !== "number" || !Number.isFinite(input.timestamp)) return null;
|
|
65
|
-
return {
|
|
66
|
-
id: input.id,
|
|
67
|
-
runId: input.runId,
|
|
68
|
-
scenarioId: stringOrUndefined(input.scenarioId),
|
|
69
|
-
target: input.target,
|
|
70
|
-
phase: input.phase,
|
|
71
|
-
timestamp: input.timestamp,
|
|
72
|
-
stepIndex: finiteNumberOrUndefined(input.stepIndex),
|
|
73
|
-
parentId: stringOrUndefined(input.parentId),
|
|
74
|
-
payload: input.payload,
|
|
75
|
-
metadata: isRecord(input.metadata) ? { ...input.metadata } : void 0
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function runtimeTrajectoryRecordKey(record, index, recordIdOf) {
|
|
79
|
-
return stringOrUndefined(recordIdOf?.(record, index)) ?? stringOrUndefined(record.id) ?? `record[${index}]`;
|
|
80
|
-
}
|
|
81
|
-
function isRecord(value) {
|
|
82
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
83
|
-
}
|
|
84
|
-
function stringOrUndefined(value) {
|
|
85
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
86
|
-
}
|
|
87
|
-
function finiteNumberOrUndefined(value) {
|
|
88
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export {
|
|
92
|
-
projectRuntimeTrajectoryEvidence,
|
|
93
|
-
parseRuntimeTrajectoryHookEvent
|
|
94
|
-
};
|
|
95
|
-
//# sourceMappingURL=chunk-T4SQEITX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime-trajectory.ts"],"sourcesContent":["import type { RunSplitTag } from './run-record'\n\nexport interface RuntimeTrajectoryHookEvent {\n id: string\n runId: string\n scenarioId?: string\n target: string\n phase: string\n timestamp: number\n stepIndex?: number\n parentId?: string\n payload?: unknown\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeTrajectoryRecord {\n id?: string\n scenarioId?: string\n splitTag?: RunSplitTag\n runtimeEvents?: unknown\n [key: string]: unknown\n}\n\nexport interface RuntimeTrajectoryRunRecord {\n runId: string\n scenarioId?: string\n splitTag: RunSplitTag\n}\n\nexport interface RuntimeTrajectoryEvidenceSummary {\n recordCount: number\n recordWithRuntimeEventsCount: number\n runtimeRunCount: number\n lifecycleEventCount: number\n defaultedSplitCount: number\n}\n\nexport interface RuntimeTrajectoryEvidenceProjection {\n runs: RuntimeTrajectoryRunRecord[]\n events: RuntimeTrajectoryHookEvent[]\n summary: RuntimeTrajectoryEvidenceSummary\n diagnostics: string[]\n}\n\nexport interface ProjectRuntimeTrajectoryEvidenceOptions<\n TRecord extends RuntimeTrajectoryRecord = RuntimeTrajectoryRecord,\n> {\n records: TRecord[]\n defaultSplitTag?: RunSplitTag\n recordIdOf?: (record: TRecord, index: number) => string | undefined\n scenarioIdOf?: (record: TRecord, index: number) => string | undefined\n}\n\nconst DEFAULT_SPLIT_TAG: RunSplitTag = 'search'\n\nexport function projectRuntimeTrajectoryEvidence<TRecord extends RuntimeTrajectoryRecord>(\n options: ProjectRuntimeTrajectoryEvidenceOptions<TRecord>,\n): RuntimeTrajectoryEvidenceProjection {\n const diagnostics: string[] = []\n const runsById = new Map<string, RuntimeTrajectoryRunRecord>()\n const events: RuntimeTrajectoryHookEvent[] = []\n let recordWithRuntimeEventsCount = 0\n let defaultedSplitCount = 0\n\n for (let recordIndex = 0; recordIndex < options.records.length; recordIndex += 1) {\n const record = options.records[recordIndex]!\n const key = runtimeTrajectoryRecordKey(record, recordIndex, options.recordIdOf)\n const splitTag = record.splitTag ?? options.defaultSplitTag ?? DEFAULT_SPLIT_TAG\n if (record.splitTag === undefined) defaultedSplitCount += 1\n\n const rawEvents = record.runtimeEvents\n if (!Array.isArray(rawEvents)) {\n diagnostics.push(\n `${key}: runtimeEvents is not an array; no runtime run join can be extracted`,\n )\n continue\n }\n if (rawEvents.length === 0) {\n diagnostics.push(`${key}: no runtimeEvents; no runtime run join can be extracted`)\n continue\n }\n recordWithRuntimeEventsCount += 1\n\n for (let index = 0; index < rawEvents.length; index += 1) {\n const event = parseRuntimeTrajectoryHookEvent(rawEvents[index])\n if (!event) {\n diagnostics.push(`${key}: runtimeEvents[${index}] is not a RuntimeHookEvent`)\n continue\n }\n events.push(event)\n\n const scenarioId =\n event.scenarioId ??\n stringOrUndefined(options.scenarioIdOf?.(record, recordIndex)) ??\n stringOrUndefined(record.scenarioId)\n const prior = runsById.get(event.runId)\n if (!prior) {\n runsById.set(event.runId, { runId: event.runId, scenarioId, splitTag })\n continue\n }\n if (prior.scenarioId !== scenarioId || prior.splitTag !== splitTag) {\n diagnostics.push(`${key}: runId ${event.runId} has conflicting scenario/split metadata`)\n }\n }\n }\n\n const runs = [...runsById.values()]\n return {\n runs,\n events,\n summary: {\n recordCount: options.records.length,\n recordWithRuntimeEventsCount,\n runtimeRunCount: runs.length,\n lifecycleEventCount: events.length,\n defaultedSplitCount,\n },\n diagnostics,\n }\n}\n\nexport function parseRuntimeTrajectoryHookEvent(input: unknown): RuntimeTrajectoryHookEvent | null {\n if (!isRecord(input)) return null\n if (typeof input.id !== 'string' || input.id.length === 0) return null\n if (typeof input.runId !== 'string' || input.runId.length === 0) return null\n if (typeof input.target !== 'string' || input.target.length === 0) return null\n if (typeof input.phase !== 'string' || input.phase.length === 0) return null\n if (typeof input.timestamp !== 'number' || !Number.isFinite(input.timestamp)) return null\n\n return {\n id: input.id,\n runId: input.runId,\n scenarioId: stringOrUndefined(input.scenarioId),\n target: input.target,\n phase: input.phase,\n timestamp: input.timestamp,\n stepIndex: finiteNumberOrUndefined(input.stepIndex),\n parentId: stringOrUndefined(input.parentId),\n payload: input.payload,\n metadata: isRecord(input.metadata) ? { ...input.metadata } : undefined,\n }\n}\n\nfunction runtimeTrajectoryRecordKey<TRecord extends RuntimeTrajectoryRecord>(\n record: TRecord,\n index: number,\n recordIdOf?: (record: TRecord, index: number) => string | undefined,\n): string {\n return (\n stringOrUndefined(recordIdOf?.(record, index)) ??\n stringOrUndefined(record.id) ??\n `record[${index}]`\n )\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction stringOrUndefined(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction finiteNumberOrUndefined(value: un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UAAU,KAAK;AAEnB;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,kBAAkB,OAAoC;AAC7D,SAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,wBAAwB,OAAoC;AACnE,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;","names":[]}
|
package/dist/chunk-TT4KNT67.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CaptureIntegrityError
|
|
3
|
-
} from "./chunk-ONWEPEDO.js";
|
|
4
|
-
|
|
5
|
-
// src/trace/integrity.ts
|
|
6
|
-
var RunIntegrityError = class extends CaptureIntegrityError {
|
|
7
|
-
constructor(report) {
|
|
8
|
-
super(
|
|
9
|
-
`Run ${report.runId} failed integrity check: ${report.issues.map((i) => i.code).join(", ")}`
|
|
10
|
-
);
|
|
11
|
-
this.report = report;
|
|
12
|
-
}
|
|
13
|
-
report;
|
|
14
|
-
};
|
|
15
|
-
async function assertRunCaptured(store, runId, expectations = {}) {
|
|
16
|
-
const issues = [];
|
|
17
|
-
const run = await store.getRun(runId);
|
|
18
|
-
if (!run) {
|
|
19
|
-
return {
|
|
20
|
-
ok: false,
|
|
21
|
-
runId,
|
|
22
|
-
llmSpanCount: 0,
|
|
23
|
-
judgeSpanCount: 0,
|
|
24
|
-
toolSpanCount: 0,
|
|
25
|
-
rawProviderEventCount: 0,
|
|
26
|
-
rawSpanCoverage: { covered: 0, total: 0 },
|
|
27
|
-
issues: [{ code: "no_run", message: `Run ${runId} not found in store.` }]
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const spans = await store.spans({ runId });
|
|
31
|
-
const llmSpans = spans.filter((s) => s.kind === "llm");
|
|
32
|
-
const judgeSpans = spans.filter((s) => s.kind === "judge");
|
|
33
|
-
const toolSpans = spans.filter((s) => s.kind === "tool");
|
|
34
|
-
const llmMin = expectations.llmSpansMin ?? 0;
|
|
35
|
-
const judgeMin = expectations.judgeSpansMin ?? 0;
|
|
36
|
-
const toolMin = expectations.toolSpansMin ?? 0;
|
|
37
|
-
if (llmSpans.length < llmMin) {
|
|
38
|
-
issues.push({
|
|
39
|
-
code: "missing_llm_spans",
|
|
40
|
-
message: `Expected \u2265 ${llmMin} LLM spans, found ${llmSpans.length}.`,
|
|
41
|
-
detail: { expected: llmMin, found: llmSpans.length }
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (judgeSpans.length < judgeMin) {
|
|
45
|
-
issues.push({
|
|
46
|
-
code: "missing_judge_spans",
|
|
47
|
-
message: `Expected \u2265 ${judgeMin} judge spans, found ${judgeSpans.length}.`,
|
|
48
|
-
detail: { expected: judgeMin, found: judgeSpans.length }
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (toolSpans.length < toolMin) {
|
|
52
|
-
issues.push({
|
|
53
|
-
code: "missing_tool_spans",
|
|
54
|
-
message: `Expected \u2265 ${toolMin} tool spans, found ${toolSpans.length}.`,
|
|
55
|
-
detail: { expected: toolMin, found: toolSpans.length }
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
let rawEventCount = 0;
|
|
59
|
-
let coverage = { covered: 0, total: llmSpans.length };
|
|
60
|
-
if (expectations.rawSink) {
|
|
61
|
-
if (!expectations.rawSink.list) {
|
|
62
|
-
issues.push({
|
|
63
|
-
code: "no_raw_sink",
|
|
64
|
-
message: "Provided rawSink does not implement list(); cannot verify capture."
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
const events = await expectations.rawSink.list({ runId });
|
|
68
|
-
rawEventCount = events.length;
|
|
69
|
-
const rawMin = expectations.rawProviderEventsMin ?? 1;
|
|
70
|
-
if (rawEventCount < rawMin) {
|
|
71
|
-
issues.push({
|
|
72
|
-
code: "missing_raw_events",
|
|
73
|
-
message: `Expected \u2265 ${rawMin} raw provider events, found ${rawEventCount}.`,
|
|
74
|
-
detail: { expected: rawMin, found: rawEventCount }
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (expectations.requireRawCoverageOfLlmSpans) {
|
|
78
|
-
const requestEventsBySpan = new Set(
|
|
79
|
-
events.filter((e) => e.direction === "request" && e.spanId).map((e) => e.spanId)
|
|
80
|
-
);
|
|
81
|
-
const orphaned = llmSpans.filter((s) => !requestEventsBySpan.has(s.spanId));
|
|
82
|
-
coverage = { covered: llmSpans.length - orphaned.length, total: llmSpans.length };
|
|
83
|
-
if (orphaned.length > 0) {
|
|
84
|
-
issues.push({
|
|
85
|
-
code: "orphan_llm_span",
|
|
86
|
-
message: `${orphaned.length} LLM span(s) have no matching raw provider request event.`,
|
|
87
|
-
detail: { orphanedSpanIds: orphaned.map((s) => s.spanId) }
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else if (expectations.requireRawCoverageOfLlmSpans || expectations.rawProviderEventsMin) {
|
|
93
|
-
issues.push({
|
|
94
|
-
code: "no_raw_sink",
|
|
95
|
-
message: "Raw coverage required but no rawSink supplied to the integrity check."
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (expectations.requireOutcome && (run.outcome === void 0 || run.outcome === null)) {
|
|
99
|
-
issues.push({
|
|
100
|
-
code: "missing_outcome",
|
|
101
|
-
message: `Run ${runId} has no outcome recorded.`
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
ok: issues.length === 0,
|
|
106
|
-
runId,
|
|
107
|
-
llmSpanCount: llmSpans.length,
|
|
108
|
-
judgeSpanCount: judgeSpans.length,
|
|
109
|
-
toolSpanCount: toolSpans.length,
|
|
110
|
-
rawProviderEventCount: rawEventCount,
|
|
111
|
-
rawSpanCoverage: coverage,
|
|
112
|
-
issues
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function throwIfRunIncomplete(report) {
|
|
116
|
-
if (!report.ok) throw new RunIntegrityError(report);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
RunIntegrityError,
|
|
121
|
-
assertRunCaptured,
|
|
122
|
-
throwIfRunIncomplete
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=chunk-TT4KNT67.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/trace/integrity.ts"],"sourcesContent":["/**\n * Run-completion integrity check — at end of run, verify the expected event\n * types were actually captured. The point is the launch-review failure mode:\n * a run *appears* successful but the raw provider events were never written,\n * so a downstream reviewer can't reconstruct what happened.\n *\n * Pattern:\n *\n * const report = await assertRunCaptured(store, runId, {\n * llmSpansMin: 1,\n * judgeSpansMin: 1,\n * rawSink: providerSink, // must have ≥ 1 event for this run\n * requireRawCoverageOfLlmSpans: true, // every llm span has matching raw events\n * })\n * if (!report.ok) throwIfRunIncomplete(report) // or mark run failed and continue\n *\n * The function is read-only on the store and returns a structured report;\n * the caller chooses the failure mode (throw, mark run failed, log warning).\n * `throwIfRunIncomplete` is the convenient strict mode.\n */\n\nimport { CaptureIntegrityError } from '../errors'\nimport type { RawProviderSink } from './raw-provider-sink'\nimport type { TraceStore } from './store'\n\nexport interface RunIntegrityExpectations {\n /** Minimum LLM span count. Default 0 (no requirement). */\n llmSpansMin?: number\n /** Minimum judge span count. Default 0. */\n judgeSpansMin?: number\n /** Minimum tool span count. Default 0. */\n toolSpansMin?: number\n /**\n * Raw provider sink to consult for capture verification. When present,\n * the check requires at least one raw event for the run.\n */\n rawSink?: RawProviderSink\n /** Minimum raw provider event count. Default 0; ignored when `rawSink` absent. */\n rawProviderEventsMin?: number\n /**\n * Every LLM span must have at least one matching raw `request` event\n * (matched by spanId). Catches the common bug where the structured span\n * was emitted but the raw HTTP capture was wired to a different sink.\n */\n requireRawCoverageOfLlmSpans?: boolean\n /** Run outcome must be set (not null/undefined). Default false. */\n requireOutcome?: boolean\n}\n\nexport type RunIntegrityIssueCode =\n | 'no_run'\n | 'missing_llm_spans'\n | 'missing_judge_spans'\n | 'missing_tool_spans'\n | 'missing_raw_events'\n | 'no_raw_sink'\n | 'orphan_llm_span'\n | 'missing_outcome'\n\nexport interface RunIntegrityIssue {\n code: RunIntegrityIssueCode\n message: string\n detail?: Record<string, unknown>\n}\n\nexport interface RunIntegrityReport {\n ok: boolean\n runId: string\n llmSpanCount: number\n judgeSpanCount: number\n toolSpanCount: number\n rawProviderEventCount: number\n /**\n * Coverage of LLM spans by raw provider events keyed on spanId.\n * `total` is the number of LLM spans; `covered` is the count with at\n * least one matching `request` raw event.\n */\n rawSpanCoverage: { covered: number; total: number }\n issues: RunIntegrityIssue[]\n}\n\nexport class RunIntegrityError extends CaptureIntegrityError {\n constructor(public readonly report: RunIntegrityReport) {\n super(\n `Run ${report.runId} failed integrity check: ${report.issues.map((i) => i.code).join(', ')}`,\n )\n }\n}\n\nexport async function assertRunCaptured(\n store: TraceStore,\n runId: string,\n expectations: RunIntegrityExpectations = {},\n): Promise<RunIntegrityReport> {\n const issues: RunIntegrityIssue[] = []\n const run = await store.getRun(runId)\n if (!run) {\n return {\n ok: false,\n runId,\n llmSpanCount: 0,\n judgeSpanCount: 0,\n toolSpanCount: 0,\n rawProviderEventCount: 0,\n rawSpanCoverage: { covered: 0, total: 0 },\n issues: [{ code: 'no_run', message: `Run ${runId} not found in store.` }],\n }\n }\n\n const spans = await store.spans({ runId })\n const llmSpans = spans.filter((s) => s.kind === 'llm')\n const judgeSpans = spans.filter((s) => s.kind === 'judge')\n const toolSpans = spans.filter((s) => s.kind === 'tool')\n\n const llmMin = expectations.llmSpansMin ?? 0\n const judgeMin = expectations.judgeSpansMin ?? 0\n const toolMin = expectations.toolSpansMin ?? 0\n\n if (llmSpans.length < llmMin) {\n issues.push({\n code: 'missing_llm_spans',\n message: `Expected ≥ ${llmMin} LLM spans, found ${llmSpans.length}.`,\n detail: { expected: llmMin, found: llmSpans.length },\n })\n }\n if (judgeSpans.length < judgeMin) {\n issues.push({\n code: 'missing_judge_spans',\n message: `Expected ≥ ${judgeMin} judge spans, found ${judgeSpans.length}.`,\n detail: { expected: judgeMin, found: judgeSpans.length },\n })\n }\n if (toolSpans.length < toolMin) {\n issues.push({\n code: 'missing_tool_spans',\n message: `Expected ≥ ${toolMin} tool spans, found ${toolSpans.length}.`,\n detail: { expected: toolMin, found: toolSpans.length },\n })\n }\n\n let rawEventCount = 0\n let coverage = { covered: 0, total: llmSpans.length }\n\n if (expectations.rawSink) {\n if (!expectations.rawSink.list) {\n issues.push({\n code: 'no_raw_sink',\n message: 'Provided rawSink does not implement list(); cannot verify capture.',\n })\n } else {\n const events = await expectations.rawSink.list({ runId })\n rawEventCount = events.length\n const rawMin = expectations.rawProviderEventsMin ?? 1\n if (rawEventCount < rawMin) {\n issues.push({\n code: 'missing_raw_events',\n message: `Expected ≥ ${rawMin} raw provider events, found ${rawEventCount}.`,\n detail: { expected: rawMin, found: rawEventCount },\n })\n }\n if (expectations.requireRawCoverageOfLlmSpans) {\n const requestEventsBySpan = new Set(\n events.filter((e) => e.direction === 'request' && e.spanId).map((e) => e.spanId!),\n )\n const orphaned = llmSpans.filter((s) => !requestEventsBySpan.has(s.spanId))\n coverage = { covered: llmSpans.length - orphaned.length, total: llmSpans.length }\n if (orphaned.length > 0) {\n issues.push({\n code: 'orphan_llm_span',\n message: `${orphaned.length} LLM span(s) have no matching raw provider request event.`,\n detail: { orphanedSpanIds: orphaned.map((s) => s.spanId) },\n })\n }\n }\n }\n } else if (expectations.requireRawCoverageOfLlmSpans || expectations.rawProviderEventsMin) {\n issues.push({\n code: 'no_raw_sink',\n message: 'Raw coverage required but no rawSink supplied to the integrity check.',\n })\n }\n\n if (expectations.requireOutcome && (run.outcome === undefined || run.outcome === null)) {\n issues.push({\n code: 'missing_outcome',\n message: `Run ${runId} has no outcome recorded.`,\n })\n }\n\n return {\n ok: issues.length === 0,\n runId,\n llmSpanCount: llmSpans.length,\n judgeSpanCount: judgeSpans.length,\n toolSpanCount: toolSpans.length,\n rawProviderEventCount: rawEventCount,\n rawSpanCoverage: coverage,\n issues,\n }\n}\n\n/** Strict mode: throws `RunIntegrityError` when the report isn't ok. */\nexport function throwIfRunIncomplete(report: RunIntegrityReport): void {\n if (!report.ok) throw new RunIntegrityError(report)\n}\n"],"mappings":";;;;;AAiFO,IAAM,oBAAN,cAAgC,sBAAsB;AAAA,EAC3D,YAA4B,QAA4B;AACtD;AAAA,MACE,OAAO,OAAO,KAAK,4BAA4B,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;AAAA,IAC5F;AAH0B;AAAA,EAI5B;AAAA,EAJ4B;AAK9B;AAEA,eAAsB,kBACpB,OACA,OACA,eAAyC,CAAC,GACb;AAC7B,QAAM,SAA8B,CAAC;AACrC,QAAM,MAAM,MAAM,MAAM,OAAO,KAAK;AACpC,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,MACL,IAAI;AAAA,MACJ;AAAA,MACA,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,uBAAuB;AAAA,MACvB,iBAAiB,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,MACxC,QAAQ,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,KAAK,uBAAuB,CAAC;AAAA,IAC1E;AAAA,EACF;AAEA,QAAM,QAAQ,MAAM,MAAM,MAAM,EAAE,MAAM,CAAC;AACzC,QAAM,WAAW,MAAM,OAAO,CAAC,MAAM,EAAE,SAAS,KAAK;AACrD,QAAM,aAAa,MAAM,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO;AACzD,QAAM,YAAY,MAAM,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM;AAEvD,QAAM,SAAS,aAAa,eAAe;AAC3C,QAAM,WAAW,aAAa,iBAAiB;AAC/C,QAAM,UAAU,aAAa,gBAAgB;AAE7C,MAAI,SAAS,SAAS,QAAQ;AAC5B,WAAO,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,MAAO;AAAA,QAClF;AACA,cAAM,WAAW,SAAS,OAAO,CAAC,MAAM,CAAC,oBAAoB,IAAI,EAAE,MAAM,CAAC;AAC1E,mBAAW,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,OAAO,SAAS,OAAO;AAChF,YAAI,SAAS,SAAS,GAAG;AACvB,iBAAO,KAAK;AAAA,YACV,MAAM;AAAA,YACN,SAAS,GAAG,SAAS,MAAM;AAAA,YAC3B,QAAQ,EAAE,iBAAiB,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;AAAA,UAC3D,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,WAAW,aAAa,gCAAgC,aAAa,sBAAsB;AACzF,WAAO,KAAK;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,MAAI,aAAa,mBAAmB,IAAI,YAAY,UAAa,IAAI,YAAY,OAAO;AACtF,WAAO,KAAK;AAAA,MACV,MAAM;AAAA,MACN,SAAS,OAAO,KAAK;AAAA,IACvB,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,IAAI,OAAO,WAAW;AAAA,IACtB;AAAA,IACA,cAAc,SAAS;AAAA,IACvB,gBAAgB,WAAW;AAAA,IAC3B,eAAe,UAAU;AAAA,IACzB,uBAAuB;AAAA,IACvB,iBAAiB;AAAA,IACjB;AAAA,EACF;AACF;AAGO,SAAS,qBAAqB,QAAkC;AACrE,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,kBAAkB,MAAM;AACpD;","names":[]}
|
package/dist/chunk-U5CHZ5M3.js
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertLlmRoute
|
|
3
|
-
} from "./chunk-NJC7U437.js";
|
|
4
|
-
import {
|
|
5
|
-
researchReport
|
|
6
|
-
} from "./chunk-DPZAEKA6.js";
|
|
7
|
-
import {
|
|
8
|
-
RunIntegrityError,
|
|
9
|
-
assertRunCaptured
|
|
10
|
-
} from "./chunk-TT4KNT67.js";
|
|
11
|
-
import {
|
|
12
|
-
FileSystemRawProviderSink
|
|
13
|
-
} from "./chunk-PC4UYEBM.js";
|
|
14
|
-
import {
|
|
15
|
-
TraceEmitter
|
|
16
|
-
} from "./chunk-VQMK5FMP.js";
|
|
17
|
-
import {
|
|
18
|
-
validateRunRecord
|
|
19
|
-
} from "./chunk-S3UZOQ5Y.js";
|
|
20
|
-
import {
|
|
21
|
-
buildAgentProfileCell,
|
|
22
|
-
verifyAgentProfileCell
|
|
23
|
-
} from "./chunk-XJYR7XFV.js";
|
|
24
|
-
import {
|
|
25
|
-
canonicalize,
|
|
26
|
-
hashJson
|
|
27
|
-
} from "./chunk-VSMTAMNK.js";
|
|
28
|
-
|
|
29
|
-
// src/eval-campaign.ts
|
|
30
|
-
var DEFAULT_INTEGRITY = {
|
|
31
|
-
llmSpansMin: 1,
|
|
32
|
-
requireRawCoverageOfLlmSpans: true,
|
|
33
|
-
requireOutcome: true
|
|
34
|
-
};
|
|
35
|
-
var DEFAULT_ROUTE = {
|
|
36
|
-
requireExplicitBaseUrl: true,
|
|
37
|
-
requireAuth: true
|
|
38
|
-
};
|
|
39
|
-
async function runEvalCampaign(opts) {
|
|
40
|
-
assertLlmRoute(opts.llmOpts, opts.routeRequirements ?? DEFAULT_ROUTE);
|
|
41
|
-
if (opts.variants.length === 0) {
|
|
42
|
-
throw new Error("runEvalCampaign: variants must be non-empty.");
|
|
43
|
-
}
|
|
44
|
-
if (opts.scenarios.length === 0) {
|
|
45
|
-
throw new Error("runEvalCampaign: scenarios must be non-empty.");
|
|
46
|
-
}
|
|
47
|
-
const variantIds = /* @__PURE__ */ new Set();
|
|
48
|
-
for (const v of opts.variants) {
|
|
49
|
-
if (variantIds.has(v.id)) {
|
|
50
|
-
throw new Error(`runEvalCampaign: duplicate variant id "${v.id}".`);
|
|
51
|
-
}
|
|
52
|
-
variantIds.add(v.id);
|
|
53
|
-
}
|
|
54
|
-
const scenarioIds = /* @__PURE__ */ new Set();
|
|
55
|
-
for (const s of opts.scenarios) {
|
|
56
|
-
if (scenarioIds.has(s.scenarioId)) {
|
|
57
|
-
throw new Error(`runEvalCampaign: duplicate scenarioId "${s.scenarioId}".`);
|
|
58
|
-
}
|
|
59
|
-
scenarioIds.add(s.scenarioId);
|
|
60
|
-
}
|
|
61
|
-
if (opts.report?.comparator && !variantIds.has(opts.report.comparator)) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`runEvalCampaign: report.comparator "${opts.report.comparator}" is not a configured variantId.`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
if (!opts.commitSha) {
|
|
67
|
-
throw new Error("runEvalCampaign: commitSha is required (every RunRecord needs it).");
|
|
68
|
-
}
|
|
69
|
-
const seeds = opts.seeds ?? [0, 1, 2];
|
|
70
|
-
const splitTag = opts.splitTag ?? "holdout";
|
|
71
|
-
const concurrency = Math.max(1, opts.concurrency ?? 1);
|
|
72
|
-
const integrity = { ...DEFAULT_INTEGRITY, ...opts.integrity ?? {} };
|
|
73
|
-
const onIntegrityFailure = opts.onIntegrityFailure ?? "mark_failed";
|
|
74
|
-
const now = opts.now ?? (() => Date.now());
|
|
75
|
-
const baseUrl = (opts.llmOpts.baseUrl ?? "").replace(/\/+$/, "");
|
|
76
|
-
const provider = opts.llmOpts.provider ?? null;
|
|
77
|
-
const preregistrationHash = opts.preregistrationHash ?? null;
|
|
78
|
-
const rawSinkFactory = opts.rawSinkFactory ?? defaultRawSinkFactory(opts.workDir);
|
|
79
|
-
const campaignFingerprint = await hashJson(
|
|
80
|
-
canonicalize({
|
|
81
|
-
campaignId: opts.campaignId,
|
|
82
|
-
variants: opts.variants.map((v) => v.id).sort(),
|
|
83
|
-
scenarios: opts.scenarios.map((s) => s.scenarioId).sort(),
|
|
84
|
-
seeds: [...seeds].sort((a, b) => a - b),
|
|
85
|
-
splitTag,
|
|
86
|
-
comparator: opts.report?.comparator ?? null,
|
|
87
|
-
baseUrl,
|
|
88
|
-
provider,
|
|
89
|
-
preregistrationHash
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
const cells = [];
|
|
93
|
-
for (const variant of opts.variants) {
|
|
94
|
-
for (const scenario of opts.scenarios) {
|
|
95
|
-
for (const seed of seeds) {
|
|
96
|
-
cells.push({ variant, scenario, seed });
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const startedAt = new Date(now()).toISOString();
|
|
101
|
-
const runs = [];
|
|
102
|
-
const integrityReports = [];
|
|
103
|
-
const failedRuns = [];
|
|
104
|
-
let cursor = 0;
|
|
105
|
-
let aborting = false;
|
|
106
|
-
const genuineErrors = [];
|
|
107
|
-
const openRuns = /* @__PURE__ */ new Map();
|
|
108
|
-
async function worker() {
|
|
109
|
-
while (!aborting) {
|
|
110
|
-
const i = cursor++;
|
|
111
|
-
if (i >= cells.length) return;
|
|
112
|
-
const cell = cells[i];
|
|
113
|
-
try {
|
|
114
|
-
const result = await runOneCell(cell);
|
|
115
|
-
runs.push(result.record);
|
|
116
|
-
integrityReports.push(result.integrity);
|
|
117
|
-
} catch (err) {
|
|
118
|
-
if (err instanceof CellExecutionError) {
|
|
119
|
-
failedRuns.push(err.failed);
|
|
120
|
-
if (err.integrity) integrityReports.push(err.integrity);
|
|
121
|
-
} else {
|
|
122
|
-
genuineErrors.push(err);
|
|
123
|
-
aborting = true;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async function runOneCell(cell) {
|
|
130
|
-
const runId = (opts.runId ?? defaultRunId)({
|
|
131
|
-
campaignId: opts.campaignId,
|
|
132
|
-
runId: "",
|
|
133
|
-
// unused by default generator
|
|
134
|
-
variantId: cell.variant.id,
|
|
135
|
-
scenarioId: cell.scenario.scenarioId,
|
|
136
|
-
seed: cell.seed
|
|
137
|
-
});
|
|
138
|
-
const factoryParams = {
|
|
139
|
-
campaignId: opts.campaignId,
|
|
140
|
-
runId,
|
|
141
|
-
variantId: cell.variant.id,
|
|
142
|
-
scenarioId: cell.scenario.scenarioId,
|
|
143
|
-
seed: cell.seed
|
|
144
|
-
};
|
|
145
|
-
const store = opts.storeFactory(factoryParams);
|
|
146
|
-
const rawSink = rawSinkFactory(factoryParams);
|
|
147
|
-
const emitter = new TraceEmitter(store, {
|
|
148
|
-
runId,
|
|
149
|
-
now: opts.now,
|
|
150
|
-
onRunComplete: opts.onRunComplete
|
|
151
|
-
});
|
|
152
|
-
openRuns.set(runId, emitter);
|
|
153
|
-
const llmOpts = {
|
|
154
|
-
...opts.llmOpts,
|
|
155
|
-
rawSink,
|
|
156
|
-
traceContext: { runId }
|
|
157
|
-
};
|
|
158
|
-
const ctx = {
|
|
159
|
-
runId,
|
|
160
|
-
experimentId: opts.campaignId,
|
|
161
|
-
variant: cell.variant.payload,
|
|
162
|
-
variantId: cell.variant.id,
|
|
163
|
-
scenarioId: cell.scenario.scenarioId,
|
|
164
|
-
scenarioTags: cell.scenario.tags ?? {},
|
|
165
|
-
seed: cell.seed,
|
|
166
|
-
splitTag,
|
|
167
|
-
emitter,
|
|
168
|
-
store,
|
|
169
|
-
rawSink,
|
|
170
|
-
llmOpts
|
|
171
|
-
};
|
|
172
|
-
try {
|
|
173
|
-
const wallStart = now();
|
|
174
|
-
let outcome;
|
|
175
|
-
try {
|
|
176
|
-
outcome = await opts.runner(ctx);
|
|
177
|
-
} catch (err) {
|
|
178
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
179
|
-
await finalizeAbort(emitter, runId, message);
|
|
180
|
-
throw new CellExecutionError({
|
|
181
|
-
runId,
|
|
182
|
-
variantId: cell.variant.id,
|
|
183
|
-
scenarioId: cell.scenario.scenarioId,
|
|
184
|
-
seed: cell.seed,
|
|
185
|
-
reason: "runner_threw",
|
|
186
|
-
error: message
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
const wallMs = now() - wallStart;
|
|
190
|
-
const integrityReport = await assertRunCaptured(store, runId, { ...integrity, rawSink });
|
|
191
|
-
if (!integrityReport.ok) {
|
|
192
|
-
switch (onIntegrityFailure) {
|
|
193
|
-
case "throw":
|
|
194
|
-
throw new RunIntegrityError(integrityReport);
|
|
195
|
-
case "mark_failed":
|
|
196
|
-
throw new CellExecutionError(
|
|
197
|
-
{
|
|
198
|
-
runId,
|
|
199
|
-
variantId: cell.variant.id,
|
|
200
|
-
scenarioId: cell.scenario.scenarioId,
|
|
201
|
-
seed: cell.seed,
|
|
202
|
-
reason: "integrity_failed",
|
|
203
|
-
error: integrityReport.issues.map((i) => i.code).join(", ")
|
|
204
|
-
},
|
|
205
|
-
integrityReport
|
|
206
|
-
);
|
|
207
|
-
case "log":
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const recordOutcome = {
|
|
212
|
-
raw: outcome.raw ?? {}
|
|
213
|
-
};
|
|
214
|
-
if (splitTag === "holdout") recordOutcome.holdoutScore = outcome.score;
|
|
215
|
-
else recordOutcome.searchScore = outcome.score;
|
|
216
|
-
if (outcome.judgeScores !== void 0) recordOutcome.judgeScores = outcome.judgeScores;
|
|
217
|
-
const record = {
|
|
218
|
-
runId,
|
|
219
|
-
experimentId: opts.campaignId,
|
|
220
|
-
candidateId: cell.variant.id,
|
|
221
|
-
seed: cell.seed,
|
|
222
|
-
model: outcome.model,
|
|
223
|
-
promptHash: outcome.promptHash,
|
|
224
|
-
configHash: outcome.configHash,
|
|
225
|
-
commitSha: opts.commitSha,
|
|
226
|
-
wallMs,
|
|
227
|
-
costUsd: outcome.costUsd,
|
|
228
|
-
tokenUsage: outcome.tokenUsage,
|
|
229
|
-
judgeMetadata: outcome.judgeMetadata,
|
|
230
|
-
outcome: recordOutcome,
|
|
231
|
-
...outcome.failureClass ? { failureClass: outcome.failureClass } : {},
|
|
232
|
-
failureMode: outcome.failureMode,
|
|
233
|
-
splitTag,
|
|
234
|
-
scenarioId: cell.scenario.scenarioId
|
|
235
|
-
};
|
|
236
|
-
const profileSource = outcome.agentProfile ?? (typeof opts.agentProfile === "function" ? await opts.agentProfile({
|
|
237
|
-
campaignId: opts.campaignId,
|
|
238
|
-
runId,
|
|
239
|
-
variantId: cell.variant.id,
|
|
240
|
-
scenarioId: cell.scenario.scenarioId,
|
|
241
|
-
seed: cell.seed,
|
|
242
|
-
variant: cell.variant.payload,
|
|
243
|
-
scenarioTags: cell.scenario.tags ?? {}
|
|
244
|
-
}) : opts.agentProfile);
|
|
245
|
-
if (profileSource !== void 0) {
|
|
246
|
-
const agentProfile = await resolveAgentProfileCell(profileSource);
|
|
247
|
-
assertAgentProfileMatchesRun(agentProfile, outcome.model, outcome.promptHash);
|
|
248
|
-
record.agentProfile = agentProfile;
|
|
249
|
-
}
|
|
250
|
-
return { record: validateRunRecord(record), integrity: integrityReport };
|
|
251
|
-
} finally {
|
|
252
|
-
openRuns.delete(runId);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const workers = Array.from({ length: Math.min(concurrency, cells.length) }, () => worker());
|
|
256
|
-
await Promise.allSettled(workers);
|
|
257
|
-
for (const [runId, emitter] of openRuns) {
|
|
258
|
-
await finalizeAbort(emitter, runId, "campaign aborted: genuine error in a sibling run");
|
|
259
|
-
}
|
|
260
|
-
openRuns.clear();
|
|
261
|
-
if (genuineErrors.length > 0) {
|
|
262
|
-
throw genuineErrors.length === 1 ? genuineErrors[0] : new AggregateError(
|
|
263
|
-
genuineErrors,
|
|
264
|
-
`runEvalCampaign: ${genuineErrors.length} runs failed with genuine (non-run-level) errors`
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
let report;
|
|
268
|
-
if (opts.report) {
|
|
269
|
-
const reportOpts = {
|
|
270
|
-
...opts.report,
|
|
271
|
-
comparator: opts.report.comparator,
|
|
272
|
-
split: splitTag === "dev" ? "search" : splitTag,
|
|
273
|
-
generatedAt: new Date(now()).toISOString(),
|
|
274
|
-
preregistrationHash: preregistrationHash ?? void 0
|
|
275
|
-
};
|
|
276
|
-
report = await researchReport(runs, reportOpts);
|
|
277
|
-
}
|
|
278
|
-
const endedAt = new Date(now()).toISOString();
|
|
279
|
-
return {
|
|
280
|
-
campaignId: opts.campaignId,
|
|
281
|
-
campaignFingerprint,
|
|
282
|
-
preregistrationHash,
|
|
283
|
-
runs,
|
|
284
|
-
integrityReports,
|
|
285
|
-
failedRuns,
|
|
286
|
-
report,
|
|
287
|
-
startedAt,
|
|
288
|
-
endedAt
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
var CellExecutionError = class extends Error {
|
|
292
|
-
failed;
|
|
293
|
-
integrity;
|
|
294
|
-
constructor(failed, integrity) {
|
|
295
|
-
super(`cell ${failed.variantId}/${failed.scenarioId}@${failed.seed} failed: ${failed.reason}`);
|
|
296
|
-
this.failed = failed;
|
|
297
|
-
this.integrity = integrity;
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
async function finalizeAbort(emitter, runId, reason) {
|
|
301
|
-
const existing = await emitter.traceStore.getRun(runId);
|
|
302
|
-
if (existing === void 0) return;
|
|
303
|
-
if (existing.status !== "running") return;
|
|
304
|
-
await emitter.abortRun(reason);
|
|
305
|
-
}
|
|
306
|
-
function defaultRawSinkFactory(workDir) {
|
|
307
|
-
return (params) => {
|
|
308
|
-
if (!workDir) {
|
|
309
|
-
throw new Error(
|
|
310
|
-
"runEvalCampaign: rawSinkFactory not supplied and workDir not set. Pass either to enable raw provider capture, or pass `new NoopRawProviderSink()` via rawSinkFactory to opt out explicitly."
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
return new FileSystemRawProviderSink({
|
|
314
|
-
dir: `${workDir}/raw-events/${params.runId}`
|
|
315
|
-
});
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
async function resolveAgentProfileCell(input) {
|
|
319
|
-
if (isAgentProfileCell(input)) {
|
|
320
|
-
if (!await verifyAgentProfileCell(input)) {
|
|
321
|
-
throw new Error(`runEvalCampaign: agentProfile.cellId does not match its content`);
|
|
322
|
-
}
|
|
323
|
-
return input;
|
|
324
|
-
}
|
|
325
|
-
return buildAgentProfileCell(input);
|
|
326
|
-
}
|
|
327
|
-
function isAgentProfileCell(input) {
|
|
328
|
-
return "schemaVersion" in input && "cellId" in input;
|
|
329
|
-
}
|
|
330
|
-
function assertAgentProfileMatchesRun(profile, model, promptHash) {
|
|
331
|
-
if (profile.model !== void 0 && profile.model !== model) {
|
|
332
|
-
throw new Error(
|
|
333
|
-
`runEvalCampaign: agentProfile.model "${profile.model}" does not match outcome.model "${model}"`
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
if (profile.promptHash !== void 0 && profile.promptHash !== promptHash) {
|
|
337
|
-
throw new Error(
|
|
338
|
-
`runEvalCampaign: agentProfile.promptHash "${profile.promptHash}" does not match outcome.promptHash "${promptHash}"`
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function defaultRunId(params) {
|
|
343
|
-
const base = `${params.campaignId}::${params.variantId}::${params.scenarioId}::${params.seed}`;
|
|
344
|
-
let h1 = 2166136261;
|
|
345
|
-
let h2 = 305419896;
|
|
346
|
-
for (let i = 0; i < base.length; i++) {
|
|
347
|
-
const c = base.charCodeAt(i);
|
|
348
|
-
h1 = Math.imul(h1 ^ c, 16777619) >>> 0;
|
|
349
|
-
h2 = Math.imul(h2 ^ c, 2654435761) >>> 0;
|
|
350
|
-
}
|
|
351
|
-
return `run-${h1.toString(16).padStart(8, "0")}${h2.toString(16).padStart(8, "0")}`;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export {
|
|
355
|
-
runEvalCampaign
|
|
356
|
-
};
|
|
357
|
-
//# sourceMappingURL=chunk-U5CHZ5M3.js.map
|