@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40
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 +126 -83
- package/box/Dockerfile +5 -54
- package/box/README.md +9 -3
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +87 -0
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +12 -10
- package/dist/agent37.d.ts +17 -4
- package/dist/agent37.js +98 -17
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/agent37.d.ts +9 -4
- package/dist/conformance/agent37.js +23 -11
- package/dist/conformance/browserbase.js +3 -3
- package/dist/conformance/cases/apps.d.ts +1 -1
- package/dist/conformance/cases/apps.js +1 -1
- package/dist/conformance/cases/isolation.d.ts +18 -3
- package/dist/conformance/cases/isolation.js +73 -6
- package/dist/conformance/cases/lifetime.js +30 -0
- package/dist/conformance/cases/mount.js +4 -2
- package/dist/conformance/cases/provider.js +88 -1
- package/dist/conformance/cli.js +29 -9
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +44 -7
- package/dist/conformance/exec-stream.js +347 -88
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/report.js +3 -0
- package/dist/conformance/runner.js +127 -9
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +0 -5
- package/dist/daytona.js +19 -28
- package/dist/descriptor.d.ts +5 -3
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +1 -1
- package/dist/descriptors/daytona.js +5 -2
- package/dist/descriptors/docker.d.ts +13 -1
- package/dist/descriptors/docker.js +3 -1
- package/dist/descriptors/e2b.d.ts +2 -9
- package/dist/descriptors/e2b.js +8 -8
- package/dist/descriptors/index.d.ts +21 -19
- package/dist/descriptors/index.js +1 -3
- package/dist/descriptors/modal.d.ts +2 -6
- package/dist/descriptors/modal.js +8 -6
- package/dist/descriptors/orgo.js +2 -1
- package/dist/docker/egress-main.js +23 -15
- package/dist/docker/egress.d.ts +6 -4
- package/dist/docker/egress.js +24 -16
- package/dist/docker/inspect.d.ts +2 -2
- package/dist/docker/inspect.js +5 -5
- package/dist/docker.d.ts +6 -5
- package/dist/docker.js +12 -11
- package/dist/e2b.d.ts +12 -2
- package/dist/e2b.js +42 -19
- package/dist/host.d.ts +113 -59
- package/dist/host.js +5 -0
- package/dist/hosted/framed-exec.d.ts +49 -0
- package/dist/hosted/framed-exec.js +185 -0
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +13 -5
- package/dist/hosted/process.js +35 -12
- package/dist/hosted/provider.d.ts +16 -9
- package/dist/hosted/provider.js +475 -170
- package/dist/hosted/rest.d.ts +20 -2
- package/dist/hosted/rest.js +24 -10
- package/dist/hosted/scripts.d.ts +27 -7
- package/dist/hosted/scripts.js +77 -18
- package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
- package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
- package/dist/hosted/values.d.ts +21 -0
- package/dist/hosted/values.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/modal.d.ts +8 -2
- package/dist/modal.js +21 -15
- package/dist/mount-archil.d.ts +5 -4
- package/dist/mount-archil.js +5 -6
- package/dist/orgo.js +6 -4
- package/dist/providers.d.ts +4 -1
- package/dist/surface/api.d.ts +0 -9
- package/dist/surface/core.d.ts +7 -2
- package/dist/surface/core.js +12 -4
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +9 -3
- package/package.json +1 -1
- package/box/build-agent37.mjs +0 -158
package/box/build-agent37.mjs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
// Build the box image (this folder's Dockerfile, its desktop included) as a template of an Agent37 workspace, through
|
|
2
|
-
// Agent37's cloud build, with the workspace's key in AGENT37_API_KEY, and print the template's name: an Agent37 desktop
|
|
3
|
-
// starts from it (src/descriptors/agent37.ts AGENT37_BOX_TEMPLATE), and so can an Archil computer.
|
|
4
|
-
//
|
|
5
|
-
// Agent37 keeps a template's revisions under one name (docs: agents-api/templates), so the name is fixed, agentrun-box,
|
|
6
|
-
// and the recipe's hash (recipe.mjs: the Dockerfile and the files it copies) goes in the template's description: a
|
|
7
|
-
// workspace whose template already names this hash is built nothing, and a changed recipe publishes a new revision,
|
|
8
|
-
// which every instance made after it starts from. Builds are free, at most three at once per workspace and 45 minutes
|
|
9
|
-
// each. The calls, in order (docs: templates, "Build an image in the cloud"):
|
|
10
|
-
//
|
|
11
|
-
// GET /v1/templates/agentrun-box its description, or 404
|
|
12
|
-
// POST /v1/template-builds { name, size_bytes, description } -> { id, upload_url }
|
|
13
|
-
// PUT <upload_url> the gzipped context, Dockerfile at its root, no Agent37 key
|
|
14
|
-
// POST /v1/template-builds/{id}/start
|
|
15
|
-
// GET /v1/template-builds/{id}/logs?offset=N until status succeeded or failed (a poll registers the template)
|
|
16
|
-
//
|
|
17
|
-
// AGENT37_API_KEY=... node packages/computer/box/build-agent37.mjs
|
|
18
|
-
import { readFileSync } from "node:fs";
|
|
19
|
-
import { dirname, join } from "node:path";
|
|
20
|
-
import { fileURLToPath } from "node:url";
|
|
21
|
-
import { gzipSync } from "node:zlib";
|
|
22
|
-
import { RECIPE, recipeHash } from "./recipe.mjs";
|
|
23
|
-
|
|
24
|
-
/** The template's name in every workspace: AGENT37_BOX_TEMPLATE. */
|
|
25
|
-
export const NAME = "agentrun-box";
|
|
26
|
-
export const API_URL = "https://api.agent37.com";
|
|
27
|
-
/** Every file the image is made of: the Dockerfile (its desktop included) and what it copies (recipe.mjs). */
|
|
28
|
-
export { RECIPE };
|
|
29
|
-
/** How often a build's log is read, and the longest a build is waited for: Agent37's 45 minutes, and some. */
|
|
30
|
-
const POLL_MS = 5_000;
|
|
31
|
-
const BUILD_MS = 50 * 60_000;
|
|
32
|
-
|
|
33
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
34
|
-
|
|
35
|
-
/** The recipe's files, read from dir, and its 12-hex hash: recipe.mjs's, the one every build and the published image carry. */
|
|
36
|
-
export function recipeOf(dir = here) {
|
|
37
|
-
return { hash: recipeHash(dir), files: Object.fromEntries(RECIPE.map((name) => [name, readFileSync(join(dir, name))])) };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** The template's description: the recipe's hash is how a later build knows this one is current. */
|
|
41
|
-
export const descriptionOf = (hash) => `AgentRun's box image (Archil client and helper, tool user, Xvfb, xfwm4 and apps), recipe ${hash}`;
|
|
42
|
-
|
|
43
|
-
/** One ustar header block: a file at the archive's root, owned by root. */
|
|
44
|
-
function header(name, mode, size) {
|
|
45
|
-
const block = Buffer.alloc(512);
|
|
46
|
-
const octal = (value, width) => `${value.toString(8).padStart(width - 1, "0")}\0`;
|
|
47
|
-
block.write(name, 0, 100);
|
|
48
|
-
block.write(octal(mode, 8), 100);
|
|
49
|
-
block.write(octal(0, 8), 108);
|
|
50
|
-
block.write(octal(0, 8), 116);
|
|
51
|
-
block.write(octal(size, 12), 124);
|
|
52
|
-
block.write(octal(0, 12), 136);
|
|
53
|
-
block.write(" ", 148);
|
|
54
|
-
block.write("0", 156);
|
|
55
|
-
block.write("ustar\0", 257);
|
|
56
|
-
block.write("00", 263);
|
|
57
|
-
let sum = 0;
|
|
58
|
-
for (const byte of block) sum += byte;
|
|
59
|
-
block.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148);
|
|
60
|
-
return block;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** The build's context: a gzipped tar of the Dockerfile (0644) and the helper (0755), at its root. */
|
|
64
|
-
export function contextOf({ files }) {
|
|
65
|
-
const parts = [];
|
|
66
|
-
for (const [name, mode] of [
|
|
67
|
-
["Dockerfile", 0o644],
|
|
68
|
-
["agentrun-archil", 0o755],
|
|
69
|
-
]) {
|
|
70
|
-
const body = files[name];
|
|
71
|
-
parts.push(header(name, mode, body.length), body, Buffer.alloc((512 - (body.length % 512)) % 512));
|
|
72
|
-
}
|
|
73
|
-
parts.push(Buffer.alloc(1024));
|
|
74
|
-
return gzipSync(Buffer.concat(parts));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** An answer that is not a success, in Agent37's words (its envelope's code and message), never with the key. */
|
|
78
|
-
async function failure(what, response) {
|
|
79
|
-
const text = await response.text().catch(() => "");
|
|
80
|
-
let error;
|
|
81
|
-
try {
|
|
82
|
-
error = JSON.parse(text)?.error;
|
|
83
|
-
} catch {
|
|
84
|
-
// Not JSON: its status alone.
|
|
85
|
-
}
|
|
86
|
-
const code = typeof error === "string" ? error : error?.code;
|
|
87
|
-
const message = typeof error === "object" ? error?.message : undefined;
|
|
88
|
-
return new Error(`${what} answered ${response.status}${code ? ` ${code}` : ""}${message ? `: ${message}` : ""}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Builds the recipe as the template NAME unless the workspace's template already names its hash, and answers the
|
|
93
|
-
* template's name, revision and digest (revision and digest undefined when nothing was built). log gets the build's
|
|
94
|
-
* log as it comes.
|
|
95
|
-
*/
|
|
96
|
-
export async function build({ apiKey, fetch = globalThis.fetch, apiUrl = API_URL, dir = here, log = (text) => process.stderr.write(text), pollMs = POLL_MS, buildMs = BUILD_MS }) {
|
|
97
|
-
if (typeof apiKey !== "string" || apiKey === "") throw new Error("set AGENT37_API_KEY to the workspace's Agent37 API key, for this one command");
|
|
98
|
-
const auth = { Authorization: `Bearer ${apiKey}`, Accept: "application/json" };
|
|
99
|
-
const rest = async (method, path, body) => {
|
|
100
|
-
const response = await fetch(`${apiUrl}${path}`, {
|
|
101
|
-
method,
|
|
102
|
-
headers: { ...auth, ...(body === undefined ? {} : { "Content-Type": "application/json" }) },
|
|
103
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
104
|
-
signal: AbortSignal.timeout(60_000),
|
|
105
|
-
});
|
|
106
|
-
if (!response.ok) throw await failure(`${method} ${path}`, response);
|
|
107
|
-
return response.json();
|
|
108
|
-
};
|
|
109
|
-
const recipe = recipeOf(dir);
|
|
110
|
-
const description = descriptionOf(recipe.hash);
|
|
111
|
-
log(`build-agent37: template ${NAME}, recipe ${recipe.hash}\n`);
|
|
112
|
-
|
|
113
|
-
const current = await fetch(`${apiUrl}/v1/templates/${NAME}`, { headers: auth, signal: AbortSignal.timeout(60_000) });
|
|
114
|
-
if (current.ok) {
|
|
115
|
-
const template = await current.json();
|
|
116
|
-
if (template?.description === description) {
|
|
117
|
-
log(`build-agent37: ${NAME} revision ${template.revision} is this recipe already; nothing built\n`);
|
|
118
|
-
return { name: NAME, revision: template.revision, digest: template.image_digest };
|
|
119
|
-
}
|
|
120
|
-
} else if (current.status !== 404) {
|
|
121
|
-
throw await failure(`GET /v1/templates/${NAME}`, current);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const context = contextOf(recipe);
|
|
125
|
-
const made = await rest("POST", "/v1/template-builds", { name: NAME, size_bytes: context.length, description });
|
|
126
|
-
if (typeof made?.id !== "string" || typeof made?.upload_url !== "string") throw new Error("POST /v1/template-builds answered no id or upload_url");
|
|
127
|
-
log(`build-agent37: build ${made.id}, context ${context.length} bytes\n`);
|
|
128
|
-
// The presigned URL takes no Agent37 key, and fetch sends no Expect header.
|
|
129
|
-
const uploaded = await fetch(made.upload_url, { method: "PUT", body: context, headers: { "Content-Type": "application/gzip" }, signal: AbortSignal.timeout(300_000) });
|
|
130
|
-
if (!uploaded.ok) throw await failure("the context's upload", uploaded);
|
|
131
|
-
await rest("POST", `/v1/template-builds/${made.id}/start`, {});
|
|
132
|
-
|
|
133
|
-
const end = Date.now() + buildMs;
|
|
134
|
-
let offset = 0;
|
|
135
|
-
for (;;) {
|
|
136
|
-
const read = await rest("GET", `/v1/template-builds/${made.id}/logs?offset=${offset}`);
|
|
137
|
-
if (typeof read?.data === "string" && read.data !== "") log(read.data);
|
|
138
|
-
if (Number.isSafeInteger(read?.offset)) offset = read.offset;
|
|
139
|
-
if (read?.status === "succeeded") {
|
|
140
|
-
const { name = NAME, revision, image_digest: digest } = read.template ?? {};
|
|
141
|
-
log(`\nbuild-agent37: ${name} revision ${revision}, ${digest}\n`);
|
|
142
|
-
return { name, revision, digest };
|
|
143
|
-
}
|
|
144
|
-
if (read?.status === "failed") throw new Error(`build ${made.id} failed: ${read.error?.code ?? "no code"}${read.error?.message ? `: ${read.error.message}` : ""}`);
|
|
145
|
-
if (Date.now() > end) throw new Error(`build ${made.id} was not done within ${buildMs / 60_000} minutes (status ${read?.status}); Agent37 ends a build at 45`);
|
|
146
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (import.meta.main) {
|
|
151
|
-
try {
|
|
152
|
-
const { name } = await build({ apiKey: process.env.AGENT37_API_KEY });
|
|
153
|
-
console.log(`template=${name}`);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(`build-agent37: ${error.message}`);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
}
|