@vite-hub/sandbox 0.0.4 → 0.1.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 +327 -34
- package/dist/cloudflare-DO0h3Ncf.js +281 -0
- package/dist/cloudflare-env-BBJaBbuQ.js +39 -0
- package/dist/crabbox-BFCdf41h.js +1106 -0
- package/dist/error-diagnostics-BSysPv-D.js +166 -0
- package/dist/error-diagnostics-dGQqfgLt.js +99 -0
- package/dist/file-listing-DECFTdSl.js +26 -0
- package/dist/file-lock-CxyVl4Cv.js +73 -0
- package/dist/index-CXej1Bt0.d.ts +519 -0
- package/dist/index.d.ts +2 -69
- package/dist/index.js +277 -1183
- package/dist/internal/cloudflare.d.ts +4 -0
- package/dist/internal/cloudflare.js +16 -0
- package/dist/internal/host-toolchain.d.ts +22 -0
- package/dist/internal/host-toolchain.js +97 -0
- package/dist/internal/vercel.d.ts +4 -0
- package/dist/internal/vercel.js +16 -0
- package/dist/module-types-BfyRBaiP.js +7 -0
- package/dist/module-types-Cis4hrF1.d.ts +95 -0
- package/dist/remote-1Jz2oUMK.js +247 -0
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime-DHp6ImeP.js +32 -0
- package/dist/runtime-type-DrmrW5m5.js +42 -0
- package/dist/session-DD0S1PDC.js +337 -0
- package/dist/shell-quote-Q3u3plif.js +6 -0
- package/dist/ssh.d.ts +55 -0
- package/dist/ssh.js +219 -0
- package/dist/task/index.d.ts +67 -0
- package/dist/task/index.js +1523 -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 +20 -0
- package/dist/task/runtime/provider-loader.js +19 -0
- package/dist/task/runtime/providers/cloudflare.d.ts +28 -0
- package/dist/task/runtime/providers/cloudflare.js +26 -0
- package/dist/task/runtime/providers/vercel.d.ts +12 -0
- package/dist/{runtime → task/runtime}/providers/vercel.js +17 -14
- package/dist/task/runtime/state.d.ts +24 -0
- package/dist/task/runtime/state.js +73 -0
- package/dist/task/vite.d.ts +360 -0
- package/dist/{vite.js → task/vite.js} +964 -645
- package/dist/toolchain-BUVXtQ2m.js +527 -0
- package/dist/trusted-host-DNMJ-Oig.js +872 -0
- package/dist/vercel-Jtxa9TJx.js +279 -0
- package/package.json +99 -48
- 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/state.d.ts +0 -26
- package/dist/runtime/state.js +0 -72
- package/dist/vite.d.ts +0 -48
|
@@ -0,0 +1,279 @@
|
|
|
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-BSysPv-D.js";
|
|
4
|
+
import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
|
|
5
|
+
import { t as listCommandFiles } from "./file-listing-DECFTdSl.js";
|
|
6
|
+
import { i as resolveRemoteEnvironment, n as openRemoteSandbox, o as snapshotStream, r as remoteSandboxPlan, t as collectProcessOutput } from "./remote-1Jz2oUMK.js";
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { posix } from "node:path";
|
|
9
|
+
//#region src/vercel.ts
|
|
10
|
+
var vercel_exports = /* @__PURE__ */ __exportAll({ createVercelRuntime: () => createVercelRuntime });
|
|
11
|
+
const vercelSandboxPackage = "@vercel/sandbox";
|
|
12
|
+
function createVercelRuntime(options = {}) {
|
|
13
|
+
const runtime = options.runtime ?? "node24";
|
|
14
|
+
const executionAuthority = vercelExecutionAuthority(options.networkPolicy);
|
|
15
|
+
return markBuiltInSandboxRuntime({
|
|
16
|
+
name: "vercel",
|
|
17
|
+
async prepare(input) {
|
|
18
|
+
return remoteSandboxPlan(input, {
|
|
19
|
+
executionAuthority,
|
|
20
|
+
runtime: "vercel"
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
async open(input, openOptions) {
|
|
24
|
+
const workspace = options.source ? "/vercel/sandbox" : "/workspace";
|
|
25
|
+
const env = await resolveRemoteEnvironment(input, { workspace });
|
|
26
|
+
const instance = await (options.create ?? await loadVercelSandbox())({
|
|
27
|
+
runtime,
|
|
28
|
+
persistent: false,
|
|
29
|
+
signal: openOptions?.signal,
|
|
30
|
+
timeout: options.timeout ?? 3e5,
|
|
31
|
+
...options.cpu ? { resources: { vcpus: options.cpu } } : {},
|
|
32
|
+
...options.ports ? { ports: options.ports } : {},
|
|
33
|
+
...options.source ? { source: options.source } : {},
|
|
34
|
+
...options.networkPolicy ? { networkPolicy: options.networkPolicy } : {},
|
|
35
|
+
...options.token ? { token: options.token } : {},
|
|
36
|
+
...options.teamId ? { teamId: options.teamId } : {},
|
|
37
|
+
...options.projectId ? { projectId: options.projectId } : {}
|
|
38
|
+
});
|
|
39
|
+
const runtimeSession = createVercelSession(openOptions?.id ?? `vitehub-${randomUUID()}`, instance, env, options.ports, workspace);
|
|
40
|
+
return await openRemoteSandbox(input, runtimeSession, {
|
|
41
|
+
executionAuthority: openOptions.executionAuthority,
|
|
42
|
+
initialize: openOptions?.initialize,
|
|
43
|
+
runtime: "vercel",
|
|
44
|
+
workspace,
|
|
45
|
+
preserveWorkspace: Boolean(options.source),
|
|
46
|
+
signal: openOptions?.signal
|
|
47
|
+
}, env);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function vercelExecutionAuthority(networkPolicy) {
|
|
52
|
+
return {
|
|
53
|
+
credentials: "unknown",
|
|
54
|
+
environment: "selected",
|
|
55
|
+
filesystem: {
|
|
56
|
+
access: "read-write",
|
|
57
|
+
scope: "sandbox"
|
|
58
|
+
},
|
|
59
|
+
isolation: "microvm",
|
|
60
|
+
network: networkPolicy === "deny-all" ? "none" : networkPolicy === void 0 || networkPolicy === "allow-all" ? "unrestricted" : allowsAllNetworkDestinations(networkPolicy) ? "unrestricted" : hasEffectiveNetworkPolicy(networkPolicy) ? "restricted" : "unknown",
|
|
61
|
+
processes: "arbitrary"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function allowsAllNetworkDestinations(networkPolicy) {
|
|
65
|
+
if (hasOwnArrayEntries(ownNetworkPolicyMember(ownNetworkPolicyMember(networkPolicy, "subnets"), "deny"))) return false;
|
|
66
|
+
const allow = ownNetworkPolicyMember(networkPolicy, "allow");
|
|
67
|
+
return Array.isArray(allow) ? hasOwnArrayValue(allow, "*") : Boolean(allow && Object.hasOwn(allow, "*"));
|
|
68
|
+
}
|
|
69
|
+
function hasEffectiveNetworkPolicy(networkPolicy) {
|
|
70
|
+
const allow = ownNetworkPolicyMember(networkPolicy, "allow");
|
|
71
|
+
if (hasOwnArrayEntries(allow)) return true;
|
|
72
|
+
if (allow && !Array.isArray(allow) && Object.keys(allow).length > 0) return true;
|
|
73
|
+
const subnets = ownNetworkPolicyMember(networkPolicy, "subnets");
|
|
74
|
+
return hasOwnArrayEntries(ownNetworkPolicyMember(subnets, "allow")) || hasOwnArrayEntries(ownNetworkPolicyMember(subnets, "deny"));
|
|
75
|
+
}
|
|
76
|
+
function hasOwnArrayEntries(value) {
|
|
77
|
+
if (!Array.isArray(value)) return false;
|
|
78
|
+
for (let index = 0; index < value.length; index++) if (Object.hasOwn(value, index)) return true;
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
function hasOwnArrayValue(value, expected) {
|
|
82
|
+
for (let index = 0; index < value.length; index++) if (Object.hasOwn(value, index) && value[index] === expected) return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
function ownNetworkPolicyMember(value, key) {
|
|
86
|
+
return value !== null && value !== void 0 && Object.hasOwn(value, key) ? value[key] : void 0;
|
|
87
|
+
}
|
|
88
|
+
async function loadVercelSandbox() {
|
|
89
|
+
try {
|
|
90
|
+
const { Sandbox } = await import(
|
|
91
|
+
/* @vite-ignore */
|
|
92
|
+
vercelSandboxPackage
|
|
93
|
+
);
|
|
94
|
+
return async (options) => await Sandbox.create(options);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw sandboxErrorDiagnostics.SANDBOX_R0142({ message: `[vitehub] The vercel Sandbox runtime requires @vercel/sandbox: ${error instanceof Error ? error.message : error}` });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isMissingFile(error) {
|
|
100
|
+
return error !== null && typeof error === "object" && Object.hasOwn(error, "code") && Reflect.get(error, "code") === "ENOENT";
|
|
101
|
+
}
|
|
102
|
+
function createVercelSession(id, instance, baseEnv, ports, workspace) {
|
|
103
|
+
let destroyPromise;
|
|
104
|
+
const run = async (options) => {
|
|
105
|
+
options.abortSignal?.throwIfAborted();
|
|
106
|
+
const process = await instance.runCommand({
|
|
107
|
+
args: ["-lc", options.command],
|
|
108
|
+
cmd: "sh",
|
|
109
|
+
cwd: options.workingDirectory ?? workspace,
|
|
110
|
+
detached: true,
|
|
111
|
+
env: {
|
|
112
|
+
...baseEnv,
|
|
113
|
+
...options.env
|
|
114
|
+
},
|
|
115
|
+
signal: options.abortSignal
|
|
116
|
+
});
|
|
117
|
+
let abort;
|
|
118
|
+
const aborted = new Promise((_, reject) => {
|
|
119
|
+
abort = () => {
|
|
120
|
+
process.kill().catch(() => void 0);
|
|
121
|
+
reject(options.abortSignal.reason);
|
|
122
|
+
};
|
|
123
|
+
options.abortSignal?.addEventListener("abort", abort, { once: true });
|
|
124
|
+
});
|
|
125
|
+
try {
|
|
126
|
+
return await Promise.race([collectProcessOutput(process), aborted]);
|
|
127
|
+
} finally {
|
|
128
|
+
if (abort) options.abortSignal?.removeEventListener("abort", abort);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const fs = instance.fs;
|
|
132
|
+
return {
|
|
133
|
+
defaultWorkingDirectory: workspace,
|
|
134
|
+
id,
|
|
135
|
+
...ports?.length ? { ports } : {},
|
|
136
|
+
async destroy() {
|
|
137
|
+
destroyPromise ??= (async () => {
|
|
138
|
+
if (instance.stop) await instance.stop({ blocking: true });
|
|
139
|
+
else await instance[Symbol.asyncDispose]?.();
|
|
140
|
+
})();
|
|
141
|
+
try {
|
|
142
|
+
await destroyPromise;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
destroyPromise = void 0;
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async existsFile({ abortSignal, path }) {
|
|
149
|
+
abortSignal?.throwIfAborted();
|
|
150
|
+
if (fs?.exists) return await fs.exists(path, { signal: abortSignal });
|
|
151
|
+
if (fs?.access) try {
|
|
152
|
+
await fs.access(path, { signal: abortSignal });
|
|
153
|
+
return true;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (isMissingFile(error)) return false;
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
return (await run({
|
|
159
|
+
abortSignal,
|
|
160
|
+
command: `test -e ${shellQuote(path)}`
|
|
161
|
+
})).exitCode === 0;
|
|
162
|
+
},
|
|
163
|
+
...ports?.length ? { async getPortUrl({ port, protocol = "http" }) {
|
|
164
|
+
if (!ports.includes(port)) throw sandboxErrorDiagnostics.SANDBOX_R0143({ message: `[vitehub] Vercel Sandbox port ${port} was not declared in runtime.ports.` });
|
|
165
|
+
const url = new URL(instance.domain(port));
|
|
166
|
+
url.protocol = protocol === "ws" ? url.protocol === "https:" ? "wss:" : "ws:" : `${protocol}:`;
|
|
167
|
+
return String(url);
|
|
168
|
+
} } : void 0,
|
|
169
|
+
async listFiles({ abortSignal, path, recursive }) {
|
|
170
|
+
abortSignal?.throwIfAborted();
|
|
171
|
+
if (!fs?.readdir) return await listCommandFiles(run, {
|
|
172
|
+
abortSignal,
|
|
173
|
+
path,
|
|
174
|
+
recursive
|
|
175
|
+
}, (result) => sandboxErrorDiagnostics.SANDBOX_R0145({ message: result.stderr }));
|
|
176
|
+
const entries = [];
|
|
177
|
+
await visit(path);
|
|
178
|
+
return entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
179
|
+
async function visit(directory) {
|
|
180
|
+
for (const name of await fs.readdir(directory, { signal: abortSignal })) {
|
|
181
|
+
const child = posix.join(directory, name);
|
|
182
|
+
const stat = fs.lstat ? await fs.lstat(child, { signal: abortSignal }) : await fs.stat(child, { signal: abortSignal });
|
|
183
|
+
entries.push({
|
|
184
|
+
path: child,
|
|
185
|
+
size: stat.isFile() ? stat.size : void 0,
|
|
186
|
+
type: stat.isDirectory() ? "directory" : stat.isSymbolicLink() ? "symlink" : "file"
|
|
187
|
+
});
|
|
188
|
+
if (recursive && stat.isDirectory()) await visit(child);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async makeDirectory({ abortSignal, path, recursive }) {
|
|
193
|
+
abortSignal?.throwIfAborted();
|
|
194
|
+
if (fs?.mkdir) {
|
|
195
|
+
await fs.mkdir(path, {
|
|
196
|
+
recursive,
|
|
197
|
+
signal: abortSignal
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (recursive) {
|
|
202
|
+
await instance.mkDir(path, { signal: abortSignal });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
await instance.mkDir(path, { signal: abortSignal });
|
|
206
|
+
},
|
|
207
|
+
...fs?.rename ? { async moveFile({ abortSignal, destination, source }) {
|
|
208
|
+
await fs.rename(source, destination, { signal: abortSignal });
|
|
209
|
+
} } : {},
|
|
210
|
+
async readBinaryFile({ abortSignal, path }) {
|
|
211
|
+
abortSignal?.throwIfAborted();
|
|
212
|
+
try {
|
|
213
|
+
const contents = fs?.readFile ? await fs.readFile(path, { signal: abortSignal }) : await instance.readFileToBuffer({ path }, { signal: abortSignal });
|
|
214
|
+
return contents === null ? null : new Uint8Array(contents);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (isMissingFile(error)) return null;
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
async removeFile({ abortSignal, path, recursive }) {
|
|
221
|
+
abortSignal?.throwIfAborted();
|
|
222
|
+
if (fs?.rm) {
|
|
223
|
+
await fs.rm(path, {
|
|
224
|
+
force: true,
|
|
225
|
+
recursive,
|
|
226
|
+
signal: abortSignal
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const result = await run({
|
|
231
|
+
abortSignal,
|
|
232
|
+
command: recursive ? `rm -rf -- ${shellQuote(path)}` : `if test -d ${shellQuote(path)}; then rmdir -- ${shellQuote(path)}; else rm -f -- ${shellQuote(path)}; fi`
|
|
233
|
+
});
|
|
234
|
+
if (result.exitCode !== 0) throw sandboxErrorDiagnostics.SANDBOX_R0144({ message: result.stderr });
|
|
235
|
+
},
|
|
236
|
+
run,
|
|
237
|
+
async spawn(options) {
|
|
238
|
+
options.abortSignal?.throwIfAborted();
|
|
239
|
+
return vercelProcess(await instance.runCommand({
|
|
240
|
+
args: ["-lc", options.command],
|
|
241
|
+
cmd: "sh",
|
|
242
|
+
cwd: options.workingDirectory ?? workspace,
|
|
243
|
+
detached: true,
|
|
244
|
+
env: {
|
|
245
|
+
...baseEnv,
|
|
246
|
+
...options.env
|
|
247
|
+
},
|
|
248
|
+
signal: options.abortSignal
|
|
249
|
+
}));
|
|
250
|
+
},
|
|
251
|
+
async stop() {},
|
|
252
|
+
async writeBinaryFile({ abortSignal, content, path }) {
|
|
253
|
+
abortSignal?.throwIfAborted();
|
|
254
|
+
if (fs?.writeFile) {
|
|
255
|
+
await fs.writeFile(path, content, { signal: abortSignal });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await instance.writeFiles([{
|
|
259
|
+
content,
|
|
260
|
+
path
|
|
261
|
+
}], { signal: abortSignal });
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function vercelProcess(process) {
|
|
266
|
+
const wait = process.wait();
|
|
267
|
+
return {
|
|
268
|
+
stderr: snapshotStream(async () => await process.stderr()),
|
|
269
|
+
stdout: snapshotStream(async () => await process.stdout()),
|
|
270
|
+
async kill() {
|
|
271
|
+
await process.kill();
|
|
272
|
+
},
|
|
273
|
+
async wait() {
|
|
274
|
+
return await wait;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
//#endregion
|
|
279
|
+
export { vercel_exports as n, 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.1.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,85 +31,131 @@
|
|
|
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
|
-
"
|
|
76
|
-
"esbuild": "^0.28.1",
|
|
77
|
-
"h3": "2.0.1-rc.25",
|
|
112
|
+
"@vite-hub/runtime": "0.1.0",
|
|
113
|
+
"esbuild": "^0.28.2",
|
|
78
114
|
"local-pkg": "^1.2.1",
|
|
79
115
|
"mlly": "^1.8.2",
|
|
116
|
+
"nostics": "1.3.0",
|
|
80
117
|
"pathe": "^2.0.3",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"ufo": "^1.6.4",
|
|
85
|
-
"unimport": "^6.3.0",
|
|
86
|
-
"yaml": "^2.9.0"
|
|
118
|
+
"semver": "^7.8.5",
|
|
119
|
+
"unimport": "^6.5.0",
|
|
120
|
+
"yaml": "^2.9.1"
|
|
87
121
|
},
|
|
88
122
|
"devDependencies": {
|
|
123
|
+
"@cloudflare/sandbox": "^0.12.10",
|
|
124
|
+
"@types/node": "^24.19.1",
|
|
125
|
+
"@types/semver": "^7.8.0",
|
|
126
|
+
"@types/ssh2": "^1.15.6",
|
|
127
|
+
"@vercel/sandbox": "^3.5.1",
|
|
89
128
|
"ofetch": "^1.5.1",
|
|
90
|
-
"publint": "^0.3.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
129
|
+
"publint": "^0.3.25",
|
|
130
|
+
"rollup": "^4.64.0",
|
|
131
|
+
"ssh2": "^1.17.0",
|
|
132
|
+
"typescript": "^6.0.3",
|
|
133
|
+
"vite": "^8.2.2",
|
|
134
|
+
"vite-plus": "^0.3.3",
|
|
135
|
+
"vitest": "^4.1.11",
|
|
136
|
+
"zod": "^4.6.7",
|
|
94
137
|
"@vite-hub/internal": "0.0.1"
|
|
95
138
|
},
|
|
96
139
|
"peerDependencies": {
|
|
97
|
-
"@cloudflare/sandbox": "^0.
|
|
98
|
-
"
|
|
140
|
+
"@cloudflare/sandbox": "^0.12.10",
|
|
141
|
+
"ssh2": "^1.17.0",
|
|
142
|
+
"@vercel/sandbox": "^3.5.1",
|
|
143
|
+
"typescript": "^5.8.0 || ^6.0.0",
|
|
99
144
|
"vite": ">=8.0.0"
|
|
100
145
|
},
|
|
101
146
|
"peerDependenciesMeta": {
|
|
102
147
|
"@cloudflare/sandbox": {
|
|
103
148
|
"optional": true
|
|
104
149
|
},
|
|
150
|
+
"ssh2": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
105
153
|
"@vercel/sandbox": {
|
|
106
154
|
"optional": true
|
|
107
155
|
},
|
|
156
|
+
"typescript": {
|
|
157
|
+
"optional": true
|
|
158
|
+
},
|
|
108
159
|
"vite": {
|
|
109
160
|
"optional": true
|
|
110
161
|
}
|
|
@@ -115,7 +166,7 @@
|
|
|
115
166
|
"scripts": {
|
|
116
167
|
"build": "vp pack",
|
|
117
168
|
"dev": "vp pack --watch",
|
|
118
|
-
"typecheck": "
|
|
169
|
+
"typecheck": "vp run --cache -t @vite-hub/sandbox#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
119
170
|
"test": "vp run -t @vite-hub/sandbox#build && vp test"
|
|
120
171
|
}
|
|
121
172
|
}
|
|
@@ -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 };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { l as SandboxDefinitionOptions, p as SandboxProvider, u as SandboxDefinitionProviderOptions } from "./module-types-DKYItiOu.js";
|
|
2
|
-
import { Box } from "@vite-hub/box";
|
|
3
|
-
|
|
4
|
-
//#region src/runtime/provider-loader.d.ts
|
|
5
|
-
interface ResolvedSandboxBox {
|
|
6
|
-
closeAfterRun?: boolean;
|
|
7
|
-
provider: SandboxProvider;
|
|
8
|
-
resolveBox: (requirements: readonly string[]) => Promise<Box>;
|
|
9
|
-
sandboxId?: string;
|
|
10
|
-
}
|
|
11
|
-
interface SandboxRuntimeProvider {
|
|
12
|
-
resolveSandboxBox: (options: {
|
|
13
|
-
local: SandboxDefinitionOptions;
|
|
14
|
-
provider: SandboxDefinitionProviderOptions & {
|
|
15
|
-
provider: SandboxProvider;
|
|
16
|
-
};
|
|
17
|
-
} | any, context?: any) => Promise<ResolvedSandboxBox>;
|
|
18
|
-
}
|
|
19
|
-
declare function loadSandboxRuntimeProvider(provider: SandboxProvider): Promise<SandboxRuntimeProvider>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { SandboxRuntimeProvider as n, loadSandboxRuntimeProvider as r, ResolvedSandboxBox as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/provider-loader.ts
|
|
2
|
-
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
3
|
-
async function loadSandboxRuntimeProvider(provider) {
|
|
4
|
-
if (provider === "cloudflare") {
|
|
5
|
-
const { resolveCloudflareSandboxBox } = await dynamicImport("./providers/cloudflare.js");
|
|
6
|
-
return { resolveSandboxBox: resolveCloudflareSandboxBox };
|
|
7
|
-
}
|
|
8
|
-
if (provider === "vercel") {
|
|
9
|
-
const { resolveVercelSandboxBox } = await dynamicImport("./providers/vercel.js");
|
|
10
|
-
return { resolveSandboxBox: resolveVercelSandboxBox };
|
|
11
|
-
}
|
|
12
|
-
throw new Error(`[vitehub] Unsupported sandbox provider: ${provider}`);
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
export { loadSandboxRuntimeProvider };
|