@parcha/agentrun-serve 0.1.0-beta.53 → 0.1.0-beta.55
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 +138 -3
- package/README.md +346 -99
- package/dist/adapters.d.ts +10 -0
- package/dist/adapters.js +46 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +7 -14
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +7 -6
- package/dist/api-only.d.ts +17 -6
- package/dist/api-only.js +22 -9
- package/dist/cli.js +11 -4
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +6 -4
- package/dist/composio-preset.js +50 -17
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-needs.d.ts +1 -1
- package/dist/computer-needs.js +1 -1
- package/dist/computer-setting.d.ts +8 -4
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/computers.d.ts +0 -2
- package/dist/computers.js +1 -1
- package/dist/console/assets/backend-D5EmB4N3.js +166 -0
- package/dist/console/assets/index-DUYLaqiR.js +746 -0
- package/dist/console/assets/index-DYhU4adm.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +7 -0
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/github-connection.d.ts +50 -1
- package/dist/github-connection.js +96 -3
- package/dist/github-faux.d.ts +11 -2
- package/dist/github-faux.js +138 -7
- package/dist/github-pull-request.d.ts +37 -0
- package/dist/github-pull-request.js +110 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +2 -0
- package/dist/host-check.js +6 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.js +10 -2
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-probe.js +2 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.js +235 -41
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +17 -1
- package/dist/place-offers.js +46 -5
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/runner/adapter-loop.d.ts +6 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +6 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -2
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +39 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +5 -4
- package/dist/runner/main.js +4 -2
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -8
- package/dist/runner/metrics.js +20 -27
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.js +24 -11
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +23 -0
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +55 -8
- package/dist/server.js +363 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/agent-body.d.ts +2 -2
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +90 -34
- package/dist/store/store.d.ts +54 -14
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +9 -8
- package/dist/suggestions.d.ts +282 -0
- package/dist/suggestions.js +919 -0
- package/dist/telemetry.d.ts +8 -1
- package/dist/telemetry.js +12 -4
- package/dist/template-eval.d.ts +49 -4
- package/dist/template-eval.js +168 -45
- package/dist/template-import.d.ts +17 -0
- package/dist/template-import.js +36 -2
- package/dist/templates.d.ts +83 -76
- package/dist/templates.js +29 -48
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +2 -2
- package/dist/timeline/timeline.js +1 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +19 -9
- package/dist/trigger-launch-hook.js +35 -25
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +2 -2
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/synced-folder.d.ts +1 -1
- package/dist/workspace/synced-folder.js +11 -14
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +5 -4
- package/templates/agent-scout/agent.md +46 -0
- package/templates/agent-scout/skills/scout/SKILL.md +88 -0
- package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
- package/dist/console/assets/index-BFgyZzF_.js +0 -734
- package/dist/console/assets/index-DbilxljH.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
package/dist/telemetry.d.ts
CHANGED
|
@@ -7,7 +7,11 @@ export declare const TELEMETRY_FILE = ".telemetry.json";
|
|
|
7
7
|
/** How often a running server says it still runs. */
|
|
8
8
|
export declare const HEARTBEAT_MS: number;
|
|
9
9
|
export declare const TELEMETRY_NOTICE = "AgentRun sends anonymous usage counts (a random id, the version, the platform, how many runs as a range): never prompts, files, keys or names. Nothing was sent at this start. Turn it off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1. Every field: https://github.com/Parcha-ai/agentrun/blob/main/docs/telemetry.md";
|
|
10
|
-
|
|
10
|
+
/** What someone did with suggested agents (suggestions.ts), said as the name alone: never which repository, suggestion
|
|
11
|
+
* or agent. */
|
|
12
|
+
export type UsageEventName = "suggestions_scanned" | "suggestion_discarded" | "suggested_agent_created";
|
|
13
|
+
export declare const USAGE_EVENTS: readonly UsageEventName[];
|
|
14
|
+
export type TelemetryEventName = "server_started" | "heartbeat" | "first_run_completed" | UsageEventName;
|
|
11
15
|
/** One event, as sent (and as debug prints it). `runs` is a range, never a count. */
|
|
12
16
|
export interface TelemetryEvent {
|
|
13
17
|
api_key: string;
|
|
@@ -39,6 +43,9 @@ export interface Telemetry {
|
|
|
39
43
|
notice?: string;
|
|
40
44
|
/** A run reached its end here. `status` is the runner's (`ended` is a completed run). */
|
|
41
45
|
runEnded(status: string): void;
|
|
46
|
+
/** Someone used a feature the counts name: said at once, except during the start that printed the notice, until its
|
|
47
|
+
* first heartbeat, when it is dropped (never held for later). A name not in USAGE_EVENTS is never sent. */
|
|
48
|
+
used(event: UsageEventName): void;
|
|
42
49
|
/** Stops the heartbeat and waits for the count's last write. Sends nothing. */
|
|
43
50
|
close(): Promise<void>;
|
|
44
51
|
}
|
package/dist/telemetry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Anonymous usage counts (docs/telemetry.md): that a server started, that it is still running a day later,
|
|
2
|
-
// first run completed
|
|
3
|
-
//
|
|
1
|
+
// Anonymous usage counts (docs/telemetry.md): that a server started, that it is still running a day later, that its
|
|
2
|
+
// first run completed, and that someone used suggested agents (a scan started, a suggestion discarded, a suggested
|
|
3
|
+
// agent's pull request opened). Each event holds a random id made for this data directory, the server's version, the
|
|
4
|
+
// platform, and how many runs ended here as a range. It never holds a prompt, a workflow, a key, a name, a path or an address.
|
|
4
5
|
//
|
|
5
6
|
// Off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1, in CI, under a test runner, and under --faux. The start that first could send prints one
|
|
6
7
|
// notice and sends nothing at its start, so a person reads how to turn it off before anything leaves the machine.
|
|
@@ -24,6 +25,7 @@ export const HEARTBEAT_MS = 24 * 60 * 60 * 1000;
|
|
|
24
25
|
const SEND_TIMEOUT_MS = 3_000;
|
|
25
26
|
const ownVersion = () => JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
26
27
|
export const TELEMETRY_NOTICE = "AgentRun sends anonymous usage counts (a random id, the version, the platform, how many runs as a range): never prompts, files, keys or names. Nothing was sent at this start. Turn it off with AGENTRUN_TELEMETRY=0 or DO_NOT_TRACK=1. Every field: https://github.com/Parcha-ai/agentrun/blob/main/docs/telemetry.md";
|
|
28
|
+
export const USAGE_EVENTS = ["suggestions_scanned", "suggestion_discarded", "suggested_agent_created"];
|
|
27
29
|
const OFF = new Set(["0", "false", "off", "no"]);
|
|
28
30
|
/** What this start does, from its environment (docs/telemetry.md). */
|
|
29
31
|
export function telemetryMode(env, o = {}) {
|
|
@@ -68,7 +70,7 @@ export function startTelemetry(o) {
|
|
|
68
70
|
const env = o.env ?? process.env;
|
|
69
71
|
const key = o.key ?? TELEMETRY_KEY;
|
|
70
72
|
const mode = telemetryMode(env, { ...(o.faux ? { faux: true } : {}), key });
|
|
71
|
-
const idle = { mode, runEnded: () => { }, close: () => Promise.resolve() };
|
|
73
|
+
const idle = { mode, runEnded: () => { }, used: () => { }, close: () => Promise.resolve() };
|
|
72
74
|
if (mode !== "on" && mode !== "debug")
|
|
73
75
|
return idle;
|
|
74
76
|
const file = join(o.data, TELEMETRY_FILE);
|
|
@@ -171,6 +173,12 @@ export function startTelemetry(o) {
|
|
|
171
173
|
if (completed && !holding)
|
|
172
174
|
emit("first_run_completed");
|
|
173
175
|
},
|
|
176
|
+
used(event) {
|
|
177
|
+
// The notice's start sends nothing before its first heartbeat; a feature used then is not counted at all.
|
|
178
|
+
if (holding || !USAGE_EVENTS.includes(event))
|
|
179
|
+
return;
|
|
180
|
+
emit(event);
|
|
181
|
+
},
|
|
174
182
|
close: () => (clearInterval(beat), writing ?? Promise.resolve()),
|
|
175
183
|
};
|
|
176
184
|
}
|
package/dist/template-eval.d.ts
CHANGED
|
@@ -164,6 +164,12 @@ export type ToolCall = {
|
|
|
164
164
|
result?: string | null;
|
|
165
165
|
arguments?: Json;
|
|
166
166
|
};
|
|
167
|
+
/** A file a run left in its work folder: its path, its size in bytes and, for a text file read whole, its text. */
|
|
168
|
+
export type FinalFile = {
|
|
169
|
+
path: string;
|
|
170
|
+
bytes: number;
|
|
171
|
+
text?: string;
|
|
172
|
+
};
|
|
167
173
|
/** What a run left, for its graders. */
|
|
168
174
|
export type RunRecord = {
|
|
169
175
|
/** The run's final answer, or "" when it has none. */
|
|
@@ -174,6 +180,9 @@ export type RunRecord = {
|
|
|
174
180
|
mcpCalls: ToolCall[];
|
|
175
181
|
/** The paths of its files, from its work folder. */
|
|
176
182
|
files: string[];
|
|
183
|
+
/** Its work folder's files as it left them, for its llm graders (finalFilesOf): each text file with its whole `text`,
|
|
184
|
+
* any other (media, a binary, one past what was read) with its size alone. */
|
|
185
|
+
finalFiles?: FinalFile[];
|
|
177
186
|
/** The clock it ran on, its case's `now`; absent, the real one. */
|
|
178
187
|
now?: string;
|
|
179
188
|
/** Its fake mailbox after it, for a case with `email` (eval-mailbox.ts). */
|
|
@@ -200,8 +209,8 @@ export declare function gradeDeterministic(grader: Exclude<Grader, {
|
|
|
200
209
|
* carries a grader for it. Undefined for a package with no output schema. */
|
|
201
210
|
export declare function outputVerdict(pkg: Package, result: unknown): GraderResult | undefined;
|
|
202
211
|
/** The input a grader run gets for an llm grader: the rubric, the clock the run ran on when its case set one (the grader's
|
|
203
|
-
* own run is on the real clock), the run's input, its answer (its target field marked when the grader names one),
|
|
204
|
-
* calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
|
|
212
|
+
* own run is on the real clock), the run's input, its answer (its target field marked when the grader names one), the
|
|
213
|
+
* files it left (fitFiles: whole ahead of its calls, which are cut first), its calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
|
|
205
214
|
export declare function graderInput(grader: Extract<Grader, {
|
|
206
215
|
type: "llm";
|
|
207
216
|
}>, input: string, run: RunRecord, max?: number): string;
|
|
@@ -217,6 +226,11 @@ export declare function fitCalls(lines: readonly {
|
|
|
217
226
|
result: string;
|
|
218
227
|
tool?: string;
|
|
219
228
|
}[], room: number, what?: string): string;
|
|
229
|
+
/** A run's final files in at most `room` characters: each text file in a <file> block, whole when they all fit; else each
|
|
230
|
+
* text past a length L keeps its head and tail with its middle cut and marked, L the longest that fits (so the largest
|
|
231
|
+
* is cut first); else every text left out. A file with no text (media, a binary, one past what was read) is named with
|
|
232
|
+
* its size on a last line, cut to the room when even that passes it. */
|
|
233
|
+
export declare function fitFiles(files: readonly FinalFile[], room: number): string;
|
|
220
234
|
/** A grader run's answer read as its verdict: the last json block's (else the last JSON object's) {pass, reason}. */
|
|
221
235
|
export declare function verdictOf(answer: string): {
|
|
222
236
|
pass: boolean;
|
|
@@ -234,19 +248,48 @@ export declare function startFake(name: string, fixture: McpFixture): Promise<Fa
|
|
|
234
248
|
type Answered = {
|
|
235
249
|
status: number;
|
|
236
250
|
body: unknown;
|
|
251
|
+
headers?: Headers;
|
|
237
252
|
};
|
|
238
|
-
/** `statusOnly`: the answer's status alone, its body cancelled unread (a file's existence, never its bytes). `
|
|
239
|
-
*
|
|
253
|
+
/** `statusOnly`: the answer's status alone, its body cancelled unread (a file's existence, never its bytes). `text`: its
|
|
254
|
+
* body as the text it is, never parsed (a file's bytes: a JSON file's text, as it was written), with the answer's headers.
|
|
255
|
+
* `signal`: the request and the read of its body stop when it aborts, and the call rejects. */
|
|
240
256
|
export type Api = (method: string, path: string, body?: unknown, headers?: Record<string, string>, options?: {
|
|
241
257
|
statusOnly?: true;
|
|
258
|
+
text?: true;
|
|
242
259
|
signal?: AbortSignal;
|
|
243
260
|
}) => Promise<Answered>;
|
|
261
|
+
/** A client of the v2 API at `baseUrl` (ending in /v2) with `token`. */
|
|
262
|
+
export declare function apiOf(baseUrl: string, token: string): Api;
|
|
263
|
+
/** How long the run read that asks whether a runner holds a queued run may take. */
|
|
264
|
+
export declare const CLAIM_READ_TIMEOUT_MS = 10000;
|
|
244
265
|
/** A run's tool calls, each named as a grader names it: the gate's own rule (RunGate.enter), its settings key, but a
|
|
245
266
|
* shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
|
|
246
267
|
* call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
|
|
247
268
|
* under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
|
|
248
269
|
* its output's head as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
|
|
249
270
|
export declare function callsOf(rows: readonly Json[], harness: string, toolkits?: Readonly<Record<string, string>>): ToolCall[];
|
|
271
|
+
/** A file of a run's work folder as its listing names it: its size, its type (null for an extension the server does not
|
|
272
|
+
* type) and whether the server could read it. */
|
|
273
|
+
export type Listed = {
|
|
274
|
+
path: string;
|
|
275
|
+
bytes: number;
|
|
276
|
+
type: string | null;
|
|
277
|
+
unreadable: boolean;
|
|
278
|
+
};
|
|
279
|
+
/** How long one read of a run's final file may take, its body included: a server that stalls mid-file leaves that file's
|
|
280
|
+
* text out, and the eval goes on. */
|
|
281
|
+
export declare const FILE_READ_TIMEOUT_MS = 10000;
|
|
282
|
+
/** How long all of a run's final file reads may take together: past it, the files not yet read are listed by size alone. */
|
|
283
|
+
export declare const FILE_READS_TIMEOUT_MS = 30000;
|
|
284
|
+
/** A run's final files for its llm graders: each text file's whole text, read smallest first while the texts read stay
|
|
285
|
+
* within GRADER_PROMPT_MAX UTF-8 bytes in all (one grader input holds that many characters, and a character is at least
|
|
286
|
+
* a byte), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
|
|
287
|
+
* secrets (`?cut=run`, run-reads-over-store.ts cutRunFile): every value its timeline's calls are cut of, and every secret
|
|
288
|
+
* shape, is "[redacted]" in the text a grader sees. An answer without the cut's mark (`x-agentrun-cut: run`: a server
|
|
289
|
+
* that doesn't know the cut and would serve the raw bytes) leaves the text out. A read that fails, is refused (403, 413,
|
|
290
|
+
* 415), takes longer than `readTimeoutMs`, or would pass the budget leaves that file's text out, never the grade, and
|
|
291
|
+
* the files after it are still read; past FILE_READS_TIMEOUT_MS in all, the rest are left out. In the listing's order. */
|
|
292
|
+
export declare function finalFilesOf(api: Api, runId: string, listed: readonly Listed[], signal?: AbortSignal, readTimeoutMs?: number): Promise<FinalFile[]>;
|
|
250
293
|
/** How long a run's metrics read may take before the run is reported without them. */
|
|
251
294
|
export declare const METRICS_TIMEOUT_MS = 10000;
|
|
252
295
|
/** The metrics of the one run `agentId` made (RunMetrics), from GET /stats?agent=; null when the server kept none (the run
|
|
@@ -279,6 +322,8 @@ export type EvalOptions = {
|
|
|
279
322
|
runTimeoutMs?: number;
|
|
280
323
|
/** How long one run may stay queued with no runner taking it (default QUEUE_TIMEOUT_MS). */
|
|
281
324
|
queueTimeoutMs?: number;
|
|
325
|
+
/** How long one read of a run's final file may take, its body included (default FILE_READ_TIMEOUT_MS). */
|
|
326
|
+
fileReadTimeoutMs?: number;
|
|
282
327
|
/** Told each step as one line (the CLI's stderr). */
|
|
283
328
|
log?: (line: string) => void;
|
|
284
329
|
/** Stops the eval: the run in progress is cancelled, what the eval made is cleaned up as at its end, and the eval
|
package/dist/template-eval.js
CHANGED
|
@@ -18,6 +18,7 @@ import { parseDocument } from "yaml";
|
|
|
18
18
|
import { answerJson, lastJsonBlock } from "./answer-json.js";
|
|
19
19
|
import { correctionsProblems } from "./learn/index.js";
|
|
20
20
|
import { linkCheck } from "./link-check.js";
|
|
21
|
+
import { frontMatter } from "./manifest.js";
|
|
21
22
|
import { inputMessage } from "./run-manifest.js";
|
|
22
23
|
import { shownUrl } from "./mcp-probe.js";
|
|
23
24
|
import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, monidNameOf, parseToolName } from "./tool-names.js";
|
|
@@ -65,7 +66,6 @@ export const GRADER_NAME = "Template eval grader";
|
|
|
65
66
|
export const EVAL_HARNESSES = "agentrun-eval-harnesses";
|
|
66
67
|
/** An owner's data folder is the eval's own server's to open (EvalOptions.data): a named server keeps its own. */
|
|
67
68
|
export const ON_DATA_WITH_SERVER = "--on-data is the data folder of the eval's own server, and --server names another server: give one of them";
|
|
68
|
-
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
69
69
|
const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
|
|
70
70
|
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed", "previous"];
|
|
71
71
|
const GRADER_FIELDS = {
|
|
@@ -97,13 +97,15 @@ export class CaseError extends Error {
|
|
|
97
97
|
this.problems = problems;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
/** A file's YAML front matter and body, read as
|
|
100
|
+
/** A file's YAML front matter and body, read as a package's are (manifest.ts); an empty one is a mapping with no keys. */
|
|
101
101
|
function frontOf(text) {
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
102
|
+
const read = frontMatter(text);
|
|
103
|
+
if (!read)
|
|
104
104
|
return { data: {}, body: text };
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if ("problem" in read)
|
|
106
|
+
return `its front matter ${read.problem}`;
|
|
107
|
+
const data = read.data ?? {};
|
|
108
|
+
return isObject(data) ? { data, body: read.body } : "its front matter is not a mapping";
|
|
107
109
|
}
|
|
108
110
|
function yamlOf(text) {
|
|
109
111
|
const doc = parseDocument(text, { schema: "core", merge: false, uniqueKeys: true, strict: true });
|
|
@@ -295,7 +297,7 @@ export function readCases(dir, names) {
|
|
|
295
297
|
const problems = [];
|
|
296
298
|
const missing = (names ?? []).filter((name) => !pkg.evals.includes(name));
|
|
297
299
|
if (missing.length)
|
|
298
|
-
throw new CaseError(dir, missing.map((name) => `evals/${name}: no such case (the package's are ${pkg.evals.join(", ") || "none"})`));
|
|
300
|
+
throw new CaseError(dir, missing.map((name) => `evals/${name}: no such case (the package's are ${[...pkg.evals].sort().join(", ") || "none"})`));
|
|
299
301
|
const cases = [];
|
|
300
302
|
for (const name of pkg.evals.filter((name) => !names?.length || names.includes(name))) {
|
|
301
303
|
const at = `evals/${name}`;
|
|
@@ -706,8 +708,8 @@ export function outputVerdict(pkg, result) {
|
|
|
706
708
|
return { grader: "output", type: "output", cost_usd: null, pass: why === undefined, reason: why === undefined ? `the answer's json meets ${pkg.output.schema}` : `the answer misses ${pkg.output.schema}: ${why}` };
|
|
707
709
|
}
|
|
708
710
|
/** The input a grader run gets for an llm grader: the rubric, the clock the run ran on when its case set one (the grader's
|
|
709
|
-
* own run is on the real clock), the run's input, its answer (its target field marked when the grader names one),
|
|
710
|
-
* calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
|
|
711
|
+
* own run is on the real clock), the run's input, its answer (its target field marked when the grader names one), the
|
|
712
|
+
* files it left (fitFiles: whole ahead of its calls, which are cut first), its calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
|
|
711
713
|
export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
712
714
|
const target = grader.target ? targetOf(run.answer, grader.target) : undefined;
|
|
713
715
|
const at = run.now === undefined ? undefined : instantOf(run.now);
|
|
@@ -721,12 +723,19 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
|
721
723
|
// What the run did to its fake mailbox: the messages it added (a draft, a copy in Sent), moved or labelled, and sent.
|
|
722
724
|
...(run.mailbox ? [`<mailbox-after untrusted>\nThe run's email account was a fake mailbox (layout ${run.mailbox.after.layout}). What the run left in it:\n${mailboxText(run.mailbox.after)}\n</mailbox-after>`] : []),
|
|
723
725
|
];
|
|
724
|
-
//
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
726
|
+
// The files the run left, ahead of its calls. A call shows a file's bytes only in its arguments or its output, each cut
|
|
727
|
+
// where the timeline cuts it (a string of its arguments at 2,000 characters, its output at CALL_RESULT_CHARS, each
|
|
728
|
+
// ending "..."), and a cut call reads to a grader as a run that did less than its file holds.
|
|
729
|
+
const files = run.finalFiles ?? [];
|
|
730
|
+
const texts = files.filter((file) => file.text !== undefined);
|
|
731
|
+
// Each call with its arguments (else its input's preview), its status and its output's head; a call that names a file
|
|
732
|
+
// shown whole says where it is.
|
|
733
|
+
const lines = run.calls.map((call, i) => {
|
|
734
|
+
const head = `${i + 1}. ${call.tool}${call.arguments ? ` ${JSON.stringify(call.arguments)}` : call.preview ? ` (${call.preview})` : ""}${call.status ? ` -> ${call.status}` : ""}`;
|
|
735
|
+
const result = call.result ?? "";
|
|
736
|
+
const named = texts.filter((file) => head.includes(file.path) || result.includes(file.path)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
737
|
+
return { head: named ? `${head} [the file ${named.path} is in <files>, whole unless marked cut]` : head, result, tool: call.name ?? call.tool };
|
|
738
|
+
});
|
|
730
739
|
// Each call a fake MCP server received, its arguments whole in its log: they are the part a cut may take.
|
|
731
740
|
const mcpLines = run.mcpCalls.map((call, i) => ({ head: `${i + 1}. ${call.tool}`, result: JSON.stringify(call.arguments ?? {}) }));
|
|
732
741
|
const wrap = (text) => `<tool-calls untrusted>\n${text}\n</tool-calls>`;
|
|
@@ -734,13 +743,18 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
|
|
|
734
743
|
// A run that searched or fetched: each link its answer cites, matched against its web calls' urls in code (link-check.ts).
|
|
735
744
|
const links = linkCheck(run.answer, run.calls);
|
|
736
745
|
const linked = links === undefined ? [] : [`<link-check untrusted>\n${links}\n</link-check>`];
|
|
737
|
-
|
|
738
|
-
const room = max - [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
|
|
746
|
+
const wrapFiles = (text) => `<files untrusted>\nThe files in the run's work folder when it ended, each text file whole unless marked cut (a call below that shows one only in part shows a cut of it):\n${text}\n</files>`;
|
|
747
|
+
const room = max - [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : []), ...(files.length ? [wrapFiles("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
|
|
739
748
|
const wholeOf = (list) => list.reduce((sum, one) => sum + one.head.length + one.result.length + 3, 0);
|
|
740
749
|
const [callsWhole, mcpWhole] = [wholeOf(lines), wholeOf(mcpLines)];
|
|
741
|
-
|
|
750
|
+
// The files come first: they take what they need of the room, but no more than leaves the calls a quarter of it (or
|
|
751
|
+
// all they need, when that is less), so a call's result is cut before a file is.
|
|
752
|
+
const shownFiles = files.length ? fitFiles(files, Math.max(0, room - Math.min(callsWhole + mcpWhole, Math.floor(room / 4)))) : undefined;
|
|
753
|
+
// Both call lists share the room the rest leave, each in proportion to its whole size.
|
|
754
|
+
const left = room - (shownFiles === undefined ? 0 : shownFiles.length);
|
|
755
|
+
const mcpRoom = callsWhole + mcpWhole <= left ? mcpWhole : Math.floor((left * mcpWhole) / Math.max(1, callsWhole + mcpWhole));
|
|
742
756
|
const after = mcpLines.length ? [wrapMcp(fitCalls(mcpLines, mcpRoom, "argument list"))] : [];
|
|
743
|
-
return [...before, wrap(lines.length ? fitCalls(lines,
|
|
757
|
+
return [...before, ...(shownFiles === undefined ? [] : [wrapFiles(shownFiles)]), wrap(lines.length ? fitCalls(lines, left - mcpRoom) : "(none)"), ...linked, ...after].join("\n\n");
|
|
744
758
|
}
|
|
745
759
|
/** A grader's calls, one line each (`head`, then `: <result>`), in at most `room` characters: whole when they fit; else
|
|
746
760
|
* each result past a length L keeps its first two thirds and last third of L with its middle cut and marked, L the
|
|
@@ -754,14 +768,7 @@ export function fitCalls(lines, room, what = "result") {
|
|
|
754
768
|
const whole = lines.map((one) => line(one.head, one.result)).join("\n");
|
|
755
769
|
if (whole.length <= room)
|
|
756
770
|
return whole;
|
|
757
|
-
const said =
|
|
758
|
-
const middle = (text, keep) => {
|
|
759
|
-
if (text.length <= keep)
|
|
760
|
-
return text;
|
|
761
|
-
const marker = ` [... ${text.length - keep} characters cut ...] `;
|
|
762
|
-
const tail = Math.floor(keep / 3);
|
|
763
|
-
return `${text.slice(0, keep - tail)}${marker}${text.slice(text.length - tail)}`;
|
|
764
|
-
};
|
|
771
|
+
const said = saidCut;
|
|
765
772
|
const webs = lines.map((one) => (one.tool ? webShownOf(one.tool, one.result) : undefined));
|
|
766
773
|
const LONG = said(`each long ${what} keeps its head and tail, its middle cut where marked${webs.some(Boolean) ? "; a web_search keeps every result's url, title and date, and a web_fetch its url and title, their snippets and page text cut" : ""}`);
|
|
767
774
|
// What a result cut to `keep` adds to its line, ": " included: the marker a cut adds is at most 40 characters, counted
|
|
@@ -812,6 +819,45 @@ export function fitCalls(lines, room, what = "result") {
|
|
|
812
819
|
const dropped = heads.length - kept[0].length - kept[1].length;
|
|
813
820
|
return [said(`every ${what} is left out, and ${dropped} call${dropped === 1 ? "" : "s"} in the middle`), ...kept[0], `[... ${dropped} call${dropped === 1 ? "" : "s"} cut ...]`, ...kept[1]].join("\n");
|
|
814
821
|
}
|
|
822
|
+
/** A cut's note, on the first line of what it cut. */
|
|
823
|
+
const saidCut = (cut) => `(Cut to keep this prompt under its cap: ${cut}.)`;
|
|
824
|
+
/** `text` in at most `keep` characters and its marker: whole when it fits, else its first two thirds and last third of
|
|
825
|
+
* `keep`, its middle cut and marked in place with how much was cut (a marker of at most 40 characters). */
|
|
826
|
+
function middle(text, keep) {
|
|
827
|
+
if (text.length <= keep)
|
|
828
|
+
return text;
|
|
829
|
+
const marker = ` [... ${text.length - keep} characters cut ...] `;
|
|
830
|
+
const tail = Math.floor(keep / 3);
|
|
831
|
+
return `${text.slice(0, keep - tail)}${marker}${text.slice(text.length - tail)}`;
|
|
832
|
+
}
|
|
833
|
+
/** A run's final files in at most `room` characters: each text file in a <file> block, whole when they all fit; else each
|
|
834
|
+
* text past a length L keeps its head and tail with its middle cut and marked, L the longest that fits (so the largest
|
|
835
|
+
* is cut first); else every text left out. A file with no text (media, a binary, one past what was read) is named with
|
|
836
|
+
* its size on a last line, cut to the room when even that passes it. */
|
|
837
|
+
export function fitFiles(files, room) {
|
|
838
|
+
const block = (file, text) => `<file path="${file.path}" bytes="${file.bytes}">\n${text}\n</file>`;
|
|
839
|
+
const texts = files.filter((file) => file.text !== undefined);
|
|
840
|
+
const others = files.filter((file) => file.text === undefined);
|
|
841
|
+
const named = others.length ? [`Not shown (not text, or past what a grader is given), by path and size in bytes: ${others.map((file) => `${file.path} (${file.bytes})`).join(", ")}`] : [];
|
|
842
|
+
const whole = [...texts.map((file) => block(file, file.text)), ...named].join("\n");
|
|
843
|
+
if (whole.length <= room)
|
|
844
|
+
return whole;
|
|
845
|
+
const LONG = saidCut("each long file keeps its head and tail, its middle cut where marked");
|
|
846
|
+
const size = (keep) => LONG.length + 1 + texts.reduce((sum, file) => sum + block(file, "").length + (file.text.length <= keep ? file.text.length : keep + 40) + 1, 0) + named.reduce((sum, line) => sum + line.length, 0);
|
|
847
|
+
if (texts.length && size(0) <= room) {
|
|
848
|
+
let [low, top] = [0, Math.max(...texts.map((file) => file.text.length))];
|
|
849
|
+
while (low < top) {
|
|
850
|
+
const mid = Math.ceil((low + top) / 2);
|
|
851
|
+
if (size(mid) <= room)
|
|
852
|
+
low = mid;
|
|
853
|
+
else
|
|
854
|
+
top = mid - 1;
|
|
855
|
+
}
|
|
856
|
+
return [LONG, ...texts.map((file) => block(file, middle(file.text, low))), ...named].join("\n");
|
|
857
|
+
}
|
|
858
|
+
const list = [saidCut("every file's text is left out"), `By path and size in bytes: ${files.map((file) => `${file.path} (${file.bytes})`).join(", ")}`].join("\n");
|
|
859
|
+
return list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)} ...`;
|
|
860
|
+
}
|
|
815
861
|
/** A grader run's answer read as its verdict: the last json block's (else the last JSON object's) {pass, reason}. */
|
|
816
862
|
export function verdictOf(answer) {
|
|
817
863
|
const candidates = [lastJsonBlock(answer), ...[...answer.matchAll(/\{[^{}]*"pass"[^{}]*\}/g)].map((m) => m[0]).reverse()];
|
|
@@ -881,7 +927,7 @@ async function bytesOf(req) {
|
|
|
881
927
|
return Buffer.concat(chunks);
|
|
882
928
|
}
|
|
883
929
|
/** A client of the v2 API at `baseUrl` (ending in /v2) with `token`. */
|
|
884
|
-
function apiOf(baseUrl, token) {
|
|
930
|
+
export function apiOf(baseUrl, token) {
|
|
885
931
|
return async (method, path, body, headers = {}, options = {}) => {
|
|
886
932
|
const raw = typeof body === "string";
|
|
887
933
|
// The console's page takes a write from its session only with a JSON body type, a body or not (page.ts answerPage):
|
|
@@ -902,6 +948,8 @@ function apiOf(baseUrl, token) {
|
|
|
902
948
|
return { status: res.status, body: null };
|
|
903
949
|
}
|
|
904
950
|
const text = await res.text();
|
|
951
|
+
if (options.text)
|
|
952
|
+
return { status: res.status, body: text, headers: res.headers };
|
|
905
953
|
let json = text;
|
|
906
954
|
try {
|
|
907
955
|
json = JSON.parse(text);
|
|
@@ -923,13 +971,28 @@ function expectOk(what, answered, ok = [200, 201, 202]) {
|
|
|
923
971
|
throw new ApiFailure(`${what}: ${answered.status} ${typeof error?.message === "string" ? error.message : JSON.stringify(answered.body).slice(0, 300)}${fields}`);
|
|
924
972
|
}
|
|
925
973
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
974
|
+
/** How long the run read that asks whether a runner holds a queued run may take. */
|
|
975
|
+
export const CLAIM_READ_TIMEOUT_MS = 10_000;
|
|
976
|
+
/** Whether a runner holds the run now (the run read's `claim`); undefined when the read fails, takes over
|
|
977
|
+
* CLAIM_READ_TIMEOUT_MS or is stopped by `signal` (the eval's stop): not known, so never a reason to cancel the run. */
|
|
978
|
+
async function heldNow(api, runId, signal) {
|
|
979
|
+
const timeout = AbortSignal.timeout(CLAIM_READ_TIMEOUT_MS);
|
|
980
|
+
const read = await api("GET", `/runs/${runId}`, undefined, {}, { signal: signal ? AbortSignal.any([signal, timeout]) : timeout }).catch(() => undefined);
|
|
981
|
+
return read?.status === 200 && isObject(read.body) ? isObject(read.body.claim) : undefined;
|
|
982
|
+
}
|
|
926
983
|
/** A run waited for: its rows until it ends (completed, failed, cancelled) or waits on a person (input_required), or
|
|
927
984
|
* `deadline` passes (then it is cancelled). A stop of the eval (`signal`) cancels it too, and throws. */
|
|
928
985
|
async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIMEOUT_MS) {
|
|
929
986
|
const view = new Map();
|
|
930
987
|
let after = 0;
|
|
931
|
-
|
|
932
|
-
|
|
988
|
+
const started = Date.now();
|
|
989
|
+
// A run nobody takes stays queued: given up on once it has gone queueTimeoutMs with no runner holding it, by name, never
|
|
990
|
+
// left to the whole deadline. A run's view reads queued until its first rows show, held or not (a slow start on a busy
|
|
991
|
+
// machine), so a queued page past the bound asks the run read whether a runner holds it now: one does, and the bound
|
|
992
|
+
// starts again from now, so a run a runner keeps holding is waited for to its own deadline. A read that doesn't answer
|
|
993
|
+
// (failed, stalled past its bound, or stopped) says neither: it is asked again at the next page, and the stop and the
|
|
994
|
+
// deadline still end the wait.
|
|
995
|
+
let queuedUntil = started + queueTimeoutMs;
|
|
933
996
|
for (;;) {
|
|
934
997
|
if (signal?.aborted) {
|
|
935
998
|
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
@@ -953,12 +1016,17 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
953
1016
|
return { status, rows, waiting: typeof waiting?.summary === "string" ? waiting.summary : "it waits on a person" };
|
|
954
1017
|
}
|
|
955
1018
|
if (status === "queued" && Date.now() > queuedUntil) {
|
|
956
|
-
await api
|
|
957
|
-
|
|
1019
|
+
const held = await heldNow(api, runId, signal);
|
|
1020
|
+
if (held === true)
|
|
1021
|
+
queuedUntil = Date.now() + queueTimeoutMs;
|
|
1022
|
+
else if (held === false) {
|
|
1023
|
+
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
1024
|
+
return { status: "timed_out", rows, why: `the run stayed queued for ${Math.round(queueTimeoutMs / 1000)} s with no runner holding it, and it was cancelled` };
|
|
1025
|
+
}
|
|
958
1026
|
}
|
|
959
1027
|
if (Date.now() > deadline) {
|
|
960
1028
|
await api("POST", `/runs/${runId}/cancel`, {});
|
|
961
|
-
return { status: "timed_out", rows, why: `the run took longer than ${Math.round((deadline -
|
|
1029
|
+
return { status: "timed_out", rows, why: `the run took longer than ${Math.round((deadline - started) / 1000)} s (state ${String(page.state)} when the wait gave up) and was cancelled` };
|
|
962
1030
|
}
|
|
963
1031
|
if (page.has_more !== true && page.unchanged === true)
|
|
964
1032
|
await sleep(250);
|
|
@@ -981,28 +1049,73 @@ export function callsOf(rows, harness, toolkits = {}) {
|
|
|
981
1049
|
return { tool: shellToolOf(name) ?? (key === undefined ? undefined : onServerName(key, toolkits)) ?? name, name, preview: row.tool_input_preview ?? null, ...(isObject(row.tool_input) ? { arguments: row.tool_input } : {}), status: result?.tool_status ?? null, result: output };
|
|
982
1050
|
});
|
|
983
1051
|
}
|
|
984
|
-
/** Every file
|
|
1052
|
+
/** Every file of a run's work folder (the files route, page by page). */
|
|
985
1053
|
async function filesOf(api, runId) {
|
|
986
|
-
const
|
|
1054
|
+
const files = [];
|
|
987
1055
|
for (let cursor = null;;) {
|
|
988
1056
|
const page = await api("GET", `/runs/${runId}/files${cursor ? `?cursor=${encodeURIComponent(cursor)}` : ""}`);
|
|
989
1057
|
if (page.status !== 200 || !isObject(page.body))
|
|
990
|
-
return
|
|
991
|
-
for (const file of page.body.files ?? [])
|
|
1058
|
+
return files;
|
|
1059
|
+
for (const file of page.body.files ?? []) {
|
|
992
1060
|
if (typeof file.path === "string")
|
|
993
|
-
|
|
1061
|
+
files.push({ path: file.path, bytes: typeof file.size_bytes === "number" ? file.size_bytes : 0, type: typeof file.content_type === "string" ? file.content_type : null, unreadable: file.unreadable === true });
|
|
1062
|
+
}
|
|
994
1063
|
cursor = typeof page.body.next_cursor === "string" ? page.body.next_cursor : null;
|
|
995
1064
|
if (!cursor)
|
|
996
|
-
return
|
|
1065
|
+
return files;
|
|
997
1066
|
}
|
|
998
1067
|
}
|
|
1068
|
+
const filePath = (runId, path) => `/runs/${runId}/files/${path.split("/").map(encodeURIComponent).join("/")}`;
|
|
1069
|
+
/** A type a file's bytes are text in: text/*, JSON and NDJSON. A file the server gives no type (an extension it does not
|
|
1070
|
+
* know: .srt, .vtt, .yaml) is read too: the server answers its text when its bytes are UTF-8 with no NUL, else 415. */
|
|
1071
|
+
const TEXT_TYPE = /^(text\/|application\/(json|x-ndjson)\b)/;
|
|
1072
|
+
/** How long one read of a run's final file may take, its body included: a server that stalls mid-file leaves that file's
|
|
1073
|
+
* text out, and the eval goes on. */
|
|
1074
|
+
export const FILE_READ_TIMEOUT_MS = 10_000;
|
|
1075
|
+
/** How long all of a run's final file reads may take together: past it, the files not yet read are listed by size alone. */
|
|
1076
|
+
export const FILE_READS_TIMEOUT_MS = 30_000;
|
|
1077
|
+
/** A run's final files for its llm graders: each text file's whole text, read smallest first while the texts read stay
|
|
1078
|
+
* within GRADER_PROMPT_MAX UTF-8 bytes in all (one grader input holds that many characters, and a character is at least
|
|
1079
|
+
* a byte), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
|
|
1080
|
+
* secrets (`?cut=run`, run-reads-over-store.ts cutRunFile): every value its timeline's calls are cut of, and every secret
|
|
1081
|
+
* shape, is "[redacted]" in the text a grader sees. An answer without the cut's mark (`x-agentrun-cut: run`: a server
|
|
1082
|
+
* that doesn't know the cut and would serve the raw bytes) leaves the text out. A read that fails, is refused (403, 413,
|
|
1083
|
+
* 415), takes longer than `readTimeoutMs`, or would pass the budget leaves that file's text out, never the grade, and
|
|
1084
|
+
* the files after it are still read; past FILE_READS_TIMEOUT_MS in all, the rest are left out. In the listing's order. */
|
|
1085
|
+
export async function finalFilesOf(api, runId, listed, signal, readTimeoutMs = FILE_READ_TIMEOUT_MS) {
|
|
1086
|
+
const texts = new Map();
|
|
1087
|
+
let left = GRADER_PROMPT_MAX;
|
|
1088
|
+
const until = Date.now() + Math.max(FILE_READS_TIMEOUT_MS, readTimeoutMs);
|
|
1089
|
+
for (const file of [...listed].filter((one) => !one.unreadable && (one.type === null || TEXT_TYPE.test(one.type))).sort((a, b) => a.bytes - b.bytes)) {
|
|
1090
|
+
if (file.bytes > left)
|
|
1091
|
+
continue;
|
|
1092
|
+
signal?.throwIfAborted();
|
|
1093
|
+
const remaining = until - Date.now();
|
|
1094
|
+
if (remaining <= 0)
|
|
1095
|
+
break;
|
|
1096
|
+
const bound = AbortSignal.timeout(Math.min(readTimeoutMs, remaining));
|
|
1097
|
+
const read = await api("GET", `${filePath(runId, file.path)}?cut=run`, undefined, {}, { text: true, signal: signal ? AbortSignal.any([signal, bound]) : bound }).catch((error) => {
|
|
1098
|
+
if (signal?.aborted)
|
|
1099
|
+
throw error;
|
|
1100
|
+
return undefined;
|
|
1101
|
+
});
|
|
1102
|
+
if (read?.status !== 200 || read.headers?.get("x-agentrun-cut") !== "run" || typeof read.body !== "string")
|
|
1103
|
+
continue;
|
|
1104
|
+
const bytes = Buffer.byteLength(read.body);
|
|
1105
|
+
if (bytes > left)
|
|
1106
|
+
continue;
|
|
1107
|
+
texts.set(file.path, read.body);
|
|
1108
|
+
left -= bytes;
|
|
1109
|
+
}
|
|
1110
|
+
return listed.map((file) => ({ path: file.path, bytes: file.bytes, ...(texts.has(file.path) ? { text: texts.get(file.path) } : {}) }));
|
|
1111
|
+
}
|
|
999
1112
|
/** Each path a file_exists grader names that the run's work folder holds, read one by one (GET /runs/{id}/files/{path}):
|
|
1000
1113
|
* the listing is capped (its `truncated`), so a file past its cap or depth is never taken for absent. Only the status
|
|
1001
1114
|
* is read: the file's body is cancelled unread, whatever its size. */
|
|
1002
1115
|
async function presentOf(api, runId, paths) {
|
|
1003
1116
|
const present = [];
|
|
1004
1117
|
for (const path of new Set(paths)) {
|
|
1005
|
-
const read = await api("GET",
|
|
1118
|
+
const read = await api("GET", filePath(runId, path), undefined, {}, { statusOnly: true });
|
|
1006
1119
|
if (read.status === 200)
|
|
1007
1120
|
present.push(path);
|
|
1008
1121
|
}
|
|
@@ -1107,7 +1220,7 @@ export async function evalTemplate(options) {
|
|
|
1107
1220
|
const { withoutFaux } = await import("./model.js");
|
|
1108
1221
|
const serveOptions = options.serve ?? {};
|
|
1109
1222
|
// Its run lines go to stderr: stdout is the eval's report.
|
|
1110
|
-
const beside = await runnerBeside(data, { mcpLoopback: serve.localInstall, mcpOwn: serve.own, evalFakes: (agentId) => fakes.get(agentId), harnessInstall, onLine: (line) => console.error(line), ...(serveOptions.faux ? { env: { ...withoutFaux(process.env), ...fauxEnvOf({ data: data, ...serveOptions }) } } : {}) }).catch(async (error) => {
|
|
1223
|
+
const beside = await runnerBeside(data, { mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, evalFakes: (agentId) => fakes.get(agentId), harnessInstall, onLine: (line) => console.error(line), ...(serveOptions.faux ? { env: { ...withoutFaux(process.env), ...fauxEnvOf({ data: data, ...serveOptions }) } } : {}) }).catch(async (error) => {
|
|
1111
1224
|
await closeServe();
|
|
1112
1225
|
removeTree(scratch);
|
|
1113
1226
|
throw error;
|
|
@@ -1436,10 +1549,16 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
|
|
|
1436
1549
|
made.triggers.add(one.trigger_id);
|
|
1437
1550
|
}
|
|
1438
1551
|
await deleteTriggers(api, made, true);
|
|
1439
|
-
if (via !== undefined && !kept)
|
|
1440
|
-
throw new ApiFailure(`the apply made no trigger named ${via}`);
|
|
1441
1552
|
if (kept)
|
|
1442
1553
|
made.triggers.add(kept);
|
|
1554
|
+
// A server under AGENTRUN_RUN_KEYS=1 takes a key it lacks from each run, and says so in the apply's warning at
|
|
1555
|
+
// secrets.<NAME>; an eval's runs carry no keys, so each would be refused. The eval stops before any, as for a case that
|
|
1556
|
+
// does not check (its agent removed with the case).
|
|
1557
|
+
const owed = (Array.isArray(applied.warnings) ? applied.warnings : []).flatMap((warning) => (isObject(warning) && warning.reason === "not_set_up_here" && typeof warning.field === "string" && warning.field.startsWith("secrets.") ? [warning.field.slice("secrets.".length)] : []));
|
|
1558
|
+
if (owed.length)
|
|
1559
|
+
throw new CaseError(ctx.options.dir, [`the server takes ${owed.join(" and ")} from each run (AGENTRUN_RUN_KEYS=1), and an eval's runs carry no keys: run it without --server, or on a server that holds ${owed.length > 1 ? "them" : "it"}`]);
|
|
1560
|
+
if (via !== undefined && !kept)
|
|
1561
|
+
throw new ApiFailure(`the apply made no trigger named ${via}`);
|
|
1443
1562
|
const agent = expectOk(`reading the agent ${agentId}`, await api("GET", `/agents/${encodeURIComponent(agentId)}`));
|
|
1444
1563
|
// The saved server the apply gave each need ({toolkit: server}; null for a need it left unset).
|
|
1445
1564
|
const used = Object.fromEntries(Object.entries(isObject(applied.servers) ? applied.servers : {}).filter((entry) => typeof entry[1] === "string"));
|
|
@@ -1532,14 +1651,15 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1532
1651
|
stopped();
|
|
1533
1652
|
const result = isObject(view.result) ? view.result : {};
|
|
1534
1653
|
const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
|
|
1654
|
+
const listed = await filesOf(api, runId);
|
|
1535
1655
|
const record = {
|
|
1536
1656
|
answer: typeof result.final_answer === "string" ? result.final_answer : "",
|
|
1537
1657
|
calls: callsOf(ended.rows, harness, Object.fromEntries(Object.entries(used).map(([toolkit, server]) => [server, toolkit]))),
|
|
1538
1658
|
mcpCalls: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))),
|
|
1539
1659
|
files: await (async () => {
|
|
1540
|
-
const
|
|
1660
|
+
const paths = listed.map((file) => file.path);
|
|
1541
1661
|
const named = one.graders.flatMap((grader) => (grader.type === "file_exists" ? [grader.path] : []));
|
|
1542
|
-
return [...
|
|
1662
|
+
return [...paths, ...(await presentOf(api, runId, named.filter((path) => !paths.includes(path))))];
|
|
1543
1663
|
})(),
|
|
1544
1664
|
...(one.now !== undefined ? { now: one.now } : {}),
|
|
1545
1665
|
...(mailbox ? { mailbox } : {}),
|
|
@@ -1560,6 +1680,9 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1560
1680
|
: !graded ? `the run ended ${ended.status}${pending ? ` (${pending})` : ""}${isObject(view.error) && typeof view.error.message === "string" ? `: ${view.error.message}` : ""}`
|
|
1561
1681
|
: undefined;
|
|
1562
1682
|
const output = ended.status === "completed" ? outputVerdict(ctx.pkg, view.result) : undefined;
|
|
1683
|
+
// The files it left, read whole for its llm graders: only a run they grade, so a case of other graders reads none.
|
|
1684
|
+
if (graded && one.graders.some((grader) => grader.type === "llm"))
|
|
1685
|
+
record.finalFiles = await finalFilesOf(api, runId, listed, options.signal, options.fileReadTimeoutMs);
|
|
1563
1686
|
const graders = output ? [output] : [];
|
|
1564
1687
|
for (const grader of one.graders) {
|
|
1565
1688
|
stopped();
|
|
@@ -34,6 +34,23 @@ export declare function importTemplate(deps: TemplateImportDeps, raw: unknown, s
|
|
|
34
34
|
trusted: boolean;
|
|
35
35
|
replaced: string | null;
|
|
36
36
|
}>;
|
|
37
|
+
/** A package made into an agent here as an imported template, from files this server wrote itself (a suggested agent's,
|
|
38
|
+
* suggestions.ts): checked, kept, then applied. Once `apply` has made the agent nothing after it can fail (the registry
|
|
39
|
+
* is in memory), so a thrown error always means no agent was made, which is what Suggestions.create reads it as. An
|
|
40
|
+
* apply refused (a missing model key, say) takes the kept package back as it was before (removed, or the earlier one),
|
|
41
|
+
* but only while the row is still the one this call kept: an import of the same id meanwhile (POST /v2/templates/import)
|
|
42
|
+
* stands. */
|
|
43
|
+
export declare function applyImported<T>(deps: {
|
|
44
|
+
registry: Pick<TemplateRegistry, "put">;
|
|
45
|
+
store: {
|
|
46
|
+
importedTemplates: Pick<Store["importedTemplates"], "list" | "put" | "remove">;
|
|
47
|
+
};
|
|
48
|
+
apply: (pkg: Package) => Promise<T>;
|
|
49
|
+
}, id: string, origin: {
|
|
50
|
+
source: string;
|
|
51
|
+
sha: string;
|
|
52
|
+
publisher: string;
|
|
53
|
+
}, files: ReadonlyMap<string, Buffer>): Promise<T>;
|
|
37
54
|
/** DELETE /v2/templates/{id}: an imported package removed from the store and the registry. A bundled one is 403; none of
|
|
38
55
|
* that id, 404. Agents applied from it stay. */
|
|
39
56
|
export declare function deleteTemplate(deps: Pick<TemplateImportDeps, "registry" | "store">, id: string): Promise<void>;
|