@computesdk/pethost 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +81 -2
- package/dist/index.d.mts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +541 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +515 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { defineProvider } from "@computesdk/provider";
|
|
3
|
+
|
|
4
|
+
// src/client.ts
|
|
5
|
+
import { Sandboxes, SandboxesError } from "pethost/sandboxes";
|
|
6
|
+
var clients = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function client(config) {
|
|
8
|
+
const cached = clients.get(config);
|
|
9
|
+
if (cached) return cached;
|
|
10
|
+
const token = config.token || process.env.PETHOST_TOKEN;
|
|
11
|
+
if (!token) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"Missing Pethost API token. Pass pethost({ token }) or set PETHOST_TOKEN.\nCreate one in your workspace of sandboxes at https://console.pethost.dev: press Connect an agent, open TypeScript and press Create an API token."
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const made = new Sandboxes({
|
|
17
|
+
token,
|
|
18
|
+
baseUrl: config.baseUrl || process.env.PETHOST_URL || void 0,
|
|
19
|
+
workspace: config.workspace || process.env.PETHOST_WORKSPACE || void 0
|
|
20
|
+
});
|
|
21
|
+
clients.set(config, made);
|
|
22
|
+
return made;
|
|
23
|
+
}
|
|
24
|
+
function isCode(error, ...codes) {
|
|
25
|
+
return error instanceof SandboxesError && codes.includes(error.code);
|
|
26
|
+
}
|
|
27
|
+
function seconds(ms, what) {
|
|
28
|
+
if (ms === void 0 || ms === 0) return void 0;
|
|
29
|
+
if (!Number.isFinite(ms) || ms < 0) throw new Error(`Pethost ${what} must be a non-negative number of milliseconds; 0 means none.`);
|
|
30
|
+
return Math.ceil(ms / 1e3);
|
|
31
|
+
}
|
|
32
|
+
function sleep(ms) {
|
|
33
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/commands.ts
|
|
37
|
+
import { escapeShellArg, TIMEOUT_EXIT_CODE } from "@computesdk/provider";
|
|
38
|
+
var FIRST_WAIT_SECONDS = 10;
|
|
39
|
+
function commandText(command, env) {
|
|
40
|
+
const entries = Object.entries(env ?? {});
|
|
41
|
+
if (entries.length === 0) return command;
|
|
42
|
+
const exports = entries.map(([name, value]) => {
|
|
43
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid environment variable name: ${name}`);
|
|
44
|
+
return `export ${name}="${escapeShellArg(value)}"`;
|
|
45
|
+
});
|
|
46
|
+
return `${exports.join("\n")}
|
|
47
|
+
${command}`;
|
|
48
|
+
}
|
|
49
|
+
function request(sandbox, command, options) {
|
|
50
|
+
return {
|
|
51
|
+
sandboxId: sandbox.sandboxId,
|
|
52
|
+
command: commandText(command, options?.env),
|
|
53
|
+
cwd: options?.cwd,
|
|
54
|
+
timeoutSeconds: seconds(options?.timeout, "command timeout")
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function exitCode(command) {
|
|
58
|
+
if (command.state === "TIMED_OUT") return TIMEOUT_EXIT_CODE;
|
|
59
|
+
if (command.state === "LOST") {
|
|
60
|
+
throw new Error(`Pethost command ${command.commandId} was lost: its sandbox lost its memory while it ran, so its end is not known.`);
|
|
61
|
+
}
|
|
62
|
+
return command.exitCode ?? 1;
|
|
63
|
+
}
|
|
64
|
+
function joinOutput(firstText, firstEnd, streamed, total) {
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
const streamStart = Number(total) - streamed.length;
|
|
67
|
+
const end = Number(firstEnd);
|
|
68
|
+
if (streamStart <= end - Buffer.byteLength(firstText)) return decoder.decode(streamed);
|
|
69
|
+
if (streamStart <= end) return firstText + decoder.decode(streamed.subarray(end - streamStart));
|
|
70
|
+
return firstText + decoder.decode(streamed);
|
|
71
|
+
}
|
|
72
|
+
function concat(chunks) {
|
|
73
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
74
|
+
}
|
|
75
|
+
async function stopQuietly(sandbox, commandId) {
|
|
76
|
+
try {
|
|
77
|
+
await sandbox.client.stopCommand({ sandboxId: sandbox.sandboxId, commandId });
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (!isCode(error, "NOT_FOUND")) throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function follow(sandbox, commandId, onFrame) {
|
|
83
|
+
try {
|
|
84
|
+
for await (const frame of sandbox.client.watchCommand({ sandboxId: sandbox.sandboxId, commandId })) {
|
|
85
|
+
if (frame.output === "stdout") onFrame("stdout", frame.stdout);
|
|
86
|
+
else if (frame.output === "stderr") onFrame("stderr", frame.stderr);
|
|
87
|
+
else if (frame.output === "ended") return frame.ended;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Pethost command ${commandId}: its output stream ended before the command did.`);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
await stopQuietly(sandbox, commandId).catch(() => {
|
|
92
|
+
});
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function run(sandbox, command, options) {
|
|
97
|
+
const start = Date.now();
|
|
98
|
+
const base = request(sandbox, command, options);
|
|
99
|
+
if (options?.background) {
|
|
100
|
+
await sandbox.client.runCommand({ ...base, waitSeconds: 0 });
|
|
101
|
+
return { stdout: "", stderr: "", exitCode: 0, durationMs: Date.now() - start };
|
|
102
|
+
}
|
|
103
|
+
const first = await sandbox.client.runCommand({ ...base, waitSeconds: FIRST_WAIT_SECONDS });
|
|
104
|
+
if (first.state !== "RUNNING" && !first.outputTruncated) {
|
|
105
|
+
return { stdout: first.stdout, stderr: first.stderr, exitCode: exitCode(first), durationMs: Date.now() - start };
|
|
106
|
+
}
|
|
107
|
+
const chunks = { stdout: [], stderr: [] };
|
|
108
|
+
const ended = await follow(sandbox, first.commandId, (stream2, bytes) => chunks[stream2].push(bytes));
|
|
109
|
+
return {
|
|
110
|
+
stdout: joinOutput(first.stdout, first.stdoutBytes, concat(chunks.stdout), ended.stdoutBytes),
|
|
111
|
+
stderr: joinOutput(first.stderr, first.stderrBytes, concat(chunks.stderr), ended.stderrBytes),
|
|
112
|
+
exitCode: exitCode(ended),
|
|
113
|
+
durationMs: Date.now() - start
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function stream(sandbox, command, options) {
|
|
117
|
+
if (options.background) return run(sandbox, command, options);
|
|
118
|
+
const start = Date.now();
|
|
119
|
+
const started = await sandbox.client.runCommand({ ...request(sandbox, command, options), waitSeconds: 0 });
|
|
120
|
+
const decoders = { stdout: new TextDecoder(), stderr: new TextDecoder() };
|
|
121
|
+
const text = { stdout: "", stderr: "" };
|
|
122
|
+
const emit = (name, chunk) => {
|
|
123
|
+
if (!chunk) return;
|
|
124
|
+
text[name] += chunk;
|
|
125
|
+
(name === "stdout" ? options.onStdout : options.onStderr)?.(chunk);
|
|
126
|
+
};
|
|
127
|
+
const ended = await follow(sandbox, started.commandId, (name, bytes) => emit(name, decoders[name].decode(bytes, { stream: true })));
|
|
128
|
+
emit("stdout", decoders.stdout.decode());
|
|
129
|
+
emit("stderr", decoders.stderr.decode());
|
|
130
|
+
return { stdout: text.stdout, stderr: text.stderr, exitCode: exitCode(ended), durationMs: Date.now() - start };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/files.ts
|
|
134
|
+
import { posix } from "path";
|
|
135
|
+
var MIB = 1024 * 1024;
|
|
136
|
+
var READ_FIRST_BYTES = 64 * 1024;
|
|
137
|
+
var READ_INLINE_BYTES = MIB;
|
|
138
|
+
var WRITE_INLINE_BYTES = 8 * MIB;
|
|
139
|
+
async function change(sandbox, verb, path, file) {
|
|
140
|
+
const answer = await sandbox.client.writeFiles({ sandboxId: sandbox.sandboxId, changes: [{ path, ...file }] });
|
|
141
|
+
if (answer.doneCount < 1) throw new Error(`Pethost could not ${verb} ${path}: ${answer.failureMessage || "unknown failure"}`);
|
|
142
|
+
}
|
|
143
|
+
async function transfer(url, init, what) {
|
|
144
|
+
const response = await fetch(url, init);
|
|
145
|
+
if (!response.ok) throw new Error(`Pethost ${what} failed (HTTP ${response.status}).`);
|
|
146
|
+
return response;
|
|
147
|
+
}
|
|
148
|
+
function read(sandbox, path, length) {
|
|
149
|
+
return sandbox.client.readFile({ sandboxId: sandbox.sandboxId, path, lengthBytes: BigInt(length) });
|
|
150
|
+
}
|
|
151
|
+
function textOf(file) {
|
|
152
|
+
if (file.content === "text") return file.text;
|
|
153
|
+
if (file.content === "data") return new TextDecoder().decode(file.data);
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
async function download(sandbox, path) {
|
|
157
|
+
const link = await sandbox.client.createLink({ sandboxId: sandbox.sandboxId, downloadPath: path });
|
|
158
|
+
const response = await transfer(link.url, {}, `download of ${path}`);
|
|
159
|
+
return new TextDecoder().decode(await response.arrayBuffer());
|
|
160
|
+
}
|
|
161
|
+
async function readFile(sandbox, path) {
|
|
162
|
+
const first = await read(sandbox, path, READ_FIRST_BYTES);
|
|
163
|
+
const size = Number(first.sizeBytes);
|
|
164
|
+
if (size <= READ_FIRST_BYTES) return textOf(first);
|
|
165
|
+
if (size <= READ_INLINE_BYTES) return textOf(await read(sandbox, path, size));
|
|
166
|
+
return download(sandbox, path);
|
|
167
|
+
}
|
|
168
|
+
async function writeFile(sandbox, path, content) {
|
|
169
|
+
if (Buffer.byteLength(content) <= WRITE_INLINE_BYTES) {
|
|
170
|
+
await change(sandbox, "write", path, { text: content });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const link = await sandbox.client.createLink({ sandboxId: sandbox.sandboxId, uploadPath: path });
|
|
174
|
+
const response = await transfer(link.url, { method: "PUT", body: Buffer.from(content) }, `upload of ${path}`);
|
|
175
|
+
await response.body?.cancel();
|
|
176
|
+
}
|
|
177
|
+
async function mkdir(sandbox, path) {
|
|
178
|
+
await change(sandbox, "make the directory", path, { makeDirectory: {} });
|
|
179
|
+
}
|
|
180
|
+
async function remove(sandbox, path) {
|
|
181
|
+
await change(sandbox, "delete", path, { delete: {} });
|
|
182
|
+
}
|
|
183
|
+
async function readdir(sandbox, path) {
|
|
184
|
+
const entries = [];
|
|
185
|
+
let pageToken;
|
|
186
|
+
do {
|
|
187
|
+
const page = await sandbox.client.listFiles({ sandboxId: sandbox.sandboxId, path, pageToken });
|
|
188
|
+
for (const file of page.files) {
|
|
189
|
+
entries.push({
|
|
190
|
+
name: posix.basename(file.path),
|
|
191
|
+
type: file.kind === "DIRECTORY" ? "directory" : "file",
|
|
192
|
+
size: Number(file.sizeBytes),
|
|
193
|
+
modified: file.modifyTime
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
pageToken = page.nextPageToken || void 0;
|
|
197
|
+
} while (pageToken);
|
|
198
|
+
return entries;
|
|
199
|
+
}
|
|
200
|
+
async function exists(sandbox, path) {
|
|
201
|
+
try {
|
|
202
|
+
await sandbox.client.listFiles({ sandboxId: sandbox.sandboxId, path });
|
|
203
|
+
return true;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (isCode(error, "NOT_FOUND")) return false;
|
|
206
|
+
if (isCode(error, "PERMISSION_DENIED")) return true;
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/templates.ts
|
|
212
|
+
var snapshotCapabilities = {
|
|
213
|
+
scope: "rootfs",
|
|
214
|
+
memory: false,
|
|
215
|
+
destroysSource: false,
|
|
216
|
+
source: "kept",
|
|
217
|
+
// A new version is SAVING until it is uploaded; create starts only from a READY one.
|
|
218
|
+
readiness: "eventual"
|
|
219
|
+
};
|
|
220
|
+
function snapshotInfo(template) {
|
|
221
|
+
return {
|
|
222
|
+
id: `${template.name}@${template.version}`,
|
|
223
|
+
provider: "pethost",
|
|
224
|
+
createdAt: template.createTime ?? /* @__PURE__ */ new Date(0),
|
|
225
|
+
metadata: {
|
|
226
|
+
name: template.name,
|
|
227
|
+
version: template.version,
|
|
228
|
+
state: String(template.state ?? ""),
|
|
229
|
+
failureMessage: template.failureMessage,
|
|
230
|
+
sizeBytes: Number(template.sizeBytes),
|
|
231
|
+
base: template.base
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function templateInfo(template) {
|
|
236
|
+
const info = snapshotInfo(template);
|
|
237
|
+
return { ...info, templateId: info.id, builtIn: template.builtIn, description: template.description };
|
|
238
|
+
}
|
|
239
|
+
function nameOf(id) {
|
|
240
|
+
return id.split("@")[0];
|
|
241
|
+
}
|
|
242
|
+
function save(api, sandboxId, name, description) {
|
|
243
|
+
return api.createTemplate({ name, sandboxId, description });
|
|
244
|
+
}
|
|
245
|
+
async function listAll(api, limit) {
|
|
246
|
+
const templates = [];
|
|
247
|
+
let pageToken;
|
|
248
|
+
do {
|
|
249
|
+
const page = await api.listTemplates({ pageSize: 500, pageToken });
|
|
250
|
+
templates.push(...page.templates);
|
|
251
|
+
pageToken = page.nextPageToken || void 0;
|
|
252
|
+
} while (pageToken && (limit === void 0 || templates.length < limit));
|
|
253
|
+
return limit === void 0 ? templates : templates.slice(0, limit);
|
|
254
|
+
}
|
|
255
|
+
async function deleteSnapshot(api, id) {
|
|
256
|
+
const name = nameOf(id);
|
|
257
|
+
const { templates } = await api.listTemplates({ name, pageSize: 2 });
|
|
258
|
+
if (templates.length > 1) {
|
|
259
|
+
throw new Error(`Pethost deletes a template's name with all its versions, and ${name} has more than one, so ${id} is not deleted alone. template.delete('${name}') deletes them all.`);
|
|
260
|
+
}
|
|
261
|
+
const [only] = templates;
|
|
262
|
+
if (!only || id.includes("@") && `${only.name}@${only.version}` !== id) return;
|
|
263
|
+
await deleteByName(api, id);
|
|
264
|
+
}
|
|
265
|
+
async function deleteByName(api, id) {
|
|
266
|
+
try {
|
|
267
|
+
await api.deleteTemplate({ name: nameOf(id) });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (!isCode(error, "NOT_FOUND")) throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function waitUntilReady(config, id, options) {
|
|
273
|
+
const api = client(config);
|
|
274
|
+
const deadline = Date.now() + (options?.timeoutMs ?? 6e5);
|
|
275
|
+
for (; ; ) {
|
|
276
|
+
const template = await api.getTemplate({ template: id });
|
|
277
|
+
if (template.state === "READY") return;
|
|
278
|
+
if (template.state === "FAILED") throw new Error(`Pethost template ${id} failed: ${template.failureMessage}`);
|
|
279
|
+
if (Date.now() >= deadline) throw new Error(`Timed out waiting for Pethost template ${id} to be READY.`);
|
|
280
|
+
await sleep(Math.min(500, Math.max(0, deadline - Date.now())));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
var snapshotMethods = {
|
|
284
|
+
create: async (config, sandboxId, options) => {
|
|
285
|
+
const name = options?.name ?? `snapshot-${sandboxId}-${Date.now().toString(36)}`;
|
|
286
|
+
return snapshotInfo(await save(client(config), sandboxId, name));
|
|
287
|
+
},
|
|
288
|
+
list: async (config, options) => {
|
|
289
|
+
const source = options?.instanceId ?? options?.sandboxId;
|
|
290
|
+
const prefix = source === void 0 ? void 0 : `snapshot-${source}-`;
|
|
291
|
+
const templates = (await listAll(client(config))).filter((template) => !template.builtIn && (!prefix || template.name.startsWith(prefix)));
|
|
292
|
+
return templates.slice(0, options?.limit ?? templates.length).map(snapshotInfo);
|
|
293
|
+
},
|
|
294
|
+
delete: (config, id) => deleteSnapshot(client(config), id),
|
|
295
|
+
capabilities: snapshotCapabilities,
|
|
296
|
+
waitUntilReady
|
|
297
|
+
};
|
|
298
|
+
var templateMethods = {
|
|
299
|
+
create: async (config, options) => {
|
|
300
|
+
const { sandboxId, name, description } = options;
|
|
301
|
+
if (!sandboxId) throw new Error("Pethost saves a template from a sandbox: pass sandboxId.");
|
|
302
|
+
return templateInfo(await save(client(config), sandboxId, name, description));
|
|
303
|
+
},
|
|
304
|
+
list: async (config, options) => (await listAll(client(config), options?.limit)).map(templateInfo),
|
|
305
|
+
/** Deletes every version of the template's name. */
|
|
306
|
+
delete: (config, id) => deleteByName(client(config), id)
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/index.ts
|
|
310
|
+
var SIZES = {
|
|
311
|
+
md: { size: "SMALL", vcpus: 2, memoryMiB: 4096, diskMiB: 10240 },
|
|
312
|
+
lg: { size: "DEFAULT", vcpus: 4, memoryMiB: 8192, diskMiB: 20480 },
|
|
313
|
+
xl: { size: "LARGE", vcpus: 8, memoryMiB: 16384, diskMiB: 40960 },
|
|
314
|
+
"2xl": { size: "XLARGE", vcpus: 16, memoryMiB: 32768, diskMiB: 81920 }
|
|
315
|
+
};
|
|
316
|
+
var UNSUPPORTED_OPTIONS = [
|
|
317
|
+
"cpu",
|
|
318
|
+
"cpuLimit",
|
|
319
|
+
"cpus",
|
|
320
|
+
"vcpus",
|
|
321
|
+
"memory",
|
|
322
|
+
"memoryMiB",
|
|
323
|
+
"memMiB",
|
|
324
|
+
"memoryMb",
|
|
325
|
+
"diskMiB",
|
|
326
|
+
"diskMb",
|
|
327
|
+
"resources",
|
|
328
|
+
"launch_parameters",
|
|
329
|
+
"deploymentPlan",
|
|
330
|
+
"vmTier",
|
|
331
|
+
"gpu",
|
|
332
|
+
"region"
|
|
333
|
+
];
|
|
334
|
+
function wrap(api, record) {
|
|
335
|
+
return { instance: { client: api, sandboxId: record.sandboxId, record }, instanceId: record.sandboxId };
|
|
336
|
+
}
|
|
337
|
+
function labels(options) {
|
|
338
|
+
if (options?.labels !== void 0) return options.labels;
|
|
339
|
+
if (options?.metadata === void 0) return void 0;
|
|
340
|
+
return Object.entries(options.metadata).map(([key, value]) => ({ key, value: String(value) }));
|
|
341
|
+
}
|
|
342
|
+
function environment(native, env) {
|
|
343
|
+
const replaced = (name) => name !== void 0 && Object.prototype.hasOwnProperty.call(env, name);
|
|
344
|
+
const variables = (native.environment?.variables ?? []).filter((variable) => !replaced(variable.name));
|
|
345
|
+
return { variables: [...variables, ...Object.entries(env).map(([name, value]) => ({ name, value }))] };
|
|
346
|
+
}
|
|
347
|
+
function settings(config, options) {
|
|
348
|
+
const native = { ...config.settings, ...options?.settings };
|
|
349
|
+
const size = options?.size ?? config.size ?? native.size;
|
|
350
|
+
const idle = seconds(options?.timeout ?? config.timeout, "timeout");
|
|
351
|
+
const env = options?.envs ?? options?.env;
|
|
352
|
+
return {
|
|
353
|
+
...native,
|
|
354
|
+
...size === void 0 ? {} : { size },
|
|
355
|
+
...idle === void 0 ? {} : { lifecycle: { ...native.lifecycle, deleteAfterIdleSeconds: idle } },
|
|
356
|
+
...env === void 0 ? {} : { environment: environment(native, env) }
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
async function createRequest(config, options) {
|
|
360
|
+
for (const key of UNSUPPORTED_OPTIONS) {
|
|
361
|
+
if (options?.[key] !== void 0) throw new Error(`Pethost does not take ${key}: sandboxes come in four sizes, chosen with size (SMALL, DEFAULT, LARGE, XLARGE) or sizeClass.`);
|
|
362
|
+
}
|
|
363
|
+
if (options?.image !== void 0) throw new Error("Pethost starts sandboxes from templates, not images: pass templateId.");
|
|
364
|
+
if (options?.templateId && options?.snapshotId) throw new Error("Pass templateId or snapshotId, not both.");
|
|
365
|
+
const template = options?.snapshotId ?? options?.templateId ?? config.template;
|
|
366
|
+
return { template, name: options?.name, labels: labels(options), settings: settings(config, options) };
|
|
367
|
+
}
|
|
368
|
+
function status(record) {
|
|
369
|
+
if (record.state === "RUNNING") return "running";
|
|
370
|
+
if (record.state === "STOPPED" && record.stateReason === "CRASH") return "error";
|
|
371
|
+
return "stopped";
|
|
372
|
+
}
|
|
373
|
+
async function getPethostPortLink(sandbox, options) {
|
|
374
|
+
return sandbox.client.createLink({ sandboxId: sandbox.sandboxId, port: options.port, ttlSeconds: options.ttlSeconds });
|
|
375
|
+
}
|
|
376
|
+
async function publicUrl(sandbox, port) {
|
|
377
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
378
|
+
const record = await sandbox.client.getSandbox({ sandboxId: sandbox.sandboxId });
|
|
379
|
+
const open = record.settings?.ingress?.publicPorts ?? [];
|
|
380
|
+
const known = open.find((p) => p.port === port);
|
|
381
|
+
if (known) return known.url;
|
|
382
|
+
try {
|
|
383
|
+
const updated = await sandbox.client.updateSandbox({
|
|
384
|
+
sandboxId: sandbox.sandboxId,
|
|
385
|
+
ifRevision: record.revision,
|
|
386
|
+
settings: { ingress: { publicPorts: [...open.map((p) => ({ port: p.port })), { port }] } }
|
|
387
|
+
});
|
|
388
|
+
const url = updated.settings?.ingress?.publicPorts.find((p) => p.port === port)?.url;
|
|
389
|
+
if (!url) throw new Error(`Pethost did not answer an address for port ${port}.`);
|
|
390
|
+
return url;
|
|
391
|
+
} catch (error) {
|
|
392
|
+
if (!isCode(error, "ABORTED") || attempt >= 2) throw error;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async function getUrl(sandbox, options) {
|
|
397
|
+
const { port, protocol = "https" } = options;
|
|
398
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Port must be an integer from 1 through 65535.");
|
|
399
|
+
if (protocol !== "https" && protocol !== "wss") throw new Error("Pethost port addresses are HTTPS (and WSS on the same address).");
|
|
400
|
+
const url = options.public ? await publicUrl(sandbox, port) : (await getPethostPortLink(sandbox, { port })).url;
|
|
401
|
+
return protocol === "wss" ? url.replace(/^https:/, "wss:") : url;
|
|
402
|
+
}
|
|
403
|
+
async function resume(sandbox) {
|
|
404
|
+
const deadline = Date.now() + 6e5;
|
|
405
|
+
let record = await sandbox.client.resumeSandbox({ sandboxId: sandbox.sandboxId });
|
|
406
|
+
while (record.state !== "RUNNING" && record.restore && Date.now() < deadline) {
|
|
407
|
+
await sleep(1e3);
|
|
408
|
+
record = await sandbox.client.resumeSandbox({ sandboxId: sandbox.sandboxId });
|
|
409
|
+
}
|
|
410
|
+
if (record.state !== "RUNNING") throw new Error(`Pethost sandbox ${sandbox.sandboxId} did not resume: ${record.stateMessage || record.state}`);
|
|
411
|
+
return { ...sandbox, record };
|
|
412
|
+
}
|
|
413
|
+
var createPethostProvider = defineProvider({
|
|
414
|
+
name: "pethost",
|
|
415
|
+
// https://pethost.dev/sandboxes/ (FAQ, "Where do sandboxes run?"): one region, in the EU.
|
|
416
|
+
regions: {
|
|
417
|
+
support: () => ({ placement: "fixed", regions: {}, reason: "Pethost sandboxes run in one region, in the EU; none runs in the US." }),
|
|
418
|
+
nativeOptions: () => ({})
|
|
419
|
+
},
|
|
420
|
+
sizes: (_config, profile) => {
|
|
421
|
+
const size = SIZES[profile.sizeClass];
|
|
422
|
+
if (!size) {
|
|
423
|
+
return { status: "unsupported", reason: `Pethost sizes are SMALL (2 vCPU / 4 GiB), DEFAULT (4/8), LARGE (8/16) and XLARGE (16/32); ${profile.sizeClass} matches none.` };
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
status: "supported",
|
|
427
|
+
nativeOptions: { size: size.size },
|
|
428
|
+
resolved: { vcpus: size.vcpus, memoryMiB: size.memoryMiB, diskMiB: size.diskMiB }
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
methods: {
|
|
432
|
+
instances: {
|
|
433
|
+
create: async (config, options) => {
|
|
434
|
+
const request2 = await createRequest(config, options);
|
|
435
|
+
const api = client(config);
|
|
436
|
+
return wrap(api, await api.createSandbox(request2));
|
|
437
|
+
},
|
|
438
|
+
getById: async (config, sandboxId) => {
|
|
439
|
+
const api = client(config);
|
|
440
|
+
try {
|
|
441
|
+
const record = await api.getSandbox({ sandboxId });
|
|
442
|
+
return record.state === "DELETED" ? null : wrap(api, record);
|
|
443
|
+
} catch (error) {
|
|
444
|
+
if (isCode(error, "NOT_FOUND", "INVALID_ARGUMENT")) return null;
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
list: async (config) => {
|
|
449
|
+
const api = client(config);
|
|
450
|
+
const found = [];
|
|
451
|
+
let pageToken;
|
|
452
|
+
do {
|
|
453
|
+
const page = await api.listSandboxes({ pageSize: 500, pageToken });
|
|
454
|
+
found.push(...page.sandboxes.map((record) => wrap(api, record)));
|
|
455
|
+
pageToken = page.nextPageToken || void 0;
|
|
456
|
+
} while (pageToken);
|
|
457
|
+
return found;
|
|
458
|
+
},
|
|
459
|
+
destroy: async (config, sandboxId) => {
|
|
460
|
+
try {
|
|
461
|
+
await client(config).deleteSandbox({ sandboxId });
|
|
462
|
+
} catch (error) {
|
|
463
|
+
if (!isCode(error, "NOT_FOUND")) throw error;
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
runCommand: run,
|
|
467
|
+
streamCommand: stream,
|
|
468
|
+
getInfo: async (sandbox) => {
|
|
469
|
+
const record = await sandbox.client.getSandbox({ sandboxId: sandbox.sandboxId });
|
|
470
|
+
return {
|
|
471
|
+
id: record.sandboxId,
|
|
472
|
+
provider: "pethost",
|
|
473
|
+
status: status(record),
|
|
474
|
+
createdAt: record.createTime ?? /* @__PURE__ */ new Date(0),
|
|
475
|
+
timeout: (record.settings?.lifecycle?.deleteAfterIdleSeconds ?? 0) * 1e3,
|
|
476
|
+
metadata: {
|
|
477
|
+
name: record.name,
|
|
478
|
+
state: record.state,
|
|
479
|
+
stateReason: record.stateReason,
|
|
480
|
+
stateMessage: record.stateMessage,
|
|
481
|
+
template: record.template,
|
|
482
|
+
size: record.settings?.size,
|
|
483
|
+
lifecycle: record.settings?.lifecycle,
|
|
484
|
+
labels: record.labels,
|
|
485
|
+
nextState: record.nextState,
|
|
486
|
+
nextStateTime: record.nextStateTime,
|
|
487
|
+
sshCommand: record.sshCommand,
|
|
488
|
+
panelUrl: record.panelUrl
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
},
|
|
492
|
+
getUrl,
|
|
493
|
+
pause: async (sandbox) => {
|
|
494
|
+
await sandbox.client.pauseSandbox({ sandboxId: sandbox.sandboxId });
|
|
495
|
+
},
|
|
496
|
+
resume,
|
|
497
|
+
pauseCapabilities: { memory: true },
|
|
498
|
+
// No cap on a sandbox's life: it is deleted when asked, or by its idle timer (timeout).
|
|
499
|
+
lifetime: {},
|
|
500
|
+
filesystem: { readFile, writeFile, mkdir, readdir, exists, remove },
|
|
501
|
+
getInstance: (sandbox) => sandbox
|
|
502
|
+
},
|
|
503
|
+
snapshot: snapshotMethods,
|
|
504
|
+
template: templateMethods
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
function pethost(config = {}) {
|
|
508
|
+
const provider = createPethostProvider(config);
|
|
509
|
+
return { ...provider, snapshot: provider.snapshot, template: provider.template };
|
|
510
|
+
}
|
|
511
|
+
export {
|
|
512
|
+
getPethostPortLink,
|
|
513
|
+
pethost
|
|
514
|
+
};
|
|
515
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/commands.ts","../src/files.ts","../src/templates.ts"],"sourcesContent":["import { defineProvider } from '@computesdk/provider';\nimport type {\n InstanceSizeManager,\n Provider,\n ProviderSnapshotManager,\n ProviderTemplateManager,\n} from '@computesdk/provider';\nimport type { CreateInstanceOptions, InstanceInfo } from 'computesdk';\nimport type { CreateSandboxRequest, LabelInput, Link, Sandbox, SandboxSettingsInput, Size } from 'pethost/sandboxes';\nimport { client, isCode, seconds, sleep } from './client';\nimport type { PethostConfig, PethostSandbox } from './client';\nimport { run, stream } from './commands';\nimport { exists, mkdir, readdir, readFile, remove, writeFile } from './files';\nimport { snapshotMethods, templateMethods } from './templates';\nimport type { PethostCreateTemplateOptions, PethostSnapshot, PethostTemplate } from './templates';\n\n/** Each size as Pethost runs it (SMALL to XLARGE), by the standard size it serves. */\nconst SIZES: Partial<Record<string, { size: Size; vcpus: number; memoryMiB: number; diskMiB: number }>> = {\n md: { size: 'SMALL', vcpus: 2, memoryMiB: 4096, diskMiB: 10240 },\n lg: { size: 'DEFAULT', vcpus: 4, memoryMiB: 8192, diskMiB: 20480 },\n xl: { size: 'LARGE', vcpus: 8, memoryMiB: 16384, diskMiB: 40960 },\n '2xl': { size: 'XLARGE', vcpus: 16, memoryMiB: 32768, diskMiB: 81920 },\n};\n\n/** Create options of other providers that would otherwise be ignored without a word. */\nconst UNSUPPORTED_OPTIONS = ['cpu', 'cpuLimit', 'cpus', 'vcpus', 'memory', 'memoryMiB', 'memMiB', 'memoryMb', 'diskMiB', 'diskMb',\n 'resources', 'launch_parameters', 'deploymentPlan', 'vmTier', 'gpu', 'region'];\n\nfunction wrap(api: PethostSandbox['client'], record: Sandbox) {\n return { instance: { client: api, sandboxId: record.sandboxId, record }, instanceId: record.sandboxId };\n}\n\nfunction labels(options?: CreateInstanceOptions): LabelInput[] | undefined {\n if (options?.labels !== undefined) return options.labels as LabelInput[];\n if (options?.metadata === undefined) return undefined;\n return Object.entries(options.metadata).map(([key, value]) => ({ key, value: String(value) }));\n}\n\n/** The native variables (secrets among them) with the call's envs over them, by name. */\nfunction environment(native: SandboxSettingsInput, env: Record<string, string>): SandboxSettingsInput['environment'] {\n const replaced = (name?: string) => name !== undefined && Object.prototype.hasOwnProperty.call(env, name);\n const variables = (native.environment?.variables ?? []).filter(variable => !replaced(variable.name));\n return { variables: [...variables, ...Object.entries(env).map(([name, value]) => ({ name, value }))] };\n}\n\n/** Settings for a create: the config's, then the call's; a group sent replaces the template's. */\nfunction settings(config: PethostConfig, options?: CreateInstanceOptions): SandboxSettingsInput {\n const native = { ...config.settings, ...(options?.settings as SandboxSettingsInput | undefined) };\n const size = (options?.size as Size | undefined) ?? config.size ?? native.size;\n const idle = seconds(options?.timeout ?? config.timeout, 'timeout');\n const env = (options?.envs ?? options?.env) as Record<string, string> | undefined;\n return {\n ...native,\n ...(size === undefined ? {} : { size }),\n ...(idle === undefined ? {} : { lifecycle: { ...native.lifecycle, deleteAfterIdleSeconds: idle } }),\n ...(env === undefined ? {} : { environment: environment(native, env) }),\n };\n}\n\nasync function createRequest(config: PethostConfig, options?: CreateInstanceOptions): Promise<CreateSandboxRequest> {\n for (const key of UNSUPPORTED_OPTIONS) {\n if (options?.[key] !== undefined) throw new Error(`Pethost does not take ${key}: sandboxes come in four sizes, chosen with size (SMALL, DEFAULT, LARGE, XLARGE) or sizeClass.`);\n }\n if (options?.image !== undefined) throw new Error('Pethost starts sandboxes from templates, not images: pass templateId.');\n if (options?.templateId && options?.snapshotId) throw new Error('Pass templateId or snapshotId, not both.');\n const template = options?.snapshotId ?? options?.templateId ?? config.template;\n return { template, name: options?.name, labels: labels(options), settings: settings(config, options) };\n}\n\nfunction status(record: Sandbox): InstanceInfo['status'] {\n if (record.state === 'RUNNING') return 'running';\n if (record.state === 'STOPPED' && record.stateReason === 'CRASH') return 'error';\n return 'stopped';\n}\n\n/** A port's address and a token for it alone, sent as `Pethost-Token: <token>`. */\nexport async function getPethostPortLink(sandbox: PethostSandbox, options: { port: number; ttlSeconds?: number }): Promise<Link> {\n return sandbox.client.createLink({ sandboxId: sandbox.sandboxId, port: options.port, ttlSeconds: options.ttlSeconds });\n}\n\n/** Makes a port public (settings.ingress.publicPorts) and answers its address. */\nasync function publicUrl(sandbox: PethostSandbox, port: number): Promise<string> {\n for (let attempt = 0; ; attempt += 1) {\n const record = await sandbox.client.getSandbox({ sandboxId: sandbox.sandboxId });\n const open = record.settings?.ingress?.publicPorts ?? [];\n const known = open.find(p => p.port === port);\n if (known) return known.url;\n try {\n const updated = await sandbox.client.updateSandbox({\n sandboxId: sandbox.sandboxId,\n ifRevision: record.revision,\n settings: { ingress: { publicPorts: [...open.map(p => ({ port: p.port })), { port }] } },\n });\n const url = updated.settings?.ingress?.publicPorts.find(p => p.port === port)?.url;\n if (!url) throw new Error(`Pethost did not answer an address for port ${port}.`);\n return url;\n } catch (error) {\n // Another call changed the sandbox's settings in between: read them again.\n if (!isCode(error, 'ABORTED') || attempt >= 2) throw error;\n }\n }\n}\n\nasync function getUrl(sandbox: PethostSandbox, options: { port: number; protocol?: string; public?: boolean }): Promise<string> {\n const { port, protocol = 'https' } = options;\n if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error('Port must be an integer from 1 through 65535.');\n if (protocol !== 'https' && protocol !== 'wss') throw new Error('Pethost port addresses are HTTPS (and WSS on the same address).');\n const url = options.public ? await publicUrl(sandbox, port) : (await getPethostPortLink(sandbox, { port })).url;\n return protocol === 'wss' ? url.replace(/^https:/, 'wss:') : url;\n}\n\n/** Resumes a sandbox; a stopped one whose disk is fetched from object storage is waited on. */\nasync function resume(sandbox: PethostSandbox): Promise<PethostSandbox> {\n const deadline = Date.now() + 600_000;\n let record = await sandbox.client.resumeSandbox({ sandboxId: sandbox.sandboxId });\n while (record.state !== 'RUNNING' && record.restore && Date.now() < deadline) {\n await sleep(1000);\n record = await sandbox.client.resumeSandbox({ sandboxId: sandbox.sandboxId });\n }\n if (record.state !== 'RUNNING') throw new Error(`Pethost sandbox ${sandbox.sandboxId} did not resume: ${record.stateMessage || record.state}`);\n return { ...sandbox, record };\n}\n\nexport interface PethostProvider extends Provider<PethostSandbox, PethostTemplate, PethostSnapshot> {\n snapshot: ProviderSnapshotManager<PethostSnapshot>;\n template: ProviderTemplateManager<PethostTemplate, PethostCreateTemplateOptions>;\n readonly sizes: InstanceSizeManager;\n}\n\nconst createPethostProvider = defineProvider<PethostSandbox, PethostConfig, PethostTemplate, PethostSnapshot>({\n name: 'pethost',\n // https://pethost.dev/sandboxes/ (FAQ, \"Where do sandboxes run?\"): one region, in the EU.\n regions: {\n support: () => ({ placement: 'fixed', regions: {}, reason: 'Pethost sandboxes run in one region, in the EU; none runs in the US.' }),\n nativeOptions: () => ({}),\n },\n sizes: (_config, profile) => {\n const size = SIZES[profile.sizeClass];\n if (!size) {\n return { status: 'unsupported', reason: `Pethost sizes are SMALL (2 vCPU / 4 GiB), DEFAULT (4/8), LARGE (8/16) and XLARGE (16/32); ${profile.sizeClass} matches none.` };\n }\n return {\n status: 'supported',\n nativeOptions: { size: size.size },\n resolved: { vcpus: size.vcpus, memoryMiB: size.memoryMiB, diskMiB: size.diskMiB },\n };\n },\n methods: {\n instances: {\n create: async (config, options) => {\n const request = await createRequest(config, options);\n const api = client(config);\n // The factory destroys a sandbox whose create answers after an abort.\n return wrap(api, await api.createSandbox(request));\n },\n getById: async (config, sandboxId) => {\n const api = client(config);\n try {\n const record = await api.getSandbox({ sandboxId });\n return record.state === 'DELETED' ? null : wrap(api, record);\n } catch (error) {\n if (isCode(error, 'NOT_FOUND', 'INVALID_ARGUMENT')) return null;\n throw error;\n }\n },\n list: async config => {\n const api = client(config);\n const found: ReturnType<typeof wrap>[] = [];\n let pageToken: string | undefined;\n do {\n const page = await api.listSandboxes({ pageSize: 500, pageToken });\n found.push(...page.sandboxes.map(record => wrap(api, record)));\n pageToken = page.nextPageToken || undefined;\n } while (pageToken);\n return found;\n },\n destroy: async (config, sandboxId) => {\n try {\n await client(config).deleteSandbox({ sandboxId });\n } catch (error) {\n if (!isCode(error, 'NOT_FOUND')) throw error;\n }\n },\n runCommand: run,\n streamCommand: stream,\n getInfo: async sandbox => {\n const record = await sandbox.client.getSandbox({ sandboxId: sandbox.sandboxId });\n return {\n id: record.sandboxId,\n provider: 'pethost',\n status: status(record),\n createdAt: record.createTime ?? new Date(0),\n timeout: (record.settings?.lifecycle?.deleteAfterIdleSeconds ?? 0) * 1000,\n metadata: {\n name: record.name,\n state: record.state,\n stateReason: record.stateReason,\n stateMessage: record.stateMessage,\n template: record.template,\n size: record.settings?.size,\n lifecycle: record.settings?.lifecycle,\n labels: record.labels,\n nextState: record.nextState,\n nextStateTime: record.nextStateTime,\n sshCommand: record.sshCommand,\n panelUrl: record.panelUrl,\n },\n };\n },\n getUrl,\n pause: async sandbox => {\n await sandbox.client.pauseSandbox({ sandboxId: sandbox.sandboxId });\n },\n resume,\n pauseCapabilities: { memory: true },\n // No cap on a sandbox's life: it is deleted when asked, or by its idle timer (timeout).\n lifetime: {},\n filesystem: { readFile, writeFile, mkdir, readdir, exists, remove },\n getInstance: sandbox => sandbox,\n },\n snapshot: snapshotMethods,\n template: templateMethods,\n },\n});\n\nexport function pethost(config: PethostConfig = {}): PethostProvider {\n const provider = createPethostProvider(config);\n return { ...provider, snapshot: provider.snapshot!, template: provider.template! } as PethostProvider;\n}\n\nexport type { PethostConfig, PethostSandbox } from './client';\nexport type { PethostCreateTemplateOptions, PethostSnapshot, PethostTemplate } from './templates';\nexport type { Size as PethostSize, SandboxSettingsInput as PethostSettings } from 'pethost/sandboxes';\n","import { Sandboxes, SandboxesError } from 'pethost/sandboxes';\nimport type { ErrorCode, Sandbox, SandboxSettingsInput, Size } from 'pethost/sandboxes';\n\nexport interface PethostConfig {\n /** API token. Falls back to PETHOST_TOKEN. */\n token?: string;\n /**\n * The workspace of sandboxes, by id or name. Needed only when the token's account has several.\n * Falls back to PETHOST_WORKSPACE.\n */\n workspace?: string;\n /** API address. Falls back to PETHOST_URL, then https://console.pethost.dev. */\n baseUrl?: string;\n /** Template a sandbox starts from when create names none. Default: Pethost's `base`. */\n template?: string;\n /** Size of new sandboxes: SMALL, DEFAULT, LARGE or XLARGE. Default: the template's (DEFAULT for `base`). */\n size?: Size;\n /**\n * Deletes a sandbox once it has been idle this many milliseconds (lifecycle.deleteAfterIdleSeconds,\n * rounded up to a second). Pethost puts no cap on a sandbox's life, so this counts idle time.\n */\n timeout?: number;\n /** Native settings for every create: lifecycle, egress, ingress, environment. */\n settings?: SandboxSettingsInput;\n}\n\n/** A sandbox as the provider holds it. */\nexport interface PethostSandbox {\n /** The client that made or found it: it keeps the sandbox's runtime connection. */\n readonly client: Sandboxes;\n readonly sandboxId: string;\n /** The sandbox's record as the call that returned it answered. */\n readonly record: Sandbox;\n}\n\n// One client per provider config, so runtime calls reuse the connection a create answered with.\nconst clients = new WeakMap<PethostConfig, Sandboxes>();\n\nexport function client(config: PethostConfig): Sandboxes {\n const cached = clients.get(config);\n if (cached) return cached;\n const token = config.token || process.env.PETHOST_TOKEN;\n if (!token) {\n throw new Error(\n 'Missing Pethost API token. Pass pethost({ token }) or set PETHOST_TOKEN.\\n' +\n 'Create one in your workspace of sandboxes at https://console.pethost.dev: ' +\n 'press Connect an agent, open TypeScript and press Create an API token.'\n );\n }\n const made = new Sandboxes({\n token,\n baseUrl: config.baseUrl || process.env.PETHOST_URL || undefined,\n workspace: config.workspace || process.env.PETHOST_WORKSPACE || undefined,\n });\n clients.set(config, made);\n return made;\n}\n\nexport function isCode(error: unknown, ...codes: ErrorCode[]): boolean {\n return error instanceof SandboxesError && codes.includes(error.code);\n}\n\n/** Milliseconds as whole seconds, rounded up; undefined or 0 means none. */\nexport function seconds(ms: number | undefined, what: string): number | undefined {\n if (ms === undefined || ms === 0) return undefined;\n if (!Number.isFinite(ms) || ms < 0) throw new Error(`Pethost ${what} must be a non-negative number of milliseconds; 0 means none.`);\n return Math.ceil(ms / 1000);\n}\n\nexport function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n","import { escapeShellArg, TIMEOUT_EXIT_CODE } from '@computesdk/provider';\nimport type { CommandResult, RunCommandOptions } from 'computesdk';\nimport type { Command, RunCommandRequest } from 'pethost/sandboxes';\nimport { isCode, seconds } from './client';\nimport type { PethostSandbox } from './client';\n\n/**\n * How long the first call waits for a foreground command. A command that ends sooner (the usual\n * case) takes one round trip; a longer one is followed from then on through the output stream,\n * which replays the newest 64 KiB, so a command's output is whole unless it wrote more than that\n * before following began.\n */\nconst FIRST_WAIT_SECONDS = 10;\n\n/** The command text bash -lc runs: the env as exports, so every part of a compound command sees it. */\nexport function commandText(command: string, env?: Record<string, string>): string {\n const entries = Object.entries(env ?? {});\n if (entries.length === 0) return command;\n const exports = entries.map(([name, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid environment variable name: ${name}`);\n return `export ${name}=\"${escapeShellArg(value)}\"`;\n });\n return `${exports.join('\\n')}\\n${command}`;\n}\n\nfunction request(sandbox: PethostSandbox, command: string, options?: RunCommandOptions): RunCommandRequest {\n return {\n sandboxId: sandbox.sandboxId,\n command: commandText(command, options?.env),\n cwd: options?.cwd,\n timeoutSeconds: seconds(options?.timeout, 'command timeout'),\n };\n}\n\n/** The exit code a CommandResult reports for a command that has ended. */\nexport function exitCode(command: Command): number {\n if (command.state === 'TIMED_OUT') return TIMEOUT_EXIT_CODE;\n if (command.state === 'LOST') {\n throw new Error(`Pethost command ${command.commandId} was lost: its sandbox lost its memory while it ran, so its end is not known.`);\n }\n return command.exitCode ?? 1;\n}\n\n/**\n * Joins a first answer's output (the last 32 KiB before byte `firstEnd`) with the stream that\n * followed it, which ended at byte `total` and replayed what the server still held. Byte offsets\n * line the two up, so nothing is repeated.\n */\nexport function joinOutput(firstText: string, firstEnd: bigint, streamed: Uint8Array, total: bigint): string {\n const decoder = new TextDecoder();\n const streamStart = Number(total) - streamed.length;\n const end = Number(firstEnd);\n if (streamStart <= end - Buffer.byteLength(firstText)) return decoder.decode(streamed);\n if (streamStart <= end) return firstText + decoder.decode(streamed.subarray(end - streamStart));\n // The server no longer held the bytes between the two.\n return firstText + decoder.decode(streamed);\n}\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n return new Uint8Array(Buffer.concat(chunks));\n}\n\nasync function stopQuietly(sandbox: PethostSandbox, commandId: string): Promise<void> {\n try {\n await sandbox.client.stopCommand({ sandboxId: sandbox.sandboxId, commandId });\n } catch (error) {\n if (!isCode(error, 'NOT_FOUND')) throw error;\n }\n}\n\n/** Follows a command to its end; a failure stops it, so no foreground command is left running. */\nasync function follow(\n sandbox: PethostSandbox,\n commandId: string,\n onFrame: (stream: 'stdout' | 'stderr', bytes: Uint8Array) => void,\n): Promise<Command> {\n try {\n for await (const frame of sandbox.client.watchCommand({ sandboxId: sandbox.sandboxId, commandId })) {\n if (frame.output === 'stdout') onFrame('stdout', frame.stdout);\n else if (frame.output === 'stderr') onFrame('stderr', frame.stderr);\n else if (frame.output === 'ended') return frame.ended;\n }\n throw new Error(`Pethost command ${commandId}: its output stream ended before the command did.`);\n } catch (error) {\n await stopQuietly(sandbox, commandId).catch(() => {});\n throw error;\n }\n}\n\n/** runCommand: one call for a command that ends within the first wait, else its output stream. */\nexport async function run(sandbox: PethostSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> {\n const start = Date.now();\n const base = request(sandbox, command, options);\n if (options?.background) {\n await sandbox.client.runCommand({ ...base, waitSeconds: 0 });\n return { stdout: '', stderr: '', exitCode: 0, durationMs: Date.now() - start };\n }\n\n const first = await sandbox.client.runCommand({ ...base, waitSeconds: FIRST_WAIT_SECONDS });\n if (first.state !== 'RUNNING' && !first.outputTruncated) {\n return { stdout: first.stdout, stderr: first.stderr, exitCode: exitCode(first), durationMs: Date.now() - start };\n }\n\n // Still running, or its output passed what one answer holds: the stream replays and goes on.\n const chunks = { stdout: [] as Uint8Array[], stderr: [] as Uint8Array[] };\n const ended = await follow(sandbox, first.commandId, (stream, bytes) => chunks[stream].push(bytes));\n return {\n stdout: joinOutput(first.stdout, first.stdoutBytes, concat(chunks.stdout), ended.stdoutBytes),\n stderr: joinOutput(first.stderr, first.stderrBytes, concat(chunks.stderr), ended.stderrBytes),\n exitCode: exitCode(ended),\n durationMs: Date.now() - start,\n };\n}\n\n/** streamCommand: the output stream from the command's start, handed to the callbacks as it comes. */\nexport async function stream(sandbox: PethostSandbox, command: string, options: RunCommandOptions): Promise<CommandResult> {\n if (options.background) return run(sandbox, command, options);\n const start = Date.now();\n const started = await sandbox.client.runCommand({ ...request(sandbox, command, options), waitSeconds: 0 });\n\n const decoders = { stdout: new TextDecoder(), stderr: new TextDecoder() };\n const text = { stdout: '', stderr: '' };\n const emit = (name: 'stdout' | 'stderr', chunk: string) => {\n if (!chunk) return;\n text[name] += chunk;\n (name === 'stdout' ? options.onStdout : options.onStderr)?.(chunk);\n };\n const ended = await follow(sandbox, started.commandId, (name, bytes) => emit(name, decoders[name].decode(bytes, { stream: true })));\n emit('stdout', decoders.stdout.decode());\n emit('stderr', decoders.stderr.decode());\n return { stdout: text.stdout, stderr: text.stderr, exitCode: exitCode(ended), durationMs: Date.now() - start };\n}\n","import { posix } from 'node:path';\nimport type { FileEntry } from 'computesdk';\nimport type { File, FileChangeInput, WriteFilesResponse } from 'pethost/sandboxes';\nimport { isCode } from './client';\nimport type { PethostSandbox } from './client';\n\nconst MIB = 1024 * 1024;\n/** The first read is small: it tells the file's size, so a large file costs 64 KiB more, not 1 MiB. */\nconst READ_FIRST_BYTES = 64 * 1024;\n/** ReadFile answers at most 1 MiB; a larger file comes whole through a download link. */\nconst READ_INLINE_BYTES = MIB;\n/** WriteFiles takes up to 17 MiB a call; past this, a file goes through an upload link. */\nconst WRITE_INLINE_BYTES = 8 * MIB;\n\nasync function change(sandbox: PethostSandbox, verb: string, path: string, file: FileChangeInput): Promise<void> {\n const answer: WriteFilesResponse = await sandbox.client.writeFiles({ sandboxId: sandbox.sandboxId, changes: [{ path, ...file } as FileChangeInput] });\n if (answer.doneCount < 1) throw new Error(`Pethost could not ${verb} ${path}: ${answer.failureMessage || 'unknown failure'}`);\n}\n\n/** A link's URL holds its own token; it must not show in an error. */\nasync function transfer(url: string, init: RequestInit, what: string): Promise<Response> {\n const response = await fetch(url, init);\n if (!response.ok) throw new Error(`Pethost ${what} failed (HTTP ${response.status}).`);\n return response;\n}\n\nfunction read(sandbox: PethostSandbox, path: string, length: number): Promise<File> {\n return sandbox.client.readFile({ sandboxId: sandbox.sandboxId, path, lengthBytes: BigInt(length) });\n}\n\nfunction textOf(file: File): string {\n if (file.content === 'text') return file.text;\n if (file.content === 'data') return new TextDecoder().decode(file.data);\n return '';\n}\n\nasync function download(sandbox: PethostSandbox, path: string): Promise<string> {\n const link = await sandbox.client.createLink({ sandboxId: sandbox.sandboxId, downloadPath: path });\n const response = await transfer(link.url, {}, `download of ${path}`);\n return new TextDecoder().decode(await response.arrayBuffer());\n}\n\nexport async function readFile(sandbox: PethostSandbox, path: string): Promise<string> {\n const first = await read(sandbox, path, READ_FIRST_BYTES);\n const size = Number(first.sizeBytes);\n if (size <= READ_FIRST_BYTES) return textOf(first);\n // Read again whole, not from where the first read ended: its text is decoded, so its length\n // in bytes need not be what was read.\n if (size <= READ_INLINE_BYTES) return textOf(await read(sandbox, path, size));\n return download(sandbox, path);\n}\n\nexport async function writeFile(sandbox: PethostSandbox, path: string, content: string): Promise<void> {\n if (Buffer.byteLength(content) <= WRITE_INLINE_BYTES) {\n await change(sandbox, 'write', path, { text: content });\n return;\n }\n const link = await sandbox.client.createLink({ sandboxId: sandbox.sandboxId, uploadPath: path });\n const response = await transfer(link.url, { method: 'PUT', body: Buffer.from(content) }, `upload of ${path}`);\n await response.body?.cancel();\n}\n\nexport async function mkdir(sandbox: PethostSandbox, path: string): Promise<void> {\n await change(sandbox, 'make the directory', path, { makeDirectory: {} });\n}\n\nexport async function remove(sandbox: PethostSandbox, path: string): Promise<void> {\n await change(sandbox, 'delete', path, { delete: {} });\n}\n\nexport async function readdir(sandbox: PethostSandbox, path: string): Promise<FileEntry[]> {\n const entries: FileEntry[] = [];\n let pageToken: string | undefined;\n do {\n const page = await sandbox.client.listFiles({ sandboxId: sandbox.sandboxId, path, pageToken });\n for (const file of page.files) {\n entries.push({\n name: posix.basename(file.path),\n type: file.kind === 'DIRECTORY' ? 'directory' : 'file',\n size: Number(file.sizeBytes),\n modified: file.modifyTime,\n });\n }\n pageToken = page.nextPageToken || undefined;\n } while (pageToken);\n return entries;\n}\n\nexport async function exists(sandbox: PethostSandbox, path: string): Promise<boolean> {\n try {\n await sandbox.client.listFiles({ sandboxId: sandbox.sandboxId, path });\n return true;\n } catch (error) {\n if (isCode(error, 'NOT_FOUND')) return false;\n // Something there that the user may not list is still there.\n if (isCode(error, 'PERMISSION_DENIED')) return true;\n throw error;\n }\n}\n","import type { CreateSnapshotOptions, CreateTemplateOptions, ListSnapshotsOptions, ListTemplatesOptions, SnapshotCapabilities } from '@computesdk/provider';\nimport type { Sandboxes, Template } from 'pethost/sandboxes';\nimport { client, isCode, sleep } from './client';\nimport type { PethostConfig } from './client';\n\n/**\n * Snapshots and templates are both Pethost templates: a sandbox's disk and settings saved as a\n * version, `name@version`, which any number of sandboxes start from on any server. The source\n * runs on; memory and processes are not kept (pause keeps those).\n */\nexport const snapshotCapabilities: SnapshotCapabilities = {\n scope: 'rootfs',\n memory: false,\n destroysSource: false,\n source: 'kept',\n // A new version is SAVING until it is uploaded; create starts only from a READY one.\n readiness: 'eventual',\n};\n\nexport interface PethostSnapshot {\n /** `name@version`: what create's snapshotId and templateId take. */\n id: string;\n provider: 'pethost';\n createdAt: Date;\n metadata: { name: string; version: number; state: string; failureMessage: string; sizeBytes: number; base: string };\n}\n\nexport interface PethostTemplate extends PethostSnapshot {\n /** Same as id. */\n templateId: string;\n builtIn: boolean;\n description: string;\n}\n\nexport interface PethostCreateTemplateOptions extends CreateTemplateOptions {\n /** The sandbox whose disk and settings the new version holds. A name that exists gets its next version. */\n sandboxId: string;\n}\n\nfunction snapshotInfo(template: Template): PethostSnapshot {\n return {\n id: `${template.name}@${template.version}`,\n provider: 'pethost',\n createdAt: template.createTime ?? new Date(0),\n metadata: {\n name: template.name,\n version: template.version,\n state: String(template.state ?? ''),\n failureMessage: template.failureMessage,\n sizeBytes: Number(template.sizeBytes),\n base: template.base,\n },\n };\n}\n\nfunction templateInfo(template: Template): PethostTemplate {\n const info = snapshotInfo(template);\n return { ...info, templateId: info.id, builtIn: template.builtIn, description: template.description };\n}\n\nfunction nameOf(id: string): string {\n return id.split('@')[0];\n}\n\nfunction save(api: Sandboxes, sandboxId: string, name: string, description?: string): Promise<Template> {\n return api.createTemplate({ name, sandboxId, description });\n}\n\nasync function listAll(api: Sandboxes, limit?: number): Promise<Template[]> {\n const templates: Template[] = [];\n let pageToken: string | undefined;\n do {\n const page = await api.listTemplates({ pageSize: 500, pageToken });\n templates.push(...page.templates);\n pageToken = page.nextPageToken || undefined;\n } while (pageToken && (limit === undefined || templates.length < limit));\n return limit === undefined ? templates : templates.slice(0, limit);\n}\n\n/**\n * Pethost deletes a name with all its versions, so a snapshot is deleted only while its version\n * is its name's one version, and refused when others would go with it. The names create gives\n * are unique, so those always are.\n */\nasync function deleteSnapshot(api: Sandboxes, id: string): Promise<void> {\n const name = nameOf(id);\n const { templates } = await api.listTemplates({ name, pageSize: 2 });\n if (templates.length > 1) {\n throw new Error(`Pethost deletes a template's name with all its versions, and ${name} has more than one, so ${id} is not deleted alone. template.delete('${name}') deletes them all.`);\n }\n const [only] = templates;\n if (!only || (id.includes('@') && `${only.name}@${only.version}` !== id)) return;\n await deleteByName(api, id);\n}\n\nasync function deleteByName(api: Sandboxes, id: string): Promise<void> {\n try {\n await api.deleteTemplate({ name: nameOf(id) });\n } catch (error) {\n if (!isCode(error, 'NOT_FOUND')) throw error;\n }\n}\n\n/** Waits until a saved version is READY: create starts only from one. */\nexport async function waitUntilReady(config: PethostConfig, id: string, options?: { timeoutMs?: number }): Promise<void> {\n const api = client(config);\n const deadline = Date.now() + (options?.timeoutMs ?? 600_000);\n for (;;) {\n const template = await api.getTemplate({ template: id });\n if (template.state === 'READY') return;\n if (template.state === 'FAILED') throw new Error(`Pethost template ${id} failed: ${template.failureMessage}`);\n if (Date.now() >= deadline) throw new Error(`Timed out waiting for Pethost template ${id} to be READY.`);\n await sleep(Math.min(500, Math.max(0, deadline - Date.now())));\n }\n}\n\nexport const snapshotMethods = {\n create: async (config: PethostConfig, sandboxId: string, options?: CreateSnapshotOptions): Promise<PethostSnapshot> => {\n const name = options?.name ?? `snapshot-${sandboxId}-${Date.now().toString(36)}`;\n return snapshotInfo(await save(client(config), sandboxId, name));\n },\n list: async (config: PethostConfig, options?: ListSnapshotsOptions): Promise<PethostSnapshot[]> => {\n // A version does not record its sandbox; the names create gives say it.\n const source = options?.instanceId ?? options?.sandboxId;\n const prefix = source === undefined ? undefined : `snapshot-${source}-`;\n const templates = (await listAll(client(config))).filter(template => !template.builtIn && (!prefix || template.name.startsWith(prefix)));\n return templates.slice(0, options?.limit ?? templates.length).map(snapshotInfo);\n },\n delete: (config: PethostConfig, id: string): Promise<void> => deleteSnapshot(client(config), id),\n capabilities: snapshotCapabilities,\n waitUntilReady,\n};\n\nexport const templateMethods = {\n create: async (config: PethostConfig, options: CreateTemplateOptions): Promise<PethostTemplate> => {\n const { sandboxId, name, description } = options as PethostCreateTemplateOptions;\n if (!sandboxId) throw new Error('Pethost saves a template from a sandbox: pass sandboxId.');\n return templateInfo(await save(client(config), sandboxId, name, description));\n },\n list: async (config: PethostConfig, options?: ListTemplatesOptions): Promise<PethostTemplate[]> =>\n (await listAll(client(config), options?.limit)).map(templateInfo),\n /** Deletes every version of the template's name. */\n delete: (config: PethostConfig, id: string): Promise<void> => deleteByName(client(config), id),\n};\n"],"mappings":";AAAA,SAAS,sBAAsB;;;ACA/B,SAAS,WAAW,sBAAsB;AAoC1C,IAAM,UAAU,oBAAI,QAAkC;AAE/C,SAAS,OAAO,QAAkC;AACvD,QAAM,SAAS,QAAQ,IAAI,MAAM;AACjC,MAAI,OAAQ,QAAO;AACnB,QAAM,QAAQ,OAAO,SAAS,QAAQ,IAAI;AAC1C,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,QAAM,OAAO,IAAI,UAAU;AAAA,IACzB;AAAA,IACA,SAAS,OAAO,WAAW,QAAQ,IAAI,eAAe;AAAA,IACtD,WAAW,OAAO,aAAa,QAAQ,IAAI,qBAAqB;AAAA,EAClE,CAAC;AACD,UAAQ,IAAI,QAAQ,IAAI;AACxB,SAAO;AACT;AAEO,SAAS,OAAO,UAAmB,OAA6B;AACrE,SAAO,iBAAiB,kBAAkB,MAAM,SAAS,MAAM,IAAI;AACrE;AAGO,SAAS,QAAQ,IAAwB,MAAkC;AAChF,MAAI,OAAO,UAAa,OAAO,EAAG,QAAO;AACzC,MAAI,CAAC,OAAO,SAAS,EAAE,KAAK,KAAK,EAAG,OAAM,IAAI,MAAM,WAAW,IAAI,+DAA+D;AAClI,SAAO,KAAK,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