@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
@@ -0,0 +1,259 @@
1
+ // The daemon file a Docker computer binds: this process's own copy of the provider's daemon, mode 0755, named by the
2
+ // sha256 of its bytes, in a directory only this process's user may enter. npm installs the package's daemons at 0755
3
+ // minus the installer's umask (0700 under umask 077), and a bind shows the computer the host file's own mode, so a
4
+ // computer's user, which has no capabilities, could not run the installed file itself. The daemon is every computer's
5
+ // init, so the directory is checked, never trusted: not a link, this user's, mode 0700, and no directory above it
6
+ // writable by another user, who could otherwise swap it out between the check and docker run.
7
+ import { createHash, randomBytes } from "node:crypto";
8
+ import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
9
+ import { homedir } from "node:os";
10
+ import { basename, dirname, join, resolve } from "node:path";
11
+ import { fail, ok } from "./result.js";
12
+ /**
13
+ * The default directory for the copies: ~/.cache/agentrun-computer. The library reads no environment, XDG_CACHE_HOME
14
+ * included: a caller that keeps its cache elsewhere passes the provider's daemonCache.
15
+ */
16
+ export function defaultDaemonCache() {
17
+ return join(homedir(), ".cache", "agentrun-computer");
18
+ }
19
+ const NODE_FS = {
20
+ closeSync,
21
+ fchmodSync,
22
+ fstatSync: (fd) => fstatSync(fd),
23
+ fsyncSync,
24
+ lstatSync: (path) => lstatSync(path),
25
+ mkdirSync: (path, options) => mkdirSync(path, options),
26
+ openSync: (path, flags, mode) => openSync(path, flags, mode),
27
+ readFileSync: (fd) => readFileSync(fd),
28
+ realpathSync: (path) => realpathSync(path),
29
+ renameSync,
30
+ unlinkSync,
31
+ writeFileSync: (fd, data) => writeFileSync(fd, data),
32
+ };
33
+ const octal = (mode) => mode.toString(8).padStart(4, "0");
34
+ const codeOf = (error) => error.code;
35
+ const wordsOf = (error) => error.message;
36
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
37
+ const ELSEWHERE = "or give the provider another daemonCache";
38
+ /**
39
+ * The path of a 0755 copy of the daemon at `source` in `directory`, named computerd-<sha256>, made if it is not there
40
+ * yet and hashed again before it is returned; or a refusal in words. A copy is written to a temporary file in the
41
+ * directory and renamed into place, so processes copying the same daemon at once each leave a whole file, and only the
42
+ * same bytes ever take that name. A directory that is gone partway (a cache cleaner) is made again and checked again,
43
+ * once. Never throws: every failure is a Result in words naming its path. `fs` is node:fs's own but in tests.
44
+ */
45
+ export function daemonCopy(source, directory, fs = NODE_FS) {
46
+ const uid = process.getuid?.();
47
+ if (uid === undefined)
48
+ return fail("unsupported", "this platform has no user ids, so the provider cannot keep the daemon's copy where only this user may change it");
49
+ let bytes;
50
+ try {
51
+ // O_NONBLOCK: a FIFO at the path fails the isFile check below instead of holding the open.
52
+ const fd = fs.openSync(source, constants.O_RDONLY | constants.O_NONBLOCK);
53
+ try {
54
+ if (!fs.fstatSync(fd).isFile())
55
+ return fail("not_found", `no daemon binary at ${source}: run npm run build:daemon -w @parcha/agentrun-computer`);
56
+ bytes = fs.readFileSync(fd);
57
+ }
58
+ finally {
59
+ fs.closeSync(fd);
60
+ }
61
+ }
62
+ catch (error) {
63
+ const code = codeOf(error);
64
+ if (code === "ENOENT" || code === "ENOTDIR")
65
+ return fail("not_found", `no daemon binary at ${source}: run npm run build:daemon -w @parcha/agentrun-computer`);
66
+ return fail("invalid", `the daemon at ${source} cannot be read by this process (${code ?? wordsOf(error)}): the provider copies it for each computer, so this process's user must be able to read it`);
67
+ }
68
+ const sha = sha256(bytes);
69
+ // A directory a cleaner removes while it is checked or written in is made again, once.
70
+ const first = copyInto(fs, resolve(directory), sha, bytes, uid, source);
71
+ if (!("vanished" in first))
72
+ return first;
73
+ const second = copyInto(fs, resolve(directory), sha, bytes, uid, source);
74
+ if (!("vanished" in second))
75
+ return second;
76
+ return fail("invalid", `the daemon copy directory ${resolve(directory)} vanished while the provider checked it or copied the daemon into it, twice (${second.vanished} was gone), as a cleaner removing it does; ${ELSEWHERE}`);
77
+ }
78
+ /**
79
+ * `directory`, made if missing and checked as daemonCopy checks its own (privateDirectory: this user's, 0700, no link,
80
+ * nothing above it another user may write), as a path with no link in it; made again once when a cleaner removes it
81
+ * partway. For what else the provider keeps beside the daemon's copy: the trees the volume option stages
82
+ * (src/docker/stage.ts), the daemon's directory and the egress proxy's code.
83
+ */
84
+ export function privateCacheDirectory(directory) {
85
+ const uid = process.getuid?.();
86
+ if (uid === undefined)
87
+ return fail("unsupported", "this platform has no user ids, so the provider cannot keep its copies where only this user may change them");
88
+ const first = privateDirectory(NODE_FS, resolve(directory), uid);
89
+ if (!("vanished" in first))
90
+ return first;
91
+ const second = privateDirectory(NODE_FS, resolve(directory), uid);
92
+ if (!("vanished" in second))
93
+ return second;
94
+ return fail("invalid", `the daemon copy directory ${resolve(directory)} vanished while the provider checked it, twice (${second.vanished} was gone); ${ELSEWHERE}`);
95
+ }
96
+ /** daemonCopy's work in its directory: the copy's path, a refusal, or the directory gone under it. */
97
+ function copyInto(fs, directory, sha, bytes, uid, source) {
98
+ const dir = privateDirectory(fs, directory, uid);
99
+ if ("vanished" in dir || !dir.ok)
100
+ return dir;
101
+ const path = join(dir.value, `computerd-${sha}`);
102
+ const found = copyState(fs, path, sha, uid);
103
+ if (found !== "replace" && found !== "absent")
104
+ return found;
105
+ const temp = join(dir.value, `.computerd-${sha}.${randomBytes(8).toString("hex")}.tmp`);
106
+ try {
107
+ const fd = fs.openSync(temp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o700);
108
+ try {
109
+ fs.writeFileSync(fd, bytes);
110
+ // fchmod is not narrowed by the umask: the copy is 0755 whatever it is.
111
+ fs.fchmodSync(fd, 0o755);
112
+ fs.fsyncSync(fd);
113
+ }
114
+ finally {
115
+ fs.closeSync(fd);
116
+ }
117
+ fs.renameSync(temp, path);
118
+ }
119
+ catch (error) {
120
+ try {
121
+ fs.unlinkSync(temp);
122
+ }
123
+ catch {
124
+ // Never made, or already renamed.
125
+ }
126
+ // The temporary file cannot be made, or renamed, in a directory that is gone.
127
+ if (codeOf(error) === "ENOENT")
128
+ return { vanished: dir.value };
129
+ return fail("invalid", `cannot copy the daemon at ${source} to ${path}: ${wordsOf(error)}`);
130
+ }
131
+ const made = copyState(fs, path, sha, uid);
132
+ if (made === "absent")
133
+ return { vanished: dir.value };
134
+ if (made === "replace")
135
+ return fail("invalid", `the daemon's copy at ${path} did not hold the daemon's bytes, mode 0755 and this user's ownership once written`);
136
+ return made;
137
+ }
138
+ const LINK_WORDS = "the provider binds only a file it wrote itself and never follows a link there";
139
+ /**
140
+ * The copy at `path` as found: whole (its path), absent, to be written over, or a refusal. Its entry is read with
141
+ * lstat first, so a copy this user cannot open (mode 0000 or 0111) is written over like any other wrong mode, and a
142
+ * link or another user's file is refused before anything opens it; a 0755 copy of this user's is then opened without
143
+ * following a link and hashed. Every failure to read it is a Result naming it.
144
+ */
145
+ function copyState(fs, path, sha, uid) {
146
+ const cannot = (error) => fail("invalid", `cannot read the daemon's copy at ${path}: ${wordsOf(error)}`);
147
+ let entry;
148
+ try {
149
+ entry = fs.lstatSync(path);
150
+ }
151
+ catch (error) {
152
+ return codeOf(error) === "ENOENT" ? "absent" : cannot(error);
153
+ }
154
+ if (entry.isSymbolicLink())
155
+ return fail("refused", `the daemon's copy at ${path} is a symbolic link; ${LINK_WORDS}: remove it, ${ELSEWHERE}`);
156
+ if (!entry.isFile())
157
+ return fail("refused", `the daemon's copy at ${path} is not a regular file; the provider binds only a file it wrote itself: remove it, ${ELSEWHERE}`);
158
+ if (entry.uid !== uid) {
159
+ return fail("refused", `the daemon's copy at ${path} is owned by uid ${entry.uid}, not this process's uid ${uid}; the provider binds only a file it wrote itself: remove it, ${ELSEWHERE}`);
160
+ }
161
+ if ((entry.mode & 0o7777) !== 0o755)
162
+ return "replace";
163
+ let fd;
164
+ try {
165
+ fd = fs.openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
166
+ }
167
+ catch (error) {
168
+ const code = codeOf(error);
169
+ if (code === "ENOENT")
170
+ return "absent";
171
+ // Made a link since the lstat: O_NOFOLLOW fails with ELOOP on Linux and macOS, EMLINK on FreeBSD.
172
+ if (code === "ELOOP" || code === "EMLINK")
173
+ return fail("refused", `the daemon's copy at ${path} is a symbolic link; ${LINK_WORDS}: remove it, ${ELSEWHERE}`);
174
+ return cannot(error);
175
+ }
176
+ try {
177
+ const stat = fs.fstatSync(fd);
178
+ // The file opened is checked itself: another process of this user's may have renamed its identical copy over the
179
+ // one lstat read, which is as good. One that is not a 0755 file of this user's is written over, then checked again.
180
+ if (!stat.isFile() || stat.uid !== uid || (stat.mode & 0o7777) !== 0o755)
181
+ return "replace";
182
+ return sha256(fs.readFileSync(fd)) === sha ? ok(path) : "replace";
183
+ }
184
+ catch (error) {
185
+ return cannot(error);
186
+ }
187
+ finally {
188
+ fs.closeSync(fd);
189
+ }
190
+ }
191
+ /**
192
+ * `directory` made if missing (mode 0700, and its missing parents too), as a path with no link in it, once it and every
193
+ * directory above it pass: it is a directory, not a link, this user's, mode 0700; each one above is root's or this
194
+ * user's, and no other user may write it unless it is sticky (as /tmp is), where no other user may move this one's
195
+ * entries. Nothing is ever chmodded or chowned: a directory that fails is refused in words, one that cannot be checked
196
+ * is a Result naming it, and one that is gone when it is checked (a cleaner removed it) is Vanished.
197
+ */
198
+ function privateDirectory(fs, directory, uid) {
199
+ const parent = dirname(directory);
200
+ let real;
201
+ try {
202
+ fs.mkdirSync(parent, { recursive: true, mode: 0o700 });
203
+ real = fs.realpathSync(parent);
204
+ }
205
+ catch (error) {
206
+ return fail("invalid", `cannot make ${parent}, the directory the daemon copy directory goes in: ${wordsOf(error)}; make it, ${ELSEWHERE}`);
207
+ }
208
+ for (let at = real;; at = dirname(at)) {
209
+ let stat;
210
+ try {
211
+ stat = fs.lstatSync(at);
212
+ }
213
+ catch (error) {
214
+ if (codeOf(error) === "ENOENT")
215
+ return { vanished: at };
216
+ return fail("invalid", `cannot check ${at}, above the daemon copy directory ${directory}: ${wordsOf(error)}; ${ELSEWHERE}`);
217
+ }
218
+ if (stat.uid !== 0 && stat.uid !== uid) {
219
+ return fail("refused", `${at}, above the daemon copy directory ${directory}, is owned by uid ${stat.uid}: only root or this process's uid ${uid} may own the directories above it, since their owner could swap it out; ${ELSEWHERE}`);
220
+ }
221
+ if ((stat.mode & 0o022) !== 0 && (stat.mode & 0o1000) === 0) {
222
+ return fail("refused", `${at} has mode ${octal(stat.mode & 0o7777)}: a user other than its owner may write it, and so swap out the daemon copy directory ${directory} under it; ${ELSEWHERE}`);
223
+ }
224
+ if (dirname(at) === at)
225
+ break;
226
+ }
227
+ const path = join(real, basename(directory));
228
+ try {
229
+ fs.mkdirSync(path, { mode: 0o700 });
230
+ }
231
+ catch (error) {
232
+ const code = codeOf(error);
233
+ if (code === "ENOENT")
234
+ return { vanished: real };
235
+ if (code !== "EEXIST")
236
+ return fail("invalid", `cannot make the daemon copy directory ${path}: ${wordsOf(error)}; ${ELSEWHERE}`);
237
+ }
238
+ let stat;
239
+ try {
240
+ stat = fs.lstatSync(path);
241
+ }
242
+ catch (error) {
243
+ if (codeOf(error) === "ENOENT")
244
+ return { vanished: path };
245
+ return fail("invalid", `cannot check the daemon copy directory ${path}: ${wordsOf(error)}; ${ELSEWHERE}`);
246
+ }
247
+ if (stat.isSymbolicLink()) {
248
+ return fail("refused", `the daemon copy directory ${path} is a symbolic link; the provider binds the daemon only from a directory this user owns, and never follows a link there: remove it, ${ELSEWHERE}`);
249
+ }
250
+ if (!stat.isDirectory())
251
+ return fail("refused", `the daemon copy directory ${path} is not a directory: remove it, ${ELSEWHERE}`);
252
+ if (stat.uid !== uid) {
253
+ return fail("refused", `the daemon copy directory ${path} is owned by uid ${stat.uid}, not this process's uid ${uid}; only this user may own the directory every computer's init is bound from: ${ELSEWHERE}`);
254
+ }
255
+ if ((stat.mode & 0o777) !== 0o700) {
256
+ return fail("refused", `the daemon copy directory ${path} has mode ${octal(stat.mode & 0o777)}; it must be 0700, so that only this user may enter it, and the provider never changes it: chmod 700 it, ${ELSEWHERE}`);
257
+ }
258
+ return ok(path);
259
+ }
@@ -0,0 +1,178 @@
1
+ import type { KindCapabilities } from "./kinds.js";
2
+ import { type MountKind } from "./mount.js";
3
+ import { type ProviderNote } from "./mount-archil.js";
4
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
5
+ import { type Result } from "./result.js";
6
+ import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
+ /** The longest each kind of call may take, and the pauses between polls and retries. */
8
+ export interface DaytonaTimeouts {
9
+ /** One control-plane or toolbox call. */
10
+ requestMs: number;
11
+ /** POST /sandbox. */
12
+ createMs: number;
13
+ /** From the create's answer to a started sandbox. */
14
+ startMs: number;
15
+ /** One DELETE. */
16
+ deleteMs: number;
17
+ /** From the delete's answer to a sandbox Daytona reads as gone (404) and no longer lists. */
18
+ goneMs: number;
19
+ /** From the stop's answer to a sandbox Daytona reads, and lists, as stopped (or gone, when a stop deletes). */
20
+ stopMs: number;
21
+ /** The daemon's upload. */
22
+ uploadMs: number;
23
+ /** The install script. */
24
+ execMs: number;
25
+ /** From a connect's start to the daemon's hello, and each read-back call after it. */
26
+ helloMs: number;
27
+ pollMs: number;
28
+ /** The first pause before a retry; each next one doubles. */
29
+ retryMs: number;
30
+ /** How long create waits for the listing to show the new computer steadily, and for how long it must. */
31
+ listedMs: number;
32
+ listedStableMs: number;
33
+ }
34
+ /** The parts of a WebSocket the provider uses: Node's global WebSocket, or a fake in tests. */
35
+ export interface WebSocketLike {
36
+ binaryType: string;
37
+ addEventListener(type: "open" | "message" | "close" | "error", listener: (event: {
38
+ data?: unknown;
39
+ code?: number;
40
+ message?: string;
41
+ }) => void): void;
42
+ close(code?: number): void;
43
+ }
44
+ export type WebSocketFactory = (url: string, init: {
45
+ headers: Record<string, string>;
46
+ protocols: string[];
47
+ }) => WebSocketLike;
48
+ export interface DaytonaProviderOptions {
49
+ /** The Daytona API key. The caller passes it; this provider never reads the environment and never puts it in a computer. */
50
+ apiKey: string;
51
+ /** Told what is no failure of the call it came from: a release that did not let an Archil folder go cleanly. */
52
+ onNote?: ProviderNote;
53
+ /** Default https://app.daytona.io/api. */
54
+ apiUrl?: string;
55
+ /** The daemon binary on this machine, for the sandboxes' architecture (dist/computerd-linux-<arch>). */
56
+ daemonPath: string;
57
+ /** Go's name for the sandboxes' architecture, which hello must report. Default amd64. */
58
+ arch?: string;
59
+ /** The class the snapshots this provider is given make: container (default) or linux-vm. */
60
+ sandboxClass?: "container" | "linux-vm";
61
+ /** The Daytona target (region); default the organization's. */
62
+ target?: string;
63
+ /**
64
+ * Who the daemon runs as, uid:gid in numbers, never root. Default 2510:2510 (TOOL_USER), a uid no process of Daytona's
65
+ * holds: init refuses to start while another process does.
66
+ */
67
+ daemonUser?: string;
68
+ /**
69
+ * Daytona's autoStopInterval: minutes without outside activity after which Daytona stops the sandbox, whatever runs in
70
+ * it; 0 (default) is never. A whole number, 0 or more.
71
+ */
72
+ autoStopMinutes?: number;
73
+ /**
74
+ * Daytona's autoDeleteInterval: minutes a sandbox may stay stopped before Daytona deletes it; 0 deletes it as soon as it
75
+ * stops, so a stopped computer is never kept. A whole number, 0 or more; unset, Daytona never deletes a stopped one
76
+ * (-1 is sent) and the TTL ends it.
77
+ */
78
+ autoDeleteMinutes?: number;
79
+ /** For tests: every request goes through it. Default the global fetch. */
80
+ fetch?: typeof fetch;
81
+ /** For tests: every log stream opens through it. Default Node's global WebSocket. */
82
+ webSocket?: WebSocketFactory;
83
+ timeouts?: Partial<DaytonaTimeouts>;
84
+ }
85
+ /**
86
+ * The mount kinds a Daytona computer takes: an Archil mount of the run's folder (mount-archil.ts), made as root through
87
+ * the toolbox, from a snapshot of box/Dockerfile, with the daemon user agentrun-tool (daemonUser "2510:2510").
88
+ */
89
+ export declare const MOUNT: readonly MountKind[];
90
+ /** The machine kind and groups of its one configuration: a linux computer. */
91
+ export declare const CAPABILITIES: readonly KindCapabilities[];
92
+ /** What create() takes: the provider's options, the daemon optional (default this package's build for the arch). */
93
+ export type DaytonaCreateOptions = Omit<DaytonaProviderOptions, "daemonPath"> & {
94
+ daemonPath?: string;
95
+ };
96
+ /**
97
+ * A DaytonaProvider from its options alone; it reads no environment, so the key, the API URL (default Daytona's own) and
98
+ * the target are the caller's: serve passes its DAYTONA_API_KEY, DAYTONA_API_URL and DAYTONA_TARGET, the conformance
99
+ * module the settings it reads. Throws in words when an option is missing or wrong, never echoing the key.
100
+ */
101
+ export declare function create(options: DaytonaCreateOptions): DaytonaProvider;
102
+ /** The conformance CLI's module for Daytona: the run's idle stop and auto-delete, its snapshot, notes and drifted twin. */
103
+ export declare const conformance: () => Promise<typeof import("./conformance/daytona.js")>;
104
+ /** The image that asks for Daytona's default snapshot: the create sends no snapshot field. */
105
+ export declare const DAYTONA_DEFAULT_SNAPSHOT = "default";
106
+ /**
107
+ * The three commands the provider sends into a sandbox, exactly: install (through /process/execute), init and stdio
108
+ * (each a session command), the child daemon's commands (childCommands). Exported so a test can run them where Daytona
109
+ * would, in a root container.
110
+ */
111
+ export declare function daytonaCommands({ staging, deadline, user }?: {
112
+ staging?: string;
113
+ deadline?: string;
114
+ user?: string;
115
+ }): {
116
+ install: string;
117
+ init: string;
118
+ stdio: string;
119
+ };
120
+ /**
121
+ * Computers that are Daytona sandboxes. A spec's image is a Daytona snapshot (its id or name), which gives the class and
122
+ * the size. See the README's Daytona section for every call, and its citation.
123
+ */
124
+ export declare class DaytonaProvider implements ComputerProvider {
125
+ #private;
126
+ readonly id = "daytona";
127
+ readonly version: string;
128
+ constructor({ apiKey, onNote, apiUrl, daemonPath, arch, sandboxClass, target, daemonUser, autoStopMinutes, autoDeleteMinutes, fetch: fetcher, webSocket, timeouts, }: DaytonaProviderOptions);
129
+ /**
130
+ * daemon child: Daytona's toolbox daemon is the sandbox's first process, and init is a command it runs in a session
131
+ * (#prepare), so deleting that session ends init and leaves the sandbox. maxLifetimeMs is the 30 days check() has
132
+ * always given; Daytona's TTL is in whole minutes and documents no cap of its own. The toolbox listens on 2280 on
133
+ * every interface and runs commands for whoever reaches it, so init starts with --own-network, and network none is
134
+ * all a computer takes until a proxy carries open and allowlists out of the daemon's own network.
135
+ */
136
+ capabilities(): ComputerCapabilities;
137
+ check(spec: ComputerSpec): Refusal[];
138
+ create(spec: ComputerSpec, { signal }?: {
139
+ signal?: AbortSignal;
140
+ }): Promise<Result<ComputerRef>>;
141
+ /** The live view: screen.watch on a connection of the watch's own (daemonWatch); a sandbox has no screen. */
142
+ watch(ref: ComputerRef, handlers: ScreenWatchHandlers, options?: WatchOptions): Promise<Result<ScreenWatch>>;
143
+ connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
144
+ attach(ref: {
145
+ id: string;
146
+ } | {
147
+ labels: Record<string, string>;
148
+ }, { signal }?: CallContext): Promise<Result<AttachedComputer>>;
149
+ /**
150
+ * For the sweep after a live run: every sandbox Daytona lists with agentrun.computer=1, whatever its name or state, as
151
+ * Daytona reports it. list() keeps only this provider's computers; this keeps everything the label query returns.
152
+ */
153
+ listLabelled({ signal }?: CallContext): Promise<Result<Array<{
154
+ id: string;
155
+ name?: string;
156
+ state?: string;
157
+ }>>>;
158
+ /** For the sweep: GET /sandbox/{id} once, retried as every read is, and the status Daytona answered (404: none). */
159
+ probe(id: string, { signal }?: CallContext): Promise<Result<{
160
+ status: number;
161
+ state?: string;
162
+ }>>;
163
+ /**
164
+ * Settings' test: one page of the account's sandboxes by the provider's own label, which makes nothing. The count is
165
+ * read from the listing, with no read of each sandbox: a busy account answers as fast, and one sandbox's read never
166
+ * fails a working key. A further page is "or more".
167
+ */
168
+ testConnection({ signal }?: CallContext): Promise<Result<{
169
+ detail: string;
170
+ }>>;
171
+ list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
172
+ network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
173
+ /**
174
+ * Daytona answers a delete or a stop before the sandbox is gone or stopped, and its listing trails both: release
175
+ * returns once Daytona reads the computer as release left it, or fails naming the last state it read.
176
+ */
177
+ release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
178
+ }