@parcha/agentrun-computer 0.1.0-beta.58 → 0.1.0-beta.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +285 -81
- package/box/Dockerfile +4 -3
- package/box/install.sh +57 -11
- package/dist/agent37.d.ts +11 -4
- package/dist/agent37.js +217 -19
- package/dist/attach.d.ts +24 -4
- package/dist/attach.js +50 -19
- package/dist/boxd.js +22 -9
- package/dist/browser.d.ts +56 -11
- package/dist/browser.js +76 -17
- package/dist/browserbase.d.ts +20 -5
- package/dist/browserbase.js +186 -21
- package/dist/child-env.d.ts +11 -0
- package/dist/child-env.js +22 -0
- package/dist/chrome.d.ts +5 -2
- package/dist/chrome.js +5 -2
- package/dist/cloudflare.d.ts +2 -0
- package/dist/cloudflare.js +5 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/agent37.d.ts +20 -40
- package/dist/conformance/agent37.js +31 -118
- package/dist/conformance/archil.d.ts +13 -3
- package/dist/conformance/archil.js +22 -17
- package/dist/conformance/boxd.d.ts +8 -31
- package/dist/conformance/boxd.js +19 -74
- package/dist/conformance/browserbase.d.ts +3 -6
- package/dist/conformance/browserbase.js +6 -17
- package/dist/conformance/cases/health.js +6 -3
- package/dist/conformance/cases/provider.js +4 -1
- package/dist/conformance/cli.d.ts +3 -1
- package/dist/conformance/cli.js +69 -9
- package/dist/conformance/cloudflare.d.ts +3 -6
- package/dist/conformance/cloudflare.js +7 -15
- package/dist/conformance/daytona.d.ts +6 -20
- package/dist/conformance/daytona.js +22 -57
- package/dist/conformance/dial-only.d.ts +4 -3
- package/dist/conformance/dial-only.js +3 -3
- package/dist/conformance/docker.d.ts +4 -5
- package/dist/conformance/docker.js +8 -14
- package/dist/conformance/e2b.d.ts +10 -36
- package/dist/conformance/e2b.js +27 -84
- package/dist/conformance/fly.d.ts +3 -6
- package/dist/conformance/fly.js +2 -6
- package/dist/conformance/groundbox.d.ts +7 -23
- package/dist/conformance/groundbox.js +16 -56
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/kernel.d.ts +3 -6
- package/dist/conformance/kernel.js +5 -15
- package/dist/conformance/kind.d.ts +0 -6
- package/dist/conformance/kind.js +0 -4
- package/dist/conformance/local-chrome.d.ts +5 -7
- package/dist/conformance/local-chrome.js +7 -11
- package/dist/conformance/modal.d.ts +10 -38
- package/dist/conformance/modal.js +27 -74
- package/dist/conformance/module-kit.d.ts +87 -0
- package/dist/conformance/module-kit.js +88 -0
- package/dist/conformance/morph.d.ts +7 -23
- package/dist/conformance/morph.js +20 -66
- package/dist/conformance/orgo.d.ts +5 -10
- package/dist/conformance/orgo.js +15 -27
- package/dist/conformance/phone-harness.d.ts +3 -5
- package/dist/conformance/phone-harness.js +3 -11
- package/dist/conformance/runner.d.ts +13 -3
- package/dist/conformance/runner.js +32 -11
- package/dist/conformance/smolcloud.d.ts +7 -23
- package/dist/conformance/smolcloud.js +16 -49
- package/dist/conformance/sweep.d.ts +10 -5
- package/dist/conformance/sweep.js +91 -38
- package/dist/conformance/tti.d.ts +69 -0
- package/dist/conformance/tti.js +205 -0
- package/dist/conformance/types.d.ts +9 -2
- package/dist/daytona.js +60 -20
- package/dist/descriptor.d.ts +37 -0
- package/dist/descriptor.js +9 -0
- package/dist/descriptors/agent37.d.ts +4 -1
- package/dist/descriptors/agent37.js +5 -2
- package/dist/descriptors/browserbase.d.ts +3 -0
- package/dist/descriptors/browserbase.js +4 -0
- package/dist/descriptors/docker.d.ts +2 -0
- package/dist/descriptors/docker.js +5 -0
- package/dist/descriptors/env-names.d.ts +32 -0
- package/dist/descriptors/env-names.js +60 -0
- package/dist/descriptors/index.d.ts +14 -3
- package/dist/descriptors/kernel.d.ts +3 -0
- package/dist/descriptors/kernel.js +2 -0
- package/dist/descriptors/local-chrome.d.ts +1 -1
- package/dist/descriptors/local-chrome.js +5 -3
- package/dist/descriptors/phone-harness.d.ts +1 -1
- package/dist/descriptors/phone-harness.js +4 -2
- package/dist/docker/egress.d.ts +7 -0
- package/dist/docker/egress.js +8 -0
- package/dist/docker/image.d.ts +5 -1
- package/dist/docker/image.js +12 -8
- package/dist/docker.d.ts +52 -13
- package/dist/docker.js +166 -92
- package/dist/drift.js +6 -6
- package/dist/e2b.d.ts +2 -2
- package/dist/e2b.js +2 -3
- package/dist/groundbox.js +6 -6
- package/dist/host.d.ts +23 -0
- package/dist/hosted/download.d.ts +23 -0
- package/dist/hosted/download.js +144 -0
- package/dist/hosted/process.d.ts +5 -0
- package/dist/hosted/process.js +20 -0
- package/dist/hosted/provider.js +120 -48
- package/dist/hosted/rest.d.ts +19 -8
- package/dist/hosted/rest.js +47 -14
- package/dist/hosted/scripts.d.ts +10 -0
- package/dist/hosted/scripts.js +23 -2
- package/dist/hosted/ssh-exec.d.ts +7 -1
- package/dist/hosted/ssh-exec.js +19 -14
- package/dist/hosted/ssh-key.d.ts +18 -0
- package/dist/hosted/ssh-key.js +36 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/janitor.d.ts +7 -1
- package/dist/janitor.js +2 -2
- package/dist/kernel.d.ts +14 -4
- package/dist/kernel.js +141 -18
- package/dist/local-chrome.d.ts +12 -3
- package/dist/local-chrome.js +108 -10
- package/dist/local-supervisor.js +1 -0
- package/dist/modal.d.ts +6 -5
- package/dist/modal.js +7 -7
- package/dist/morph.js +5 -8
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +3 -3
- package/dist/orgo-desktop.js +2 -4
- package/dist/orgo.d.ts +6 -0
- package/dist/orgo.js +158 -15
- package/dist/phone-harness.d.ts +7 -5
- package/dist/phone-harness.js +60 -61
- package/dist/protocol.d.ts +10 -0
- package/dist/protocol.js +17 -0
- package/dist/provider.d.ts +6 -2
- package/dist/screen-watch.d.ts +6 -1
- package/dist/screen-watch.js +166 -12
- package/dist/vendor-sdk.d.ts +9 -0
- package/dist/vendor-sdk.js +26 -0
- package/package.json +8 -1
|
@@ -4,40 +4,49 @@
|
|
|
4
4
|
// node packages/computer/dist/conformance/sweep.js --provider <id> --before <file>
|
|
5
5
|
// node packages/computer/dist/conformance/sweep.js --provider <id> --after <file>
|
|
6
6
|
//
|
|
7
|
-
// --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
7
|
+
// --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1,
|
|
8
|
+
// and a run id it mints for the run it wraps, which it prints: {"recorded":n,"file":...,"run":"<id>"}. The run is given
|
|
9
|
+
// that id with the conformance CLI's --run (runConformance's run), and every machine it makes carries it as
|
|
10
|
+
// agentrun.conformance (RUN_LABEL). <file> must not be there yet: --before makes it, and refuses one that is, with
|
|
11
|
+
// nothing listed, since another run's --after may read it (each run takes its own, from mktemp -d).
|
|
12
|
+
// --after lists them again, deletes every one whose id is not in <file> and whose RUN_LABEL is the file's run, then
|
|
13
|
+
// reads each of those back by get until the vendor no longer has it, up to 60 s each, and prints one JSON line,
|
|
14
|
+
// {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every machine of the run it found that was not there
|
|
15
|
+
// before, gone + stillThere.length = swept, and leftAlone counts the other new labelled machines, which another user of
|
|
16
|
+
// the account or another conformance run made during the run: never touched. A machine in <file> is never touched
|
|
17
|
+
// either: no call names it, and a before file of another provider is refused, as is one that names no run, and one
|
|
18
|
+
// listed elsewhere for a provider whose module names where it lists (sweepScope: an app and a server), since every
|
|
19
|
+
// machine there would read as new.
|
|
20
|
+
// Exit 0 when every swept machine is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read
|
|
21
|
+
// (or, for --before, one that is there already), missing settings, or a listing the vendor refused (nothing is deleted
|
|
22
|
+
// then). It makes nothing, so it needs no live switch.
|
|
18
23
|
//
|
|
19
|
-
// The conformance runner runs the same sweep (sweepMachines) at the end of every run of a hosted provider, over
|
|
20
|
-
// run's
|
|
21
|
-
|
|
24
|
+
// The conformance runner runs the same sweep (sweepMachines) at the end of every run of a hosted provider, over its own
|
|
25
|
+
// labels, the run's and the runner's (RUNNER_LABEL): its report's cleanup.sweep, whose stillThere must be empty for Core
|
|
26
|
+
// to pass.
|
|
27
|
+
import { closeSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
22
28
|
import { COMPUTER_LABEL } from "../drift.js";
|
|
23
29
|
import { isCommand } from "../entry.js";
|
|
24
30
|
import { hostCall } from "../hosted/process.js";
|
|
25
31
|
import { foundBy, listedBy, NAME_LABEL, settle } from "../hosted/provider.js";
|
|
26
|
-
import { providerModule } from "../providers.js";
|
|
27
|
-
import { ok } from "../result.js";
|
|
28
|
-
import { RUN_LABEL } from "./runner.js";
|
|
32
|
+
import { providerIds, providerModule } from "../providers.js";
|
|
33
|
+
import { fail, ok } from "../result.js";
|
|
34
|
+
import { newRunId, RUN_ID, RUN_LABEL } from "./runner.js";
|
|
29
35
|
/**
|
|
30
|
-
* The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`,
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, whose RUN_LABEL is
|
|
37
|
+
* `run` is deleted and read back gone; any other is left alone and counted. A listing the vendor refused is the error,
|
|
38
|
+
* with nothing deleted, as is a run that is not a run id: nothing is listed then.
|
|
33
39
|
*/
|
|
34
|
-
export async function sweepMachines(host, { labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } }
|
|
40
|
+
export async function sweepMachines(host, { run, labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } }) {
|
|
41
|
+
// A caller with no run (undefined) would otherwise match every machine that carries no run label.
|
|
42
|
+
if (typeof run !== "string" || !RUN_ID.test(run))
|
|
43
|
+
return fail("invalid", `run is a conformance run's id, 12 hex characters; got ${JSON.stringify(run)}`);
|
|
35
44
|
const listed = await foundBy(host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, { listMs, requestMs });
|
|
36
45
|
if (!listed.ok)
|
|
37
46
|
return listed;
|
|
38
47
|
const added = listed.value.filter((machine) => !before.has(machine.id));
|
|
39
|
-
// Only
|
|
40
|
-
const fresh = added.filter((machine) =>
|
|
48
|
+
// Only this run's machines: one another user of the account, or another conformance run, made meanwhile is not its.
|
|
49
|
+
const fresh = added.filter((machine) => machine.labels[RUN_LABEL] === run);
|
|
41
50
|
const leftAlone = added.length - fresh.length;
|
|
42
51
|
for (const machine of fresh) {
|
|
43
52
|
const deleted = await hostCall(host, `the delete of ${machine.id}`, (ctx) => host.delete(machine.id, ctx), requestMs);
|
|
@@ -55,14 +64,30 @@ export async function sweepMachines(host, { labels = {}, before = new Set(), wai
|
|
|
55
64
|
const stillThere = fresh.filter((_, i) => !gone[i]).map((machine) => machine.id);
|
|
56
65
|
return ok({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone });
|
|
57
66
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
/** The registry's providers on the shared machine-host adapter, in its order: each whose conformance module has
|
|
68
|
+
* createHost (what moduleOf asks of one). Read from the modules, so a provider added there is listed with no edit. */
|
|
69
|
+
export async function sweepableProviders() {
|
|
70
|
+
const ids = [];
|
|
71
|
+
for (const id of providerIds) {
|
|
72
|
+
const module = (await providerModule(id)
|
|
73
|
+
.then((one) => one.conformance?.())
|
|
74
|
+
.catch(() => undefined));
|
|
75
|
+
if (typeof module?.createHost === "function")
|
|
76
|
+
ids.push(id);
|
|
77
|
+
}
|
|
78
|
+
return ids;
|
|
79
|
+
}
|
|
80
|
+
const usage = async () => `usage: node packages/computer/dist/conformance/sweep.js --provider <id> --before <file> | --after <file>
|
|
81
|
+
--provider <id> a provider on the shared machine-host adapter (${(await sweepableProviders()).join(", ")})
|
|
82
|
+
--before <file> record the id of every machine the vendor lists with ${COMPUTER_LABEL}=1 into <file>, with a run id
|
|
83
|
+
it mints and prints ({"recorded":n,"file":...,"run":"<id>"}): give it to the run's --run.
|
|
84
|
+
<file> must not be there yet (each run its own, from mktemp -d): an existing one is refused
|
|
85
|
+
--after <file> delete every machine listed with ${COMPUTER_LABEL}=1 whose id is not in <file> and whose ${RUN_LABEL}
|
|
86
|
+
is <file>'s run, read each back until the vendor no longer has it (up to 60 s each), and print
|
|
87
|
+
{"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; any other new one is left alone
|
|
64
88
|
settings: the provider's conformance module's (COMPUTER_<VENDOR>_*), never the vendor's own names
|
|
65
|
-
exit: 0 every swept machine is gone, 1 one is still there, 2 usage error, unreadable before file,
|
|
89
|
+
exit: 0 every swept machine is gone, 1 one is still there, 2 usage error, unreadable before file, a --before file there
|
|
90
|
+
already, no settings, or a refused listing`;
|
|
66
91
|
class Usage extends Error {
|
|
67
92
|
}
|
|
68
93
|
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
@@ -92,8 +117,11 @@ function parse(argv) {
|
|
|
92
117
|
throw new Usage("give --before <file> or --after <file>, one of them");
|
|
93
118
|
return { provider, ...found };
|
|
94
119
|
}
|
|
95
|
-
/**
|
|
96
|
-
|
|
120
|
+
/**
|
|
121
|
+
* The ids a before file of this provider (and of this scope, when the provider names one) holds and the run it minted,
|
|
122
|
+
* or why it is not one.
|
|
123
|
+
*/
|
|
124
|
+
function beforeOf(file, provider, scope) {
|
|
97
125
|
let text;
|
|
98
126
|
try {
|
|
99
127
|
text = readFileSync(file, "utf8");
|
|
@@ -118,7 +146,11 @@ function beforeIds(file, provider, scope) {
|
|
|
118
146
|
const words = typeof listed === "string" && listed !== "" ? `was listed in ${listed}` : "names no place it was listed in";
|
|
119
147
|
throw new Usage(`${file} ${words}, and the settings name ${scope} now: every machine there would read as new, so nothing was listed or deleted`);
|
|
120
148
|
}
|
|
121
|
-
|
|
149
|
+
const run = record.run;
|
|
150
|
+
if (typeof run !== "string" || !RUN_ID.test(run)) {
|
|
151
|
+
throw new Usage(`${file} names no conformance run ("run", 12 hex characters): record it again with --before, and give the run it prints to the conformance CLI's --run; nothing was listed or deleted`);
|
|
152
|
+
}
|
|
153
|
+
return { ids: new Set(ids), run };
|
|
122
154
|
}
|
|
123
155
|
/** The provider's conformance module, for its host and scope. */
|
|
124
156
|
async function moduleOf(provider) {
|
|
@@ -153,26 +185,47 @@ export async function main(argv, io = {}) {
|
|
|
153
185
|
const module = io.host === undefined ? await moduleOf(args.provider) : undefined;
|
|
154
186
|
scope = io.host === undefined ? scopeOf(module, env) : io.scope;
|
|
155
187
|
if (args.mode === "after")
|
|
156
|
-
before =
|
|
188
|
+
before = beforeOf(args.file, args.provider, scope);
|
|
157
189
|
host = io.host ?? (await module.createHost({ env }));
|
|
158
190
|
}
|
|
159
191
|
catch (error) {
|
|
160
|
-
await write(stderr, `${error.message}\n${error instanceof Usage ? `${
|
|
192
|
+
await write(stderr, `${error.message}\n${error instanceof Usage ? `${await usage()}\n` : ""}`);
|
|
161
193
|
return 2;
|
|
162
194
|
}
|
|
163
195
|
if (before === undefined) {
|
|
196
|
+
// The file is made here, before the listing, and only if it is not there ("wx"): a before file another run
|
|
197
|
+
// recorded is never written over, or that run's --after would read this run's id and delete this run's machines.
|
|
198
|
+
let fd;
|
|
199
|
+
try {
|
|
200
|
+
fd = openSync(args.file, "wx");
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const why = error.code === "EEXIST" ? "is there already, and --before never writes over a before file: another run's --after may read it. Give each run a file of its own (mktemp -d)" : `cannot be made: ${error.message}`;
|
|
204
|
+
await write(stderr, `${args.file} ${why}; nothing was listed\n`);
|
|
205
|
+
return 2;
|
|
206
|
+
}
|
|
164
207
|
const listed = await listedBy(host, "the listing", { [COMPUTER_LABEL]: "1" }, 60_000);
|
|
165
208
|
if (!listed.ok) {
|
|
209
|
+
// The empty file this --before made goes, so the same path takes the next one.
|
|
210
|
+
closeSync(fd);
|
|
211
|
+
rmSync(args.file, { force: true });
|
|
166
212
|
await write(stderr, `listing the machines carrying ${COMPUTER_LABEL}=1 failed, so nothing was recorded: ${listed.error.message}\n`);
|
|
167
213
|
return 2;
|
|
168
214
|
}
|
|
169
215
|
const ids = listed.value.map((machine) => machine.id).sort();
|
|
170
|
-
|
|
171
|
-
|
|
216
|
+
// The run this sweep wraps: its --after deletes only the machines labelled with this id, never another run's.
|
|
217
|
+
const run = newRunId();
|
|
218
|
+
try {
|
|
219
|
+
writeFileSync(fd, `${JSON.stringify({ provider: args.provider, ...(scope === undefined ? {} : { scope }), label: `${COMPUTER_LABEL}=1`, run, at: new Date().toISOString(), ids }, null, 2)}\n`);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
closeSync(fd);
|
|
223
|
+
}
|
|
224
|
+
await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file, run })}\n`);
|
|
172
225
|
return 0;
|
|
173
226
|
}
|
|
174
227
|
const said = [];
|
|
175
|
-
const swept = await sweepMachines(host, { before, waitMs, pollMs, onWords: (words) => said.push(words) });
|
|
228
|
+
const swept = await sweepMachines(host, { run: before.run, before: before.ids, waitMs, pollMs, onWords: (words) => said.push(words) });
|
|
176
229
|
for (const words of said)
|
|
177
230
|
await write(stderr, `${words}\n`);
|
|
178
231
|
if (!swept.ok) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ComputerProvider } from "../provider.js";
|
|
2
|
+
import type { ComputerDaemon, ComputerNote, ConformanceOptions, ConformanceReport } from "./types.js";
|
|
3
|
+
export interface TtiStats {
|
|
4
|
+
median: number;
|
|
5
|
+
p95: number;
|
|
6
|
+
p99: number;
|
|
7
|
+
}
|
|
8
|
+
/** One shape of the run: one computer at a time (serial) or all at once (burst). */
|
|
9
|
+
export interface TtiShape {
|
|
10
|
+
/** Computers asked for. */
|
|
11
|
+
n: number;
|
|
12
|
+
/** Computers that ran their first command. */
|
|
13
|
+
ok: number;
|
|
14
|
+
/** ok / n. */
|
|
15
|
+
successRate: number;
|
|
16
|
+
/** Each computer's TTI in ms, of those that came up, in the order they did. */
|
|
17
|
+
ttiMs: number[];
|
|
18
|
+
stats: TtiStats;
|
|
19
|
+
/** ComputeSDK's composite score, 0 to 100 (ttiScore). */
|
|
20
|
+
score: number;
|
|
21
|
+
/** Why the rest did not come up: each distinct reason and how many computers gave it. */
|
|
22
|
+
errors: Array<{
|
|
23
|
+
words: string;
|
|
24
|
+
count: number;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export interface TtiReport {
|
|
28
|
+
provider: string;
|
|
29
|
+
providerVersion: string;
|
|
30
|
+
kind: ConformanceReport["kind"];
|
|
31
|
+
daemonMode: ConformanceReport["daemonMode"];
|
|
32
|
+
image: string;
|
|
33
|
+
/** The first command each computer runs. */
|
|
34
|
+
command: string[];
|
|
35
|
+
/** Whether any computer ran its first command; why: the first reason one did not, when none did. */
|
|
36
|
+
cameUp: boolean;
|
|
37
|
+
why?: string;
|
|
38
|
+
serial?: TtiShape;
|
|
39
|
+
burst?: TtiShape;
|
|
40
|
+
/** Every computer came up and the run left nothing behind. */
|
|
41
|
+
pass: boolean;
|
|
42
|
+
cleanup: ConformanceReport["cleanup"];
|
|
43
|
+
computers: ConformanceReport["computers"];
|
|
44
|
+
daemons: ComputerDaemon[];
|
|
45
|
+
notes?: string[];
|
|
46
|
+
providerNotes?: ComputerNote[];
|
|
47
|
+
}
|
|
48
|
+
export interface TtiOptions extends Omit<ConformanceOptions, "cases" | "only" | "kind" | "concurrency"> {
|
|
49
|
+
/** Computers made one at a time, each deleted before the next: the serial shape. 0 for none. */
|
|
50
|
+
iterations: number;
|
|
51
|
+
/** Computers made all at once: the burst shape. 0 for none. */
|
|
52
|
+
burst: number;
|
|
53
|
+
}
|
|
54
|
+
/** ComputeSDK's statistics: 5% of the values trimmed from each end when that leaves some, then median, p95 and p99. */
|
|
55
|
+
export declare function ttiStats(values: readonly number[]): TtiStats;
|
|
56
|
+
/**
|
|
57
|
+
* ComputeSDK's composite score: median, p95 and p99 each scored 100 * (1 - ms / 10000), 0 at or past 10 s, weighted
|
|
58
|
+
* 0.6, 0.25 and 0.15, times the success rate, to two decimals. No computer up scores 0.
|
|
59
|
+
*/
|
|
60
|
+
export declare function ttiScore(stats: TtiStats, successRate: number): number;
|
|
61
|
+
/**
|
|
62
|
+
* Measures the provider's TTI: `iterations` computers one at a time, each its own case (made, timed, deleted), then
|
|
63
|
+
* `burst` computers all at once in one case. Each computer has 150 s to come up; one that does not counts against its
|
|
64
|
+
* shape's success rate with its words. The run's cleanup is the conformance runner's: every computer carries the run's
|
|
65
|
+
* label, a janitor provider is swept by it, and the label is listed to show nothing is left.
|
|
66
|
+
*/
|
|
67
|
+
export declare function measureTti(provider: ComputerProvider, options: TtiOptions): Promise<TtiReport>;
|
|
68
|
+
/** The report as a person reads it: came up, one line per shape, its errors under it, the cleanup, the verdict last. */
|
|
69
|
+
export declare function formatTti(report: TtiReport): string;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { runConformance } from "./runner.js";
|
|
2
|
+
/** How long one computer has to come up: ComputeSDK's create bound (120 s) and its first command's (30 s). */
|
|
3
|
+
const COME_UP_MS = 150_000;
|
|
4
|
+
/** Each of median, p95 and p99 scores 100 at 0 ms and 0 at this or more (ComputeSDK's ceiling). */
|
|
5
|
+
const CEILING_MS = 10_000;
|
|
6
|
+
const WEIGHTS = { median: 0.6, p95: 0.25, p99: 0.15 };
|
|
7
|
+
/** The share of the fastest and of the slowest TTIs left out of the statistics, each (ComputeSDK's trim). */
|
|
8
|
+
const TRIM = 0.05;
|
|
9
|
+
/** At most this many kinds of error are printed under a shape's line; --json carries them all. */
|
|
10
|
+
const ERRORS_SHOWN = 5;
|
|
11
|
+
/** ComputeSDK's percentile: nearest rank over values sorted ascending. */
|
|
12
|
+
function percentile(sorted, p) {
|
|
13
|
+
if (sorted.length === 0)
|
|
14
|
+
return 0;
|
|
15
|
+
const at = Math.max(0, Math.ceil((p / 100) * sorted.length) - 1);
|
|
16
|
+
return sorted[Math.min(at, sorted.length - 1)];
|
|
17
|
+
}
|
|
18
|
+
/** ComputeSDK's statistics: 5% of the values trimmed from each end when that leaves some, then median, p95 and p99. */
|
|
19
|
+
export function ttiStats(values) {
|
|
20
|
+
if (values.length === 0)
|
|
21
|
+
return { median: 0, p95: 0, p99: 0 };
|
|
22
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
23
|
+
const cut = Math.floor(sorted.length * TRIM);
|
|
24
|
+
const kept = cut > 0 && sorted.length - 2 * cut > 0 ? sorted.slice(cut, sorted.length - cut) : sorted;
|
|
25
|
+
const mid = Math.floor(kept.length / 2);
|
|
26
|
+
const median = kept.length % 2 === 0 ? (kept[mid - 1] + kept[mid]) / 2 : kept[mid];
|
|
27
|
+
return { median, p95: percentile(kept, 95), p99: percentile(kept, 99) };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ComputeSDK's composite score: median, p95 and p99 each scored 100 * (1 - ms / 10000), 0 at or past 10 s, weighted
|
|
31
|
+
* 0.6, 0.25 and 0.15, times the success rate, to two decimals. No computer up scores 0.
|
|
32
|
+
*/
|
|
33
|
+
export function ttiScore(stats, successRate) {
|
|
34
|
+
if (successRate === 0)
|
|
35
|
+
return 0;
|
|
36
|
+
const metric = (ms) => Math.max(0, 100 * (1 - ms / CEILING_MS));
|
|
37
|
+
const timing = WEIGHTS.median * metric(stats.median) + WEIGHTS.p95 * metric(stats.p95) + WEIGHTS.p99 * metric(stats.p99);
|
|
38
|
+
return Math.round(timing * successRate * 100) / 100;
|
|
39
|
+
}
|
|
40
|
+
const words = (error) => (error instanceof Error ? error.message : String(error)).replace(/\s*\n\s*/g, " ");
|
|
41
|
+
/**
|
|
42
|
+
* One computer: create, connect, the first command, timed on the run's clock from create's call to the command's
|
|
43
|
+
* answer. The runner deletes it when its case ends, outside the time, as ComputeSDK leaves out destroy.
|
|
44
|
+
*/
|
|
45
|
+
async function comeUp(t, command) {
|
|
46
|
+
const start = t.clock.now();
|
|
47
|
+
const ref = await t.create();
|
|
48
|
+
const connection = await t.connect(ref);
|
|
49
|
+
const ran = await t.exec(command, {}, connection.client);
|
|
50
|
+
if (ran.exitCode !== 0)
|
|
51
|
+
throw new Error(`the first command, ${command.join(" ")}, exited ${ran.exitCode ?? ran.signal}${ran.err.trim() === "" ? "" : `: ${ran.err.trim()}`}`);
|
|
52
|
+
return t.clock.now() - start;
|
|
53
|
+
}
|
|
54
|
+
/** Skips the case when the provider runs no command: TTI is time to the first one. */
|
|
55
|
+
function needsExec(t) {
|
|
56
|
+
const { groups } = t.provider.capabilities();
|
|
57
|
+
if (!(Array.isArray(groups) && groups.includes("exec")))
|
|
58
|
+
t.skip("the provider declares no exec: TTI is time to the first command, and its computers run none");
|
|
59
|
+
}
|
|
60
|
+
/** The shape's numbers from what each computer gave. */
|
|
61
|
+
function shape(came) {
|
|
62
|
+
const ttiMs = came.flatMap((one) => ("ms" in one ? [one.ms] : []));
|
|
63
|
+
const errors = [];
|
|
64
|
+
for (const one of came) {
|
|
65
|
+
if (!("error" in one))
|
|
66
|
+
continue;
|
|
67
|
+
const seen = errors.find((error) => error.words === one.error);
|
|
68
|
+
if (seen)
|
|
69
|
+
seen.count += 1;
|
|
70
|
+
else
|
|
71
|
+
errors.push({ words: one.error, count: 1 });
|
|
72
|
+
}
|
|
73
|
+
const successRate = came.length === 0 ? 0 : ttiMs.length / came.length;
|
|
74
|
+
const stats = ttiStats(ttiMs);
|
|
75
|
+
return { n: came.length, ok: ttiMs.length, successRate, ttiMs, stats, score: ttiScore(stats, successRate), errors };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Measures the provider's TTI: `iterations` computers one at a time, each its own case (made, timed, deleted), then
|
|
79
|
+
* `burst` computers all at once in one case. Each computer has 150 s to come up; one that does not counts against its
|
|
80
|
+
* shape's success rate with its words. The run's cleanup is the conformance runner's: every computer carries the run's
|
|
81
|
+
* label, a janitor provider is swept by it, and the label is listed to show nothing is left.
|
|
82
|
+
*/
|
|
83
|
+
export async function measureTti(provider, options) {
|
|
84
|
+
const { iterations, burst, ...rest } = options;
|
|
85
|
+
for (const [name, value] of [
|
|
86
|
+
["iterations", iterations],
|
|
87
|
+
["burst", burst],
|
|
88
|
+
]) {
|
|
89
|
+
if (!(Number.isSafeInteger(value) && value >= 0))
|
|
90
|
+
throw new TypeError(`${name} is a whole number of computers, 0 or more; got ${value}`);
|
|
91
|
+
}
|
|
92
|
+
if (iterations + burst === 0)
|
|
93
|
+
throw new TypeError("a TTI run makes at least one computer: give iterations or burst");
|
|
94
|
+
// ComputeSDK runs `node -v`; an image need not carry node, so the first command is the shell's echo, Windows' too.
|
|
95
|
+
const command = provider.capabilities().os === "windows" ? ["cmd.exe", "/d", "/c", "echo agentrun"] : ["echo", "agentrun"];
|
|
96
|
+
const serialMs = new Map();
|
|
97
|
+
const bursted = [];
|
|
98
|
+
const cases = Array.from({ length: iterations }, (_, i) => ({
|
|
99
|
+
id: `tti.serial-${i + 1}`,
|
|
100
|
+
level: "full",
|
|
101
|
+
group: "tti",
|
|
102
|
+
needs: [],
|
|
103
|
+
computer: "none",
|
|
104
|
+
timeoutMs: COME_UP_MS,
|
|
105
|
+
async run(t) {
|
|
106
|
+
needsExec(t);
|
|
107
|
+
serialMs.set(`tti.serial-${i + 1}`, await comeUp(t, command));
|
|
108
|
+
},
|
|
109
|
+
}));
|
|
110
|
+
if (burst > 0) {
|
|
111
|
+
cases.push({
|
|
112
|
+
id: "tti.burst",
|
|
113
|
+
level: "full",
|
|
114
|
+
group: "tti",
|
|
115
|
+
needs: [],
|
|
116
|
+
computer: "none",
|
|
117
|
+
timeoutMs: COME_UP_MS,
|
|
118
|
+
async run(t) {
|
|
119
|
+
needsExec(t);
|
|
120
|
+
// Each computer is recorded as it comes up or fails; once the case's time is out, what is left is counted
|
|
121
|
+
// with the case's own reason below, and a late answer is not recorded.
|
|
122
|
+
const record = (one) => {
|
|
123
|
+
if (!t.signal.aborted)
|
|
124
|
+
bursted.push(one);
|
|
125
|
+
};
|
|
126
|
+
await Promise.all(Array.from({ length: burst }, () => comeUp(t, command).then((ms) => record({ ms }), (error) => record({ error: words(error) }))));
|
|
127
|
+
const failed = bursted.filter((one) => "error" in one).length;
|
|
128
|
+
if (failed > 0)
|
|
129
|
+
throw new Error(`${failed} of ${burst} computers did not come up`);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const report = await runConformance(provider, { ...rest, cases });
|
|
134
|
+
const resultOf = (id) => report.results.find((result) => result.id === id);
|
|
135
|
+
const serial = Array.from({ length: iterations }, (_, i) => {
|
|
136
|
+
const id = `tti.serial-${i + 1}`;
|
|
137
|
+
const ms = serialMs.get(id);
|
|
138
|
+
return resultOf(id)?.status === "pass" && ms !== undefined ? { ms } : { error: resultOf(id)?.reason ?? `${id} did not run` };
|
|
139
|
+
});
|
|
140
|
+
const burstCame = [...bursted, ...Array.from({ length: burst - bursted.length }, () => ({ error: resultOf("tti.burst")?.reason ?? "tti.burst did not run" }))];
|
|
141
|
+
const shapes = { ...(iterations > 0 ? { serial: shape(serial) } : {}), ...(burst > 0 ? { burst: shape(burstCame) } : {}) };
|
|
142
|
+
const all = [...serial, ...burstCame];
|
|
143
|
+
const cameUp = all.some((one) => "ms" in one);
|
|
144
|
+
const firstError = all.find((one) => "error" in one);
|
|
145
|
+
const clean = report.cleanup.left.length === 0 && report.cleanup.errors.length === 0;
|
|
146
|
+
return {
|
|
147
|
+
provider: report.provider,
|
|
148
|
+
providerVersion: report.providerVersion,
|
|
149
|
+
kind: report.kind,
|
|
150
|
+
daemonMode: report.daemonMode,
|
|
151
|
+
image: report.image,
|
|
152
|
+
command,
|
|
153
|
+
cameUp,
|
|
154
|
+
...(cameUp || firstError === undefined ? {} : { why: firstError.error }),
|
|
155
|
+
...shapes,
|
|
156
|
+
pass: firstError === undefined && clean,
|
|
157
|
+
cleanup: report.cleanup,
|
|
158
|
+
computers: report.computers,
|
|
159
|
+
daemons: report.daemons,
|
|
160
|
+
...(report.notes === undefined ? {} : { notes: report.notes }),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** The report as a person reads it: came up, one line per shape, its errors under it, the cleanup, the verdict last. */
|
|
164
|
+
export function formatTti(report) {
|
|
165
|
+
const lines = [`computer tti · ${report.provider} · ${report.kind}, daemon ${report.daemonMode} · image ${report.image}`];
|
|
166
|
+
lines.push(report.cameUp ? "came up: yes" : `came up: no: ${report.why ?? "no computer was asked for"}`);
|
|
167
|
+
const ms = (value) => `${Math.round(value)} ms`;
|
|
168
|
+
for (const [label, one] of [
|
|
169
|
+
["serial", report.serial],
|
|
170
|
+
["burst ", report.burst],
|
|
171
|
+
]) {
|
|
172
|
+
if (one === undefined)
|
|
173
|
+
continue;
|
|
174
|
+
const shown = `n ${one.n}${label === "burst " ? " at once" : ""} · ok ${one.ok}/${one.n} (${Math.round(one.successRate * 100)}%)`;
|
|
175
|
+
lines.push(`${label} ${shown} · median ${ms(one.stats.median)} · p95 ${ms(one.stats.p95)} · p99 ${ms(one.stats.p99)} · score ${one.score}`);
|
|
176
|
+
for (const error of one.errors.slice(0, ERRORS_SHOWN))
|
|
177
|
+
lines.push(` ✗ ${error.count}x ${error.words}`);
|
|
178
|
+
if (one.errors.length > ERRORS_SHOWN)
|
|
179
|
+
lines.push(` ✗ and ${one.errors.length - ERRORS_SHOWN} more kinds of error (--json has them all)`);
|
|
180
|
+
}
|
|
181
|
+
const { cleanup } = report;
|
|
182
|
+
if (cleanup.late.length > 0)
|
|
183
|
+
lines.push(`cleanup - deleted after their case ended: ${cleanup.late.join(", ")}`);
|
|
184
|
+
if (cleanup.left.length === 0 && cleanup.errors.length === 0)
|
|
185
|
+
lines.push(`cleanup ✓ 0 left · ${cleanup.deleted.length} deleted`);
|
|
186
|
+
else {
|
|
187
|
+
lines.push(`cleanup ✗ ${cleanup.left.length > 0 ? `left ${cleanup.left.join(", ")}` : "could not show nothing was left"}`);
|
|
188
|
+
for (const error of cleanup.errors)
|
|
189
|
+
lines.push(` ✗ ${error}`);
|
|
190
|
+
}
|
|
191
|
+
lines.push(`computers alive at once: ${report.computers.peak} at most`);
|
|
192
|
+
for (const note of report.notes ?? [])
|
|
193
|
+
lines.push(`note: ${note}`);
|
|
194
|
+
for (const { computer, note } of report.providerNotes ?? [])
|
|
195
|
+
lines.push(`provider note ${computer}: ${note}`);
|
|
196
|
+
const shapes = [report.serial, report.burst].filter((one) => one !== undefined);
|
|
197
|
+
const total = shapes.reduce((sum, one) => sum + one.n, 0);
|
|
198
|
+
const down = total - shapes.reduce((sum, one) => sum + one.ok, 0);
|
|
199
|
+
const reasons = [
|
|
200
|
+
...(down > 0 ? [`${down} of ${total} computers did not come up`] : []),
|
|
201
|
+
...(cleanup.left.length > 0 || cleanup.errors.length > 0 ? ["the cleanup did not show nothing was left"] : []),
|
|
202
|
+
];
|
|
203
|
+
lines.push(reasons.length === 0 ? `tti PASS: ${total} of ${total} computers came up` : `tti FAIL: ${reasons.join("; ")}`);
|
|
204
|
+
return `${lines.join("\n")}\n`;
|
|
205
|
+
}
|
|
@@ -10,7 +10,7 @@ import type { KindVerdict } from "./kind.js";
|
|
|
10
10
|
/** Core: what a computer of its kind must do. Full: an optional capability, tested only where it is declared. */
|
|
11
11
|
export type Level = "core" | "full";
|
|
12
12
|
/** The suite's own grouping of its cases, the first part of each case id; not the protocol's Group. */
|
|
13
|
-
export type CaseGroup = "health" | "exec" | "files" | "process" | "provider" | "drift" | "isolation" | "mount" | "screen" | "input" | "touch" | "apps" | "ui" | "lifetime" | "browser" | "gpu";
|
|
13
|
+
export type CaseGroup = "health" | "exec" | "files" | "process" | "provider" | "drift" | "isolation" | "mount" | "screen" | "input" | "touch" | "apps" | "ui" | "lifetime" | "browser" | "gpu" | "tti";
|
|
14
14
|
/**
|
|
15
15
|
* What a case needs: a group (declared by both the provider's capabilities().groups and the computer's hello), a
|
|
16
16
|
* network the provider declares, the janitor as the keeper of deadlines, a spec.user the provider takes, a release that
|
|
@@ -66,7 +66,7 @@ export interface CaseContext {
|
|
|
66
66
|
/** A connection of the case's own to that computer, after hello: computerd, or the provider itself (daemon none). */
|
|
67
67
|
readonly client: ComputerClient;
|
|
68
68
|
readonly hello: HelloResult;
|
|
69
|
-
/** The
|
|
69
|
+
/** The labels every computer of this runner carries: the run's id (agentrun.conformance) and the runner's own. */
|
|
70
70
|
readonly runLabels: Record<string, string>;
|
|
71
71
|
/** How long a case waits on a program before it fails: a bound, never a claim about speed. */
|
|
72
72
|
readonly patience: number;
|
|
@@ -307,6 +307,13 @@ export interface ConformanceOptions {
|
|
|
307
307
|
* computer, is refused, in words.
|
|
308
308
|
*/
|
|
309
309
|
kind?: ComputerSettingKind;
|
|
310
|
+
/**
|
|
311
|
+
* The run's id, which every computer it makes carries as agentrun.conformance: the one the live sweep's --before
|
|
312
|
+
* minted, so its --after deletes this run's computers and no other's (12 hex characters). Default a fresh one. Several
|
|
313
|
+
* runners may share one: each also labels its computers with an id of its own (agentrun.conformance.runner), and its
|
|
314
|
+
* end-of-run sweeps go by that too, so the first to end never deletes another's.
|
|
315
|
+
*/
|
|
316
|
+
run?: string;
|
|
310
317
|
signal?: AbortSignal;
|
|
311
318
|
/** The cases to run; default casesFor the provider's machine kind: a browser's own cases, else every case of the suite. */
|
|
312
319
|
cases?: Case[];
|
package/dist/daytona.js
CHANGED
|
@@ -71,7 +71,10 @@ const OUT = Buffer.from([1, 1, 1]);
|
|
|
71
71
|
const ERR = Buffer.from([2, 2, 2]);
|
|
72
72
|
/** A line the client wrote, echoed back: a request or a notification is never a daemon's reply. */
|
|
73
73
|
const ECHO = /^\{"jsonrpc":"2\.0",("id":\d+,)?"method":/;
|
|
74
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* The toolbox session a dial sandbox's agentrun-dial runs in, its one command: dialLog reads its log by this id. A
|
|
76
|
+
* second start (redial) runs in a session of its own, this name with -2.
|
|
77
|
+
*/
|
|
75
78
|
const DIAL_SESSION = "agentrun-dial";
|
|
76
79
|
const decoder = new TextDecoder();
|
|
77
80
|
/**
|
|
@@ -127,12 +130,18 @@ class DaytonaHost {
|
|
|
127
130
|
*/
|
|
128
131
|
descriptor = DAYTONA;
|
|
129
132
|
facts;
|
|
130
|
-
/** connect exec alone: a dial host has
|
|
133
|
+
/** connect exec alone: a dial host has none of them (HostFacts.connect). */
|
|
131
134
|
exec;
|
|
132
135
|
upload;
|
|
133
|
-
|
|
136
|
+
download;
|
|
137
|
+
/** connect dial alone: agentrun-dial's session command's log, its exit, and its second start. */
|
|
134
138
|
dialLog;
|
|
135
|
-
|
|
139
|
+
dialExit;
|
|
140
|
+
redial;
|
|
141
|
+
/**
|
|
142
|
+
* The session and command that run agentrun-dial, by sandbox id, from its create or its second start, and the attach
|
|
143
|
+
* URL its line sets: what dialLog and dialExit read, and redial starts again. Let go of at its delete.
|
|
144
|
+
*/
|
|
136
145
|
#dials = new Map();
|
|
137
146
|
/** Daytona's REST API: the control plane, and the toolbox of each sandbox. */
|
|
138
147
|
#rest;
|
|
@@ -178,9 +187,13 @@ class DaytonaHost {
|
|
|
178
187
|
if (options.connect === "exec") {
|
|
179
188
|
this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
|
|
180
189
|
this.upload = (id, path, bytes, ctx) => this.#upload(id, path, bytes, ctx);
|
|
190
|
+
this.download = (id, path, ctx) => this.#download(id, path, ctx);
|
|
181
191
|
}
|
|
182
|
-
else
|
|
192
|
+
else {
|
|
183
193
|
this.dialLog = (id, ctx) => this.#dialLog(id, ctx);
|
|
194
|
+
this.dialExit = (id, ctx) => this.#dialExit(id, ctx);
|
|
195
|
+
this.redial = (id, ctx) => this.#redial(id, ctx);
|
|
196
|
+
}
|
|
184
197
|
}
|
|
185
198
|
/**
|
|
186
199
|
* A snapshot name has no control characters, and its size is the snapshot's; a GPU computer is made from the
|
|
@@ -292,7 +305,7 @@ class DaytonaHost {
|
|
|
292
305
|
try {
|
|
293
306
|
const toolbox = await this.#toolbox(id);
|
|
294
307
|
const { commandId } = await this.#runAsync(toolbox, DIAL_SESSION, dialLaunch({ rootOnly: this.facts.rootOnly, attach }), Math.max(1, until - Date.now()));
|
|
295
|
-
this.#dials.set(id, commandId);
|
|
308
|
+
this.#dials.set(id, { session: DIAL_SESSION, command: commandId, attach, starts: 1 });
|
|
296
309
|
}
|
|
297
310
|
catch (error) {
|
|
298
311
|
throw new HostError("vendor", `starting agentrun-dial in ${id} failed: ${words(error)}`);
|
|
@@ -304,13 +317,39 @@ class DaytonaHost {
|
|
|
304
317
|
* prefixes are dropped. undefined when this host started no agentrun-dial there.
|
|
305
318
|
*/
|
|
306
319
|
async #dialLog(id, ctx) {
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
320
|
+
const dial = this.#dials.get(id);
|
|
321
|
+
if (dial === undefined)
|
|
309
322
|
return undefined;
|
|
310
|
-
const session = `${await this.#toolbox(id, ctx.signal)}/process/session/${
|
|
311
|
-
const logs = orThrow(await this.#rest.call("GET", `${session}/command/${encodeURIComponent(
|
|
323
|
+
const session = `${await this.#toolbox(id, ctx.signal)}/process/session/${dial.session}`;
|
|
324
|
+
const logs = orThrow(await this.#rest.call("GET", `${session}/command/${encodeURIComponent(dial.command)}/logs`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
|
|
312
325
|
return decoder.decode(logs.bytes).replaceAll(OUT.toString("latin1"), "").replaceAll(ERR.toString("latin1"), "");
|
|
313
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* agentrun-dial's exit code: one read of its session, whose command of the id its start returned carries exitCode
|
|
329
|
+
* once it has exited (as the exec path reads a command's exit). undefined while it runs, and where this host started
|
|
330
|
+
* no agentrun-dial.
|
|
331
|
+
*/
|
|
332
|
+
async #dialExit(id, ctx) {
|
|
333
|
+
const dial = this.#dials.get(id);
|
|
334
|
+
if (dial === undefined)
|
|
335
|
+
return undefined;
|
|
336
|
+
const read = orThrow(await this.#rest.json("GET", `${await this.#toolbox(id, ctx.signal)}/process/session/${dial.session}`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
|
|
337
|
+
const found = (read?.commands ?? []).find((one) => one.id === dial.command);
|
|
338
|
+
return typeof found?.exitCode === "number" ? found.exitCode : undefined;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* agentrun-dial started once more, as create started it (dialLaunch's line, the same attach URL; the token is the
|
|
342
|
+
* sandbox's env still), in a session of its own: dialLog and dialExit read that one from then. A sandbox this host
|
|
343
|
+
* started no agentrun-dial in is refused.
|
|
344
|
+
*/
|
|
345
|
+
async #redial(id, ctx) {
|
|
346
|
+
const dial = this.#dials.get(id);
|
|
347
|
+
if (dial === undefined)
|
|
348
|
+
throw new HostError("not_found", `no agentrun-dial was started in the sandbox ${id}, so it is not started again`);
|
|
349
|
+
const session = `${DIAL_SESSION}-${dial.starts + 1}`;
|
|
350
|
+
const { commandId } = await this.#runAsync(await this.#toolbox(id, ctx.signal), session, dialLaunch({ rootOnly: this.facts.rootOnly, attach: dial.attach }), ctx.timeoutMs, ctx.signal);
|
|
351
|
+
this.#dials.set(id, { ...dial, session, command: commandId, starts: dial.starts + 1 });
|
|
352
|
+
}
|
|
314
353
|
/** GET /sandbox/{id}; one Daytona answers 404 for, or reads destroyed, is none. */
|
|
315
354
|
async get(id, ctx) {
|
|
316
355
|
const found = orThrow(await sandboxOf(this.#rest, id, ctx.signal));
|
|
@@ -380,16 +419,7 @@ class DaytonaHost {
|
|
|
380
419
|
const asked = orThrow(await this.#rest.json("GET", sandboxUrl(this.#rest, id, "/toolbox-proxy-url"), { retry: true }, signal));
|
|
381
420
|
proxy = asked?.url;
|
|
382
421
|
}
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
url = new URL(proxy ?? "");
|
|
386
|
-
}
|
|
387
|
-
catch {
|
|
388
|
-
throw new Error(`Daytona gave no toolbox URL for ${id}`);
|
|
389
|
-
}
|
|
390
|
-
if (url.protocol !== "https:")
|
|
391
|
-
throw new Error(`the toolbox URL Daytona gave is not https (${url.protocol}), so the key is not sent to it`);
|
|
392
|
-
const toolbox = `${url.href.replace(/\/+$/, "")}/${encodeURIComponent(id)}`;
|
|
422
|
+
const toolbox = `${httpsBase(proxy ?? "", `the toolbox URL Daytona gave for ${id}`)}/${encodeURIComponent(id)}`;
|
|
393
423
|
this.#toolboxes.set(id, toolbox);
|
|
394
424
|
return toolbox;
|
|
395
425
|
}
|
|
@@ -415,6 +445,16 @@ class DaytonaHost {
|
|
|
415
445
|
if (!older.ok)
|
|
416
446
|
throw new HostError(older.error.code, `${missing}, then ${older.error.message}`);
|
|
417
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* The bytes of the file at `path` in the sandbox, whole: the toolbox's GET files/download (the open daemon's routes,
|
|
450
|
+
* daytonaio/daytona@b5a5d9e7 apps/daemon/pkg/toolbox/server.go), as root. Far faster than exec's stdout, which is a
|
|
451
|
+
* session command's log read over a WebSocket (about 0.3 MB/s, the sandbox bench, 11-25). Connect exec alone.
|
|
452
|
+
*/
|
|
453
|
+
async #download(id, path, ctx) {
|
|
454
|
+
const toolbox = await this.#toolbox(id, ctx.signal);
|
|
455
|
+
const got = orThrow(await this.#rest.call("GET", `${toolbox}/files/download?${new URLSearchParams({ path })}`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
|
|
456
|
+
return got.bytes;
|
|
457
|
+
}
|
|
418
458
|
/**
|
|
419
459
|
* A session command of its own (#commands), on framedExec: argv as one shell line, run async with no input echo, as
|
|
420
460
|
* the toolbox's user (root, or one with passwordless sudo, which the adapter's scripts use). Connect exec alone.
|