@vite-hub/sandbox 0.0.1 → 0.0.3
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 +35 -37
- package/dist/cloudflare-env-2NctU8i7.js +12 -0
- package/dist/index.d.ts +23 -32
- package/dist/index.js +688 -265
- package/dist/module-types-DfXe133f.d.ts +91 -0
- package/dist/provider-loader-hL7uHVWp.d.ts +21 -0
- package/dist/runtime/provider-loader.d.ts +2 -17
- package/dist/runtime/provider-loader.js +4 -10
- package/dist/runtime/providers/cloudflare.d.ts +5 -11
- package/dist/runtime/providers/cloudflare.js +14 -11
- package/dist/runtime/providers/vercel.d.ts +103 -12
- package/dist/runtime/providers/vercel.js +16 -30
- package/dist/runtime/state.d.ts +1 -1
- package/dist/vite.d.ts +12 -28
- package/dist/vite.js +2280 -354
- package/package.json +60 -59
- package/dist/_shared-CJ2_pS4E.js +0 -53
- package/dist/cloudflare-retry-Cfra7MvS.js +0 -21
- package/dist/common-CS4FcWrh.d.ts +0 -369
- package/dist/index-B4j3Mvzr.d.ts +0 -146
- package/dist/integration-wkNE8jMO.js +0 -2032
- package/dist/module-types-CUcY8iuI.d.ts +0 -88
- package/dist/nitro.d.ts +0 -19
- package/dist/nitro.js +0 -488
- package/dist/provider-detection-IbezCeoR.js +0 -25
- package/dist/runtime/nitro-plugin.d.ts +0 -4
- package/dist/runtime/nitro-plugin.js +0 -8
- package/dist/sandbox/providers/cloudflare.d.ts +0 -7
- package/dist/sandbox/providers/cloudflare.js +0 -339
- package/dist/sandbox/providers/vercel.d.ts +0 -17
- package/dist/sandbox/providers/vercel.js +0 -538
- package/dist/shared-pqTHYWg1.d.ts +0 -8
- package/dist/utils-V7ODsDW_.js +0 -44
- package/dist/vercel-runtime-BPzvh_6V.js +0 -11
- /package/dist/{module-types-BomzaqnM.js → module-types-Dj1MFmHT.js} +0 -0
package/README.md
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
# @vite-hub/sandbox
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/badge/ViteHub-vitehub.dev-646cff?style=flat-square"></a>
|
|
5
|
-
<img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square">
|
|
6
|
-
<img alt="Vite" src="https://img.shields.io/badge/Vite-discovery-646cff?style=flat-square">
|
|
7
|
-
<img alt="Sandbox" src="https://img.shields.io/badge/Sandbox-isolated%20runs-b45309?style=flat-square">
|
|
8
|
-
</p>
|
|
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.
|
|
9
4
|
|
|
10
|
-
|
|
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
|
+
```
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
The folder supplies the Definition name, and the adjacent manifest owns portable lifecycle metadata:
|
|
13
17
|
|
|
14
|
-
```
|
|
15
|
-
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"private": true,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"vitehub": {
|
|
23
|
+
"sandbox": {
|
|
24
|
+
"timeout": 30000
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
```
|
|
17
29
|
|
|
18
|
-
|
|
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.
|
|
19
31
|
|
|
20
|
-
|
|
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.
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
// server/sandboxes/release-notes.ts
|
|
24
|
-
import { defineSandbox } from "@vite-hub/sandbox"
|
|
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.
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
summary: payload.notes?.split("\n")[0] ?? "",
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
```
|
|
36
|
+
Use `<path>.sandbox.ts` with `defineSandbox()` for free-form Definitions outside `server/sandboxes`.
|
|
32
37
|
|
|
33
38
|
```ts
|
|
34
|
-
// server/api/release-notes.post.ts
|
|
35
39
|
import { runSandbox } from "@vite-hub/sandbox"
|
|
36
|
-
import { defineEventHandler, readBody } from "h3"
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return result.isOk() ? result.value : { error: result.error.message }
|
|
41
|
-
})
|
|
41
|
+
const [error, result] = await runSandbox("release-notes", { notes: "ship it" })
|
|
42
|
+
if (error) throw error
|
|
42
43
|
```
|
|
43
44
|
|
|
45
|
+
Resolve a runner when orchestration needs to inspect the provider boundary before execution:
|
|
46
|
+
|
|
44
47
|
```ts
|
|
45
|
-
|
|
46
|
-
import { defineNitroConfig } from "nitro/config"
|
|
48
|
+
import { resolveSandboxRunner } from "@vite-hub/sandbox"
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sandbox: { provider: "cloudflare" },
|
|
51
|
-
})
|
|
50
|
+
const runner = await resolveSandboxRunner("release-notes")
|
|
51
|
+
console.log(runner.executionAuthority)
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Nitro discovers `server/sandboxes/<name>.ts`. Vite also supports `src/<name>.sandbox.ts` through `hubSandbox()`. Provider config selects [Cloudflare Sandbox SDK](https://developers.cloudflare.com/sandbox/) or [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox/).
|
|
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.
|
|
57
55
|
|
|
58
|
-
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { g as VercelSandboxProviderOptions,
|
|
2
|
-
import { n as SandboxClient } from "./index-B4j3Mvzr.js";
|
|
3
|
-
import { a as SandboxDefinitionFromHandler, c as SandboxDefinitionProviderOptions, d as SandboxExecutionOptions, f as SandboxOkResult, h as SandboxError, i as SandboxDefinitionBundle, l as SandboxDefinitionRuntime, m as getSandboxFeatureProvider, n as CloudflareSandboxDefinitionProviderOptions, o as SandboxDefinitionHandler, p as SandboxRunResult, r as SandboxDefinition, s as SandboxDefinitionOptions, t as AgentSandboxConfig, u as SandboxErrResult } from "./module-types-CUcY8iuI.js";
|
|
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-DfXe133f.js";
|
|
4
2
|
import { H3Event } from "h3";
|
|
3
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
5
4
|
import { SandboxDefinitionModules } from "#vitehub-sandbox-registry";
|
|
6
5
|
|
|
7
6
|
//#region src/runtime/registry.d.ts
|
|
8
|
-
declare function defineSandbox<THandler extends (...args: any[]) => any>(
|
|
7
|
+
declare function defineSandbox<THandler extends (...args: any[]) => any>(input: SandboxDefinitionInput<Parameters<THandler>[0], Awaited<ReturnType<THandler>>> & {
|
|
8
|
+
run: THandler;
|
|
9
|
+
}): SandboxDefinitionFromHandler<THandler>;
|
|
9
10
|
//#endregion
|
|
10
11
|
//#region src/internal/shared/request-payload.d.ts
|
|
11
12
|
declare function readRequestPayload<TPayload = Record<string, never>>(event: H3Event, fallback?: TPayload): Promise<TPayload | unknown>;
|
|
@@ -37,38 +38,28 @@ interface ValidationOptions<TValue = unknown> {
|
|
|
37
38
|
declare function readValidatedPayload<TInput, TOutput>(payload: TInput, validate: StandardSchemaValidator<TInput, TOutput>, options?: ValidationOptions<TInput>): Promise<TOutput>;
|
|
38
39
|
declare function readValidatedPayload<TInput, TResult>(payload: TInput, validate: ValidationFunction<TInput, TResult>, options?: ValidationOptions<TInput>): Promise<ValidationResult<TInput, Awaited<TResult>>>;
|
|
39
40
|
//#endregion
|
|
40
|
-
//#region src/runtime/provider-resolution.d.ts
|
|
41
|
-
type SandboxEvent = {
|
|
42
|
-
context?: {
|
|
43
|
-
cloudflare?: {
|
|
44
|
-
env?: Record<string, unknown>;
|
|
45
|
-
};
|
|
46
|
-
_platform?: {
|
|
47
|
-
cloudflare?: {
|
|
48
|
-
env?: Record<string, unknown>;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/runtime/runtime.d.ts
|
|
55
|
-
declare function createSandboxWithConfig(config: AgentSandboxConfig, local?: SandboxDefinitionOptions, context?: {
|
|
56
|
-
event?: SandboxEvent;
|
|
57
|
-
}): Promise<SandboxClient>;
|
|
58
|
-
//#endregion
|
|
59
41
|
//#region src/runtime/registry-types.d.ts
|
|
60
42
|
type SandboxDefinitionName = keyof SandboxDefinitionModules;
|
|
61
|
-
type SandboxRegistryDefinition<TName extends keyof SandboxDefinitionModules> = SandboxDefinitionModules[TName]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
type SandboxResult<TDefinition> = SandboxRunner<TDefinition> extends ((...args: any[]) => infer TResult) ? Awaited<TResult> : unknown;
|
|
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;
|
|
69
50
|
//#endregion
|
|
70
51
|
//#region src/runtime/public.d.ts
|
|
71
52
|
declare function runSandbox<const TName extends SandboxDefinitionName>(name: TName, payload?: SandboxPayload<SandboxRegistryDefinition<TName>>, options?: SandboxExecutionOptions): Promise<SandboxRunResult<SandboxResult<SandboxRegistryDefinition<TName>>>>;
|
|
72
53
|
declare function runSandbox(name: string, payload?: unknown, options?: SandboxExecutionOptions): Promise<SandboxRunResult<unknown>>;
|
|
73
54
|
//#endregion
|
|
74
|
-
|
|
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 };
|