@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.33
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 +37 -0
- package/README.md +78 -46
- package/dist/adapters.d.ts +0 -3
- package/dist/adapters.js +0 -7
- package/dist/agents.d.ts +1 -1
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +46 -0
- package/dist/box-settings.js +107 -0
- package/dist/boxes.d.ts +4 -1
- package/dist/browser-cost.js +2 -1
- package/dist/browser-person.d.ts +0 -2
- package/dist/browser-person.js +0 -2
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +0 -7
- package/dist/cap.js +0 -22
- package/dist/cli.js +23 -8
- package/dist/computers.d.ts +1 -1
- package/dist/console/assets/index-Dn0ngwG9.js +535 -0
- package/dist/console/assets/index-DvW6Aled.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/files.d.ts +0 -8
- package/dist/files.js +0 -17
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +1 -1
- package/dist/harness-install.d.ts +23 -0
- package/dist/harness-install.js +99 -4
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/import.js +52 -13
- package/dist/learn/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +19 -6
- package/dist/learned-workflow.d.ts +5 -4
- package/dist/learned-workflow.js +6 -3
- package/dist/learning-routes.d.ts +9 -46
- package/dist/learning-routes.js +25 -29
- package/dist/learning-run.d.ts +4 -231
- package/dist/learning-run.js +7 -651
- package/dist/live/translate.js +1 -1
- package/dist/mcp-gateway.d.ts +0 -3
- package/dist/mcp-gateway.js +0 -13
- package/dist/mcp-probe.d.ts +2 -2
- package/dist/mcp-probe.js +2 -2
- package/dist/mcp-servers-store.js +1 -1
- package/dist/openapi.js +3 -3
- package/dist/page.js +3 -1
- package/dist/paid-calls.js +3 -2
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/run-db.d.ts +0 -2
- package/dist/run-db.js +0 -4
- package/dist/run-learning-served.d.ts +38 -0
- package/dist/run-learning-served.js +9 -0
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +5 -9
- package/dist/run-view.js +4 -22
- package/dist/runner/adapter-loop.d.ts +8 -2
- package/dist/runner/adapter-loop.js +44 -12
- package/dist/runner/adapter-run-spec.d.ts +8 -0
- package/dist/runner/adapter-run-spec.js +6 -5
- package/dist/runner/adapters/pi.d.ts +4 -0
- package/dist/runner/adapters/pi.js +4 -1
- package/dist/runner/beside.js +19 -8
- package/dist/runner/claim-secrets.js +1 -1
- package/dist/runner/cli-run-spec.js +15 -1
- package/dist/runner/journal-kinds.d.ts +6 -0
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +11 -4
- package/dist/runner/main.js +39 -10
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/model-route.js +21 -2
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/workflow-spec.js +5 -9
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +16 -5
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +272 -84
- package/dist/sealed-settings.d.ts +2 -2
- package/dist/sealed-settings.js +3 -10
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-secrets-store.js +1 -1
- package/dist/server-secrets.js +3 -0
- package/dist/server.d.ts +10 -6
- package/dist/server.js +89 -41
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/open.d.ts +12 -2
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/migrate.js +18 -1
- package/dist/store/sqlite/store.js +23 -8
- package/dist/store/store.d.ts +3 -0
- package/dist/store-reads/journal.d.ts +16 -0
- package/dist/store-reads/journal.js +82 -6
- package/dist/store-view.js +38 -5
- package/dist/tool-keys.d.ts +4 -3
- package/dist/tool-keys.js +7 -4
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +4 -1
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/workspace/computer-deps.d.ts +29 -0
- package/dist/workspace/computer-deps.js +48 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +1 -1
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +0 -3
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
package/dist/box-paths.js
CHANGED
|
@@ -5,31 +5,99 @@
|
|
|
5
5
|
// container, as compose.yaml makes it. The server reads its own container's id from /proc/self/mountinfo (Docker binds
|
|
6
6
|
// /etc/hostname from `<its root>/containers/<id>/hostname`), asks Docker for that container's mounts, and takes the
|
|
7
7
|
// named volume that holds the data directory; a box then mounts the run's work/ and its egress directory as that volume's
|
|
8
|
-
// subpaths (pi-transport's Docker `paths`, `volume-subpath`: Docker Engine 26 and later), never the volume's root
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// subpaths (pi-transport's Docker `paths`, `volume-subpath`: Docker Engine 26 and later), never the volume's root, and a
|
|
9
|
+
// run's Docker computer mounts its run's folder and its daemon copy the same way (workspace/computer-deps.ts
|
|
10
|
+
// dockerVolumeOf, the Docker provider's `volume`). Any other layout, or an older engine, is a reason, said once at the
|
|
11
|
+
// start, and docker is unavailable: a guess would make every box fail at its create.
|
|
11
12
|
import { execFile } from "node:child_process";
|
|
12
13
|
import { existsSync } from "node:fs";
|
|
13
14
|
import { readFile } from "node:fs/promises";
|
|
15
|
+
import { FAUX_ENV } from "./model.js";
|
|
14
16
|
import { withoutSecrets } from "./secrets.js";
|
|
15
17
|
/** The one way a server in a container runs boxes. */
|
|
16
18
|
export const IN_COMPOSE = "run AgentRun in a container with `docker compose up` from compose.yaml (its named data volume is how boxes reach a run's files)";
|
|
17
19
|
/** An engine that cannot mount a volume's subpath. */
|
|
18
20
|
export const OLD_ENGINE = "Docker Engine <26 can't mount a named volume's subpath: upgrade to Docker 26+";
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
/**
|
|
24
|
-
|
|
21
|
+
/** Why a Docker computer can't run for a server whose Docker daemon (at `endpoint`) is another machine's: a run's
|
|
22
|
+
* computer mounts the run's folder (and the computer's daemon) by this server's own paths, which that daemon doesn't
|
|
23
|
+
* have. */
|
|
24
|
+
export const remoteDockerWords = (endpoint) => `this server's Docker daemon (${endpoint}) is another machine's: it can't mount the run's folder from this machine, so Docker computers aren't available on this setup (give the agent another computer, or run the server on the Docker host)`;
|
|
25
|
+
/** Loopback, by name or address: a daemon this machine reaches over its own loopback. */
|
|
26
|
+
const LOOPBACK = /^(localhost|127(\.\d{1,3}){3}|\[?::1\]?)$/i; // key-gate: loopback-rule names this machine only, to tell its own daemon from another machine; the line dials nothing
|
|
27
|
+
/** Whether a daemon endpoint is another machine's: ssh://, or tcp:// to a host that is not this machine's loopback.
|
|
28
|
+
* Everything else is this machine's: unix:// (and fd://), npipe:// (Docker Desktop on Windows), tcp:// to loopback. Its
|
|
29
|
+
* Docker provider still applies its own allow-list rule to those (the provider's check where it isn't on the host). */
|
|
30
|
+
export function remoteEndpoint(endpoint) {
|
|
31
|
+
const scheme = /^([a-z][a-z0-9+.-]*):\/\//i.exec(endpoint)?.[1]?.toLowerCase();
|
|
32
|
+
if (scheme === "ssh")
|
|
33
|
+
return true;
|
|
34
|
+
if (scheme !== "tcp")
|
|
35
|
+
return false;
|
|
36
|
+
let host;
|
|
37
|
+
try {
|
|
38
|
+
host = new URL(endpoint).hostname;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return !LOOPBACK.test(host);
|
|
44
|
+
}
|
|
45
|
+
/** The daemon `env`'s docker reaches, when it is another machine's (remoteEndpoint): DOCKER_HOST when set, else the
|
|
46
|
+
* current context's endpoint as the CLI resolves it (DOCKER_CONTEXT, else the saved current context), read as the
|
|
47
|
+
* computer package's Docker provider reads it (`docker context inspect`); undefined for this machine's. A context that
|
|
48
|
+
* can't be read is taken as this machine's: its Docker provider still refuses at create where it isn't. `docker` is
|
|
49
|
+
* the tests'. */
|
|
50
|
+
export async function remoteDockerOf(env, docker = dockerCall(env)) {
|
|
51
|
+
const host = env.DOCKER_HOST?.trim();
|
|
52
|
+
if (host)
|
|
53
|
+
return remoteEndpoint(host) ? host : undefined;
|
|
54
|
+
const ran = await docker(["context", "inspect", "--format", "{{json .Endpoints.docker.Host}}"]);
|
|
55
|
+
if (ran.code !== 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
let endpoint;
|
|
25
58
|
try {
|
|
26
|
-
|
|
27
|
-
return typeof paths?.at === "string" && typeof paths.volume === "string" ? { at: paths.at, volume: paths.volume } : undefined;
|
|
59
|
+
endpoint = JSON.parse(ran.stdout.trim());
|
|
28
60
|
}
|
|
29
61
|
catch {
|
|
30
62
|
return undefined;
|
|
31
63
|
}
|
|
64
|
+
return typeof endpoint === "string" && remoteEndpoint(endpoint) ? endpoint : undefined;
|
|
65
|
+
}
|
|
66
|
+
/** remoteDockerOf, once per process for each environment's docker. */
|
|
67
|
+
const remotes = new Map();
|
|
68
|
+
export function remoteDockerOnce(env) {
|
|
69
|
+
const key = [env.PATH, env.DOCKER_HOST, env.DOCKER_CONTEXT, env.DOCKER_CONFIG].map((one) => one ?? "").join("\0");
|
|
70
|
+
let known = remotes.get(key);
|
|
71
|
+
if (!known)
|
|
72
|
+
remotes.set(key, (known = remoteDockerOf(env)));
|
|
73
|
+
return known;
|
|
74
|
+
}
|
|
75
|
+
/** Why this server can't run a Docker computer, or undefined when it can: on its Docker's own host (`here`), or in a
|
|
76
|
+
* container of that Docker's with its data on a named volume (`paths`: the computer mounts the run's folder and its
|
|
77
|
+
* daemon as that volume's subpaths, workspace/computer-deps.ts dockerVolumeOf). Any other layout says why (`reason`,
|
|
78
|
+
* dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint). The one check every
|
|
79
|
+
* reader of Docker's offer takes. */
|
|
80
|
+
export function dockerComputerRefusal(paths, remote) {
|
|
81
|
+
if ("reason" in paths)
|
|
82
|
+
return paths.reason;
|
|
83
|
+
return remote !== undefined ? remoteDockerWords(remote) : undefined;
|
|
84
|
+
}
|
|
85
|
+
/** Where a runner's Docker has the data directory `data`, read once by the runner that makes a Docker computer: as the
|
|
86
|
+
* server reads it at its start (dockerPathsOf), on Linux alone; under `--faux` from the mountinfo file the tests name
|
|
87
|
+
* (FAUX_MOUNTINFO_ENV), else as a host. */
|
|
88
|
+
export async function dockerPathsForRuns(env, data, platform = process.platform) {
|
|
89
|
+
if (platform !== "linux")
|
|
90
|
+
return { here: true };
|
|
91
|
+
if (env[FAUX_ENV]) {
|
|
92
|
+
const faux = env[FAUX_MOUNTINFO_ENV];
|
|
93
|
+
return faux ? dockerPathsOf(env, data, { mountinfo: await readFile(faux, "utf8"), inContainer: true }) : { here: true };
|
|
94
|
+
}
|
|
95
|
+
return dockerPathsOf(env, data);
|
|
32
96
|
}
|
|
97
|
+
/** Under `--faux` only: a file the server reads as its /proc/self/mountinfo (server.ts fauxMountinfo). */
|
|
98
|
+
export const FAUX_MOUNTINFO_ENV = "AGENTRUN_SERVE_FAUX_MOUNTINFO";
|
|
99
|
+
/** What the server hands a run's process: the paths, as JSON; empty on a host. */
|
|
100
|
+
export const RUN_BOX_PATHS_ENV = "AGENTRUN_RUN_BOX_PATHS";
|
|
33
101
|
/** The directory the runs' egress proxy sockets are in, for a server in a container: on its data volume, so a box can
|
|
34
102
|
* mount its run's (box-egress.ts egressDir). */
|
|
35
103
|
export const egressParentOf = (data) => `${data}/box-egress`;
|
package/dist/box-relay.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { vmRelay } from "./box-relay-vm.js";
|
|
2
2
|
/** The relay's address in the data directory: `{"url": "http://<loopback>:<port>"}`. */
|
|
3
3
|
export declare const BOX_RELAY_FILE = ".box-relay";
|
|
4
|
-
/** What a run's Daytona provider sends as its key: never a key. The relay sends the server's in its place. */
|
|
5
|
-
export declare const RELAYED_KEY = "relayed-by-the-server";
|
|
6
4
|
export type BoxRelayOptions = {
|
|
7
5
|
/** The data directory: where the relay's address goes. */
|
|
8
6
|
root: string;
|
|
@@ -36,12 +34,3 @@ export declare function relayAddress(root: string, runDir: string): Promise<{
|
|
|
36
34
|
url: string;
|
|
37
35
|
token: string;
|
|
38
36
|
}>;
|
|
39
|
-
/** The `fetch` a run's Daytona provider uses: each call goes to the relay, which sends it on with the key. */
|
|
40
|
-
export declare const relayFetch: (root: string, runDir: string, runId: string) => typeof fetch;
|
|
41
|
-
/** Asks the relay for run `runId`'s box: made and seeded by the server when it has none. */
|
|
42
|
-
export declare function relayedBox(root: string, runDir: string, runId: string, signal?: AbortSignal): Promise<{
|
|
43
|
-
id: string;
|
|
44
|
-
made: boolean;
|
|
45
|
-
replaced?: boolean;
|
|
46
|
-
apiUrl?: string;
|
|
47
|
-
}>;
|
package/dist/box-relay.js
CHANGED
|
@@ -19,8 +19,6 @@ import { readJson, RUN_DOOR_TOKEN, writeWhole } from "./files.js";
|
|
|
19
19
|
export const BOX_RELAY_FILE = ".box-relay";
|
|
20
20
|
/** Where the relay listens: only this machine's runs reach it. */
|
|
21
21
|
const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule the relay listens on loopback only, for the runs of this machine
|
|
22
|
-
/** What a run's Daytona provider sends as its key: never a key. The relay sends the server's in its place. */
|
|
23
|
-
export const RELAYED_KEY = "relayed-by-the-server";
|
|
24
22
|
/** The header that names the Daytona URL a relayed call is for. */
|
|
25
23
|
const TARGET = "x-agentrun-target";
|
|
26
24
|
/** The label that names a box's run (run-box.ts RUN_LABEL), kept here so the run's process loads no more than it needs. */
|
|
@@ -207,21 +205,3 @@ export async function relayAddress(root, runDir) {
|
|
|
207
205
|
throw new Error("this server's box relay is not running, and a run reaches its remote box only through it");
|
|
208
206
|
return { url, token: token.trim() };
|
|
209
207
|
}
|
|
210
|
-
/** The `fetch` a run's Daytona provider uses: each call goes to the relay, which sends it on with the key. */
|
|
211
|
-
export const relayFetch = (root, runDir, runId) => (async (input, init) => {
|
|
212
|
-
const { url, token } = await relayAddress(root, runDir);
|
|
213
|
-
const headers = new Headers(init?.headers);
|
|
214
|
-
headers.set("authorization", `Bearer ${token}`);
|
|
215
|
-
headers.set(TARGET, input instanceof Request ? input.url : String(input));
|
|
216
|
-
return fetch(`${url}/runs/${encodeURIComponent(runId)}/daytona`, { ...init, headers });
|
|
217
|
-
});
|
|
218
|
-
/** Asks the relay for run `runId`'s box: made and seeded by the server when it has none. */
|
|
219
|
-
export async function relayedBox(root, runDir, runId, signal) {
|
|
220
|
-
const { url, token } = await relayAddress(root, runDir);
|
|
221
|
-
const sent = await fetch(`${url}/runs/${encodeURIComponent(runId)}/box`, { method: "POST", headers: { authorization: `Bearer ${token}` }, redirect: "error", ...(signal ? { signal } : {}) });
|
|
222
|
-
const body = (await sent.json().catch(() => null));
|
|
223
|
-
if (!sent.ok || typeof body?.id !== "string") {
|
|
224
|
-
throw new Error(`the server did not give the run its box: ${typeof body?.message === "string" ? body.message : `it answered ${sent.status}`}`);
|
|
225
|
-
}
|
|
226
|
-
return { id: body.id, made: body.made === true, ...(body.replaced === true ? { replaced: true } : {}), ...(typeof body.api_url === "string" ? { apiUrl: body.api_url } : {}) };
|
|
227
|
-
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BoxProvider } from "@parcha/pi-transport";
|
|
2
|
+
import { type DockerNetwork, egressBlockedBy } from "./box-egress.js";
|
|
3
|
+
/** The settings that bound a Docker box; unset, their defaults: enough for a build, and safe on a laptop, where one run's
|
|
4
|
+
* runaway build or fork bomb would otherwise starve everything else. */
|
|
5
|
+
export declare const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
6
|
+
export declare const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
7
|
+
export declare const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
8
|
+
/** 2 CPUs' time: a CFS quota (pi-transport's Docker provider), which holds whatever CPU count Docker's VM has. */
|
|
9
|
+
export declare const DEFAULT_BOX_CPUS = 2;
|
|
10
|
+
/** 4 GiB, swap included (--memory-swap the same). */
|
|
11
|
+
export declare const DEFAULT_BOX_MEMORY = "4g";
|
|
12
|
+
/** Processes and threads at once. */
|
|
13
|
+
export declare const DEFAULT_BOX_PIDS = 1024;
|
|
14
|
+
/** A Docker box's limits, as pi-transport's Docker provider takes them. */
|
|
15
|
+
export type BoxLimits = {
|
|
16
|
+
cpus: number;
|
|
17
|
+
memory: string;
|
|
18
|
+
pidsLimit: number;
|
|
19
|
+
};
|
|
20
|
+
/** A Docker box's limits from `env`: each setting's value, or its default when unset or empty. A value that is not one, or
|
|
21
|
+
* that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
|
|
22
|
+
* allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
|
|
23
|
+
export declare function boxLimitsOf(env: NodeJS.ProcessEnv): BoxLimits;
|
|
24
|
+
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
25
|
+
export declare const memoryMbOf: (memory: string) => number;
|
|
26
|
+
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
27
|
+
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
28
|
+
export declare const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
29
|
+
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
30
|
+
* GitHub for a clone or an archive. */
|
|
31
|
+
export declare const DEFAULT_BOX_ALLOW: readonly string[];
|
|
32
|
+
/** The most hosts the list may hold: Daytona's own limit on a sandbox's domain list. */
|
|
33
|
+
export declare const MAX_BOX_ALLOW = 100;
|
|
34
|
+
/** The hosts a box may reach, from `env`'s AGENTRUN_BOX_ALLOW: its list, lower-cased, each host once; the default list when
|
|
35
|
+
* unset or empty; `none` for no network. `*`, an IP address, a CIDR, a port, a URL, or more than 100 hosts throws, saying
|
|
36
|
+
* what the setting takes: the start checks it (startServe), so no run meets one. */
|
|
37
|
+
export declare function boxAllowOf(env: NodeJS.ProcessEnv): readonly string[] | "none";
|
|
38
|
+
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
39
|
+
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
40
|
+
* it as the reason. */
|
|
41
|
+
export declare function boxNetworkOf(env: NodeJS.ProcessEnv, options?: Parameters<typeof egressBlockedBy>[1]): Promise<DockerNetwork>;
|
|
42
|
+
/** Under `--faux` only: a module whose default export, given the data root, is the provider the tests' faux box comes
|
|
43
|
+
* from in place of Docker. */
|
|
44
|
+
export declare const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
45
|
+
/** The tests' faux box provider, from its module. */
|
|
46
|
+
export declare const fauxBoxes: (module: string, root: string) => Promise<BoxProvider>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// A box's settings as the server reads them at its start: a Docker box's limits (AGENTRUN_BOX_CPUS, _MEMORY, _PIDS), the
|
|
2
|
+
// hosts a box may reach (AGENTRUN_BOX_ALLOW) and what a server's Docker boxes reach from them, and, under `--faux` only,
|
|
3
|
+
// the tests' faux box provider. A setting that is not one throws, naming it: the start checks each, so no run meets one.
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { egressBlockedBy } from "./box-egress.js";
|
|
6
|
+
import { vmDocker } from "./box-egress-vm.js";
|
|
7
|
+
/** The settings that bound a Docker box; unset, their defaults: enough for a build, and safe on a laptop, where one run's
|
|
8
|
+
* runaway build or fork bomb would otherwise starve everything else. */
|
|
9
|
+
export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
10
|
+
export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
11
|
+
export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
12
|
+
/** 2 CPUs' time: a CFS quota (pi-transport's Docker provider), which holds whatever CPU count Docker's VM has. */
|
|
13
|
+
export const DEFAULT_BOX_CPUS = 2;
|
|
14
|
+
/** 4 GiB, swap included (--memory-swap the same). */
|
|
15
|
+
export const DEFAULT_BOX_MEMORY = "4g";
|
|
16
|
+
/** Processes and threads at once. */
|
|
17
|
+
export const DEFAULT_BOX_PIDS = 1024;
|
|
18
|
+
/** The fewest CPUs a quota gives: the kernel's least quota is 1 ms of each 100 ms period. A quota is also a whole number of
|
|
19
|
+
* µs, so a count too large for one (or a long string of digits, which reads as Infinity) is refused too. */
|
|
20
|
+
const MIN_BOX_CPUS = 0.01;
|
|
21
|
+
const MIB = 1024 * 1024;
|
|
22
|
+
/** A size's units as Docker reads them, each 1024 of the one before. */
|
|
23
|
+
const SIZE_UNITS = { b: 1, k: 1024, m: MIB, g: 1024 * MIB };
|
|
24
|
+
/** The least memory Docker gives a container. */
|
|
25
|
+
const MIN_BOX_MEMORY = 6 * MIB;
|
|
26
|
+
/** The most processes a cgroup may be given (the kernel's PID_MAX_LIMIT); above it, every create fails. */
|
|
27
|
+
const MAX_BOX_PIDS = 4_194_304;
|
|
28
|
+
/** A Docker box's limits from `env`: each setting's value, or its default when unset or empty. A value that is not one, or
|
|
29
|
+
* that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
|
|
30
|
+
* allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
|
|
31
|
+
export function boxLimitsOf(env) {
|
|
32
|
+
const read = (name, what, takes) => {
|
|
33
|
+
const value = env[name];
|
|
34
|
+
if (!value)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (!takes(value))
|
|
37
|
+
throw new Error(`${name} is ${what}; it is ${JSON.stringify(value)}`);
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
const cpus = read(BOX_CPUS_ENV, "a number of CPUs of at least 0.01, such as 2 or 1.5", (value) => /^\d+(\.\d+)?$/.test(value) && Number(value) >= MIN_BOX_CPUS && Number.isSafeInteger(Math.round(Number(value) * 100_000)));
|
|
41
|
+
const memory = read(BOX_MEMORY_ENV, "a size of at least 6m with its unit (b, k, m or g), such as 512m or 4g", (value) => {
|
|
42
|
+
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(value);
|
|
43
|
+
// Its bytes as Docker reads them, and pi-transport's Docker provider: the number times the unit, the fraction dropped.
|
|
44
|
+
const bytes = size ? Math.floor(Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) : 0;
|
|
45
|
+
return Number.isSafeInteger(bytes) && bytes >= MIN_BOX_MEMORY;
|
|
46
|
+
});
|
|
47
|
+
const pids = read(BOX_PIDS_ENV, "a whole number from 1 to 4194304, such as 1024", (value) => /^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_BOX_PIDS);
|
|
48
|
+
return { cpus: cpus === undefined ? DEFAULT_BOX_CPUS : Number(cpus), memory: memory ?? DEFAULT_BOX_MEMORY, pidsLimit: pids === undefined ? DEFAULT_BOX_PIDS : Number(pids) };
|
|
49
|
+
}
|
|
50
|
+
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
51
|
+
export const memoryMbOf = (memory) => {
|
|
52
|
+
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(memory);
|
|
53
|
+
return size ? Math.floor((Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) / MIB) : 0;
|
|
54
|
+
};
|
|
55
|
+
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
56
|
+
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
57
|
+
export const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
58
|
+
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
59
|
+
* GitHub for a clone or an archive. */
|
|
60
|
+
export const DEFAULT_BOX_ALLOW = Object.freeze(["pypi.org", "files.pythonhosted.org", "registry.npmjs.org", "registry.yarnpkg.com", "github.com", "codeload.github.com"]);
|
|
61
|
+
/** The most hosts the list may hold: Daytona's own limit on a sandbox's domain list. */
|
|
62
|
+
export const MAX_BOX_ALLOW = 100;
|
|
63
|
+
/** A host name, or `*.` and one: letters, digits and hyphens in dotted labels, the last one starting with a letter, so no
|
|
64
|
+
* IP address is one. */
|
|
65
|
+
const ALLOW_HOST = /^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
66
|
+
/** The hosts a box may reach, from `env`'s AGENTRUN_BOX_ALLOW: its list, lower-cased, each host once; the default list when
|
|
67
|
+
* unset or empty; `none` for no network. `*`, an IP address, a CIDR, a port, a URL, or more than 100 hosts throws, saying
|
|
68
|
+
* what the setting takes: the start checks it (startServe), so no run meets one. */
|
|
69
|
+
export function boxAllowOf(env) {
|
|
70
|
+
const value = (env[BOX_ALLOW_ENV] ?? "").trim();
|
|
71
|
+
if (!value)
|
|
72
|
+
return DEFAULT_BOX_ALLOW;
|
|
73
|
+
if (value.toLowerCase() === "none")
|
|
74
|
+
return "none";
|
|
75
|
+
const hosts = [...new Set(value.split(",").map((host) => host.trim().toLowerCase()).filter(Boolean))];
|
|
76
|
+
const takes = "a comma list of host names (such as pypi.org or *.pythonhosted.org), or none for no network";
|
|
77
|
+
const bad = hosts.find((host) => !ALLOW_HOST.test(host));
|
|
78
|
+
if (bad !== undefined)
|
|
79
|
+
throw new Error(`${BOX_ALLOW_ENV} is ${takes}: ${JSON.stringify(bad)} is not a host name${bad === "*" ? " (a box never reaches every host)" : ""}`);
|
|
80
|
+
if (hosts.length === 0)
|
|
81
|
+
throw new Error(`${BOX_ALLOW_ENV} is ${takes}; it is ${JSON.stringify(value)}`);
|
|
82
|
+
if (hosts.length > MAX_BOX_ALLOW)
|
|
83
|
+
throw new Error(`${BOX_ALLOW_ENV} names ${hosts.length} hosts; it takes at most ${MAX_BOX_ALLOW}`);
|
|
84
|
+
return Object.freeze(hosts);
|
|
85
|
+
}
|
|
86
|
+
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
87
|
+
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
88
|
+
* it as the reason. */
|
|
89
|
+
export async function boxNetworkOf(env, options = {}) {
|
|
90
|
+
const allow = boxAllowOf(env);
|
|
91
|
+
if (allow === "none")
|
|
92
|
+
return { allow: "none", reason: `${BOX_ALLOW_ENV} is none` };
|
|
93
|
+
const blocked = await egressBlockedBy(env, options);
|
|
94
|
+
if (!blocked)
|
|
95
|
+
return { allow };
|
|
96
|
+
// On a Mac only: a Docker that docker info names as a VM runtime this server knows gets the proxy container
|
|
97
|
+
// (box-egress-vm.ts); any other stays none, saying why.
|
|
98
|
+
if ((options.platform ?? process.platform) !== "darwin")
|
|
99
|
+
return { allow: "none", reason: blocked };
|
|
100
|
+
const vm = await vmDocker(env, { ...(options.platform ? { platform: options.platform } : {}), ...(options.kernel ? { kernel: options.kernel } : {}), ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}) });
|
|
101
|
+
return "runtime" in vm ? { allow, vm: vm.runtime } : { allow: "none", reason: vm.reason };
|
|
102
|
+
}
|
|
103
|
+
/** Under `--faux` only: a module whose default export, given the data root, is the provider the tests' faux box comes
|
|
104
|
+
* from in place of Docker. */
|
|
105
|
+
export const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
106
|
+
/** The tests' faux box provider, from its module. */
|
|
107
|
+
export const fauxBoxes = async (module, root) => (await import(pathToFileURL(module).href)).default(root);
|
package/dist/boxes.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ export type BoxId = (typeof BOX_IDS)[number];
|
|
|
16
16
|
* more than the probe did (box-image.ts): `preparing` is available, its image still coming. */
|
|
17
17
|
/** A box as capabilities show it. `network`: what an available box reaches (BOX_NETWORKS), with `network_reason` when
|
|
18
18
|
* it is available and has none for a cause of its own (a Docker in a VM, a daemon elsewhere; a Daytona that could not
|
|
19
|
-
* keep its domain list).
|
|
19
|
+
* keep its domain list). `host_addresses`: for Docker from a container (compose.yaml), the Docker host's own addresses
|
|
20
|
+
* its computers' egress proxy refuses as the host's (docker-host-addresses.ts: the read through the socket and
|
|
21
|
+
* AGENTRUN_DOCKER_HOST_ADDRESSES). */
|
|
20
22
|
export type BoxOffer = {
|
|
21
23
|
id: BoxId;
|
|
22
24
|
available: boolean;
|
|
@@ -24,6 +26,7 @@ export type BoxOffer = {
|
|
|
24
26
|
reason?: string;
|
|
25
27
|
network?: BoxNetwork;
|
|
26
28
|
network_reason?: string;
|
|
29
|
+
host_addresses?: string[];
|
|
27
30
|
};
|
|
28
31
|
/** What an available box reaches: the hosts of `places.allow` (`allowlist`), or nothing (`none`). */
|
|
29
32
|
export declare const BOX_NETWORKS: readonly ["allowlist", "none"];
|
package/dist/browser-cost.js
CHANGED
|
@@ -63,7 +63,8 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
63
63
|
const refused = capped ? String(error.message) : `${name} could not be held: ${String(error?.message ?? error)}`;
|
|
64
64
|
// The cap's own refusal, as the run's pause reads it (a room refusal's figures; a refusal for good).
|
|
65
65
|
const given = error;
|
|
66
|
-
|
|
66
|
+
// Its code rides with it (Refusal.code): the model request the pause refuses next is the cap's refusal.
|
|
67
|
+
return { refused, ...(capped ? { refusal: { refuse: refused, code: SPEND_CAP_REACHED, forGood: given.forGood ?? true, ...(given.figures ? { figures: given.figures } : {}) } } : {}) };
|
|
67
68
|
});
|
|
68
69
|
pending.add(admitted);
|
|
69
70
|
void admitted.finally(() => pending.delete(admitted));
|
package/dist/browser-person.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** pi-browser's tool for the agent's ask. */
|
|
2
|
-
export declare const HANDOFF_TOOL = "browser_request_handoff";
|
|
3
1
|
/** The ask's directory in the run's directory (never in work/). */
|
|
4
2
|
export declare const BROWSER_ASK_DIR = "browser-ask";
|
|
5
3
|
/** How long a person's time lasts at most before it expires: an unanswered ask, and a take-over with no input. Its worth of session time is held up front. */
|
package/dist/browser-person.js
CHANGED
|
@@ -21,8 +21,6 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
21
21
|
import { closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
22
22
|
import { join } from "node:path";
|
|
23
23
|
import { HOST_PHASE } from "@parcha/pi-durable-agent/timeline";
|
|
24
|
-
/** pi-browser's tool for the agent's ask. */
|
|
25
|
-
export const HANDOFF_TOOL = "browser_request_handoff";
|
|
26
24
|
/** The ask's directory in the run's directory (never in work/). */
|
|
27
25
|
export const BROWSER_ASK_DIR = "browser-ask";
|
|
28
26
|
/** How long a person's time lasts at most before it expires: an unanswered ask, and a take-over with no input. Its worth of session time is held up front. */
|
package/dist/budget.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ export declare const CAP_RAISED = "cap.json";
|
|
|
4
4
|
export declare const CAP_STOPPED = "cap-stopped.json";
|
|
5
5
|
/** How long a workflow run's pause keeps its process before it lets it go (the lead's ruling: 10 minutes). */
|
|
6
6
|
export declare const BUDGET_HOLD_MS: number;
|
|
7
|
-
/** The process's environment variable naming another hold, in ms (the server's `budgetHold` option, for its tests). */
|
|
8
|
-
export declare const BUDGET_HOLD_ENV = "AGENTRUN_SERVE_BUDGET_HOLD_MS";
|
|
9
7
|
/** Where a step stands in its workflow: its node's label and execution path. */
|
|
10
8
|
export type StepAt = {
|
|
11
9
|
label: string;
|
|
@@ -40,8 +38,6 @@ export declare class CapStop extends Error {
|
|
|
40
38
|
}
|
|
41
39
|
/** The pause the run at `root` stands at, as its process wrote it; undefined when it waits at none. */
|
|
42
40
|
export declare const budgetPausedIn: (root: string) => BudgetMark | undefined;
|
|
43
|
-
/** The refusal that ended the run at `root` for good, as its process wrote it; undefined when none did. */
|
|
44
|
-
export declare const capStoppedIn: (root: string) => CapStopped | undefined;
|
|
45
41
|
/** A raise's cap, for the run's process to read (the server writes it after serve.json keeps it). */
|
|
46
42
|
export declare const writeRaisedCap: (root: string, usd: number) => void;
|
|
47
43
|
/** The pause's mark taken away: a raise sent its run on, here when no process waits at it (it was let go). */
|
package/dist/budget.js
CHANGED
|
@@ -24,8 +24,6 @@ export const CAP_RAISED = "cap.json";
|
|
|
24
24
|
export const CAP_STOPPED = "cap-stopped.json";
|
|
25
25
|
/** How long a workflow run's pause keeps its process before it lets it go (the lead's ruling: 10 minutes). */
|
|
26
26
|
export const BUDGET_HOLD_MS = 10 * 60_000;
|
|
27
|
-
/** The process's environment variable naming another hold, in ms (the server's `budgetHold` option, for its tests). */
|
|
28
|
-
export const BUDGET_HOLD_ENV = "AGENTRUN_SERVE_BUDGET_HOLD_MS";
|
|
29
27
|
const POLL_MS = 250;
|
|
30
28
|
/** A step its cap refused for good: thrown where the step stood, never an item's failure (it is no EffectFailure and
|
|
31
29
|
* declares no itemFailure), so the workflow fails on it and the server reads `cap-stopped.json`. */
|
|
@@ -57,11 +55,6 @@ export const budgetPausedIn = (root) => {
|
|
|
57
55
|
const mark = readJson(join(root, BUDGET_PAUSE));
|
|
58
56
|
return mark && typeof mark.words === "string" && typeof mark.cap_usd === "number" ? mark : undefined;
|
|
59
57
|
};
|
|
60
|
-
/** The refusal that ended the run at `root` for good, as its process wrote it; undefined when none did. */
|
|
61
|
-
export const capStoppedIn = (root) => {
|
|
62
|
-
const stop = readJson(join(root, CAP_STOPPED));
|
|
63
|
-
return stop && typeof stop.words === "string" ? stop : undefined;
|
|
64
|
-
};
|
|
65
58
|
/** A raise's cap, for the run's process to read (the server writes it after serve.json keeps it). */
|
|
66
59
|
export const writeRaisedCap = (root, usd) => writeWhole(join(root, CAP_RAISED), { max_cost_usd: usd });
|
|
67
60
|
/** The pause's mark taken away: a raise sent its run on, here when no process waits at it (it was let go). */
|
package/dist/cap.d.ts
CHANGED
|
@@ -29,8 +29,6 @@ export declare const CAP_MODES: readonly ["expected", "strict"];
|
|
|
29
29
|
export type CapMode = (typeof CAP_MODES)[number];
|
|
30
30
|
/** A run's cap mode, passed to its process; absent is "expected". */
|
|
31
31
|
export declare const CAP_MODE_ENV = "AGENTRUN_SERVE_CAP_MODE";
|
|
32
|
-
/** The run's cap mode from its process's environment. */
|
|
33
|
-
export declare function capModeOf(env: NodeJS.ProcessEnv): CapMode;
|
|
34
32
|
/** How long after a request ended the next one in its conversation is expected to read its cache: 4 minutes, inside
|
|
35
33
|
* Anthropic's 5 (a cache kept that long from its last use; OpenAI's lasts longer). A request later than that is priced
|
|
36
34
|
* with nothing cached. */
|
|
@@ -192,8 +190,6 @@ export type SideRequest = {
|
|
|
192
190
|
feeUsd(): number;
|
|
193
191
|
};
|
|
194
192
|
export declare const sideRequests: WeakMap<object, SideRequest>;
|
|
195
|
-
/** The run's cap from its process's environment; absent for a run without one. */
|
|
196
|
-
export declare function capOf(env: NodeJS.ProcessEnv): number | undefined;
|
|
197
193
|
/** The code a cap's refusal begins with: `spend_cap_reached: `, or with a note after it, as a request it limited refuses
|
|
198
194
|
* in (CAP_REFUSAL_CODE, "spend_cap_reached (out of budget): "). Every reader of a refusal's text (a run's end, its
|
|
199
195
|
* learning, the spend read back) reads the code through this, never a bare prefix. */
|
|
@@ -414,9 +410,6 @@ export type RefusalFigures = {
|
|
|
414
410
|
leastCapUsd: number;
|
|
415
411
|
boundUsd?: number;
|
|
416
412
|
};
|
|
417
|
-
/** A refusal's figures as its start mark keeps them (`spentUsd`, `needsUsd`, `leastCapUsd`, and `boundUsd` when above 0);
|
|
418
|
-
* none without. */
|
|
419
|
-
export declare const refusalFields: (figures: RefusalFigures | undefined) => Record<string, number>;
|
|
420
413
|
/** The words of a refusal for room (CAP_REFUSAL_CODE: what is left of the cap cannot buy the request's least), which a
|
|
421
414
|
* higher cap would send; undefined for any other text, a refusal no cap could fix included (an unknown spend, no price,
|
|
422
415
|
* no output ceiling, an input not measured: the bare `spend_cap_reached: ` code). The one reader of that difference. */
|
package/dist/cap.js
CHANGED
|
@@ -77,15 +77,6 @@ export const BOUND_FIELD = "boundUsd";
|
|
|
77
77
|
export const CAP_MODES = ["expected", "strict"];
|
|
78
78
|
/** A run's cap mode, passed to its process; absent is "expected". */
|
|
79
79
|
export const CAP_MODE_ENV = "AGENTRUN_SERVE_CAP_MODE";
|
|
80
|
-
/** The run's cap mode from its process's environment. */
|
|
81
|
-
export function capModeOf(env) {
|
|
82
|
-
const text = env[CAP_MODE_ENV];
|
|
83
|
-
if (text === undefined || text === "")
|
|
84
|
-
return "expected";
|
|
85
|
-
if (!CAP_MODES.includes(text))
|
|
86
|
-
throw new Error(`${CAP_MODE_ENV} is ${text}, not one of ${CAP_MODES.join(", ")}`);
|
|
87
|
-
return text;
|
|
88
|
-
}
|
|
89
80
|
/** How long after a request ended the next one in its conversation is expected to read its cache: 4 minutes, inside
|
|
90
81
|
* Anthropic's 5 (a cache kept that long from its last use; OpenAI's lasts longer). A request later than that is priced
|
|
91
82
|
* with nothing cached. */
|
|
@@ -313,16 +304,6 @@ const endUnrecorded = (entry) => {
|
|
|
313
304
|
* search's results are billed as input, about 25,000 tokens a search as a working estimate. */
|
|
314
305
|
export const NATIVE_SEARCH_ALLOWANCE_TOKENS = 8 * 25_000;
|
|
315
306
|
export const sideRequests = new WeakMap();
|
|
316
|
-
/** The run's cap from its process's environment; absent for a run without one. */
|
|
317
|
-
export function capOf(env) {
|
|
318
|
-
const text = env[CAP_ENV];
|
|
319
|
-
if (text === undefined || text === "")
|
|
320
|
-
return undefined;
|
|
321
|
-
const cap = Number(text);
|
|
322
|
-
if (!(Number.isFinite(cap) && cap > 0))
|
|
323
|
-
throw new Error(`${CAP_ENV} is ${text}, not a number above 0`);
|
|
324
|
-
return cap;
|
|
325
|
-
}
|
|
326
307
|
/** The code a cap's refusal begins with: `spend_cap_reached: `, or with a note after it, as a request it limited refuses
|
|
327
308
|
* in (CAP_REFUSAL_CODE, "spend_cap_reached (out of budget): "). Every reader of a refusal's text (a run's end, its
|
|
328
309
|
* learning, the spend read back) reads the code through this, never a bare prefix. */
|
|
@@ -925,9 +906,6 @@ export function money(usd) {
|
|
|
925
906
|
* which pi-ai's retry (isRetryableAssistantError, which reads only an error's text) takes as final whatever digits the
|
|
926
907
|
* words after it hold. The words after it are the ones a person reads. */
|
|
927
908
|
export const CAP_REFUSAL_CODE = `${SPEND_CAP_REACHED} (out of budget): `;
|
|
928
|
-
/** A refusal's figures as its start mark keeps them (`spentUsd`, `needsUsd`, `leastCapUsd`, and `boundUsd` when above 0);
|
|
929
|
-
* none without. */
|
|
930
|
-
export const refusalFields = (figures) => figures ? { spentUsd: figures.spentUsd, needsUsd: figures.needsUsd, leastCapUsd: figures.leastCapUsd, ...(typeof figures.boundUsd === "number" && figures.boundUsd > 0 ? { boundUsd: figures.boundUsd } : {}) } : {};
|
|
931
909
|
/** The words of a refusal for room (CAP_REFUSAL_CODE: what is left of the cap cannot buy the request's least), which a
|
|
932
910
|
* higher cap would send; undefined for any other text, a refusal no cap could fix included (an unknown spend, no price,
|
|
933
911
|
* no output ceiling, an input not measured: the bare `spend_cap_reached: ` code). The one reader of that difference. */
|
package/dist/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import { resetPassword } from "./owner.js";
|
|
|
17
17
|
import { banner, boxImageLine } from "./print.js";
|
|
18
18
|
import { DEFAULT_PORT, fauxEnvOf, startServe } from "./server.js";
|
|
19
19
|
import { runnerBeside } from "./runner/beside.js";
|
|
20
|
+
import { apiOnlyFrom } from "./api-only.js";
|
|
20
21
|
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
|
|
21
22
|
agentrun-serve reset-password [--data DIR]
|
|
22
23
|
agentrun-serve validate-template DIR
|
|
@@ -62,6 +63,10 @@ printed only by the start that made it. AGENTRUN_PUBLIC_URL, when set, is the ad
|
|
|
62
63
|
published port, or a proxy's URL), and the link printed uses it; with none, Render's RENDER_EXTERNAL_URL is. stdout gets one line per request, per run start and
|
|
63
64
|
end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
|
|
64
65
|
|
|
66
|
+
AGENTRUN_API_ONLY=1 serves the run routes alone, for a server behind its caller's backend: a run's launch, read, list,
|
|
67
|
+
timeline, messages, stop, cancel, kill and cap raise, its files and uploads, capabilities, health and usage. Every other
|
|
68
|
+
address (the page, sign-in, setup, settings, MCP, triggers and their hooks, agents) is a 404, and there are no accounts.
|
|
69
|
+
|
|
65
70
|
The page is for one person, who signs in with a password (AGENTRUN_ACCOUNTS=0 turns this off; the token works for
|
|
66
71
|
scripts and the CLI either way). With no AGENTRUN_PUBLIC_URL, listening on loopback, the first visit to the page sets the
|
|
67
72
|
password; with it, or on any other address, the setup link this server prints carries a code. Sign-in tries are limited
|
|
@@ -286,7 +291,16 @@ const data = values.data ?? defaultData();
|
|
|
286
291
|
const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
287
292
|
// A stdout its reader closed (a pipe left behind) loses the log lines, never the server.
|
|
288
293
|
process.stdout.on("error", () => undefined);
|
|
289
|
-
|
|
294
|
+
// AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
|
|
295
|
+
let apiOnly;
|
|
296
|
+
try {
|
|
297
|
+
apiOnly = apiOnlyFrom(process.env);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.error(`${error.message}\n\n${USAGE}`);
|
|
301
|
+
process.exit(2);
|
|
302
|
+
}
|
|
303
|
+
const accounts = !apiOnly && process.env.AGENTRUN_ACCOUNTS !== "0";
|
|
290
304
|
// The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
|
|
291
305
|
// before the banner is printed waits for it.
|
|
292
306
|
let imageSaid = false;
|
|
@@ -315,7 +329,7 @@ try {
|
|
|
315
329
|
...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
|
|
316
330
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
317
331
|
...(publicUrl ? { publicUrl } : {}),
|
|
318
|
-
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}),
|
|
332
|
+
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}),
|
|
319
333
|
// The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
|
|
320
334
|
...(trustedProxies.length ? { trustedProxies } : {}),
|
|
321
335
|
});
|
|
@@ -332,10 +346,10 @@ if (!values["no-runner"]) {
|
|
|
332
346
|
try {
|
|
333
347
|
// The beside-runner sees the server's test switches (server.ts fauxEnvOf: --faux and its modules), which the CLI hands
|
|
334
348
|
// the server as options, never through this process's environment: without them a --faux start's runner looks its faux
|
|
335
|
-
// model up in pi-ai's own catalog and every run fails on its first request.
|
|
336
|
-
// its
|
|
337
|
-
const {
|
|
338
|
-
runnerProc = await runnerBeside(data, { env:
|
|
349
|
+
// model up in pi-ai's own catalog and every run fails on its first request. A test switch this process inherited from
|
|
350
|
+
// its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
|
|
351
|
+
const { besideRunEnv } = await import("./runner/main.js");
|
|
352
|
+
runnerProc = await runnerBeside(data, { env: besideRunEnv(process.env, fauxEnvOf(serveOptions)) });
|
|
339
353
|
}
|
|
340
354
|
catch (error) {
|
|
341
355
|
console.error(`agentrun-serve: the runner could not start: ${error.message}`);
|
|
@@ -345,7 +359,7 @@ if (!values["no-runner"]) {
|
|
|
345
359
|
}
|
|
346
360
|
// A token from the environment is the operator's already, and the stored one is printed by the start that made it only.
|
|
347
361
|
const source = given ? "env" : serve.tokenMade ? "made" : "file";
|
|
348
|
-
for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
|
|
362
|
+
for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, ...(apiOnly ? { apiOnly } : {}), boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
|
|
349
363
|
console.log(line);
|
|
350
364
|
// Open setup (no public address, a loopback listener): the link that sets the password. Any other start printed the
|
|
351
365
|
// setup link with its code as the code was made (owner.ts).
|
|
@@ -356,7 +370,8 @@ for (const line of early.splice(0))
|
|
|
356
370
|
console.log(line);
|
|
357
371
|
// The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
|
|
358
372
|
// and the browser's history.
|
|
359
|
-
|
|
373
|
+
// API-only: there is no console, so nothing to open.
|
|
374
|
+
if (values.open && !apiOnly && canOpen(process.env))
|
|
360
375
|
spawn(process.platform === "darwin" ? "open" : "xdg-open", [`${publicUrl ?? serve.url}/`], { stdio: "ignore", detached: true }).on("error", () => { }).unref();
|
|
361
376
|
const record = join(resolve(data), SERVER_FILE);
|
|
362
377
|
// The record goes only while it is this server's: a server that takes the lock next writes its own, which this stop must
|
package/dist/computers.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type FolderMode = "local" | "disk";
|
|
|
38
38
|
export interface ComputerRoutesOptions {
|
|
39
39
|
/** The server's one store: its sealed keys. */
|
|
40
40
|
readonly store: Pick<Store, "sealedKeys">;
|
|
41
|
-
/** The server's seal key: there is always one (seal-key.ts
|
|
41
|
+
/** The server's seal key: there is always one (seal-key.ts bootSealKey, at the start). */
|
|
42
42
|
readonly sealKey: Buffer;
|
|
43
43
|
readonly kinds: KindRegistry;
|
|
44
44
|
/** Each provider module's create(), by provider id (the computer package's): what a test and a claim make. */
|