@parcha/agentrun-serve 0.1.0-beta.30 → 0.1.0-beta.31
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 +50 -0
- package/README.md +182 -26
- package/dist/agents.d.ts +8 -3
- package/dist/agents.js +4 -1
- package/dist/app.js +23 -8
- package/dist/background.d.ts +2 -1
- package/dist/background.js +41 -20
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +3 -2
- package/dist/box-relay-vm.d.ts +4 -0
- package/dist/box-relay-vm.js +76 -55
- package/dist/boxes.d.ts +7 -2
- package/dist/boxes.js +30 -11
- package/dist/cap.d.ts +2 -1
- package/dist/cap.js +2 -1
- package/dist/cli.js +30 -4
- package/dist/console/assets/{index-34jfpIbQ.js → index-CnJBf7Lc.js} +90 -85
- package/dist/console/index.html +1 -1
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/files.d.ts +3 -0
- package/dist/files.js +3 -0
- package/dist/grade.d.ts +5 -2
- package/dist/grade.js +13 -5
- package/dist/harness-app.js +10 -1
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/grade.d.ts +3 -0
- package/dist/learn/grade.js +3 -1
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/reflect.js +2 -0
- package/dist/learn/skills.d.ts +2 -0
- package/dist/learn/skills.js +16 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +1 -1
- package/dist/learning-run.js +25 -4
- package/dist/learning-words.d.ts +7 -3
- package/dist/learning-words.js +26 -8
- package/dist/learning.d.ts +9 -1
- package/dist/learning.js +57 -2
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +26 -5
- package/dist/mcp-servers.js +53 -10
- package/dist/openapi.js +52 -9
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/place.d.ts +3 -2
- package/dist/place.js +11 -3
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/run-box.js +15 -5
- package/dist/runnable.d.ts +8 -1
- package/dist/runnable.js +51 -2
- package/dist/runs.d.ts +15 -8
- package/dist/runs.js +66 -13
- package/dist/secrets.d.ts +15 -0
- package/dist/secrets.js +20 -2
- package/dist/server.d.ts +10 -1
- package/dist/server.js +111 -29
- package/dist/tool-gate.d.ts +18 -3
- package/dist/tool-gate.js +44 -13
- package/dist/tool-keys.d.ts +2 -1
- package/dist/tool-keys.js +4 -8
- package/dist/tool-plane.d.ts +5 -1
- package/dist/tool-plane.js +30 -6
- package/dist/tools.js +8 -5
- package/dist/web-fetch.js +3 -3
- package/package.json +12 -16
package/dist/boxes.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
// server's settings and probed once at its start. bwrap comes later. The registry says which boxes this server has, why
|
|
3
3
|
// it lacks the others, and hands out an available box's provider (and the VM box's client, for the box relay).
|
|
4
4
|
//
|
|
5
|
-
// AGENTRUN_BOXES lists the boxes to set up.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// AGENTRUN_BOXES lists the boxes to set up. Not set at all, it is docker alone (DEFAULT_BOXES): a plain start probes
|
|
6
|
+
// Docker and offers it when Docker answers, so a new agent lands in its box (place.ts); every other box is the operator's
|
|
7
|
+
// to list. Set, it wins: a box it does not list is never probed and is unavailable, its reason naming the setting that
|
|
8
|
+
// lists it, an empty value or `none` sets up no box, and a name in it that is no box refuses the start. Every reason says
|
|
9
|
+
// what to do next.
|
|
10
|
+
// pi-transport is a dependency of this package (a plain install has the Docker box) and the VM provider's SDK is the
|
|
11
|
+
// host's; each is loaded by the
|
|
8
12
|
// probe that needs it, and a box whose module is not installed says what to install. The keys are the server's own: the
|
|
9
13
|
// launcher hands them over with its other secrets (secrets.ts), the probes read them here, and no run's process is
|
|
10
14
|
// handed one (SERVER_ONLY in runs.ts).
|
|
@@ -25,8 +29,12 @@ export const BOX_IDS = ["bwrap", "docker", VM, "daytona"];
|
|
|
25
29
|
export const BOX_NETWORKS = ["allowlist", "none"];
|
|
26
30
|
/** A box's state in capabilities: ready, preparing (available; a run's first box waits for its image), or unavailable. */
|
|
27
31
|
export const BOX_STATES = ["ready", "preparing", "unavailable"];
|
|
28
|
-
/** The setting that lists the boxes to set up: a comma list of box ids. */
|
|
32
|
+
/** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
|
|
29
33
|
export const BOXES_ENV = "AGENTRUN_BOXES";
|
|
34
|
+
/** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
|
|
35
|
+
export const DEFAULT_BOXES = ["docker"];
|
|
36
|
+
/** The AGENTRUN_BOXES that sets up no box, as an empty one does. */
|
|
37
|
+
const NO_BOXES = "none";
|
|
30
38
|
/** The VM provider's app, which its sandboxes live in (made when missing). */
|
|
31
39
|
export const BOX_APP_ENV = "AGENTRUN_BOX_APP";
|
|
32
40
|
const DEFAULT_BOX_APP = "agentrun";
|
|
@@ -50,9 +58,19 @@ const NOT_PROBED = "configured; not probed at start";
|
|
|
50
58
|
const TRANSPORT = "@parcha/pi-transport";
|
|
51
59
|
const unavailable = (id, reason) => ({ offer: { id, available: false, reason } });
|
|
52
60
|
const available = (id, provider, reason, client) => ({ offer: { id, available: true, ...(reason ? { reason } : {}) }, provider, ...(client === undefined ? {} : { client }) });
|
|
53
|
-
/**
|
|
61
|
+
/** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
|
|
62
|
+
export const boxesByDefault = (env) => env[BOXES_ENV] === undefined;
|
|
63
|
+
/** The boxes `env` lists in AGENTRUN_BOXES, DEFAULT_BOXES when it is not set, none when it is empty or `none`; a name
|
|
64
|
+
* that is no box throws, naming it, and so does `none` with another. */
|
|
54
65
|
export function enabledBoxes(env) {
|
|
55
|
-
|
|
66
|
+
if (boxesByDefault(env))
|
|
67
|
+
return new Set(DEFAULT_BOXES);
|
|
68
|
+
const names = env[BOXES_ENV].split(",").map((name) => name.trim()).filter(Boolean);
|
|
69
|
+
if (names.includes(NO_BOXES)) {
|
|
70
|
+
if (names.length > 1)
|
|
71
|
+
throw new Error(`${BOXES_ENV}=${NO_BOXES} sets up no box, so it names no other: list the boxes to set up, or ${NO_BOXES} alone`);
|
|
72
|
+
return new Set();
|
|
73
|
+
}
|
|
56
74
|
const unknown = names.filter((name) => !BOX_IDS.includes(name));
|
|
57
75
|
if (unknown.length)
|
|
58
76
|
throw new Error(`${BOXES_ENV} names ${unknown.join(", ")}, which ${unknown.length === 1 ? "is not a box" : "are not boxes"}: list any of ${BOX_IDS.join(", ")}`);
|
|
@@ -90,7 +108,7 @@ async function bounded(id, timeoutMs, probe) {
|
|
|
90
108
|
const late = new Promise((resolve) => {
|
|
91
109
|
timer = setTimeout(() => {
|
|
92
110
|
controller.abort();
|
|
93
|
-
resolve(unavailable(id, `its probe did not finish within ${timeoutMs} ms`));
|
|
111
|
+
resolve(unavailable(id, id === "docker" ? `Docker isn't answering on this machine (docker version took over ${timeoutMs} ms): start Docker, then restart AgentRun` : `its probe did not finish within ${timeoutMs} ms`));
|
|
94
112
|
}, timeoutMs);
|
|
95
113
|
});
|
|
96
114
|
try {
|
|
@@ -130,13 +148,14 @@ const PROBES = {
|
|
|
130
148
|
const code = error?.code;
|
|
131
149
|
resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error) } : {}), out: String(stdout) });
|
|
132
150
|
}));
|
|
133
|
-
// The probe runs once, at the start: each fix takes a restart.
|
|
151
|
+
// The probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
|
|
152
|
+
// first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
|
|
134
153
|
if (answer.failed === "ENOENT")
|
|
135
|
-
return unavailable("docker", "no docker command on
|
|
154
|
+
return unavailable("docker", "Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
|
|
136
155
|
if (answer.failed)
|
|
137
|
-
return unavailable("docker", `docker version failed
|
|
156
|
+
return unavailable("docker", `Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
|
|
138
157
|
if (!answer.out.trim())
|
|
139
|
-
return unavailable("docker", "docker version named no
|
|
158
|
+
return unavailable("docker", "Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
|
|
140
159
|
return available("docker", boxes.value());
|
|
141
160
|
},
|
|
142
161
|
/** One authenticated read the provider makes anyway: the box with a name no box has (lowercase letters, digits and
|
package/dist/cap.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ export declare function spentIn(storeFile: string, { sides }?: {
|
|
|
132
132
|
/** /usage's meters for a run that ended, from its store: `tools`, each TOOL_COST's `usd`, unknown (null) when one is,
|
|
133
133
|
* or when a call was cut (marked, never settled: what it charged no one knows); and `tokens`, the rest of its root
|
|
134
134
|
* conversation as its settled timeline prices it; `browser`, the part of `tools` that is browser session time
|
|
135
|
-
* (browser-cost.ts), with its seconds; and `others`, the rest of `tools`, each unknown (null) apart. A mark is never a charge here (the cap's alone). Never for a live run: its process
|
|
135
|
+
* (browser-cost.ts), with its seconds; and `others`, the rest of `tools`, each unknown (null) apart; and `notMetered`, the tool calls it ran with no price (TOOL_UNMETERED, an MCP tool its owner set none for), outside every figure here (absent when none). A mark is never a charge here (the cap's alone). Never for a live run: its process
|
|
136
136
|
* holds the store exclusively. */
|
|
137
137
|
export type Meters = {
|
|
138
138
|
tools: number | null;
|
|
@@ -142,6 +142,7 @@ export type Meters = {
|
|
|
142
142
|
seconds: number;
|
|
143
143
|
};
|
|
144
144
|
others: number | null;
|
|
145
|
+
notMetered?: number;
|
|
145
146
|
};
|
|
146
147
|
export declare function metersIn(storeFile: string): Meters;
|
|
147
148
|
/** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
|
package/dist/cap.js
CHANGED
|
@@ -482,7 +482,8 @@ export function meterFiguresIn(storeFile) {
|
|
|
482
482
|
const usage = timelineOf(rest, { settled: true }).find((row) => row.kind === "usage");
|
|
483
483
|
const otherTools = marks.size || others.some((usd) => usd === undefined) ? null : others.reduce((sum, usd) => sum + usd, 0);
|
|
484
484
|
known.tokens = usage ? (usage.usage?.usd ?? usage.usage?.so_far_usd ?? 0) : 0;
|
|
485
|
-
|
|
485
|
+
const notMetered = usage?.usage?.not_metered;
|
|
486
|
+
return { tools, tokens: usage ? (usage.usage?.usd ?? null) : 0, browser, others: otherTools, known, ...(notMetered ? { notMetered } : {}) };
|
|
486
487
|
}
|
|
487
488
|
finally {
|
|
488
489
|
db.close();
|
package/dist/cli.js
CHANGED
|
@@ -7,10 +7,12 @@ import { secret } from "./secrets.js";
|
|
|
7
7
|
import "./quiet-sqlite-warning.js";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
|
-
import {
|
|
10
|
+
import { chmodSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
import { defaultData, SERVER_FILE } from "./files.js";
|
|
11
13
|
import { canOpen } from "./host.js";
|
|
12
14
|
import { resetPassword } from "./owner.js";
|
|
13
|
-
import { banner } from "./print.js";
|
|
15
|
+
import { banner, boxImageLine } from "./print.js";
|
|
14
16
|
import { DEFAULT_PORT, startServe } from "./server.js";
|
|
15
17
|
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL]
|
|
16
18
|
agentrun-serve reset-password [--data DIR]
|
|
@@ -138,13 +140,31 @@ const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
|
138
140
|
// A stdout its reader closed (a pipe left behind) loses the log lines, never the server.
|
|
139
141
|
process.stdout.on("error", () => undefined);
|
|
140
142
|
const accounts = process.env.AGENTRUN_ACCOUNTS !== "0";
|
|
143
|
+
// The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
|
|
144
|
+
// before the banner is printed waits for it.
|
|
145
|
+
let imageSaid = false;
|
|
146
|
+
let bannered = false;
|
|
147
|
+
const early = [];
|
|
148
|
+
const onBoxImage = (state) => {
|
|
149
|
+
const line = boxImageLine(state, imageSaid);
|
|
150
|
+
if (line === undefined)
|
|
151
|
+
return;
|
|
152
|
+
imageSaid = true;
|
|
153
|
+
if (bannered)
|
|
154
|
+
console.log(line);
|
|
155
|
+
else
|
|
156
|
+
early.push(line);
|
|
157
|
+
};
|
|
141
158
|
let serve;
|
|
142
159
|
try {
|
|
143
160
|
serve = await startServe({
|
|
161
|
+
onBoxImage,
|
|
144
162
|
data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), allowHosts: values["allow-host"],
|
|
145
163
|
...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
|
|
146
164
|
...(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`),
|
|
147
|
-
|
|
165
|
+
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
166
|
+
...(publicUrl ? { publicUrl } : {}),
|
|
167
|
+
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}),
|
|
148
168
|
});
|
|
149
169
|
}
|
|
150
170
|
catch (error) {
|
|
@@ -158,10 +178,16 @@ for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token:
|
|
|
158
178
|
// With a public address the setup link and its code are printed as the code is made (owner.ts).
|
|
159
179
|
if (serve.setupUrl && !publicUrl)
|
|
160
180
|
console.log(`Set your password: ${serve.setupUrl} (the first visit sets it)`);
|
|
181
|
+
bannered = true;
|
|
182
|
+
for (const line of early.splice(0))
|
|
183
|
+
console.log(line);
|
|
161
184
|
// The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
|
|
162
185
|
// and the browser's history.
|
|
163
186
|
if (values.open && canOpen(process.env))
|
|
164
187
|
spawn(process.platform === "darwin" ? "open" : "xdg-open", [`${publicUrl ?? serve.url}/`], { stdio: "ignore", detached: true }).on("error", () => { }).unref();
|
|
165
|
-
const
|
|
188
|
+
const record = join(resolve(data), SERVER_FILE);
|
|
189
|
+
writeFileSync(record, `${JSON.stringify({ base_url: serve.baseUrl, pid: process.pid, ...(serve.tokenFile ? { token_file: serve.tokenFile } : {}) })}\n`, { mode: 0o600 });
|
|
190
|
+
chmodSync(record, 0o600);
|
|
191
|
+
const stop = () => void serve.close().then(() => (rmSync(record, { force: true }), process.exit(0)));
|
|
166
192
|
process.once("SIGINT", stop);
|
|
167
193
|
process.once("SIGTERM", stop);
|