@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,519 @@
|
|
|
1
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/cloudflare.d.ts
|
|
3
|
+
interface CloudflareSandboxOptions {
|
|
4
|
+
cloudflare?: {
|
|
5
|
+
keepAlive?: boolean;
|
|
6
|
+
normalizeId?: boolean;
|
|
7
|
+
sleepAfter?: number | string;
|
|
8
|
+
};
|
|
9
|
+
getSandbox?: (namespace: CloudflareDurableObjectNamespace, id: string, options?: CloudflareSandboxOptions["cloudflare"]) => CloudflareSandboxStub;
|
|
10
|
+
hostname?: string;
|
|
11
|
+
namespace: CloudflareDurableObjectNamespace;
|
|
12
|
+
sandboxId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface CloudflareDurableObjectNamespace {
|
|
15
|
+
get(id: unknown): unknown;
|
|
16
|
+
idFromName(name: string): unknown;
|
|
17
|
+
}
|
|
18
|
+
interface CloudflareSandboxStub {
|
|
19
|
+
deleteFile?(path: string): Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
} | void>;
|
|
22
|
+
destroy(): Promise<void>;
|
|
23
|
+
exec(command: string, options?: {
|
|
24
|
+
cwd?: string;
|
|
25
|
+
env?: Record<string, string | undefined>;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
exitCode: number;
|
|
29
|
+
stderr: string;
|
|
30
|
+
stdout: string;
|
|
31
|
+
success: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
exists?(path: string): Promise<{
|
|
34
|
+
exists: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
exposePort?(port: number, options: {
|
|
37
|
+
hostname: string;
|
|
38
|
+
protocol?: "http" | "https";
|
|
39
|
+
}): Promise<{
|
|
40
|
+
url: string;
|
|
41
|
+
}>;
|
|
42
|
+
listFiles?(path: string, options?: {
|
|
43
|
+
recursive?: boolean;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
files: Array<{
|
|
46
|
+
absolutePath: string;
|
|
47
|
+
name: string;
|
|
48
|
+
size: number;
|
|
49
|
+
type: "directory" | "file" | "other" | "symlink";
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
mkdir?(path: string, options?: {
|
|
53
|
+
recursive?: boolean;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
success: boolean;
|
|
56
|
+
} | void>;
|
|
57
|
+
moveFile?(source: string, destination: string): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
} | void>;
|
|
60
|
+
readFile(path: string, options?: {
|
|
61
|
+
encoding?: string;
|
|
62
|
+
}): Promise<{
|
|
63
|
+
content: string;
|
|
64
|
+
success?: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
startProcess?(command: string, options?: {
|
|
67
|
+
cwd?: string;
|
|
68
|
+
env?: Record<string, string>;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
getLogs(): Promise<{
|
|
71
|
+
stderr: string;
|
|
72
|
+
stdout: string;
|
|
73
|
+
}>;
|
|
74
|
+
id: string;
|
|
75
|
+
kill(signal?: string): Promise<void>;
|
|
76
|
+
waitForExit(): Promise<{
|
|
77
|
+
exitCode: number;
|
|
78
|
+
}>;
|
|
79
|
+
}>;
|
|
80
|
+
writeFile(path: string, contents: string, options?: {
|
|
81
|
+
encoding?: string;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
} | void>;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/internal/crabbox.d.ts
|
|
88
|
+
interface CrabboxOptions {
|
|
89
|
+
/** Enables loopback port URLs when the target shares the ViteHub process network namespace. */
|
|
90
|
+
network?: "direct";
|
|
91
|
+
profile?: string;
|
|
92
|
+
/** Replaces an existing static lease for the shared sibling-workspace root. */
|
|
93
|
+
reclaim?: boolean;
|
|
94
|
+
/** Private durable storage on the target host for writable Sandbox state. */
|
|
95
|
+
stateRoot?: string;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/internal/session-memory.d.ts
|
|
99
|
+
interface TrustedHostResources {
|
|
100
|
+
/** Writable delegated cgroup v2 parent. The controller must live in a separate subgroup. */
|
|
101
|
+
cgroupParent: string;
|
|
102
|
+
/** Aggregate resident memory limit for this session's commands and descendants. */
|
|
103
|
+
memoryMaxBytes: number;
|
|
104
|
+
memoryHighBytes?: number;
|
|
105
|
+
/** Aggregate swap limit. Defaults to zero. */
|
|
106
|
+
memorySwapMaxBytes?: number;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/internal/trusted-host.d.ts
|
|
110
|
+
interface TrustedHostOptions {
|
|
111
|
+
/** Linux-only aggregate limits for session commands. Requires cgroup v2 delegation. */
|
|
112
|
+
resources?: TrustedHostResources;
|
|
113
|
+
stateRoot?: string;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/vercel.d.ts
|
|
117
|
+
type VercelSandboxSource = {
|
|
118
|
+
depth?: number;
|
|
119
|
+
revision?: string;
|
|
120
|
+
type: "git";
|
|
121
|
+
url: string;
|
|
122
|
+
} | {
|
|
123
|
+
password: string;
|
|
124
|
+
username: string;
|
|
125
|
+
depth?: number;
|
|
126
|
+
revision?: string;
|
|
127
|
+
type: "git";
|
|
128
|
+
url: string;
|
|
129
|
+
} | {
|
|
130
|
+
snapshotId: string;
|
|
131
|
+
type: "snapshot";
|
|
132
|
+
} | {
|
|
133
|
+
type: "tarball";
|
|
134
|
+
url: string;
|
|
135
|
+
};
|
|
136
|
+
type VercelSandboxNetworkPolicy = "allow-all" | "deny-all" | {
|
|
137
|
+
allow?: readonly string[] | Readonly<Record<string, readonly unknown[]>>;
|
|
138
|
+
subnets?: {
|
|
139
|
+
allow?: readonly string[];
|
|
140
|
+
deny?: readonly string[];
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
interface VercelSandboxOptions {
|
|
144
|
+
cpu?: number;
|
|
145
|
+
create?: (options: VercelSandboxCreateOptions) => Promise<VercelSandboxInstance>;
|
|
146
|
+
networkPolicy?: VercelSandboxNetworkPolicy;
|
|
147
|
+
ports?: readonly number[];
|
|
148
|
+
projectId?: string;
|
|
149
|
+
runtime?: "node22" | "node24" | (string & {});
|
|
150
|
+
source?: VercelSandboxSource;
|
|
151
|
+
teamId?: string;
|
|
152
|
+
timeout?: number;
|
|
153
|
+
token?: string;
|
|
154
|
+
}
|
|
155
|
+
interface VercelSandboxCreateOptions {
|
|
156
|
+
networkPolicy?: VercelSandboxNetworkPolicy;
|
|
157
|
+
ports?: readonly number[];
|
|
158
|
+
persistent?: boolean;
|
|
159
|
+
projectId?: string;
|
|
160
|
+
resources?: {
|
|
161
|
+
vcpus?: number;
|
|
162
|
+
};
|
|
163
|
+
runtime: string;
|
|
164
|
+
signal?: AbortSignal;
|
|
165
|
+
source?: VercelSandboxSource;
|
|
166
|
+
teamId?: string;
|
|
167
|
+
timeout?: number;
|
|
168
|
+
token?: string;
|
|
169
|
+
}
|
|
170
|
+
interface VercelSandboxCommand {
|
|
171
|
+
kill(): Promise<void>;
|
|
172
|
+
stderr(): Promise<string>;
|
|
173
|
+
stdout(): Promise<string>;
|
|
174
|
+
wait(): Promise<{
|
|
175
|
+
exitCode: number;
|
|
176
|
+
}>;
|
|
177
|
+
}
|
|
178
|
+
interface VercelSandboxInstance {
|
|
179
|
+
domain(port: number): string;
|
|
180
|
+
fs?: {
|
|
181
|
+
access?(path: string, options?: {
|
|
182
|
+
signal?: AbortSignal;
|
|
183
|
+
}): Promise<void>;
|
|
184
|
+
exists?(path: string, options?: {
|
|
185
|
+
signal?: AbortSignal;
|
|
186
|
+
}): Promise<boolean>;
|
|
187
|
+
lstat?(path: string, options?: {
|
|
188
|
+
signal?: AbortSignal;
|
|
189
|
+
}): Promise<VercelFileStat>;
|
|
190
|
+
mkdir(path: string, options?: {
|
|
191
|
+
recursive?: boolean;
|
|
192
|
+
signal?: AbortSignal;
|
|
193
|
+
}): Promise<unknown>;
|
|
194
|
+
readFile(path: string, options?: {
|
|
195
|
+
signal?: AbortSignal;
|
|
196
|
+
}): Promise<Uint8Array>;
|
|
197
|
+
readdir(path: string, options?: {
|
|
198
|
+
signal?: AbortSignal;
|
|
199
|
+
}): Promise<string[]>;
|
|
200
|
+
rename(source: string, destination: string, options?: {
|
|
201
|
+
signal?: AbortSignal;
|
|
202
|
+
}): Promise<void>;
|
|
203
|
+
rm(path: string, options?: {
|
|
204
|
+
force?: boolean;
|
|
205
|
+
recursive?: boolean;
|
|
206
|
+
signal?: AbortSignal;
|
|
207
|
+
}): Promise<void>;
|
|
208
|
+
stat(path: string, options?: {
|
|
209
|
+
signal?: AbortSignal;
|
|
210
|
+
}): Promise<VercelFileStat>;
|
|
211
|
+
writeFile(path: string, contents: Uint8Array, options?: {
|
|
212
|
+
signal?: AbortSignal;
|
|
213
|
+
}): Promise<void>;
|
|
214
|
+
};
|
|
215
|
+
mkDir(path: string, options?: {
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
}): Promise<void>;
|
|
218
|
+
readFileToBuffer(options: {
|
|
219
|
+
path: string;
|
|
220
|
+
}, request?: {
|
|
221
|
+
signal?: AbortSignal;
|
|
222
|
+
}): Promise<Uint8Array | null>;
|
|
223
|
+
runCommand(options: {
|
|
224
|
+
args?: readonly string[];
|
|
225
|
+
cmd: string;
|
|
226
|
+
cwd?: string;
|
|
227
|
+
detached?: boolean;
|
|
228
|
+
env?: Record<string, string>;
|
|
229
|
+
signal?: AbortSignal;
|
|
230
|
+
}): Promise<VercelSandboxCommand>;
|
|
231
|
+
stop?(options?: {
|
|
232
|
+
blocking?: boolean;
|
|
233
|
+
signal?: AbortSignal;
|
|
234
|
+
}): Promise<unknown>;
|
|
235
|
+
writeFiles(files: readonly {
|
|
236
|
+
content: Uint8Array;
|
|
237
|
+
path: string;
|
|
238
|
+
}[], options?: {
|
|
239
|
+
signal?: AbortSignal;
|
|
240
|
+
}): Promise<void>;
|
|
241
|
+
[Symbol.asyncDispose]?(): Promise<void>;
|
|
242
|
+
}
|
|
243
|
+
interface VercelFileStat {
|
|
244
|
+
isDirectory(): boolean;
|
|
245
|
+
isFile(): boolean;
|
|
246
|
+
isSymbolicLink(): boolean;
|
|
247
|
+
size: number;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/index.d.ts
|
|
251
|
+
type SandboxRequirement = string | {
|
|
252
|
+
args?: readonly string[];
|
|
253
|
+
command: string;
|
|
254
|
+
name?: string;
|
|
255
|
+
timeout?: number;
|
|
256
|
+
};
|
|
257
|
+
type SandboxValue<T, Context> = T | ((context: Context) => T | undefined | Promise<T | undefined>);
|
|
258
|
+
type SandboxFile<Context> = {
|
|
259
|
+
contents: SandboxValue<string | Uint8Array, Context>;
|
|
260
|
+
} | {
|
|
261
|
+
from: string;
|
|
262
|
+
};
|
|
263
|
+
interface SandboxHome<Context> {
|
|
264
|
+
files?: Readonly<Record<string, SandboxFile<Context>>>;
|
|
265
|
+
state?: Readonly<Record<string, {
|
|
266
|
+
key: string;
|
|
267
|
+
seed?: Readonly<Record<string, SandboxFile<Context>>>;
|
|
268
|
+
}>>;
|
|
269
|
+
}
|
|
270
|
+
interface SandboxCheckout<Context> {
|
|
271
|
+
ref: SandboxValue<string, Context>;
|
|
272
|
+
remote: SandboxValue<string, Context>;
|
|
273
|
+
sha: SandboxValue<string, Context>;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Node.js and package manager for Sandbox commands. `"project"` reads both from
|
|
277
|
+
* the project, the same as `{ node: "project", packageManager: "project" }`.
|
|
278
|
+
*/
|
|
279
|
+
type SandboxToolchain = "project" | SandboxToolchainOptions;
|
|
280
|
+
interface SandboxToolchainOptions {
|
|
281
|
+
/** Node.js version, range, or alias used when the project pins none. */
|
|
282
|
+
fallbackNode?: string;
|
|
283
|
+
/** `"project"` (default) or a Node.js version, range, or alias such as `22`, `^22.11.0`, or `lts/*`. */
|
|
284
|
+
node?: "project" | (string & {});
|
|
285
|
+
/** `"project"` (default) reads package.json; `false` uses the npm bundled with Node.js; or `name@version`. */
|
|
286
|
+
packageManager?: "project" | false | (string & {});
|
|
287
|
+
}
|
|
288
|
+
interface SandboxToolchainPin {
|
|
289
|
+
/** Project file or option that declared the version, such as `.node-version`. */
|
|
290
|
+
readonly source: string;
|
|
291
|
+
/** Declared version, range, or alias. */
|
|
292
|
+
readonly version: string;
|
|
293
|
+
}
|
|
294
|
+
interface SandboxToolchainPackageManagerPin extends SandboxToolchainPin {
|
|
295
|
+
/** Expected `algorithm.hex` digest from a package.json packageManager value. */
|
|
296
|
+
readonly integrity?: string;
|
|
297
|
+
readonly name: "npm" | "pnpm" | "yarn";
|
|
298
|
+
}
|
|
299
|
+
interface SandboxToolchainPins {
|
|
300
|
+
readonly node: SandboxToolchainPin;
|
|
301
|
+
readonly packageManager?: SandboxToolchainPackageManagerPin;
|
|
302
|
+
}
|
|
303
|
+
/** Normalized toolchain declaration passed to Sandbox runtimes. */
|
|
304
|
+
interface SandboxToolchainInput {
|
|
305
|
+
readonly fallbackNode?: string;
|
|
306
|
+
readonly node: string;
|
|
307
|
+
readonly packageManager: string | false;
|
|
308
|
+
/** Pins read before the Sandbox opened. Runtimes read checkout pins after materialization. */
|
|
309
|
+
readonly pins?: SandboxToolchainPins;
|
|
310
|
+
}
|
|
311
|
+
interface SandboxToolchainPlan {
|
|
312
|
+
readonly node?: SandboxToolchainPin;
|
|
313
|
+
readonly packageManager?: SandboxToolchainPackageManagerPin;
|
|
314
|
+
/** `checkout` pins are read from the Sandbox checkout each time it opens. */
|
|
315
|
+
readonly source: "checkout" | "project";
|
|
316
|
+
}
|
|
317
|
+
/** Toolchain provisioned for an open Sandbox session. */
|
|
318
|
+
interface SandboxResolvedToolchain {
|
|
319
|
+
/** Directories prepended to PATH, in order. */
|
|
320
|
+
readonly bin: readonly string[];
|
|
321
|
+
readonly node: {
|
|
322
|
+
readonly source: string;
|
|
323
|
+
readonly version: string;
|
|
324
|
+
};
|
|
325
|
+
readonly packageManager?: {
|
|
326
|
+
readonly name: SandboxToolchainPackageManagerPin["name"];
|
|
327
|
+
readonly source: string;
|
|
328
|
+
readonly version: string;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
interface SandboxDefinition<Context = unknown> {
|
|
332
|
+
checkout?: SandboxCheckout<Context>;
|
|
333
|
+
cwd?: SandboxValue<string, Context>;
|
|
334
|
+
env?: Readonly<Record<string, SandboxValue<string, Context>>>;
|
|
335
|
+
home?: SandboxHome<Context>;
|
|
336
|
+
requires?: readonly SandboxRequirement[];
|
|
337
|
+
runtime: SandboxRuntimeDefinition;
|
|
338
|
+
/** Provision project-pinned Node.js and package manager before requirement checks. */
|
|
339
|
+
toolchain?: SandboxToolchain;
|
|
340
|
+
}
|
|
341
|
+
type BuiltInSandboxRuntimeName = "crabbox" | "trusted-host" | "vercel";
|
|
342
|
+
type BuiltInSandboxRuntime = BuiltInSandboxRuntimeName | ({
|
|
343
|
+
kind: "crabbox";
|
|
344
|
+
} & CrabboxOptions) | ({
|
|
345
|
+
kind: "trusted-host";
|
|
346
|
+
} & TrustedHostOptions) | ({
|
|
347
|
+
kind: "cloudflare";
|
|
348
|
+
} & CloudflareSandboxOptions) | ({
|
|
349
|
+
kind: "vercel";
|
|
350
|
+
} & VercelSandboxOptions);
|
|
351
|
+
type SandboxRuntimeDefinition = BuiltInSandboxRuntime | SandboxRuntime;
|
|
352
|
+
interface SandboxRuntime {
|
|
353
|
+
readonly name: string;
|
|
354
|
+
/** Set when sessions reach loopback services of the ViteHub process, for example through SSH tunnels. */
|
|
355
|
+
readonly network?: "direct";
|
|
356
|
+
open(input: SandboxRuntimeInput, options: SandboxRuntimeOpenOptions): Promise<SandboxSession>;
|
|
357
|
+
prepare(input: SandboxRuntimeInput): Promise<SandboxRuntimePlan>;
|
|
358
|
+
}
|
|
359
|
+
interface SandboxOpenOptions {
|
|
360
|
+
id?: string;
|
|
361
|
+
initialize?: (session: SandboxSession, context: {
|
|
362
|
+
signal?: AbortSignal;
|
|
363
|
+
}) => Promise<void>;
|
|
364
|
+
signal?: AbortSignal;
|
|
365
|
+
}
|
|
366
|
+
interface SandboxRuntimeOpenOptions extends SandboxOpenOptions {
|
|
367
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
368
|
+
}
|
|
369
|
+
interface SandboxExecOptions {
|
|
370
|
+
cwd?: string;
|
|
371
|
+
env?: Readonly<Record<string, string>>;
|
|
372
|
+
signal?: AbortSignal;
|
|
373
|
+
timeout?: number;
|
|
374
|
+
}
|
|
375
|
+
interface SandboxExecResult {
|
|
376
|
+
readonly code: number;
|
|
377
|
+
readonly ok: boolean;
|
|
378
|
+
readonly stderr: string;
|
|
379
|
+
readonly stdout: string;
|
|
380
|
+
}
|
|
381
|
+
interface SandboxProcessExit {
|
|
382
|
+
readonly code: number;
|
|
383
|
+
}
|
|
384
|
+
interface SandboxProcess {
|
|
385
|
+
readonly pid?: number;
|
|
386
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
387
|
+
/** Process input. Present only when the runtime forwards stdin to the command. */
|
|
388
|
+
readonly stdin?: WritableStream<Uint8Array>;
|
|
389
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
390
|
+
kill(signal?: string): Promise<void>;
|
|
391
|
+
wait(): Promise<SandboxProcessExit>;
|
|
392
|
+
}
|
|
393
|
+
interface SandboxFileEntry {
|
|
394
|
+
readonly path: string;
|
|
395
|
+
readonly size?: number;
|
|
396
|
+
readonly type: "directory" | "file" | "symlink";
|
|
397
|
+
}
|
|
398
|
+
interface SandboxFileOptions {
|
|
399
|
+
signal?: AbortSignal;
|
|
400
|
+
}
|
|
401
|
+
interface SandboxListFilesOptions extends SandboxFileOptions {
|
|
402
|
+
exclude?: readonly string[];
|
|
403
|
+
recursive?: boolean;
|
|
404
|
+
}
|
|
405
|
+
interface SandboxRemoveFileOptions extends SandboxFileOptions {
|
|
406
|
+
recursive?: boolean;
|
|
407
|
+
}
|
|
408
|
+
interface SandboxFiles {
|
|
409
|
+
exists(path: string, options?: SandboxFileOptions): Promise<boolean>;
|
|
410
|
+
list(path: string, options?: SandboxListFilesOptions): Promise<readonly SandboxFileEntry[]>;
|
|
411
|
+
mkdir(path: string, options?: SandboxFileOptions & {
|
|
412
|
+
recursive?: boolean;
|
|
413
|
+
}): Promise<void>;
|
|
414
|
+
move?(source: string, destination: string, options?: SandboxFileOptions): Promise<void>;
|
|
415
|
+
read(path: string, options?: SandboxFileOptions): Promise<Uint8Array | null>;
|
|
416
|
+
remove(path: string, options?: SandboxRemoveFileOptions): Promise<void>;
|
|
417
|
+
write(path: string, contents: Uint8Array, options?: SandboxFileOptions): Promise<void>;
|
|
418
|
+
}
|
|
419
|
+
interface SandboxPorts {
|
|
420
|
+
readonly values: readonly number[];
|
|
421
|
+
expose(port: number, options?: {
|
|
422
|
+
protocol?: "http" | "https" | "ws";
|
|
423
|
+
}): Promise<URL>;
|
|
424
|
+
}
|
|
425
|
+
interface SandboxSession {
|
|
426
|
+
readonly cwd: string;
|
|
427
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
428
|
+
readonly files: SandboxFiles;
|
|
429
|
+
readonly id: string;
|
|
430
|
+
readonly inspectionConcurrency?: number;
|
|
431
|
+
readonly ports?: SandboxPorts;
|
|
432
|
+
/** Provisioned toolchain, when the Sandbox declares one. */
|
|
433
|
+
readonly toolchain?: SandboxResolvedToolchain;
|
|
434
|
+
readonly spawn?: (command: string, args?: readonly string[], options?: SandboxExecOptions) => Promise<SandboxProcess>;
|
|
435
|
+
close(): Promise<void>;
|
|
436
|
+
exec(command: string, args?: readonly string[], options?: SandboxExecOptions): Promise<SandboxExecResult>;
|
|
437
|
+
/** Replace the session workspace with a host checkout's working tree, when the runtime has a faster transfer. */
|
|
438
|
+
importWorkspace?(checkout: string, signal?: AbortSignal): Promise<void>;
|
|
439
|
+
/** Install the workspace's dependencies inside the session instead of receiving the host's installed outputs. */
|
|
440
|
+
refreshDependencies?(checkout: string, signal?: AbortSignal): Promise<void>;
|
|
441
|
+
}
|
|
442
|
+
interface ResolvedSandboxFile {
|
|
443
|
+
readonly resolve: () => Promise<Uint8Array>;
|
|
444
|
+
}
|
|
445
|
+
interface ResolvedSandboxState {
|
|
446
|
+
readonly key: string;
|
|
447
|
+
readonly path: string;
|
|
448
|
+
readonly projections: readonly string[];
|
|
449
|
+
readonly seed: Readonly<Record<string, ResolvedSandboxFile>>;
|
|
450
|
+
}
|
|
451
|
+
interface ResolvedSandboxPlan {
|
|
452
|
+
readonly env: Readonly<Record<string, () => Promise<string>>>;
|
|
453
|
+
readonly files: Readonly<Record<string, ResolvedSandboxFile>>;
|
|
454
|
+
readonly state: readonly ResolvedSandboxState[];
|
|
455
|
+
}
|
|
456
|
+
interface ResolvedSandboxRequirementInput {
|
|
457
|
+
readonly args: readonly string[];
|
|
458
|
+
readonly command: string;
|
|
459
|
+
readonly name: string;
|
|
460
|
+
readonly timeout?: number;
|
|
461
|
+
}
|
|
462
|
+
interface SandboxRuntimeInput {
|
|
463
|
+
checkout?: ResolvedSandboxCheckout;
|
|
464
|
+
cwd?: string;
|
|
465
|
+
identity: string;
|
|
466
|
+
plan: ResolvedSandboxPlan;
|
|
467
|
+
requirements: readonly ResolvedSandboxRequirementInput[];
|
|
468
|
+
toolchain?: SandboxToolchainInput;
|
|
469
|
+
}
|
|
470
|
+
interface ResolvedSandboxCheckout {
|
|
471
|
+
readonly ref: string;
|
|
472
|
+
readonly remote: string;
|
|
473
|
+
readonly sha: string;
|
|
474
|
+
}
|
|
475
|
+
interface SandboxEnvironment {
|
|
476
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
477
|
+
}
|
|
478
|
+
interface SandboxResolvedRequirement {
|
|
479
|
+
readonly command: string;
|
|
480
|
+
readonly name: string;
|
|
481
|
+
readonly timeout?: number;
|
|
482
|
+
}
|
|
483
|
+
interface SandboxPlan {
|
|
484
|
+
/** Configured trusted-host command limits. Absent on runtimes without this contract. */
|
|
485
|
+
readonly resources?: TrustedHostOptions["resources"];
|
|
486
|
+
readonly cache: {
|
|
487
|
+
readonly state: "disposable";
|
|
488
|
+
};
|
|
489
|
+
readonly environment: SandboxEnvironment;
|
|
490
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
491
|
+
readonly home: {
|
|
492
|
+
readonly state: readonly {
|
|
493
|
+
readonly identity: string;
|
|
494
|
+
readonly path: string;
|
|
495
|
+
}[];
|
|
496
|
+
};
|
|
497
|
+
readonly identity: string;
|
|
498
|
+
readonly requirements: readonly SandboxResolvedRequirement[];
|
|
499
|
+
readonly runtime: string;
|
|
500
|
+
readonly toolchain?: SandboxToolchainPlan;
|
|
501
|
+
readonly workspace: {
|
|
502
|
+
readonly path?: string;
|
|
503
|
+
readonly state: "authoritative" | "disposable";
|
|
504
|
+
readonly workDir?: "." | "workspace";
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
type SandboxRuntimePlan = Omit<SandboxPlan, "home"> & {
|
|
508
|
+
readonly home?: SandboxPlan["home"];
|
|
509
|
+
};
|
|
510
|
+
interface Sandbox {
|
|
511
|
+
readonly plan: SandboxPlan;
|
|
512
|
+
open(options?: SandboxOpenOptions): Promise<SandboxSession>;
|
|
513
|
+
}
|
|
514
|
+
interface ResolveSandboxOptions {
|
|
515
|
+
requires?: readonly SandboxRequirement[];
|
|
516
|
+
}
|
|
517
|
+
declare function resolveSandbox<Context>(definition: SandboxDefinition<Context>, context: Context, options?: ResolveSandboxOptions): Promise<Sandbox>;
|
|
518
|
+
//#endregion
|
|
519
|
+
export { CrabboxOptions as $, SandboxRuntime as A, SandboxToolchainPin as B, SandboxPorts as C, SandboxRequirement as D, SandboxRemoveFileOptions as E, SandboxSession as F, VercelFileStat as G, SandboxToolchainPlan as H, SandboxToolchain as I, VercelSandboxInstance as J, VercelSandboxCommand as K, SandboxToolchainInput as L, SandboxRuntimeInput as M, SandboxRuntimeOpenOptions as N, SandboxResolvedRequirement as O, SandboxRuntimePlan as P, TrustedHostOptions as Q, SandboxToolchainOptions as R, SandboxPlan as S, SandboxProcessExit as T, SandboxValue as U, SandboxToolchainPins as V, resolveSandbox as W, VercelSandboxOptions as X, VercelSandboxNetworkPolicy as Y, VercelSandboxSource as Z, SandboxFileOptions as _, ResolvedSandboxFile as a, SandboxListFilesOptions as b, ResolvedSandboxState as c, SandboxDefinition as d, CloudflareDurableObjectNamespace as et, SandboxEnvironment as f, SandboxFileEntry as g, SandboxFile as h, ResolvedSandboxCheckout as i, SandboxRuntimeDefinition as j, SandboxResolvedToolchain as k, Sandbox as l, SandboxExecResult as m, BuiltInSandboxRuntimeName as n, CloudflareSandboxStub as nt, ResolvedSandboxPlan as o, SandboxExecOptions as p, VercelSandboxCreateOptions as q, ResolveSandboxOptions as r, ResolvedSandboxRequirementInput as s, BuiltInSandboxRuntime as t, CloudflareSandboxOptions as tt, SandboxCheckout as u, SandboxFiles as v, SandboxProcess as w, SandboxOpenOptions as x, SandboxHome as y, SandboxToolchainPackageManagerPin as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
import { SandboxDefinitionModules } from "#vitehub-sandbox-registry";
|
|
4
|
-
|
|
5
|
-
//#region src/runtime/registry.d.ts
|
|
6
|
-
declare function defineSandbox<THandler extends (...args: any[]) => any>(input: SandboxDefinitionInput<Parameters<THandler>[0], Awaited<ReturnType<THandler>>> & {
|
|
7
|
-
run: THandler;
|
|
8
|
-
}): SandboxDefinitionFromHandler<THandler>;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/internal/shared/request-payload.d.ts
|
|
11
|
-
interface RequestPayloadEvent {
|
|
12
|
-
req: {
|
|
13
|
-
json: () => Promise<unknown>;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
declare function readRequestPayload(event: RequestPayloadEvent, fallback?: unknown): Promise<unknown>;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/internal/shared/validation.d.ts
|
|
19
|
-
interface ValidationIssue {
|
|
20
|
-
message: string;
|
|
21
|
-
path?: readonly unknown[];
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
interface StandardSchemaValidationResult<TOutput = unknown> {
|
|
25
|
-
value: TOutput;
|
|
26
|
-
issues?: readonly ValidationIssue[];
|
|
27
|
-
}
|
|
28
|
-
interface StandardSchemaValidator<TInput = unknown, TOutput = TInput> {
|
|
29
|
-
'~standard': {
|
|
30
|
-
validate: (input: TInput) => StandardSchemaValidationResult<TOutput> | Promise<StandardSchemaValidationResult<TOutput>>;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
type ValidationFunction<TInput = unknown, TResult = TInput> = (input: TInput) => TResult | Promise<TResult>;
|
|
34
|
-
type ValidationResult<TInput, TResult> = TResult extends false | true | null | undefined ? TInput : TResult;
|
|
35
|
-
interface ValidationErrorContext<TValue = unknown> {
|
|
36
|
-
value?: TValue;
|
|
37
|
-
issues?: readonly ValidationIssue[];
|
|
38
|
-
}
|
|
39
|
-
interface ValidationOptions<TValue = unknown> {
|
|
40
|
-
onError?: (context: ValidationErrorContext<TValue>) => unknown;
|
|
41
|
-
}
|
|
42
|
-
declare function readValidatedPayload<TInput, TOutput>(payload: TInput, validate: StandardSchemaValidator<TInput, TOutput>, options?: ValidationOptions<TInput>): Promise<TOutput>;
|
|
43
|
-
declare function readValidatedPayload<TInput, TResult>(payload: TInput, validate: ValidationFunction<TInput, TResult>, options?: ValidationOptions<TInput>): Promise<ValidationResult<TInput, Awaited<TResult>>>;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/runtime/registry-types.d.ts
|
|
46
|
-
type SandboxDefinitionName = keyof SandboxDefinitionModules;
|
|
47
|
-
type SandboxRegistryDefinition<TName extends keyof SandboxDefinitionModules> = SandboxDefinitionModules[TName];
|
|
48
|
-
type SandboxPayload<TDefinition> = TDefinition extends {
|
|
49
|
-
payload: infer TPayload;
|
|
50
|
-
} ? TPayload : unknown;
|
|
51
|
-
type SandboxResult<TDefinition> = TDefinition extends {
|
|
52
|
-
result: infer TResult;
|
|
53
|
-
} ? TResult : unknown;
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/runtime/public.d.ts
|
|
56
|
-
declare function runSandbox<const TName extends SandboxDefinitionName>(name: TName, payload?: SandboxPayload<SandboxRegistryDefinition<TName>>, options?: SandboxExecutionOptions): Promise<SandboxRunResult<SandboxResult<SandboxRegistryDefinition<TName>>>>;
|
|
57
|
-
declare function runSandbox(name: string, payload?: unknown, options?: SandboxExecutionOptions): Promise<SandboxRunResult<unknown>>;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/runtime/runtime.d.ts
|
|
60
|
-
interface SandboxRunner {
|
|
61
|
-
readonly executionAuthority: ExecutionAuthority;
|
|
62
|
-
name: string;
|
|
63
|
-
run: <TPayload = unknown, TResult = unknown>(payload?: TPayload, options?: SandboxExecutionOptions) => Promise<TResult>;
|
|
64
|
-
}
|
|
65
|
-
declare function resolveSandboxRunner<TPayload = unknown, TResult = unknown>(name?: string): Promise<SandboxRunner & {
|
|
66
|
-
run: (payload?: TPayload, options?: SandboxExecutionOptions) => Promise<TResult>;
|
|
67
|
-
}>;
|
|
68
|
-
//#endregion
|
|
69
|
-
export { type AgentSandboxConfig, type CloudflareSandboxDefinitionProviderOptions, type CloudflareSandboxOptions, type RequestPayloadEvent, type SandboxDefinition, type SandboxDefinitionBundle, type SandboxDefinitionFromHandler, type SandboxDefinitionHandler, type SandboxDefinitionInput, type SandboxDefinitionOptions, type SandboxDefinitionProviderOptions, type SandboxExecutionOptions, type SandboxProjectOptions, type SandboxProvider, type SandboxRunResult, type SandboxRunner, type VercelSandboxProviderOptions, defineSandbox, type getSandboxFeatureProvider, readRequestPayload, readValidatedPayload, resolveSandboxRunner, runSandbox };
|
|
1
|
+
import { $ as CrabboxOptions, A as SandboxRuntime, B as SandboxToolchainPin, C as SandboxPorts, D as SandboxRequirement, E as SandboxRemoveFileOptions, F as SandboxSession, G as VercelFileStat, H as SandboxToolchainPlan, I as SandboxToolchain, J as VercelSandboxInstance, K as VercelSandboxCommand, L as SandboxToolchainInput, M as SandboxRuntimeInput, N as SandboxRuntimeOpenOptions, O as SandboxResolvedRequirement, P as SandboxRuntimePlan, Q as TrustedHostOptions, R as SandboxToolchainOptions, S as SandboxPlan, T as SandboxProcessExit, U as SandboxValue, V as SandboxToolchainPins, W as resolveSandbox, X as VercelSandboxOptions, Y as VercelSandboxNetworkPolicy, Z as VercelSandboxSource, _ as SandboxFileOptions, a as ResolvedSandboxFile, b as SandboxListFilesOptions, c as ResolvedSandboxState, d as SandboxDefinition, et as CloudflareDurableObjectNamespace, f as SandboxEnvironment, g as SandboxFileEntry, h as SandboxFile, i as ResolvedSandboxCheckout, j as SandboxRuntimeDefinition, k as SandboxResolvedToolchain, l as Sandbox, m as SandboxExecResult, n as BuiltInSandboxRuntimeName, nt as CloudflareSandboxStub, o as ResolvedSandboxPlan, p as SandboxExecOptions, q as VercelSandboxCreateOptions, r as ResolveSandboxOptions, s as ResolvedSandboxRequirementInput, t as BuiltInSandboxRuntime, tt as CloudflareSandboxOptions, u as SandboxCheckout, v as SandboxFiles, w as SandboxProcess, x as SandboxOpenOptions, y as SandboxHome, z as SandboxToolchainPackageManagerPin } from "./index-CXej1Bt0.js";
|
|
2
|
+
export { BuiltInSandboxRuntime, BuiltInSandboxRuntimeName, type CloudflareDurableObjectNamespace, type CloudflareSandboxOptions, type CloudflareSandboxStub, type CrabboxOptions, ResolveSandboxOptions, ResolvedSandboxCheckout, ResolvedSandboxFile, ResolvedSandboxPlan, ResolvedSandboxRequirementInput, ResolvedSandboxState, Sandbox, SandboxCheckout, SandboxDefinition, SandboxEnvironment, SandboxExecOptions, SandboxExecResult, SandboxFile, SandboxFileEntry, SandboxFileOptions, SandboxFiles, SandboxHome, SandboxListFilesOptions, SandboxOpenOptions, SandboxPlan, SandboxPorts, SandboxProcess, SandboxProcessExit, SandboxRemoveFileOptions, SandboxRequirement, SandboxResolvedRequirement, SandboxResolvedToolchain, SandboxRuntime, SandboxRuntimeDefinition, SandboxRuntimeInput, SandboxRuntimeOpenOptions, SandboxRuntimePlan, SandboxSession, SandboxToolchain, SandboxToolchainInput, SandboxToolchainOptions, SandboxToolchainPackageManagerPin, SandboxToolchainPin, SandboxToolchainPins, SandboxToolchainPlan, SandboxValue, type TrustedHostOptions, type VercelFileStat, type VercelSandboxCommand, type VercelSandboxCreateOptions, type VercelSandboxInstance, type VercelSandboxNetworkPolicy, type VercelSandboxOptions, type VercelSandboxSource, resolveSandbox };
|