@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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 +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +69 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +24 -0
- package/dist/turn-end.js +15 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +189 -0
- package/dist/webhooks.js +503 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// What a run is told of its workspace: one line after its first message naming the files given to it (`file_ids`,
|
|
2
|
+
// copied into its work/inputs/, uploads.ts), so a model asked about "the attached file" knows where it is. On every
|
|
3
|
+
// harness: it rides in the first message itself, which runs.ts sends to the run's door. Bounded: at most
|
|
4
|
+
// MANIFEST_ENTRIES files, then how many more, and never past what the door takes in one message (FIRST_MESSAGE_BYTES):
|
|
5
|
+
// a message that fits at the run's creation still fits with its line.
|
|
6
|
+
import { INPUTS_DIR } from "./uploads.js";
|
|
7
|
+
import { walkWork } from "./workspace.js";
|
|
8
|
+
/** The most files the line names; the rest are counted. */
|
|
9
|
+
export const MANIFEST_ENTRIES = 20;
|
|
10
|
+
/** The most the first message may take, as the JSON string the run's door is sent: pi-durable-disk's door takes a body of
|
|
11
|
+
* at most 1 MiB (serve.ts), and this leaves room for the request's other fields. */
|
|
12
|
+
export const FIRST_MESSAGE_BYTES = (1 << 20) - 4096;
|
|
13
|
+
/** `bytes` as a person reads a size: `32 B`, `1.5 KB`, `2.0 MB`. */
|
|
14
|
+
export const sizeOf = (bytes) => bytes < 1024 ? `${bytes} B` : bytes < 1024 * 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
15
|
+
/** What a quoted name never holds as itself: a control character, a format character (an RTL override, a zero-width
|
|
16
|
+
* space) or a line or paragraph separator, which JSON leaves as they are where it escapes no more than it must. */
|
|
17
|
+
const UNSEEN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
18
|
+
/** `name` as a JSON string, each character UNSEEN names as its `\uXXXX` escape: so a quote or a comma in it cannot end
|
|
19
|
+
* it and forge another entry, and nothing in it can break the line or reorder what is read. */
|
|
20
|
+
export const quoted = (name) => JSON.stringify(name).replace(UNSEEN, (found) => Array.from({ length: found.length }, (_, i) => `\\u${found.charCodeAt(i).toString(16).padStart(4, "0")}`).join(""));
|
|
21
|
+
/** `label: "a" (1 B), "b" (2 B).`, at most `entries` (MANIFEST_ENTRIES) of `files`, each name `quoted`, and then `and N
|
|
22
|
+
* more`, or with none named `label: N files.`; undefined for no file. */
|
|
23
|
+
export function filesLine(label, files, entries = MANIFEST_ENTRIES) {
|
|
24
|
+
if (files.length === 0)
|
|
25
|
+
return undefined;
|
|
26
|
+
const named = files.slice(0, Math.min(entries, MANIFEST_ENTRIES)).map((file) => `${quoted(file.path)} (${sizeOf(file.size)})`);
|
|
27
|
+
const more = files.length - named.length;
|
|
28
|
+
if (named.length === 0)
|
|
29
|
+
return `${label}: ${files.length} ${files.length === 1 ? "file" : "files"}.`;
|
|
30
|
+
return `${label}: ${named.join(", ")}${more > 0 ? `, and ${more} more` : ""}.`;
|
|
31
|
+
}
|
|
32
|
+
/** The size of `text` as the door is sent it: a JSON string, in UTF-8 bytes. */
|
|
33
|
+
const sentBytes = (text) => Buffer.byteLength(JSON.stringify(text));
|
|
34
|
+
/** How deep the walk of work/inputs/ goes: an upload's path is at most 1024 characters, so at most 512 folders deep,
|
|
35
|
+
* and inputs/ is one more. */
|
|
36
|
+
const INPUTS_DEPTH = 513;
|
|
37
|
+
/** The regular files under the run's work/inputs/, by their path from work/, in order, as deep as an upload's path
|
|
38
|
+
* goes: walked from work/ as the run's file list is (workspace.ts walkWork), entering inputs/ alone, so a link at
|
|
39
|
+
* inputs/ or anywhere below it is never followed; a dot-name left out. None when there is no inputs/ or it cannot be
|
|
40
|
+
* read. */
|
|
41
|
+
export async function inputFiles(work) {
|
|
42
|
+
const files = [];
|
|
43
|
+
await walkWork(work, (path, stats) => void (stats.isFile() && files.push({ path, size: stats.size })), {
|
|
44
|
+
skip: (name, path) => name.startsWith(".") || (path === name && name !== INPUTS_DIR),
|
|
45
|
+
depth: INPUTS_DEPTH,
|
|
46
|
+
}).catch(() => undefined);
|
|
47
|
+
return files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
48
|
+
}
|
|
49
|
+
/** The run's first message: `content`, then, after a blank line, the files given to it, when it has any: as many named
|
|
50
|
+
* as keep the message within `budget` (FIRST_MESSAGE_BYTES), else only how many, else no line at all, so the line never
|
|
51
|
+
* turns a message the run took into one its door refuses. */
|
|
52
|
+
export async function firstMessage(content, work, budget = FIRST_MESSAGE_BYTES) {
|
|
53
|
+
const files = await inputFiles(work);
|
|
54
|
+
for (let entries = Math.min(files.length, MANIFEST_ENTRIES); entries >= 0 && files.length > 0; entries--) {
|
|
55
|
+
const message = `${content}\n\n${filesLine("Files for this run", files, entries)}`;
|
|
56
|
+
if (sentBytes(message) <= budget)
|
|
57
|
+
return message;
|
|
58
|
+
}
|
|
59
|
+
return content;
|
|
60
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type InputIssue } from "./errors.js";
|
|
2
|
+
import { type HarnessCapability } from "./harness.js";
|
|
3
|
+
import { type ModelRef } from "./model.js";
|
|
4
|
+
import type { BoxOffer } from "./boxes.js";
|
|
5
|
+
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
6
|
+
/** A revision's body as it is saved or stored. */
|
|
7
|
+
export type RevisionShape = {
|
|
8
|
+
kind: "agentic";
|
|
9
|
+
instructions: string;
|
|
10
|
+
tools?: readonly string[];
|
|
11
|
+
model?: string;
|
|
12
|
+
harness?: string;
|
|
13
|
+
place?: {
|
|
14
|
+
mode: string;
|
|
15
|
+
box?: string;
|
|
16
|
+
};
|
|
17
|
+
toolSettings?: ToolSettingsMap;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "workflow";
|
|
20
|
+
workflow: unknown;
|
|
21
|
+
tools?: readonly string[];
|
|
22
|
+
harness?: string;
|
|
23
|
+
place?: {
|
|
24
|
+
mode: string;
|
|
25
|
+
box?: string;
|
|
26
|
+
};
|
|
27
|
+
toolSettings?: ToolSettingsMap;
|
|
28
|
+
};
|
|
29
|
+
/** One thing that keeps a revision from running here. `host`: a setting of this host could fix it. `tool` (one it does
|
|
30
|
+
* not bind), `missing` (a bound tool's unset variables), `adapter`, `decision` (a decision provider's unset key), `codeNodes`
|
|
31
|
+
* (code nodes this server does not run), `shell` (a shell or executor call), `tier`, `harness`, `box` (the place's,
|
|
32
|
+
* which this server does not have) and `denied` (a tool a workflow's call node calls that is set to deny) name it for a
|
|
33
|
+
* run's 409 details. */
|
|
34
|
+
export type Blocker = InputIssue & {
|
|
35
|
+
host: boolean;
|
|
36
|
+
tool?: string;
|
|
37
|
+
missing?: {
|
|
38
|
+
tool: string;
|
|
39
|
+
vars: string[];
|
|
40
|
+
};
|
|
41
|
+
adapter?: string;
|
|
42
|
+
decision?: {
|
|
43
|
+
provider: string;
|
|
44
|
+
needs: string[];
|
|
45
|
+
};
|
|
46
|
+
codeNodes?: true;
|
|
47
|
+
shell?: true;
|
|
48
|
+
tier?: string;
|
|
49
|
+
harness?: string;
|
|
50
|
+
box?: string;
|
|
51
|
+
denied?: string;
|
|
52
|
+
asks?: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
|
|
56
|
+
* default for that harness. `why`: the model itself is the problem (`host`, a setting of this host could fix it);
|
|
57
|
+
* `refused`: the harness runs here but refuses that model. Undefined when claude-agent does not run here: its model is
|
|
58
|
+
* its own, and the harness says why. A save, a run and capabilities' `harnesses[].default_model` all ask this, so they
|
|
59
|
+
* cannot drift.
|
|
60
|
+
*/
|
|
61
|
+
export declare function harnessModel(env: NodeJS.ProcessEnv, harness: string, ref: string | undefined, available: boolean): Promise<{
|
|
62
|
+
model: ModelRef;
|
|
63
|
+
} | {
|
|
64
|
+
why: string;
|
|
65
|
+
host: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
refused: string;
|
|
68
|
+
} | undefined>;
|
|
69
|
+
/** The reason a warning gives: the revision runs once this host has what it names. */
|
|
70
|
+
export declare const NOT_SET_UP = "not_set_up_here";
|
|
71
|
+
/** Set to 1 (`--allow-code-nodes`), this server runs workflows' `code` nodes: in the run's process, through the DSL's
|
|
72
|
+
* `new Function` transform, which is no sandbox. Off by default. */
|
|
73
|
+
export declare const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
74
|
+
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
75
|
+
* server's box registry set up at its start (boxes.ts); none, every box is unavailable. `offers`: the harnesses' offers
|
|
76
|
+
* the server already holds (its reading); none given, they are probed here. */
|
|
77
|
+
export declare function blockersOf(env: NodeJS.ProcessEnv, revision: RevisionShape, settings?: ToolSettingsMap, { capped, boxes, offers }?: {
|
|
78
|
+
capped?: boolean;
|
|
79
|
+
boxes?: readonly BoxOffer[];
|
|
80
|
+
offers?: readonly HarnessCapability[];
|
|
81
|
+
}): Promise<Blocker[]>;
|
|
82
|
+
/** A blocker as a field issue, for a 422 or a warning. */
|
|
83
|
+
export declare const issueOf: ({ field, reason, message, fix }: Blocker) => InputIssue;
|
package/dist/runnable.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// What keeps a revision from running on this host, checked when a definition is saved and again before each run, so
|
|
2
|
+
// the two cannot drift. A blocker no setting of this host fixes (a tool it does not bind, a model pi-ai does not know,
|
|
3
|
+
// no instructions, a workflow needing what it does not give) refuses the save, 422 by field; one a setting fixes (a
|
|
4
|
+
// provider's key, a default model, a tier's model) saves as a warning. Either refuses a run, 409 agent_not_runnable.
|
|
5
|
+
import { WORKFLOW_ADAPTERS } from "./app.js";
|
|
6
|
+
import { DECISION_ADAPTER, providerMissing, providersNamed } from "./decisions.js";
|
|
7
|
+
import { REPLAY } from "./host-tools.js";
|
|
8
|
+
import { sentence } from "./errors.js";
|
|
9
|
+
import { DEFAULT_HARNESS, FAUX_HARNESS_ENV, harnessOffers } from "./harness.js";
|
|
10
|
+
import { chooseModel, llmTiers, nodeTiers, workflowNodes } from "./model.js";
|
|
11
|
+
import { boxAvailability, placeFix, RUN_BOXES } from "./place.js";
|
|
12
|
+
import { allows, BOUND_TOOLS, CALL_TOOLS, grantedTools, missingEnv, NODE_TOOLS, toolOf, workflowTools } from "./tools.js";
|
|
13
|
+
import { capabilityOf, DENIED, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
|
|
14
|
+
import { permissionOf } from "./tool-gate.js";
|
|
15
|
+
import { PARALLEL_KEY_ENV } from "./decisions.js";
|
|
16
|
+
/**
|
|
17
|
+
* The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
|
|
18
|
+
* default for that harness. `why`: the model itself is the problem (`host`, a setting of this host could fix it);
|
|
19
|
+
* `refused`: the harness runs here but refuses that model. Undefined when claude-agent does not run here: its model is
|
|
20
|
+
* its own, and the harness says why. A save, a run and capabilities' `harnesses[].default_model` all ask this, so they
|
|
21
|
+
* cannot drift.
|
|
22
|
+
*/
|
|
23
|
+
export async function harnessModel(env, harness, ref, available) {
|
|
24
|
+
// claude-agent's model is its own (adapters.ts), never routed through the other harnesses' gateway; on the faux
|
|
25
|
+
// harness every harness takes the run's usual model.
|
|
26
|
+
const own = harness === "claude-agent" && !env[FAUX_HARNESS_ENV];
|
|
27
|
+
if (own && !available)
|
|
28
|
+
return undefined;
|
|
29
|
+
// codex's is the run's usual model, but an OpenAI model it reaches through OpenRouter alone is OpenRouter's (codexRef).
|
|
30
|
+
const chosen = own ? (await import("./adapters.js")).claudeModel(env, ref) : harness === "codex" || harness === "opencode" ? await (await import("./adapters.js")).codexModel(env, ref, harness) : await chooseModel(env, ref, "default", harness);
|
|
31
|
+
if ("why" in chosen)
|
|
32
|
+
return chosen;
|
|
33
|
+
// The harness runs here; whether it runs this model (the revision's, or the default) is checked on it.
|
|
34
|
+
if (harness !== DEFAULT_HARNESS && available) {
|
|
35
|
+
const { harnessReason } = await import("./adapters.js");
|
|
36
|
+
const refused = await harnessReason(harness, env, { model: chosen.model, models: { getModel: () => undefined } });
|
|
37
|
+
if (refused !== undefined)
|
|
38
|
+
return { refused };
|
|
39
|
+
}
|
|
40
|
+
return { model: chosen.model };
|
|
41
|
+
}
|
|
42
|
+
/** The reason a warning gives: the revision runs once this host has what it names. */
|
|
43
|
+
export const NOT_SET_UP = "not_set_up_here";
|
|
44
|
+
/** Set to 1 (`--allow-code-nodes`), this server runs workflows' `code` nodes: in the run's process, through the DSL's
|
|
45
|
+
* `new Function` transform, which is no sandbox. Off by default. */
|
|
46
|
+
export const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
47
|
+
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
48
|
+
* server's box registry set up at its start (boxes.ts); none, every box is unavailable. `offers`: the harnesses' offers
|
|
49
|
+
* the server already holds (its reading); none given, they are probed here. */
|
|
50
|
+
export async function blockersOf(env, revision, settings = {}, { capped = false, boxes = [], offers } = {}) {
|
|
51
|
+
const out = [];
|
|
52
|
+
/** A web tool its run would resolve unavailable (tool-plane.ts): a warning at save, a 409 at a run, never another
|
|
53
|
+
* provider in its place. One set to deny is not: its run starts, and the gate refuses each call. */
|
|
54
|
+
const unavailable = (field, tools, tool) => {
|
|
55
|
+
const resolved = planeFor(env, { tools, harness, ...(revision.kind === "workflow" ? { workflow: true } : {}), ...(revision.kind === "agentic" && revision.model ? { model: revision.model } : {}), ...(revision.toolSettings ? { overrides: revision.toolSettings } : {}) }, settings, { capped })[capabilityOf(tool)];
|
|
56
|
+
if (isUnavailable(resolved) && resolved !== DENIED)
|
|
57
|
+
out.push({ field, reason: NOT_SET_UP, message: `The tool ${tool} does not run here on ${harness}: ${whyUnavailable(resolved)}.`, host: true, ...(resolved === NO_PARALLEL_KEY ? { missing: { tool, vars: [PARALLEL_KEY_ENV] } } : {}) });
|
|
58
|
+
};
|
|
59
|
+
/** A bound tool whose variables this host does not set: a warning at save, a 409 at a run. */
|
|
60
|
+
const unset = (field, tool) => {
|
|
61
|
+
const vars = missingEnv(toolOf(tool), env);
|
|
62
|
+
if (vars.length)
|
|
63
|
+
out.push({ field, reason: NOT_SET_UP, message: `This server's environment does not set what the tool needs: the tool ${tool} needs ${vars.join(" and ")}.`, host: true, missing: { tool, vars } });
|
|
64
|
+
};
|
|
65
|
+
const harness = revision.harness ?? DEFAULT_HARNESS;
|
|
66
|
+
const offer = (offers ?? (await harnessOffers(env))).find((h) => h.id === harness);
|
|
67
|
+
if (!offer?.available)
|
|
68
|
+
out.push({ field: "definition.harness", reason: NOT_SET_UP, message: offer?.reason ?? `This server does not run ${harness}.`, host: true, harness });
|
|
69
|
+
const { place } = revision;
|
|
70
|
+
// A workflow's model and call nodes run on the runner here; in a box they do not run yet. Its fix names the runner: an
|
|
71
|
+
// edit that leaves the place out keeps the agent's (agents.ts), so removing the field would change nothing.
|
|
72
|
+
if (revision.kind === "workflow" && place && place.mode !== "runner")
|
|
73
|
+
out.push({ field: "definition.place", reason: "not_an_option", message: `A workflow runs on the runner here: its place is runner (or none), not ${place.mode} on ${place.box ?? "no box"}.`, fix: placeFix({ mode: "runner" }), host: false });
|
|
74
|
+
else if (place && place.mode !== "runner") {
|
|
75
|
+
const box = boxAvailability(boxes).find((b) => b.id === place.box);
|
|
76
|
+
// A box's reason says what to do, with no full stop of its own: the sentence ends in one, whatever the reason ends in.
|
|
77
|
+
if (!box?.available)
|
|
78
|
+
out.push({ field: "definition.place", reason: NOT_SET_UP, message: sentence(`This agent's place is ${place.mode} on ${place.box ?? "no box"}, and this server cannot run it there: ${box?.reason ?? "that is not a box this server has"}`), host: true, ...(place.box ? { box: place.box } : {}) });
|
|
79
|
+
}
|
|
80
|
+
if (revision.kind === "agentic") {
|
|
81
|
+
if (!revision.instructions.trim())
|
|
82
|
+
out.push({ field: "definition.instructions", reason: "too_short", message: "definition.instructions is empty: an agentic revision needs instructions.", host: false });
|
|
83
|
+
(revision.tools ?? []).forEach((tool, index) => {
|
|
84
|
+
if (!allows(BOUND_TOOLS, tool))
|
|
85
|
+
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `agentrun-serve binds the tools ${BOUND_TOOLS.join(", ")}; ${tool} is not one of them.`, host: false, tool });
|
|
86
|
+
// A shell runs only in a box: no place, or the runner, has none.
|
|
87
|
+
else if (toolOf(tool).sandboxOnly && (place?.mode ?? "runner") === "runner")
|
|
88
|
+
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} runs only in a box, and ${place ? "this agent's place is the runner" : "this agent names no place, so it runs on the runner"}, which has no shell: give it a sandbox place.`, fix: placeFix({ mode: "sandbox", box: RUN_BOXES[0] }), host: false, tool });
|
|
89
|
+
// Its writes into work/ go by path from this machine, and a box's command could swap a link in on their way.
|
|
90
|
+
else if (toolOf(tool).runnerOnly && place?.mode === "sandbox")
|
|
91
|
+
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} does not run in a sandbox place yet: it saves files into the run's work/ from this server, outside the box, and a command in the box could point those writes elsewhere on this server. Give it to an agent whose place is the runner.`, fix: `Remove "${tool}" from definition.tools.`, host: false, tool });
|
|
92
|
+
// Another harness gets the host tools only (host-tools.ts: the file tools, fetch_page, web_fetch, web_search and
|
|
93
|
+
// monid's): any other tool this host binds, ask_person among them, is pi's here and refuses the run, never runs
|
|
94
|
+
// without it.
|
|
95
|
+
else if (harness !== DEFAULT_HARNESS && !(tool in REPLAY))
|
|
96
|
+
out.push({ field: `definition.tools[${index}]`, reason: NOT_SET_UP, message: `${tool} runs on pi here; on ${harness} it is not bound yet.`, host: true, tool });
|
|
97
|
+
else {
|
|
98
|
+
unset(`definition.tools[${index}]`, tool);
|
|
99
|
+
unavailable(`definition.tools[${index}]`, revision.tools ?? [], tool);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const resolved = await harnessModel(env, harness, revision.model, offer?.available === true);
|
|
103
|
+
if (!resolved)
|
|
104
|
+
return out;
|
|
105
|
+
if ("why" in resolved)
|
|
106
|
+
out.push({ field: "definition.model", reason: resolved.host ? NOT_SET_UP : "not_an_option", message: resolved.why, host: resolved.host });
|
|
107
|
+
else if ("refused" in resolved)
|
|
108
|
+
out.push({ field: revision.model ? "definition.model" : "definition.harness", reason: NOT_SET_UP, message: resolved.refused, host: true, harness });
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
// A workflow's model nodes run on pi here; on another harness they are not bound yet, and never run on pi instead.
|
|
112
|
+
if (harness !== DEFAULT_HARNESS)
|
|
113
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `A workflow runs on pi here; on ${harness} its model nodes are not bound yet.`, host: true, harness });
|
|
114
|
+
const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
|
|
115
|
+
const inspection = inspectWorkflow(revision.workflow);
|
|
116
|
+
const { requires } = inspection;
|
|
117
|
+
const nodes = workflowNodes(revision.workflow, inspection);
|
|
118
|
+
const runs = "agentrun-serve runs a workflow's model nodes (agent, decide, extract, report)";
|
|
119
|
+
for (const adapter of requires.adapters.filter((name) => !WORKFLOW_ADAPTERS.includes(name))) {
|
|
120
|
+
// Typed questions run on the provider each node names (Jev for one that names none) once this host sets its key:
|
|
121
|
+
// until then a warning at save, a 409 at a run. A provider this server does not have refuses the save.
|
|
122
|
+
if (adapter === DECISION_ADAPTER) {
|
|
123
|
+
for (const provider of providersNamed(nodes)) {
|
|
124
|
+
const missing = providerMissing(env, provider);
|
|
125
|
+
if (!missing)
|
|
126
|
+
continue;
|
|
127
|
+
out.push(missing.needs
|
|
128
|
+
? { field: "definition.workflow", reason: NOT_SET_UP, message: missing.message, host: true, adapter, decision: { provider, needs: missing.needs } }
|
|
129
|
+
: { field: "definition.workflow", reason: "not_an_option", message: missing.message, host: false, adapter });
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
out.push({ field: "definition.workflow", reason: "not_an_option", message: `${runs}; this workflow also needs ${adapter}.`, host: false, adapter });
|
|
134
|
+
}
|
|
135
|
+
// `code` nodes run here (the DSL's pure transform) when the server allows them; a call through a shell or the executor never does.
|
|
136
|
+
const shells = nodes.some((node) => node.node === "call" && (node.via === "shell" || node.via === "executor"));
|
|
137
|
+
if (requires.executableCode && shells)
|
|
138
|
+
out.push({ field: "definition.workflow", reason: "not_an_option", message: `${runs}, code nodes and calls via tool; this workflow also calls a shell or the executor.`, host: false, shell: true });
|
|
139
|
+
else if (requires.executableCode && env[CODE_NODES_ENV] !== "1")
|
|
140
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `This server runs no code nodes: start it with --allow-code-nodes (or ${CODE_NODES_ENV}=1) to run this workflow's.`, host: true, codeNodes: true });
|
|
141
|
+
const named = workflowTools(nodes);
|
|
142
|
+
for (const tool of named.nodes) {
|
|
143
|
+
if (!allows(NODE_TOOLS, tool))
|
|
144
|
+
out.push({ field: "definition.workflow", reason: "not_an_option", message: `A workflow's model nodes get the tools ${NODE_TOOLS.join(", ")} here; this workflow also names ${tool}.`, host: false, tool });
|
|
145
|
+
}
|
|
146
|
+
for (const tool of named.calls) {
|
|
147
|
+
if (!allows(CALL_TOOLS, tool))
|
|
148
|
+
out.push({ field: "definition.workflow", reason: "not_an_option", message: `A workflow's call nodes run the tools ${CALL_TOOLS.join(", ")} here; this workflow also calls ${tool}.`, host: false, tool });
|
|
149
|
+
// A call node is the author's own step, and it cannot wait for an approval: one that calls a tool set to deny, or to
|
|
150
|
+
// ask (which it could never get), would be refused mid-run (app.ts runEffect), so the run never starts.
|
|
151
|
+
// Held to its settings key: a legacy name (fetch_page) takes its capability's permission (web_fetch's), as the gate does.
|
|
152
|
+
else if (permissionOf(capabilityOf(tool), settings, (revision.toolSettings ?? {})) === "ask")
|
|
153
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `This workflow's call node calls ${capabilityOf(tool) === tool ? tool : `${tool} (${capabilityOf(tool)})`}, which is set to ask, and a workflow's call node can't wait for an approval: set it to allow for this agent.`, host: true, asks: capabilityOf(tool) });
|
|
154
|
+
else if (permissionOf(capabilityOf(tool), settings, (revision.toolSettings ?? {})) === "deny")
|
|
155
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `This workflow's call node calls ${capabilityOf(tool) === tool ? tool : `${tool} (${capabilityOf(tool)})`}, which is set to deny on this server.`, host: true, denied: capabilityOf(tool) });
|
|
156
|
+
}
|
|
157
|
+
const granted = await grantedTools(revision);
|
|
158
|
+
for (const tool of new Set([...named.nodes.filter((name) => allows(NODE_TOOLS, name)), ...named.calls.filter((name) => allows(CALL_TOOLS, name))])) {
|
|
159
|
+
unset("definition.workflow", tool);
|
|
160
|
+
unavailable("definition.workflow", granted, tool);
|
|
161
|
+
}
|
|
162
|
+
for (const tier of llmTiers(nodes, nodeTiers(nodes))) {
|
|
163
|
+
const chosen = await chooseModel(env, undefined, tier);
|
|
164
|
+
if ("why" in chosen)
|
|
165
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: chosen.why, host: true, tier });
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
/** A blocker as a field issue, for a 422 or a warning. */
|
|
170
|
+
export const issueOf = ({ field, reason, message, fix }) => ({ field, reason, message, ...(fix ? { fix } : {}) });
|