@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.50
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 +26 -9
- package/README.md +104 -22
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +9 -11
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/{index-CR2ZGei1.css → index-D0mr9wfZ.css} +1 -1
- package/dist/console/assets/index-D7G6o-1E.js +720 -0
- package/dist/console/index.html +2 -2
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness.js +2 -1
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/openapi.js +25 -17
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +2 -2
- package/dist/run-launch.js +2 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +15 -1
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +13 -6
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +14 -6
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/learning-end.js +9 -4
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/run-child-host.d.ts +15 -2
- package/dist/runner/run-child-host.js +24 -8
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/sdk/runs.d.ts +3 -4
- package/dist/sdk/runs.js +10 -7
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +4 -0
- package/dist/server.js +3 -3
- package/dist/store/agent-body.d.ts +2 -3
- package/dist/store/agent-body.js +3 -2
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/schema.d.ts +8 -3
- package/dist/store/schema.js +12 -2
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/store.d.ts +2 -4
- package/dist/store/sqlite/store.js +95 -85
- package/dist/store/store.d.ts +8 -1
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +37 -18
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +1 -1
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +19 -1
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +101 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
package/dist/template-eval.js
CHANGED
|
@@ -23,6 +23,7 @@ import { shownUrl } from "./mcp-probe.js";
|
|
|
23
23
|
import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, monidNameOf, parseToolName } from "./tool-names.js";
|
|
24
24
|
import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailboxVerdict, seed, seededFaux, snapshot } from "./eval-mailbox.js";
|
|
25
25
|
import { caseFeeds, feedFixtureOf } from "./eval-feed.js";
|
|
26
|
+
import { HANDED_KINDS, handedPrevious, handedVerdict, previousFixtureOf, seedPrevious } from "./eval-previous.js";
|
|
26
27
|
import { EMAIL_TOOLS } from "./email/names.js";
|
|
27
28
|
import { CALENDAR_EVENTS } from "./calendar/names.js";
|
|
28
29
|
import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
|
|
@@ -31,6 +32,7 @@ import { webShownOf } from "./timeline/index.js";
|
|
|
31
32
|
import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
|
|
32
33
|
import { webFixtureOf } from "./web-fake.js";
|
|
33
34
|
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
35
|
+
import { WEB_SAVE_TOOL } from "./web-save.js";
|
|
34
36
|
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
35
37
|
import { dayIn, serverZone } from "./environment.js";
|
|
36
38
|
import { instantOf } from "./trigger-adapter.js";
|
|
@@ -65,13 +67,14 @@ export const EVAL_HARNESSES = "agentrun-eval-harnesses";
|
|
|
65
67
|
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";
|
|
66
68
|
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
67
69
|
const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
|
|
68
|
-
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed"];
|
|
70
|
+
const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed", "previous"];
|
|
69
71
|
const GRADER_FIELDS = {
|
|
70
72
|
llm: ["type", "target"],
|
|
71
73
|
regex: ["type", "pattern", "flags", "expect", "target"],
|
|
72
74
|
tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "args"],
|
|
73
75
|
file_exists: ["type", "path"],
|
|
74
76
|
mailbox: ["type", "message_id", "in", "not_in"],
|
|
77
|
+
handed: ["type", "expect", "dropped"],
|
|
75
78
|
};
|
|
76
79
|
/** A target: a field of the answer's JSON, dotted for a nested one. */
|
|
77
80
|
const TARGET = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
@@ -81,7 +84,7 @@ const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule each fake MCP server li
|
|
|
81
84
|
/** A host name on this machine: a case with fake MCP servers needs a server here, which reaches them on loopback. */
|
|
82
85
|
const LOOPBACK_HOST = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule a server on this machine reaches the fakes
|
|
83
86
|
/** A case's fields that the eval's own runner alone binds (EvalFakes), each with what it does: a named server refuses them. */
|
|
84
|
-
const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["calendar", "calendar fakes the server's calendar"], ["feed", "feed fakes the package's feeds"]];
|
|
87
|
+
const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["calendar", "calendar fakes the server's calendar"], ["feed", "feed fakes the package's feeds"], ["previous", "previous seeds the case's earlier runs in the server's store"]];
|
|
85
88
|
/** A case's run input: its prompt's body as content (none when empty), then its typed fields. */
|
|
86
89
|
export const runInput = (content, fields) => ({ ...(content ? { content } : {}), ...fields });
|
|
87
90
|
/** Cases that do not check: every problem, each naming its file. */
|
|
@@ -267,6 +270,18 @@ function graderOfType(p, file, text, bad) {
|
|
|
267
270
|
return bad(`${file}: a mailbox grader says where the message is (in) or is not (not_in)`), undefined;
|
|
268
271
|
return { file, type, messageId: data.message_id, ...(typeof data.in === "string" ? { in: data.in } : {}), notIn: notIn };
|
|
269
272
|
}
|
|
273
|
+
case "handed": {
|
|
274
|
+
// What a previous case's run was handed after its message (eval-previous.ts handedPrevious): its kind, and for carried
|
|
275
|
+
// fields how many first entries each carried array gave up.
|
|
276
|
+
if (!HANDED_KINDS.includes(data.expect))
|
|
277
|
+
return bad(`${file}: expect is ${HANDED_KINDS.slice(0, -1).join(", ")} or ${HANDED_KINDS.at(-1)}`), undefined;
|
|
278
|
+
const dropped = data.dropped;
|
|
279
|
+
if (dropped !== undefined && !(isObject(dropped) && Object.values(dropped).every((n) => Number.isSafeInteger(n) && n >= 0)))
|
|
280
|
+
return bad(`${file}: dropped is a mapping of a carried array's field to how many of its first entries were dropped, 0 or more`), undefined;
|
|
281
|
+
if (dropped !== undefined && data.expect !== "carried")
|
|
282
|
+
return bad(`${file}: dropped counts a carried array's entries, and expect is ${String(data.expect)}, not carried`), undefined;
|
|
283
|
+
return { file, type, expect: data.expect, ...(isObject(dropped) ? { dropped: dropped } : {}) };
|
|
284
|
+
}
|
|
270
285
|
}
|
|
271
286
|
return undefined;
|
|
272
287
|
}
|
|
@@ -306,8 +321,8 @@ export function readCases(dir, names) {
|
|
|
306
321
|
const c = typeof spec === "string" ? (bad(`${at}/case.yaml: ${spec}`), {}) : isObject(spec) ? spec : (bad(`${at}/case.yaml: is not a mapping`), {});
|
|
307
322
|
for (const field of unknown(c, CASE_FIELDS))
|
|
308
323
|
bad(`${at}/case.yaml: no field ${field}: its fields are ${CASE_FIELDS.join(", ")}`);
|
|
309
|
-
// An email case's run is on its trigger's input, and its prompt gives none (
|
|
310
|
-
if (c.email === undefined && c.feed === undefined)
|
|
324
|
+
// An email, feed or previous case's run is on its trigger's input, and its prompt gives none (each holds it to that).
|
|
325
|
+
if (c.email === undefined && c.feed === undefined && c.previous === undefined)
|
|
311
326
|
for (const issue of inputIssues(runInput(body, fields), inputSchemaOf(pkg.inputSchema)))
|
|
312
327
|
bad(`${at}/prompt.md: ${issue.message}`);
|
|
313
328
|
if (c.parameters !== undefined && !isObject(c.parameters))
|
|
@@ -358,8 +373,8 @@ export function readCases(dir, names) {
|
|
|
358
373
|
if (c.web !== undefined) {
|
|
359
374
|
const path = c.web === "unavailable" ? undefined : inside(root, c.web, "file");
|
|
360
375
|
// Only a package that names a web tool has one: one that names no tools gets its computer's shell tools, or none.
|
|
361
|
-
if (!
|
|
362
|
-
bad(`${at}/case.yaml: web fakes web_search and
|
|
376
|
+
if (![WEB_SEARCH_TOOL, WEB_FETCH_TOOL, WEB_SAVE_TOOL].some((tool) => pkg.tools?.includes(tool)))
|
|
377
|
+
bad(`${at}/case.yaml: web fakes web_search, web_fetch and web_save, and the package's tools name none of them`);
|
|
363
378
|
else if (c.web === "unavailable")
|
|
364
379
|
web = "unavailable";
|
|
365
380
|
else if (!path)
|
|
@@ -471,6 +486,39 @@ export function readCases(dir, names) {
|
|
|
471
486
|
if (body || fields || f.max_cost_usd !== undefined)
|
|
472
487
|
bad(`${at}/prompt.md: a feed case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
|
|
473
488
|
}
|
|
489
|
+
// The case's previous runs: its fixture, and the package's schedule trigger its runs start from (eval-previous.ts).
|
|
490
|
+
let previous;
|
|
491
|
+
if (c.previous !== undefined) {
|
|
492
|
+
const path = inside(root, c.previous, "file");
|
|
493
|
+
let parsed;
|
|
494
|
+
if (c.email !== undefined || c.feed !== undefined)
|
|
495
|
+
bad(`${at}/case.yaml: a previous case's run is started by the package's schedule trigger: previous goes with neither email nor feed`);
|
|
496
|
+
if (!path)
|
|
497
|
+
bad(`${at}/case.yaml: previous is a previous-runs fixture file in the case (not ${JSON.stringify(c.previous)})`);
|
|
498
|
+
else {
|
|
499
|
+
try {
|
|
500
|
+
parsed = JSON.parse(readFileSync(join(root, path), "utf8"));
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
bad(`${at}/${path}: is not JSON (${error.message})`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const fixture = parsed === undefined ? undefined : previousFixtureOf(parsed, `${at}/${path}`, pkg.outputSchema, bad);
|
|
507
|
+
const kindOf = (t) => (isObject(t.source) ? t.source.kind : undefined);
|
|
508
|
+
const named = fixture?.trigger === undefined ? undefined : pkg.triggers.find((t) => t.name === fixture.trigger);
|
|
509
|
+
const starts = named ? [named] : pkg.triggers.filter((t) => kindOf(t) === "schedule");
|
|
510
|
+
if (!fixture)
|
|
511
|
+
undefined;
|
|
512
|
+
else if (fixture.trigger !== undefined && !named)
|
|
513
|
+
bad(`${at}/${path}: trigger ${fixture.trigger} is not one of the package's triggers (${pkg.triggers.map((t) => String(t.name)).join(", ") || "none"})`);
|
|
514
|
+
else if (starts.length !== 1 || kindOf(starts[0]) !== "schedule")
|
|
515
|
+
bad(`${at}/${path}: a previous case starts its run through the package's schedule trigger, and ${named ? `${fixture.trigger} is a ${String(kindOf(named))} trigger` : starts.length ? `the package has ${starts.length}: name one with trigger` : "the package has none"}`);
|
|
516
|
+
else
|
|
517
|
+
previous = { ...fixture, trigger: String(starts[0].name) };
|
|
518
|
+
// Its run is the trigger's, on the trigger's input and cap: the prompt gives neither.
|
|
519
|
+
if (body || fields || f.max_cost_usd !== undefined)
|
|
520
|
+
bad(`${at}/prompt.md: a previous case's run is started by the package's schedule trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
|
|
521
|
+
}
|
|
474
522
|
let learning;
|
|
475
523
|
if (c.learning !== undefined) {
|
|
476
524
|
const file = inside(root, c.learning, "file");
|
|
@@ -493,6 +541,8 @@ export function readCases(dir, names) {
|
|
|
493
541
|
const unrun = grader?.layouts?.filter((layout) => email && !email.layouts.includes(layout)) ?? [];
|
|
494
542
|
if (grader?.type === "mailbox" && c.email === undefined)
|
|
495
543
|
bad(`${at}/graders/${entry.name}: a mailbox grader reads the case's fake mailbox, and the case has no email`);
|
|
544
|
+
else if (grader?.type === "handed" && c.previous === undefined)
|
|
545
|
+
bad(`${at}/graders/${entry.name}: a handed grader reads what a previous case's run was handed, and the case has no previous`);
|
|
496
546
|
else if (grader?.layouts && c.email === undefined)
|
|
497
547
|
bad(`${at}/graders/${entry.name}: layouts grades the runs of an email case's layouts, and the case has no email`);
|
|
498
548
|
else if (unrun.length)
|
|
@@ -505,7 +555,7 @@ export function readCases(dir, names) {
|
|
|
505
555
|
cases.push({
|
|
506
556
|
name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
|
|
507
557
|
...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
|
|
508
|
-
parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), ...(learning !== undefined ? { learning } : {}), graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}),
|
|
558
|
+
parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), ...(learning !== undefined ? { learning } : {}), graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}), ...(previous ? { previous } : {}),
|
|
509
559
|
});
|
|
510
560
|
}
|
|
511
561
|
if (problems.length)
|
|
@@ -642,6 +692,8 @@ export function gradeDeterministic(grader, run, faked) {
|
|
|
642
692
|
}
|
|
643
693
|
case "mailbox":
|
|
644
694
|
return run.mailbox ? mailboxVerdict(run.mailbox, grader.messageId, grader.in, grader.notIn) : { pass: false, reason: "the run has no fake mailbox to read" };
|
|
695
|
+
case "handed":
|
|
696
|
+
return handedVerdict(run.handed, grader.expect, grader.dropped);
|
|
645
697
|
}
|
|
646
698
|
}
|
|
647
699
|
/** The output check of a completed run of a package that declares `output`, beside its case's graders: the server's own
|
|
@@ -1001,7 +1053,7 @@ export async function evalTemplate(options) {
|
|
|
1001
1053
|
throw new CaseError(options.dir, refused);
|
|
1002
1054
|
// Each run's fakes, by the agent the eval made for it (runOnce), which the runner beside the server reads at the claim.
|
|
1003
1055
|
const fakes = new Map();
|
|
1004
|
-
const clock = !options.server && cases.some((one) => one.email || one.feed) ? evalClock() : undefined;
|
|
1056
|
+
const clock = !options.server && cases.some((one) => one.email || one.feed || one.previous) ? evalClock() : undefined;
|
|
1005
1057
|
// Where the eval's own server reads each feed: the running feed case's fakes (feedRun). A feed no case routes (a feed
|
|
1006
1058
|
// trigger of the package's that the eval deletes once the apply made it, read at its creation) is served nowhere: its
|
|
1007
1059
|
// read is unreachable at once, never sent, so no eval reads a real feed.
|
|
@@ -1080,7 +1132,8 @@ export async function evalTemplate(options) {
|
|
|
1080
1132
|
}
|
|
1081
1133
|
// On the owner's folder, an email case's fake mailbox would replace the account its server keeps (one account, saved
|
|
1082
1134
|
// and removed per run): refused before anything runs, the account as it was.
|
|
1083
|
-
|
|
1135
|
+
// Only an email case saves a mailbox: a previous or feed case on the clock leaves the account alone.
|
|
1136
|
+
if (cases.some((one) => one.email) && options.data !== undefined) {
|
|
1084
1137
|
const kept = await api("GET", "/settings/email", undefined, owner).catch(() => undefined);
|
|
1085
1138
|
const address = kept?.status === 200 && isObject(kept.body) ? kept.body.address : undefined;
|
|
1086
1139
|
if (typeof address === "string" || kept?.status !== 200) {
|
|
@@ -1108,8 +1161,12 @@ export async function evalTemplate(options) {
|
|
|
1108
1161
|
const results = [];
|
|
1109
1162
|
let grader;
|
|
1110
1163
|
const made = { agents: [], runs: new Set(), triggers: new Set() };
|
|
1164
|
+
// A previous case's earlier runs are written in the eval's own server's store (eval-previous.ts seedPrevious), opened
|
|
1165
|
+
// beside the server as its runner opens it, once, when the first such run seeds.
|
|
1166
|
+
let opened;
|
|
1167
|
+
const store = data !== undefined && cases.some((one) => one.previous) ? () => (opened ??= import("./store/open.js").then(({ openStore }) => openStore({ dataDir: data, role: "runner" }))) : undefined;
|
|
1111
1168
|
const ctx = {
|
|
1112
|
-
api, pkg, options, made, log, fakes, feedRoutes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}),
|
|
1169
|
+
api, pkg, options, made, log, fakes, feedRoutes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}), ...(store ? { store } : {}),
|
|
1113
1170
|
graderAgent: async () => {
|
|
1114
1171
|
if (grader)
|
|
1115
1172
|
return grader;
|
|
@@ -1135,6 +1192,7 @@ export async function evalTemplate(options) {
|
|
|
1135
1192
|
if (options.server || options.data !== undefined)
|
|
1136
1193
|
for (const id of made.agents)
|
|
1137
1194
|
await api("POST", `/agents/${encodeURIComponent(id)}/archive`, {}).catch(() => undefined);
|
|
1195
|
+
await opened?.then((one) => one.close(), () => undefined);
|
|
1138
1196
|
await close();
|
|
1139
1197
|
if (scratch)
|
|
1140
1198
|
removeTree(scratch);
|
|
@@ -1357,8 +1415,8 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
|
|
|
1357
1415
|
// every run. Left where the run before took it, a schedule's next time is a later day each run, with no mail of the case.
|
|
1358
1416
|
// A millisecond before it: a schedule's next time is strictly after the clock, so a case whose `now` is the schedule's
|
|
1359
1417
|
// own time (an evening digest's 18:00) fires for that time, not the next day's.
|
|
1360
|
-
// An email or
|
|
1361
|
-
const via = mail ? one.email.trigger : feeds ? one.feed.trigger :
|
|
1418
|
+
// An email, feed or previous case's run is its one trigger's (readCases chose it): `via`, that trigger's name.
|
|
1419
|
+
const via = mail ? one.email.trigger : feeds ? one.feed.trigger : one.previous?.trigger;
|
|
1362
1420
|
if (via !== undefined && one.now !== undefined)
|
|
1363
1421
|
ctx.clock?.set(instantOf(one.now) - 1);
|
|
1364
1422
|
// Approvals never, for the eval's own agent only: a run that stopped at its first ask would measure nothing. The
|
|
@@ -1414,6 +1472,17 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
|
|
|
1414
1472
|
}, fixture.message ? " (its accept rules may leave the case's message)" : "");
|
|
1415
1473
|
fired = { mailbox: () => mailboxAfter(mail.faux, mail.layout, before) };
|
|
1416
1474
|
}
|
|
1475
|
+
else if (one.previous) {
|
|
1476
|
+
// The case's earlier results, each a completed run of this agent that a firing of the trigger started, ended before
|
|
1477
|
+
// the clock's time, so the trigger's own firing hands the run the last one's (trigger-targets.ts previousResultOf).
|
|
1478
|
+
if (!ctx.store || !ctx.clock)
|
|
1479
|
+
throw new ApiFailure("a previous case's earlier runs are seeded in the eval's own server's store, and this eval has none");
|
|
1480
|
+
const trigger = expectOk(`reading the package's trigger ${via}`, await api("GET", `/triggers/${encodeURIComponent(kept)}`));
|
|
1481
|
+
const target = isObject(trigger.target) && isObject(trigger.target.input) ? trigger.target.input : {};
|
|
1482
|
+
const previous = await seedPrevious(await ctx.store(), one.previous, { agentId, triggerId: kept, content: typeof target.content === "string" ? target.content : "", before: ctx.clock.now() });
|
|
1483
|
+
runId = await triggerRun(ctx, via, agentId, kept, () => undefined, "");
|
|
1484
|
+
fired = { previous };
|
|
1485
|
+
}
|
|
1417
1486
|
else {
|
|
1418
1487
|
runId = await triggerRun(ctx, via, agentId, kept, () => feeds.deliver(), " (its accept rules may leave the case's item)");
|
|
1419
1488
|
fired = {};
|
|
@@ -1438,6 +1507,14 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
|
|
|
1438
1507
|
await deleteTriggers(api, made);
|
|
1439
1508
|
}
|
|
1440
1509
|
}
|
|
1510
|
+
/** What a previous case's run, its input content `content`, was handed of the last result `seeded`: that run read back as
|
|
1511
|
+
* the trigger reads it (its result.output and end, GET /runs/{id}), handed over as the trigger hands it (handedPrevious). */
|
|
1512
|
+
async function handedOf(api, content, seeded) {
|
|
1513
|
+
const last = seeded.at(-1);
|
|
1514
|
+
const read = expectOk(`reading the seeded run ${last.runId}`, await api("GET", `/runs/${last.runId}`));
|
|
1515
|
+
const output = isObject(read.result) ? (read.result.output ?? null) : null;
|
|
1516
|
+
return handedPrevious(content, last, { output, endedAt: typeof read.ended_at === "string" ? read.ended_at : null });
|
|
1517
|
+
}
|
|
1441
1518
|
/** The started run `runId` of `agentId` waited on, read and graded; its calls on the saved servers `used` gave its needs
|
|
1442
1519
|
* ({toolkit: server}) named on the package's toolkits; a run its trigger started (`fired`) graded on the input it was
|
|
1443
1520
|
* given, an email run's fake mailbox read once it has ended. */
|
|
@@ -1451,6 +1528,7 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1451
1528
|
// Its metrics once it has ended (a cancelled run's end writes them too), before the eval's server can go.
|
|
1452
1529
|
const metrics = await metricsOf(api, agentId, options.signal);
|
|
1453
1530
|
const mailbox = fired?.mailbox ? await fired.mailbox() : undefined;
|
|
1531
|
+
const handed = fired?.previous ? await handedOf(api, isObject(view.input) && typeof view.input.content === "string" ? view.input.content : "", fired.previous) : undefined;
|
|
1454
1532
|
stopped();
|
|
1455
1533
|
const result = isObject(view.result) ? view.result : {};
|
|
1456
1534
|
const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
|
|
@@ -1465,9 +1543,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
|
|
|
1465
1543
|
})(),
|
|
1466
1544
|
...(one.now !== undefined ? { now: one.now } : {}),
|
|
1467
1545
|
...(mailbox ? { mailbox } : {}),
|
|
1546
|
+
...(handed ? { handed } : {}),
|
|
1468
1547
|
};
|
|
1469
1548
|
stopped();
|
|
1470
|
-
const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}) };
|
|
1549
|
+
const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}), ...(handed ? { handed_previous: handed } : {}) };
|
|
1471
1550
|
// The grader's task: the input the run was given, an email or feed run's its trigger's (the payload in its tag).
|
|
1472
1551
|
const task = fired ? inputMessage(view.input ?? {}) : inputMessage(runInput(one.input, one.fields));
|
|
1473
1552
|
// Waiting on its person's answer (an ask_person question, a tool call's approval) is where such a run stops, and is
|
package/dist/templates.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const MANIFEST = "agent.md";
|
|
|
19
19
|
export declare const MODEL_TIERS: Readonly<Record<string, Tier>>;
|
|
20
20
|
/** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
|
|
21
21
|
* to it by the server's own verdict (template-eval.ts outputVerdict). */
|
|
22
|
-
export declare const GRADER_TYPES: readonly ["llm", "regex", "tool_used", "file_exists", "mailbox"];
|
|
22
|
+
export declare const GRADER_TYPES: readonly ["llm", "regex", "tool_used", "file_exists", "mailbox", "handed"];
|
|
23
23
|
/** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
|
|
24
24
|
* `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
|
|
25
25
|
export declare const COMPUTER_ENTRIES: readonly ["shell", "none"];
|
package/dist/templates.js
CHANGED
|
@@ -37,7 +37,7 @@ export const MODEL_TIERS = { fast: "fast", balanced: "default", strong: "strong"
|
|
|
37
37
|
const SCALAR_TYPES = ["string", "number", "integer", "boolean"];
|
|
38
38
|
/** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
|
|
39
39
|
* to it by the server's own verdict (template-eval.ts outputVerdict). */
|
|
40
|
-
export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbox"];
|
|
40
|
+
export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbox", "handed"];
|
|
41
41
|
/** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
|
|
42
42
|
* `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
|
|
43
43
|
export const COMPUTER_ENTRIES = ["shell", "none"];
|
|
@@ -902,9 +902,10 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
902
902
|
const caseDoc = own.includes("case.yaml") ? parseDocument(text(`${at}/case.yaml`), { uniqueKeys: true }) : undefined;
|
|
903
903
|
if (caseDoc?.errors.length)
|
|
904
904
|
bad(`${at}/case.yaml`, "is not YAML");
|
|
905
|
-
// An email or
|
|
905
|
+
// An email, feed or previous case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has
|
|
906
|
+
// no body.
|
|
906
907
|
const caseJs = !!caseDoc && !caseDoc.errors.length && isObject(caseDoc.toJS()) ? caseDoc.toJS() : undefined;
|
|
907
|
-
const triggeredCase = caseJs !== undefined && (caseJs.email !== undefined || caseJs.feed !== undefined);
|
|
908
|
+
const triggeredCase = caseJs !== undefined && (caseJs.email !== undefined || caseJs.feed !== undefined || caseJs.previous !== undefined);
|
|
908
909
|
if (!own.includes("prompt.md"))
|
|
909
910
|
bad(at, "has no prompt.md");
|
|
910
911
|
else if (!triggeredCase && !front(`${at}/prompt.md`, false)?.body.trim())
|
package/dist/timeline/labels.js
CHANGED
|
@@ -81,6 +81,10 @@ export function savedPaths(tool, args, result) {
|
|
|
81
81
|
const file = str(args.path) ?? str(args.file_path);
|
|
82
82
|
return file ? [file] : [];
|
|
83
83
|
}
|
|
84
|
+
if (tool === "web_save") {
|
|
85
|
+
const saved = obj(json(result.text));
|
|
86
|
+
return saved?.ok === true && str(saved.path) ? [str(saved.path)] : [];
|
|
87
|
+
}
|
|
84
88
|
if (tool !== "browser_downloads")
|
|
85
89
|
return [];
|
|
86
90
|
const fetched = json(result.text)?.fetched;
|
|
@@ -130,6 +134,19 @@ const fetchOutcome = (result) => {
|
|
|
130
134
|
// web_fetch answers a page, `{ok, url, status, title, text, links, refused?, error?}`.
|
|
131
135
|
registerLabel("web_fetch", fetchLabel, fetchFold, { name: "Fetch web pages" });
|
|
132
136
|
registerOutcome("web_fetch", fetchOutcome);
|
|
137
|
+
// web_save answers `{ok: true, path, bytes, content_type, url}` or `{ok: false, url, path?, refused | error}` (web-save.ts):
|
|
138
|
+
// the path it answered, else the one asked (a bare name under media/, as it saves one), and the host it was asked for.
|
|
139
|
+
const savedAt = (a, result) => {
|
|
140
|
+
const answered = result && str(obj(json(result.text))?.path);
|
|
141
|
+
const asked = str(a.path);
|
|
142
|
+
return answered ?? (asked ? (asked.includes("/") ? asked : `media/${asked}`) : "a file");
|
|
143
|
+
};
|
|
144
|
+
const fromHost = (a) => {
|
|
145
|
+
const host = URL.parse(str(a.url) ?? "")?.host;
|
|
146
|
+
return host ? ` from ${host}` : "";
|
|
147
|
+
};
|
|
148
|
+
registerLabel("web_save", (a, result) => `${unfetched(result) ? "Tried to save" : "Saved"} ${savedAt(a, result)}${fromHost(a)}`, { many: (n) => `Saved ${n} files from the web`, subject: (input) => input ?? undefined }, { name: "Save files from the web" });
|
|
149
|
+
registerOutcome("web_save", fetchOutcome);
|
|
133
150
|
registerLabel("web_search", (a) => {
|
|
134
151
|
const query = str(a.query);
|
|
135
152
|
return query ? `Searched the web for "${cut(scrubUrls(query), 60)}"` : "Searched the web";
|
package/dist/tool-list.js
CHANGED
|
@@ -6,6 +6,7 @@ export const TOOL_LIST = Object.freeze({
|
|
|
6
6
|
ask_person: { table: true, replay: "safe", blurb: "Ask you a question mid-run" },
|
|
7
7
|
web_fetch: { table: true, askable: true, replay: "safe", host: true, blurb: "Read a public web page" },
|
|
8
8
|
web_search: { table: true, askable: true, replay: "safe", host: true, blurb: "Search the web" },
|
|
9
|
+
web_save: { table: true, askable: true, replay: "never", host: true, blurb: "Save a public file into the run's folder" },
|
|
9
10
|
email_search: { table: true, askable: true, replay: "safe", host: true, blurb: "Search the email account's mail" },
|
|
10
11
|
email_read: { table: true, askable: true, replay: "safe", host: true, blurb: "Read an email or its thread" },
|
|
11
12
|
email_draft: { table: true, askable: true, replay: "never", host: true, blurb: "Save an email draft" },
|
package/dist/tools.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { Refusal } from "@parcha/agentrun-kernel";
|
|
|
11
11
|
import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
|
|
12
12
|
import { type SearchOn } from "./web-search.js";
|
|
13
13
|
import { type WebFake } from "./web-fake.js";
|
|
14
|
+
import { type SaveSlots } from "./web-save.js";
|
|
14
15
|
import { type Plane, type Resolution, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
|
|
15
16
|
import type { DenyFrom, SettingFrom } from "./tool-gate.js";
|
|
16
17
|
import type { LiveHandover, LiveViewerStore } from "./browser-live.js";
|
|
@@ -122,8 +123,8 @@ export type ToolHost = {
|
|
|
122
123
|
/** The run's own models a native web_search goes through (hosted-search.ts), asked as a search runs: on the runner, the
|
|
123
124
|
* session's port (its proxy, policy, key, price and cap), this run's alone. Absent: a native search has no model. */
|
|
124
125
|
search?: SearchOn;
|
|
125
|
-
/** A template eval's web fake for this run (web-fake.ts): its web_search and
|
|
126
|
-
* network. Only the eval's own runner sets it (runner/beside.ts evalFakes). Absent: the plane's providers. */
|
|
126
|
+
/** A template eval's web fake for this run (web-fake.ts): its web_search, web_fetch and web_save answer from it, never
|
|
127
|
+
* the network. Only the eval's own runner sets it (runner/beside.ts evalFakes). Absent: the plane's providers. */
|
|
127
128
|
web?: WebFake;
|
|
128
129
|
/** The run's clock where a template eval case sets one (its `now`): a draft's or a send's Date reads it. Absent: the real
|
|
129
130
|
* clock. */
|
|
@@ -137,6 +138,9 @@ export type ToolHost = {
|
|
|
137
138
|
/** That server's own addresses (Serve.own, AdapterSpecDeps.mcpOwn): calendar_events never reads on loopback at their
|
|
138
139
|
* ports, a redirect's hop included, as the server's own read (calendar/routes.ts) never does. */
|
|
139
140
|
serverOwn?: readonly string[];
|
|
141
|
+
/** web_save's download slots: in a run's own process, its runner's gate over the channel (runner/save-slots.ts).
|
|
142
|
+
* Absent: this process's (web-save.ts SERVER_SLOTS). */
|
|
143
|
+
saveSlots?: SaveSlots;
|
|
140
144
|
};
|
|
141
145
|
/** A fake mail account's servers, on loopback (email/email-faux.ts), and the kind of server it plays: what email_file's
|
|
142
146
|
* description says, which a loopback account saved as `other` would otherwise read as folders. */
|
package/dist/tools.js
CHANGED
|
@@ -33,7 +33,8 @@ import { sessionRecordings } from "./computer-record.js";
|
|
|
33
33
|
import { forModel } from "./result.js";
|
|
34
34
|
import { fetchFor, pagesOf, WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
|
|
35
35
|
import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
36
|
-
import { fakeFetch, fakeSearch } from "./web-fake.js";
|
|
36
|
+
import { fakeFetch, fakeSaveOptions, fakeSearch } from "./web-fake.js";
|
|
37
|
+
import { SAVE_MAX_BYTES, WEB_SAVE_TOOL, webSaveTool } from "./web-save.js";
|
|
37
38
|
import { browserNeeds, explainsView, isUnavailable, NO_PARALLEL_KEY, PICKABLE, planeOf, PROVIDERS, serverGate, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
38
39
|
import { fauxFetch, PARALLEL_KEY_ENV } from "./decisions.js";
|
|
39
40
|
import { keyNeeded } from "./key-words.js";
|
|
@@ -624,6 +625,17 @@ export const TOOLS = Object.freeze({
|
|
|
624
625
|
bind: async (host) => installTool(host, "web-search", booking(webSearchTool(host.env, host.search, host.web && ((args, provider) => fakeSearch(host.web, args, provider))))),
|
|
625
626
|
effect: async (args, run) => bookedIn(run.ledger, () => searchFor(run.env, args, run.signal, run.search)),
|
|
626
627
|
},
|
|
628
|
+
// web_save (web-save.ts). It makes no paid request, so nothing books it. No node or call node names it: a workflow's
|
|
629
|
+
// effect has only a local work path, not the run's Workspace.
|
|
630
|
+
[WEB_SAVE_TOOL]: {
|
|
631
|
+
summary: `Download one public file into the run's work/ (a bare name under media/), never overwriting: { url, path } -> { ok: true, path, bytes, content_type, url } or { ok: false, url, refused | error }; at most ${SAVE_MAX_BYTES / (1024 * 1024)} MiB, a media type only when its bytes agree.`,
|
|
632
|
+
needs: [],
|
|
633
|
+
nodes: false,
|
|
634
|
+
bind: async (host) => {
|
|
635
|
+
const web = host.web;
|
|
636
|
+
return installTool(host, "web-save", webSaveTool(() => host.workspace ?? localWorkspace(host.where.work), async () => (web ? fakeSaveOptions(web) : fetchOptions(host.env, FAUX_ENV)), host.saveSlots));
|
|
637
|
+
},
|
|
638
|
+
},
|
|
627
639
|
// The email tools (email/tools.ts) on the server's one email account (Settings → Email), every harness's as web_fetch is;
|
|
628
640
|
// the mail libraries load at the first bind.
|
|
629
641
|
[EMAIL_SEARCH]: emailTool(EMAIL_SEARCH),
|
|
@@ -28,11 +28,7 @@ export interface TriggerTargetDeps {
|
|
|
28
28
|
* when it ended; undefined for a run that is unknown or did not complete (the run view). `carried`: the top-level
|
|
29
29
|
* fields the output schema it was checked against (its pinned revision's, never the agent's current one) names in
|
|
30
30
|
* `x-carried` (answer-json.ts carriedFields), absent when it names none. */
|
|
31
|
-
completedOutput(runId: string): Promise<
|
|
32
|
-
output: unknown;
|
|
33
|
-
endedAt: string | null;
|
|
34
|
-
carried?: readonly string[];
|
|
35
|
-
} | undefined>;
|
|
31
|
+
completedOutput(runId: string): Promise<CompletedOutput | undefined>;
|
|
36
32
|
}
|
|
37
33
|
/** The most bytes of a previous run's result a triggered run is handed, as JSON: past it, it is handed none, said so. */
|
|
38
34
|
export declare const PREVIOUS_RESULT_MAX_BYTES: number;
|
|
@@ -46,6 +42,26 @@ export declare const previousCarriedWords: (runId: string, endedAt: string | nul
|
|
|
46
42
|
/** What a triggered run is told when its trigger's previous result is over PREVIOUS_RESULT_MAX_BYTES (and no carried
|
|
47
43
|
* fields of it fit, its carried arrays' entries dropped). */
|
|
48
44
|
export declare const previousResultTooLarge: (runId: string) => string;
|
|
45
|
+
/** A completed run's result as the trigger reads it back (TriggerTargetDeps.completedOutput). */
|
|
46
|
+
export type CompletedOutput = {
|
|
47
|
+
output: unknown;
|
|
48
|
+
endedAt: string | null;
|
|
49
|
+
carried?: readonly string[];
|
|
50
|
+
};
|
|
51
|
+
/** What a triggered run is handed of its trigger's last completed run `runId`, whose result is `done`: `whole`, its
|
|
52
|
+
* result.output as it is; `carried`, its carried `fields` alone, `dropped` the entries each carried array gave up from its
|
|
53
|
+
* front, by field (0 for one that gave up none; a carried field that is no array is not in it); `too_large`, nothing,
|
|
54
|
+
* said so; `none`, nothing at all (it has no output: its answer did not meet its schema). `text` is the words the run's
|
|
55
|
+
* message carries it in after the trigger's (empty for none). previousResultOf hands the text; a template eval grades
|
|
56
|
+
* the rest (eval-previous.ts handedPrevious). */
|
|
57
|
+
export type PreviousHandover = {
|
|
58
|
+
kind: "whole" | "carried" | "too_large" | "none";
|
|
59
|
+
text: string;
|
|
60
|
+
run_id?: string;
|
|
61
|
+
fields?: string[];
|
|
62
|
+
dropped?: Record<string, number>;
|
|
63
|
+
};
|
|
64
|
+
export declare function previousHandover(runId: string, done: CompletedOutput): PreviousHandover;
|
|
49
65
|
/** The trigger-facing run policy: the subset of the trigger engine's deps this module owns. The engine's other deps (an
|
|
50
66
|
* adapter's sealed settings, the failed-firing webhook) stay server-wired. */
|
|
51
67
|
export type TriggerTargets = {
|
package/dist/trigger-targets.js
CHANGED
|
@@ -32,18 +32,20 @@ async function previousResultOf(store, deps, trigger) {
|
|
|
32
32
|
const firings = (await store.triggers.firings(trigger.id)).filter((firing) => firing.key !== trigger.firing_key && firing.runId).slice(0, PREVIOUS_FIRINGS_READ);
|
|
33
33
|
for (const firing of firings) {
|
|
34
34
|
const done = await deps.completedOutput(firing.runId);
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
if (done.output === null || done.output === undefined)
|
|
38
|
-
return "";
|
|
39
|
-
const json = JSON.stringify(done.output, null, 2);
|
|
40
|
-
const bytes = Buffer.byteLength(json);
|
|
41
|
-
if (bytes <= PREVIOUS_RESULT_MAX_BYTES)
|
|
42
|
-
return previousResultWords(firing.runId, done.endedAt, json);
|
|
43
|
-
return carriedOf(firing.runId, done, bytes) ?? previousResultTooLarge(firing.runId);
|
|
35
|
+
if (done)
|
|
36
|
+
return previousHandover(firing.runId, done).text;
|
|
44
37
|
}
|
|
45
38
|
return "";
|
|
46
39
|
}
|
|
40
|
+
export function previousHandover(runId, done) {
|
|
41
|
+
if (done.output === null || done.output === undefined)
|
|
42
|
+
return { kind: "none", text: "" };
|
|
43
|
+
const json = JSON.stringify(done.output, null, 2);
|
|
44
|
+
const bytes = Buffer.byteLength(json);
|
|
45
|
+
if (bytes <= PREVIOUS_RESULT_MAX_BYTES)
|
|
46
|
+
return { kind: "whole", text: previousResultWords(runId, done.endedAt, json), run_id: runId };
|
|
47
|
+
return carriedOf(runId, done, bytes) ?? { kind: "too_large", text: previousResultTooLarge(runId), run_id: runId };
|
|
48
|
+
}
|
|
47
49
|
/** A previous result over the limit, `bytes` whole, as its carried fields alone (`done.carried`, the ones it holds),
|
|
48
50
|
* measured as the whole is. When they are over PREVIOUS_RESULT_MAX_BYTES, carried arrays give up entries from the front
|
|
49
51
|
* (the convention: a template keeps a carried array oldest first; the engine reads no dates), one at a time, from the
|
|
@@ -83,7 +85,8 @@ function carriedOf(runId, done, bytes) {
|
|
|
83
85
|
if (Buffer.byteLength(json) > PREVIOUS_RESULT_MAX_BYTES)
|
|
84
86
|
return undefined;
|
|
85
87
|
}
|
|
86
|
-
|
|
88
|
+
const text = previousCarriedWords(runId, done.endedAt, fields, bytes, json, fields.flatMap((field) => (dropped.has(field) ? [[field, dropped.get(field)]] : [])));
|
|
89
|
+
return { kind: "carried", text, run_id: runId, fields, dropped: Object.fromEntries(fields.flatMap((field) => (Array.isArray(picked[field]) ? [[field, dropped.get(field) ?? 0]] : []))) };
|
|
87
90
|
}
|
|
88
91
|
/** The bytes of a carried array from entry `from` on, as JSON.stringify(picked, null, 2) lays it out one level into the
|
|
89
92
|
* object: `[]`, or `[\n`, each entry at four spaces (its own inner lines four further in) joined by `,\n`, then `\n ]`.
|
package/dist/web-fake.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type Page, type Part } from "./web-fetch-direct.js";
|
|
|
2
2
|
import { type WebPage } from "./web-fetch.js";
|
|
3
3
|
import { type Hit, type Search } from "./web-search.js";
|
|
4
4
|
import type { Plane } from "./tool-plane.js";
|
|
5
|
+
import type { PublicFetchOptions } from "@parcha/pi-browser";
|
|
5
6
|
export type SearchAnswer = {
|
|
6
7
|
query: string;
|
|
7
8
|
results: Hit[];
|
|
@@ -18,6 +19,21 @@ export type FetchAnswer = {
|
|
|
18
19
|
url: string;
|
|
19
20
|
error: string;
|
|
20
21
|
};
|
|
22
|
+
/** A saved file's answer: its body as text or as base64, its declared type and status. */
|
|
23
|
+
export type FileBody = {
|
|
24
|
+
status?: number;
|
|
25
|
+
content_type?: string;
|
|
26
|
+
} & ({
|
|
27
|
+
text: string;
|
|
28
|
+
} | {
|
|
29
|
+
base64: string;
|
|
30
|
+
});
|
|
31
|
+
export type SaveAnswer = ({
|
|
32
|
+
url: string;
|
|
33
|
+
} & FileBody) | {
|
|
34
|
+
url: string;
|
|
35
|
+
error: string;
|
|
36
|
+
};
|
|
21
37
|
export type WebFixture = {
|
|
22
38
|
search: {
|
|
23
39
|
answers: SearchAnswer[];
|
|
@@ -37,6 +53,12 @@ export type WebFixture = {
|
|
|
37
53
|
error: string;
|
|
38
54
|
};
|
|
39
55
|
};
|
|
56
|
+
save?: {
|
|
57
|
+
answers: SaveAnswer[];
|
|
58
|
+
default?: FileBody | {
|
|
59
|
+
error: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
40
62
|
};
|
|
41
63
|
/** A case's web fake: every web call failing, or a fixture. */
|
|
42
64
|
export type WebFake = "unavailable" | WebFixture;
|
|
@@ -51,6 +73,9 @@ export declare function fakeSearch(fake: WebFake, args: Record<string, unknown>,
|
|
|
51
73
|
export declare function fakeFetch(fake: WebFake, url: unknown, part?: Part & {
|
|
52
74
|
signal?: AbortSignal;
|
|
53
75
|
}): Promise<WebPage | Page>;
|
|
76
|
+
/** The guard's resolver and fetch for web_save in `fake`: every name a public address, each file answered from the
|
|
77
|
+
* fixture's `save` (by exact URL, else its default), every other URL a refused connection, as a host that is down. */
|
|
78
|
+
export declare function fakeSaveOptions(fake: WebFake): Pick<PublicFetchOptions, "lookup" | "fetchImpl">;
|
|
54
79
|
/** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
|
|
55
80
|
* the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
|
|
56
81
|
export declare function fakedPlane(plane: Plane | undefined): Plane | undefined;
|
package/dist/web-fake.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// RATE_LIMITED), and every page fails as a fetch whose connection is refused does (the guarded direct fetch's own words,
|
|
5
5
|
// web-fetch-direct.ts readDirect). A fixture: each search answered by the first answer whose `query` (a regular
|
|
6
6
|
// expression, case-insensitive) matches the query, else its default; each page by the answer for exactly its URL, else
|
|
7
|
-
// its default, read through the guarded direct fetch's own path (its URL, port and status checks, its parts).
|
|
7
|
+
// its default, read through the guarded direct fetch's own path (its URL, port and status checks, its parts). web_save's
|
|
8
|
+
// files (web-save.ts) answer from the fixture's optional `save`: each file by the answer for exactly its URL, else its
|
|
9
|
+
// default, else a refused connection, downloaded through web_save's own guarded path (every hop checked, the cap, the type
|
|
10
|
+
// checked against the bytes); `unavailable` refuses every connection.
|
|
8
11
|
//
|
|
9
12
|
// Only the eval's own in-process runner binds it (runner/beside.ts `evalFakes`, by the agent the eval made for the run):
|
|
10
13
|
// no package field, API field, setting or environment variable reaches it, so no other server's runs ever see a fake.
|
|
@@ -55,6 +58,22 @@ export function webFixtureOf(value, at, bad) {
|
|
|
55
58
|
});
|
|
56
59
|
if (!pageOk(fetch.default, false))
|
|
57
60
|
say("fetch.default is {status?, title?, text} or {error}");
|
|
61
|
+
const statusOk = (status) => status === undefined || (Number.isInteger(status) && status >= 200 && status <= 599);
|
|
62
|
+
const fileOk = (answer, keyed) => isObject(answer) && (!keyed || (isText(answer.url) && URL.canParse(answer.url)))
|
|
63
|
+
&& (isText(answer.error) ? answer.text === undefined && answer.base64 === undefined : (isText(answer.text) !== isText(answer.base64)) && (answer.text === undefined || isText(answer.text)) && (answer.base64 === undefined || isText(answer.base64)) && statusOk(answer.status) && (answer.content_type === undefined || isText(answer.content_type)));
|
|
64
|
+
if (value.save !== undefined) {
|
|
65
|
+
const save = value.save;
|
|
66
|
+
if (!isObject(save) || !Array.isArray(save.answers))
|
|
67
|
+
say("save is {answers, default?}, answers a list of {url, content_type?, status?, text | base64} or {url, error}");
|
|
68
|
+
else {
|
|
69
|
+
save.answers.forEach((answer, i) => {
|
|
70
|
+
if (!fileOk(answer, true))
|
|
71
|
+
say(`save.answers.${i} is {url, content_type?, status?, text | base64} or {url, error}, its url absolute and its status 200 to 599`);
|
|
72
|
+
});
|
|
73
|
+
if (save.default !== undefined && !fileOk(save.default, false))
|
|
74
|
+
say("save.default is {content_type?, status?, text | base64} or {error}");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
58
77
|
for (const problem of problems)
|
|
59
78
|
bad(problem);
|
|
60
79
|
return problems.length ? undefined : value;
|
|
@@ -95,6 +114,24 @@ export async function fakeFetch(fake, url, part = {}) {
|
|
|
95
114
|
// A page served as text has no title of its own: the fixture's.
|
|
96
115
|
return page.ok && answer && !("error" in answer) && answer.title ? { ...page, title: clip(answer.title, TITLE_CAP) } : page;
|
|
97
116
|
}
|
|
117
|
+
/** The guard's resolver and fetch for web_save in `fake`: every name a public address, each file answered from the
|
|
118
|
+
* fixture's `save` (by exact URL, else its default), every other URL a refused connection, as a host that is down. */
|
|
119
|
+
export function fakeSaveOptions(fake) {
|
|
120
|
+
return {
|
|
121
|
+
lookup: async () => [PUBLIC_ADDRESS],
|
|
122
|
+
fetchImpl: async (url) => {
|
|
123
|
+
const save = fake === "unavailable" ? undefined : fake.save;
|
|
124
|
+
const answer = save?.answers.find((one) => one.url === String(url)) ?? save?.default;
|
|
125
|
+
if (answer === undefined)
|
|
126
|
+
throw new TypeError("fetch failed", { cause: Object.assign(new Error("connect ECONNREFUSED"), { code: "ECONNREFUSED" }) });
|
|
127
|
+
if ("error" in answer)
|
|
128
|
+
throw new TypeError(answer.error);
|
|
129
|
+
const status = answer.status ?? 200;
|
|
130
|
+
const body = "base64" in answer ? Buffer.from(answer.base64, "base64") : answer.text;
|
|
131
|
+
return new Response(NULL_BODY.has(status) ? null : body, { status, headers: answer.content_type ? { "content-type": answer.content_type } : {} });
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
98
135
|
/** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
|
|
99
136
|
* the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
|
|
100
137
|
export function fakedPlane(plane) {
|