@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.32

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 (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2401 -2
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +92 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +118 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +125 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +190 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +178 -0
  106. package/dist/daytona.js +1484 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +150 -0
  124. package/dist/docker.js +1200 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +335 -0
  128. package/dist/e2b.js +1515 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +62 -4
package/box/Dockerfile ADDED
@@ -0,0 +1,69 @@
1
+ # The image a remote computer with an Archil mount starts from: a Daytona snapshot (build-daytona.py), a Modal image
2
+ # (build-modal.py), or an E2B template, named by the computer spec's image. It is a small Debian with a coding agent's
3
+ # tools, plus what keeps the run's work folder on the owner's Archil disk:
4
+ #
5
+ # - the archil client at /usr/bin/archil, 0.10.1 (the version the live checks ran), checked by sha256;
6
+ # - the root helper, this folder's agentrun-archil, at /usr/local/sbin/agentrun-archil, root:root 0755;
7
+ # - the tool user agentrun-tool, uid and gid 2510, which computerd runs every tool as;
8
+ # - FUSE (fuse3, and the client's own FUSE library). No firewall: init and every tool run in a network namespace of
9
+ # their own with loopback alone (computerd init --own-network), while the archil client and serve, as root, stay in
10
+ # the computer's, which reaches Archil;
11
+ # - /workspace, empty and root's, where the helper mounts the run's folder.
12
+ #
13
+ # No sudo and no sudoers file: the image's user is root, so the provider's own exec (Daytona's toolbox, Modal's exec,
14
+ # E2B's commands as root) runs the helper as root, and the tool user has no way to root. The build fails if the base
15
+ # brings either. computerd is not part of the image: the provider uploads and installs it, root's alone, at create, and
16
+ # the helper's serve runs that one.
17
+ #
18
+ # /proc with hidepid=2 is not part of an image: the helper remounts /proc so before each mount, as root, and refuses the
19
+ # mount in a computer where that fails.
20
+ #
21
+ # An archil package whose sha256 reads `unpinned` stops the build, saying so: pin both sums before any build.
22
+ FROM python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30
23
+
24
+ ARG ARCHIL_VERSION=0.10.1-1793222256
25
+ ARG ARCHIL_SHA256_AMD64=f219e70287e8152f3f0c7222e1c3319f4665897235af7c33a8846e56a5a5786a
26
+ ARG ARCHIL_SHA256_ARM64=10ed430e51c268af095dd9e6c7aa6cdbb951d2430d62a76458719db168f40c0e
27
+
28
+ RUN set -eu; \
29
+ arch="$(dpkg --print-architecture)"; \
30
+ case "$arch" in \
31
+ amd64) sum="$ARCHIL_SHA256_AMD64" ;; \
32
+ arm64) sum="$ARCHIL_SHA256_ARM64" ;; \
33
+ *) echo "no archil client for $arch" >&2; exit 1 ;; \
34
+ esac; \
35
+ case "$sum" in unpinned) echo "archil ${ARCHIL_VERSION} for $arch has no pinned sha256 yet: set ARCHIL_SHA256_$(echo "$arch" | tr a-z A-Z) to the package's sum" >&2; exit 1 ;; esac; \
36
+ apt-get update -qq; \
37
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
38
+ git curl ca-certificates nodejs npm ripgrep fuse3 >/dev/null; \
39
+ curl -fsSL -o /tmp/archil.deb "https://s3.amazonaws.com/archil-client/pkg/archil_${ARCHIL_VERSION}_${arch}.deb"; \
40
+ echo "$sum /tmp/archil.deb" | sha256sum -c -; \
41
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends /tmp/archil.deb >/dev/null; \
42
+ rm -rf /var/lib/apt/lists/* /tmp/archil.deb; \
43
+ groupadd --gid 2510 agentrun-tool; \
44
+ useradd --uid 2510 --gid 2510 --no-create-home --home-dir /tmp --shell /bin/sh agentrun-tool; \
45
+ install -d -o root -g root -m 0755 /workspace
46
+
47
+ COPY agentrun-archil /usr/local/sbin/agentrun-archil
48
+
49
+ # What the helper runs, where it runs it from: an image that lacks one fails here, not at a run's first mount. And no
50
+ # way to root for the tool user: no sudo, no sudoers. A provider's builder may add sudo to the base before these steps
51
+ # (E2B's does): it is taken away first, the package where it is installed and every sudoers file, then checked gone.
52
+ RUN set -eu; \
53
+ 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; \
54
+ rm -rf /etc/sudoers /etc/sudoers.d; \
55
+ chown root:root /usr/local/sbin/agentrun-archil; \
56
+ chmod 0755 /usr/local/sbin/agentrun-archil; \
57
+ 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 \
58
+ [ -x "$x" ] || { echo "the image has no $x" >&2; exit 1; }; \
59
+ done; \
60
+ ! command -v sudo >/dev/null 2>&1 || { echo "the image has sudo" >&2; exit 1; }; \
61
+ [ ! -e /etc/sudoers ] && [ ! -e /etc/sudoers.d ] || { echo "the image has a sudoers file" >&2; exit 1; }; \
62
+ ids="$(id -u agentrun-tool):$(id -g agentrun-tool)"; \
63
+ [ "$ids" = "2510:2510" ] || { echo "agentrun-tool is $ids" >&2; exit 1; }; \
64
+ archil --version | head -1
65
+
66
+ USER root
67
+ # A computer's first process is its provider's own (Daytona's runs this when a snapshot names no entrypoint; Modal's and
68
+ # E2B's are their own): never the base image's python.
69
+ CMD ["sleep", "infinity"]
@@ -0,0 +1,168 @@
1
+ #!/bin/sh
2
+ # agentrun-archil: the root helper of a remote computer, which keeps one run's work folder on the owner's Archil disk
3
+ # at /workspace. It does four things and nothing else, each with fixed arguments to the archil client, to find and chown,
4
+ # or to computerd:
5
+ #
6
+ # mount <disk> <region> agents/<agent>/runs/<run>/work the disk token as one line on fd 0
7
+ # revoke <disk> <region> agents/<agent>/runs/<run>/work the disk token as one line on fd 0
8
+ # serve
9
+ # checkin
10
+ #
11
+ # mount archil mount <disk>:/<path> /workspace --region <region>: exclusive, so no other client writes the folder;
12
+ # then every path of the mounted tree that is not agentrun-tool's is given to it (the links themselves, never
13
+ # followed, and never past the mount): the disk's object API makes files root's, 644, and while a computer holds
14
+ # the folder no outside write lands (Archil refuses it), so what the object API made is all there at the mount.
15
+ # revoke the same with --force: takes the folder back from a computer that is gone and left its delegation behind.
16
+ # serve becomes `computerd sync-serve`, resident, holding no token: on its socket it takes one fixed byte and answers
17
+ # the exit code of `archil sync /workspace` (every write so far durable), coalesced; it exits when the mount
18
+ # goes or its socket is taken away.
19
+ # checkin takes serve's socket away, then archil checkin /workspace: lets go of the folder.
20
+ #
21
+ # The archil client and serve run as root in the computer's own network namespace, which reaches Archil; init and every
22
+ # tool run in a namespace of their own with loopback alone (computerd init --own-network), so the tools have no network
23
+ # and reach no daemon of the provider's. This helper sets no firewall.
24
+ #
25
+ # Install it root:root 0755 at /usr/local/sbin/agentrun-archil. The provider runs it as root through its own exec (the
26
+ # image's user is root), never through sudo: the image has none. The run's tools run as agentrun-tool, through
27
+ # computerd, with no way to root at all.
28
+ #
29
+ # The token is read from fd 0 and handed to archil only in the environment of its exec (archil reads it nowhere else),
30
+ # never as an argument and never in a file. Every argument is checked here, whoever calls: a caller that is not root, a
31
+ # wrong verb or count, a newline, a disk, region or folder of any other shape (an absolute path, `.` or `..`, an empty
32
+ # or extra segment), a mountpoint that is a link or not empty, or a token of any other shape exits 2 and runs nothing.
33
+ # A serve or checkin with nothing mounted exits 3 and runs nothing. A mount or revoke in a computer whose /proc lets a
34
+ # user see another's processes (no hidepid=2 or invisible) exits 4 and runs nothing; each first remounts /proc with
35
+ # hidepid=2, which a computer whose root may not remount leaves as it was. A mount the client refuses answers the
36
+ # client's exit code; a mount whose tree cannot then be given to agentrun-tool exits 4. A serve whose computerd is not
37
+ # root's alone exits 4.
38
+ set -eu
39
+ umask 077
40
+ PATH=/usr/sbin:/usr/bin:/sbin:/bin
41
+ export PATH
42
+ # Space, tab and newline, as a shell starts: written so no line ends in white space.
43
+ IFS=$(printf ' \t\nx')
44
+ IFS=${IFS%x}
45
+ unset ENV CDPATH
46
+
47
+ ARCHIL=/usr/bin/archil
48
+ MP=/workspace
49
+ MOUNTS=/proc/self/mounts
50
+ MOUNT=/usr/bin/mount
51
+ CHOWN=/usr/bin/chown
52
+ FIND=/usr/bin/find
53
+ TOOL=agentrun-tool
54
+ TOOL_UID=2510
55
+ COMPUTERD=/opt/agentrun/computerd
56
+ SOCK=/run/agentrun-archil/archil.sock
57
+ ROOT_UID=0
58
+ HELD_TOP=/
59
+
60
+ refuse() {
61
+ printf 'agentrun-archil: %s\n' "$1" >&2
62
+ exit 2
63
+ }
64
+
65
+ [ "$(id -u)" = "$ROOT_UID" ] || refuse "run it as root, through the provider's own exec"
66
+
67
+ # A newline in any argument is refused before anything reads one: the checks below are line by line.
68
+ nl='
69
+ '
70
+ for arg in "$@"; do
71
+ case "$arg" in *"$nl"*) refuse "an argument holds a newline" ;; esac
72
+ done
73
+
74
+ matches() { printf '%s\n' "$1" | grep -Eqx -- "$2"; }
75
+
76
+ # Whether $MP is in the mount table, as an archil mount (fuse.archil) or as anything (any).
77
+ listed() { awk -v m="$MP" -v t="$1" '$2 == m && (t == "any" || $3 == t) { f = 1 } END { exit !f }' "$MOUNTS"; }
78
+
79
+ take() {
80
+ [ "$#" -eq 3 ] || refuse "$verb takes <disk> <region> agents/<agent>/runs/<run>/work"
81
+ disk=$1 region=$2 folder=$3
82
+ matches "$disk" 'dsk-[0-9a-f]{16}|[A-Za-z0-9][A-Za-z0-9._@+-]{0,127}/[A-Za-z0-9][A-Za-z0-9._-]{0,127}' || refuse "the disk is a disk id (dsk-...) or owner/name"
83
+ matches "$region" '[a-z0-9]+-[a-z0-9][a-z0-9-]{0,62}' || refuse "the region is a provider, a dash and its region, lowercase letters, digits and dashes"
84
+ matches "$folder" 'agents/[A-Za-z0-9][A-Za-z0-9_-]{0,127}/runs/[A-Za-z0-9][A-Za-z0-9_-]{0,127}/work' || refuse "the folder is agents/<agent>/runs/<run>/work, nothing else"
85
+ # The computer's /proc (its last mount there) must hide each user's processes from the others, hidepid=2 or invisible
86
+ # as newer kernels name it: else the run's tools could see this root archil client's. No image sets it, so it is
87
+ # remounted so first, as root may where it holds CAP_SYS_ADMIN; a computer where that fails is refused by the check.
88
+ "$MOUNT" -o remount,hidepid=2 /proc >/dev/null 2>&1 || :
89
+ if ! awk '$2 == "/proc" && $3 == "proc" { o = $4 } END { exit !(o ~ /(^|,)hidepid=(2|invisible)(,|$)/) }' "$MOUNTS"; then
90
+ printf 'agentrun-archil: /proc is not mounted with hidepid=2 (or invisible): the run'"'"'s tools could see the root archil client'"'"'s processes\n' >&2
91
+ exit 4
92
+ fi
93
+ if listed fuse.archil; then
94
+ # This folder, mounted here already (a computer found again): nothing to do. Any other is refused.
95
+ awk -v m="$MP" -v a="$disk:/$folder" -v b="$disk:/$folder[$region]" '$2 == m && $3 == "fuse.archil" && ($1 == a || $1 == b) { f = 1 } END { exit !f }' "$MOUNTS" || refuse "$MP holds another archil mount"
96
+ printf 'agentrun-archil: %s is mounted already\n' "$MP" >&2
97
+ exit 0
98
+ fi
99
+ listed any && refuse "$MP is another mount"
100
+ [ ! -L "$MP" ] && [ -d "$MP" ] || refuse "$MP is not a real directory"
101
+ [ "$(realpath -e "$MP")" = "$MP" ] || refuse "$MP is not its own real path"
102
+ [ -z "$(ls -A "$MP")" ] || refuse "$MP is not empty"
103
+ token=
104
+ IFS= read -r token || [ -n "$token" ] || refuse "no token on fd 0"
105
+ [ "${#token}" -ge 16 ] && [ "${#token}" -le 4096 ] || refuse "the token is not a disk token"
106
+ case "$token" in *[!A-Za-z0-9._~+/=-]*) refuse "the token is not a disk token" ;; esac
107
+ # In the environment of archil's command alone (an assignment before the command, never exported to this shell's own,
108
+ # which was fixed at its start), and archil runs as root, so no other user reads it there.
109
+ rc=0
110
+ ARCHIL_MOUNT_TOKEN=$token "$ARCHIL" mount $force "$disk:/$folder" "$MP" --region "$region" || rc=$?
111
+ token=
112
+ [ "$rc" -eq 0 ] || exit "$rc"
113
+ # The whole tree is the tool user's: the tools write the run's folder, and the disk's object API made what is in it
114
+ # root's (644, 755). Only what is not the tool user's already; links themselves (-h), never followed; never past the
115
+ # mount (-xdev). Nothing outside lands while this computer holds the folder, so this once is enough.
116
+ "$FIND" "$MP" -xdev ! -uid "$TOOL_UID" -exec "$CHOWN" -h "$TOOL:$TOOL" {} + || {
117
+ printf 'agentrun-archil: %s is mounted, but this computer cannot give its tree to %s, so the tools could not write it\n' "$MP" "$TOOL" >&2
118
+ exit 4
119
+ }
120
+ }
121
+
122
+ # serve and checkin act on the archil mount at $MP; with none there (a computer whose mount went), nothing is held, and
123
+ # they say so with exit 3.
124
+ held() {
125
+ [ "$#" -eq 0 ] || refuse "$verb takes no argument"
126
+ if ! listed fuse.archil; then
127
+ printf 'agentrun-archil: nothing is mounted at %s\n' "$MP" >&2
128
+ exit 3
129
+ fi
130
+ }
131
+
132
+ # Whether $COMPUTERD is root's alone: a regular file, it and every folder above it (to $HELD_TOP) owned by root and
133
+ # writable by no group or other user, so no link and no ACL. Else a user who could rename an entry on the path could
134
+ # put another program there, which serve would run as root. `ls -ldn` is in BusyBox and coreutils alike; a trailing `.`
135
+ # (an SELinux label) is allowed, a `+` (an ACL) is not.
136
+ rootsalone() {
137
+ [ -f "$COMPUTERD" ] && [ ! -L "$COMPUTERD" ] || return 1
138
+ x=$COMPUTERD
139
+ while :; do
140
+ set -- $(ls -ldn "$x" 2>/dev/null)
141
+ case "${1-}" in ?????[!w]??[!w]? | ?????[!w]??[!w]?.) ;; *) return 1 ;; esac
142
+ [ "${3-}" = "$ROOT_UID" ] || return 1
143
+ [ "$x" = "$HELD_TOP" ] || [ "$x" = / ] && return 0
144
+ x=${x%/*}
145
+ x=${x:-/}
146
+ done
147
+ }
148
+
149
+ # serve: computerd's resident sync server, as root, with fixed arguments alone: the socket, the mountpoint, the mount
150
+ # table, the archil client and the tool user's group, which may connect. No token: its stdin is not passed on.
151
+ serve() {
152
+ held "$@"
153
+ rootsalone || { printf 'agentrun-archil: computerd at %s is not root'"'"'s alone, so serve runs nothing\n' "$COMPUTERD" >&2; exit 4; }
154
+ gid=$(id -g "$TOOL" 2>/dev/null) || { printf 'agentrun-archil: there is no user %s\n' "$TOOL" >&2; exit 4; }
155
+ exec "$COMPUTERD" sync-serve --socket "$SOCK" --mountpoint "$MP" --mounts "$MOUNTS" --archil "$ARCHIL" --gid "$gid" </dev/null
156
+ }
157
+
158
+ [ "$#" -ge 1 ] || refuse "say mount, revoke, serve or checkin"
159
+ verb=$1
160
+ shift
161
+ case "$verb" in
162
+ mount) force= && take "$@" ;;
163
+ revoke) force=--force && take "$@" ;;
164
+ serve) serve "$@" ;;
165
+ # serve's socket goes first, so serve exits and no sync is asked of a folder let go.
166
+ checkin) held "$@" && rm -f -- "$SOCK" && exec "$ARCHIL" checkin "$MP" ;;
167
+ *) refuse "say mount, revoke, serve or checkin" ;;
168
+ esac
@@ -0,0 +1,26 @@
1
+ # Build the Archil image (this folder's Dockerfile) as a Daytona snapshot, with Daytona's Python SDK (`pip install
2
+ # daytona`) and its key in DAYTONA_API_KEY, and print the snapshot's name: a Daytona computer with an Archil mount names
3
+ # it as its spec's image. The name is the recipe's hash (the Dockerfile and the files it copies), so a changed recipe is
4
+ # a new snapshot, and the same recipe is the one built before: Daytona then refuses the name, and the printed name is
5
+ # the one to use. Its size is 2 CPUs, 4 GB of memory and a 10 GB disk.
6
+ #
7
+ # python3 packages/computer/box/build-daytona.py
8
+ import hashlib
9
+ import os
10
+ import sys
11
+
12
+ from daytona import CreateSnapshotParams, Daytona, Image, Resources
13
+
14
+ here = os.path.dirname(os.path.abspath(__file__))
15
+ recipe = b"".join(open(os.path.join(here, name), "rb").read() for name in ("Dockerfile", "agentrun-archil"))
16
+ name = "agentrun-archil-" + hashlib.sha256(recipe).hexdigest()[:12]
17
+ print(f"build-daytona: snapshot {name}", file=sys.stderr)
18
+ Daytona().snapshot.create(
19
+ CreateSnapshotParams(
20
+ name=name,
21
+ image=Image.from_dockerfile(os.path.join(here, "Dockerfile")),
22
+ resources=Resources(cpu=2, memory=4, disk=10),
23
+ ),
24
+ on_logs=lambda line: print(line, file=sys.stderr),
25
+ )
26
+ print(f"snapshot={name}")
@@ -0,0 +1,32 @@
1
+ // Build the Archil image (this folder's Dockerfile) as an E2B template, with the host's own e2b SDK (in this repository,
2
+ // the root devDependency the lock pins) and its key in E2B_API_KEY, and print the template's name: an E2B computer with
3
+ // an Archil mount names it as its spec's image. The name is the recipe's hash (the Dockerfile and the files it copies),
4
+ // so a changed recipe is a new template, and the same recipe is the one built before (E2B's cache). Its size is 2 CPUs
5
+ // and 4 GB of memory.
6
+ //
7
+ // E2B_API_KEY=... node packages/computer/box/build-e2b.mjs
8
+ import { createHash } from "node:crypto";
9
+ import { readFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ /** The host's own SDK, as the E2B provider takes it: by a name that is not a literal, never this package's dependency. */
14
+ const E2B_PACKAGE = "e2b";
15
+ const { Template } = await import(E2B_PACKAGE).catch(() => {
16
+ console.error(`build-e2b: the ${E2B_PACKAGE} package is not installed: run npm ci at the repository root (it is a root devDependency there), or install ${E2B_PACKAGE} beside this script`);
17
+ process.exit(2);
18
+ });
19
+
20
+ const here = dirname(fileURLToPath(import.meta.url));
21
+ /** Every file the image is made of: the Dockerfile and what it copies. */
22
+ const RECIPE = ["Dockerfile", "agentrun-archil"];
23
+ const recipe = Buffer.concat(RECIPE.map((name) => readFileSync(join(here, name))));
24
+ const name = "agentrun-archil-" + createHash("sha256").update(recipe).digest("hex").slice(0, 12);
25
+ console.error(`build-e2b: template ${name}`);
26
+ const template = Template({ fileContextPath: here }).fromDockerfile(join(here, "Dockerfile"));
27
+ await Template.build(template, name, {
28
+ cpuCount: 2,
29
+ memoryMB: 4096,
30
+ onBuildLogs: (entry) => console.error(String(entry?.message ?? entry)),
31
+ });
32
+ console.log(`template=${name}`);
@@ -0,0 +1,17 @@
1
+ # Build the Archil image (this folder's Dockerfile) on Modal, with Modal's Python client (`pip install 'modal>=1.2'`)
2
+ # and its token (MODAL_TOKEN_ID and MODAL_TOKEN_SECRET, or `modal token set`), in the app named as the first argument
3
+ # (default agentrun-computer), and print the image's id, `im-...`: a Modal computer with an Archil mount names it as its
4
+ # spec's image. The same recipe is Modal's cached build, the same id.
5
+ #
6
+ # python3 packages/computer/box/build-modal.py [app]
7
+ import os
8
+ import sys
9
+
10
+ import modal
11
+
12
+ here = os.path.dirname(os.path.abspath(__file__))
13
+ app = modal.App.lookup(sys.argv[1] if len(sys.argv) > 1 else "agentrun-computer", create_if_missing=True)
14
+ image = modal.Image.from_dockerfile(os.path.join(here, "Dockerfile"), context_dir=here)
15
+ image.build(app)
16
+ print(f"build-modal: image {image.object_id}", file=sys.stderr)
17
+ print(f"image={image.object_id}")
@@ -0,0 +1,18 @@
1
+ import { type Group, type InputActionsResult } from "./protocol.js";
2
+ export type ActionFailure = NonNullable<InputActionsResult["failed"]>;
3
+ export interface CheckActionsOptions {
4
+ /** Whether the implementer can scroll by pixels; X11's core wheel events are clicks. Default true. */
5
+ pixelScroll?: boolean;
6
+ }
7
+ /** The most characters one type action takes: computerd's MaxTypeRunes (daemon/internal/desktop/check.go). */
8
+ export declare const MAX_TYPE_CHARACTERS: number;
9
+ /** Whether key is a name in KEYS or one printable ASCII character (0x21-0x7e). */
10
+ export declare function isKey(key: unknown): boolean;
11
+ /**
12
+ * The first reason the whole batch must not run, with its index, or undefined when it may. Nothing runs on a failure:
13
+ * the reply is { done: 0, failed }. The batch's shape and length come first, then each action in order: its shape
14
+ * (`invalid`), its keys (`invalid`), its group against groups (`unsupported`), a pixel scroll where there is none
15
+ * (`unsupported`), a key's repeat over MAX_KEY_REPEAT (`limit`), a type's text over MAX_TYPE_CHARACTERS (`limit`), and
16
+ * the summed durations (`limit`).
17
+ */
18
+ export declare function checkActions(actions: unknown, groups: readonly Group[], { pixelScroll }?: CheckActionsOptions): ActionFailure | undefined;
@@ -0,0 +1,139 @@
1
+ // The batch check of input.actions: the shape, the length, every key against KEYS, each action's group against what is
2
+ // declared, and the summed wait and hold. The implementer runs it before any action; a caller can run it early; the
3
+ // in-process clients of daemon none use it as their check.
4
+ import { KEYS, MAX_ACTIONS, MAX_BATCH_WAIT_MS, MAX_KEY_REPEAT } from "./protocol.js";
5
+ const KEY_NAMES = new Set(KEYS);
6
+ const BUTTONS = new Set(["left", "right", "middle"]);
7
+ const PHONE_BUTTONS = new Set(["back", "home", "app_switch"]);
8
+ /** The group each action type needs; wait needs any input group. */
9
+ const GROUP_OF = {
10
+ move: "input.pointer",
11
+ down: "input.pointer",
12
+ up: "input.pointer",
13
+ click: "input.pointer",
14
+ drag: "input.pointer",
15
+ scroll: "input.pointer",
16
+ key: "input.keys",
17
+ hold: "input.keys",
18
+ type: "input.keys",
19
+ tap: "input.touch",
20
+ long_press: "input.touch",
21
+ swipe: "input.touch",
22
+ pinch: "input.touch",
23
+ button: "input.touch",
24
+ wait: "input",
25
+ };
26
+ /** The most characters one type action takes: computerd's MaxTypeRunes (daemon/internal/desktop/check.go). */
27
+ export const MAX_TYPE_CHARACTERS = 64 << 10;
28
+ /** The actions whose ms is a duration, checked by shapeOf and summed toward MAX_BATCH_WAIT_MS. */
29
+ const TIMED = new Set(["wait", "hold", "long_press", "swipe", "pinch"]);
30
+ /** Whether key is a name in KEYS or one printable ASCII character (0x21-0x7e). */
31
+ export function isKey(key) {
32
+ if (typeof key !== "string")
33
+ return false;
34
+ if (KEY_NAMES.has(key))
35
+ return true;
36
+ return key.length === 1 && key.charCodeAt(0) >= 0x21 && key.charCodeAt(0) <= 0x7e;
37
+ }
38
+ const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
39
+ const isMs = (value) => Number.isSafeInteger(value) && value >= 0;
40
+ const isPoint = (value) => Array.isArray(value) && value.length === 2 && value.every(isNumber);
41
+ const isPath = (value) => Array.isArray(value) && value.length >= 2 && value.every(isPoint);
42
+ const show = (value) => JSON.stringify(value) ?? String(value);
43
+ /** What is wrong with one action's shape, in words, or undefined. Keys are checked apart, as `invalid` too. */
44
+ function shapeOf(action) {
45
+ const has = (field) => action[field] !== undefined;
46
+ const button = () => (has("button") && !BUTTONS.has(action.button) ? `button ${show(action.button)} is not left, right or middle` : undefined);
47
+ const at = (required) => ((required || has("at")) && !isPoint(action.at) ? `at ${show(action.at)} is not a point [x, y]` : undefined);
48
+ const ms = (required) => ((required || has("ms")) && !isMs(action.ms) ? `ms ${show(action.ms)} is not a whole number of milliseconds` : undefined);
49
+ const keys = (required) => (required || has("keys")) && !(Array.isArray(action.keys) && (!required || action.keys.length > 0)) ? `keys ${show(action.keys)} is not a list of keys` : undefined;
50
+ switch (action.type) {
51
+ case "move":
52
+ return at(true);
53
+ case "down":
54
+ case "up":
55
+ return button();
56
+ case "click":
57
+ return at(false) ?? button() ?? (has("count") && ![1, 2, 3].includes(action.count) ? `count ${show(action.count)} is not 1, 2 or 3` : undefined) ?? keys(false);
58
+ case "drag":
59
+ return (!isPath(action.path) ? "path is not a list of 2 or more points" : undefined) ?? button() ?? keys(false);
60
+ case "scroll":
61
+ return (at(false) ??
62
+ (["dx", "dy"].find((d) => has(d) && !isNumber(action[d])) !== undefined ? "dx and dy are numbers" : undefined) ??
63
+ (action.unit !== "clicks" && action.unit !== "px" ? `unit ${show(action.unit)} is not clicks or px` : undefined) ??
64
+ keys(false));
65
+ case "key":
66
+ return keys(true) ?? (has("repeat") && !(Number.isSafeInteger(action.repeat) && action.repeat > 0) ? `repeat ${show(action.repeat)} is not a whole number above 0` : undefined);
67
+ case "hold":
68
+ return keys(true) ?? ms(true);
69
+ case "type":
70
+ return typeof action.text !== "string" ? "text is not a string" : undefined;
71
+ case "tap":
72
+ return at(true) ?? (has("count") && ![1, 2].includes(action.count) ? `count ${show(action.count)} is not 1 or 2` : undefined);
73
+ case "long_press":
74
+ return at(true) ?? ms(false);
75
+ case "swipe":
76
+ return (!isPath(action.path) ? "path is not a list of 2 or more points" : undefined) ?? ms(false);
77
+ case "pinch":
78
+ return at(true) ?? (!(isNumber(action.scale) && action.scale > 0) ? `scale ${show(action.scale)} is not a number above 0` : undefined) ?? ms(false);
79
+ case "button":
80
+ return !PHONE_BUTTONS.has(action.name) ? `name ${show(action.name)} is not back, home or app_switch` : undefined;
81
+ case "wait":
82
+ return ms(true);
83
+ default:
84
+ return `type ${show(action.type)} is not an input action`;
85
+ }
86
+ }
87
+ /**
88
+ * The first reason the whole batch must not run, with its index, or undefined when it may. Nothing runs on a failure:
89
+ * the reply is { done: 0, failed }. The batch's shape and length come first, then each action in order: its shape
90
+ * (`invalid`), its keys (`invalid`), its group against groups (`unsupported`), a pixel scroll where there is none
91
+ * (`unsupported`), a key's repeat over MAX_KEY_REPEAT (`limit`), a type's text over MAX_TYPE_CHARACTERS (`limit`), and
92
+ * the summed durations (`limit`).
93
+ */
94
+ export function checkActions(actions, groups, { pixelScroll = true } = {}) {
95
+ if (!Array.isArray(actions))
96
+ return { index: 0, kind: "invalid", message: "actions is not a list" };
97
+ if (actions.length > MAX_ACTIONS)
98
+ return { index: MAX_ACTIONS, kind: "limit", message: `a batch holds at most ${MAX_ACTIONS} actions; this one has ${actions.length}` };
99
+ const input = groups.some((group) => group.startsWith("input."));
100
+ let waited = 0;
101
+ for (const [index, action] of actions.entries()) {
102
+ if (typeof action !== "object" || action === null || Array.isArray(action))
103
+ return { index, kind: "invalid", message: `action ${index} is not an object` };
104
+ const given = action;
105
+ const shape = shapeOf(given);
106
+ if (shape !== undefined)
107
+ return { index, kind: "invalid", message: `action ${index} (${show(given.type)}): ${shape}` };
108
+ // By index, not by value: the bad key may itself be undefined.
109
+ const keys = Array.isArray(given.keys) ? given.keys : [];
110
+ const bad = keys.findIndex((key) => !isKey(key));
111
+ if (bad !== -1) {
112
+ return { index, kind: "invalid", message: `action ${index}: ${show(keys[bad])} is not a key: a key is a name in KEYS or one printable ASCII character` };
113
+ }
114
+ const type = given.type;
115
+ const group = GROUP_OF[type];
116
+ if (group === "input" ? !input : !groups.includes(group)) {
117
+ return { index, kind: "unsupported", message: `action ${index} (${type}) needs ${group === "input" ? "an input group" : group}, which this computer does not declare` };
118
+ }
119
+ if (type === "scroll" && given.unit === "px" && !pixelScroll) {
120
+ return { index, kind: "unsupported", message: `action ${index}: this computer scrolls by clicks, not pixels` };
121
+ }
122
+ if (type === "key" && given.repeat !== undefined && given.repeat > MAX_KEY_REPEAT) {
123
+ return { index, kind: "limit", message: `action ${index}: repeat ${given.repeat} is over ${MAX_KEY_REPEAT}` };
124
+ }
125
+ if (type === "type") {
126
+ const characters = [...given.text].length;
127
+ if (characters > MAX_TYPE_CHARACTERS)
128
+ return { index, kind: "limit", message: `action ${index}: text of ${characters} characters; one type takes at most ${MAX_TYPE_CHARACTERS}` };
129
+ }
130
+ // Every duration counts: wait and hold, and the ms of a long press, a swipe or a pinch. Only these five: shapeOf
131
+ // checks ms on them alone, so an ms on any other action (which may be negative) never enters the sum.
132
+ if (TIMED.has(type) && given.ms !== undefined) {
133
+ waited += given.ms;
134
+ if (waited > MAX_BATCH_WAIT_MS)
135
+ return { index, kind: "limit", message: `the batch's durations reach ${waited} ms at action ${index}, over ${MAX_BATCH_WAIT_MS} ms` };
136
+ }
137
+ }
138
+ return undefined;
139
+ }
@@ -0,0 +1,151 @@
1
+ import type { ComputerClient, Group, HelloResult } from "./protocol.js";
2
+ import type { ComputerCapabilities, ComputerSpec, Refusal } from "./provider.js";
3
+ import { type ComputerErrorCode, type Result } from "./result.js";
4
+ /** The one image a browser computer runs: the vendor's own Chromium. */
5
+ export declare const BROWSER_IMAGE = "chromium";
6
+ /**
7
+ * Where a provider keeps the URLs it was handed, by session id, in memory only. Default a Map of its own; a host that
8
+ * builds one provider per call passes one store to all of them (pi-browser's process-wide holdings).
9
+ */
10
+ export interface UrlStore {
11
+ get(id: string): string | undefined;
12
+ set(id: string, url: string): void;
13
+ delete(id: string): void;
14
+ }
15
+ export declare const memoryUrls: () => UrlStore;
16
+ /** A browser's live view: the fullscreen URL, and, where the vendor gives them, the framed one and each tab's. Every URL is a secret. */
17
+ export interface BrowserStream {
18
+ url: string;
19
+ expiresAt?: Date;
20
+ framed?: string;
21
+ pages?: Array<{
22
+ id: string | null;
23
+ url: string | null;
24
+ title: string | null;
25
+ fullscreen: string | null;
26
+ }>;
27
+ }
28
+ /** How a release is confirmed: the vendor read back this many times at most, this far apart, until the session ended. */
29
+ export interface ReleaseConfirm {
30
+ polls: number;
31
+ intervalMs: number;
32
+ }
33
+ export declare const DEFAULT_CONFIRM: ReleaseConfirm;
34
+ export declare const defaultSleep: (ms: number) => Promise<void>;
35
+ /** A vendor call's failure as the provider returns it: a code and words, and the error the call threw, for a caller that rethrows it as it was. */
36
+ export type VendorFailure = {
37
+ code: ComputerErrorCode;
38
+ message: string;
39
+ readonly cause?: unknown;
40
+ };
41
+ /** A failure whose cause rides along out of sight: not enumerable, so it is in no JSON, no log line and no report. */
42
+ export declare function vendorFail(code: ComputerErrorCode, message: string, cause?: unknown): Result<never>;
43
+ /** The error a vendor call threw, behind a failure vendorFail made; undefined for any other. */
44
+ export declare const causeOf: (result: Result<unknown>) => unknown;
45
+ /** The code a vendor's HTTP status reads as. */
46
+ export declare function statusCode(status: number | undefined, vendor: "browserbase" | "kernel"): ComputerErrorCode;
47
+ /** Why labels are not ones a browser provider writes into a vendor's metadata, in words; undefined when they are. */
48
+ export declare function labelsProblem(labels: unknown): string | undefined;
49
+ /** A label a vendor's query can carry as it is: plain characters, so a quote never ends the query early. */
50
+ export declare const queryable: ([key, value]: [string, string]) => boolean;
51
+ /** Whether a session's metadata carries every one of these labels. */
52
+ export declare const carries: (held: unknown, labels: Record<string, string>) => boolean;
53
+ /** The labels a vendor's metadata holds, its string entries only. */
54
+ export declare const labelsOf: (held: unknown) => Record<string, string>;
55
+ /**
56
+ * The label every create writes beside the spec's, a value of its own: a create whose reply is lost, or whose caller
57
+ * cancels it, finds the browser it made by this label alone and releases it. The provider's own: check() refuses it in a
58
+ * spec, and no list or attach shows it.
59
+ */
60
+ export declare const CREATE_LABEL = "agentrun.create";
61
+ /** Labels without the provider's create label. */
62
+ export declare const withoutCreateLabel: (labels: Record<string, string>) => Record<string, string>;
63
+ /** A create label's value: 16 hex digits, fresh per create. */
64
+ export declare const createLabelValue: () => string;
65
+ /**
66
+ * Whether a create that threw may still have made a browser: anything but the vendor's own 4xx answer (a refusal, which
67
+ * makes nothing). A request not answered, aborted, cut short, or answered 5xx or with a body that is no browser may
68
+ * have been admitted.
69
+ */
70
+ export declare function createUncertain(error: unknown): boolean;
71
+ /** How long a lost create's browser is looked for, in all, and how often: a vendor may list it a moment late. */
72
+ export declare const RECOVER_MS = 30000;
73
+ /**
74
+ * After a create whose outcome is unknown: the browsers carrying its create label, found under a signal of the
75
+ * recovery's own (the caller's may be what ended the create), each released. The words say what became of them, for the
76
+ * create's failure; they never carry a URL.
77
+ */
78
+ export declare function recoverCreate(what: string, find: (signal: AbortSignal) => Promise<Result<string[]>>, release: (id: string) => Promise<Result<void>>, sleep: (ms: number) => Promise<void>): Promise<string>;
79
+ /**
80
+ * The checks every browser provider makes before a vendor call: the image is chromium, the lifetime is within the
81
+ * vendor's cap (and at least min), the network is open, the labels are ones the vendor's metadata holds, and no field a
82
+ * browser does not take (a size, a user, a workdir, a mount).
83
+ */
84
+ export declare function checkBrowser(spec: ComputerSpec, capabilities: ComputerCapabilities, vendor: string, minLifetimeMs?: number): Refusal[];
85
+ /** hello for a browser: the provider's version, linux, kind browser and its groups. The vendor reports no arch. */
86
+ export declare const browserHello: (version: string, groups: Group[]) => HelloResult;
87
+ /**
88
+ * The client of a browser's connection: it answers hello, and ping from the vendor's own read of the session (gone
89
+ * once it has ended); any other method is unsupported, in words, since a browser is driven over CDP.
90
+ */
91
+ export declare function browserClient(hello: HelloResult, alive: (signal?: AbortSignal) => Promise<Result<boolean>>): ComputerClient;
92
+ /**
93
+ * A release, confirmed: the request is sent twice at most, then the vendor's own read must say the session ended, polled
94
+ * up to confirm.polls times. Done means the vendor says it no longer runs, not that the request was sent; a session the
95
+ * vendor no longer knows ("gone") is released. A session still running is a failure carrying the request's own error.
96
+ */
97
+ export declare function releaseConfirmed(o: {
98
+ request: () => Promise<Result<"gone" | "asked">>;
99
+ running: () => Promise<Result<boolean>>;
100
+ confirm: ReleaseConfirm;
101
+ sleep: (ms: number) => Promise<void>;
102
+ stillRunning: string;
103
+ }): Promise<Result<void>>;
104
+ /**
105
+ * A vendor call that failed: the call (a method and a route template, never an id or a URL), the HTTP status when one
106
+ * came back, and the vendor's error code when it is a plain identifier. The vendor's own words are never copied: an echo
107
+ * of the request could carry a key.
108
+ */
109
+ export declare class BrowserVendorError extends Error {
110
+ readonly status: number | undefined;
111
+ readonly code: string | undefined;
112
+ constructor(vendor: string, call: string, status: number | undefined, code?: string, options?: {
113
+ cause?: unknown;
114
+ });
115
+ }
116
+ /** A vendor's error code, kept only when it is a plain identifier. */
117
+ export declare const plainCode: (code: unknown) => string | undefined;
118
+ /**
119
+ * A vendor call's thrown error as a result: aborted, or the code its status reads as, in words that name the call and the
120
+ * status alone. The error itself rides along as the failure's hidden cause (vendorFail).
121
+ */
122
+ export declare function vendorFailure(vendor: "browserbase" | "kernel", name: string, call: string, error: unknown): Result<never>;
123
+ /**
124
+ * Why a vendor's CDP URL is not one to hand a driver, in words that never carry it; undefined when it is. It must be wss:
125
+ * (the session's signing key rides it) on the vendor's own domain or a host under it: a vendor answer that named another
126
+ * host would send the driver, and the key, there. The REST call that gave it was https to the vendor's pinned API with
127
+ * redirects refused; this holds the CDP URL itself to the same.
128
+ */
129
+ export declare function cdpUrlProblem(url: unknown, name: string, domain: string): string | undefined;
130
+ /** What the REST calls share: one request, never retried, read whole; a failure throws a BrowserVendorError. */
131
+ export interface RestReply {
132
+ status: number;
133
+ json: unknown;
134
+ headers: {
135
+ get(name: string): string | null;
136
+ };
137
+ }
138
+ export declare function restCall(o: {
139
+ vendor: string;
140
+ fetch: typeof fetch;
141
+ base: string;
142
+ headers: Record<string, string>;
143
+ }, method: string, route: string, call: string, init?: {
144
+ body?: unknown;
145
+ query?: URLSearchParams;
146
+ signal?: AbortSignal;
147
+ }): Promise<RestReply>;
148
+ /** An https base URL, with no trailing slash, so a key never crosses in the clear; throws in words on another. */
149
+ export declare function httpsBase(url: string, what: string): string;
150
+ /** A vendor's session id as a ref or attach gives it: a plain token, never a path. */
151
+ export declare const idProblem: (id: unknown, vendor: string) => string | undefined;