@vite-hub/sandbox 0.0.2 → 0.0.4
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/LICENSE +201 -0
- package/README.md +97 -24
- package/dist/{cloudflare-env-2NctU8i7.js → cloudflare-env-QQV4uzCT.js} +4 -2
- package/dist/index.d.ts +8 -4
- package/dist/index.js +34 -23
- package/dist/{module-types-Cjqo67ay.d.ts → module-types-DKYItiOu.d.ts} +3 -1
- package/dist/{provider-loader-3ml65ZFy.d.ts → provider-loader-D0UihePq.d.ts} +1 -1
- package/dist/runtime/provider-loader.d.ts +1 -1
- package/dist/runtime/provider-loader.js +4 -4
- package/dist/runtime/providers/cloudflare.d.ts +4 -5
- package/dist/runtime/providers/cloudflare.js +4 -4
- package/dist/runtime/providers/vercel.d.ts +111 -4
- package/dist/runtime/providers/vercel.js +3 -3
- package/dist/runtime/state.d.ts +11 -2
- package/dist/runtime/state.js +52 -1
- package/dist/vite.d.ts +26 -2
- package/dist/vite.js +1097 -136
- package/package.json +17 -12
- package/dist/index-DiH4OGAU.d.ts +0 -101
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as getCloudflareEnv } from "../../cloudflare-env-
|
|
2
|
-
import { resolveCloudflareBox } from "@vite-hub/box/cloudflare";
|
|
1
|
+
import { t as getCloudflareEnv } from "../../cloudflare-env-QQV4uzCT.js";
|
|
2
|
+
import { resolveCloudflareBox } from "@vite-hub/box/_internal/cloudflare";
|
|
3
3
|
//#region src/runtime/providers/cloudflare.ts
|
|
4
|
-
async function
|
|
4
|
+
async function resolveCloudflareSandboxBox(options, context = {}) {
|
|
5
5
|
const env = getCloudflareEnv(context.event);
|
|
6
6
|
const bindingName = options.provider.binding || "SANDBOX";
|
|
7
7
|
const namespace = env?.[bindingName];
|
|
@@ -22,4 +22,4 @@ async function resolveSandboxBox(options, context = {}) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
export {
|
|
25
|
+
export { resolveCloudflareSandboxBox };
|
|
@@ -1,14 +1,121 @@
|
|
|
1
|
-
import { h as VercelSandboxProviderOptions, l as SandboxDefinitionOptions } from "../../module-types-
|
|
2
|
-
import {
|
|
1
|
+
import { h as VercelSandboxProviderOptions, l as SandboxDefinitionOptions } from "../../module-types-DKYItiOu.js";
|
|
2
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
3
3
|
|
|
4
|
+
//#region ../box/dist/index-C37Q7osK.d.ts
|
|
5
|
+
interface BoxOpenOptions {
|
|
6
|
+
id?: string;
|
|
7
|
+
initialize?: (session: BoxSession, context: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
interface BoxExecOptions {
|
|
13
|
+
cwd?: string;
|
|
14
|
+
env?: Readonly<Record<string, string>>;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
interface BoxExecResult {
|
|
19
|
+
readonly code: number;
|
|
20
|
+
readonly ok: boolean;
|
|
21
|
+
readonly stderr: string;
|
|
22
|
+
readonly stdout: string;
|
|
23
|
+
}
|
|
24
|
+
interface BoxProcessExit {
|
|
25
|
+
readonly code: number;
|
|
26
|
+
}
|
|
27
|
+
interface BoxProcess {
|
|
28
|
+
readonly pid?: number;
|
|
29
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
30
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
31
|
+
kill(signal?: string): Promise<void>;
|
|
32
|
+
wait(): Promise<BoxProcessExit>;
|
|
33
|
+
}
|
|
34
|
+
interface BoxFileEntry {
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly size?: number;
|
|
37
|
+
readonly type: "directory" | "file" | "symlink";
|
|
38
|
+
}
|
|
39
|
+
interface BoxFileOptions {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}
|
|
42
|
+
interface BoxListFilesOptions extends BoxFileOptions {
|
|
43
|
+
exclude?: readonly string[];
|
|
44
|
+
recursive?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface BoxRemoveFileOptions extends BoxFileOptions {
|
|
47
|
+
recursive?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface BoxFiles {
|
|
50
|
+
exists(path: string, options?: BoxFileOptions): Promise<boolean>;
|
|
51
|
+
list(path: string, options?: BoxListFilesOptions): Promise<readonly BoxFileEntry[]>;
|
|
52
|
+
mkdir(path: string, options?: BoxFileOptions & {
|
|
53
|
+
recursive?: boolean;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
move?(source: string, destination: string, options?: BoxFileOptions): Promise<void>;
|
|
56
|
+
read(path: string, options?: BoxFileOptions): Promise<Uint8Array | null>;
|
|
57
|
+
remove(path: string, options?: BoxRemoveFileOptions): Promise<void>;
|
|
58
|
+
write(path: string, contents: Uint8Array, options?: BoxFileOptions): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
interface BoxPorts {
|
|
61
|
+
readonly values: readonly number[];
|
|
62
|
+
expose(port: number, options?: {
|
|
63
|
+
protocol?: "http" | "https" | "ws";
|
|
64
|
+
}): Promise<URL>;
|
|
65
|
+
}
|
|
66
|
+
interface BoxSession {
|
|
67
|
+
readonly cwd: string;
|
|
68
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
69
|
+
readonly files: BoxFiles;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly inspectionConcurrency?: number;
|
|
72
|
+
readonly ports?: BoxPorts;
|
|
73
|
+
readonly spawn?: (command: string, args?: readonly string[], options?: BoxExecOptions) => Promise<BoxProcess>;
|
|
74
|
+
close(): Promise<void>;
|
|
75
|
+
exec(command: string, args?: readonly string[], options?: BoxExecOptions): Promise<BoxExecResult>;
|
|
76
|
+
}
|
|
77
|
+
interface BoxEnvironment {
|
|
78
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
79
|
+
}
|
|
80
|
+
interface BoxResolvedRequirement {
|
|
81
|
+
readonly command: string;
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly timeout?: number;
|
|
84
|
+
}
|
|
85
|
+
interface BoxPlan {
|
|
86
|
+
readonly cache: {
|
|
87
|
+
readonly state: "disposable";
|
|
88
|
+
};
|
|
89
|
+
readonly environment: BoxEnvironment;
|
|
90
|
+
readonly executionAuthority: ExecutionAuthority;
|
|
91
|
+
readonly home: {
|
|
92
|
+
readonly state: readonly {
|
|
93
|
+
readonly identity: string;
|
|
94
|
+
readonly path: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
readonly identity: string;
|
|
98
|
+
readonly requirements: readonly BoxResolvedRequirement[];
|
|
99
|
+
readonly runtime: string;
|
|
100
|
+
readonly workspace: {
|
|
101
|
+
readonly path?: string;
|
|
102
|
+
readonly state: "authoritative" | "disposable";
|
|
103
|
+
readonly workDir?: "." | "workspace";
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
interface Box {
|
|
107
|
+
readonly plan: BoxPlan;
|
|
108
|
+
open(options?: BoxOpenOptions): Promise<BoxSession>;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
4
111
|
//#region src/runtime/providers/vercel.d.ts
|
|
5
112
|
type SandboxOptions = {
|
|
6
113
|
local: SandboxDefinitionOptions;
|
|
7
114
|
provider: VercelSandboxProviderOptions;
|
|
8
115
|
};
|
|
9
|
-
declare function
|
|
116
|
+
declare function resolveVercelSandboxBox(options: SandboxOptions): Promise<{
|
|
10
117
|
provider: "vercel";
|
|
11
118
|
resolveBox: (requirements: readonly string[]) => Promise<Box>;
|
|
12
119
|
}>;
|
|
13
120
|
//#endregion
|
|
14
|
-
export {
|
|
121
|
+
export { resolveVercelSandboxBox };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveVercelBox } from "@vite-hub/box/vercel";
|
|
1
|
+
import { resolveVercelBox } from "@vite-hub/box/_internal/vercel";
|
|
2
2
|
//#region src/internal/shared/env.ts
|
|
3
3
|
function readNonEmptyEnv(env, ...keys) {
|
|
4
4
|
for (const key of keys) {
|
|
@@ -31,7 +31,7 @@ function resolveCredentials(provider) {
|
|
|
31
31
|
projectId
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
async function
|
|
34
|
+
async function resolveVercelSandboxBox(options) {
|
|
35
35
|
const credentials = resolveCredentials(options.provider);
|
|
36
36
|
const boxOptions = {
|
|
37
37
|
runtime: options.provider.runtime || "node24",
|
|
@@ -48,4 +48,4 @@ async function resolveSandboxBox(options) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
|
-
export {
|
|
51
|
+
export { resolveVercelSandboxBox };
|
package/dist/runtime/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SandboxDefinitionBundle, l as SandboxDefinitionOptions, t as AgentSandboxConfig } from "../module-types-
|
|
1
|
+
import { a as SandboxDefinitionBundle, l as SandboxDefinitionOptions, t as AgentSandboxConfig } from "../module-types-DKYItiOu.js";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/state.d.ts
|
|
4
4
|
type SandboxRegistryEntry = {
|
|
@@ -8,10 +8,19 @@ type SandboxRegistryEntry = {
|
|
|
8
8
|
type SandboxRuntimeRegistry = Record<string, SandboxRegistryEntry | (() => Promise<{
|
|
9
9
|
default?: SandboxRegistryEntry;
|
|
10
10
|
}>)>;
|
|
11
|
+
type GeneratedSandboxRuntimeRegistryEntry = {
|
|
12
|
+
load: () => Promise<{
|
|
13
|
+
default?: SandboxRegistryEntry;
|
|
14
|
+
}>;
|
|
15
|
+
stablePath: string;
|
|
16
|
+
};
|
|
17
|
+
type GeneratedSandboxRuntimeRegistry = Record<string, GeneratedSandboxRuntimeRegistryEntry>;
|
|
18
|
+
declare function createGeneratedSandboxModuleSpecifier(path: string, recover?: boolean): string;
|
|
19
|
+
declare function createGeneratedSandboxRuntimeRegistry(scope: string, registry: GeneratedSandboxRuntimeRegistry): SandboxRuntimeRegistry;
|
|
11
20
|
declare function getSandboxRuntimeConfig(): false | AgentSandboxConfig | undefined;
|
|
12
21
|
declare function getSandboxRuntimeRegistry(): SandboxRuntimeRegistry | undefined;
|
|
13
22
|
declare function setSandboxRuntimeConfig(config: false | AgentSandboxConfig | undefined): void;
|
|
14
23
|
declare function setSandboxRuntimeRegistry(registry: SandboxRuntimeRegistry | undefined): void;
|
|
15
24
|
declare function resetSandboxRuntimeState(): void;
|
|
16
25
|
//#endregion
|
|
17
|
-
export { SandboxRegistryEntry, SandboxRuntimeRegistry, getSandboxRuntimeConfig, getSandboxRuntimeRegistry, resetSandboxRuntimeState, setSandboxRuntimeConfig, setSandboxRuntimeRegistry };
|
|
26
|
+
export { SandboxRegistryEntry, SandboxRuntimeRegistry, createGeneratedSandboxModuleSpecifier, createGeneratedSandboxRuntimeRegistry, getSandboxRuntimeConfig, getSandboxRuntimeRegistry, resetSandboxRuntimeState, setSandboxRuntimeConfig, setSandboxRuntimeRegistry };
|
package/dist/runtime/state.js
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
1
2
|
//#region src/runtime/state.ts
|
|
2
3
|
let sandboxConfig;
|
|
3
4
|
let sandboxRegistry;
|
|
5
|
+
const generatedRegistries = /* @__PURE__ */ new Map();
|
|
6
|
+
const generatedRegistryOwnership = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
let generatedRegistryRecoveryId = 0;
|
|
8
|
+
function isMissingGeneratedSandboxModule(error) {
|
|
9
|
+
const code = Reflect.get(Object(error), "code");
|
|
10
|
+
return code === "ENOENT" || code === "ERR_MODULE_NOT_FOUND";
|
|
11
|
+
}
|
|
12
|
+
function createGeneratedSandboxModuleSpecifier(path, recover = false) {
|
|
13
|
+
const normalizedPath = path.replaceAll("\\", "/");
|
|
14
|
+
const url = normalizedPath.startsWith("file:") ? new URL(normalizedPath) : pathToFileURL(normalizedPath);
|
|
15
|
+
if (recover) url.searchParams.set("vitehub-recovery", String(++generatedRegistryRecoveryId));
|
|
16
|
+
return url.href;
|
|
17
|
+
}
|
|
18
|
+
async function loadActiveGeneratedSandboxDefinition(scope, name) {
|
|
19
|
+
const activeEntry = (await import(
|
|
20
|
+
/* @vite-ignore */
|
|
21
|
+
createGeneratedSandboxModuleSpecifier(scope, true)
|
|
22
|
+
)).default?.[name];
|
|
23
|
+
if (!activeEntry) throw new Error(`[vitehub] Sandbox definition "${name}" is no longer generated.`);
|
|
24
|
+
return typeof activeEntry === "function" ? await activeEntry() : { default: activeEntry };
|
|
25
|
+
}
|
|
26
|
+
function createGeneratedSandboxRuntimeRegistry(scope, registry) {
|
|
27
|
+
const runtimeRegistry = Object.fromEntries(Object.keys(registry).map((name) => [name, async () => {
|
|
28
|
+
const activeRegistry = generatedRegistries.get(scope);
|
|
29
|
+
const entry = activeRegistry === void 0 ? registry[name] : activeRegistry[name];
|
|
30
|
+
if (!entry) throw new Error(`[vitehub] Sandbox definition "${name}" is no longer generated.`);
|
|
31
|
+
try {
|
|
32
|
+
return await entry.load();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!isMissingGeneratedSandboxModule(error)) throw error;
|
|
35
|
+
try {
|
|
36
|
+
return await import(
|
|
37
|
+
/* @vite-ignore */
|
|
38
|
+
createGeneratedSandboxModuleSpecifier(entry.stablePath, true)
|
|
39
|
+
);
|
|
40
|
+
} catch (stableError) {
|
|
41
|
+
if (!isMissingGeneratedSandboxModule(stableError)) throw stableError;
|
|
42
|
+
return await loadActiveGeneratedSandboxDefinition(scope, name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}]));
|
|
46
|
+
generatedRegistryOwnership.set(runtimeRegistry, {
|
|
47
|
+
registry,
|
|
48
|
+
scope
|
|
49
|
+
});
|
|
50
|
+
return runtimeRegistry;
|
|
51
|
+
}
|
|
4
52
|
function getSandboxRuntimeConfig() {
|
|
5
53
|
return sandboxConfig;
|
|
6
54
|
}
|
|
@@ -12,10 +60,13 @@ function setSandboxRuntimeConfig(config) {
|
|
|
12
60
|
}
|
|
13
61
|
function setSandboxRuntimeRegistry(registry) {
|
|
14
62
|
sandboxRegistry = registry;
|
|
63
|
+
const generated = registry && generatedRegistryOwnership.get(registry);
|
|
64
|
+
if (generated) generatedRegistries.set(generated.scope, generated.registry);
|
|
15
65
|
}
|
|
16
66
|
function resetSandboxRuntimeState() {
|
|
17
67
|
sandboxConfig = void 0;
|
|
18
68
|
sandboxRegistry = void 0;
|
|
69
|
+
generatedRegistries.clear();
|
|
19
70
|
}
|
|
20
71
|
//#endregion
|
|
21
|
-
export { getSandboxRuntimeConfig, getSandboxRuntimeRegistry, resetSandboxRuntimeState, setSandboxRuntimeConfig, setSandboxRuntimeRegistry };
|
|
72
|
+
export { createGeneratedSandboxModuleSpecifier, createGeneratedSandboxRuntimeRegistry, getSandboxRuntimeConfig, getSandboxRuntimeRegistry, resetSandboxRuntimeState, setSandboxRuntimeConfig, setSandboxRuntimeRegistry };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import { t as AgentSandboxConfig } from "./module-types-
|
|
1
|
+
import { t as AgentSandboxConfig } from "./module-types-DKYItiOu.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
|
|
4
|
+
//#region src/internal/shared/feature-definitions.d.ts
|
|
5
|
+
interface ScannedDefinition {
|
|
6
|
+
name: string;
|
|
7
|
+
handler: string;
|
|
8
|
+
_meta: {
|
|
9
|
+
filename: string;
|
|
10
|
+
sourcePath: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/discovery.d.ts
|
|
15
|
+
interface DiscoveredSandboxDefinition extends ScannedDefinition {
|
|
16
|
+
kind: 'definition' | 'package-entry';
|
|
17
|
+
source: 'server-sandboxes' | 'vite-suffix';
|
|
18
|
+
}
|
|
19
|
+
declare function discoverSandboxDefinitions(options: {
|
|
20
|
+
mode?: 'vite-suffix';
|
|
21
|
+
rootDir: string;
|
|
22
|
+
scanDirs?: string[];
|
|
23
|
+
} | {
|
|
24
|
+
mode: 'server-sandboxes';
|
|
25
|
+
scanDirs: string[];
|
|
26
|
+
}): DiscoveredSandboxDefinition[];
|
|
27
|
+
//#endregion
|
|
4
28
|
//#region src/vite.d.ts
|
|
5
29
|
type SandboxPublicOptions = AgentSandboxConfig | false;
|
|
6
30
|
type SandboxVitePlugin = Plugin & {
|
|
@@ -21,4 +45,4 @@ declare module 'vite' {
|
|
|
21
45
|
}
|
|
22
46
|
}
|
|
23
47
|
//#endregion
|
|
24
|
-
export { SandboxPublicOptions, SandboxVitePlugin, hubSandbox };
|
|
48
|
+
export { type DiscoveredSandboxDefinition, SandboxPublicOptions, SandboxVitePlugin, discoverSandboxDefinitions, hubSandbox };
|