@vite-hub/sandbox 0.0.4 → 0.3.0
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 +395 -37
- package/dist/abortable-CR01hzfi.js +57 -0
- package/dist/cloudflare-Cog_r2Me.js +910 -0
- package/dist/cloudflare-env-lookup-DzI6Xv1Y.js +16 -0
- package/dist/cloudflare-failure-CFQhalfh.js +50 -0
- package/dist/container-CqfD8yuE.js +868 -0
- package/dist/crabbox-sbV3Zjuo.js +1110 -0
- package/dist/error-diagnostics-5QT_BjbQ.js +354 -0
- package/dist/error-diagnostics-BJtLRL9w.js +536 -0
- package/dist/file-listing-CHtRrfo1.js +26 -0
- package/dist/file-lock-D0-XPogS.js +74 -0
- package/dist/index-DsoQAUb7.d.ts +594 -0
- package/dist/index.d.ts +2 -69
- package/dist/index.js +281 -1182
- package/dist/internal/cloudflare.d.ts +176 -0
- package/dist/internal/cloudflare.js +8 -0
- package/dist/internal/host-toolchain.d.ts +22 -0
- package/dist/internal/host-toolchain.js +96 -0
- package/dist/internal/vercel.d.ts +4 -0
- package/dist/internal/vercel.js +8 -0
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/module-types-B0LQ5H2S.js +7 -0
- package/dist/module-types-DCeJbS9Z.d.ts +110 -0
- package/dist/process-sweep-CMaujWE5.js +33 -0
- package/dist/provider-resolution-C6AQzuFG.js +133 -0
- package/dist/remote-70ZVZZlq.js +265 -0
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime-DHp6ImeP.js +32 -0
- package/dist/runtime-type-Deo4qzxN.js +9 -0
- package/dist/session-e0lyzjJ3.js +338 -0
- package/dist/shell-quote-Q3u3plif.js +6 -0
- package/dist/size-7AkVwGZb.js +118 -0
- package/dist/ssh.d.ts +63 -0
- package/dist/ssh.js +286 -0
- package/dist/task/index.d.ts +69 -0
- package/dist/task/index.js +1414 -0
- package/dist/task/runtime/empty-registry.d.ts +6 -0
- package/dist/{runtime → task/runtime}/empty-registry.js +2 -2
- package/dist/task/runtime/provider-loader.d.ts +18 -0
- package/dist/task/runtime/provider-loader.js +16 -0
- package/dist/task/runtime/providers/cloudflare.d.ts +14 -0
- package/dist/task/runtime/providers/cloudflare.js +27 -0
- package/dist/task/runtime/providers/vercel.d.ts +12 -0
- package/dist/task/runtime/providers/vercel.js +85 -0
- package/dist/task/runtime/state.d.ts +27 -0
- package/dist/task/runtime/state.js +82 -0
- package/dist/task/vite.d.ts +486 -0
- package/dist/task/vite.js +3966 -0
- package/dist/toolchain-BIVGMRty.js +528 -0
- package/dist/trusted-host-kxkpaQcs.js +714 -0
- package/dist/vercel-BGGrNpza.js +352 -0
- package/package.json +105 -51
- package/dist/cloudflare-env-QQV4uzCT.js +0 -14
- package/dist/module-types-DKYItiOu.d.ts +0 -93
- package/dist/module-types-Dj1MFmHT.js +0 -7
- package/dist/provider-loader-D0UihePq.d.ts +0 -21
- package/dist/runtime/empty-registry.d.ts +0 -6
- package/dist/runtime/provider-loader.d.ts +0 -2
- package/dist/runtime/provider-loader.js +0 -15
- package/dist/runtime/providers/cloudflare.d.ts +0 -29
- package/dist/runtime/providers/cloudflare.js +0 -25
- package/dist/runtime/providers/vercel.d.ts +0 -121
- package/dist/runtime/providers/vercel.js +0 -51
- package/dist/runtime/state.d.ts +0 -26
- package/dist/runtime/state.js +0 -72
- package/dist/vite.d.ts +0 -48
- package/dist/vite.js +0 -3324
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
import { r as markBuiltInSandboxRuntime } from "./runtime-DHp6ImeP.js";
|
|
3
|
+
import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
|
|
4
|
+
import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
|
|
5
|
+
import { t as listCommandFiles } from "./file-listing-CHtRrfo1.js";
|
|
6
|
+
import { i as resolveRemoteEnvironment, n as openRemoteSandbox, r as remoteSandboxPlan, t as collectProcessOutput } from "./remote-70ZVZZlq.js";
|
|
7
|
+
import { n as killOnAbort } from "./abortable-CR01hzfi.js";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { posix } from "node:path";
|
|
10
|
+
//#region src/vercel.ts
|
|
11
|
+
var vercel_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
createVercelRuntime: () => createVercelRuntime,
|
|
13
|
+
loadVercelSandbox: () => loadVercelSandbox
|
|
14
|
+
});
|
|
15
|
+
/** The signals that the Vercel Sandbox SDK sends by name. Other signals use their number. */
|
|
16
|
+
const vercelSignalNames = [
|
|
17
|
+
"SIGHUP",
|
|
18
|
+
"SIGINT",
|
|
19
|
+
"SIGQUIT",
|
|
20
|
+
"SIGKILL",
|
|
21
|
+
"SIGTERM",
|
|
22
|
+
"SIGCONT",
|
|
23
|
+
"SIGSTOP"
|
|
24
|
+
];
|
|
25
|
+
function createVercelRuntime(options = {}) {
|
|
26
|
+
const runtime = options.source?.type === "snapshot" ? options.runtime : options.runtime ?? "node24";
|
|
27
|
+
const executionAuthority = vercelExecutionAuthority(options.networkPolicy);
|
|
28
|
+
return markBuiltInSandboxRuntime({
|
|
29
|
+
name: "vercel",
|
|
30
|
+
async prepare(input) {
|
|
31
|
+
return remoteSandboxPlan(input, {
|
|
32
|
+
executionAuthority,
|
|
33
|
+
runtime: "vercel"
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
async open(input, openOptions) {
|
|
37
|
+
const workspace = options.source ? "/vercel/sandbox" : "/workspace";
|
|
38
|
+
const env = await resolveRemoteEnvironment(input, { workspace });
|
|
39
|
+
const instance = await (options.create ?? await loadVercelSandbox())({
|
|
40
|
+
...runtime ? { runtime } : {},
|
|
41
|
+
persistent: false,
|
|
42
|
+
signal: openOptions?.signal,
|
|
43
|
+
timeout: options.timeout ?? 3e5,
|
|
44
|
+
...options.cpu ? { resources: { vcpus: options.cpu } } : {},
|
|
45
|
+
...options.ports ? { ports: options.ports } : {},
|
|
46
|
+
...options.source ? { source: options.source } : {},
|
|
47
|
+
...options.networkPolicy ? { networkPolicy: options.networkPolicy } : {},
|
|
48
|
+
...options.token ? { token: options.token } : {},
|
|
49
|
+
...options.teamId ? { teamId: options.teamId } : {},
|
|
50
|
+
...options.projectId ? { projectId: options.projectId } : {}
|
|
51
|
+
});
|
|
52
|
+
const runtimeSession = createVercelSession(openOptions?.id ?? `vitehub-${randomUUID()}`, instance, env, options.ports, workspace);
|
|
53
|
+
return await openRemoteSandbox(input, runtimeSession, {
|
|
54
|
+
executionAuthority: openOptions.executionAuthority,
|
|
55
|
+
initialize: openOptions?.initialize,
|
|
56
|
+
runtime: "vercel",
|
|
57
|
+
workspace,
|
|
58
|
+
preserveWorkspace: Boolean(options.source),
|
|
59
|
+
signal: openOptions?.signal
|
|
60
|
+
}, env);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function vercelExecutionAuthority(networkPolicy) {
|
|
65
|
+
return {
|
|
66
|
+
credentials: "unknown",
|
|
67
|
+
environment: "selected",
|
|
68
|
+
filesystem: {
|
|
69
|
+
access: "read-write",
|
|
70
|
+
scope: "sandbox"
|
|
71
|
+
},
|
|
72
|
+
isolation: "microvm",
|
|
73
|
+
network: networkPolicy === "deny-all" ? "none" : networkPolicy === void 0 || networkPolicy === "allow-all" ? "unrestricted" : allowsAllNetworkDestinations(networkPolicy) ? "unrestricted" : hasEffectiveNetworkPolicy(networkPolicy) ? "restricted" : "unknown",
|
|
74
|
+
processes: "arbitrary"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function allowsAllNetworkDestinations(networkPolicy) {
|
|
78
|
+
if (hasOwnArrayEntries(ownNetworkPolicyMember(ownNetworkPolicyMember(networkPolicy, "subnets"), "deny"))) return false;
|
|
79
|
+
const allow = ownNetworkPolicyMember(networkPolicy, "allow");
|
|
80
|
+
return Array.isArray(allow) ? hasOwnArrayValue(allow, "*") : Boolean(allow && Object.hasOwn(allow, "*"));
|
|
81
|
+
}
|
|
82
|
+
function hasEffectiveNetworkPolicy(networkPolicy) {
|
|
83
|
+
const allow = ownNetworkPolicyMember(networkPolicy, "allow");
|
|
84
|
+
if (hasOwnArrayEntries(allow)) return true;
|
|
85
|
+
if (allow && !Array.isArray(allow) && Object.keys(allow).length > 0) return true;
|
|
86
|
+
const subnets = ownNetworkPolicyMember(networkPolicy, "subnets");
|
|
87
|
+
return hasOwnArrayEntries(ownNetworkPolicyMember(subnets, "allow")) || hasOwnArrayEntries(ownNetworkPolicyMember(subnets, "deny"));
|
|
88
|
+
}
|
|
89
|
+
function hasOwnArrayEntries(value) {
|
|
90
|
+
if (!Array.isArray(value)) return false;
|
|
91
|
+
for (let index = 0; index < value.length; index++) if (Object.hasOwn(value, index)) return true;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
function hasOwnArrayValue(value, expected) {
|
|
95
|
+
for (let index = 0; index < value.length; index++) if (Object.hasOwn(value, index) && value[index] === expected) return true;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
function ownNetworkPolicyMember(value, key) {
|
|
99
|
+
return value !== null && value !== void 0 && Object.hasOwn(value, key) ? value[key] : void 0;
|
|
100
|
+
}
|
|
101
|
+
async function loadVercelSandbox() {
|
|
102
|
+
try {
|
|
103
|
+
const { Sandbox } = await import("@vercel/sandbox");
|
|
104
|
+
return async (options) => await Sandbox.create(options);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw sandboxErrorDiagnostics.SANDBOX_R0142({ message: `[vitehub] The vercel Sandbox runtime requires @vercel/sandbox: ${error instanceof Error ? error.message : error}` });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function isMissingFile(error) {
|
|
110
|
+
return error !== null && typeof error === "object" && Object.hasOwn(error, "code") && Reflect.get(error, "code") === "ENOENT";
|
|
111
|
+
}
|
|
112
|
+
function createVercelSession(id, instance, baseEnv, ports, workspace) {
|
|
113
|
+
let destroyPromise;
|
|
114
|
+
const startCommand = (options) => {
|
|
115
|
+
options.abortSignal?.throwIfAborted();
|
|
116
|
+
return instance.runCommand({
|
|
117
|
+
args: ["-c", options.command],
|
|
118
|
+
cmd: "sh",
|
|
119
|
+
cwd: options.workingDirectory ?? workspace,
|
|
120
|
+
detached: true,
|
|
121
|
+
env: {
|
|
122
|
+
...baseEnv,
|
|
123
|
+
...options.env
|
|
124
|
+
},
|
|
125
|
+
signal: options.abortSignal,
|
|
126
|
+
...options.stdin ? { stdin: true } : {}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const run = async (options) => {
|
|
130
|
+
const process = await startCommand(options);
|
|
131
|
+
let abort;
|
|
132
|
+
const aborted = new Promise((_, reject) => {
|
|
133
|
+
abort = () => {
|
|
134
|
+
process.kill("SIGKILL").catch(() => void 0);
|
|
135
|
+
reject(options.abortSignal.reason);
|
|
136
|
+
};
|
|
137
|
+
options.abortSignal?.addEventListener("abort", abort, { once: true });
|
|
138
|
+
});
|
|
139
|
+
try {
|
|
140
|
+
return await Promise.race([collectProcessOutput(process), aborted]);
|
|
141
|
+
} finally {
|
|
142
|
+
if (abort) options.abortSignal?.removeEventListener("abort", abort);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const fs = instance.fs;
|
|
146
|
+
return {
|
|
147
|
+
defaultWorkingDirectory: workspace,
|
|
148
|
+
id,
|
|
149
|
+
...ports?.length ? { ports } : {},
|
|
150
|
+
async destroy() {
|
|
151
|
+
destroyPromise ??= (async () => {
|
|
152
|
+
if (instance.stop) await instance.stop({ blocking: true });
|
|
153
|
+
else await instance[Symbol.asyncDispose]?.();
|
|
154
|
+
})();
|
|
155
|
+
try {
|
|
156
|
+
await destroyPromise;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
destroyPromise = void 0;
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
async existsFile({ abortSignal, path }) {
|
|
163
|
+
abortSignal?.throwIfAborted();
|
|
164
|
+
if (fs?.exists) return await fs.exists(path, { signal: abortSignal });
|
|
165
|
+
if (fs?.access) try {
|
|
166
|
+
await fs.access(path, { signal: abortSignal });
|
|
167
|
+
return true;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (isMissingFile(error)) return false;
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
return (await run({
|
|
173
|
+
abortSignal,
|
|
174
|
+
command: `test -e ${shellQuote(path)}`
|
|
175
|
+
})).exitCode === 0;
|
|
176
|
+
},
|
|
177
|
+
...ports?.length ? { async getPortUrl({ port, protocol = "http" }) {
|
|
178
|
+
if (!ports.includes(port)) throw sandboxErrorDiagnostics.SANDBOX_R0143({ message: `[vitehub] Vercel Sandbox port ${port} was not declared in runtime.ports.` });
|
|
179
|
+
const url = new URL(instance.domain(port));
|
|
180
|
+
url.protocol = protocol === "ws" ? url.protocol === "https:" ? "wss:" : "ws:" : `${protocol}:`;
|
|
181
|
+
return String(url);
|
|
182
|
+
} } : void 0,
|
|
183
|
+
async listFiles({ abortSignal, path, recursive }) {
|
|
184
|
+
abortSignal?.throwIfAborted();
|
|
185
|
+
if (!fs?.readdir) return await listCommandFiles(run, {
|
|
186
|
+
abortSignal,
|
|
187
|
+
path,
|
|
188
|
+
recursive
|
|
189
|
+
}, (result) => sandboxErrorDiagnostics.SANDBOX_R0145({ message: result.stderr }));
|
|
190
|
+
const entries = [];
|
|
191
|
+
await visit(path);
|
|
192
|
+
return entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
193
|
+
async function visit(directory) {
|
|
194
|
+
for (const name of await fs.readdir(directory, { signal: abortSignal })) {
|
|
195
|
+
const child = posix.join(directory, name);
|
|
196
|
+
const stat = fs.lstat ? await fs.lstat(child, { signal: abortSignal }) : await fs.stat(child, { signal: abortSignal });
|
|
197
|
+
entries.push({
|
|
198
|
+
path: child,
|
|
199
|
+
size: stat.isFile() ? stat.size : void 0,
|
|
200
|
+
type: stat.isDirectory() ? "directory" : stat.isSymbolicLink() ? "symlink" : "file"
|
|
201
|
+
});
|
|
202
|
+
if (recursive && stat.isDirectory()) await visit(child);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
async makeDirectory({ abortSignal, path, recursive }) {
|
|
207
|
+
abortSignal?.throwIfAborted();
|
|
208
|
+
if (fs?.mkdir) {
|
|
209
|
+
await fs.mkdir(path, {
|
|
210
|
+
recursive,
|
|
211
|
+
signal: abortSignal
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (recursive) {
|
|
216
|
+
await instance.mkDir(path, { signal: abortSignal });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
await instance.mkDir(path, { signal: abortSignal });
|
|
220
|
+
},
|
|
221
|
+
...fs?.rename ? { async moveFile({ abortSignal, destination, source }) {
|
|
222
|
+
await fs.rename(source, destination, { signal: abortSignal });
|
|
223
|
+
} } : {},
|
|
224
|
+
async readBinaryFile({ abortSignal, path }) {
|
|
225
|
+
abortSignal?.throwIfAborted();
|
|
226
|
+
try {
|
|
227
|
+
const contents = fs?.readFile ? await fs.readFile(path, { signal: abortSignal }) : await instance.readFileToBuffer({ path }, { signal: abortSignal });
|
|
228
|
+
return contents === null ? null : new Uint8Array(contents);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (isMissingFile(error)) return null;
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
async removeFile({ abortSignal, path, recursive }) {
|
|
235
|
+
abortSignal?.throwIfAborted();
|
|
236
|
+
if (fs?.rm) {
|
|
237
|
+
await fs.rm(path, {
|
|
238
|
+
force: true,
|
|
239
|
+
recursive,
|
|
240
|
+
signal: abortSignal
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const result = await run({
|
|
245
|
+
abortSignal,
|
|
246
|
+
command: recursive ? `rm -rf -- ${shellQuote(path)}` : `if test -d ${shellQuote(path)}; then rmdir -- ${shellQuote(path)}; else rm -f -- ${shellQuote(path)}; fi`
|
|
247
|
+
});
|
|
248
|
+
if (result.exitCode !== 0) throw sandboxErrorDiagnostics.SANDBOX_R0144({ message: result.stderr });
|
|
249
|
+
},
|
|
250
|
+
run,
|
|
251
|
+
async spawn(options) {
|
|
252
|
+
const process = await startCommand(options);
|
|
253
|
+
return killOnAbort(vercelProcess(process, options.stdin), options.abortSignal);
|
|
254
|
+
},
|
|
255
|
+
async stop() {},
|
|
256
|
+
async writeBinaryFile({ abortSignal, content, path }) {
|
|
257
|
+
abortSignal?.throwIfAborted();
|
|
258
|
+
if (fs?.writeFile) {
|
|
259
|
+
await fs.writeFile(path, content, { signal: abortSignal });
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
await instance.writeFiles([{
|
|
263
|
+
content,
|
|
264
|
+
path
|
|
265
|
+
}], { signal: abortSignal });
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function vercelProcess(process, stdin) {
|
|
270
|
+
const wait = process.wait();
|
|
271
|
+
return {
|
|
272
|
+
...streamLogs(process),
|
|
273
|
+
...stdin ? { stdin: new WritableStream({
|
|
274
|
+
abort: async () => await process.closeStdin(),
|
|
275
|
+
close: async () => await process.closeStdin(),
|
|
276
|
+
write: async (chunk) => await process.writeStdin(chunk)
|
|
277
|
+
}) } : {},
|
|
278
|
+
async kill(signal) {
|
|
279
|
+
await process.kill(vercelSignal(signal));
|
|
280
|
+
},
|
|
281
|
+
async wait() {
|
|
282
|
+
return await wait;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** Bounds each channel independently so an unread channel cannot stall its sibling. */
|
|
287
|
+
function streamLogs(command) {
|
|
288
|
+
const bufferLimit = 1048576;
|
|
289
|
+
const encoder = new TextEncoder();
|
|
290
|
+
const abort = new AbortController();
|
|
291
|
+
const iterator = command.logs({ signal: abort.signal })[Symbol.asyncIterator]();
|
|
292
|
+
const open = /* @__PURE__ */ new Map();
|
|
293
|
+
let stopped = false;
|
|
294
|
+
const stop = async () => {
|
|
295
|
+
if (stopped) return;
|
|
296
|
+
stopped = true;
|
|
297
|
+
abort.abort();
|
|
298
|
+
try {
|
|
299
|
+
await iterator.return?.();
|
|
300
|
+
} catch {}
|
|
301
|
+
};
|
|
302
|
+
const stream = (name) => new ReadableStream({
|
|
303
|
+
cancel() {
|
|
304
|
+
open.delete(name);
|
|
305
|
+
if (open.size === 0) return stop();
|
|
306
|
+
},
|
|
307
|
+
start(controller) {
|
|
308
|
+
open.set(name, controller);
|
|
309
|
+
}
|
|
310
|
+
}, new ByteLengthQueuingStrategy({ highWaterMark: bufferLimit }));
|
|
311
|
+
const output = {
|
|
312
|
+
stderr: stream("stderr"),
|
|
313
|
+
stdout: stream("stdout")
|
|
314
|
+
};
|
|
315
|
+
(async () => {
|
|
316
|
+
try {
|
|
317
|
+
while (open.size > 0) {
|
|
318
|
+
const entry = await iterator.next();
|
|
319
|
+
if (entry.done) break;
|
|
320
|
+
const line = entry.value;
|
|
321
|
+
const controller = open.get(line.stream);
|
|
322
|
+
if (!controller || line.data.length === 0) continue;
|
|
323
|
+
const chunk = new Uint8Array(Math.min(line.data.length * 3, controller.desiredSize ?? 0));
|
|
324
|
+
const { read, written } = encoder.encodeInto(line.data, chunk);
|
|
325
|
+
if (read < line.data.length) {
|
|
326
|
+
controller.error(sandboxErrorDiagnostics.SANDBOX_R0159({ message: `Vercel ${line.stream} exceeded the ${bufferLimit}-byte output buffer limit. Consume both streams concurrently or cancel unused output.` }));
|
|
327
|
+
open.delete(line.stream);
|
|
328
|
+
} else controller.enqueue(written === chunk.byteLength ? chunk : chunk.slice(0, written));
|
|
329
|
+
}
|
|
330
|
+
for (const controller of open.values()) controller.close();
|
|
331
|
+
} catch (error) {
|
|
332
|
+
for (const controller of open.values()) controller.error(error);
|
|
333
|
+
} finally {
|
|
334
|
+
open.clear();
|
|
335
|
+
await stop();
|
|
336
|
+
}
|
|
337
|
+
})();
|
|
338
|
+
return output;
|
|
339
|
+
}
|
|
340
|
+
function vercelSignal(signal) {
|
|
341
|
+
if (signal === void 0) return void 0;
|
|
342
|
+
if (/^\d+$/.test(signal)) return Number(signal);
|
|
343
|
+
const name = `SIG${signal.toUpperCase().replace(/^SIG/, "")}`;
|
|
344
|
+
const known = vercelSignalNames.find((value) => value === name);
|
|
345
|
+
if (!known) throw sandboxErrorDiagnostics.SANDBOX_R0165({
|
|
346
|
+
runtime: "Vercel",
|
|
347
|
+
signal: String(signal)
|
|
348
|
+
});
|
|
349
|
+
return known;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
export { loadVercelSandbox as n, vercel_exports as r, createVercelRuntime as t };
|
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/sandbox",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Portable, isolated Sandboxes for ViteHub Agents, and Sandbox Tasks that run named package projects in them.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"agent",
|
|
7
|
+
"ai-agents",
|
|
6
8
|
"cloudflare",
|
|
9
|
+
"code-execution",
|
|
10
|
+
"runtime",
|
|
7
11
|
"sandbox",
|
|
12
|
+
"typescript",
|
|
8
13
|
"vercel",
|
|
9
14
|
"vite",
|
|
10
15
|
"vitehub"
|
|
11
16
|
],
|
|
12
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://vitehub.dev",
|
|
13
18
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
19
|
"license": "Apache-2.0",
|
|
15
20
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -26,96 +31,145 @@
|
|
|
26
31
|
"sideEffects": false,
|
|
27
32
|
"types": "./dist/index.d.ts",
|
|
28
33
|
"imports": {
|
|
29
|
-
"#vitehub-sandbox-provider-loader": {
|
|
30
|
-
"types": "./dist/runtime/provider-loader.d.ts",
|
|
31
|
-
"default": "./dist/runtime/provider-loader.js"
|
|
34
|
+
"#vitehub-sandbox-task-provider-loader": {
|
|
35
|
+
"types": "./dist/task/runtime/provider-loader.d.ts",
|
|
36
|
+
"default": "./dist/task/runtime/provider-loader.js"
|
|
32
37
|
},
|
|
33
|
-
"#vitehub-sandbox-registry": {
|
|
34
|
-
"types": "./dist/runtime/empty-registry.d.ts",
|
|
35
|
-
"default": "./dist/runtime/empty-registry.js"
|
|
38
|
+
"#vitehub-sandbox-task-registry": {
|
|
39
|
+
"types": "./dist/task/runtime/empty-registry.d.ts",
|
|
40
|
+
"default": "./dist/task/runtime/empty-registry.js"
|
|
36
41
|
}
|
|
37
42
|
},
|
|
38
43
|
"exports": {
|
|
39
44
|
".": {
|
|
40
45
|
"types": "./dist/index.d.ts",
|
|
41
|
-
"import": "./dist/index.js"
|
|
46
|
+
"import": "./dist/index.js",
|
|
47
|
+
"default": "./dist/index.js"
|
|
42
48
|
},
|
|
43
|
-
"./
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
49
|
+
"./_internal/cloudflare": {
|
|
50
|
+
"types": "./dist/internal/cloudflare.d.ts",
|
|
51
|
+
"import": "./dist/internal/cloudflare.js",
|
|
52
|
+
"default": "./dist/internal/cloudflare.js"
|
|
46
53
|
},
|
|
47
|
-
"./
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/
|
|
54
|
+
"./_internal/toolchain": {
|
|
55
|
+
"types": "./dist/internal/host-toolchain.d.ts",
|
|
56
|
+
"import": "./dist/internal/host-toolchain.js",
|
|
57
|
+
"default": "./dist/internal/host-toolchain.js"
|
|
50
58
|
},
|
|
51
|
-
"./
|
|
52
|
-
"types": "./dist/
|
|
53
|
-
"import": "./dist/
|
|
59
|
+
"./_internal/vercel": {
|
|
60
|
+
"types": "./dist/internal/vercel.d.ts",
|
|
61
|
+
"import": "./dist/internal/vercel.js",
|
|
62
|
+
"default": "./dist/internal/vercel.js"
|
|
54
63
|
},
|
|
55
|
-
"./
|
|
56
|
-
"types": "./dist/
|
|
57
|
-
"import": "./dist/
|
|
64
|
+
"./ssh": {
|
|
65
|
+
"types": "./dist/ssh.d.ts",
|
|
66
|
+
"import": "./dist/ssh.js",
|
|
67
|
+
"default": "./dist/ssh.js"
|
|
68
|
+
},
|
|
69
|
+
"./task": {
|
|
70
|
+
"types": "./dist/task/index.d.ts",
|
|
71
|
+
"import": "./dist/task/index.js",
|
|
72
|
+
"default": "./dist/task/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./task/runtime/empty-registry": {
|
|
75
|
+
"types": "./dist/task/runtime/empty-registry.d.ts",
|
|
76
|
+
"import": "./dist/task/runtime/empty-registry.js",
|
|
77
|
+
"default": "./dist/task/runtime/empty-registry.js"
|
|
78
|
+
},
|
|
79
|
+
"./task/runtime/provider-loader": {
|
|
80
|
+
"types": "./dist/task/runtime/provider-loader.d.ts",
|
|
81
|
+
"import": "./dist/task/runtime/provider-loader.js",
|
|
82
|
+
"default": "./dist/task/runtime/provider-loader.js"
|
|
83
|
+
},
|
|
84
|
+
"./task/runtime/state": {
|
|
85
|
+
"types": "./dist/task/runtime/state.d.ts",
|
|
86
|
+
"import": "./dist/task/runtime/state.js",
|
|
87
|
+
"default": "./dist/task/runtime/state.js"
|
|
88
|
+
},
|
|
89
|
+
"./task/vite": {
|
|
90
|
+
"types": "./dist/task/vite.d.ts",
|
|
91
|
+
"import": "./dist/task/vite.js",
|
|
92
|
+
"default": "./dist/task/vite.js"
|
|
58
93
|
},
|
|
59
94
|
"./package.json": "./package.json",
|
|
60
|
-
"./_internal/runtime": {
|
|
61
|
-
"types": "./dist/index.d.ts",
|
|
62
|
-
"import": "./dist/index.js"
|
|
95
|
+
"./_internal/task/runtime": {
|
|
96
|
+
"types": "./dist/task/index.d.ts",
|
|
97
|
+
"import": "./dist/task/index.js",
|
|
98
|
+
"default": "./dist/task/index.js"
|
|
63
99
|
},
|
|
64
|
-
"./_internal/runtime/providers/cloudflare": {
|
|
65
|
-
"types": "./dist/runtime/providers/cloudflare.d.ts",
|
|
66
|
-
"import": "./dist/runtime/providers/cloudflare.js"
|
|
100
|
+
"./_internal/task/runtime/providers/cloudflare": {
|
|
101
|
+
"types": "./dist/task/runtime/providers/cloudflare.d.ts",
|
|
102
|
+
"import": "./dist/task/runtime/providers/cloudflare.js",
|
|
103
|
+
"default": "./dist/task/runtime/providers/cloudflare.js"
|
|
67
104
|
},
|
|
68
|
-
"./_internal/runtime/providers/vercel": {
|
|
69
|
-
"types": "./dist/runtime/providers/vercel.d.ts",
|
|
70
|
-
"import": "./dist/runtime/providers/vercel.js"
|
|
105
|
+
"./_internal/task/runtime/providers/vercel": {
|
|
106
|
+
"types": "./dist/task/runtime/providers/vercel.d.ts",
|
|
107
|
+
"import": "./dist/task/runtime/providers/vercel.js",
|
|
108
|
+
"default": "./dist/task/runtime/providers/vercel.js"
|
|
71
109
|
}
|
|
72
110
|
},
|
|
73
111
|
"dependencies": {
|
|
74
|
-
"@vite-hub/
|
|
75
|
-
"@vite-hub/runtime": "0.0.4",
|
|
76
|
-
"esbuild": "^0.28.1",
|
|
77
|
-
"h3": "2.0.1-rc.25",
|
|
112
|
+
"@vite-hub/runtime": "0.3.0",
|
|
78
113
|
"local-pkg": "^1.2.1",
|
|
79
114
|
"mlly": "^1.8.2",
|
|
115
|
+
"nostics": "1.4.0",
|
|
80
116
|
"pathe": "^2.0.3",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"unimport": "^6.3.0",
|
|
86
|
-
"yaml": "^2.9.0"
|
|
117
|
+
"picomatch": "^4.0.7",
|
|
118
|
+
"semver": "^7.8.5",
|
|
119
|
+
"unimport": "^6.5.0",
|
|
120
|
+
"yaml": "^2.9.1"
|
|
87
121
|
},
|
|
88
122
|
"devDependencies": {
|
|
123
|
+
"@cloudflare/sandbox": "^1.0.3",
|
|
124
|
+
"@types/node": "^24.19.1",
|
|
125
|
+
"@types/picomatch": "^4.0.3",
|
|
126
|
+
"@types/semver": "^7.8.0",
|
|
127
|
+
"@types/ssh2": "^1.15.6",
|
|
128
|
+
"@vercel/sandbox": "^3.9.1 || ^4.0.0",
|
|
129
|
+
"@vite-hub/internal": "0.0.1",
|
|
130
|
+
"esbuild": "^0.28.2",
|
|
131
|
+
"miniflare": "4.20260730.0",
|
|
89
132
|
"ofetch": "^1.5.1",
|
|
90
|
-
"publint": "^0.3.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
133
|
+
"publint": "^0.3.25",
|
|
134
|
+
"rollup": "^4.64.0",
|
|
135
|
+
"ssh2": "^1.17.0",
|
|
136
|
+
"typescript": "^6.0.3",
|
|
137
|
+
"vite": "^8.2.2",
|
|
138
|
+
"vite-plus": "^0.3.3",
|
|
139
|
+
"vitest": "^4.1.11",
|
|
140
|
+
"zod": "^4.6.7"
|
|
95
141
|
},
|
|
96
142
|
"peerDependencies": {
|
|
97
|
-
"@cloudflare/sandbox": "^0.
|
|
98
|
-
"
|
|
143
|
+
"@cloudflare/sandbox": "^1.0.3",
|
|
144
|
+
"ssh2": "^1.17.0",
|
|
145
|
+
"@vercel/sandbox": "^3.9.1 || ^4.0.0",
|
|
146
|
+
"typescript": "^5.8.0 || ^6.0.0",
|
|
99
147
|
"vite": ">=8.0.0"
|
|
100
148
|
},
|
|
101
149
|
"peerDependenciesMeta": {
|
|
102
150
|
"@cloudflare/sandbox": {
|
|
103
151
|
"optional": true
|
|
104
152
|
},
|
|
153
|
+
"ssh2": {
|
|
154
|
+
"optional": true
|
|
155
|
+
},
|
|
105
156
|
"@vercel/sandbox": {
|
|
106
157
|
"optional": true
|
|
107
158
|
},
|
|
159
|
+
"typescript": {
|
|
160
|
+
"optional": true
|
|
161
|
+
},
|
|
108
162
|
"vite": {
|
|
109
163
|
"optional": true
|
|
110
164
|
}
|
|
111
165
|
},
|
|
112
166
|
"engines": {
|
|
113
|
-
"node": ">=
|
|
167
|
+
"node": ">=22.18.0"
|
|
114
168
|
},
|
|
115
169
|
"scripts": {
|
|
116
170
|
"build": "vp pack",
|
|
117
171
|
"dev": "vp pack --watch",
|
|
118
|
-
"typecheck": "
|
|
119
|
-
"test": "vp run -t @vite-hub/sandbox#build && vp test"
|
|
172
|
+
"typecheck": "vp run --cache -t @vite-hub/sandbox#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
173
|
+
"test": "vp run --cache -t @vite-hub/sandbox#build && vp test"
|
|
120
174
|
}
|
|
121
175
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
3
|
-
const runtimeGlobal = globalThis;
|
|
4
|
-
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
5
|
-
function getActiveCloudflareEnv() {
|
|
6
|
-
const scoped = activeEnvStorage.getStore();
|
|
7
|
-
return scoped ? scoped.env : globalThis.__env__;
|
|
8
|
-
}
|
|
9
|
-
function getCloudflareEnv(event) {
|
|
10
|
-
const target = event;
|
|
11
|
-
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || target?.node?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { getCloudflareEnv as t };
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
|
-
import { VercelBoxNetworkPolicy, VercelBoxSource } from "@vite-hub/box";
|
|
3
|
-
|
|
4
|
-
//#region src/project.d.ts
|
|
5
|
-
type SandboxPackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn';
|
|
6
|
-
interface SandboxProjectFile {
|
|
7
|
-
contents: string;
|
|
8
|
-
encoding: 'base64';
|
|
9
|
-
mode?: number;
|
|
10
|
-
}
|
|
11
|
-
interface SandboxProject {
|
|
12
|
-
digest: string;
|
|
13
|
-
files: Record<string, SandboxProjectFile>;
|
|
14
|
-
install: {
|
|
15
|
-
args: string[];
|
|
16
|
-
command: SandboxPackageManager;
|
|
17
|
-
cwd: string;
|
|
18
|
-
};
|
|
19
|
-
options?: SandboxProjectOptions;
|
|
20
|
-
packagePath: string;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/module-types.d.ts
|
|
24
|
-
type SandboxProvider = 'cloudflare' | 'vercel';
|
|
25
|
-
interface CloudflareSandboxOptions {
|
|
26
|
-
sleepAfter?: string | number;
|
|
27
|
-
keepAlive?: boolean;
|
|
28
|
-
normalizeId?: boolean;
|
|
29
|
-
}
|
|
30
|
-
interface VercelSandboxProviderOptions {
|
|
31
|
-
provider: 'vercel';
|
|
32
|
-
runtime?: string;
|
|
33
|
-
timeout?: number;
|
|
34
|
-
cpu?: number;
|
|
35
|
-
ports?: number[];
|
|
36
|
-
source?: VercelBoxSource;
|
|
37
|
-
networkPolicy?: VercelBoxNetworkPolicy;
|
|
38
|
-
token?: string;
|
|
39
|
-
teamId?: string;
|
|
40
|
-
projectId?: string;
|
|
41
|
-
}
|
|
42
|
-
interface CloudflareSandboxDefinitionProviderOptions {
|
|
43
|
-
provider: 'cloudflare';
|
|
44
|
-
binding?: string;
|
|
45
|
-
className?: string;
|
|
46
|
-
migrationTag?: string;
|
|
47
|
-
name?: string;
|
|
48
|
-
sandboxId?: string;
|
|
49
|
-
sleepAfter?: CloudflareSandboxOptions['sleepAfter'];
|
|
50
|
-
keepAlive?: CloudflareSandboxOptions['keepAlive'];
|
|
51
|
-
normalizeId?: CloudflareSandboxOptions['normalizeId'];
|
|
52
|
-
}
|
|
53
|
-
type SandboxDefinitionProviderOptions = VercelSandboxProviderOptions | CloudflareSandboxDefinitionProviderOptions;
|
|
54
|
-
type AgentSandboxConfig = SandboxDefinitionProviderOptions | {
|
|
55
|
-
provider?: undefined;
|
|
56
|
-
name?: string;
|
|
57
|
-
};
|
|
58
|
-
interface SandboxDefinitionBundle {
|
|
59
|
-
entry: string;
|
|
60
|
-
execution?: 'definition' | 'module';
|
|
61
|
-
modules: Record<string, string>;
|
|
62
|
-
project?: SandboxProject;
|
|
63
|
-
}
|
|
64
|
-
interface SandboxExecutionOptions {
|
|
65
|
-
context?: Record<string, unknown>;
|
|
66
|
-
sandboxId?: string;
|
|
67
|
-
}
|
|
68
|
-
type SandboxDefinitionHandler<TPayload = unknown, TResult = unknown> = (payload?: TPayload, context?: Record<string, unknown>) => TResult | Promise<TResult>;
|
|
69
|
-
type SandboxDefinitionPayload<THandler extends (...args: any[]) => any> = Parameters<THandler> extends [infer TPayload, ...unknown[]] ? TPayload : unknown;
|
|
70
|
-
type SandboxDefinitionResult<THandler extends (...args: any[]) => any> = Awaited<ReturnType<THandler>>;
|
|
71
|
-
interface SandboxDefinitionOptions {
|
|
72
|
-
timeout?: number;
|
|
73
|
-
env?: Record<string, string>;
|
|
74
|
-
}
|
|
75
|
-
interface SandboxProjectOptions {
|
|
76
|
-
timeout?: number;
|
|
77
|
-
}
|
|
78
|
-
interface SandboxDefinitionInput<TPayload = unknown, TResult = unknown> extends SandboxDefinitionOptions {
|
|
79
|
-
/** Force project packaging on or off. Omit to detect project use automatically. */
|
|
80
|
-
project?: boolean;
|
|
81
|
-
run: SandboxDefinitionHandler<TPayload, TResult>;
|
|
82
|
-
}
|
|
83
|
-
interface SandboxDefinition<TPayload = unknown, TResult = unknown> {
|
|
84
|
-
run: SandboxDefinitionHandler<TPayload, TResult>;
|
|
85
|
-
options?: SandboxDefinitionOptions;
|
|
86
|
-
}
|
|
87
|
-
type SandboxDefinitionFromHandler<THandler extends (...args: any[]) => any> = SandboxDefinition<SandboxDefinitionPayload<THandler>, SandboxDefinitionResult<THandler>> & {
|
|
88
|
-
run: THandler;
|
|
89
|
-
};
|
|
90
|
-
type SandboxRunResult<TResult = unknown> = [error: null, value: TResult] | [error: ViteHubError<`SANDBOX_${string}`>, value: undefined];
|
|
91
|
-
declare function getSandboxFeatureProvider(config?: AgentSandboxConfig | false): SandboxDefinitionProviderOptions | undefined;
|
|
92
|
-
//#endregion
|
|
93
|
-
export { SandboxDefinitionBundle as a, SandboxDefinitionInput as c, SandboxExecutionOptions as d, SandboxProjectOptions as f, getSandboxFeatureProvider as g, VercelSandboxProviderOptions as h, SandboxDefinition as i, SandboxDefinitionOptions as l, SandboxRunResult as m, CloudflareSandboxDefinitionProviderOptions as n, SandboxDefinitionFromHandler as o, SandboxProvider as p, CloudflareSandboxOptions as r, SandboxDefinitionHandler as s, AgentSandboxConfig as t, SandboxDefinitionProviderOptions as u };
|