@parcha/agentrun-computer 0.1.0-beta.40 → 0.1.0-beta.42
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/NOTICE +2 -0
- package/README.md +285 -28
- package/box/Dockerfile +6 -4
- package/box/README.md +10 -2
- package/box/build-daytona.py +3 -1
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +68 -7
- package/dist/attach.d.ts +46 -1
- package/dist/attach.js +48 -4
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +1 -1
- package/dist/boxd.d.ts +126 -0
- package/dist/boxd.js +418 -0
- package/dist/cloudflare.d.ts +32 -0
- package/dist/cloudflare.js +179 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/boxd.d.ts +77 -0
- package/dist/conformance/boxd.js +113 -0
- package/dist/conformance/cases/isolation.js +1 -17
- package/dist/conformance/cases/provider.js +42 -26
- package/dist/conformance/cli.js +4 -1
- package/dist/conformance/cloudflare.d.ts +42 -0
- package/dist/conformance/cloudflare.js +54 -0
- package/dist/conformance/daytona.d.ts +25 -0
- package/dist/conformance/daytona.js +26 -1
- package/dist/conformance/dial-only.d.ts +6 -0
- package/dist/conformance/dial-only.js +9 -0
- package/dist/conformance/e2b.d.ts +12 -3
- package/dist/conformance/e2b.js +21 -4
- package/dist/conformance/exec-stream.js +14 -6
- package/dist/conformance/fly.d.ts +52 -0
- package/dist/conformance/fly.js +52 -0
- package/dist/conformance/modal.d.ts +15 -2
- package/dist/conformance/modal.js +36 -3
- package/dist/conformance/morph.d.ts +59 -0
- package/dist/conformance/morph.js +95 -0
- package/dist/conformance/phone-harness.js +2 -2
- package/dist/conformance/runner.js +5 -1
- package/dist/conformance/sweep.d.ts +1 -1
- package/dist/conformance/sweep.js +1 -1
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +8 -1
- package/dist/daytona.js +124 -101
- package/dist/descriptor.d.ts +22 -1
- package/dist/descriptor.js +18 -0
- package/dist/descriptors/boxd.d.ts +52 -0
- package/dist/descriptors/boxd.js +29 -0
- package/dist/descriptors/cloudflare.d.ts +21 -0
- package/dist/descriptors/cloudflare.js +29 -0
- package/dist/descriptors/daytona.d.ts +12 -3
- package/dist/descriptors/daytona.js +15 -7
- package/dist/descriptors/e2b.d.ts +4 -0
- package/dist/descriptors/e2b.js +3 -0
- package/dist/descriptors/fly.d.ts +19 -0
- package/dist/descriptors/fly.js +28 -0
- package/dist/descriptors/index.d.ts +121 -2
- package/dist/descriptors/index.js +7 -2
- package/dist/descriptors/modal.d.ts +3 -0
- package/dist/descriptors/modal.js +7 -2
- package/dist/descriptors/morph.d.ts +15 -0
- package/dist/descriptors/morph.js +21 -0
- package/dist/descriptors/phone-harness.d.ts +1 -0
- package/dist/descriptors/phone-harness.js +2 -0
- package/dist/e2b.d.ts +7 -1
- package/dist/e2b.js +87 -44
- package/dist/fly.d.ts +43 -0
- package/dist/fly.js +245 -0
- package/dist/host.d.ts +52 -48
- package/dist/hosted/framed-exec.d.ts +8 -19
- package/dist/hosted/framed-exec.js +21 -87
- package/dist/hosted/process.d.ts +21 -0
- package/dist/hosted/process.js +37 -2
- package/dist/hosted/provider.d.ts +32 -6
- package/dist/hosted/provider.js +239 -236
- package/dist/hosted/rest.d.ts +19 -0
- package/dist/hosted/rest.js +76 -0
- package/dist/hosted/scripts.d.ts +52 -8
- package/dist/hosted/scripts.js +118 -23
- package/dist/hosted/ssh-exec.d.ts +9 -7
- package/dist/hosted/ssh-exec.js +93 -54
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +9 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/kinds.d.ts +2 -0
- package/dist/modal.d.ts +6 -0
- package/dist/modal.js +40 -17
- package/dist/morph.d.ts +65 -0
- package/dist/morph.js +495 -0
- package/dist/phone-harness.d.ts +15 -5
- package/dist/phone-harness.js +50 -15
- package/dist/providers.d.ts +4 -2
- package/dist/screen-watch.js +2 -2
- package/package.json +20 -2
package/box/install.sh
CHANGED
|
@@ -19,6 +19,8 @@ ARCHIL_SHA256_AMD64=f219e70287e8152f3f0c7222e1c3319f4665897235af7c33a8846e56a5a5
|
|
|
19
19
|
ARCHIL_SHA256_ARM64=10ed430e51c268af095dd9e6c7aa6cdbb951d2430d62a76458719db168f40c0e
|
|
20
20
|
# Where the provider runs the root helper from.
|
|
21
21
|
HELPER=/usr/local/sbin/agentrun-archil
|
|
22
|
+
# The entrypoint of a machine that dials the server (dial below).
|
|
23
|
+
DIAL=/usr/local/bin/agentrun-dial
|
|
22
24
|
|
|
23
25
|
here=$(dirname "$0")
|
|
24
26
|
|
|
@@ -62,15 +64,74 @@ helper() {
|
|
|
62
64
|
cp "$here/agentrun-archil" "$HELPER"
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
# (
|
|
67
|
+
# agentrun-dial, the image's entrypoint when the provider's create set AGENTRUN_ATTACH_URL (the Dockerfile's CMD): for a
|
|
68
|
+
# vendor that boots the image with env but has no exec stream into it, so the machine dials the server
|
|
69
|
+
# (spec/computer/attach.md). The provider's exec path never runs it.
|
|
70
|
+
dial() {
|
|
71
|
+
cat >"$DIAL" <<'EOF'
|
|
72
|
+
#!/bin/sh
|
|
73
|
+
# agentrun-dial (written by the box image's install.sh): a machine that dials the server. From the env the provider's
|
|
74
|
+
# create gave it, it fetches the server's computerd with the machine's token, checks its sha256, installs it root's alone
|
|
75
|
+
# where the provider's exec install puts it, starts `computerd init` as that start does, in a clean environment without
|
|
76
|
+
# the token, and becomes `computerd attach` with the attach URL and the token alone in its environment. A daemon whose
|
|
77
|
+
# sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. Exits 2 for env missing, 3 when the fetch failed,
|
|
78
|
+
# 4 for a sha256 mismatch, 5 when init never listened; else it is `computerd attach` and exits as it does.
|
|
79
|
+
set -euf
|
|
80
|
+
DAEMON=/opt/agentrun/computerd
|
|
81
|
+
HOME_DIR=/work
|
|
82
|
+
SOCKET_DIR=/run/agentrun
|
|
83
|
+
INIT_LOG=/run/agentrun-init.log
|
|
84
|
+
OWNER=0:0
|
|
85
|
+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
86
|
+
for v in AGENTRUN_ATTACH_URL AGENTRUN_ATTACH_TOKEN AGENTRUN_DAEMON_URL AGENTRUN_DAEMON_SHA256 AGENTRUN_INIT_ARGS; do
|
|
87
|
+
eval "[ -n \"\${$v-}\" ]" || { echo "agentrun-dial: $v is not set; the provider's create sets it" >&2; exit 2; }
|
|
88
|
+
done
|
|
89
|
+
mkdir -p "${DAEMON%/*}" "$HOME_DIR" "$SOCKET_DIR"
|
|
90
|
+
chown "$OWNER" "${DAEMON%/*}" "$SOCKET_DIR"
|
|
91
|
+
chmod 0755 "${DAEMON%/*}"
|
|
92
|
+
# init's socket is root's alone: whoever can connect to it drives the machine.
|
|
93
|
+
chmod 0700 "$SOCKET_DIR"
|
|
94
|
+
rm -f "$DAEMON.part"
|
|
95
|
+
# The token goes to curl on its stdin, never on a command line, which every user may read in /proc.
|
|
96
|
+
printf 'Authorization: Bearer %s\n' "$AGENTRUN_ATTACH_TOKEN" |
|
|
97
|
+
curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
|
|
98
|
+
{ echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL failed" >&2; rm -f "$DAEMON.part"; exit 3; }
|
|
99
|
+
sum=$(sha256sum "$DAEMON.part" | cut -c1-64)
|
|
100
|
+
if [ "$sum" != "$AGENTRUN_DAEMON_SHA256" ]; then
|
|
101
|
+
rm -f "$DAEMON.part"
|
|
102
|
+
echo "agentrun-dial: the daemon from $AGENTRUN_DAEMON_URL reads sha256 $sum, not $AGENTRUN_DAEMON_SHA256, so nothing runs" >&2
|
|
103
|
+
exit 4
|
|
104
|
+
fi
|
|
105
|
+
chown "$OWNER" "$DAEMON.part"
|
|
106
|
+
chmod 0755 "$DAEMON.part"
|
|
107
|
+
mv -f "$DAEMON.part" "$DAEMON"
|
|
108
|
+
# init's arguments are words with no space and no pattern (set -f): split, never globbed.
|
|
109
|
+
env -i PATH="$PATH" HOME="$HOME_DIR" AGENTRUN_COMPUTERD_SOCKET="$SOCKET_DIR/computerd.sock" \
|
|
110
|
+
setsid sh -c 'cd "$HOME" && exec "$@"' sh "$DAEMON" init $AGENTRUN_INIT_ARGS >"$INIT_LOG" 2>&1 </dev/null &
|
|
111
|
+
i=0
|
|
112
|
+
until [ -S "$SOCKET_DIR/computerd.sock" ]; do
|
|
113
|
+
i=$((i + 1))
|
|
114
|
+
[ "$i" -le 300 ] || { echo "agentrun-dial: init did not listen at $SOCKET_DIR/computerd.sock within 30 s; its log:" >&2; cat "$INIT_LOG" >&2; exit 5; }
|
|
115
|
+
sleep 0.1
|
|
116
|
+
done
|
|
117
|
+
# attach's environment: the URL and token alone (it dials init at its default socket, SOCKET_DIR's).
|
|
118
|
+
for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
|
|
119
|
+
case "$v" in AGENTRUN_ATTACH_URL | AGENTRUN_ATTACH_TOKEN | DAEMON) ;; *) unset "$v" 2>/dev/null || : ;; esac
|
|
120
|
+
done
|
|
121
|
+
exec "$DAEMON" attach
|
|
122
|
+
EOF
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# What the helper and agentrun-dial run, where they run it from: an image that lacks one fails here, not at a run's
|
|
126
|
+
# first mount. And no way to root for the tool user: no sudo, no sudoers. A provider's builder may add sudo to the base
|
|
127
|
+
# before these steps (E2B's does): it is taken away first, the package where it is installed and every sudoers file,
|
|
128
|
+
# then checked gone.
|
|
68
129
|
checked() {
|
|
69
130
|
if dpkg -s sudo >/dev/null 2>&1; then SUDO_FORCE_REMOVE=yes DEBIAN_FRONTEND=noninteractive apt-get purge -y -qq sudo >/dev/null; fi
|
|
70
131
|
rm -rf /etc/sudoers /etc/sudoers.d
|
|
71
|
-
chown root:root "$HELPER"
|
|
72
|
-
chmod 0755 "$HELPER"
|
|
73
|
-
for x in /usr/bin/archil /usr/bin/awk /usr/bin/realpath /usr/bin/mount /usr/bin/chown /usr/bin/find /usr/bin/id /usr/bin/ls; do
|
|
132
|
+
chown root:root "$HELPER" "$DIAL"
|
|
133
|
+
chmod 0755 "$HELPER" "$DIAL"
|
|
134
|
+
for x in /usr/bin/archil /usr/bin/awk /usr/bin/realpath /usr/bin/mount /usr/bin/chown /usr/bin/find /usr/bin/id /usr/bin/ls /usr/bin/curl /usr/bin/setsid /usr/bin/sha256sum; do
|
|
74
135
|
[ -x "$x" ] || { echo "the image has no $x" >&2; exit 1; }
|
|
75
136
|
done
|
|
76
137
|
! command -v sudo >/dev/null 2>&1 || { echo "the image has sudo" >&2; exit 1; }
|
|
@@ -81,7 +142,7 @@ checked() {
|
|
|
81
142
|
}
|
|
82
143
|
|
|
83
144
|
case "$*" in
|
|
84
|
-
"") packages; desktop; helper; checked ;;
|
|
145
|
+
"") packages; desktop; helper; dial; checked ;;
|
|
85
146
|
checked) checked ;;
|
|
86
147
|
*) echo "usage: sh install.sh [checked]" >&2; exit 2 ;;
|
|
87
148
|
esac
|
package/dist/attach.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type Readable, Writable } from "node:stream";
|
|
2
|
-
import { type HelloResult } from "./protocol.js";
|
|
2
|
+
import { type ComputerKind, type ComputerOs, type HelloResult } from "./protocol.js";
|
|
3
3
|
import { type ComputerConnection, type ComputerProvider } from "./provider.js";
|
|
4
4
|
import { type Result } from "./result.js";
|
|
5
5
|
export declare const ATTACH_PATH = "/v2/computers/attach";
|
|
6
|
+
/** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
|
|
7
|
+
export declare const DAEMON_PATH = "/v2/computers/daemon";
|
|
6
8
|
/** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
|
|
7
9
|
export declare const ATTACH_SUBPROTOCOL = "agentrun.computer.0.2";
|
|
8
10
|
/** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
|
|
@@ -82,7 +84,48 @@ export interface PairedComputer {
|
|
|
82
84
|
/** What it paired as: its hello at pairing. A later hello of another kind or os is refused (ATTACH_CLOSE.mismatch). */
|
|
83
85
|
hello: HelloResult;
|
|
84
86
|
labels: Record<string, string>;
|
|
87
|
+
/** A hosted machine that dials with a minted token (mintedComputer), not a person's: its hello keeps its arch too. */
|
|
88
|
+
minted?: true;
|
|
85
89
|
}
|
|
90
|
+
/** What a hosted machine's token is minted for: the computer its hello must say it is, and when the token stops. */
|
|
91
|
+
export interface MachineMint {
|
|
92
|
+
kind: ComputerKind;
|
|
93
|
+
os: ComputerOs;
|
|
94
|
+
/** Go's name, as hello says it: amd64, arm64. */
|
|
95
|
+
arch: string;
|
|
96
|
+
/** The machine's backstopAt: past it the token is refused, whatever else holds. */
|
|
97
|
+
expiresAt: Date;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The tokens of hosted machines that dial (spec/computer/attach.md, Hosted machines that dial), as the server's store
|
|
101
|
+
* keeps them: HostedProvider mints one at each dial create and revokes it at the delete. A token is `art_` and 64 hex
|
|
102
|
+
* digits (32 random bytes); the store keeps only its sha256, bound to the machine and its mint, and never logs it. The
|
|
103
|
+
* server's attach upgrade and its daemon route take it while it is neither revoked nor past expiresAt, and hand its
|
|
104
|
+
* socket to the AttachHub as mintedComputer(machine, mint). machine is the computer's name, computer-<12 hex digits>,
|
|
105
|
+
* from its create's request id (computerNameFor): what the provider's connect and release are given.
|
|
106
|
+
*/
|
|
107
|
+
export interface MachineTokens {
|
|
108
|
+
/** A new token for the machine, replacing any it had. */
|
|
109
|
+
mint(machine: string, mint: MachineMint): Promise<string>;
|
|
110
|
+
/** The machine's token refused from now on; a machine with none is done. */
|
|
111
|
+
revoke(machine: string): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* MachineTokens in one process's memory, as serve's store keeps them (the sha256 alone): for tests and a conformance
|
|
115
|
+
* kit. check is what the server's attach and daemon routes ask of a token.
|
|
116
|
+
*/
|
|
117
|
+
export declare class MemoryMachineTokens implements MachineTokens {
|
|
118
|
+
#private;
|
|
119
|
+
mint(machine: string, mint: MachineMint): Promise<string>;
|
|
120
|
+
revoke(machine: string): Promise<void>;
|
|
121
|
+
/** The machine and mint a token is good for at `at`: undefined for one unknown, revoked, or past its expiresAt. */
|
|
122
|
+
check(token: string, at?: Date): {
|
|
123
|
+
machine: string;
|
|
124
|
+
mint: MachineMint;
|
|
125
|
+
} | undefined;
|
|
126
|
+
}
|
|
127
|
+
/** A minted machine as the AttachHub takes its socket: under the machine's name, its hello held to the mint. */
|
|
128
|
+
export declare function mintedComputer(machine: string, { kind, os, arch }: Pick<MachineMint, "kind" | "os" | "arch">): PairedComputer;
|
|
86
129
|
/**
|
|
87
130
|
* Why a hello may not stand for a paired computer, or undefined. The protocol version must be the server's; the
|
|
88
131
|
* driver's own version may be any: a person's installed app updates on its own schedule, and the server cannot
|
|
@@ -110,6 +153,8 @@ export declare class AttachHub {
|
|
|
110
153
|
accept(paired: PairedComputer, socket: AttachSocket): Promise<Result<HelloResult>>;
|
|
111
154
|
/** Whether the computer is attached now. */
|
|
112
155
|
online(id: string): boolean;
|
|
156
|
+
/** When the computer's live connection said hello and went live; undefined while it is not attached. */
|
|
157
|
+
since(id: string): Date | undefined;
|
|
113
158
|
/** The hello of the computer's live connection: its driver's version and groups now, which an update may change. */
|
|
114
159
|
hello(id: string): HelloResult | undefined;
|
|
115
160
|
/**
|
package/dist/attach.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// with the token it got by pairing, and the same JSON-RPC messages travel as text frames, one message per frame. Serve
|
|
4
4
|
// is the caller: it sends hello first, then the run's calls. The AttachHub keeps one live connection per paired
|
|
5
5
|
// computer; attachedProvider hands that computer to a run as a provider, one run at a time.
|
|
6
|
-
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
7
7
|
import { PassThrough, Writable } from "node:stream";
|
|
8
8
|
import { DaemonClient } from "./client.js";
|
|
9
9
|
import { kindServed } from "./kinds.js";
|
|
@@ -11,6 +11,8 @@ import { PROTOCOL_VERSION } from "./protocol.js";
|
|
|
11
11
|
import { checkLifetime, kindRefusals, runLifetimeMs } from "./provider.js";
|
|
12
12
|
import { fail, ok } from "./result.js";
|
|
13
13
|
export const ATTACH_PATH = "/v2/computers/attach";
|
|
14
|
+
/** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
|
|
15
|
+
export const DAEMON_PATH = "/v2/computers/daemon";
|
|
14
16
|
/** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
|
|
15
17
|
export const ATTACH_SUBPROTOCOL = `agentrun.computer.${PROTOCOL_VERSION}`;
|
|
16
18
|
/** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
|
|
@@ -89,6 +91,39 @@ export function socketStreams(socket) {
|
|
|
89
91
|
});
|
|
90
92
|
return { readable, writable };
|
|
91
93
|
}
|
|
94
|
+
const sha256 = (token) => createHash("sha256").update(token).digest("hex");
|
|
95
|
+
/**
|
|
96
|
+
* MachineTokens in one process's memory, as serve's store keeps them (the sha256 alone): for tests and a conformance
|
|
97
|
+
* kit. check is what the server's attach and daemon routes ask of a token.
|
|
98
|
+
*/
|
|
99
|
+
export class MemoryMachineTokens {
|
|
100
|
+
#held = new Map();
|
|
101
|
+
#hashOf = new Map();
|
|
102
|
+
// No await in either: a mint replaces the machine's token at once, so two of one machine leave one token, not two.
|
|
103
|
+
async mint(machine, mint) {
|
|
104
|
+
this.#drop(machine);
|
|
105
|
+
const token = `art_${randomBytes(32).toString("hex")}`;
|
|
106
|
+
this.#held.set(sha256(token), { machine, mint: { ...mint } });
|
|
107
|
+
this.#hashOf.set(machine, sha256(token));
|
|
108
|
+
return token;
|
|
109
|
+
}
|
|
110
|
+
async revoke(machine) {
|
|
111
|
+
this.#drop(machine);
|
|
112
|
+
}
|
|
113
|
+
#drop(machine) {
|
|
114
|
+
this.#held.delete(this.#hashOf.get(machine) ?? "");
|
|
115
|
+
this.#hashOf.delete(machine);
|
|
116
|
+
}
|
|
117
|
+
/** The machine and mint a token is good for at `at`: undefined for one unknown, revoked, or past its expiresAt. */
|
|
118
|
+
check(token, at = new Date()) {
|
|
119
|
+
const held = this.#held.get(sha256(token));
|
|
120
|
+
return held === undefined || at.getTime() > held.mint.expiresAt.getTime() ? undefined : held;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** A minted machine as the AttachHub takes its socket: under the machine's name, its hello held to the mint. */
|
|
124
|
+
export function mintedComputer(machine, { kind, os, arch }) {
|
|
125
|
+
return { id: machine, name: machine, hello: { protocol: PROTOCOL_VERSION, version: "", os, kind, arch, groups: [] }, labels: {}, minted: true };
|
|
126
|
+
}
|
|
92
127
|
/** Whether protocol version a ("0.3") comes after b ("0.2"), part by part as numbers. */
|
|
93
128
|
function laterProtocol(a, b) {
|
|
94
129
|
const [x, y] = [a, b].map((version) => version.split(".").map((part) => Number.parseInt(part, 10) || 0));
|
|
@@ -103,8 +138,9 @@ function laterProtocol(a, b) {
|
|
|
103
138
|
* replace it the way a provider replaces a copied daemon.
|
|
104
139
|
*/
|
|
105
140
|
export function helloMismatch(paired, hello) {
|
|
106
|
-
// Serve names no OS and no driver app: one way to update, in the same words for every computer.
|
|
107
|
-
|
|
141
|
+
// Serve names no OS and no driver app: one way to update, in the same words for every computer. A minted machine
|
|
142
|
+
// fetched this server's own computerd at boot, so another build there is not one this server gave it.
|
|
143
|
+
const update = paired.minted ? `${paired.name} runs a computerd that is not this server's build: create the computer again` : `update the driver on ${paired.name} (the download is on the console's Computers page)`;
|
|
108
144
|
const said = hello;
|
|
109
145
|
if (typeof said !== "object" || said === null || typeof said.protocol !== "string" || typeof said.version !== "string") {
|
|
110
146
|
return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver answered hello without its protocol and version: ${update}` };
|
|
@@ -124,6 +160,10 @@ export function helloMismatch(paired, hello) {
|
|
|
124
160
|
if (missing.length > 0) {
|
|
125
161
|
return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver ${hello.version} answered a protocol ${PROTOCOL_VERSION} hello without ${missing.join(", ")}: ${update}` };
|
|
126
162
|
}
|
|
163
|
+
if (paired.minted && (hello.kind !== paired.hello.kind || hello.os !== paired.hello.os || hello.arch !== paired.hello.arch)) {
|
|
164
|
+
const was = paired.hello;
|
|
165
|
+
return { code: ATTACH_CLOSE.mismatch, message: `${paired.name} was made a ${was.os} ${was.kind} on ${was.arch} and says ${hello.os} ${hello.kind} on ${hello.arch}: its token is that machine's alone` };
|
|
166
|
+
}
|
|
127
167
|
if (hello.kind !== paired.hello.kind || hello.os !== paired.hello.os) {
|
|
128
168
|
return { code: ATTACH_CLOSE.mismatch, message: `${paired.name} paired as a ${paired.hello.os} ${paired.hello.kind} and now says ${hello.os} ${hello.kind}: pair it again` };
|
|
129
169
|
}
|
|
@@ -207,7 +247,7 @@ export class AttachHub {
|
|
|
207
247
|
}
|
|
208
248
|
if (closed)
|
|
209
249
|
return fail("gone", `${paired.name}'s socket closed while it said hello`);
|
|
210
|
-
mine = { socket, client, hello: hello.value, dial };
|
|
250
|
+
mine = { socket, client, hello: hello.value, dial, since: new Date() };
|
|
211
251
|
this.#live.set(paired.id, mine);
|
|
212
252
|
older?.socket.close(ATTACH_CLOSE.replaced, "the computer dialed again");
|
|
213
253
|
return hello;
|
|
@@ -216,6 +256,10 @@ export class AttachHub {
|
|
|
216
256
|
online(id) {
|
|
217
257
|
return this.#live.has(id);
|
|
218
258
|
}
|
|
259
|
+
/** When the computer's live connection said hello and went live; undefined while it is not attached. */
|
|
260
|
+
since(id) {
|
|
261
|
+
return this.#live.get(id)?.since;
|
|
262
|
+
}
|
|
219
263
|
/** The hello of the computer's live connection: its driver's version and groups now, which an update may change. */
|
|
220
264
|
hello(id) {
|
|
221
265
|
return this.#live.get(id)?.hello;
|
package/dist/box-image.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function boxRecipeHash(): string;
|
|
|
5
5
|
/** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
|
|
6
6
|
export declare const boxImageRef: () => string;
|
|
7
7
|
/**
|
|
8
|
-
* The E2B team that publishes the box template: release.yml's box
|
|
8
|
+
* The E2B team that publishes the box template: release.yml's box job builds the box image as the E2B template
|
|
9
9
|
* agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
|
|
10
10
|
* account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
|
|
11
11
|
*/
|
package/dist/box-image.js
CHANGED
|
@@ -15,7 +15,7 @@ export function boxRecipeHash() {
|
|
|
15
15
|
/** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
|
|
16
16
|
export const boxImageRef = () => `${BOX_IMAGE_REPOSITORY}:${boxRecipeHash()}`;
|
|
17
17
|
/**
|
|
18
|
-
* The E2B team that publishes the box template: release.yml's box
|
|
18
|
+
* The E2B team that publishes the box template: release.yml's box job builds the box image as the E2B template
|
|
19
19
|
* agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
|
|
20
20
|
* account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
|
|
21
21
|
*/
|
package/dist/boxd.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { HostedProvider, type HostedOptions } from "./hosted/provider.js";
|
|
2
|
+
import type { CallContext } from "./provider.js";
|
|
3
|
+
import { type Result } from "./result.js";
|
|
4
|
+
/** A machine as the SDK reports it (Machine, models.d.ts), as far as this host reads it. */
|
|
5
|
+
export interface BoxdMachine {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
status: string;
|
|
9
|
+
labels: Record<string, string>;
|
|
10
|
+
org: {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
} | null;
|
|
14
|
+
createdAt: Date | null;
|
|
15
|
+
}
|
|
16
|
+
/** A streamed exec (ExecStream, exec.d.ts): stdout is the stream itself. */
|
|
17
|
+
export interface BoxdExecStream extends AsyncIterable<Uint8Array> {
|
|
18
|
+
readonly stderr: AsyncIterable<Uint8Array>;
|
|
19
|
+
write(data: Uint8Array): void;
|
|
20
|
+
end(): void;
|
|
21
|
+
wait(): Promise<number>;
|
|
22
|
+
close(): void;
|
|
23
|
+
}
|
|
24
|
+
/** The SDK's machines namespace, as far as this host calls it (Machines, machines.d.ts). */
|
|
25
|
+
export interface BoxdMachines {
|
|
26
|
+
/** deleteAfter: seconds from now until boxd deletes the machine, whatever it is doing. */
|
|
27
|
+
create(params: {
|
|
28
|
+
name: string;
|
|
29
|
+
org?: string;
|
|
30
|
+
labels?: Record<string, string>;
|
|
31
|
+
isolated: true;
|
|
32
|
+
config: {
|
|
33
|
+
autoSuspendTimeout: 0;
|
|
34
|
+
vcpu?: number;
|
|
35
|
+
memory?: string;
|
|
36
|
+
};
|
|
37
|
+
fromSnapshot?: string;
|
|
38
|
+
deleteAfter?: number;
|
|
39
|
+
}): Promise<BoxdMachine>;
|
|
40
|
+
get(id: string): Promise<BoxdMachine>;
|
|
41
|
+
list(params: {
|
|
42
|
+
org?: string;
|
|
43
|
+
labels: Record<string, string>;
|
|
44
|
+
}): Promise<Iterable<BoxdMachine>>;
|
|
45
|
+
delete(id: string): Promise<void>;
|
|
46
|
+
streamExec(id: string, params: {
|
|
47
|
+
command: string;
|
|
48
|
+
}): BoxdExecStream;
|
|
49
|
+
readonly files: {
|
|
50
|
+
upload(id: string, path: string, data: Uint8Array): Promise<number>;
|
|
51
|
+
};
|
|
52
|
+
waitUntilReady(id: string, params: {
|
|
53
|
+
timeout: number;
|
|
54
|
+
}): Promise<BoxdMachine>;
|
|
55
|
+
setEgressAllow(id: string, entries: string[]): Promise<string[]>;
|
|
56
|
+
setAutoHibernateTimeout(id: string, seconds: number): Promise<void>;
|
|
57
|
+
updateLabels(id: string, params: {
|
|
58
|
+
set: Record<string, string>;
|
|
59
|
+
}): Promise<Record<string, string>>;
|
|
60
|
+
}
|
|
61
|
+
/** A snapshot as the SDK reads one (Snapshot, models.d.ts), as far as this host reads it. */
|
|
62
|
+
export interface BoxdSnapshot {
|
|
63
|
+
name: string;
|
|
64
|
+
/** "pending" until the capture lands, then "ready" or "failed" (ArtifactStatus). */
|
|
65
|
+
status: string;
|
|
66
|
+
/** True unless its bytes are on a worker's disk: boxd makes no machine from it until boxd's operator unarchives it. */
|
|
67
|
+
archived: boolean;
|
|
68
|
+
storage: string;
|
|
69
|
+
}
|
|
70
|
+
/** The SDK's snapshots namespace, as far as this host calls it (Snapshots, snapshots.d.ts). */
|
|
71
|
+
export interface BoxdSnapshots {
|
|
72
|
+
/** Captures a running machine (memory and disk) under the name; answers before the capture lands. */
|
|
73
|
+
create(machine: string, name: string): Promise<unknown>;
|
|
74
|
+
get(name: string, params: {
|
|
75
|
+
org?: string;
|
|
76
|
+
}): Promise<BoxdSnapshot>;
|
|
77
|
+
}
|
|
78
|
+
/** The SDK's Boxd class: given the key, the address and the region ("" is home) so it reads none from the environment. */
|
|
79
|
+
export type BoxdClientClass = new (options: {
|
|
80
|
+
apiKey: string;
|
|
81
|
+
baseURL: string;
|
|
82
|
+
region: string;
|
|
83
|
+
timeout: number;
|
|
84
|
+
maxRetries?: number;
|
|
85
|
+
}) => {
|
|
86
|
+
readonly machines: BoxdMachines;
|
|
87
|
+
readonly snapshots: BoxdSnapshots;
|
|
88
|
+
};
|
|
89
|
+
export interface BoxdProviderOptions extends HostedOptions {
|
|
90
|
+
/** The boxd API key: the caller passes it; the provider never reads it from the environment or puts it in a computer. */
|
|
91
|
+
apiKey: string;
|
|
92
|
+
Boxd: BoxdClientClass;
|
|
93
|
+
/** The org (name or id) machines are made in and listed from. Unset: the key's own. */
|
|
94
|
+
org?: string;
|
|
95
|
+
/** "fra", "nyc", ... Unset: the API's home region. */
|
|
96
|
+
region?: string;
|
|
97
|
+
/** Default https://boxd.sh:9443, the SDK's own. */
|
|
98
|
+
baseUrl?: string;
|
|
99
|
+
/** A boxd size, both or neither: 1 and 4G, 2 and 8G, 4 and 16G, 8 and 32G. Unset: the org's default. */
|
|
100
|
+
vcpu?: number;
|
|
101
|
+
memory?: string;
|
|
102
|
+
}
|
|
103
|
+
export type BoxdOptions = Omit<BoxdProviderOptions, "Boxd"> & {
|
|
104
|
+
Boxd?: BoxdClientClass;
|
|
105
|
+
};
|
|
106
|
+
/** A BoxdProvider from its options alone; throws in words when the key is missing, never echoing one. */
|
|
107
|
+
export declare function create(options: BoxdOptions): Promise<BoxdProvider>;
|
|
108
|
+
/** The conformance CLI's module for boxd. */
|
|
109
|
+
export declare const conformance: () => Promise<typeof import("./conformance/boxd.js")>;
|
|
110
|
+
/** The desktop snapshot this package's recipe names: agentrun-desktop-<12 hex of the recipe's sha256>. */
|
|
111
|
+
export declare const boxdDesktopSnapshot: () => string;
|
|
112
|
+
/**
|
|
113
|
+
* Computers that are boxd machines, on the shared adapter. A spec's image is "default" or a boxd snapshot's name. A
|
|
114
|
+
* server starts a sandbox from boxd's own image, and a desktop from the snapshot prepareImage() answers.
|
|
115
|
+
*/
|
|
116
|
+
export declare class BoxdProvider extends HostedProvider {
|
|
117
|
+
/**
|
|
118
|
+
* The provider contract's prepareImage (its descriptor declares it). A sandbox: boxd's own image, with no call. A
|
|
119
|
+
* desktop: the desktop snapshot (boxdDesktopSnapshot) in the key's org, found or built once (BoxdHost.desktopSnapshot),
|
|
120
|
+
* so a new recipe is a new snapshot; onWait is told "build" once, before a build, never when the org has it.
|
|
121
|
+
*/
|
|
122
|
+
prepareImage(context?: CallContext & {
|
|
123
|
+
onWait?: (making: "build" | "pull", tag: string) => void;
|
|
124
|
+
}): Promise<Result<string>>;
|
|
125
|
+
constructor(options: BoxdProviderOptions);
|
|
126
|
+
}
|