@vite-hub/sandbox 0.0.0 → 0.0.2
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 +54 -1
- package/dist/cloudflare-env-2NctU8i7.js +12 -0
- package/dist/index-DiH4OGAU.d.ts +101 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1208 -0
- package/dist/module-types-Cjqo67ay.d.ts +91 -0
- package/dist/module-types-Dj1MFmHT.js +7 -0
- package/dist/provider-loader-3ml65ZFy.d.ts +21 -0
- package/dist/runtime/empty-registry.d.ts +6 -0
- package/dist/runtime/empty-registry.js +20 -0
- package/dist/runtime/provider-loader.d.ts +2 -0
- package/dist/runtime/provider-loader.js +15 -0
- package/dist/runtime/providers/cloudflare.d.ts +30 -0
- package/dist/runtime/providers/cloudflare.js +25 -0
- package/dist/runtime/providers/vercel.d.ts +14 -0
- package/dist/runtime/providers/vercel.js +51 -0
- package/dist/runtime/state.d.ts +17 -0
- package/dist/runtime/state.js +21 -0
- package/dist/vite.d.ts +24 -0
- package/dist/vite.js +2363 -0
- package/package.json +112 -5
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
1
|
# @vite-hub/sandbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@vite-hub/sandbox` discovers and runs named work by composing a package project and a Box. Sandbox owns discovery, orchestration, and project staging; Box owns provider-specific execution.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
// server/sandboxes/release-notes/index.ts
|
|
7
|
+
interface SandboxPayload {
|
|
8
|
+
notes?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default async function releaseNotes(payload: SandboxPayload = {}) {
|
|
12
|
+
return { summary: payload.notes?.split("\n")[0] ?? "" }
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The folder supplies the Definition name, and the adjacent manifest owns portable lifecycle metadata:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"private": true,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"vitehub": {
|
|
23
|
+
"sandbox": {
|
|
24
|
+
"timeout": 30000
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
ViteHub calls the default function with `(payload, context)` and infers the `runSandbox()` payload and result types from it. Nested `Blob` and `Uint8Array` values cross the Box boundary through binary sidecars rather than application JSON; Node.js `Buffer` values retain their `Buffer` type. Existing non-function default exports remain supported; their optional exported `SandboxPayload` type is the payload fallback. The entrypoint needs no `@vite-hub/sandbox` runtime dependency.
|
|
31
|
+
|
|
32
|
+
ViteHub uses the manifest's `packageManager`, then a lockfile at that package root, then npm. A matching `pnpm-workspace.yaml` selects pnpm, moves preparation to the pnpm workspace root, and carries the transitive `workspace:*` dependency closure into the Box while the entrypoint still runs from its package directory.
|
|
33
|
+
|
|
34
|
+
Package entrypoints are ESM projects. Keep `"type": "module"`, use explicit relative ESM imports for local `.ts` and `.mts` source, and depend on packages that expose runtime-ready JavaScript. ViteHub compiles the reachable local TypeScript graph without bundling package dependencies or moving relative assets. It rejects CommonJS/CTS, package import aliases and self-references for local source, imports that escape the selected package, and workspace dependencies that expose TypeScript runtime entries.
|
|
35
|
+
|
|
36
|
+
Use `<path>.sandbox.ts` with `defineSandbox()` for free-form Definitions outside `server/sandboxes`.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { runSandbox } from "@vite-hub/sandbox"
|
|
40
|
+
|
|
41
|
+
const [error, result] = await runSandbox("release-notes", { notes: "ship it" })
|
|
42
|
+
if (error) throw error
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Resolve a runner when orchestration needs to inspect the provider boundary before execution:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { resolveSandboxRunner } from "@vite-hub/sandbox"
|
|
49
|
+
|
|
50
|
+
const runner = await resolveSandboxRunner("release-notes")
|
|
51
|
+
console.log(runner.executionAuthority)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The runner exposes the selected Box provider's complete `ExecutionAuthority` descriptor. A Sandbox Definition name and its structural command arguments choose work to run; they do not limit what that process can read, reach, inherit, or spawn.
|
|
55
|
+
|
|
56
|
+
Add `hubSandbox()` to Vite for discovery, typed registry generation, package preparation plans, and host output. Provider images and full Dockerfile overrides belong to the selected Box adapter or host configuration; Sandbox Definitions stay portable.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const activeEnvStorage = new AsyncLocalStorage();
|
|
3
|
+
function getActiveCloudflareEnv() {
|
|
4
|
+
const scoped = activeEnvStorage.getStore();
|
|
5
|
+
return scoped ? scoped.env : globalThis.__env__;
|
|
6
|
+
}
|
|
7
|
+
function getCloudflareEnv(event) {
|
|
8
|
+
const target = event;
|
|
9
|
+
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getCloudflareEnv as t };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
2
|
+
|
|
3
|
+
//#region ../box/dist/index-Vc0GwE3_.d.ts
|
|
4
|
+
interface BoxOpenOptions {
|
|
5
|
+
id?: string;
|
|
6
|
+
initialize?: (session: BoxSession, context: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
interface BoxExecOptions {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
env?: Readonly<Record<string, string>>;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}
|
|
17
|
+
interface BoxExecResult {
|
|
18
|
+
readonly code: number;
|
|
19
|
+
readonly ok: boolean;
|
|
20
|
+
readonly stderr: string;
|
|
21
|
+
readonly stdout: string;
|
|
22
|
+
}
|
|
23
|
+
interface BoxProcessExit {
|
|
24
|
+
readonly code: number;
|
|
25
|
+
}
|
|
26
|
+
interface BoxProcess {
|
|
27
|
+
readonly pid?: number;
|
|
28
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
29
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
30
|
+
kill(signal?: string): Promise<void>;
|
|
31
|
+
wait(): Promise<BoxProcessExit>;
|
|
32
|
+
}
|
|
33
|
+
interface BoxFileEntry {
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly size?: number;
|
|
36
|
+
readonly type: "directory" | "file" | "symlink";
|
|
37
|
+
}
|
|
38
|
+
interface BoxFileOptions {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
interface BoxListFilesOptions extends BoxFileOptions {
|
|
42
|
+
recursive?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface BoxRemoveFileOptions extends BoxFileOptions {
|
|
45
|
+
recursive?: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface BoxFiles {
|
|
48
|
+
exists(path: string, options?: BoxFileOptions): Promise<boolean>;
|
|
49
|
+
list(path: string, options?: BoxListFilesOptions): Promise<readonly BoxFileEntry[]>;
|
|
50
|
+
mkdir(path: string, options?: BoxFileOptions & {
|
|
51
|
+
recursive?: boolean;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
move?(source: string, destination: string, options?: BoxFileOptions): Promise<void>;
|
|
54
|
+
read(path: string, options?: BoxFileOptions): Promise<Uint8Array | null>;
|
|
55
|
+
remove(path: string, options?: BoxRemoveFileOptions): Promise<void>;
|
|
56
|
+
write(path: string, contents: Uint8Array, options?: BoxFileOptions): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
interface BoxPorts {
|
|
59
|
+
readonly values: readonly number[];
|
|
60
|
+
expose(port: number, options?: {
|
|
61
|
+
protocol?: "http" | "https" | "ws";
|
|
62
|
+
}): Promise<URL>;
|
|
63
|
+
}
|
|
64
|
+
interface BoxSession {
|
|
65
|
+
readonly cwd: string;
|
|
66
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
67
|
+
readonly files: BoxFiles;
|
|
68
|
+
readonly id: string;
|
|
69
|
+
readonly ports?: BoxPorts;
|
|
70
|
+
readonly spawn?: (command: string, args?: readonly string[], options?: BoxExecOptions) => Promise<BoxProcess>;
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
exec(command: string, args?: readonly string[], options?: BoxExecOptions): Promise<BoxExecResult>;
|
|
73
|
+
}
|
|
74
|
+
interface BoxEnvironment {
|
|
75
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
76
|
+
}
|
|
77
|
+
interface BoxResolvedRequirement {
|
|
78
|
+
readonly command: string;
|
|
79
|
+
readonly name: string;
|
|
80
|
+
}
|
|
81
|
+
interface BoxPlan {
|
|
82
|
+
readonly cache: {
|
|
83
|
+
readonly state: "disposable";
|
|
84
|
+
};
|
|
85
|
+
readonly environment: BoxEnvironment;
|
|
86
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
87
|
+
readonly identity: string;
|
|
88
|
+
readonly requirements: readonly BoxResolvedRequirement[];
|
|
89
|
+
readonly runtime: string;
|
|
90
|
+
readonly workspace: {
|
|
91
|
+
readonly path?: string;
|
|
92
|
+
readonly state: "authoritative" | "disposable";
|
|
93
|
+
readonly workDir?: "." | "workspace";
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface Box {
|
|
97
|
+
readonly plan: BoxPlan;
|
|
98
|
+
open(options?: BoxOpenOptions): Promise<BoxSession>;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { Box as t };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { a as SandboxDefinitionBundle, c as SandboxDefinitionInput, d as SandboxExecutionOptions, f as SandboxProjectOptions, g as getSandboxFeatureProvider, h as VercelSandboxProviderOptions, i as SandboxDefinition, l as SandboxDefinitionOptions, m as SandboxRunResult, n as CloudflareSandboxDefinitionProviderOptions, o as SandboxDefinitionFromHandler, p as SandboxProvider, r as CloudflareSandboxOptions, s as SandboxDefinitionHandler, t as AgentSandboxConfig, u as SandboxDefinitionProviderOptions } from "./module-types-Cjqo67ay.js";
|
|
2
|
+
import { H3Event } from "h3";
|
|
3
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
4
|
+
import { SandboxDefinitionModules } from "#vitehub-sandbox-registry";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime/registry.d.ts
|
|
7
|
+
declare function defineSandbox<THandler extends (...args: any[]) => any>(input: SandboxDefinitionInput<Parameters<THandler>[0], Awaited<ReturnType<THandler>>> & {
|
|
8
|
+
run: THandler;
|
|
9
|
+
}): SandboxDefinitionFromHandler<THandler>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/internal/shared/request-payload.d.ts
|
|
12
|
+
declare function readRequestPayload<TPayload = Record<string, never>>(event: H3Event, fallback?: TPayload): Promise<TPayload | unknown>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/internal/shared/validation.d.ts
|
|
15
|
+
interface ValidationIssue {
|
|
16
|
+
message: string;
|
|
17
|
+
path?: readonly unknown[];
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
interface StandardSchemaValidationResult<TOutput = unknown> {
|
|
21
|
+
value: TOutput;
|
|
22
|
+
issues?: readonly ValidationIssue[];
|
|
23
|
+
}
|
|
24
|
+
interface StandardSchemaValidator<TInput = unknown, TOutput = TInput> {
|
|
25
|
+
'~standard': {
|
|
26
|
+
validate: (input: TInput) => StandardSchemaValidationResult<TOutput> | Promise<StandardSchemaValidationResult<TOutput>>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
type ValidationFunction<TInput = unknown, TResult = TInput> = (input: TInput) => TResult | Promise<TResult>;
|
|
30
|
+
type ValidationResult<TInput, TResult> = TResult extends false | true | null | undefined ? TInput : TResult;
|
|
31
|
+
interface ValidationErrorContext<TValue = unknown> {
|
|
32
|
+
value?: TValue;
|
|
33
|
+
issues?: readonly ValidationIssue[];
|
|
34
|
+
}
|
|
35
|
+
interface ValidationOptions<TValue = unknown> {
|
|
36
|
+
onError?: (context: ValidationErrorContext<TValue>) => unknown;
|
|
37
|
+
}
|
|
38
|
+
declare function readValidatedPayload<TInput, TOutput>(payload: TInput, validate: StandardSchemaValidator<TInput, TOutput>, options?: ValidationOptions<TInput>): Promise<TOutput>;
|
|
39
|
+
declare function readValidatedPayload<TInput, TResult>(payload: TInput, validate: ValidationFunction<TInput, TResult>, options?: ValidationOptions<TInput>): Promise<ValidationResult<TInput, Awaited<TResult>>>;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/runtime/registry-types.d.ts
|
|
42
|
+
type SandboxDefinitionName = keyof SandboxDefinitionModules;
|
|
43
|
+
type SandboxRegistryDefinition<TName extends keyof SandboxDefinitionModules> = SandboxDefinitionModules[TName];
|
|
44
|
+
type SandboxPayload<TDefinition> = TDefinition extends {
|
|
45
|
+
payload: infer TPayload;
|
|
46
|
+
} ? TPayload : unknown;
|
|
47
|
+
type SandboxResult<TDefinition> = TDefinition extends {
|
|
48
|
+
result: infer TResult;
|
|
49
|
+
} ? TResult : unknown;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/runtime/public.d.ts
|
|
52
|
+
declare function runSandbox<const TName extends SandboxDefinitionName>(name: TName, payload?: SandboxPayload<SandboxRegistryDefinition<TName>>, options?: SandboxExecutionOptions): Promise<SandboxRunResult<SandboxResult<SandboxRegistryDefinition<TName>>>>;
|
|
53
|
+
declare function runSandbox(name: string, payload?: unknown, options?: SandboxExecutionOptions): Promise<SandboxRunResult<unknown>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/runtime/runtime.d.ts
|
|
56
|
+
interface SandboxRunner {
|
|
57
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
58
|
+
name: string;
|
|
59
|
+
run: <TPayload = unknown, TResult = unknown>(payload?: TPayload, options?: SandboxExecutionOptions) => Promise<TResult>;
|
|
60
|
+
}
|
|
61
|
+
declare function resolveSandboxRunner<TPayload = unknown, TResult = unknown>(name?: string): Promise<SandboxRunner & {
|
|
62
|
+
run: (payload?: TPayload, options?: SandboxExecutionOptions) => Promise<TResult>;
|
|
63
|
+
}>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { type AgentSandboxConfig, type CloudflareSandboxDefinitionProviderOptions, type CloudflareSandboxOptions, 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 };
|