@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.54
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 +149 -1
- package/README.md +295 -37
- package/dist/agent-delete.d.ts +5 -6
- package/dist/agent-delete.js +30 -67
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +26 -20
- package/dist/agents-store.js +42 -34
- package/dist/api-only.d.ts +25 -6
- package/dist/api-only.js +34 -13
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +76 -8
- package/dist/composio-preset.d.ts +3 -1
- package/dist/composio-preset.js +5 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +5 -2
- package/dist/computer-setting.js +8 -1
- package/dist/computers.d.ts +0 -2
- package/dist/computers.js +1 -1
- package/dist/console/assets/index-B_85An2t.js +745 -0
- package/dist/console/assets/index-n1YsbnYh.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +10 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.js +10 -13
- package/dist/github-connection.d.ts +50 -1
- package/dist/github-connection.js +96 -3
- package/dist/github-faux.d.ts +11 -2
- package/dist/github-faux.js +138 -7
- package/dist/github-pull-request.d.ts +37 -0
- package/dist/github-pull-request.js +110 -0
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +14 -1
- package/dist/learn/commit.js +156 -1
- package/dist/learn/compile.js +22 -8
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +10 -1
- package/dist/learn/learning.sh +15 -3
- package/dist/learn/promote.d.ts +2 -2
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning.d.ts +9 -6
- package/dist/learning.js +9 -4
- package/dist/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/mcp-gateway.js +15 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +8 -3
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +16 -12
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +275 -40
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +16 -1
- package/dist/run-launch.js +30 -1
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-view.d.ts +17 -0
- package/dist/run-view.js +25 -1
- package/dist/runner/adapter-loop.d.ts +11 -3
- package/dist/runner/adapter-loop.js +138 -22
- package/dist/runner/adapter-run-spec.js +26 -13
- package/dist/runner/audit.d.ts +2 -0
- package/dist/runner/audit.js +9 -1
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +29 -3
- package/dist/runner/claim-secrets.js +38 -4
- package/dist/runner/cli-run-spec.js +24 -13
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +11 -1
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +2 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +7 -2
- package/dist/runner/learning-end.js +22 -10
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-run.d.ts +10 -7
- package/dist/runner/mcp-run.js +3 -5
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +15 -3
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +14 -6
- package/dist/runner/promotion.js +98 -41
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +178 -45
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +28 -2
- package/dist/runner/runner.js +26 -9
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.d.ts +34 -6
- package/dist/runs-over-store.js +133 -25
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +117 -26
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +79 -32
- package/dist/server.js +673 -113
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +6 -2
- package/dist/store/agent-body.js +18 -7
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +2 -1
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +4 -12
- package/dist/store/sqlite/run-launch.js +5 -19
- package/dist/store/sqlite/store.js +224 -170
- package/dist/store/store.d.ts +116 -39
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +2 -2
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/suggestions.d.ts +282 -0
- package/dist/suggestions.js +919 -0
- package/dist/telemetry.d.ts +8 -1
- package/dist/telemetry.js +12 -4
- package/dist/template-import.d.ts +27 -2
- package/dist/template-import.js +148 -13
- package/dist/templates.d.ts +103 -77
- package/dist/templates.js +71 -17
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/trigger-launch-hook.d.ts +49 -0
- package/dist/trigger-launch-hook.js +91 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +1 -1
- package/dist/uploads.js +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +3 -4
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/dist/workspace/synced-folder.d.ts +1 -1
- package/dist/workspace/synced-folder.js +11 -14
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +8 -4
- package/templates/agent-scout/agent.md +46 -0
- package/templates/agent-scout/skills/scout/SKILL.md +88 -0
- package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
- package/dist/console/assets/index-B-D0EM3j.js +0 -733
- package/dist/console/assets/index-DlQepP2J.css +0 -1
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 { DOCKER_IMAGE_FIX, needsIssues } from "./computer-needs.js";
|
|
12
13
|
// Where a package's MCP tools come from (a Composio toolkit, GitHub's MCP server, or any other server by its address): a
|
|
13
14
|
// saved MCP server records one too, and apply maps each need to a server whose record matches.
|
|
14
15
|
import { MCP_SOURCES } from "./mcp-sources.js";
|
|
@@ -41,7 +42,7 @@ export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbo
|
|
|
41
42
|
/** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
|
|
42
43
|
* `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
|
|
43
44
|
export const COMPUTER_ENTRIES = ["shell", "none"];
|
|
44
|
-
const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "category", "tags", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "checkout", "parameters", "inputs", "secrets", "budget", "learning", "approvals", "triggers", "output"];
|
|
45
|
+
const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "category", "tags", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "needs", "checkout", "parameters", "inputs", "secrets", "budget", "learning", "approvals", "triggers", "output"];
|
|
45
46
|
/** What a package is for, shown on a marketplace page and the console's list: display only, never applied. */
|
|
46
47
|
export const CATEGORIES = ["engineering", "security", "sales", "marketing", "research", "finance", "operations", "compliance", "personal"];
|
|
47
48
|
const TAG = /^[a-z0-9-]{1,32}$/;
|
|
@@ -85,6 +86,23 @@ const PLACEHOLDER = /\$\{parameters\.([^}]*)\}/g;
|
|
|
85
86
|
/** Text that is one placeholder alone: it takes the parameter's value with its type (a pin's, a trigger's input's). */
|
|
86
87
|
const WHOLE = /^\$\{parameters\.([^}]*)\}$/;
|
|
87
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
|
+
}
|
|
88
106
|
/** A package's model choices at most, a choice label's length, and a warning's or a note's. */
|
|
89
107
|
const MAX_CHOICES = 3;
|
|
90
108
|
const MAX_CHOICE_LABEL = 40;
|
|
@@ -681,9 +699,22 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
681
699
|
bad(MANIFEST, `computer: [none] gives no shell, so ${shellOnly.join(", ")} would never be granted: add shell to computer, or take ${shellOnly.length === 1 ? "it" : "them"} out of tools`);
|
|
682
700
|
}
|
|
683
701
|
}
|
|
702
|
+
// The programs its sandbox must have, checked as a sandbox's computer.needs is: only beside [shell] alone, so a package
|
|
703
|
+
// that needs them is a sandbox's or nothing, never a fallback to no computer.
|
|
704
|
+
let needs;
|
|
705
|
+
if (f.needs !== undefined) {
|
|
706
|
+
const issues = needsIssues(f.needs, "needs");
|
|
707
|
+
for (const issue of issues)
|
|
708
|
+
bad(MANIFEST, issue.message);
|
|
709
|
+
if (computer?.length !== 1 || computer[0] !== "shell")
|
|
710
|
+
bad(MANIFEST, "needs: the programs a sandbox must have, so computer is [shell]: a template that needs them never falls back to no computer, nor runs where a new agent does");
|
|
711
|
+
else if (!issues.length)
|
|
712
|
+
needs = [...f.needs];
|
|
713
|
+
}
|
|
684
714
|
// The server's checkout before each run's first turn: the pull request the run's GitHub event names, at its head.
|
|
685
|
-
|
|
686
|
-
|
|
715
|
+
// Or the head of the default branch of the repository the run names.
|
|
716
|
+
if (f.checkout !== undefined && f.checkout !== "pull_request" && f.checkout !== "repository")
|
|
717
|
+
bad(MANIFEST, "checkout is pull_request or repository: the server checks out, in repo/ before the first turn, the pull request the run's GitHub event names (at its head), or the head of the default branch of the repository the run names");
|
|
687
718
|
// The setup an apply takes, in the inputs' grammar, by the same compiler; none, a schema of no fields.
|
|
688
719
|
const parameters = fieldsSchema(f.parameters, "parameters", (message) => bad(MANIFEST, message)) ?? { type: "object", additionalProperties: false, properties: {} };
|
|
689
720
|
const fields = fieldsOf(parameters);
|
|
@@ -872,11 +903,13 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
872
903
|
const rules = kind("rules") === "dir" ? src.entries("rules") : [];
|
|
873
904
|
if (rules.length && !skillDirs.length)
|
|
874
905
|
bad("rules/", "rules ship beside each skill's SKILL.md, and the package has no skill");
|
|
906
|
+
const ruleNames = [];
|
|
875
907
|
for (const entry of rules) {
|
|
876
908
|
if (!entry.isFile() || !entry.name.endsWith(".md")) {
|
|
877
909
|
bad(`rules/${entry.name}`, "rules/ holds only .md files");
|
|
878
910
|
continue;
|
|
879
911
|
}
|
|
912
|
+
ruleNames.push(entry.name);
|
|
880
913
|
for (const skill of skillDirs.filter((d) => d.isDirectory())) {
|
|
881
914
|
const path = `${skill.name}/${entry.name}`;
|
|
882
915
|
if (Object.hasOwn(skills, path))
|
|
@@ -942,8 +975,8 @@ export function readPackage(from, { evalFixtures = true } = {}) {
|
|
|
942
975
|
...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
|
|
943
976
|
...(typeof f.category === "string" ? { category: f.category } : {}), tags,
|
|
944
977
|
...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: { ...f.model, ...(choices ? { choices } : {}) } } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
|
|
945
|
-
...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout:
|
|
946
|
-
triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, evals,
|
|
978
|
+
...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(needs ? { needs } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" || f.checkout === "repository" ? { checkout: f.checkout } : {}), parameters, ...(inputSchema ? { inputSchema } : {}), secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd, ...(f.budget.max_requests !== undefined ? { max_requests: f.budget.max_requests } : {}) } } : {}), ...(f.learning !== undefined ? { learning: learningSettingOf(f.learning) } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
|
|
979
|
+
triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, ...(ruleNames.length ? { rules: ruleNames.sort() } : {}), evals,
|
|
947
980
|
};
|
|
948
981
|
// What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
|
|
949
982
|
// /v2/agents and POST /v2/triggers check their bodies (all but the agent the trigger names, which an apply makes). A
|
|
@@ -1016,11 +1049,12 @@ export function readPackages(dir = TEMPLATES_DIR) {
|
|
|
1016
1049
|
/** A package as GET /v2/templates lists it: what an apply asks for and makes. */
|
|
1017
1050
|
export function packageView(p) {
|
|
1018
1051
|
return {
|
|
1019
|
-
|
|
1052
|
+
// An upload has no publisher: its own owner sent it.
|
|
1053
|
+
id: p.id, bundled: p.origin === null, source: p.origin?.source ?? null, sha: p.origin?.sha ?? null, publisher: p.origin?.publisher || null,
|
|
1020
1054
|
name: p.name, display_name: p.displayName ?? null, version: p.version, description: p.description, license: p.license ?? null, author: p.author ?? null, repository: p.repository ?? null,
|
|
1021
1055
|
category: p.category ?? null, tags: p.tags,
|
|
1022
1056
|
output: p.output ? { schema: p.output.schema, json_schema: p.outputSchema ?? null } : null,
|
|
1023
|
-
harness: p.harness ?? null, model: modelView(p.model), effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null, computer: p.computer ?? null, checkout: p.checkout ?? null,
|
|
1057
|
+
harness: p.harness ?? null, model: modelView(p.model), effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null, computer: p.computer ?? null, needs: p.needs ?? null, checkout: p.checkout ?? null,
|
|
1024
1058
|
mcp: p.mcp.map(({ source, toolkit, tools, required, reason, allow, pin }) => ({ source, toolkit, required, reason: reason ?? null, tools: tools.map((name) => ({ name, tool: mcpToolName(toolkit, name), asks: allow.includes(name) ? "allow" : "ask", ...(Object.hasOwn(pin, name) ? { pin: pin[name] } : {}) })) })), parameters: p.parameters, input_schema: p.inputSchema ?? null, secrets: p.secrets,
|
|
1025
1059
|
budget: p.budget ?? null, learning: p.learning ?? false, approvals_default: p.approvals ?? "ask", triggers: p.triggers, skills: Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length)), evals: p.evals,
|
|
1026
1060
|
};
|
|
@@ -1032,11 +1066,12 @@ function modelView(model) {
|
|
|
1032
1066
|
const { choices, ...rest } = model;
|
|
1033
1067
|
return { ...rest, ...(choices ? { choices: choices.map(({ id, label, model: ref, harness, warning, note, secrets }) => ({ id, label, model: ref, harness, warning: warning ?? null, note: note ?? null, secrets })) } : {}) };
|
|
1034
1068
|
}
|
|
1035
|
-
/** A package as an import
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
|
|
1039
|
-
|
|
1069
|
+
/** A package whole, as an import and a read of one answer it: its listing with the computer it would get here
|
|
1070
|
+
* (`computerHere`), and every text its agent would be given, the instructions and each skill file by path (a rule and
|
|
1071
|
+
* the answer's schema beside each SKILL.md among them), so a person reads what a package would tell their agent before
|
|
1072
|
+
* it is applied. */
|
|
1073
|
+
export function packageDetail(p, computerHere) {
|
|
1074
|
+
return { template: { ...packageView(p), computer_here: computerHere(p) }, instructions: p.instructions, skill_files: { ...p.skills } };
|
|
1040
1075
|
}
|
|
1041
1076
|
/** The packages this server serves: the ones it ships, read at its start, and the ones imported here (the store keeps
|
|
1042
1077
|
* them; the server loads them beside the bundled ones at its start). An id is one package; a bundled one is never
|
|
@@ -1065,15 +1100,25 @@ export class TemplateRegistry {
|
|
|
1065
1100
|
return this.imported.delete(id);
|
|
1066
1101
|
}
|
|
1067
1102
|
}
|
|
1068
|
-
/** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?}`), checked
|
|
1103
|
+
/** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?, revision?, sha?, dry_run?}`), checked
|
|
1069
1104
|
* against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
|
|
1070
1105
|
* package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
|
|
1071
|
-
* of the package's model choices by id (`choice`), never both.
|
|
1106
|
+
* of the package's model choices by id (`choice`), never both. `revision` (with agent_id) and `sha` are what the caller
|
|
1107
|
+
* read: the agent's current revision and the package's sha, each held to them (412 when another). 422 naming every field
|
|
1108
|
+
* that is wrong. */
|
|
1072
1109
|
export function applyBodyOf(p, body) {
|
|
1073
|
-
const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides", "agent_id"]);
|
|
1110
|
+
const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides", "agent_id", "revision", "sha", "dry_run"]);
|
|
1111
|
+
if (body.dry_run !== undefined && typeof body.dry_run !== "boolean")
|
|
1112
|
+
issues.push({ field: "dry_run", reason: "wrong_type", message: "dry_run is true or false: true answers the apply's plan and writes nothing" });
|
|
1074
1113
|
// The agent an update writes onto (the server checks it was made from this package): text, else a 422 with the rest.
|
|
1075
1114
|
if (body.agent_id !== undefined && !(typeof body.agent_id === "string" && body.agent_id.trim()))
|
|
1076
1115
|
issues.push({ field: "agent_id", reason: "wrong_type", message: `agent_id is the id of an agent the ${p.name} template made: the apply writes a new revision of it in place of making another` });
|
|
1116
|
+
if (body.revision !== undefined && !(typeof body.revision === "string" && body.revision))
|
|
1117
|
+
issues.push({ field: "revision", reason: "wrong_type", message: "revision is the id of the agent's revision you read (GET /agents/{agent_id} `revision`): the apply writes only while it is still the current one" });
|
|
1118
|
+
else if (body.revision !== undefined && body.agent_id === undefined)
|
|
1119
|
+
issues.push({ field: "revision", reason: "not_allowed", message: "revision is the agent's current revision as you read it, so it goes with agent_id: an apply without one makes a new agent" });
|
|
1120
|
+
if (body.sha !== undefined && !(typeof body.sha === "string" && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(body.sha)))
|
|
1121
|
+
issues.push({ field: "sha", reason: "bad_format", message: "sha is the package's sha as you read it (GET /templates `sha`): a commit's 40 hex characters, or an upload's 64" });
|
|
1077
1122
|
const listed = p.mcp.flatMap(({ toolkit, tools }) => tools.map((tool) => mcpToolName(toolkit, tool)));
|
|
1078
1123
|
const grants = [];
|
|
1079
1124
|
if (body.grants !== undefined && !Array.isArray(body.grants))
|
|
@@ -1129,7 +1174,7 @@ export function applyBodyOf(p, body) {
|
|
|
1129
1174
|
}
|
|
1130
1175
|
if (issues.length)
|
|
1131
1176
|
throw invalid(issues);
|
|
1132
|
-
return { parameters, grants, servers, ...(typeof body.agent_id === "string" ? { agentId: body.agent_id.trim() } : {}), ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
|
|
1177
|
+
return { parameters, grants, servers, dryRun: body.dry_run === true, ...(typeof body.agent_id === "string" ? { agentId: body.agent_id.trim() } : {}), ...(typeof body.revision === "string" ? { revision: body.revision } : {}), ...(typeof body.sha === "string" ? { sha: body.sha } : {}), ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
|
|
1133
1178
|
}
|
|
1134
1179
|
/** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
|
|
1135
1180
|
* with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its
|
|
@@ -1211,6 +1256,8 @@ export async function choiceUnrunnable(env, choice, offer) {
|
|
|
1211
1256
|
}
|
|
1212
1257
|
/** What to do where a package's computer list has no shell to take: in the apply's refusal and its fallback warning. */
|
|
1213
1258
|
export const COMPUTER_FIX = "Turn on Archil in Settings → Workspace, or run AgentRun where Docker answers, then apply again to give it a shell.";
|
|
1259
|
+
/** What to do where a package that needs programs (`needs`) has no sandbox to take: a Docker box whose image has them. */
|
|
1260
|
+
export const NEEDS_FIX = `Run AgentRun where Docker answers, with Archil off in Settings → Workspace. ${DOCKER_IMAGE_FIX} Then apply again.`;
|
|
1214
1261
|
/** The first entry of a package's computer list (`[shell, none]`) this server meets now, given the shell it has
|
|
1215
1262
|
* (`here`): shell, where it has one; none, always (kind none, and no shell tool: a run on the runner in Mode 2 has bash,
|
|
1216
1263
|
* so a shell tool is dropped rather than left to it). Undefined for a package with no list (it runs where a new agent
|
|
@@ -1226,6 +1273,13 @@ export function pickComputer(p, here) {
|
|
|
1226
1273
|
const clash = found && found.computer.kind === "sandbox" && runnerOnly.length ? `${found.words} runs ${runnerOnly.join(", ")} nowhere` : undefined;
|
|
1227
1274
|
const shell = clash ? undefined : found;
|
|
1228
1275
|
const lack = "none" in here ? here.none : clash ?? "this server has none";
|
|
1276
|
+
// A package that needs programs (its list is [shell] alone) takes a sandbox, whose box each run checks for them: a
|
|
1277
|
+
// shell that is no sandbox (Archil's serverless exec runs on the runner, whose programs no run checks) is refused.
|
|
1278
|
+
if (p.needs && !(shell && shell.computer.kind === "sandbox")) {
|
|
1279
|
+
const why = shell ? `the shell here is ${shell.words}, which is no sandbox` : lack;
|
|
1280
|
+
const list = new Intl.ListFormat("en", { type: "conjunction" }).format(p.needs);
|
|
1281
|
+
return { refused: `The ${p.name} template needs a sandbox that has ${list}, and ${why}. Nothing was created. ${NEEDS_FIX}`, fix: NEEDS_FIX };
|
|
1282
|
+
}
|
|
1229
1283
|
const entry = p.computer.find((one) => one === "none" || shell);
|
|
1230
1284
|
if (!entry)
|
|
1231
1285
|
return { refused: `The ${p.name} template needs a shell, and ${lack}. Nothing was created.` };
|
|
@@ -1236,7 +1290,7 @@ export function pickComputer(p, here) {
|
|
|
1236
1290
|
? `${lack.charAt(0).toUpperCase()}${lack.slice(1)}, so the agent was made with the template's next choice, no computer${dropped.length ? `, and without ${without}` : ""}. ${COMPUTER_FIX}`
|
|
1237
1291
|
: dropped.length && shell ? `The shell here is ${shell.words}, which runs ${runs.join(", ")} alone, so the agent was made without ${without}.` : null;
|
|
1238
1292
|
return entry === "shell" && shell
|
|
1239
|
-
? { entry, computer: { ...shell.computer }, shell: shell.words, dropped, defaults: [...shell.tools], note }
|
|
1293
|
+
? { entry, computer: { ...shell.computer, ...(p.needs ? { needs: [...p.needs] } : {}) }, shell: shell.words, dropped, defaults: [...shell.tools], note }
|
|
1240
1294
|
: { entry, computer: { kind: "none" }, shell: null, dropped, defaults: [], note };
|
|
1241
1295
|
}
|
|
1242
1296
|
/** The model of each tier a package's subagents run on here (the definition's model_tiers), as `{modelTiers?, warning?}`:
|
package/dist/timeline/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
|
|
|
6
6
|
export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES, type MessageOrigin, type TriggerSource } from "./origin.js";
|
|
7
7
|
export { cut, scrubUrl, scrubUrls } from "./util.js";
|
|
8
8
|
export { webCut, webShownOf, webWithin, type WebShown } from "./web-calls.js";
|
|
9
|
-
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
|
|
9
|
+
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
|
package/dist/timeline/index.js
CHANGED
|
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
|
|
|
6
6
|
export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES } from "./origin.js";
|
|
7
7
|
export { cut, scrubUrl, scrubUrls } from "./util.js";
|
|
8
8
|
export { webCut, webShownOf, webWithin } from "./web-calls.js";
|
|
9
|
-
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
|
|
9
|
+
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
|
|
@@ -180,6 +180,11 @@ export declare const chargedTool: (row: TimelineEvent) => string | undefined;
|
|
|
180
180
|
* told after the note's "AgentRun server note:" label). A row of its own, the server's ("AgentRun: …", labelled once);
|
|
181
181
|
* no request, no cost. */
|
|
182
182
|
export declare const CAP_WRAPUP = "agentrun.cap_wrapup";
|
|
183
|
+
/** A tool call the spend cap's wrap-up refused (serve's wrap-up.ts, the runner's gate): `callId` and the cap it was
|
|
184
|
+
* refused under (`capUsd`), on the run's root. The call's own refused row is its result's; this one is data only, for the
|
|
185
|
+
* run's view (`stopped_for`, `budget_refused_calls`): no row, no request, no cost. A call refused twice (a replay) is
|
|
186
|
+
* one call. */
|
|
187
|
+
export declare const CAP_REFUSED = "agentrun.cap_refused";
|
|
183
188
|
/** The run's model was told once, on its first request after its claim gave it a computer in place of an earlier
|
|
184
189
|
* claim's, that the old one is gone with what was on it (`words`, what it was told after the label, as the wrap-up's).
|
|
185
190
|
* A row of its own, the server's, as the wrap-up's; no request, no cost. */
|
|
@@ -101,6 +101,11 @@ export const chargedTool = (row) => !row.usage ? undefined : row.kind === "phase
|
|
|
101
101
|
* told after the note's "AgentRun server note:" label). A row of its own, the server's ("AgentRun: …", labelled once);
|
|
102
102
|
* no request, no cost. */
|
|
103
103
|
export const CAP_WRAPUP = "agentrun.cap_wrapup";
|
|
104
|
+
/** A tool call the spend cap's wrap-up refused (serve's wrap-up.ts, the runner's gate): `callId` and the cap it was
|
|
105
|
+
* refused under (`capUsd`), on the run's root. The call's own refused row is its result's; this one is data only, for the
|
|
106
|
+
* run's view (`stopped_for`, `budget_refused_calls`): no row, no request, no cost. A call refused twice (a replay) is
|
|
107
|
+
* one call. */
|
|
108
|
+
export const CAP_REFUSED = "agentrun.cap_refused";
|
|
104
109
|
/** The run's model was told once, on its first request after its claim gave it a computer in place of an earlier
|
|
105
110
|
* claim's, that the old one is gone with what was on it (`words`, what it was told after the label, as the wrap-up's).
|
|
106
111
|
* A row of its own, the server's, as the wrap-up's; no request, no cost. */
|
|
@@ -788,6 +793,9 @@ function createProjector(options) {
|
|
|
788
793
|
const add = (row) => { rows.push(row); out.push(row); };
|
|
789
794
|
const touch = (row) => { if (!out.includes(row))
|
|
790
795
|
out.push(row); };
|
|
796
|
+
// The wrap-up's refusal of a call, kept for the run's view: its result row is the call's own.
|
|
797
|
+
if (entry.kind === CAP_REFUSED)
|
|
798
|
+
return out;
|
|
791
799
|
if (entry.kind === CAP_WRAPUP || entry.kind === COMPUTER_NOTE) {
|
|
792
800
|
// What the run's model was told near its cap, or after its computer was replaced: the server's row (`origin:
|
|
793
801
|
// "server"`, in the words of its other rows), no request, no cost, and no message any turn took (its id ends in
|
package/dist/tool-plane.d.ts
CHANGED
|
@@ -40,11 +40,11 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
|
|
|
40
40
|
* give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
|
|
41
41
|
* those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
|
|
42
42
|
export declare const serverGate: (name: string, settings: ToolSettingsMap, effect?: ToolEffect) => {
|
|
43
|
-
default_permission: "ask" | "
|
|
44
|
-
permissions: ("ask" | "
|
|
43
|
+
default_permission: "ask" | "deny" | "allow";
|
|
44
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
45
45
|
fallback_allow_reads?: true | undefined;
|
|
46
46
|
allow_reads?: true | undefined;
|
|
47
|
-
permission: "ask" | "
|
|
47
|
+
permission: "ask" | "deny" | "allow";
|
|
48
48
|
};
|
|
49
49
|
/** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
|
|
50
50
|
* workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL), and the host's
|
|
@@ -289,17 +289,17 @@ export declare function shellUnavailable(name: string, shell: ShellPlace): Resol
|
|
|
289
289
|
* computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
|
|
290
290
|
export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[], shell?: ShellPlace, effectOf?: (name: string) => ToolEffect | undefined): ({
|
|
291
291
|
resolved: Resolution;
|
|
292
|
-
permission: "ask" | "
|
|
292
|
+
permission: "ask" | "deny" | "allow";
|
|
293
293
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
294
|
-
default_permission: "ask" | "
|
|
295
|
-
permissions: ("ask" | "
|
|
294
|
+
default_permission: "ask" | "deny" | "allow";
|
|
295
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
296
296
|
blurb?: string | undefined;
|
|
297
297
|
name: string;
|
|
298
298
|
} | {
|
|
299
|
-
permission: "ask" | "
|
|
299
|
+
permission: "ask" | "deny" | "allow";
|
|
300
300
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
301
|
-
default_permission: "ask" | "
|
|
302
|
-
permissions: ("ask" | "
|
|
301
|
+
default_permission: "ask" | "deny" | "allow";
|
|
302
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
303
303
|
blurb?: string | undefined;
|
|
304
304
|
name: string;
|
|
305
305
|
} | {
|
|
@@ -307,10 +307,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
|
|
|
307
307
|
provider_from: string;
|
|
308
308
|
default_provider: string;
|
|
309
309
|
resolved: Resolution;
|
|
310
|
-
permission: "ask" | "
|
|
310
|
+
permission: "ask" | "deny" | "allow";
|
|
311
311
|
permission_from: import("./refusal-words.js").SettingFrom;
|
|
312
|
-
default_permission: "ask" | "
|
|
313
|
-
permissions: ("ask" | "
|
|
312
|
+
default_permission: "ask" | "deny" | "allow";
|
|
313
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
314
314
|
blurb?: string | undefined;
|
|
315
315
|
name: string;
|
|
316
316
|
})[];
|
package/dist/tools.d.ts
CHANGED
|
@@ -341,13 +341,13 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
341
341
|
providers?: string[] | undefined;
|
|
342
342
|
provider?: string | undefined;
|
|
343
343
|
default_provider?: string | undefined;
|
|
344
|
-
resolves?: Record<"opencode" | "codex" | "
|
|
345
|
-
why?: Record<"opencode" | "codex" | "
|
|
346
|
-
default_permission: "ask" | "
|
|
347
|
-
permissions: ("ask" | "
|
|
344
|
+
resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", Resolution> | undefined;
|
|
345
|
+
why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
|
|
346
|
+
default_permission: "ask" | "deny" | "allow";
|
|
347
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
348
348
|
fallback_allow_reads?: true | undefined;
|
|
349
349
|
allow_reads?: true | undefined;
|
|
350
|
-
permission: "ask" | "
|
|
350
|
+
permission: "ask" | "deny" | "allow";
|
|
351
351
|
harnesses: string[];
|
|
352
352
|
missing?: string[] | undefined;
|
|
353
353
|
reason?: string | undefined;
|
|
@@ -360,11 +360,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
360
360
|
name: string;
|
|
361
361
|
summary: string;
|
|
362
362
|
} | {
|
|
363
|
-
default_permission: "ask" | "
|
|
364
|
-
permissions: ("ask" | "
|
|
363
|
+
default_permission: "ask" | "deny" | "allow";
|
|
364
|
+
permissions: ("ask" | "deny" | "allow")[];
|
|
365
365
|
fallback_allow_reads?: true | undefined;
|
|
366
366
|
allow_reads?: true | undefined;
|
|
367
|
-
permission: "ask" | "
|
|
367
|
+
permission: "ask" | "deny" | "allow";
|
|
368
368
|
name: string;
|
|
369
369
|
summary: string;
|
|
370
370
|
blurb: string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Json } from "./validate.js";
|
|
2
|
+
export declare const LAUNCH_HOOK_URL_ENV = "AGENTRUN_LAUNCH_HOOK_URL";
|
|
3
|
+
export declare const LAUNCH_HOOK_SECRET_ENV = "AGENTRUN_LAUNCH_HOOK_SECRET";
|
|
4
|
+
/** How long the host has to answer a firing, its connection included. */
|
|
5
|
+
export declare const LAUNCH_HOOK_TIMEOUT_MS = 10000;
|
|
6
|
+
/** How long after its 2xx a host that answered without starting the firing's run may still start it (one start, under
|
|
7
|
+
* the firing: triggers.ts handedStart). From the answer, not from fired_at: a catch-up, a firing that waited on its
|
|
8
|
+
* trigger's max_active_runs, or one a stop cut short and the next start handed again reaches the host late, and its
|
|
9
|
+
* host gets the same 10 minutes as any. */
|
|
10
|
+
export declare const LAUNCH_HOOK_LATE_START_MS: number;
|
|
11
|
+
/** The hook a server hands its firings to: where, and the secret it signs with. `timeoutMs`: a test's bound, else
|
|
12
|
+
* LAUNCH_HOOK_TIMEOUT_MS. `bound`: a test's seam, the signal for a POST's bound in place of AbortSignal.timeout. */
|
|
13
|
+
export type LaunchHook = {
|
|
14
|
+
readonly url: string;
|
|
15
|
+
readonly secret: string;
|
|
16
|
+
readonly timeoutMs?: number;
|
|
17
|
+
readonly bound?: (ms: number) => AbortSignal;
|
|
18
|
+
};
|
|
19
|
+
/** What the host is sent for a firing: its id (the message's webhook-id too), its trigger, the agent and the revision a
|
|
20
|
+
* run would start on now, the run's input as the trigger gives it, and the firing's time. */
|
|
21
|
+
export type HookFiring = {
|
|
22
|
+
firing_id: string;
|
|
23
|
+
trigger_id: string;
|
|
24
|
+
agent_id: string;
|
|
25
|
+
revision_id: string | null;
|
|
26
|
+
input: Json;
|
|
27
|
+
fired_at: string;
|
|
28
|
+
};
|
|
29
|
+
/** The host's answer: taken (2xx); or why the firing is skipped; or `stopped`, the server's stop cut it short and the
|
|
30
|
+
* firing is left as it was. */
|
|
31
|
+
export type Handed = {
|
|
32
|
+
taken: true;
|
|
33
|
+
} | {
|
|
34
|
+
skipped: string;
|
|
35
|
+
} | {
|
|
36
|
+
stopped: true;
|
|
37
|
+
};
|
|
38
|
+
/** The launch hook `given` sets (the URL from the environment, the secret as the server holds its own), or undefined when
|
|
39
|
+
* neither is set. Throws, in words that never hold the secret, when one is set without the other, the URL is not https
|
|
40
|
+
* (http only to loopback) or holds a user or password, or the secret is not a `whsec_` secret of MIN_KEY_BYTES or more. */
|
|
41
|
+
export declare function launchHookFrom(given: {
|
|
42
|
+
url?: string | undefined;
|
|
43
|
+
secret?: string | undefined;
|
|
44
|
+
}): LaunchHook | undefined;
|
|
45
|
+
/** Where `hook` sends, for the start's banner: its origin alone, never a path or query that may hold a token. */
|
|
46
|
+
export declare const hookOrigin: (hook: LaunchHook) => string;
|
|
47
|
+
/** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
|
|
48
|
+
* cut by `stop`. A redirect is not followed. */
|
|
49
|
+
export declare function handToHost(hook: LaunchHook, firing: HookFiring, stop: AbortSignal, now?: () => number): Promise<Handed>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The launch hook: a server started with AGENTRUN_LAUNCH_HOOK_URL and AGENTRUN_LAUNCH_HOOK_SECRET hands each trigger firing
|
|
2
|
+
// that would start a run to the host behind it instead (triggers.ts drive), and starts no run of its own for it. The host
|
|
3
|
+
// starts the run through the API (POST /v2/agents/{agent_id}/runs with `trigger_firing` and its own model_key, keys and
|
|
4
|
+
// max_cost_usd: the firing's run, under its key, triggers.ts handedStart) and answers 2xx, before or after that start
|
|
5
|
+
// (after: within LAUNCH_HOOK_LATE_START_MS of that 2xx, the firing's start_by); any other answer, or none within
|
|
6
|
+
// LAUNCH_HOOK_TIMEOUT_MS, and the firing is skipped with why, unless the host started its run. Unset, nothing changes.
|
|
7
|
+
// Off this machine the hook is https: a firing's input can carry a person's data, and the signature proves who sent it,
|
|
8
|
+
// not that no one else read it.
|
|
9
|
+
// The POST is signed as the outbound webhook's messages are (standard-webhooks.ts): `webhook-id` (the firing's id, the
|
|
10
|
+
// same each time it is handed), `webhook-timestamp` (Unix seconds) and `webhook-signature: v1,<base64 HMAC-SHA256 of
|
|
11
|
+
// "{id}.{timestamp}.{body}">` under the secret's key, so a host checks it with any Standard Webhooks library.
|
|
12
|
+
import { fetch as undiciFetch } from "undici";
|
|
13
|
+
import { keyBytes, MIN_KEY_BYTES, SECRET_PREFIX, signatureOf } from "./standard-webhooks.js";
|
|
14
|
+
export const LAUNCH_HOOK_URL_ENV = "AGENTRUN_LAUNCH_HOOK_URL";
|
|
15
|
+
export const LAUNCH_HOOK_SECRET_ENV = "AGENTRUN_LAUNCH_HOOK_SECRET";
|
|
16
|
+
/** How long the host has to answer a firing, its connection included. */
|
|
17
|
+
export const LAUNCH_HOOK_TIMEOUT_MS = 10_000;
|
|
18
|
+
/** How long after its 2xx a host that answered without starting the firing's run may still start it (one start, under
|
|
19
|
+
* the firing: triggers.ts handedStart). From the answer, not from fired_at: a catch-up, a firing that waited on its
|
|
20
|
+
* trigger's max_active_runs, or one a stop cut short and the next start handed again reaches the host late, and its
|
|
21
|
+
* host gets the same 10 minutes as any. */
|
|
22
|
+
export const LAUNCH_HOOK_LATE_START_MS = 10 * 60_000;
|
|
23
|
+
/** A host this machine alone answers: localhost, 127.0.0.0/8 or ::1, as URL writes them (lower case, IPv4 in four parts,
|
|
24
|
+
* IPv6 in brackets and shortest form). */
|
|
25
|
+
const loopback = (hostname) => hostname === "localhost" || hostname === "[::1]" || /^127(\.\d{1,3}){3}$/.test(hostname);
|
|
26
|
+
/** The launch hook `given` sets (the URL from the environment, the secret as the server holds its own), or undefined when
|
|
27
|
+
* neither is set. Throws, in words that never hold the secret, when one is set without the other, the URL is not https
|
|
28
|
+
* (http only to loopback) or holds a user or password, or the secret is not a `whsec_` secret of MIN_KEY_BYTES or more. */
|
|
29
|
+
export function launchHookFrom(given) {
|
|
30
|
+
const url = given.url?.trim() || undefined;
|
|
31
|
+
const secret = given.secret?.trim() || undefined;
|
|
32
|
+
if (!url && !secret)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (!secret)
|
|
35
|
+
throw new Error(`${LAUNCH_HOOK_URL_ENV} is set without ${LAUNCH_HOOK_SECRET_ENV}: the launch hook signs every firing it hands over. Set both, or neither.`);
|
|
36
|
+
if (!url)
|
|
37
|
+
throw new Error(`${LAUNCH_HOOK_SECRET_ENV} is set without ${LAUNCH_HOOK_URL_ENV}: the launch hook needs the host's URL. Set both, or neither.`);
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = new URL(url);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new Error(`${LAUNCH_HOOK_URL_ENV} is not a URL: give the host's http or https address for firings.`);
|
|
44
|
+
}
|
|
45
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:")
|
|
46
|
+
throw new Error(`${LAUNCH_HOOK_URL_ENV} is an http or https address, not ${parsed.protocol}`);
|
|
47
|
+
if (parsed.protocol === "http:" && !loopback(parsed.hostname)) {
|
|
48
|
+
throw new Error(`${LAUNCH_HOOK_URL_ENV} is http to ${parsed.hostname}: a firing's input can carry a person's data, so a hook off this machine is https. Plain http is for 127.0.0.0/8, ::1 or localhost alone.`);
|
|
49
|
+
}
|
|
50
|
+
if (parsed.username || parsed.password)
|
|
51
|
+
throw new Error(`${LAUNCH_HOOK_URL_ENV} holds no user or password: the host checks the signature.`);
|
|
52
|
+
if (!secret.startsWith(SECRET_PREFIX))
|
|
53
|
+
throw new Error(`${LAUNCH_HOOK_SECRET_ENV} is a Standard Webhooks secret: ${SECRET_PREFIX} and its key in base64.`);
|
|
54
|
+
if (keyBytes(secret) < MIN_KEY_BYTES)
|
|
55
|
+
throw new Error(`${LAUNCH_HOOK_SECRET_ENV}'s key is shorter than ${MIN_KEY_BYTES} bytes: make one of 32 random bytes.`);
|
|
56
|
+
return { url, secret };
|
|
57
|
+
}
|
|
58
|
+
/** Where `hook` sends, for the start's banner: its origin alone, never a path or query that may hold a token. */
|
|
59
|
+
export const hookOrigin = (hook) => new URL(hook.url).origin;
|
|
60
|
+
/** `firing` handed to `hook`: one signed POST of it, stamped at `now` (the triggers' clock), within the hook's bound and
|
|
61
|
+
* cut by `stop`. A redirect is not followed. */
|
|
62
|
+
export async function handToHost(hook, firing, stop, now = Date.now) {
|
|
63
|
+
const timeoutMs = hook.timeoutMs ?? LAUNCH_HOOK_TIMEOUT_MS;
|
|
64
|
+
const body = JSON.stringify(firing);
|
|
65
|
+
const timestamp = String(Math.floor(now() / 1000));
|
|
66
|
+
const headers = {
|
|
67
|
+
"content-type": "application/json",
|
|
68
|
+
"user-agent": "agentrun-serve-launch-hook/1",
|
|
69
|
+
"webhook-id": firing.firing_id,
|
|
70
|
+
"webhook-timestamp": timestamp,
|
|
71
|
+
"webhook-signature": signatureOf(hook.secret, firing.firing_id, timestamp, body),
|
|
72
|
+
};
|
|
73
|
+
const signal = AbortSignal.any([hook.bound ? hook.bound(timeoutMs) : AbortSignal.timeout(timeoutMs), stop]);
|
|
74
|
+
try {
|
|
75
|
+
const res = await undiciFetch(hook.url, { method: "POST", redirect: "manual", signal, headers, body });
|
|
76
|
+
// The answer's body is not read: the run the host started is found by the firing's key, never by what it says.
|
|
77
|
+
await res.body?.cancel().catch(() => undefined);
|
|
78
|
+
if (res.status >= 200 && res.status <= 299)
|
|
79
|
+
return { taken: true };
|
|
80
|
+
const said = res.status >= 300 && res.status < 400 ? `answered ${res.status}: a redirect is not followed` : `answered ${res.status}`;
|
|
81
|
+
return { skipped: `The launch hook ${said}, so the host did not take this firing.` };
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (stop.aborted)
|
|
85
|
+
return { stopped: true };
|
|
86
|
+
if (error.name === "TimeoutError" || signal.aborted)
|
|
87
|
+
return { skipped: `The launch hook did not answer in ${timeoutMs / 1000} s, so the host did not take this firing.` };
|
|
88
|
+
const code = error.cause?.code;
|
|
89
|
+
return { skipped: `The launch hook was not reached${typeof code === "string" ? ` (${code})` : ""}, so the host did not take this firing.` };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { type InputIssue } from "./errors.js";
|
|
1
|
+
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
2
|
import { type RunMoment, type RunsStore, type StartDeps } from "./runs-over-store.js";
|
|
3
3
|
import type { Store } from "./store/index.js";
|
|
4
4
|
import type { AgentEntry } from "./agents-store.js";
|
|
5
5
|
import type { MessageOrigin } from "./timeline/index.js";
|
|
6
6
|
import type { Json } from "./validate.js";
|
|
7
7
|
import type { RunTrigger, Target } from "./triggers.js";
|
|
8
|
+
/** Why a trigger may not message a run on a harness recipe billed to its vendor's plan: the turn would run as that run
|
|
9
|
+
* does, on its owner's own sign-in, which runs only what a person starts (HARNESS.md#run-it), and a scheduled turn runs
|
|
10
|
+
* on keys saved for the harness, which no server saves yet (the claim's RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
|
|
11
|
+
export declare const RECIPE_MESSAGE_PERSON_ONLY = "The run is on a harness recipe billed to its vendor's plan, which runs on its owner's own sign-in only for what a person starts: a trigger's turn runs on keys saved for that harness, and this server saves no harness's keys yet. Message the run yourself, or target a run on a harness billed through this server's model proxy.";
|
|
8
12
|
/** What the trigger target policy needs that lives elsewhere: the run-start leaves (StartDeps, shared with the create
|
|
9
13
|
* route), the agent reads, and the run view that gives a run's live moment and its v2 status. */
|
|
10
14
|
export interface TriggerTargetDeps {
|
|
@@ -19,6 +23,9 @@ export interface TriggerTargetDeps {
|
|
|
19
23
|
/** A run's live moment, for a message's acceptance and a target's cap/kind check (the run view → RunMoment); undefined
|
|
20
24
|
* for an unknown run. */
|
|
21
25
|
momentOf(runId: string): Promise<RunMoment | undefined>;
|
|
26
|
+
/** Whether `harness` is a harness recipe billed to its vendor's plan in this server's table (harness-table.ts
|
|
27
|
+
* recipeHarness): a trigger never messages a run on one. Absent: none is. */
|
|
28
|
+
planRecipe?(harness: string): boolean;
|
|
22
29
|
/** `work`, a write that may open run `runId` of agent `agentId` again, done in the agent's delete turn (server.ts
|
|
23
30
|
* runWrite): never under a purge of the run, and 410 purged after one. */
|
|
24
31
|
runWrite<T>(agentId: string, runId: string, work: () => Promise<T>): Promise<T>;
|
|
@@ -29,6 +36,11 @@ export interface TriggerTargetDeps {
|
|
|
29
36
|
* fields the output schema it was checked against (its pinned revision's, never the agent's current one) names in
|
|
30
37
|
* `x-carried` (answer-json.ts carriedFields), absent when it names none. */
|
|
31
38
|
completedOutput(runId: string): Promise<CompletedOutput | undefined>;
|
|
39
|
+
/** Under the run-keys setting, the keys a run of `revision` owes when it carries none (run-keys.ts keysOwed); absent
|
|
40
|
+
* when the setting is off. */
|
|
41
|
+
keysOwed?(revision: object): InputIssue[];
|
|
42
|
+
/** The server has the launch hook: each start_run firing goes to the backend in front of it (trigger-launch-hook.ts). */
|
|
43
|
+
readonly hooked?: boolean;
|
|
32
44
|
}
|
|
33
45
|
/** The most bytes of a previous run's result a triggered run is handed, as JSON: past it, it is handed none, said so. */
|
|
34
46
|
export declare const PREVIOUS_RESULT_MAX_BYTES: number;
|
|
@@ -66,6 +78,7 @@ export declare function previousHandover(runId: string, done: CompletedOutput):
|
|
|
66
78
|
* adapter's sealed settings, the failed-firing webhook) stay server-wired. */
|
|
67
79
|
export type TriggerTargets = {
|
|
68
80
|
targetIssues(target: Target): Promise<InputIssue[]>;
|
|
81
|
+
targetRefusal(target: Target): Promise<ApiError | undefined>;
|
|
69
82
|
start(target: Extract<Target, {
|
|
70
83
|
kind: "start_run";
|
|
71
84
|
}>, input: Json, origin: RunTrigger, from: MessageOrigin, title: string | undefined, previous: boolean): Promise<{
|
package/dist/trigger-targets.js
CHANGED
|
@@ -8,8 +8,13 @@ import { ApiError, unsupported } from "./errors.js";
|
|
|
8
8
|
import { message, startRun, WAITS_ON_A_PERSON } from "./runs-over-store.js";
|
|
9
9
|
import { runOfOrigin } from "./store-reads/runs.js";
|
|
10
10
|
import { NATIVE_CAP_UNSUPPORTED, NATIVE_RUN_OVERRIDES_UNSUPPORTED, nativeOf, nativeRunOverrides } from "./native/binding.js";
|
|
11
|
+
import { firingsOwe, keysOwedRefusal } from "./run-keys.js";
|
|
11
12
|
/** Why a trigger may not message a run with no cap (server.ts NO_CAP). */
|
|
12
13
|
const NO_CAP = "The run has no spend cap: a trigger only messages a run with one, as every turn it drives is capped.";
|
|
14
|
+
/** Why a trigger may not message a run on a harness recipe billed to its vendor's plan: the turn would run as that run
|
|
15
|
+
* does, on its owner's own sign-in, which runs only what a person starts (HARNESS.md#run-it), and a scheduled turn runs
|
|
16
|
+
* on keys saved for the harness, which no server saves yet (the claim's RECIPE_SIGN_IN_PERSON_ONLY, for a new run). */
|
|
17
|
+
export const RECIPE_MESSAGE_PERSON_ONLY = "The run is on a harness recipe billed to its vendor's plan, which runs on its owner's own sign-in only for what a person starts: a trigger's turn runs on keys saved for that harness, and this server saves no harness's keys yet. Message the run yourself, or target a run on a harness billed through this server's model proxy.";
|
|
13
18
|
/** The most of a trigger's firings, newest first, read for its last completed run. */
|
|
14
19
|
const PREVIOUS_FIRINGS_READ = 20;
|
|
15
20
|
/** The most bytes of a previous run's result a triggered run is handed, as JSON: past it, it is handed none, said so. */
|
|
@@ -110,6 +115,15 @@ function carriedEntryBytes(entry) {
|
|
|
110
115
|
/** The trigger target policy over `store`, with its reads and the run-start leaves injected. */
|
|
111
116
|
export function triggerTargets(store, deps) {
|
|
112
117
|
return {
|
|
118
|
+
async targetRefusal(target) {
|
|
119
|
+
if (!deps.keysOwed)
|
|
120
|
+
return undefined;
|
|
121
|
+
// The revision a firing would open a turn of: the run's own for a message_run, the agent's current for a start_run.
|
|
122
|
+
const row = target.kind === "message_run" ? await store.runs.get(target.run_id) : undefined;
|
|
123
|
+
const revision = target.kind === "message_run" ? (row ? await store.agents.revision(row.revisionId) : undefined) : (await deps.getAgent(target.agent_id))?.revision;
|
|
124
|
+
const owed = revision ? deps.keysOwed(revision) : [];
|
|
125
|
+
return firingsOwe(owed, target.kind, deps.hooked === true) ? keysOwedRefusal(owed) : undefined;
|
|
126
|
+
},
|
|
113
127
|
async targetIssues(target) {
|
|
114
128
|
if (target.kind === "message_run") {
|
|
115
129
|
const run = await deps.momentOf(target.run_id);
|
|
@@ -117,6 +131,8 @@ export function triggerTargets(store, deps) {
|
|
|
117
131
|
return [{ field: "target.run_id", reason: "not_found", message: `no run ${target.run_id}` }];
|
|
118
132
|
if (run.kind === "workflow")
|
|
119
133
|
return [{ field: "target.run_id", reason: "not_allowed", message: "A workflow run takes no messages here." }];
|
|
134
|
+
if (run.harness !== undefined && deps.planRecipe?.(run.harness))
|
|
135
|
+
return [{ field: "target.run_id", reason: "not_allowed", message: RECIPE_MESSAGE_PERSON_ONLY }];
|
|
120
136
|
return run.maxCostUsd === undefined ? [{ field: "target.run_id", reason: "not_allowed", message: NO_CAP }] : [];
|
|
121
137
|
}
|
|
122
138
|
const entry = await deps.getAgent(target.agent_id);
|
|
@@ -164,6 +180,10 @@ export function triggerTargets(store, deps) {
|
|
|
164
180
|
throw new ApiError("not_found", `There is no run ${target.run_id}.`);
|
|
165
181
|
if (run.kind === "workflow")
|
|
166
182
|
throw unsupported("messages.steer_workflow_runs", "A workflow run takes no messages here.");
|
|
183
|
+
// Never a turn on a plan-billed recipe (its owner's own sign-in, a person's alone): checked again at each firing, as
|
|
184
|
+
// the server may since have been started with that recipe; skipped in words, never queued.
|
|
185
|
+
if (run.harness !== undefined && deps.planRecipe?.(run.harness))
|
|
186
|
+
return { skipped: RECIPE_MESSAGE_PERSON_ONLY };
|
|
167
187
|
// Never an uncapped turn, nor an answer to a person's question, an approval or a budget pause: a run that waits on its
|
|
168
188
|
// person is told nothing by a trigger (skipped, never queued behind the person).
|
|
169
189
|
if (run.maxCostUsd === undefined)
|