@ls-stack/agent-eval 0.58.2 → 0.58.4

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.
@@ -1,7 +1,7 @@
1
- import { Et as getCaseRowCaseKey, Ot as caseRowSchema, dt as getEvalTitle, nt as updateManualScoreRequestSchema, rt as extractCacheEntries, tt as createRunRequestSchema } from "./runExecution-pHJ0_TzH.mjs";
2
- import { o as stageManualInputFile } from "./cli-HBwXIJsg.mjs";
3
- import "./src-AeXGBJ26.mjs";
4
- import { t as getRunnerInstance } from "./runner-D_pz2NON.mjs";
1
+ import { Dt as getCaseRowCaseKey, ft as getEvalTitle, it as extractCacheEntries, kt as caseRowSchema, nt as createRunRequestSchema, rt as updateManualScoreRequestSchema } from "./runExecution-CLkC-4Z1.mjs";
2
+ import { o as stageManualInputFile } from "./cli-Bf5RzM8O.mjs";
3
+ import "./src-BjMMDm_O.mjs";
4
+ import { t as getRunnerInstance } from "./runner-DW-11txl.mjs";
5
5
  import { z } from "zod/v4";
6
6
  import { readFile } from "node:fs/promises";
7
7
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -56,6 +56,8 @@ const assetsRoutes = new Hono().get("/repo-file", async (c) => {
56
56
  * - `DELETE /` clears the entire cache directory.
57
57
  * - `DELETE /actions/eval?evalKey=<key>` clears entries recorded by saved runs
58
58
  * for one exact eval identity.
59
+ * - `DELETE /actions/run-history/:runId` clears entries recorded by the run
60
+ * and all earlier saved runs.
59
61
  * - `DELETE /:namespace` clears one namespace.
60
62
  * - `DELETE /:namespace/:key` clears a single entry by its key hash.
61
63
  */
@@ -84,6 +86,20 @@ const cacheRoutes = new Hono().get("/", async (c) => {
84
86
  ok: true,
85
87
  deletedEntries: entries.length
86
88
  }, 200);
89
+ }).delete("/actions/run-history/:runId", async (c) => {
90
+ const runId = c.req.param("runId");
91
+ const runner = getRunnerInstance();
92
+ const entries = getCacheEntriesForRunAndPrevious(runner, runId);
93
+ if (entries === null) return c.json({ error: "Run not found" }, 404);
94
+ await Promise.all(entries.map((entry) => runner.clearCache({
95
+ namespace: entry.namespace,
96
+ key: entry.key
97
+ })));
98
+ return c.json({
99
+ ok: true,
100
+ deletedEntries: entries.length,
101
+ entries
102
+ }, 200);
87
103
  }).delete("/:namespace", async (c) => {
88
104
  const namespace = c.req.param("namespace");
89
105
  await getRunnerInstance().clearCache({ namespace });
@@ -106,17 +122,53 @@ function getCacheEntriesForEvalRuns(runner, evalKey) {
106
122
  if (caseRow.evalKey !== evalKey) continue;
107
123
  const caseDetail = runner.getCaseDetail(manifest.id, caseRow.caseId);
108
124
  if (caseDetail === void 0) continue;
109
- for (const entry of extractCacheEntries(caseDetail.trace, caseDetail.cacheRefs)) {
110
- if (!entry.stored) continue;
111
- entries.set(`${entry.namespace}\u0000${entry.key}`, {
112
- namespace: entry.namespace,
113
- key: entry.key
114
- });
115
- }
125
+ for (const entry of getStoredCacheEntriesForCase(caseDetail)) entries.set(`${entry.namespace}\u0000${entry.key}`, {
126
+ namespace: entry.namespace,
127
+ key: entry.key
128
+ });
116
129
  }
117
130
  }
118
131
  return [...entries.values()];
119
132
  }
133
+ function getCacheEntriesForRunAndPrevious(runner, runId) {
134
+ const selectedRun = runner.getRun(runId);
135
+ if (selectedRun === void 0) return null;
136
+ const entries = /* @__PURE__ */ new Map();
137
+ for (const manifest of runner.getRuns()) {
138
+ const run = runner.getRun(manifest.id);
139
+ if (run === void 0) continue;
140
+ if (!runIsSelectedOrPrevious(run.manifest, selectedRun.manifest)) continue;
141
+ for (const caseRow of run.cases) {
142
+ const caseDetail = runner.getCaseDetail(manifest.id, caseRow.caseId);
143
+ if (caseDetail === void 0) continue;
144
+ for (const entry of getStoredCacheEntriesForCase(caseDetail)) entries.set(`${entry.namespace}\u0000${entry.key}`, {
145
+ namespace: entry.namespace,
146
+ key: entry.key
147
+ });
148
+ }
149
+ }
150
+ return [...entries.values()];
151
+ }
152
+ function getStoredCacheEntriesForCase(caseDetail) {
153
+ const entries = extractCacheEntries(caseDetail.trace, caseDetail.cacheRefs);
154
+ for (const scoreTrace of Object.values(caseDetail.scoringTraces ?? {})) entries.push(...extractCacheEntries(scoreTrace.trace, scoreTrace.cacheRefs));
155
+ return entries.filter((entry) => entry.stored);
156
+ }
157
+ function runIsSelectedOrPrevious(manifest, selectedManifest) {
158
+ if (manifest.id === selectedManifest.id) return true;
159
+ const runSequence = readRunSequence(manifest.shortId);
160
+ const selectedSequence = readRunSequence(selectedManifest.shortId);
161
+ if (runSequence !== void 0 && selectedSequence !== void 0) return runSequence <= selectedSequence;
162
+ const runStartedAt = Date.parse(manifest.startedAt);
163
+ const selectedStartedAt = Date.parse(selectedManifest.startedAt);
164
+ if (!Number.isFinite(runStartedAt) || !Number.isFinite(selectedStartedAt)) return false;
165
+ return runStartedAt <= selectedStartedAt;
166
+ }
167
+ function readRunSequence(shortId) {
168
+ if (!shortId.startsWith("r")) return void 0;
169
+ const value = Number(shortId.slice(1));
170
+ return Number.isInteger(value) && value >= 0 ? value : void 0;
171
+ }
120
172
  //#endregion
121
173
  //#region ../../apps/server/src/routes/evals.ts
122
174
  const evalsRoutes = new Hono().get("/", (c) => {