@parcha/agentrun-computer 0.1.0-beta.58 → 0.1.0-beta.59

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.
Files changed (131) hide show
  1. package/README.md +187 -62
  2. package/box/Dockerfile +4 -3
  3. package/box/install.sh +57 -11
  4. package/dist/agent37.js +6 -9
  5. package/dist/attach.d.ts +24 -4
  6. package/dist/attach.js +50 -19
  7. package/dist/boxd.js +22 -9
  8. package/dist/browserbase.d.ts +6 -2
  9. package/dist/browserbase.js +50 -7
  10. package/dist/child-env.d.ts +11 -0
  11. package/dist/child-env.js +22 -0
  12. package/dist/chrome.d.ts +5 -2
  13. package/dist/chrome.js +5 -2
  14. package/dist/cloudflare.d.ts +2 -0
  15. package/dist/cloudflare.js +5 -3
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +1 -1
  19. package/dist/conformance/agent37.d.ts +10 -38
  20. package/dist/conformance/agent37.js +25 -113
  21. package/dist/conformance/archil.d.ts +13 -3
  22. package/dist/conformance/archil.js +22 -17
  23. package/dist/conformance/boxd.d.ts +8 -31
  24. package/dist/conformance/boxd.js +19 -74
  25. package/dist/conformance/browserbase.d.ts +3 -6
  26. package/dist/conformance/browserbase.js +6 -17
  27. package/dist/conformance/cases/health.js +6 -3
  28. package/dist/conformance/cli.d.ts +3 -1
  29. package/dist/conformance/cli.js +69 -9
  30. package/dist/conformance/cloudflare.d.ts +3 -6
  31. package/dist/conformance/cloudflare.js +7 -15
  32. package/dist/conformance/daytona.d.ts +6 -20
  33. package/dist/conformance/daytona.js +22 -57
  34. package/dist/conformance/dial-only.d.ts +4 -3
  35. package/dist/conformance/dial-only.js +3 -3
  36. package/dist/conformance/docker.d.ts +4 -5
  37. package/dist/conformance/docker.js +8 -14
  38. package/dist/conformance/e2b.d.ts +10 -36
  39. package/dist/conformance/e2b.js +27 -84
  40. package/dist/conformance/fly.d.ts +3 -6
  41. package/dist/conformance/fly.js +2 -6
  42. package/dist/conformance/groundbox.d.ts +7 -23
  43. package/dist/conformance/groundbox.js +16 -56
  44. package/dist/conformance/index.d.ts +1 -0
  45. package/dist/conformance/index.js +1 -0
  46. package/dist/conformance/kernel.d.ts +3 -6
  47. package/dist/conformance/kernel.js +5 -15
  48. package/dist/conformance/kind.d.ts +0 -6
  49. package/dist/conformance/kind.js +0 -4
  50. package/dist/conformance/local-chrome.d.ts +5 -7
  51. package/dist/conformance/local-chrome.js +7 -11
  52. package/dist/conformance/modal.d.ts +10 -38
  53. package/dist/conformance/modal.js +27 -74
  54. package/dist/conformance/module-kit.d.ts +87 -0
  55. package/dist/conformance/module-kit.js +88 -0
  56. package/dist/conformance/morph.d.ts +7 -23
  57. package/dist/conformance/morph.js +20 -66
  58. package/dist/conformance/orgo.d.ts +5 -10
  59. package/dist/conformance/orgo.js +15 -27
  60. package/dist/conformance/phone-harness.d.ts +3 -5
  61. package/dist/conformance/phone-harness.js +3 -11
  62. package/dist/conformance/runner.d.ts +13 -3
  63. package/dist/conformance/runner.js +32 -11
  64. package/dist/conformance/smolcloud.d.ts +7 -23
  65. package/dist/conformance/smolcloud.js +16 -49
  66. package/dist/conformance/sweep.d.ts +10 -5
  67. package/dist/conformance/sweep.js +91 -38
  68. package/dist/conformance/tti.d.ts +69 -0
  69. package/dist/conformance/tti.js +205 -0
  70. package/dist/conformance/types.d.ts +9 -2
  71. package/dist/daytona.js +60 -20
  72. package/dist/descriptor.d.ts +10 -0
  73. package/dist/descriptor.js +7 -0
  74. package/dist/descriptors/browserbase.d.ts +3 -0
  75. package/dist/descriptors/browserbase.js +4 -0
  76. package/dist/descriptors/docker.d.ts +1 -0
  77. package/dist/descriptors/docker.js +3 -0
  78. package/dist/descriptors/env-names.d.ts +32 -0
  79. package/dist/descriptors/env-names.js +60 -0
  80. package/dist/descriptors/index.d.ts +9 -2
  81. package/dist/descriptors/kernel.d.ts +3 -0
  82. package/dist/descriptors/kernel.js +2 -0
  83. package/dist/descriptors/local-chrome.d.ts +1 -1
  84. package/dist/descriptors/local-chrome.js +5 -3
  85. package/dist/descriptors/phone-harness.d.ts +1 -1
  86. package/dist/descriptors/phone-harness.js +4 -2
  87. package/dist/docker/egress.d.ts +7 -0
  88. package/dist/docker/egress.js +8 -0
  89. package/dist/docker/image.d.ts +5 -1
  90. package/dist/docker/image.js +12 -8
  91. package/dist/docker.d.ts +52 -13
  92. package/dist/docker.js +166 -92
  93. package/dist/drift.js +6 -6
  94. package/dist/e2b.d.ts +2 -2
  95. package/dist/e2b.js +2 -3
  96. package/dist/groundbox.js +6 -6
  97. package/dist/host.d.ts +23 -0
  98. package/dist/hosted/download.d.ts +23 -0
  99. package/dist/hosted/download.js +144 -0
  100. package/dist/hosted/process.d.ts +5 -0
  101. package/dist/hosted/process.js +20 -0
  102. package/dist/hosted/provider.js +120 -48
  103. package/dist/hosted/rest.d.ts +19 -8
  104. package/dist/hosted/rest.js +47 -14
  105. package/dist/hosted/scripts.d.ts +10 -0
  106. package/dist/hosted/scripts.js +23 -2
  107. package/dist/index.d.ts +3 -1
  108. package/dist/index.js +3 -1
  109. package/dist/janitor.d.ts +7 -1
  110. package/dist/janitor.js +2 -2
  111. package/dist/kernel.js +1 -1
  112. package/dist/local-chrome.d.ts +5 -2
  113. package/dist/local-chrome.js +4 -2
  114. package/dist/local-supervisor.js +1 -0
  115. package/dist/modal.d.ts +6 -5
  116. package/dist/modal.js +7 -7
  117. package/dist/morph.js +5 -8
  118. package/dist/orgo-channel.d.ts +3 -2
  119. package/dist/orgo-channel.js +3 -3
  120. package/dist/orgo-desktop.js +2 -4
  121. package/dist/orgo.js +2 -4
  122. package/dist/phone-harness.d.ts +7 -5
  123. package/dist/phone-harness.js +60 -61
  124. package/dist/protocol.d.ts +10 -0
  125. package/dist/protocol.js +17 -0
  126. package/dist/provider.d.ts +6 -2
  127. package/dist/screen-watch.d.ts +6 -1
  128. package/dist/screen-watch.js +166 -12
  129. package/dist/vendor-sdk.d.ts +9 -0
  130. package/dist/vendor-sdk.js +26 -0
  131. package/package.json +8 -1
package/box/install.sh CHANGED
@@ -53,10 +53,10 @@ packages() {
53
53
  desktop() {
54
54
  apt-get update -qq
55
55
  DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
56
- xvfb xfwm4 x11-xserver-utils xfce4-terminal mousepad firefox-esr xdotool fonts-dejavu-core adwaita-icon-theme >/dev/null
56
+ xvfb xfwm4 x11-xserver-utils xfce4-terminal mousepad firefox-esr thunar xdotool fonts-dejavu-core adwaita-icon-theme >/dev/null
57
57
  rm -rf /var/lib/apt/lists/*
58
- for x in Xvfb xfwm4 dbus-run-session xsetroot xfce4-terminal mousepad firefox-esr xdotool; do command -v "$x" >/dev/null || { echo "the image has no $x" >&2; exit 1; }; done
59
- for app in org.xfce.mousepad xfce4-terminal firefox-esr; do [ -f "/usr/share/applications/$app.desktop" ] || { echo "the image has no desktop file $app.desktop" >&2; exit 1; }; done
58
+ for x in Xvfb xfwm4 dbus-run-session xsetroot xfce4-terminal mousepad firefox-esr thunar xdotool; do command -v "$x" >/dev/null || { echo "the image has no $x" >&2; exit 1; }; done
59
+ for app in org.xfce.mousepad xfce4-terminal firefox-esr thunar; do [ -f "/usr/share/applications/$app.desktop" ] || { echo "the image has no desktop file $app.desktop" >&2; exit 1; }; done
60
60
  }
61
61
 
62
62
  # The root helper, from beside this file.
@@ -77,8 +77,12 @@ dial() {
77
77
  # gives /workspace to init's user (its --user), 0700, where a synced folder's runner pushes the run's folder. A daemon
78
78
  # whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. With AGENTRUN_ATTACH_EGRESS, the operator's
79
79
  # relay (<IPv4>:<port>), the fetch and attach's dial both connect to the relay and speak TLS and HTTP to the URL's host
80
- # through it, and attach is given it too. Exits 2 for env missing or a malformed relay, 3 when the fetch failed, 4 for
81
- # a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
80
+ # through it, and attach is given it too. The fetch is tried again, after 1, 2, 4 then 8 s, on a connection that failed
81
+ # (refused, reset, dropped in TLS, timed out) or an HTTP 5xx, within FETCH_S seconds in all (each try's transfer is
82
+ # held to the seconds left, so a stalled or trickling one ends there too), one line on stderr per retry;
83
+ # an HTTP 4xx is the server's refusal and is never tried again. Exits 2 for env missing or a malformed relay, 3 when the
84
+ # fetch failed, 4 for a sha256 mismatch, 5 when init never listened (init is ended first, so agentrun-dial may be
85
+ # started again), 6 when /workspace was not made init's user's, 7 when the server refused the fetch; else it is
82
86
  # `computerd attach` and exits as it does.
83
87
  set -euf
84
88
  DAEMON=/opt/agentrun/computerd
@@ -87,6 +91,8 @@ SOCKET_DIR=/run/agentrun
87
91
  INIT_LOG=/run/agentrun-init.log
88
92
  WORKSPACE=/workspace
89
93
  OWNER=0:0
94
+ FETCH_S=45
95
+ INIT_WAIT_TENTHS=300
90
96
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
91
97
  for v in AGENTRUN_ATTACH_URL AGENTRUN_ATTACH_TOKEN AGENTRUN_DAEMON_URL AGENTRUN_DAEMON_SHA256 AGENTRUN_INIT_ARGS; do
92
98
  eval "[ -n \"\${$v-}\" ]" || { echo "agentrun-dial: $v is not set; the provider's create sets it" >&2; exit 2; }
@@ -117,10 +123,41 @@ chmod 0755 "${DAEMON%/*}"
117
123
  # init's socket is root's alone: whoever can connect to it drives the machine.
118
124
  chmod 0700 "$SOCKET_DIR"
119
125
  rm -f "$DAEMON.part"
120
- # The token goes to curl on its stdin, never on a command line, which every user may read in /proc.
121
- printf 'Authorization: Bearer %s\n' "$AGENTRUN_ATTACH_TOKEN" |
122
- curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 $relay -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
123
- { echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL${relay:+ through $AGENTRUN_ATTACH_EGRESS} failed" >&2; rm -f "$DAEMON.part"; exit 3; }
126
+ # One try of the fetch, in at most $1 seconds: the HTTP status on stdout, 000 when no answer came. The token goes to curl
127
+ # on its stdin, never on a command line, which every user may read in /proc.
128
+ fetch() {
129
+ printf 'Authorization: Bearer %s\n' "$AGENTRUN_ATTACH_TOKEN" |
130
+ curl -sS --connect-timeout 10 --max-time "$1" --speed-limit 1024 --speed-time 30 $relay -H @- -o "$DAEMON.part" -w '%{http_code}' "$AGENTRUN_DAEMON_URL"
131
+ }
132
+ unfetched() {
133
+ echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL${relay:+ through $AGENTRUN_ATTACH_EGRESS} failed: $1" >&2
134
+ rm -f "$DAEMON.part"
135
+ exit "$2"
136
+ }
137
+ tries() { if [ "$1" = 1 ]; then echo "1 try"; else echo "$1 tries"; fi; }
138
+ began=$(date +%s)
139
+ try=1
140
+ pause=1
141
+ why="no time was left"
142
+ while :; do
143
+ left=$((FETCH_S - ($(date +%s) - began)))
144
+ [ "$left" -ge 1 ] || unfetched "$why, after $(tries $((try - 1)))" 3
145
+ code=0
146
+ answer=$(fetch "$left") || code=$?
147
+ case "$code:$answer" in
148
+ 0:2??) break ;;
149
+ 0:4??) unfetched "the server answered HTTP $answer" 7 ;;
150
+ 0:5??) why="the server answered HTTP $answer" ;;
151
+ 0:*) unfetched "the server answered HTTP $answer" 3 ;;
152
+ 5:* | 6:* | 7:* | 28:* | 35:* | 52:* | 55:* | 56:*) why="curl exit $code" ;;
153
+ *) unfetched "curl exit $code" 3 ;;
154
+ esac
155
+ [ $(($(date +%s) - began + pause)) -lt "$FETCH_S" ] || unfetched "$why, after $(tries "$try")" 3
156
+ echo "agentrun-dial: the daemon fetch's try $try failed ($why); trying again in $pause s" >&2
157
+ sleep "$pause"
158
+ try=$((try + 1))
159
+ [ "$pause" -ge 8 ] || pause=$((pause * 2))
160
+ done
124
161
  sum=$(sha256sum "$DAEMON.part" | cut -c1-64)
125
162
  if [ "$sum" != "$AGENTRUN_DAEMON_SHA256" ]; then
126
163
  rm -f "$DAEMON.part"
@@ -134,10 +171,19 @@ mv -f "$DAEMON.part" "$DAEMON"
134
171
  # DISPLAY, the display init's screen and input methods drive, as the provider's exec start gives it.
135
172
  env -i PATH="$PATH" HOME="$HOME_DIR" AGENTRUN_COMPUTERD_SOCKET="$SOCKET_DIR/computerd.sock" ${DISPLAY:+DISPLAY="$DISPLAY"} \
136
173
  setsid sh -c 'cd "$HOME" && exec "$@"' sh "$DAEMON" init $AGENTRUN_INIT_ARGS >"$INIT_LOG" 2>&1 </dev/null &
174
+ # setsid in a background job, never its process group's leader, makes init's own session in place: $! leads it.
175
+ init=$!
137
176
  i=0
138
177
  until [ -S "$SOCKET_DIR/computerd.sock" ]; do
139
178
  i=$((i + 1))
140
- [ "$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; }
179
+ if [ "$i" -gt "$INIT_WAIT_TENTHS" ]; then
180
+ echo "agentrun-dial: init did not listen at $SOCKET_DIR/computerd.sock within $((INIT_WAIT_TENTHS / 10)).$((INIT_WAIT_TENTHS % 10)) s; its log:" >&2
181
+ cat "$INIT_LOG" >&2
182
+ # init's group exists once setsid has run; until then $! is the start itself, ended by its pid alone.
183
+ kill -s TERM -- "-$init" 2>/dev/null || :
184
+ kill -s TERM "$init" 2>/dev/null || :
185
+ exit 5
186
+ fi
141
187
  sleep 0.1
142
188
  done
143
189
  # attach's environment: the URL and token alone, and the relay when given (it dials init at its default socket,
@@ -158,7 +204,7 @@ checked() {
158
204
  rm -rf /etc/sudoers /etc/sudoers.d
159
205
  chown root:root "$HELPER" "$DIAL"
160
206
  chmod 0755 "$HELPER" "$DIAL"
161
- 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
207
+ 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 /usr/bin/date; do
162
208
  [ -x "$x" ] || { echo "the image has no $x" >&2; exit 1; }
163
209
  done
164
210
  ! command -v sudo >/dev/null 2>&1 || { echo "the image has sudo" >&2; exit 1; }
package/dist/agent37.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // the adapter starts through the daemon), each a whole VM by default (type "vm"), or a gVisor sandbox
3
3
  // (type "default"). The control plane is Agent37's REST API over fetch (https://api.agent37.com/v1, a Bearer key);
4
4
  // every command (the daemon's upload, its install, init's start, the stdio bridge) goes over SSH, as root, through the
5
- // host's own ssh2 package, of which this package names only the slice it uses (Ssh2Module) and imports nothing at load.
5
+ // ssh2 package (an optional dependency), of which this package names only the slice it uses (Ssh2Module) and imports nothing at load.
6
6
  // Agent37 has no SSH port on the internet: the SSH stream rides a binary WebSocket to wss://{id}-22022.agent37.app,
7
7
  // which the edge opens for the workspace key in X-Agent37-Key (npm agent37@0.4.1 src/cli.js, wsHandshake and runTunnel),
8
8
  // and the instance's sshd then takes the workspace's registered SSH key. Agent37's REST exec is one-shot (no stdin,
@@ -20,8 +20,7 @@ import { HostedProvider } from "./hosted/provider.js";
20
20
  import { pemOf, SshExec, SshTunnelError } from "./hosted/ssh-exec.js";
21
21
  import { dateOf, DOMAIN, isWhole } from "./hosted/values.js";
22
22
  import { failFor, ok } from "./result.js";
23
- /** Not a literal, so no type checker or bundler resolves ssh2 from this package. */
24
- const SSH2_PACKAGE = "ssh2";
23
+ import { vendorSdk } from "./vendor-sdk.js";
25
24
  const DEFAULT_API_URL = "https://api.agent37.com";
26
25
  const DEFAULT_PROXY_DOMAIN = "agent37.app";
27
26
  /** The port the platform's sshd answers on inside every instance, reached as {id}-22022.<domain> (cli.js:21, 720). */
@@ -407,7 +406,7 @@ class Agent37Host {
407
406
  export async function create(options) {
408
407
  const { ssh2: given, ...rest } = options ?? {};
409
408
  // ssh2 is CommonJS: its Client is a named export of the module, and of its default.
410
- const loaded = given ?? (await import(SSH2_PACKAGE));
409
+ const loaded = given ?? (await vendorSdk(AGENT37.label, "ssh2"));
411
410
  const ssh2 = typeof loaded.Client === "function" ? loaded : loaded.default;
412
411
  return new Agent37Provider({ ...rest, ssh2: ssh2 });
413
412
  }
@@ -456,9 +455,7 @@ export class Agent37Provider extends HostedProvider {
456
455
  throw new Error("options.fetch must be a function, as the global fetch is");
457
456
  if (typeof WebSocket !== "function")
458
457
  throw new Error("options.WebSocket must be a WebSocket class that takes headers, as Node's global one does");
459
- const api = new URL(httpsBase(apiUrl, "the Agent37 API URL"));
460
- if (api.search !== "" || api.hash !== "")
461
- throw new Error(`the Agent37 API URL takes no query or fragment, as ${DEFAULT_API_URL} has none: ${JSON.stringify(apiUrl)}`);
458
+ const api = httpsBase(apiUrl, "the Agent37 API URL");
462
459
  if (typeof proxyDomain !== "string" || !DOMAIN.test(proxyDomain))
463
460
  throw new Error(`proxyDomain must be a host name such as ${DEFAULT_PROXY_DOMAIN}, not ${JSON.stringify(proxyDomain)}`);
464
461
  if (type !== "vm" && type !== "default")
@@ -467,11 +464,11 @@ export class Agent37Provider extends HostedProvider {
467
464
  throw new Error(`region is us, eu or ap-south, not ${JSON.stringify(region)}`);
468
465
  if (region !== "us" && type !== "vm")
469
466
  throw new Error(`Agent37 runs type default in us alone: ${region} takes type vm`);
470
- const host = new Agent37Host({ apiKey, sshKey: privateKey, ssh2, fetch: fetcher, WebSocket, apiUrl: api.href.replace(/\/+$/, ""), proxyDomain, type, region });
467
+ const host = new Agent37Host({ apiKey, sshKey: privateKey, ssh2, fetch: fetcher, WebSocket, apiUrl: api, proxyDomain, type, region });
471
468
  super(host, { ...rest, timeouts: { createMs: DEFAULT_CREATE_MS, ...timeouts } });
472
469
  }
473
470
  }
474
471
  /** The workspace a key reaches, in words, for the sweep's scope: the key's sha256 prefix, never the key. */
475
472
  export function workspaceOf(apiKey, apiUrl = DEFAULT_API_URL) {
476
- return `the Agent37 workspace of the key sha256:${createHash("sha256").update(apiKey, "utf8").digest("hex").slice(0, 12)} at ${apiUrl.replace(/\/+$/, "")}`;
473
+ return `the Agent37 workspace of the key sha256:${createHash("sha256").update(apiKey, "utf8").digest("hex").slice(0, 12)} at ${httpsBase(apiUrl, "the Agent37 API URL")}`;
477
474
  }
package/dist/attach.d.ts CHANGED
@@ -14,8 +14,14 @@ export declare const ATTACH_EGRESS_ENV = "AGENTRUN_ATTACH_EGRESS";
14
14
  * it to the same shape. Anything else throws, in words.
15
15
  */
16
16
  export declare function attachEgressOf(text: string): string;
17
- /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
17
+ /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. */
18
18
  export declare const ATTACH_SUBPROTOCOL = "agentrun.computer.0.2";
19
+ /**
20
+ * The subprotocol of those a driver asked for that serve answers with: this server's own when it is asked for, as the
21
+ * answer tells the driver what the server speaks; else the first naming a protocol version that works with this one
22
+ * (helloProblem: 0.2 or a later 0.x); else undefined, and serve refuses the upgrade.
23
+ */
24
+ export declare function attachSubprotocolOf(asked: readonly string[]): string | undefined;
19
25
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
20
26
  export declare const ATTACH_HEARTBEAT_MS = 20000;
21
27
  /** A side that hears nothing, not even a pong, for this long closes the socket with ATTACH_CLOSE.idle. */
@@ -45,7 +51,7 @@ export declare const ATTACH_CLOSE: {
45
51
  readonly idle: 4408;
46
52
  /** The same computer dialed again; the older socket is closed. */
47
53
  readonly replaced: 4409;
48
- /** The driver speaks another protocol version, or its hello lacks a group its kind needs (kindServed): update it. */
54
+ /** The driver speaks a protocol the server does not take (helloProblem), or its hello lacks a group its kind needs (kindServed): update it. */
49
55
  readonly protocol: 4426;
50
56
  };
51
57
  /** Whether a driver dials again after a close with this code; false means a person must act (pair, update). */
@@ -151,8 +157,22 @@ export declare class MemoryMachineTokens implements MachineTokens {
151
157
  /** A minted machine as the AttachHub takes its socket: under the machine's name, its hello held to the mint. */
152
158
  export declare function mintedComputer(machine: string, { kind, os, arch }: Pick<MachineMint, "kind" | "os" | "arch">): PairedComputer;
153
159
  /**
154
- * Why a hello may not stand for a paired computer, or undefined. The protocol version must be the server's; the
155
- * driver's own version may be any: a person's installed app updates on its own schedule, and the server cannot
160
+ * Whether a refused driver's protocol version comes after this server's, so the server is the side to update: a
161
+ * "<major>.<minor>" later part by part as numbers ("1.0" after "0.2"). A version of any other shape ("0.2.1",
162
+ * "0.3-beta") is no server's, so updating the server never helps, and the driver is the side to update. Serve's pairing
163
+ * reads it too.
164
+ */
165
+ export declare function laterProtocol(protocol: string): boolean;
166
+ /**
167
+ * The words of serve's 426 at the attach upgrade, when no subprotocol `asked` names a protocol this server takes
168
+ * (attachSubprotocolOf). They name the side to update as helloMismatch does: the server when one asked names a later
169
+ * protocol, else the driver. A driver stops dialing on this 426 as on a 4426 close, and a 0.1 driver, which offers only
170
+ * its own subprotocol, is refused here and never reaches hello.
171
+ */
172
+ export declare function upgradeRefusal(paired: PairedComputer, asked: readonly string[]): string;
173
+ /**
174
+ * Why a hello may not stand for a paired computer, or undefined. The protocol version must work with the server's
175
+ * (helloProblem: 0.2 or a later 0.x); the driver's own version may be any: a person's installed app updates on its own schedule, and the server cannot
156
176
  * replace it the way a provider replaces a copied daemon.
157
177
  */
158
178
  export declare function helloMismatch(paired: PairedComputer, hello: HelloResult): {
package/dist/attach.js CHANGED
@@ -9,7 +9,7 @@ import { DaemonClient } from "./client.js";
9
9
  import { kindServed } from "./kinds.js";
10
10
  import { EPOCH_LABEL, epochOf } from "./labels.js";
11
11
  import { checkMount, WORKSPACE } from "./mount.js";
12
- import { PROTOCOL_VERSION } from "./protocol.js";
12
+ import { helloProblem, PROTOCOL_VERSION } from "./protocol.js";
13
13
  import { checkLifetime, kindRefusals, runLifetimeMs } from "./provider.js";
14
14
  import { fail, ok } from "./result.js";
15
15
  export const ATTACH_PATH = "/v2/computers/attach";
@@ -29,8 +29,19 @@ export function attachEgressOf(text) {
29
29
  throw new Error(`the attach egress is <IPv4 relay>:<port>, such as 192.0.2.40:18443, a port from 1 to 65535; not ${JSON.stringify(text)}`);
30
30
  return text;
31
31
  }
32
- /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
33
- export const ATTACH_SUBPROTOCOL = `agentrun.computer.${PROTOCOL_VERSION}`;
32
+ const SUBPROTOCOL_PREFIX = "agentrun.computer.";
33
+ /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. */
34
+ export const ATTACH_SUBPROTOCOL = `${SUBPROTOCOL_PREFIX}${PROTOCOL_VERSION}`;
35
+ /**
36
+ * The subprotocol of those a driver asked for that serve answers with: this server's own when it is asked for, as the
37
+ * answer tells the driver what the server speaks; else the first naming a protocol version that works with this one
38
+ * (helloProblem: 0.2 or a later 0.x); else undefined, and serve refuses the upgrade.
39
+ */
40
+ export function attachSubprotocolOf(asked) {
41
+ if (asked.includes(ATTACH_SUBPROTOCOL))
42
+ return ATTACH_SUBPROTOCOL;
43
+ return asked.find((one) => one.startsWith(SUBPROTOCOL_PREFIX) && helloProblem(one.slice(SUBPROTOCOL_PREFIX.length), "server") === undefined);
44
+ }
34
45
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
35
46
  export const ATTACH_HEARTBEAT_MS = 20_000;
36
47
  /** A side that hears nothing, not even a pong, for this long closes the socket with ATTACH_CLOSE.idle. */
@@ -60,7 +71,7 @@ export const ATTACH_CLOSE = {
60
71
  idle: 4408,
61
72
  /** The same computer dialed again; the older socket is closed. */
62
73
  replaced: 4409,
63
- /** The driver speaks another protocol version, or its hello lacks a group its kind needs (kindServed): update it. */
74
+ /** The driver speaks a protocol the server does not take (helloProblem), or its hello lacks a group its kind needs (kindServed): update it. */
64
75
  protocol: 4426,
65
76
  };
66
77
  const STOPS = new Set([ATTACH_CLOSE.mismatch, ATTACH_CLOSE.unauthorized, ATTACH_CLOSE.protocol]);
@@ -151,30 +162,50 @@ export class MemoryMachineTokens {
151
162
  export function mintedComputer(machine, { kind, os, arch }) {
152
163
  return { id: machine, name: machine, hello: { protocol: PROTOCOL_VERSION, version: "", os, kind, arch, groups: [] }, labels: {}, minted: true };
153
164
  }
154
- /** Whether protocol version a ("0.3") comes after b ("0.2"), part by part as numbers. */
155
- function laterProtocol(a, b) {
156
- const [x, y] = [a, b].map((version) => version.split(".").map((part) => Number.parseInt(part, 10) || 0));
157
- for (let i = 0; i < Math.max(x.length, y.length); i++)
158
- if ((x[i] ?? 0) !== (y[i] ?? 0))
159
- return (x[i] ?? 0) > (y[i] ?? 0);
160
- return false;
165
+ /**
166
+ * Whether a refused driver's protocol version comes after this server's, so the server is the side to update: a
167
+ * "<major>.<minor>" later part by part as numbers ("1.0" after "0.2"). A version of any other shape ("0.2.1",
168
+ * "0.3-beta") is no server's, so updating the server never helps, and the driver is the side to update. Serve's pairing
169
+ * reads it too.
170
+ */
171
+ export function laterProtocol(protocol) {
172
+ const theirs = /^(\d+)\.(\d+)$/.exec(protocol);
173
+ if (theirs === null)
174
+ return false;
175
+ const [major, minor] = PROTOCOL_VERSION.split(".").map(Number);
176
+ return Number(theirs[1]) !== major ? Number(theirs[1]) > major : Number(theirs[2]) > minor;
177
+ }
178
+ const SERVER_OLDER = "the server is older: it is updated by whoever runs it";
179
+ /** What a person does about a refused driver on `paired`. Serve names no OS and no driver app: one way to update, in
180
+ * the same words for every computer. A minted machine fetched this server's own computerd at boot, so another build
181
+ * there is not one this server gave it. */
182
+ function updateOf(paired) {
183
+ return 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)`;
184
+ }
185
+ /**
186
+ * The words of serve's 426 at the attach upgrade, when no subprotocol `asked` names a protocol this server takes
187
+ * (attachSubprotocolOf). They name the side to update as helloMismatch does: the server when one asked names a later
188
+ * protocol, else the driver. A driver stops dialing on this 426 as on a 4426 close, and a 0.1 driver, which offers only
189
+ * its own subprotocol, is refused here and never reaches hello.
190
+ */
191
+ export function upgradeRefusal(paired, asked) {
192
+ const newer = asked.some((one) => one.startsWith(SUBPROTOCOL_PREFIX) && laterProtocol(one.slice(SUBPROTOCOL_PREFIX.length)));
193
+ return `this server speaks ${ATTACH_SUBPROTOCOL}, and ${paired.name}'s driver asked for ${asked.join(", ") || "no subprotocol"}: ${newer ? SERVER_OLDER : updateOf(paired)}`;
161
194
  }
162
195
  /**
163
- * Why a hello may not stand for a paired computer, or undefined. The protocol version must be the server's; the
164
- * driver's own version may be any: a person's installed app updates on its own schedule, and the server cannot
196
+ * Why a hello may not stand for a paired computer, or undefined. The protocol version must work with the server's
197
+ * (helloProblem: 0.2 or a later 0.x); the driver's own version may be any: a person's installed app updates on its own schedule, and the server cannot
165
198
  * replace it the way a provider replaces a copied daemon.
166
199
  */
167
200
  export function helloMismatch(paired, hello) {
168
- // Serve names no OS and no driver app: one way to update, in the same words for every computer. A minted machine
169
- // fetched this server's own computerd at boot, so another build there is not one this server gave it.
170
- 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)`;
201
+ const update = updateOf(paired);
171
202
  const said = hello;
172
203
  if (typeof said !== "object" || said === null || typeof said.protocol !== "string" || typeof said.version !== "string") {
173
204
  return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver answered hello without its protocol and version: ${update}` };
174
205
  }
175
- if (hello.protocol !== PROTOCOL_VERSION) {
176
- const newer = laterProtocol(hello.protocol, PROTOCOL_VERSION) ? "the server is older: it is updated by whoever runs it" : update;
177
- return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver ${hello.version} speaks protocol ${hello.protocol}, and this server ${PROTOCOL_VERSION}: ${newer}` };
206
+ const problem = helloProblem(hello.protocol, "server");
207
+ if (problem) {
208
+ return { code: ATTACH_CLOSE.protocol, message: `${paired.name}'s driver ${hello.version} ${problem}: ${laterProtocol(hello.protocol) ? SERVER_OLDER : update}` };
178
209
  }
179
210
  // Every field serve reads off a live hello (the provider's capabilities, the kind check): one missing is refused
180
211
  // here, never met later as a throw.
package/dist/boxd.js CHANGED
@@ -1,4 +1,4 @@
1
- // The boxd host: boxd machines (KVM microVMs, Ubuntu 24.04) as a MachineHost, through the host's own @boxd-sh/sdk, of
1
+ // The boxd host: boxd machines (KVM microVMs, Ubuntu 24.04) as a MachineHost, through @boxd-sh/sdk (an optional dependency), of
2
2
  // which this file names only the slice it calls (every fact from 0.3.1's dist/*.d.ts) and imports nothing at load.
3
3
  // boxd's agent runs every command in a machine, so computerd is a child. The daemon, the bridge, the probe, idempotent
4
4
  // create, extend and delete-then-wait-gone are the shared adapter's (./hosted/provider.ts). A desktop starts from a
@@ -13,14 +13,13 @@ import { httpsBase } from "./hosted/rest.js";
13
13
  import { shellLine } from "./hosted/scripts.js";
14
14
  import { dateOf } from "./hosted/values.js";
15
15
  import { failFor, ok } from "./result.js";
16
- /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
17
- const BOXD_PACKAGE = "@boxd-sh/sdk";
16
+ import { vendorSdk } from "./vendor-sdk.js";
18
17
  /** A BoxdProvider from its options alone; throws in words when the key is missing, never echoing one. */
19
18
  export async function create(options) {
20
19
  const { apiKey, Boxd: given, ...rest } = options ?? {};
21
20
  if (typeof apiKey !== "string" || apiKey === "")
22
21
  throw new Error("options.apiKey, the boxd API key, is required: the provider reads no environment, so the caller passes it");
23
- const Boxd = given ?? (await import(BOXD_PACKAGE)).Boxd;
22
+ const Boxd = given ?? (await vendorSdk(BOXD.label, "@boxd-sh/sdk")).Boxd;
24
23
  return new BoxdProvider({ ...rest, apiKey, Boxd });
25
24
  }
26
25
  /** The conformance CLI's module for boxd. */
@@ -44,17 +43,31 @@ const STATES = {
44
43
  ...{ pending: "starting", starting: "starting", running: "running", suspended: "running", migrating: "running" },
45
44
  ...{ hibernated: "stopped", stopped: "stopped", failed: "gone", destroyed: "gone" },
46
45
  };
46
+ /** Mozilla's APT signing key (fingerprint 35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3), where the recipe keeps it, and its sha256. */
47
+ const MOZILLA_KEY = "/etc/apt/keyrings/packages.mozilla.org.asc";
48
+ const MOZILLA_KEY_SHA256 = "3ecc63922b7795eb23fdc449ff9396f9114cb3cf186d6f5b53ad4cc3ebfbb11f";
47
49
  /**
48
- * What a desktop needs that boxd's own image lacks: a stock app, Xfce's text editor (mousepad, from Ubuntu's universe),
49
- * its desktop file checked, run as root on a build machine of boxd's own image. Xvfb is the image's already. The
50
- * snapshot's name carries this line's hash, so a new line is a new snapshot.
50
+ * What a desktop needs that boxd's own image lacks (Xvfb, xdotool and Thunar are the image's already): Xfce's text
51
+ * editor and terminal (mousepad and xfce4-terminal, from Ubuntu's universe) and Firefox ESR, from Mozilla's APT
52
+ * repository, since Ubuntu 24.04's firefox is a snap and a microVM runs no snapd. Mozilla's key is held to its sha256
53
+ * before apt reads anything it signs. Each program and desktop file is checked. Run as root on a build machine of boxd's
54
+ * own image, with no single quote in it (it goes in one pair). The snapshot's name carries this recipe's hash, so a
55
+ * new recipe is a new snapshot.
51
56
  */
52
57
  const DESKTOP_RECIPE = [
53
58
  "set -e",
54
59
  "export DEBIAN_FRONTEND=noninteractive",
55
60
  "apt-get update -qq",
56
- "apt-get install -y -qq --no-install-recommends mousepad >/dev/null",
57
- 'test -f /usr/share/applications/org.xfce.mousepad.desktop || { echo "mousepad brought no org.xfce.mousepad.desktop" >&2; exit 1; }',
61
+ "apt-get install -y -qq --no-install-recommends ca-certificates curl >/dev/null",
62
+ "install -d -m 0755 /etc/apt/keyrings",
63
+ `curl -fsSL https://packages.mozilla.org/apt/repo-signing-key.gpg -o ${MOZILLA_KEY}`,
64
+ `echo "${MOZILLA_KEY_SHA256} ${MOZILLA_KEY}" | sha256sum -c --quiet - || { echo "the APT signing key from packages.mozilla.org is not the one this recipe pins" >&2; exit 1; }`,
65
+ `echo "deb [signed-by=${MOZILLA_KEY}] https://packages.mozilla.org/apt mozilla main" > /etc/apt/sources.list.d/mozilla.list`,
66
+ 'printf "Package: *\\nPin: origin packages.mozilla.org\\nPin-Priority: 1000\\n" > /etc/apt/preferences.d/mozilla',
67
+ "apt-get update -qq",
68
+ "apt-get install -y -qq --no-install-recommends mousepad xfce4-terminal firefox-esr >/dev/null",
69
+ 'for x in mousepad xfce4-terminal firefox-esr; do command -v "$x" >/dev/null || { echo "the desktop has no $x" >&2; exit 1; }; done',
70
+ 'for app in org.xfce.mousepad xfce4-terminal firefox-esr; do test -f "/usr/share/applications/$app.desktop" || { echo "the desktop has no desktop file $app.desktop" >&2; exit 1; }; done',
58
71
  "rm -rf /var/lib/apt/lists/*",
59
72
  ].join("\n");
60
73
  /** The desktop snapshot this package's recipe names: agentrun-desktop-<12 hex of the recipe's sha256>. */
@@ -82,8 +82,6 @@ export declare function browserbaseRest({ apiKey, apiUrl, projectId, fetch: fetc
82
82
  projectId?: string;
83
83
  fetch?: typeof fetch;
84
84
  }): BrowserbaseApi;
85
- /** How long after a saving session ends Browserbase may still be writing its context back. */
86
- export declare const BROWSERBASE_PROFILE_SETTLE_MS = 5000;
87
85
  /** The directory Browserbase syncs a session's downloads from: a driver sets the download behaviour into it. */
88
86
  export declare const BROWSERBASE_DOWNLOADS_PATH = "downloads";
89
87
  export interface BrowserbaseProviderOptions {
@@ -103,6 +101,12 @@ export interface BrowserbaseProviderOptions {
103
101
  confirm?: ReleaseConfirm;
104
102
  sleep?: (ms: number) => Promise<void>;
105
103
  }
104
+ /**
105
+ * A session's signed CDP URL as a driver dials it: on the gateway that fronts the sessions' sockets where a server is
106
+ * behind one (BROWSERBASE_CONNECT_BASE_URL), its path under the gateway's and the signing query kept; else as Browserbase
107
+ * gave it. Only a URL on Browserbase's own domain moves, and a gateway that is no URL moves none.
108
+ */
109
+ export declare function throughGateway(connectUrl: string, connectBase: string | undefined): string;
106
110
  /** Computers that are Browserbase sessions. */
107
111
  export declare class BrowserbaseProvider implements ComputerProvider, BrowserComputerProvider {
108
112
  #private;
@@ -144,10 +144,50 @@ export function browserbaseRest({ apiKey, apiUrl = BROWSERBASE_API_URL, projectI
144
144
  /** Rows per downloads page, and the most pages a list reads before it fails rather than run on. */
145
145
  const DOWNLOADS_PAGE = 100;
146
146
  const MAX_PAGES = 100;
147
- /** How long after a saving session ends Browserbase may still be writing its context back. */
148
- export const BROWSERBASE_PROFILE_SETTLE_MS = 5_000;
149
147
  /** The directory Browserbase syncs a session's downloads from: a driver sets the download behaviour into it. */
150
148
  export const BROWSERBASE_DOWNLOADS_PATH = "downloads";
149
+ /**
150
+ * A session's signed CDP URL as a driver dials it: on the gateway that fronts the sessions' sockets where a server is
151
+ * behind one (BROWSERBASE_CONNECT_BASE_URL), its path under the gateway's and the signing query kept; else as Browserbase
152
+ * gave it. Only a URL on Browserbase's own domain moves, and a gateway that is no URL moves none.
153
+ */
154
+ export function throughGateway(connectUrl, connectBase) {
155
+ if (!connectBase)
156
+ return connectUrl;
157
+ try {
158
+ const target = new URL(connectBase);
159
+ const url = new URL(connectUrl);
160
+ const host = url.hostname.toLowerCase();
161
+ if (host !== CDP_DOMAIN && !host.endsWith(`.${CDP_DOMAIN}`))
162
+ return connectUrl;
163
+ url.protocol = target.protocol;
164
+ url.host = target.host;
165
+ url.pathname = target.pathname.replace(/\/$/, "") + url.pathname;
166
+ return url.toString();
167
+ }
168
+ catch {
169
+ return connectUrl;
170
+ }
171
+ }
172
+ /**
173
+ * The gateway that fronts the sessions' sockets (BROWSERBASE_CONNECT_BASE_URL), held to wss: or https: as httpsBase holds
174
+ * an API URL, since every session's signed CDP URL rides it; throws in words on another, loopback included. One that is
175
+ * no URL is not echoed: it may carry the gateway's own token.
176
+ */
177
+ function connectBaseOf(url) {
178
+ if (url === undefined)
179
+ return undefined;
180
+ let parsed;
181
+ try {
182
+ parsed = new URL(url);
183
+ }
184
+ catch {
185
+ throw new Error("BROWSERBASE_CONNECT_BASE_URL is not a URL");
186
+ }
187
+ if (parsed.protocol !== "wss:" && parsed.protocol !== "https:")
188
+ throw new Error(`BROWSERBASE_CONNECT_BASE_URL must be wss or https, so a session's signed URL never crosses in the clear: ${parsed.protocol}`);
189
+ return url;
190
+ }
151
191
  const refOf = (s) => ({ id: s.id, name: s.id });
152
192
  const deadlineOf = (s) => {
153
193
  const at = typeof s.expiresAt === "string" ? new Date(s.expiresAt) : undefined;
@@ -159,14 +199,16 @@ export class BrowserbaseProvider {
159
199
  version = VERSION;
160
200
  /**
161
201
  * A session ends at its timeout, a wall clock; it may be stealth (Verified, with the CAPTCHA solver); it opens a
162
- * context as a profile (written back about 5 s after a saving session ends) and keeps what is saved into downloads/.
163
- * capabilities().browser gives it.
202
+ * context as a profile (written back within its descriptor's settle window after a saving session ends) and keeps
203
+ * what is saved into downloads/. capabilities().browser gives it.
164
204
  */
165
205
  #browser;
166
206
  profiles;
167
207
  downloads;
168
208
  #api;
169
209
  #projectId;
210
+ /** The gateway that fronts the sessions' sockets (BROWSERBASE_CONNECT_BASE_URL), where a server is behind one. */
211
+ #connectBase;
170
212
  #urls;
171
213
  #confirm;
172
214
  #sleep;
@@ -174,7 +216,8 @@ export class BrowserbaseProvider {
174
216
  if (typeof apiKey !== "string" || apiKey === "")
175
217
  throw new Error("set options.apiKey to a Browserbase API key: the provider reads no environment");
176
218
  const gateway = env.BROWSERBASE_BASE_URL?.trim() || undefined;
177
- const behindGateway = Boolean(gateway || env.BROWSERBASE_CONNECT_BASE_URL?.trim());
219
+ this.#connectBase = connectBaseOf(env.BROWSERBASE_CONNECT_BASE_URL?.trim() || undefined);
220
+ const behindGateway = Boolean(gateway || this.#connectBase);
178
221
  this.#projectId = behindGateway ? undefined : projectId || undefined;
179
222
  const base = apiUrl || gateway;
180
223
  this.#api = browserbaseRest({ apiKey, ...(base ? { apiUrl: base } : {}), ...(this.#projectId ? { projectId: this.#projectId } : {}), ...(fetcher ? { fetch: fetcher } : {}) });
@@ -184,7 +227,7 @@ export class BrowserbaseProvider {
184
227
  this.#browser = {
185
228
  timeout: "wall-clock",
186
229
  stealth: true,
187
- profiles: { settleMs: BROWSERBASE_PROFILE_SETTLE_MS },
230
+ profiles: { settleMs: BROWSERBASE.profiles.settleMs },
188
231
  downloads: { path: BROWSERBASE_DOWNLOADS_PATH },
189
232
  };
190
233
  this.profiles = { create: (context) => this.#createProfile(context), remove: (pointer, context) => this.#removeProfile(pointer, context) };
@@ -515,7 +558,7 @@ export class BrowserbaseProvider {
515
558
  this.#urls.set(id, url);
516
559
  const hello = browserHello(VERSION, this.capabilities().groups);
517
560
  const client = browserClient(hello, (signal) => this.#alive(id, signal));
518
- return ok({ client, hello, cdp: { url }, close: async () => client.close() });
561
+ return ok({ client, hello, cdp: { url: throughGateway(url, this.#connectBase) }, close: async () => client.close() });
519
562
  }
520
563
  /** Asks Browserbase to release the session and waits until it reads as ended; one already ended or unknown is released. */
521
564
  async release(ref, how, { signal } = {}) {
@@ -0,0 +1,11 @@
1
+ export { ADB_ENV_NAMES, BASE_ENV_NAMES, CHROME_ENV_NAMES, DOCKER_ENV_NAMES } from "./descriptors/env-names.js";
2
+ /** The environment variables a host passes, by name; a name with no value is unset. */
3
+ export type HostEnv = Readonly<Record<string, string | undefined>>;
4
+ /** `env`'s values of `names` that are set, and nothing else: a child's whole environment. */
5
+ export declare function childEnv(env: HostEnv, names: readonly string[]): Record<string, string>;
6
+ /** A docker CLI child's environment: DOCKER_ENV_NAMES of `env`. */
7
+ export declare const dockerEnv: (env?: HostEnv) => Record<string, string>;
8
+ /** A Chrome child's (and the local browser's supervisor's) environment: CHROME_ENV_NAMES of `env`. */
9
+ export declare const chromeEnv: (env?: HostEnv) => Record<string, string>;
10
+ /** An adb child's (and the adb server's it starts) environment: ADB_ENV_NAMES of `env`. */
11
+ export declare const adbEnv: (env?: HostEnv) => Record<string, string>;
@@ -0,0 +1,22 @@
1
+ // The environment a child this package starts holds: the names that child reads, of the environment its host passes
2
+ // (the provider's `env` option), and nothing else, so a key the host holds never reaches a child that has no use for it.
3
+ // The package itself reads no environment: with no `env`, a child starts with none. The lists of names are
4
+ // descriptors/env-names.ts', where the descriptors' hostEnv reads them too.
5
+ import { ADB_ENV_NAMES, CHROME_ENV_NAMES, DOCKER_ENV_NAMES } from "./descriptors/env-names.js";
6
+ export { ADB_ENV_NAMES, BASE_ENV_NAMES, CHROME_ENV_NAMES, DOCKER_ENV_NAMES } from "./descriptors/env-names.js";
7
+ /** `env`'s values of `names` that are set, and nothing else: a child's whole environment. */
8
+ export function childEnv(env, names) {
9
+ const out = {};
10
+ for (const name of names) {
11
+ const value = env[name];
12
+ if (typeof value === "string")
13
+ out[name] = value;
14
+ }
15
+ return out;
16
+ }
17
+ /** A docker CLI child's environment: DOCKER_ENV_NAMES of `env`. */
18
+ export const dockerEnv = (env = {}) => childEnv(env, DOCKER_ENV_NAMES);
19
+ /** A Chrome child's (and the local browser's supervisor's) environment: CHROME_ENV_NAMES of `env`. */
20
+ export const chromeEnv = (env = {}) => childEnv(env, CHROME_ENV_NAMES);
21
+ /** An adb child's (and the adb server's it starts) environment: ADB_ENV_NAMES of `env`. */
22
+ export const adbEnv = (env = {}) => childEnv(env, ADB_ENV_NAMES);
package/dist/chrome.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type HostEnv } from "./child-env.js";
1
2
  import { type Result } from "./result.js";
2
3
  /** The environment names a Chrome is found by: PI_BROWSER_CHROME, then the common CHROME_PATH. */
3
4
  export declare const CHROME_ENV: readonly ["PI_BROWSER_CHROME", "CHROME_PATH"];
@@ -64,9 +65,11 @@ export declare const CHECK_MS = 30000;
64
65
  * Whether the Chrome at `path` starts here with its sandbox on: an executable file, a user that is not root, and one
65
66
  * headless start on a blank page (`--dump-dom about:blank`) in a profile of its own that goes with it, with a proxy no
66
67
  * name or address reaches, so nothing leaves the machine. ok with the resolved path; refused in words that never offer
67
- * to turn the sandbox off. From #1718's checkChrome. `uid`: the user this process runs as (a test's seam).
68
+ * to turn the sandbox off. From #1718's checkChrome. `uid`: the user this process runs as (a test's seam). `env`: the
69
+ * host's environment, of which Chrome holds the names it reads (CHROME_ENV_NAMES) and nothing else; without it, none.
68
70
  */
69
- export declare function checkChrome(path: string, { uid, timeoutMs }?: {
71
+ export declare function checkChrome(path: string, { uid, timeoutMs, env }?: {
70
72
  uid?: number;
71
73
  timeoutMs?: number;
74
+ env?: HostEnv;
72
75
  }): Promise<Result<string>>;
package/dist/chrome.js CHANGED
@@ -7,6 +7,7 @@ import { constants, existsSync, readFileSync } from "node:fs";
7
7
  import { access, mkdtemp, readFile, readlink, rm, stat } from "node:fs/promises";
8
8
  import { tmpdir } from "node:os";
9
9
  import { basename, delimiter, dirname, join, resolve } from "node:path";
10
+ import { chromeEnv } from "./child-env.js";
10
11
  import { fail, ok } from "./result.js";
11
12
  /** The names a Chrome or Chromium goes by on a Linux PATH. */
12
13
  const LINUX_NAMES = ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"];
@@ -178,9 +179,10 @@ export const CHECK_MS = 30_000;
178
179
  * Whether the Chrome at `path` starts here with its sandbox on: an executable file, a user that is not root, and one
179
180
  * headless start on a blank page (`--dump-dom about:blank`) in a profile of its own that goes with it, with a proxy no
180
181
  * name or address reaches, so nothing leaves the machine. ok with the resolved path; refused in words that never offer
181
- * to turn the sandbox off. From #1718's checkChrome. `uid`: the user this process runs as (a test's seam).
182
+ * to turn the sandbox off. From #1718's checkChrome. `uid`: the user this process runs as (a test's seam). `env`: the
183
+ * host's environment, of which Chrome holds the names it reads (CHROME_ENV_NAMES) and nothing else; without it, none.
182
184
  */
183
- export async function checkChrome(path, { uid = process.getuid?.(), timeoutMs = CHECK_MS } = {}) {
185
+ export async function checkChrome(path, { uid = process.getuid?.(), timeoutMs = CHECK_MS, env } = {}) {
184
186
  const at = resolve(path);
185
187
  const runs = (await stat(at).then((info) => info.isFile(), () => false)) && (await access(at, constants.X_OK).then(() => true, () => false));
186
188
  if (!runs)
@@ -194,6 +196,7 @@ export async function checkChrome(path, { uid = process.getuid?.(), timeoutMs =
194
196
  const said = await new Promise((done) => {
195
197
  const child = spawn(at, ["--headless=new", `--user-data-dir=${profile}`, "--no-first-run", "--proxy-server=http://agentrun-check.invalid:9", "--host-resolver-rules=MAP * ~NOTFOUND", "--dump-dom", "about:blank"], {
196
198
  stdio: ["ignore", "ignore", "pipe"],
199
+ env: chromeEnv(env),
197
200
  timeout: timeoutMs,
198
201
  killSignal: "SIGKILL",
199
202
  });
@@ -9,6 +9,8 @@ export interface CloudflareProviderOptions extends Omit<HostedOptions, "desktop"
9
9
  relayToken: string;
10
10
  /** The fetch every call goes through; default the global one. */
11
11
  fetch?: typeof fetch;
12
+ /** For tests: the pause before a request is tried again, given its ms and the call's signal. Default a timer. */
13
+ pause?: (ms: number, signal?: AbortSignal) => Promise<void>;
12
14
  /** The longest lifetime check takes, in ms: at most 24 h, the janitor's cap, which is the default. */
13
15
  maxLifetimeMs?: number;
14
16
  timeouts?: Partial<HostedTimeouts>;