@parcha/agentrun-serve 0.1.0-beta.54 → 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 +110 -2
- package/README.md +266 -88
- 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 +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +21 -7
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- 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/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/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/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-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 +127 -37
- 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 +5 -3
- 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 +38 -6
- 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 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.js +17 -7
- package/dist/runner/run-child.js +3 -1
- 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 +44 -8
- package/dist/server.js +283 -108
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -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/template-eval.d.ts +49 -4
- package/dist/template-eval.js +168 -45
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- 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 +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- 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/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/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +2 -2
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
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();
|
package/dist/template-import.js
CHANGED
|
@@ -8,7 +8,8 @@ import { packageSha256 } from "./agent-package.js";
|
|
|
8
8
|
import { ApiError, invalid } from "./errors.js";
|
|
9
9
|
import { UPLOAD_PREFIX } from "./store/index.js";
|
|
10
10
|
import { fetchPackageFiles, ImportRefused, IMPORT_LIMITS, parseSource, resolveSha } from "./template-source.js";
|
|
11
|
-
import {
|
|
11
|
+
import { manifestOf } from "./manifest.js";
|
|
12
|
+
import { MANIFEST, memoryFiles, PackageError, readPackage } from "./templates.js";
|
|
12
13
|
import { isObject, unknownFields } from "./validate.js";
|
|
13
14
|
/** The settings key that holds the GitHub accounts this server's owner trusts as publishers, lower-cased. */
|
|
14
15
|
export const TRUSTED_PUBLISHERS = "templates.trusted_publishers";
|
|
@@ -163,7 +164,8 @@ async function uploadTemplate(deps, raw, dryRun) {
|
|
|
163
164
|
let files;
|
|
164
165
|
try {
|
|
165
166
|
files = uploadFiles(raw);
|
|
166
|
-
const
|
|
167
|
+
const name = manifestOf(files.get(MANIFEST)?.toString("utf8") ?? "")?.name;
|
|
168
|
+
const id = `${UPLOAD_PREFIX}${typeof name === "string" ? name : ""}`;
|
|
167
169
|
pkg = importedPackage(id, { source: id, sha: uploadSha(files), publisher: "" }, files);
|
|
168
170
|
}
|
|
169
171
|
catch (error) {
|
package/dist/templates.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export declare const INPUT_TYPES: readonly ["string", "number", "integer", "bool
|
|
|
32
32
|
* formats it knows. cron and timezone are for the form alone (a schedule picker, a zone choice); where a parameter fills
|
|
33
33
|
* a schedule, the schedule's own check reads the value at apply. */
|
|
34
34
|
export declare const INPUT_FORMATS: readonly ["uri", "email", "hostname", "date", "date-time", "uuid", "cron", "timezone"];
|
|
35
|
+
/** An input's or a parameter's keys: what a form and a JSON Schema say of one field, in the order an export writes them
|
|
36
|
+
* (agent-package.ts). */
|
|
37
|
+
export declare const INPUT_KEYS: readonly ["type", "title", "description", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum", "examples", "default", "required", "items"];
|
|
38
|
+
/** A list input's `items`: a scalar's keys alone. */
|
|
39
|
+
export declare const ITEM_KEYS: readonly ["type", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum"];
|
|
35
40
|
/** The keys a package may need: those Settings saves (a tool's or a model provider's), each one a run is handed. */
|
|
36
41
|
export declare const PACKAGE_SECRETS: readonly string[];
|
|
37
42
|
/** A package's bounds: each file, all its files together (POST /agents' own body limit), and how many it holds. */
|
|
@@ -41,9 +46,6 @@ export declare const MAX_PACKAGE_FILES = 256;
|
|
|
41
46
|
/** A file of a package's evals/ (a case's fake MCP server fixture, say), which no agent is given: its own bound, apart
|
|
42
47
|
* from the agent's files' limits above. The answer's schema is given to the agent, so under evals/ too it keeps those. */
|
|
43
48
|
export declare const MAX_EVAL_FILE_BYTES: number;
|
|
44
|
-
/** The `name` agent.md's front matter gives (`text`), as text, or undefined: what an upload's folder is named before
|
|
45
|
-
* readPackage checks it whole (the name read as readPackage's front matter reads it). */
|
|
46
|
-
export declare function manifestName(text: string): string | undefined;
|
|
47
49
|
/** An MCP server a package uses, by where it comes from (`source`, `toolkit`), never by the name an owner saves it under:
|
|
48
50
|
* inside the package its tools are `mcp:<toolkit>/<tool>`. `tools`, those the agent uses and the package asks the owner to
|
|
49
51
|
* grant (a consent screen shows each, with `reason`), and `allow`, those of them expected to run without asking (reads);
|
package/dist/templates.js
CHANGED
|
@@ -9,6 +9,7 @@ import { basename, join } from "node:path";
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { parseDocument } from "yaml";
|
|
11
11
|
import { invalid } from "./errors.js";
|
|
12
|
+
import { frontMatter } from "./manifest.js";
|
|
12
13
|
import { DOCKER_IMAGE_FIX, needsIssues } from "./computer-needs.js";
|
|
13
14
|
// Where a package's MCP tools come from (a Composio toolkit, GitHub's MCP server, or any other server by its address): a
|
|
14
15
|
// saved MCP server records one too, and apply maps each need to a server whose record matches.
|
|
@@ -55,10 +56,11 @@ export const INPUT_TYPES = [...SCALAR_TYPES, "array"];
|
|
|
55
56
|
* formats it knows. cron and timezone are for the form alone (a schedule picker, a zone choice); where a parameter fills
|
|
56
57
|
* a schedule, the schedule's own check reads the value at apply. */
|
|
57
58
|
export const INPUT_FORMATS = ["uri", "email", "hostname", "date", "date-time", "uuid", "cron", "timezone"];
|
|
58
|
-
/** An input's or a parameter's keys: what a form and a JSON Schema say of one field
|
|
59
|
-
|
|
59
|
+
/** An input's or a parameter's keys: what a form and a JSON Schema say of one field, in the order an export writes them
|
|
60
|
+
* (agent-package.ts). */
|
|
61
|
+
export const INPUT_KEYS = ["type", "title", "description", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum", "examples", "default", "required", "items"];
|
|
60
62
|
/** A list input's `items`: a scalar's keys alone. */
|
|
61
|
-
const ITEM_KEYS = ["type", "pattern", "
|
|
63
|
+
export const ITEM_KEYS = ["type", "pattern", "format", "minLength", "maxLength", "minimum", "maximum", "enum"];
|
|
62
64
|
const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
63
65
|
const PARAMETER = /^[a-z][a-z0-9_]{0,63}$/;
|
|
64
66
|
/** The keys a package may need: those Settings saves (a tool's or a model provider's), each one a run is handed. */
|
|
@@ -85,24 +87,6 @@ const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[
|
|
|
85
87
|
const PLACEHOLDER = /\$\{parameters\.([^}]*)\}/g;
|
|
86
88
|
/** Text that is one placeholder alone: it takes the parameter's value with its type (a pin's, a trigger's input's). */
|
|
87
89
|
const WHOLE = /^\$\{parameters\.([^}]*)\}$/;
|
|
88
|
-
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
89
|
-
/** The `name` agent.md's front matter gives (`text`), as text, or undefined: what an upload's folder is named before
|
|
90
|
-
* readPackage checks it whole (the name read as readPackage's front matter reads it). */
|
|
91
|
-
export function manifestName(text) {
|
|
92
|
-
const match = FRONT.exec(text);
|
|
93
|
-
if (!match)
|
|
94
|
-
return undefined;
|
|
95
|
-
const doc = parseDocument(match[1], { schema: "core", merge: false, uniqueKeys: true, strict: true });
|
|
96
|
-
if (doc.errors.length)
|
|
97
|
-
return undefined;
|
|
98
|
-
try {
|
|
99
|
-
const data = doc.toJS({ maxAliasCount: 0 });
|
|
100
|
-
return isObject(data) && typeof data.name === "string" ? data.name : undefined;
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
90
|
/** A package's model choices at most, a choice label's length, and a warning's or a note's. */
|
|
107
91
|
const MAX_CHOICES = 3;
|
|
108
92
|
const MAX_CHOICE_LABEL = 40;
|
|
@@ -531,9 +515,12 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
531
515
|
const dir = src.where;
|
|
532
516
|
const problems = [];
|
|
533
517
|
const bad = (where, message) => void problems.push(`${where}: ${message}`);
|
|
518
|
+
/** The entries of the folder at `sub`, every read of a folder's entries here: a hidden file or folder (.env,
|
|
519
|
+
* .DS_Store, .cache/) is no part of a package, at its top or anywhere under it, so it is left out, never refused. */
|
|
520
|
+
const entries = (sub) => src.entries(sub).filter((entry) => !entry.name.startsWith("."));
|
|
534
521
|
/** The regular files under `sub`, by path from it with forward slashes; a link or any other kind of entry is a
|
|
535
522
|
* problem (a package is read from disk, and a link would carry a file from outside it into an agent). */
|
|
536
|
-
const files = (sub) =>
|
|
523
|
+
const files = (sub) => entries(sub).sort((a, b) => (a.name < b.name ? -1 : 1)).flatMap((entry) => {
|
|
537
524
|
const path = sub ? `${sub}/${entry.name}` : entry.name;
|
|
538
525
|
if (entry.isDirectory())
|
|
539
526
|
return files(path);
|
|
@@ -546,25 +533,17 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
546
533
|
/** A file's YAML front matter and body. */
|
|
547
534
|
const front = (path, required = true) => {
|
|
548
535
|
const content = text(path);
|
|
549
|
-
const
|
|
550
|
-
if (!
|
|
536
|
+
const read = frontMatter(content);
|
|
537
|
+
if (!read) {
|
|
551
538
|
if (required)
|
|
552
539
|
bad(path, "has no YAML front matter between --- lines");
|
|
553
540
|
return required ? undefined : { data: {}, body: content };
|
|
554
541
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
let data;
|
|
559
|
-
try {
|
|
560
|
-
data = doc.toJS({ maxAliasCount: 0 });
|
|
561
|
-
}
|
|
562
|
-
catch (error) {
|
|
563
|
-
return bad(path, `its front matter is refused: ${error.message}`), undefined;
|
|
564
|
-
}
|
|
565
|
-
if (!isObject(data))
|
|
542
|
+
if ("problem" in read)
|
|
543
|
+
return bad(path, `its front matter ${read.problem}`), undefined;
|
|
544
|
+
if (!isObject(read.data))
|
|
566
545
|
return bad(path, "its front matter is not a mapping"), undefined;
|
|
567
|
-
return { data, body:
|
|
546
|
+
return { data: read.data, body: read.body };
|
|
568
547
|
};
|
|
569
548
|
const list = (value, field, test = (item) => item !== "") => {
|
|
570
549
|
if (value === undefined)
|
|
@@ -582,7 +561,7 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
582
561
|
throw new PackageError(dir, ["it is not a folder: a package is one"]);
|
|
583
562
|
if (kind(MANIFEST) !== "file")
|
|
584
563
|
throw new PackageError(dir, [`${MANIFEST}: missing: a package is a folder with agent.md (its manifest in the front matter, the agent's instructions in the body)`]);
|
|
585
|
-
for (const entry of
|
|
564
|
+
for (const entry of entries("")) {
|
|
586
565
|
if (entry.isDirectory() && !["skills", "rules", "evals"].includes(entry.name))
|
|
587
566
|
bad(`${entry.name}/`, "a package's folders are skills/, rules/ and evals/");
|
|
588
567
|
}
|
|
@@ -883,7 +862,7 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
883
862
|
});
|
|
884
863
|
// skills/<name>/SKILL.md, each named as its folder and described, as Agent Skills are; rules/*.md beside each.
|
|
885
864
|
const skills = {};
|
|
886
|
-
const skillDirs = kind("skills") === "dir" ?
|
|
865
|
+
const skillDirs = kind("skills") === "dir" ? entries("skills") : [];
|
|
887
866
|
for (const entry of skillDirs) {
|
|
888
867
|
if (!entry.isDirectory() || !NAME.test(entry.name)) {
|
|
889
868
|
bad(`skills/${entry.name}`, "skills/ holds only skill folders, each named in lowercase letters, digits and dashes");
|
|
@@ -900,7 +879,7 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
900
879
|
for (const path of own)
|
|
901
880
|
skills[`${entry.name}/${path}`] = text(`skills/${entry.name}/${path}`);
|
|
902
881
|
}
|
|
903
|
-
const rules = kind("rules") === "dir" ?
|
|
882
|
+
const rules = kind("rules") === "dir" ? entries("rules") : [];
|
|
904
883
|
if (rules.length && !skillDirs.length)
|
|
905
884
|
bad("rules/", "rules ship beside each skill's SKILL.md, and the package has no skill");
|
|
906
885
|
const ruleNames = [];
|
|
@@ -924,7 +903,7 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
924
903
|
// evals/<case>/: prompt.md (the run's input), graders/*.md (each its type in its front matter), case.yaml and
|
|
925
904
|
// fixtures/ if it has them. The layout only: no eval runs here.
|
|
926
905
|
const evals = [];
|
|
927
|
-
for (const entry of kind("evals") === "dir" ?
|
|
906
|
+
for (const entry of kind("evals") === "dir" ? entries("evals") : []) {
|
|
928
907
|
const at = `evals/${entry.name}`;
|
|
929
908
|
if (!entry.isDirectory() || !NAME.test(entry.name)) {
|
|
930
909
|
bad(at, "evals/ holds only case folders, each named in lowercase letters, digits and dashes");
|
|
@@ -59,7 +59,7 @@ export declare const callFailed: (tool: string, result: {
|
|
|
59
59
|
export declare function registerTurnEnding(tool: string): void;
|
|
60
60
|
/** Whether `tool` ends its turn (registerTurnEnding). */
|
|
61
61
|
export declare const endsTurn: (tool: string) => boolean;
|
|
62
|
-
/** The label of a call; `result` is given once the call has finished. Unknown tools get
|
|
62
|
+
/** The label of a call; `result` is given once the call has finished. Unknown tools get the default fallback. */
|
|
63
63
|
export declare function labelOf(tool: string, args: Obj, result?: ToolResultView, extra?: Record<string, LabelFn>): string;
|
|
64
64
|
/** One line for several calls of one tool: `Read 4 pages: a.example, b.example, +2 more`. */
|
|
65
65
|
export declare function foldLabel(tool: string, calls: readonly {
|
|
@@ -68,7 +68,7 @@ export declare function foldLabel(tool: string, calls: readonly {
|
|
|
68
68
|
}[], options?: {
|
|
69
69
|
path?: (path: string) => string;
|
|
70
70
|
}): string;
|
|
71
|
-
/** The input worth showing:
|
|
71
|
+
/** The input worth showing: the base keys first, then the browser and file ones, and last the app a computer's look or act
|
|
72
72
|
* names (never what an act types: its steps; nor a codemode script, which can hold it). */
|
|
73
73
|
export declare function inputPreview(args: Obj, max: number): string | null;
|
|
74
74
|
/** Files a finished call put in the workspace. */
|
package/dist/timeline/labels.js
CHANGED
|
@@ -51,7 +51,7 @@ export function registerTurnEnding(tool) {
|
|
|
51
51
|
}
|
|
52
52
|
/** Whether `tool` ends its turn (registerTurnEnding). */
|
|
53
53
|
export const endsTurn = (tool) => turnEnding.has(tool);
|
|
54
|
-
/** The label of a call; `result` is given once the call has finished. Unknown tools get
|
|
54
|
+
/** The label of a call; `result` is given once the call has finished. Unknown tools get the default fallback. */
|
|
55
55
|
export function labelOf(tool, args, result, extra) {
|
|
56
56
|
const own = extra && Object.hasOwn(extra, tool) ? extra[tool] : undefined;
|
|
57
57
|
return (own ?? labels.get(tool))?.(args, result) ?? mcpLabel(tool) ?? `Using tool: ${tool}`;
|
|
@@ -65,7 +65,7 @@ export function foldLabel(tool, calls, options = {}) {
|
|
|
65
65
|
const subjects = calls.flatMap((call) => spec?.subject?.(named(call.input), call.output) ?? []);
|
|
66
66
|
return subjects.length ? `${head}: ${list(subjects)}` : head;
|
|
67
67
|
}
|
|
68
|
-
/** The input worth showing:
|
|
68
|
+
/** The input worth showing: the base keys first, then the browser and file ones, and last the app a computer's look or act
|
|
69
69
|
* names (never what an act types: its steps; nor a codemode script, which can hold it). */
|
|
70
70
|
export function inputPreview(args, max) {
|
|
71
71
|
for (const key of ["description", "command", "query", "file_path", "url", "path", "code", "app"]) {
|
|
@@ -9,7 +9,7 @@ export type TimelineKind = "thinking" | "text_block" | "tool_use" | "tool_result
|
|
|
9
9
|
| "learning"
|
|
10
10
|
/** A tool call that waited for a person's approval, after its result's row (serve's tool gate). */
|
|
11
11
|
| "tool_approval_requested";
|
|
12
|
-
/**
|
|
12
|
+
/** The public `TimelineEvent` (its 13 base fields) plus the open additions, all optional. */
|
|
13
13
|
export type TimelineEvent = {
|
|
14
14
|
id: string;
|
|
15
15
|
timestamp: string;
|
|
@@ -118,7 +118,7 @@ export type AgentEventLike = {
|
|
|
118
118
|
type: string;
|
|
119
119
|
[key: string]: unknown;
|
|
120
120
|
};
|
|
121
|
-
/**
|
|
121
|
+
/** The base caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
122
122
|
export declare const CAPS: {
|
|
123
123
|
summary: number;
|
|
124
124
|
preview: number;
|
|
@@ -8,7 +8,7 @@ export const nestingCallOf = (callId) => {
|
|
|
8
8
|
const at = callId.lastIndexOf("/");
|
|
9
9
|
return at > 0 ? callId.slice(0, at) : undefined;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
11
|
+
/** The base caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
12
12
|
export const CAPS = { summary: 500, preview: 500, text: 2000, thinking: 100 };
|
|
13
13
|
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a tool's output's head, still one
|
|
14
14
|
* redaction pass of the size an answer's pieces take (key-refusal.ts ANSWER_PIECE). A web call's is not its head: a
|