@vite-hub/sandbox 0.0.3 → 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-DfXe133f.d.ts → module-types-DKYItiOu.d.ts} +2 -0
- package/dist/{provider-loader-hL7uHVWp.d.ts → provider-loader-D0UihePq.d.ts} +1 -1
- package/dist/runtime/provider-loader.d.ts +1 -1
- package/dist/runtime/providers/cloudflare.d.ts +1 -1
- package/dist/runtime/providers/cloudflare.js +1 -1
- package/dist/runtime/providers/vercel.d.ts +11 -2
- 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 +1089 -132
- package/package.json +17 -4
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 };
|