@parcha/agentrun-computer 0.1.0-beta.54 → 0.1.0-beta.56
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/dist/browser.d.ts +0 -2
- package/dist/browser.js +0 -13
- package/dist/browserbase.js +2 -1
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/groundbox.js +1 -2
- package/dist/daytona.js +3 -5
- package/dist/groundbox.d.ts +2 -0
- package/dist/groundbox.js +61 -36
- package/dist/hosted/rest.d.ts +5 -0
- package/dist/hosted/rest.js +16 -0
- package/dist/kernel.js +2 -1
- package/dist/mount-archil.d.ts +2 -2
- package/dist/mount-archil.js +2 -2
- package/dist/screen-watch.js +2 -1
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -146,8 +146,6 @@ export declare function restCall(o: {
|
|
|
146
146
|
base: string;
|
|
147
147
|
headers: Record<string, string>;
|
|
148
148
|
}, method: string, route: string, call: string, init?: RestInit): Promise<RestReply>;
|
|
149
|
-
/** An https base URL, with no trailing slash, so a key never crosses in the clear; throws in words on another. */
|
|
150
|
-
export declare function httpsBase(url: string, what: string): string;
|
|
151
149
|
/** A vendor's session id as a ref or attach gives it: a plain token, never a path. */
|
|
152
150
|
export declare const idProblem: (id: unknown, vendor: string) => string | undefined;
|
|
153
151
|
/**
|
package/dist/browser.js
CHANGED
|
@@ -295,19 +295,6 @@ export async function restCall(o, method, route, call, init = {}) {
|
|
|
295
295
|
throw new BrowserVendorError(o.vendor, call, response.status, plainCode(json?.code));
|
|
296
296
|
return { status: response.status, json, headers: response.headers };
|
|
297
297
|
}
|
|
298
|
-
/** An https base URL, with no trailing slash, so a key never crosses in the clear; throws in words on another. */
|
|
299
|
-
export function httpsBase(url, what) {
|
|
300
|
-
let parsed;
|
|
301
|
-
try {
|
|
302
|
-
parsed = new URL(url);
|
|
303
|
-
}
|
|
304
|
-
catch {
|
|
305
|
-
throw new Error(`${what} is not a URL: ${JSON.stringify(url)}`);
|
|
306
|
-
}
|
|
307
|
-
if (parsed.protocol !== "https:")
|
|
308
|
-
throw new Error(`${what} must be https, so the key never crosses in the clear: ${parsed.protocol}`);
|
|
309
|
-
return url.replace(/\/+$/, "");
|
|
310
|
-
}
|
|
311
298
|
/** A vendor's session id as a ref or attach gives it: a plain token, never a path. */
|
|
312
299
|
export const idProblem = (id, vendor) => typeof id === "string" && /^[A-Za-z0-9_.:-]{1,128}$/.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a ${vendor} session's id`;
|
|
313
300
|
/**
|
package/dist/browserbase.js
CHANGED
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
import { readFileSync } from "node:fs";
|
|
22
22
|
import { BROWSERBASE } from "./descriptors/browserbase.js";
|
|
23
23
|
import { BROWSER_IMAGE } from "./descriptors/shared.js";
|
|
24
|
-
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep,
|
|
24
|
+
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep, idProblem, labelsOf, labelsProblem, limitedBytes, memoryUrls, pointerOk, queryable, recoverCreate, releaseConfirmed, restBytes, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
25
|
+
import { httpsBase } from "./hosted/rest.js";
|
|
25
26
|
import { runLifetimeMs, } from "./provider.js";
|
|
26
27
|
import { failFor, ok, vendorFail } from "./result.js";
|
|
27
28
|
import { connectionError } from "./test-connection.js";
|
|
Binary file
|
|
Binary file
|
package/dist/computerd.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// a deadline of at most 30 minutes, and Groundbox's own timer ends it 5 minutes past that.
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { boxImageRef } from "../box-image.js";
|
|
14
|
-
import { create } from "../groundbox.js";
|
|
14
|
+
import { create, DEFAULT_API_URL } from "../groundbox.js";
|
|
15
15
|
import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
|
|
16
16
|
import { kindFrom } from "./kind.js";
|
|
17
17
|
/** The environment this module reads, by name, each for the option its comment names, the live switch and the run's image. */
|
|
@@ -32,7 +32,6 @@ export const GROUNDBOX_ENV = {
|
|
|
32
32
|
};
|
|
33
33
|
/** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
|
|
34
34
|
export const ENV = GROUNDBOX_ENV;
|
|
35
|
-
const DEFAULT_API_URL = "https://api.groundbox.dev/v1";
|
|
36
35
|
/** The provider's options this module reads from env, each only when its name is set; throws in words without the key, never echoing it. */
|
|
37
36
|
export function settingsFromEnv(env = process.env) {
|
|
38
37
|
const apiKey = env[GROUNDBOX_ENV.key];
|
package/dist/daytona.js
CHANGED
|
@@ -12,7 +12,7 @@ import { HostError } from "./host.js";
|
|
|
12
12
|
import { framedExec } from "./hosted/framed-exec.js";
|
|
13
13
|
import { HostedProvider, timeoutsOf } from "./hosted/provider.js";
|
|
14
14
|
import { boundOf, orThrow, seconds, pause as sleep, words } from "./hosted/process.js";
|
|
15
|
-
import { allPages, jsonOf, rest } from "./hosted/rest.js";
|
|
15
|
+
import { allPages, httpsBase, jsonOf, rest } from "./hosted/rest.js";
|
|
16
16
|
import { dialLaunch, shellLine } from "./hosted/scripts.js";
|
|
17
17
|
import { dateOf, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
18
18
|
import { MAX_LINE_BYTES } from "./protocol.js";
|
|
@@ -613,9 +613,7 @@ export class DaytonaProvider extends HostedProvider {
|
|
|
613
613
|
throw new Error(refused);
|
|
614
614
|
if (typeof apiKey !== "string" || apiKey === "")
|
|
615
615
|
throw new Error("options.apiKey, the Daytona API key, is required: the provider reads no environment, so the caller passes it");
|
|
616
|
-
const base =
|
|
617
|
-
if (base.protocol !== "https:")
|
|
618
|
-
throw new Error(`the Daytona API URL must be https, so the key never crosses in the clear: ${base.protocol}`);
|
|
616
|
+
const base = httpsBase(apiUrl, "the Daytona API URL");
|
|
619
617
|
if (arch !== "amd64" && arch !== "arm64")
|
|
620
618
|
throw new Error(`options.arch is amd64 or arm64, not ${String(arch)}`);
|
|
621
619
|
if (sandboxClass !== "container" && sandboxClass !== "linux-vm")
|
|
@@ -643,7 +641,7 @@ export class DaytonaProvider extends HostedProvider {
|
|
|
643
641
|
const host = new DaytonaHost({
|
|
644
642
|
// On dial its capabilities declare no GPU (DIAL_NO_GPU).
|
|
645
643
|
descriptor: { ...DAYTONA, ...mountsOf(DAYTONA, set), ...(via === "dial" ? { capabilities: DAYTONA.capabilities.map(({ gpu: _gpu, ...rest }) => rest) } : {}) },
|
|
646
|
-
rest: rest({ base
|
|
644
|
+
rest: rest({ base, headers: () => headers, vendor: "daytona", fetch: fetcher ?? fetch, timeoutMs: requestMs, retry: { attempts: RETRY_ATTEMPTS, baseMs: retryMs, ...(pause ? { pause } : {}) }, explain }),
|
|
647
645
|
headers,
|
|
648
646
|
webSocket: webSocket ?? ((url, init) => new WebSocket(url, init)),
|
|
649
647
|
arch,
|
package/dist/groundbox.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface GroundboxProviderOptions extends HostedOptions {
|
|
|
38
38
|
export declare function create(options: GroundboxProviderOptions): Promise<GroundboxProvider>;
|
|
39
39
|
/** The conformance CLI's module for Groundbox: its live switch, the run's 30-minute cap and its image. */
|
|
40
40
|
export declare const conformance: () => Promise<typeof import("./conformance/groundbox.js")>;
|
|
41
|
+
/** Groundbox's REST API: the provider's default, and the conformance module's. */
|
|
42
|
+
export declare const DEFAULT_API_URL = "https://api.groundbox.dev/v1";
|
|
41
43
|
/** The command stream's bounds: SILENCE_MS, QUEUE_HIGH, QUEUE_LOW and RESUME_GIVE_UP_MS unless a test gives others. */
|
|
42
44
|
export interface StreamBounds {
|
|
43
45
|
silenceMs: number;
|
package/dist/groundbox.js
CHANGED
|
@@ -20,7 +20,7 @@ import { HostError } from "./host.js";
|
|
|
20
20
|
import { framedExec } from "./hosted/framed-exec.js";
|
|
21
21
|
import { boundOf, orThrow, pause, seconds } from "./hosted/process.js";
|
|
22
22
|
import { HostedProvider } from "./hosted/provider.js";
|
|
23
|
-
import { allPages, jsonOf, rest } from "./hosted/rest.js";
|
|
23
|
+
import { allPages, httpsBase, jsonOf, rest } from "./hosted/rest.js";
|
|
24
24
|
import { PID_KILL } from "./hosted/scripts.js";
|
|
25
25
|
import { dateOf, isWhole } from "./hosted/values.js";
|
|
26
26
|
import { ok } from "./result.js";
|
|
@@ -29,9 +29,8 @@ export async function create(options) {
|
|
|
29
29
|
}
|
|
30
30
|
/** The conformance CLI's module for Groundbox: its live switch, the run's 30-minute cap and its image. */
|
|
31
31
|
export const conformance = () => import("./conformance/groundbox.js");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const LOOPBACK = /^(127(\.\d{1,3}){3}|\[::1\]|localhost)$/;
|
|
32
|
+
/** Groundbox's REST API: the provider's default, and the conformance module's. */
|
|
33
|
+
export const DEFAULT_API_URL = "https://api.groundbox.dev/v1";
|
|
35
34
|
/** The longest a resumable command may run, in seconds: 30 days (EXEC_STREAM_MAX_TIMEOUT_S in Groundbox's contracts). The sandbox's own timer ends it first. */
|
|
36
35
|
const EXEC_STREAM_MAX_S = 30 * 24 * 3_600;
|
|
37
36
|
/** The most timeout_minutes takes: 30 days (SANDBOX_MAX_TIMEOUT_MINUTES). */
|
|
@@ -94,14 +93,17 @@ const DIR_PREFIX = "/tmp/.agentrun-exec-";
|
|
|
94
93
|
* The sh every command starts under ($1 its directory, then the argv). It makes the directory with mode 0700, as
|
|
95
94
|
* mktemp -d does, and a path already there is never its own: the command does not start (exit 126). In it, the fifo
|
|
96
95
|
* and the record of its own pid and start time (as PID_WRAPPER's line, for the kill; written whole and then renamed,
|
|
97
|
-
* so the kill never reads half of it).
|
|
98
|
-
*
|
|
96
|
+
* so the kill never reads half of it). Once both are there it puts MARK on stderr, before any byte of the argv's: a
|
|
97
|
+
* write and the kill wait for it (Groundbox says `started` before the sh has run), so neither polls. It runs the argv
|
|
98
|
+
* with the fifo as its stdin, opened to read and write, so the fifo never reads end of file between two writers; then it
|
|
99
|
+
* removes the directory and exits as the argv did.
|
|
99
100
|
*/
|
|
100
101
|
const START_SCRIPT = [
|
|
101
102
|
"d=$1; shift",
|
|
102
103
|
'mkdir -m 700 "$d" 2>/dev/null || { echo "agentrun: $d is already there, so it is not one this command made: the command did not start" >&2; exit 126; }',
|
|
103
104
|
'mkfifo -m 600 "$d/in" || exit 126',
|
|
104
|
-
'echo "$$ $(s=$(cat /proc/$$/stat 2>/dev/null) && set -- ${s##*") "} && echo "${20}")" >"$d/pid.new" && mv -f "$d/pid.new" "$d/pid"',
|
|
105
|
+
'echo "$$ $(s=$(cat /proc/$$/stat 2>/dev/null) && set -- ${s##*") "} && echo "${20}")" >"$d/pid.new" && mv -f "$d/pid.new" "$d/pid" || exit 126',
|
|
106
|
+
"echo >&2",
|
|
105
107
|
'"$@" 0<>"$d/in"; c=$?',
|
|
106
108
|
'rm -rf "$d"; exit $c',
|
|
107
109
|
].join("\n");
|
|
@@ -113,27 +115,33 @@ const START_SCRIPT = [
|
|
|
113
115
|
const OWN_DIR = `cd -P "$d" 2>/dev/null && [ "$(pwd -P)" = "$(cd -P "\${d%/*}" && pwd -P)/\${d##*/}" ] && [ "$(stat -c %u:%a .)" = "$(id -u):700" ] || { echo "$d is not the command's own directory" >&2; exit 4; }`;
|
|
114
116
|
/** The check of one file in it ($1 its name): not a link, and this user's. */
|
|
115
117
|
const ownFile = (name) => `[ ! -L ${name} ] && [ "$(stat -c %u ${name})" = "$(id -u)" ] || { echo "$d/${name} is not the command's own" >&2; exit 4; }`;
|
|
118
|
+
/** START_SCRIPT's mark, the first byte on stderr once the command's directory, fifo and pid record are made: a newline (`echo >&2`), which no refusal of the sh starts with. */
|
|
119
|
+
const MARK = 0x0a;
|
|
116
120
|
/**
|
|
117
|
-
* One write ($1 the command's directory): its stdin into the fifo there.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
121
|
+
* One write ($1 the command's directory), sent once START_SCRIPT's mark came: its stdin into the fifo there. With no
|
|
122
|
+
* fifo the command has ended (its sh removed it): exit 3. The write opens `in`, then checks it is still the fifo before
|
|
123
|
+
* cat writes a byte: a fifo that went between the checks and the open leaves a file of the write's own, removed with
|
|
124
|
+
* nothing in it, and a command that ends while cat writes leaves it no reader; exit 3 for both. Once cat has put every
|
|
125
|
+
* byte in the fifo the write is made, though the command may read them, end, and its sh remove the directory before the
|
|
126
|
+
* write answers.
|
|
120
127
|
*/
|
|
121
128
|
const WRITE_SCRIPT = [
|
|
122
|
-
'd=$1;
|
|
129
|
+
'd=$1; [ -p "$d/in" ] || exit 3',
|
|
123
130
|
OWN_DIR,
|
|
124
131
|
ownFile("in"),
|
|
125
|
-
"
|
|
132
|
+
"{",
|
|
126
133
|
'[ -p in ] || { rm -f in; cd / && rmdir "$d" 2>/dev/null; exit 3; }',
|
|
134
|
+
"cat >&3 || exit 3",
|
|
135
|
+
"} 3>in || exit 3",
|
|
127
136
|
].join("\n");
|
|
128
137
|
/**
|
|
129
138
|
* The kill ($1 the command's directory, $2 PID_KILL): the shared pid kill of the recorded pid, as root, since a command
|
|
130
|
-
* that became root through sudo is past its starter's signals, and Groundbox's own kill of a command is that user's.
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* removed, as the killed sh could not.
|
|
139
|
+
* that became root through sudo is past its starter's signals, and Groundbox's own kill of a command is that user's.
|
|
140
|
+
* Sent once START_SCRIPT's mark came, as a write is; with no record the command has ended (its sh removed it). Then the
|
|
141
|
+
* directory is removed, as the killed sh could not.
|
|
134
142
|
*/
|
|
135
143
|
const KILL_SCRIPT = [
|
|
136
|
-
'd=$1;
|
|
144
|
+
'd=$1; [ -s "$d/pid" ] || exit 0',
|
|
137
145
|
OWN_DIR,
|
|
138
146
|
ownFile("pid"),
|
|
139
147
|
"read -r pid start 2>/dev/null <pid || exit 0",
|
|
@@ -216,7 +224,7 @@ class GroundboxHost {
|
|
|
216
224
|
#api;
|
|
217
225
|
constructor(options) {
|
|
218
226
|
this.#apiKey = options.apiKey;
|
|
219
|
-
this.#apiUrl = options.apiUrl
|
|
227
|
+
this.#apiUrl = options.apiUrl;
|
|
220
228
|
this.#fetch = options.fetch;
|
|
221
229
|
this.#webSocket = options.webSocket;
|
|
222
230
|
this.#diskGb = options.diskGb;
|
|
@@ -337,14 +345,15 @@ class GroundboxHost {
|
|
|
337
345
|
* in its own process group, with the longest timeout Groundbox takes (the sandbox's own timer ends it first), its
|
|
338
346
|
* output as base64, so every byte comes as it was and a position in it is exact. A write is one call per WRITE_BYTES
|
|
339
347
|
* that writes the command's fifo and answers once it has; there is no end of stdin (a fifo held open has none), which
|
|
340
|
-
* nothing the adapter runs waits for. kill is KILL_SCRIPT's.
|
|
341
|
-
* not the command's own is refused.
|
|
348
|
+
* nothing the adapter runs waits for. kill is KILL_SCRIPT's. Both wait for START_SCRIPT's mark first. A write or a kill
|
|
349
|
+
* whose directory, fifo or pid record is not the command's own is refused.
|
|
342
350
|
*/
|
|
343
351
|
exec(id, argv, ctx) {
|
|
344
352
|
return framedExec({
|
|
345
353
|
start: (argv, ctx) => this.#start(id, argv, ctx),
|
|
346
354
|
events: (command) => this.#events(command),
|
|
347
355
|
write: async (command, text) => {
|
|
356
|
+
await this.#begun(command);
|
|
348
357
|
const bytes = Buffer.from(text, "utf8");
|
|
349
358
|
for (let at = 0; at < bytes.length; at += WRITE_BYTES) {
|
|
350
359
|
const code = await this.#step(command, [WRITE_SCRIPT, "sh", command.dir], bytes.subarray(at, at + WRITE_BYTES));
|
|
@@ -358,12 +367,22 @@ class GroundboxHost {
|
|
|
358
367
|
}
|
|
359
368
|
},
|
|
360
369
|
kill: async (command) => {
|
|
370
|
+
await this.#begun(command);
|
|
361
371
|
const code = await this.#step(command, [KILL_SCRIPT, "sh", command.dir, PID_KILL]);
|
|
362
372
|
if (code === 4)
|
|
363
373
|
throw new Error(`the command's pid record at ${command.dir} is not the command's own: the kill was refused`);
|
|
364
374
|
},
|
|
365
375
|
}, argv, ctx);
|
|
366
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Answers once START_SCRIPT's mark came (or the first of a refusal's words, or the stream ended), or STEP_MS passed:
|
|
379
|
+
* before it, the command's directory may not be made yet. The script that follows checks what is there either way.
|
|
380
|
+
*/
|
|
381
|
+
async #begun(command) {
|
|
382
|
+
let timer;
|
|
383
|
+
await Promise.race([command.begun, new Promise((done) => (timer = setTimeout(done, STEP_MS)))]);
|
|
384
|
+
clearTimeout(timer);
|
|
385
|
+
}
|
|
367
386
|
/** One short command beside a running one (POST .../exec), its stdin given whole: its exit code, -1 past its bound. Never sent twice. */
|
|
368
387
|
async #step(command, script, stdin) {
|
|
369
388
|
const body = { args: ["sh", "-c", ...script], timeout_s: STEP_S, ...(stdin === undefined ? {} : { stdin_base64: Buffer.from(stdin).toString("base64") }) };
|
|
@@ -372,7 +391,9 @@ class GroundboxHost {
|
|
|
372
391
|
}
|
|
373
392
|
/** Starts the command on a new socket and answers once Groundbox says it has started, within the call's bound. */
|
|
374
393
|
async #start(id, argv, ctx) {
|
|
375
|
-
|
|
394
|
+
let begin;
|
|
395
|
+
const begun = new Promise((done) => (begin = done));
|
|
396
|
+
const command = { sandbox: id, dir: `${DIR_PREFIX}${randomBytes(8).toString("hex")}`, seq: 0, marked: false, begun, begin, events: [], queued: 0, paused: false, resuming: false, ended: false, wake: () => { }, quiet: () => { } };
|
|
376
397
|
const first = { type: "start", args: ["sh", "-c", START_SCRIPT, "sh", command.dir, ...argv], resumable: true, encoding: "base64", timeout_s: EXEC_STREAM_MAX_S };
|
|
377
398
|
try {
|
|
378
399
|
await this.#connect(command, first, ctx);
|
|
@@ -385,7 +406,7 @@ class GroundboxHost {
|
|
|
385
406
|
}
|
|
386
407
|
/**
|
|
387
408
|
* The stream is over: nothing more is read, its socket's watchdog stops, and the socket is closed (1000, which also
|
|
388
|
-
* ends a command still running).
|
|
409
|
+
* ends a command still running). A write or a kill still waiting for the mark goes on to its script.
|
|
389
410
|
*/
|
|
390
411
|
#end(command, failure) {
|
|
391
412
|
if (!command.ended)
|
|
@@ -393,6 +414,7 @@ class GroundboxHost {
|
|
|
393
414
|
command.ended = true;
|
|
394
415
|
command.quiet();
|
|
395
416
|
command.socket?.close(END);
|
|
417
|
+
command.begin();
|
|
396
418
|
command.wake();
|
|
397
419
|
}
|
|
398
420
|
/**
|
|
@@ -481,8 +503,20 @@ class GroundboxHost {
|
|
|
481
503
|
ready();
|
|
482
504
|
}
|
|
483
505
|
else if ((message.type === "stdout" || message.type === "stderr") && typeof message.data === "string") {
|
|
484
|
-
|
|
485
|
-
|
|
506
|
+
let base64 = message.data;
|
|
507
|
+
// stderr's first byte lets the writes and the kill go as it comes, read or not: START_SCRIPT's mark, taken off,
|
|
508
|
+
// or the first of the words of a start its sh refused, kept.
|
|
509
|
+
if (message.type === "stderr" && !command.marked && base64 !== "") {
|
|
510
|
+
const bytes = Buffer.from(base64, "base64");
|
|
511
|
+
command.marked = true;
|
|
512
|
+
command.begin();
|
|
513
|
+
if (bytes[0] === MARK)
|
|
514
|
+
base64 = bytes.subarray(1).toString("base64");
|
|
515
|
+
}
|
|
516
|
+
if (base64 !== "") {
|
|
517
|
+
command.events.push({ stream: message.type, base64 });
|
|
518
|
+
command.queued += bytesOf(base64);
|
|
519
|
+
}
|
|
486
520
|
if (typeof message.seq === "number")
|
|
487
521
|
command.seq = message.seq;
|
|
488
522
|
// Everything up to seq is queued: a socket opened later attaches from there, and nothing is lost or read twice.
|
|
@@ -635,24 +669,15 @@ export class GroundboxProvider extends HostedProvider {
|
|
|
635
669
|
const { apiKey, apiUrl = DEFAULT_API_URL, diskGb, fetch, webSocket, streamBounds, maxLifetimeMs = DEFAULT_LIFETIME_MS, ...rest } = options ?? {};
|
|
636
670
|
if (typeof apiKey !== "string" || apiKey === "")
|
|
637
671
|
throw new Error("options.apiKey, the Groundbox API key, is required: the provider reads no environment, so the caller passes it");
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
url = new URL(apiUrl);
|
|
641
|
-
}
|
|
642
|
-
catch {
|
|
643
|
-
// Refused below, in words.
|
|
644
|
-
}
|
|
645
|
-
// The key rides every call and the stream's upgrade: never in cleartext past this machine.
|
|
646
|
-
if (url === undefined || !(url.protocol === "https:" || (url.protocol === "http:" && LOOPBACK.test(url.hostname)))) {
|
|
647
|
-
throw new Error(`the Groundbox API URL must be https, or http to a loopback host (127.0.0.0/8, ::1 or localhost), such as ${DEFAULT_API_URL}, not ${JSON.stringify(apiUrl)}`);
|
|
648
|
-
}
|
|
672
|
+
// The key rides every call and the stream's upgrade (wss).
|
|
673
|
+
const base = httpsBase(apiUrl, "the Groundbox API URL");
|
|
649
674
|
if (diskGb !== undefined && !(isWhole(diskGb) && diskGb >= 1 && diskGb <= MAX_DISK_GB))
|
|
650
675
|
throw new Error(`diskGb is a whole number of GB, 1 to ${MAX_DISK_GB}, not ${String(diskGb)}`);
|
|
651
676
|
if (Number(rest.daemonUser?.split(":")[0]) === IMAGE_UID)
|
|
652
677
|
throw new Error(`the daemon user ${rest.daemonUser} is the uid of the sandbox's own user, whose processes init refuses to run beside; choose another, such as 2510:2510`);
|
|
653
678
|
super(new GroundboxHost({
|
|
654
679
|
apiKey,
|
|
655
|
-
apiUrl,
|
|
680
|
+
apiUrl: base,
|
|
656
681
|
...(fetch ? { fetch } : {}),
|
|
657
682
|
webSocket: webSocket ?? ((url, init) => new WebSocket(url, init)),
|
|
658
683
|
...(diskGb === undefined ? {} : { diskGb }),
|
package/dist/hosted/rest.d.ts
CHANGED
|
@@ -71,6 +71,11 @@ export interface Rest {
|
|
|
71
71
|
*/
|
|
72
72
|
stream(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestStream>>;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* An API's https base URL, with no trailing slash, so a key never crosses in the clear; throws in words on another,
|
|
76
|
+
* loopback http included. Every provider that sends a key takes its URL through it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function httpsBase(url: string, what: string): string;
|
|
74
79
|
export declare function rest(options: RestOptions): Rest;
|
|
75
80
|
/** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
|
|
76
81
|
export declare function ndjson(body: AsyncIterable<Uint8Array>): AsyncIterable<unknown>;
|
package/dist/hosted/rest.js
CHANGED
|
@@ -41,6 +41,22 @@ function redirected(cause) {
|
|
|
41
41
|
return /redirect/i.test(`${cause?.message ?? ""} ${inner?.message ?? ""}`);
|
|
42
42
|
}
|
|
43
43
|
const NO_BODY = { async *[Symbol.asyncIterator]() { } };
|
|
44
|
+
/**
|
|
45
|
+
* An API's https base URL, with no trailing slash, so a key never crosses in the clear; throws in words on another,
|
|
46
|
+
* loopback http included. Every provider that sends a key takes its URL through it.
|
|
47
|
+
*/
|
|
48
|
+
export function httpsBase(url, what) {
|
|
49
|
+
let parsed;
|
|
50
|
+
try {
|
|
51
|
+
parsed = new URL(url);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`${what} is not a URL: ${JSON.stringify(url)}`);
|
|
55
|
+
}
|
|
56
|
+
if (parsed.protocol !== "https:")
|
|
57
|
+
throw new Error(`${what} must be https, so the key never crosses in the clear: ${parsed.protocol}`);
|
|
58
|
+
return url.replace(/\/+$/, "");
|
|
59
|
+
}
|
|
44
60
|
export function rest(options) {
|
|
45
61
|
const base = options.base.replace(/\/+$/, "");
|
|
46
62
|
const fetcher = options.fetch ?? fetch;
|
package/dist/kernel.js
CHANGED
|
@@ -20,7 +20,8 @@ import { randomBytes } from "node:crypto";
|
|
|
20
20
|
import { readFileSync } from "node:fs";
|
|
21
21
|
import { KERNEL } from "./descriptors/kernel.js";
|
|
22
22
|
import { BROWSER_IMAGE } from "./descriptors/shared.js";
|
|
23
|
-
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep,
|
|
23
|
+
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createLabelValue, createUncertain, DEFAULT_CONFIRM, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, recoverCreate, releaseConfirmed, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
24
|
+
import { httpsBase } from "./hosted/rest.js";
|
|
24
25
|
import { runLifetimeMs, } from "./provider.js";
|
|
25
26
|
import { failFor, ok, vendorFail } from "./result.js";
|
|
26
27
|
import { connectionError } from "./test-connection.js";
|
package/dist/mount-archil.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export declare function archilRefusals(spec: ComputerSpec): Refusal[];
|
|
|
69
69
|
/** The sha256 of the helper this package ships (box/agentrun-archil): the one an image must have. */
|
|
70
70
|
export declare function helperSha256(): string;
|
|
71
71
|
/**
|
|
72
|
-
* An egress gateway for the archil client
|
|
72
|
+
* An egress gateway the operator runs for the archil client: with one, the helper's mount starts
|
|
73
73
|
* `computerd archil-relay` and redirects root's TCP to Archil's 8100 and 32050 to it, and the relay carries each
|
|
74
74
|
* connection to the gateway's lane for its port with a PROXY v2 header naming the original destination. The gateway
|
|
75
75
|
* forwards only to a destination that proves, by certificate, the Archil name the client asked for.
|
|
@@ -83,7 +83,7 @@ export interface ArchilEgress {
|
|
|
83
83
|
dataLane: number;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
* Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as
|
|
86
|
+
* Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 192.0.2.40:18100:42050, as the helper checks it: an IPv4
|
|
87
87
|
* address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
|
|
88
88
|
*/
|
|
89
89
|
export declare function archilEgressOf(text: string): ArchilEgress;
|
package/dist/mount-archil.js
CHANGED
|
@@ -167,7 +167,7 @@ const LANE = /^[1-9]\d{0,4}$/;
|
|
|
167
167
|
/** Archil's own ports, which the computer redirects to the relay: no lane may be one. */
|
|
168
168
|
const ARCHIL_PORTS = new Set([8100, 32050]);
|
|
169
169
|
/**
|
|
170
|
-
* Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as
|
|
170
|
+
* Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 192.0.2.40:18100:42050, as the helper checks it: an IPv4
|
|
171
171
|
* address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
|
|
172
172
|
*/
|
|
173
173
|
export function archilEgressOf(text) {
|
|
@@ -176,7 +176,7 @@ export function archilEgressOf(text) {
|
|
|
176
176
|
const dataLane = Number(data);
|
|
177
177
|
const lane = (port, n) => LANE.test(port) && n <= 65535 && !ARCHIL_PORTS.has(n);
|
|
178
178
|
if (rest.length > 0 || !IPV4.test(gateway) || !lane(mount, mountLane) || !lane(data, dataLane) || mountLane === dataLane) {
|
|
179
|
-
throw new Error(`the Archil egress is <IPv4 gateway>:<mount lane>:<data lane>, such as
|
|
179
|
+
throw new Error(`the Archil egress is <IPv4 gateway>:<mount lane>:<data lane>, such as 192.0.2.40:18100:42050, with two different ports, neither 8100 nor 32050; not ${JSON.stringify(text)}`);
|
|
180
180
|
}
|
|
181
181
|
return { gateway, mountLane, dataLane };
|
|
182
182
|
}
|
package/dist/screen-watch.js
CHANGED
|
@@ -43,7 +43,8 @@ export function redactWords(words) {
|
|
|
43
43
|
.replace(/\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+/=-]+/gi, "[a secret]")
|
|
44
44
|
// A secret-named parameter, its name with a prefix or suffix too: api_key=, access_token=, client_secret=.
|
|
45
45
|
.replace(/\b[\w-]*(?:token|password|passwd|secret|key|jwt|auth|code|signingKey|credential)[\w-]*=[^\s&"';,]+/gi, "[a secret]")
|
|
46
|
-
|
|
46
|
+
// A token from the first "eyJ" of its run, glued to a word ("id_eyJ...") too.
|
|
47
|
+
.replace(/eyJ(?<!eyJ[A-Za-z0-9_-]*?eyJ)[A-Za-z0-9_-]+\.[A-Za-z0-9._-]*/g, "[a secret]")
|
|
47
48
|
.replace(/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, "[a secret]")
|
|
48
49
|
.replace(/\bgh[pousr]_[A-Za-z0-9]{16,}/g, "[a secret]")
|
|
49
50
|
.replace(/\b(?:sk|pk|pck|ph|tok|pw|jwt)_[A-Za-z0-9_-]{6,}/g, "[a secret]")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-computer",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.56",
|
|
4
4
|
"description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|