@vite-hub/sandbox 0.4.1 → 0.5.1

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.
Files changed (55) hide show
  1. package/dist/{abortable-CR01hzfi.js → abortable-DrHeTo1e.js} +1 -2
  2. package/dist/{cloudflare-Cog_r2Me.js → cloudflare-DrNRQPeh.js} +13 -27
  3. package/dist/{cloudflare-env-lookup-DzI6Xv1Y.js → cloudflare-env-lookup-BNbNil7g.js} +1 -2
  4. package/dist/{cloudflare-failure-CFQhalfh.js → cloudflare-failure-f-3P3ul-.js} +1 -2
  5. package/dist/{container-CqfD8yuE.js → container-DOadzngt.js} +7 -13
  6. package/dist/{crabbox-sbV3Zjuo.js → crabbox-C7KeIKnH.js} +7 -12
  7. package/dist/{error-diagnostics-BJtLRL9w.js → error-diagnostics-CApUyzzu.js} +1 -2
  8. package/dist/{error-diagnostics-BNQwU9yq.js → error-diagnostics-ClSiUwCm.js} +1 -2
  9. package/dist/{file-listing-CHtRrfo1.js → file-listing-BF122soX.js} +3 -4
  10. package/dist/{file-lock-D0-XPogS.js → file-lock-CqA7b491.js} +3 -4
  11. package/dist/{index-DsoQAUb7.d.ts → index-D9DogaoF.d.ts} +0 -15
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +12 -14
  14. package/dist/internal/cloudflare.d.ts +2 -5
  15. package/dist/internal/cloudflare.js +3 -4
  16. package/dist/internal/host-toolchain.d.ts +2 -4
  17. package/dist/internal/host-toolchain.js +4 -5
  18. package/dist/internal/vercel.d.ts +2 -4
  19. package/dist/internal/vercel.js +3 -4
  20. package/dist/{invariant-DolT9EEx.js → invariant-Dj2R1eMr.js} +1 -2
  21. package/dist/{module-types-BoOZiNN4.d.ts → module-types-B3uJG1po.d.ts} +1 -9
  22. package/dist/{module-types-B0LQ5H2S.js → module-types-CWcBHyEs.js} +1 -2
  23. package/dist/{process-sweep-CMaujWE5.js → process-sweep-DVaTb2pO.js} +1 -2
  24. package/dist/{provider-loader-BDgDJ6bX.d.ts → provider-loader-CNKHrWXG.d.ts} +2 -6
  25. package/dist/{provider-resolution-BrQfEQo0.js → provider-resolution-Cl2NKhRP.js} +5 -8
  26. package/dist/{remote-70ZVZZlq.js → remote-DlyX1drC.js} +5 -10
  27. package/dist/{rolldown-runtime-8H4AJuhK.js → rolldown-runtime-BJohB4LM.js} +1 -2
  28. package/dist/{runtime-DHp6ImeP.js → runtime-EtWFVKud.js} +1 -2
  29. package/dist/{runtime-type-Deo4qzxN.js → runtime-type-Dk-rJXlr.js} +1 -2
  30. package/dist/{session-e0lyzjJ3.js → session-DmUiyj4O.js} +5 -8
  31. package/dist/{shell-quote-Q3u3plif.js → shell-quote-MrD49m3N.js} +1 -2
  32. package/dist/ssh.d.ts +1 -3
  33. package/dist/ssh.js +11 -9
  34. package/dist/task/index.d.ts +1 -16
  35. package/dist/task/index.js +23 -44
  36. package/dist/task/runtime/empty-registry.d.ts +0 -2
  37. package/dist/task/runtime/empty-registry.js +1 -2
  38. package/dist/task/runtime/provider-loader.d.ts +1 -1
  39. package/dist/task/runtime/provider-loader.js +2 -3
  40. package/dist/task/runtime/providers/cloudflare.d.ts +3 -4
  41. package/dist/task/runtime/providers/cloudflare.js +3 -4
  42. package/dist/task/runtime/providers/local.d.ts +2 -4
  43. package/dist/task/runtime/providers/local.js +3 -4
  44. package/dist/task/runtime/providers/vercel.d.ts +3 -4
  45. package/dist/task/runtime/providers/vercel.js +9 -16
  46. package/dist/task/runtime/state.d.ts +3 -4
  47. package/dist/task/runtime/state.js +2 -3
  48. package/dist/task/vite.d.ts +24 -23
  49. package/dist/task/vite.js +108 -116
  50. package/dist/{toolchain-BIVGMRty.js → toolchain-DFFxmw3N.js} +6 -13
  51. package/dist/{trusted-host-RanFsFSB.js → trusted-host-CwMs64h1.js} +39 -24
  52. package/dist/{trusted-host-environment-CWKJ7DD_.js → trusted-host-environment-BJE5hGtQ.js} +1 -2
  53. package/dist/{vercel-BGGrNpza.js → vercel-DT74kDyI.js} +33 -29
  54. package/dist/{size-DJNpXeAt.js → vercel-credentials-BGuXoKxG.js} +18 -4
  55. package/package.json +10 -10
@@ -1,6 +1,6 @@
1
1
  import { readFile, readdir } from "node:fs/promises";
2
2
  import { setTimeout } from "node:timers/promises";
3
- //#region ../internal/src/process-sweep.ts
3
+ // ../internal/src/process-sweep.ts
4
4
  const maxRounds = 10;
5
5
  /**
6
6
  * Stops every process of this user that started with `name=value` in its environment: SIGTERM, then
@@ -29,5 +29,4 @@ function signal(pid, name) {
29
29
  process.kill(pid, name);
30
30
  } catch {}
31
31
  }
32
- //#endregion
33
32
  export { stopMarkedProcesses as t };
@@ -1,11 +1,8 @@
1
- import { l as Sandbox } from "./index-DsoQAUb7.js";
2
- import { f as SandboxTaskDriver, o as SandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "./module-types-BoOZiNN4.js";
1
+ import { l as Sandbox } from "./index-D9DogaoF.js";
2
+ import { f as SandboxTaskDriver, o as SandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "./module-types-B3uJG1po.js";
3
3
  import { ExecutionAuthority } from "@vite-hub/runtime";
4
- //#region src/task/runtime/task-sandbox.d.ts
5
4
  /** `local` runs a Sandbox Task as a process on this machine, which only `vite dev` does. */
6
5
  type SandboxTaskExecutionProvider = 'cloudflare' | 'vercel' | 'local';
7
- //#endregion
8
- //#region src/task/runtime/provider-loader.d.ts
9
6
  interface ResolvedTaskSandbox {
10
7
  provider: SandboxTaskExecutionProvider;
11
8
  resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
@@ -20,5 +17,4 @@ interface SandboxTaskRuntimeProvider {
20
17
  } | any) => Promise<ResolvedTaskSandbox>;
21
18
  }
22
19
  declare function loadSandboxTaskRuntimeProvider(provider: SandboxTaskDriver): Promise<SandboxTaskRuntimeProvider>;
23
- //#endregion
24
20
  export { SandboxTaskRuntimeProvider as n, loadSandboxTaskRuntimeProvider as r, ResolvedTaskSandbox as t };
@@ -1,7 +1,7 @@
1
- import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-BNQwU9yq.js";
2
- import { t as getActiveCloudflareEnv } from "./cloudflare-env-lookup-DzI6Xv1Y.js";
1
+ import { t as getActiveCloudflareEnv } from "./cloudflare-env-lookup-BNbNil7g.js";
2
+ import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-ClSiUwCm.js";
3
3
  import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
4
- //#region src/task/sandbox-task/errors.ts
4
+ // src/task/sandbox-task/errors.ts
5
5
  function sanitizeSandboxTaskDetail(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
6
6
  if (value === null || typeof value === "boolean") return value;
7
7
  if (typeof value === "string") return value.slice(0, 16384);
@@ -45,8 +45,7 @@ function sandboxTaskError(message, metadata = {}) {
45
45
  function isSandboxTaskError(value) {
46
46
  return getViteHubErrorShape(value)?.code.startsWith("SANDBOX_TASK_") === true;
47
47
  }
48
- //#endregion
49
- //#region src/task/internal/shared/provider-detection.ts
48
+ // src/task/internal/shared/provider-detection.ts
50
49
  function createProviderDetector(rules) {
51
50
  return () => {
52
51
  for (const rule of rules) if (rule.when()) return rule.provider;
@@ -63,8 +62,7 @@ const isVercel = () => {
63
62
  const env = getRuntimeEnv();
64
63
  return !!(env.VERCEL || env.VERCEL_ENV);
65
64
  };
66
- //#endregion
67
- //#region src/task/runtime/provider-resolution.ts
65
+ // src/task/runtime/provider-resolution.ts
68
66
  const allowedDefinitionKeys = /* @__PURE__ */ new Set(["timeout", "env"]);
69
67
  const maxTimeout = 2147483647;
70
68
  /** The timeout of a Sandbox Task run that sets no `timeout`, on every provider. */
@@ -129,5 +127,4 @@ function withSandboxTaskProvider(provider, options) {
129
127
  driver: provider
130
128
  };
131
129
  }
132
- //#endregion
133
130
  export { resolveTaskSandbox as a, isSandboxTaskError as c, resolveRuntimeProvider as i, sandboxTaskError as l, assertSandboxTaskDefinitionOptions as n, unsupportedHostedSandboxTaskProviderError as o, createCloudflareExecutionSandboxId as r, withSandboxTaskProvider as s, DEFAULT_SANDBOX_TASK_TIMEOUT_MS as t };
@@ -1,8 +1,8 @@
1
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
2
- import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
3
- import { a as sandboxRequirementSecrets, i as sandboxRequirementPlan, o as sandboxRequirementSignal, r as sandboxRequirementError, s as materializeGitCheckout, t as createSandboxSession } from "./session-e0lyzjJ3.js";
1
+ import { a as sandboxRequirementSecrets, i as sandboxRequirementPlan, o as sandboxRequirementSignal, r as sandboxRequirementError, s as materializeGitCheckout, t as createSandboxSession } from "./session-DmUiyj4O.js";
2
+ import { t as shellQuote } from "./shell-quote-MrD49m3N.js";
3
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
4
4
  import { normalizeExecutionAuthority } from "@vite-hub/runtime";
5
- //#region src/internal/remote.ts
5
+ // src/internal/remote.ts
6
6
  async function resolveRemoteSandboxRuntime(runtime, requirements) {
7
7
  const resolvedRequirements = requirements.map((command) => ({
8
8
  args: [],
@@ -163,13 +163,9 @@ async function settleFileOperations(operations, signal) {
163
163
  const failure = results.find((result) => result.status === "rejected");
164
164
  if (failure?.status === "rejected") throw failure.reason;
165
165
  }
166
- /**
167
- * Remote Sandboxes do not share a cache. Reuse an exact image node, otherwise upload
168
- * the verified toolchain into the Sandbox Home cache for this session.
169
- */
170
166
  async function provisionRemoteToolchain(input, session, options, environment) {
171
167
  const { abortSignal, home, workspace } = options;
172
- const { provisionToolchain, readProjectFilesWithShell, verifyToolchain } = await import("./toolchain-BIVGMRty.js").then((n) => n.i);
168
+ const { provisionToolchain, readProjectFilesWithShell, verifyToolchain } = await import("./toolchain-DFFxmw3N.js").then((n) => n.i);
173
169
  const run = async (script) => await session.run({
174
170
  abortSignal,
175
171
  command: `sh -c ${shellQuote(script)}`,
@@ -261,5 +257,4 @@ function snapshotStream(read) {
261
257
  }
262
258
  } });
263
259
  }
264
- //#endregion
265
260
  export { resolveRemoteSandboxRuntime as a, resolveRemoteEnvironment as i, openRemoteSandbox as n, snapshotStream as o, remoteSandboxPlan as r, collectProcessOutput as t };
@@ -1,5 +1,5 @@
1
1
  import "node:module";
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __defProp = Object.defineProperty;
4
4
  var __exportAll = (all, no_symbols) => {
5
5
  let target = {};
@@ -10,5 +10,4 @@ var __exportAll = (all, no_symbols) => {
10
10
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
11
  return target;
12
12
  };
13
- //#endregion
14
13
  export { __exportAll as t };
@@ -1,4 +1,4 @@
1
- //#region src/internal/runtime.ts
1
+ // src/internal/runtime.ts
2
2
  const builtInSandboxRuntime = Symbol.for("vitehub.sandbox.internal-runtime");
3
3
  function isFunction(value) {
4
4
  return typeof value === "function";
@@ -28,5 +28,4 @@ function markBuiltInSandboxRuntime(runtime) {
28
28
  Object.defineProperty(runtime, builtInSandboxRuntime, { value: true });
29
29
  return runtime;
30
30
  }
31
- //#endregion
32
31
  export { isBuiltInSandboxRuntime as n, markBuiltInSandboxRuntime as r, hasDeclaredSandboxRuntimeMember as t };
@@ -1,9 +1,8 @@
1
- //#region src/internal/runtime-type.ts
1
+ // src/internal/runtime-type.ts
2
2
  /** Returns a plain JSON-style object, or undefined for primitives, arrays, and functions. */
3
3
  function runtimeRecord(value) {
4
4
  if (value === null || Object(value) !== value || Array.isArray(value)) return;
5
5
  if (Object.prototype.toString.call(value) !== "[object Object]") return;
6
6
  return value;
7
7
  }
8
- //#endregion
9
8
  export { runtimeRecord as t };
@@ -1,7 +1,7 @@
1
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
2
- import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
1
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
2
+ import { t as shellQuote } from "./shell-quote-MrD49m3N.js";
3
3
  import { posix } from "node:path";
4
- //#region src/internal/git-checkout.ts
4
+ // src/internal/git-checkout.ts
5
5
  async function materializeGitCheckout(checkout, workspace, runner) {
6
6
  await run("initialize", [
7
7
  "init",
@@ -57,8 +57,7 @@ async function materializeGitCheckout(checkout, workspace, runner) {
57
57
  }
58
58
  }
59
59
  }
60
- //#endregion
61
- //#region src/internal/requirements.ts
60
+ // src/internal/requirements.ts
62
61
  const maximumDiagnosticLength = 4e3;
63
62
  function sandboxRequirementPlan(requirements) {
64
63
  return requirements.map(({ command, name, timeout }) => ({
@@ -152,8 +151,7 @@ function redactDiagnosticJson(value, patterns) {
152
151
  }
153
152
  return value;
154
153
  }
155
- //#endregion
156
- //#region src/internal/session.ts
154
+ // src/internal/session.ts
157
155
  function isExcludedSandboxPath(path, excluded) {
158
156
  const normalized = posix.normalize(path);
159
157
  return excluded.some((item) => {
@@ -334,5 +332,4 @@ function commandLine(command, args) {
334
332
  function assertPort(port) {
335
333
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw sandboxErrorDiagnostics.SANDBOX_R0129({ message: "[vitehub] Sandbox ports must be integers between 1 and 65535." });
336
334
  }
337
- //#endregion
338
335
  export { sandboxRequirementSecrets as a, sandboxRequirementPlan as i, collectSandboxRequirementOutput as n, sandboxRequirementSignal as o, sandboxRequirementError as r, materializeGitCheckout as s, createSandboxSession as t };
@@ -1,6 +1,5 @@
1
- //#region src/internal/shell-quote.ts
1
+ // src/internal/shell-quote.ts
2
2
  function shellQuote(value) {
3
3
  return `'${value.replaceAll("'", `'"'"'`)}'`;
4
4
  }
5
- //#endregion
6
5
  export { shellQuote as t };
package/dist/ssh.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/ssh.d.ts
2
1
  export interface SshLaunchOptions {
3
2
  host: string;
4
3
  user: string;
@@ -59,5 +58,4 @@ export interface SshServer {
59
58
  close(options?: SshServerCloseOptions): Promise<void>;
60
59
  }
61
60
  /** An authenticated command server, not a filesystem or network sandbox. */
62
- export declare function serveSsh(options: SshServerOptions): Promise<SshServer>;
63
- //#endregion
61
+ export declare function serveSsh(options: SshServerOptions): Promise<SshServer>;
package/dist/ssh.js CHANGED
@@ -1,13 +1,13 @@
1
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
2
- import { t as invariant } from "./invariant-DolT9EEx.js";
3
- import { t as stopMarkedProcesses } from "./process-sweep-CMaujWE5.js";
1
+ import { t as invariant } from "./invariant-Dj2R1eMr.js";
2
+ import { t as stopMarkedProcesses } from "./process-sweep-DVaTb2pO.js";
3
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFile } from "node:fs/promises";
6
6
  import { execFile, spawn } from "node:child_process";
7
7
  import { once } from "node:events";
8
8
  import { createServer } from "node:net";
9
9
  import { promisify } from "node:util";
10
- //#region src/ssh-launcher.injected.ts
10
+ // src/ssh-launcher.injected.ts
11
11
  /**
12
12
  * Source text of the SSH launcher. It runs in its own Node process outside the application bundle, with only Node and
13
13
  * OpenSSH, so its errors are plain. Its exit status and stderr reach the caller of `sshLaunch()`.
@@ -95,12 +95,13 @@ try {
95
95
  if (temporary) await rm(temporary, { recursive: true, force: true })
96
96
  }
97
97
  `;
98
- //#endregion
99
- //#region src/ssh.ts
98
+ // src/ssh.ts
100
99
  const maxTimeoutMs = 2147483647;
101
100
  const environmentName = /^[A-Z_][A-Z0-9_]*$/;
102
- /** Every process of one SSH command starts with this variable, so the server can stop the ones that leave its process group. */
103
101
  const commandEnvironmentKey = "VITEHUB_SSH_COMMAND";
102
+ function isClosedPipeError(error) {
103
+ return error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED";
104
+ }
104
105
  /** Launch a command on a trusted SSH host with the same working-directory path. */
105
106
  function sshLaunch(options) {
106
107
  if (!options.host || options.host.startsWith("-") || /[\s\0]/.test(options.host)) throw sandboxErrorDiagnostics.SANDBOX_SSH_LAUNCH_INVALID({ problem: "host" });
@@ -213,12 +214,14 @@ async function serveSsh(options) {
213
214
  children.add(child);
214
215
  markers.set(child, marker);
215
216
  stream.pipe(child.stdin);
216
- child.stdin.on("error", () => {});
217
217
  child.stdout.pipe(stream, { end: false });
218
218
  child.stderr.pipe(stream.stderr, { end: false });
219
219
  const terminate = () => {
220
220
  stop(child).catch(() => client.end());
221
221
  };
222
+ child.stdin.on("error", (error) => {
223
+ if (!isClosedPipeError(error)) terminate();
224
+ });
222
225
  stream.once("close", terminate);
223
226
  stream.on("error", terminate);
224
227
  child.once("exit", terminate);
@@ -282,5 +285,4 @@ async function serveSsh(options) {
282
285
  }
283
286
  };
284
287
  }
285
- //#endregion
286
288
  export { serveSsh, sshLaunch };
@@ -1,17 +1,12 @@
1
- import { _ as VercelSandboxTaskDriverOptions, a as SandboxTaskDefinitionBundle, c as SandboxTaskDefinitionHandler, d as SandboxTaskDevOptions, f as SandboxTaskDriver, g as SandboxTaskRunResult, h as SandboxTaskRunArguments, i as SandboxTaskDefinition, l as SandboxTaskDefinitionInput, m as SandboxTaskProjectOptions, n as CloudflareSandboxTaskDefinitionDriverOptions, o as SandboxTaskDefinitionDriverOptions, p as SandboxTaskExecutionOptions, r as CloudflareSandboxTaskOptions, s as SandboxTaskDefinitionFromHandler, t as AgentSandboxTaskConfig, u as SandboxTaskDefinitionOptions, v as getSandboxTaskFeatureDriver, y as SandboxTaskSizeOptions } from "../module-types-BoOZiNN4.js";
1
+ import { _ as VercelSandboxTaskDriverOptions, a as SandboxTaskDefinitionBundle, c as SandboxTaskDefinitionHandler, d as SandboxTaskDevOptions, f as SandboxTaskDriver, g as SandboxTaskRunResult, h as SandboxTaskRunArguments, i as SandboxTaskDefinition, l as SandboxTaskDefinitionInput, m as SandboxTaskProjectOptions, n as CloudflareSandboxTaskDefinitionDriverOptions, o as SandboxTaskDefinitionDriverOptions, p as SandboxTaskExecutionOptions, r as CloudflareSandboxTaskOptions, s as SandboxTaskDefinitionFromHandler, t as AgentSandboxTaskConfig, u as SandboxTaskDefinitionOptions, v as getSandboxTaskFeatureDriver, y as SandboxTaskSizeOptions } from "../module-types-B3uJG1po.js";
2
2
  import { ExecutionAuthority, ViteHubContext } from "@vite-hub/runtime";
3
3
  import { Buffer } from "node:buffer";
4
4
  import { SandboxTaskDefinitionModules } from "#vitehub-sandbox-task-registry";
5
- //#region src/task/runtime/registry.d.ts
6
5
  export declare function defineSandboxTask<THandler extends (...args: any[]) => any>(input: SandboxTaskDefinitionInput<Parameters<THandler>[0], Awaited<ReturnType<THandler>>> & {
7
6
  handler: THandler;
8
7
  }): SandboxTaskDefinitionFromHandler<THandler>;
9
- //#endregion
10
- //#region src/task/internal/shared/request-payload.d.ts
11
8
  /** Read the JSON body of the request in the event's Standard Context, or `fallback` when the body is not JSON. */
12
9
  export declare function readRequestPayload(event: ViteHubContext, fallback?: unknown): Promise<unknown>;
13
- //#endregion
14
- //#region src/task/internal/shared/validation.d.ts
15
10
  interface ValidationIssue {
16
11
  message: string;
17
12
  path?: readonly unknown[];
@@ -38,8 +33,6 @@ interface ValidationOptions<TValue = unknown> {
38
33
  }
39
34
  export declare function readValidatedPayload<TInput, TOutput>(payload: TInput, validate: StandardSchemaValidator<TInput, TOutput>, options?: ValidationOptions<TInput>): Promise<TOutput>;
40
35
  export declare function readValidatedPayload<TInput, TResult>(payload: TInput, validate: ValidationFunction<TInput, TResult>, options?: ValidationOptions<TInput>): Promise<ValidationResult<TInput, Awaited<TResult>>>;
41
- //#endregion
42
- //#region src/task/runtime/registry-types.d.ts
43
36
  type SandboxTaskDefinitionName = keyof SandboxTaskDefinitionModules;
44
37
  type SandboxTaskRegistryDefinition<TName extends keyof SandboxTaskDefinitionModules> = SandboxTaskDefinitionModules[TName];
45
38
  type SandboxTaskPayload<TDefinition> = TDefinition extends {
@@ -48,23 +41,16 @@ type SandboxTaskPayload<TDefinition> = TDefinition extends {
48
41
  type SandboxTaskResult<TDefinition> = TDefinition extends {
49
42
  result: infer TResult;
50
43
  } ? DecodedSandboxValue<TResult> : unknown;
51
- /** Model the result walk in entry-script.injected.ts, not the handler's remote object. */
52
44
  type DecodedSandboxValue<TValue, TApplyToJSON extends boolean = true> = TValue extends Response ? Response : TValue extends Blob ? Blob : TValue extends Buffer ? Buffer : TValue extends Uint8Array ? Uint8Array : TApplyToJSON extends false ? DecodedSandboxJson<TValue> : TValue extends {
53
45
  toJSON(key: string): infer TSerialized;
54
46
  } ? DecodedSandboxValue<TSerialized, false> | (TValue extends Date ? null : never) : DecodedSandboxJson<TValue>;
55
47
  type DecodedSandboxJson<TValue> = TValue extends string | number | boolean | null ? TValue : TValue extends InstanceType<StringConstructor> ? string : TValue extends InstanceType<NumberConstructor> ? number : TValue extends InstanceType<BooleanConstructor> ? boolean : TValue extends readonly unknown[] ? { [TIndex in keyof TValue]: DecodedSandboxValue<TValue[TIndex]>; } : TValue extends ((...args: never[]) => unknown) | undefined | bigint | symbol ? never : TValue extends object ? { [TKey in keyof TValue as TKey extends symbol ? never : TValue[TKey] extends ((...args: never[]) => unknown) ? never : TKey]: DecodedSandboxValue<TValue[TKey]>; } : TValue;
56
- //#endregion
57
- //#region src/task/runtime/public.d.ts
58
48
  /**
59
49
  * Run a Sandbox Task by its name. `data` is the decoded handler result, such as a JSON value or a native `Response`.
60
50
  * A failed run returns `SANDBOX_TASK_RUN_FAILED`, and `toResponse(error)` answers with its status.
61
51
  */
62
52
  export declare function runSandboxTask<const TName extends string>(name: TName, ...args: SandboxTaskRunArguments<TName extends SandboxTaskDefinitionName ? SandboxTaskPayload<SandboxTaskRegistryDefinition<TName>> : unknown>): Promise<SandboxTaskRunResult<TName extends SandboxTaskDefinitionName ? SandboxTaskResult<SandboxTaskRegistryDefinition<TName>> : unknown>>;
63
- //#endregion
64
- //#region src/task/runtime/provider-resolution.d.ts
65
53
  export declare function unsupportedHostedSandboxTaskProviderError(provider: unknown): Error;
66
- //#endregion
67
- //#region src/task/runtime/runtime.d.ts
68
54
  interface SandboxTaskRunner {
69
55
  readonly executionAuthority: ExecutionAuthority;
70
56
  name: string;
@@ -75,5 +61,4 @@ type ResolvedSandboxTaskRunner<TPayload, TResult> = Omit<SandboxTaskRunner, 'run
75
61
  };
76
62
  export declare function resolveSandboxTaskRunner<const TName extends SandboxTaskDefinitionName>(name: TName): Promise<ResolvedSandboxTaskRunner<SandboxTaskPayload<SandboxTaskRegistryDefinition<TName>>, SandboxTaskResult<SandboxTaskRegistryDefinition<TName>>>>;
77
63
  export declare function resolveSandboxTaskRunner<TPayload = unknown, TResult = unknown>(name?: string): Promise<ResolvedSandboxTaskRunner<TPayload, TResult>>;
78
- //#endregion
79
64
  export type { AgentSandboxTaskConfig, CloudflareSandboxTaskDefinitionDriverOptions, CloudflareSandboxTaskOptions, SandboxTaskDefinition, SandboxTaskDefinitionBundle, SandboxTaskDefinitionDriverOptions, SandboxTaskDefinitionFromHandler, SandboxTaskDefinitionHandler, SandboxTaskDefinitionInput, SandboxTaskDefinitionOptions, SandboxTaskDevOptions, SandboxTaskDriver, SandboxTaskExecutionOptions, SandboxTaskProjectOptions, SandboxTaskRunArguments, SandboxTaskRunResult, SandboxTaskRunner, SandboxTaskSizeOptions, VercelSandboxTaskDriverOptions, getSandboxTaskFeatureDriver };
@@ -1,14 +1,15 @@
1
- import { n as cloudflareRetryDelays, r as readCloudflareFailure, t as canRetryCloudflareRequest } from "../cloudflare-failure-CFQhalfh.js";
2
- import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-BNQwU9yq.js";
3
- import { a as resolveTaskSandbox, c as isSandboxTaskError, i as resolveRuntimeProvider, l as sandboxTaskError, n as assertSandboxTaskDefinitionOptions, o as unsupportedHostedSandboxTaskProviderError, r as createCloudflareExecutionSandboxId, s as withSandboxTaskProvider } from "../provider-resolution-BrQfEQo0.js";
4
- import { t as isTrustedHostReservedCommandEnvironmentKey } from "../trusted-host-environment-CWKJ7DD_.js";
1
+ import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-ClSiUwCm.js";
2
+ import { a as resolveTaskSandbox, c as isSandboxTaskError, i as resolveRuntimeProvider, l as sandboxTaskError, n as assertSandboxTaskDefinitionOptions, o as unsupportedHostedSandboxTaskProviderError, r as createCloudflareExecutionSandboxId, s as withSandboxTaskProvider } from "../provider-resolution-Cl2NKhRP.js";
3
+ import { n as cloudflareRetryDelays, r as readCloudflareFailure, t as canRetryCloudflareRequest } from "../cloudflare-failure-f-3P3ul-.js";
4
+ import { t as isTrustedHostReservedCommandEnvironmentKey } from "../trusted-host-environment-BJE5hGtQ.js";
5
5
  import { getSandboxTaskRuntimeConfig, getSandboxTaskRuntimeLocalProvider, getSandboxTaskRuntimeRegistry } from "./runtime/state.js";
6
- import { t as getSandboxTaskFeatureDriver } from "../module-types-B0LQ5H2S.js";
7
- import { defineErrors, deserializeResponse, getViteHubErrorShape, isSerializedResponse } from "@vite-hub/runtime";
6
+ import { t as getSandboxTaskFeatureDriver } from "../module-types-CWcBHyEs.js";
7
+ import { defineErrors, getViteHubErrorShape } from "@vite-hub/runtime";
8
8
  import { types } from "node:util";
9
9
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
10
+ import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
10
11
  import { dirname } from "pathe";
11
- //#region src/task/internal/shared/definition.ts
12
+ // src/task/internal/shared/definition.ts
12
13
  function assertDefinitionHandler(functionName, handler, label) {
13
14
  if (typeof handler !== "function") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_C0010({ message: `[vitehub] \`${functionName}()\` requires a ${label} as the first argument.` });
14
15
  }
@@ -22,8 +23,7 @@ function validateDefinitionOptions(functionName, options, config) {
22
23
  if (invalidKeys.length) throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_C0012({ message: `[vitehub] \`${functionName}()\` ${config.invalidKeysMessage}. Unsupported keys: ${invalidKeys.join(", ")}.` });
23
24
  return options;
24
25
  }
25
- //#endregion
26
- //#region src/task/runtime/registry.ts
26
+ // src/task/runtime/registry.ts
27
27
  function createSandboxTaskDefinition(functionName, input) {
28
28
  if (input instanceof Object && Object.hasOwn(input, "run")) throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_C0014({ message: `[vitehub] \`${functionName}({ run })\` was renamed. Pass the Sandbox handler as \`handler\`: \`${functionName}({ handler })\`.` });
29
29
  const validated = validateDefinitionOptions(functionName, input, {
@@ -47,14 +47,12 @@ function createSandboxTaskDefinition(functionName, input) {
47
47
  function defineSandboxTask(input) {
48
48
  return createSandboxTaskDefinition("defineSandboxTask", input);
49
49
  }
50
- //#endregion
51
- //#region src/task/internal/shared/request-payload.ts
50
+ // src/task/internal/shared/request-payload.ts
52
51
  /** Read the JSON body of the request in the event's Standard Context, or `fallback` when the body is not JSON. */
53
52
  async function readRequestPayload(event, fallback = {}) {
54
53
  return await getStandardContext(event).req.json().catch(() => fallback);
55
54
  }
56
- //#endregion
57
- //#region src/task/internal/shared/validation.ts
55
+ // src/task/internal/shared/validation.ts
58
56
  const VALIDATION_FAILED = "Validation failed";
59
57
  function isObject(value) {
60
58
  return !!value && typeof value === "object";
@@ -147,8 +145,7 @@ async function readValidatedPayload(payload, validate, options) {
147
145
  throw createValidationError(error);
148
146
  }
149
147
  }
150
- //#endregion
151
- //#region src/task/internal/shared/utils.ts
148
+ // src/task/internal/shared/utils.ts
152
149
  async function sleep(ms, signal) {
153
150
  if (signal?.aborted) throw signal.reason;
154
151
  await new Promise((resolve, reject) => {
@@ -164,8 +161,7 @@ async function sleep(ms, signal) {
164
161
  signal?.addEventListener("abort", onAbort, { once: true });
165
162
  });
166
163
  }
167
- //#endregion
168
- //#region src/task/runtime/binary-sidecars.ts
164
+ // src/task/runtime/binary-sidecars.ts
169
165
  const SANDBOX_VALUE_MARKER = "vitehub:sandbox-task:value";
170
166
  function isPlainObject(value) {
171
167
  if (!value || typeof value !== "object") return false;
@@ -302,8 +298,7 @@ async function decodeSandboxTaskValue(sandbox, value, assetsDir, label, signal)
302
298
  });
303
299
  return descriptor.kind === "blob" ? new Blob([bytes], { type: descriptor.type || "" }) : descriptor.kind === "buffer" ? Buffer.from(bytes) : bytes;
304
300
  }
305
- //#endregion
306
- //#region src/task/runtime/error-normalization.ts
301
+ // src/task/runtime/error-normalization.ts
307
302
  function readSandboxTaskErrorMetadata(error) {
308
303
  if (!error || typeof error !== "object") return void 0;
309
304
  const metadata = error;
@@ -361,8 +356,7 @@ function readErrorMessage(error) {
361
356
  function sandboxTaskCode(code) {
362
357
  return code?.startsWith("SANDBOX_TASK_") ? code : "SANDBOX_TASK_RUNTIME_ERROR";
363
358
  }
364
- //#endregion
365
- //#region src/task/runtime/entry-script.injected.ts
359
+ // src/task/runtime/entry-script.injected.ts
366
360
  const EXEC_STDIO_OUTPUT_MARKER = "__VITEHUB_OUTPUT__";
367
361
  function createEntrySource(definitionPath, execution = "definition", env) {
368
362
  const invocation = execution === "module" ? [
@@ -667,8 +661,7 @@ function createEntrySource(definitionPath, execution = "definition", env) {
667
661
  ``
668
662
  ].join("\n");
669
663
  }
670
- //#endregion
671
- //#region src/task/runtime/execution-files.ts
664
+ // src/task/runtime/execution-files.ts
672
665
  const DEFAULT_DEFINITION_ENTRY = "definition.js";
673
666
  function normalizeSandboxTaskDefinitionBundle(source) {
674
667
  if (typeof source === "string") return {
@@ -734,8 +727,7 @@ async function writeSandboxTaskDefinitionBundle(sandbox, baseDir, bundle, signal
734
727
  else await sandbox.exec("chmod", [mode.toString(8), `${baseDir}/${path}`]);
735
728
  }));
736
729
  }
737
- //#endregion
738
- //#region src/task/runtime/definition-preparation.ts
730
+ // src/task/runtime/definition-preparation.ts
739
731
  const projectPreparations = /* @__PURE__ */ new Map();
740
732
  async function prepareSandboxTaskDefinition(sandbox, bundle, baseDir, options) {
741
733
  const project = bundle.project;
@@ -833,8 +825,7 @@ async function prepareSandboxTaskProjectAtomically(sandbox, bundle, projectDir,
833
825
  ]).catch(() => {});
834
826
  }
835
827
  }
836
- //#endregion
837
- //#region src/task/runtime/output-recovery.ts
828
+ // src/task/runtime/output-recovery.ts
838
829
  const MIN_EXEC_OUTPUT_RECOVERY_TIMEOUT_MS = 2e4;
839
830
  const DEFAULT_EXEC_OUTPUT_RECOVERY_TIMEOUT_MS = 6e4;
840
831
  const MAX_EXEC_OUTPUT_RECOVERY_TIMEOUT_MS = 12e4;
@@ -852,7 +843,6 @@ function getErrorMessage(error) {
852
843
  if (error === void 0) return void 0;
853
844
  return String(error);
854
845
  }
855
- /** The handler command may still write its output when the Cloudflare request failed after it could reach the Container. */
856
846
  function mayHaveRunCloudflareExec(error) {
857
847
  const metadata = readSandboxTaskErrorMetadata(error);
858
848
  if (metadata?.provider && metadata.provider !== "cloudflare") return false;
@@ -998,8 +988,7 @@ async function readExecOutputWithRecovery(sandbox, outputPath, error, timeout, e
998
988
  }
999
989
  return await waitForCloudflareOutput(sandbox, outputPath, error, timeout, execution, signal);
1000
990
  }
1001
- //#endregion
1002
- //#region src/task/runtime/execute.ts
991
+ // src/task/runtime/execute.ts
1003
992
  const SANDBOX_CLEANUP_GRACE_MS = 1e3;
1004
993
  function toJson(value, label) {
1005
994
  try {
@@ -1185,8 +1174,7 @@ async function executeSandboxTaskDefinition(sandbox, definitionName, definitionO
1185
1174
  if (externalAbort) externalSignal?.removeEventListener("abort", externalAbort);
1186
1175
  }
1187
1176
  }
1188
- //#endregion
1189
- //#region src/task/runtime/task-sandbox.ts
1177
+ // src/task/runtime/task-sandbox.ts
1190
1178
  function createTaskSandbox(session, provider, closesAfterRun) {
1191
1179
  return {
1192
1180
  executionAuthority: session.executionAuthority,
@@ -1217,8 +1205,7 @@ function createTaskSandbox(session, provider, closesAfterRun) {
1217
1205
  }
1218
1206
  };
1219
1207
  }
1220
- //#endregion
1221
- //#region src/task/runtime/result.ts
1208
+ // src/task/runtime/result.ts
1222
1209
  const sandboxTaskRunErrors = /*#__PURE__*/ defineErrors({
1223
1210
  docs: "https://vitehub.dev/docs/sandbox/diagnostics",
1224
1211
  codes: { SANDBOX_TASK_RUN_FAILED: {
@@ -1230,7 +1217,6 @@ const sandboxTaskRunErrors = /*#__PURE__*/ defineErrors({
1230
1217
  })
1231
1218
  } }
1232
1219
  });
1233
- /** Preserve an explicit HTTP status or map the underlying diagnostic code. */
1234
1220
  function statusFor(error) {
1235
1221
  const status = error.details?.httpStatus;
1236
1222
  if (Number.isInteger(status) && Number(status) >= 400 && Number(status) <= 599) return Number(status);
@@ -1251,8 +1237,7 @@ function runFailed(name, error) {
1251
1237
  value: statusFor(error)
1252
1238
  });
1253
1239
  }
1254
- //#endregion
1255
- //#region src/task/runtime/runtime.ts
1240
+ // src/task/runtime/runtime.ts
1256
1241
  const cloudflareRunQueues = /* @__PURE__ */ new Map();
1257
1242
  async function awaitWithAbort(promise, signal) {
1258
1243
  if (!signal) return await promise;
@@ -1298,10 +1283,6 @@ async function serializeCloudflareRun(id, run, signal) {
1298
1283
  else previous.then(releaseAfterPrevious, releaseAfterPrevious);
1299
1284
  }
1300
1285
  }
1301
- /**
1302
- * A new run repeats every command of the failed one. Once a command starts, only the transport
1303
- * can retry that request on a cold start without replaying earlier work.
1304
- */
1305
1286
  function canRerunCloudflareTask(error, commandMayHaveRun) {
1306
1287
  if (commandMayHaveRun) return false;
1307
1288
  if (isSandboxTaskError(error) && error.cause instanceof AggregateError) error = error.cause.errors[0];
@@ -1418,10 +1399,8 @@ async function runSandboxTaskRuntime(name, payload, options) {
1418
1399
  return [runFailed(name ?? "", toSandboxTaskError(error)), void 0];
1419
1400
  }
1420
1401
  }
1421
- //#endregion
1422
- //#region src/task/runtime/public.ts
1402
+ // src/task/runtime/public.ts
1423
1403
  async function runSandboxTask(name, payload, options) {
1424
1404
  return await runSandboxTaskRuntime(name, payload, options);
1425
1405
  }
1426
- //#endregion
1427
1406
  export { defineSandboxTask, readRequestPayload, readValidatedPayload, resolveSandboxTaskRunner, runSandboxTask, unsupportedHostedSandboxTaskProviderError };
@@ -1,6 +1,4 @@
1
- //#region src/task/runtime/empty-registry.d.ts
2
1
  type SandboxTaskRegistry = Record<string, unknown>;
3
2
  export interface SandboxTaskDefinitionModules {}
4
3
  declare const registry: SandboxTaskRegistry;
5
- //#endregion
6
4
  export { registry as default };
@@ -1,4 +1,4 @@
1
- //#region src/task/runtime/empty-registry.ts
1
+ // src/task/runtime/empty-registry.ts
2
2
  function getRuntimeRegistry() {
3
3
  return globalThis.__vitehubSandboxTaskRegistry || {};
4
4
  }
@@ -16,5 +16,4 @@ const registry = new Proxy({}, {
16
16
  return Object.getOwnPropertyDescriptor(getRuntimeRegistry(), key);
17
17
  }
18
18
  });
19
- //#endregion
20
19
  export { registry as default };
@@ -1,2 +1,2 @@
1
- import { n as SandboxTaskRuntimeProvider, r as loadSandboxTaskRuntimeProvider, t as ResolvedTaskSandbox } from "../../provider-loader-BDgDJ6bX.js";
1
+ import { n as SandboxTaskRuntimeProvider, r as loadSandboxTaskRuntimeProvider, t as ResolvedTaskSandbox } from "../../provider-loader-CNKHrWXG.js";
2
2
  export { ResolvedTaskSandbox, SandboxTaskRuntimeProvider, loadSandboxTaskRuntimeProvider };
@@ -1,5 +1,5 @@
1
- import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-BNQwU9yq.js";
2
- //#region src/task/runtime/provider-loader.ts
1
+ import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-ClSiUwCm.js";
2
+ // src/task/runtime/provider-loader.ts
3
3
  const dynamicImport = new Function("specifier", "return import(specifier)");
4
4
  async function loadSandboxTaskRuntimeProvider(provider) {
5
5
  if (provider === "cloudflare") {
@@ -12,5 +12,4 @@ async function loadSandboxTaskRuntimeProvider(provider) {
12
12
  }
13
13
  throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_R0068({ message: `[vitehub] Unsupported sandbox provider: ${provider}` });
14
14
  }
15
- //#endregion
16
15
  export { loadSandboxTaskRuntimeProvider };
@@ -1,6 +1,5 @@
1
- import { l as Sandbox } from "../../../index-DsoQAUb7.js";
2
- import { n as CloudflareSandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-BoOZiNN4.js";
3
- //#region src/task/runtime/providers/cloudflare.d.ts
1
+ import { l as Sandbox } from "../../../index-D9DogaoF.js";
2
+ import { n as CloudflareSandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-B3uJG1po.js";
4
3
  type SandboxTaskOptions = {
5
4
  local: SandboxTaskDefinitionOptions;
6
5
  provider: CloudflareSandboxTaskDefinitionDriverOptions;
@@ -11,4 +10,4 @@ export declare function resolveCloudflareTaskSandbox(options: SandboxTaskOptions
11
10
  sandboxId: string | undefined;
12
11
  resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
13
12
  }>;
14
- //#endregion
13
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { resolveCloudflareSandbox } from "../../../internal/cloudflare.js";
2
- import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-BNQwU9yq.js";
3
- import { t as getActiveCloudflareEnv } from "../../../cloudflare-env-lookup-DzI6Xv1Y.js";
4
- //#region src/task/runtime/providers/cloudflare.ts
2
+ import { t as getActiveCloudflareEnv } from "../../../cloudflare-env-lookup-BNbNil7g.js";
3
+ import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-ClSiUwCm.js";
4
+ // src/task/runtime/providers/cloudflare.ts
5
5
  /** Resolve the Sandbox namespace from the bindings of the active Cloudflare request. */
6
6
  async function resolveCloudflareTaskSandbox(options) {
7
7
  const env = getActiveCloudflareEnv();
@@ -23,5 +23,4 @@ async function resolveCloudflareTaskSandbox(options) {
23
23
  }, requirements)
24
24
  };
25
25
  }
26
- //#endregion
27
26
  export { resolveCloudflareTaskSandbox };
@@ -1,8 +1,6 @@
1
- import { t as ResolvedTaskSandbox } from "../../../provider-loader-BDgDJ6bX.js";
2
- //#region src/task/runtime/providers/local.d.ts
1
+ import { t as ResolvedTaskSandbox } from "../../../provider-loader-CNKHrWXG.js";
3
2
  /**
4
3
  * `vite dev` runs each Sandbox Task as a Node process on this machine, in a temporary directory that the run removes.
5
4
  * The process is not isolated: the Sandbox `executionAuthority` says `isolation: "none"`.
6
5
  */
7
- export declare function resolveLocalTaskSandbox(): ResolvedTaskSandbox;
8
- //#endregion
6
+ export declare function resolveLocalTaskSandbox(): ResolvedTaskSandbox;
@@ -1,6 +1,6 @@
1
- import { a as resolveRemoteSandboxRuntime } from "../../../remote-70ZVZZlq.js";
2
- import { t as createTrustedHostRuntime } from "../../../trusted-host-RanFsFSB.js";
3
- //#region src/task/runtime/providers/local.ts
1
+ import { a as resolveRemoteSandboxRuntime } from "../../../remote-DlyX1drC.js";
2
+ import { t as createTrustedHostRuntime } from "../../../trusted-host-CwMs64h1.js";
3
+ // src/task/runtime/providers/local.ts
4
4
  /**
5
5
  * `vite dev` runs each Sandbox Task as a Node process on this machine, in a temporary directory that the run removes.
6
6
  * The process is not isolated: the Sandbox `executionAuthority` says `isolation: "none"`.
@@ -11,5 +11,4 @@ function resolveLocalTaskSandbox() {
11
11
  resolveSandbox: async (requirements) => await resolveRemoteSandboxRuntime(createTrustedHostRuntime(), requirements)
12
12
  };
13
13
  }
14
- //#endregion
15
14
  export { resolveLocalTaskSandbox };
@@ -1,6 +1,5 @@
1
- import { l as Sandbox } from "../../../index-DsoQAUb7.js";
2
- import { _ as VercelSandboxTaskDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-BoOZiNN4.js";
3
- //#region src/task/runtime/providers/vercel.d.ts
1
+ import { l as Sandbox } from "../../../index-D9DogaoF.js";
2
+ import { _ as VercelSandboxTaskDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-B3uJG1po.js";
4
3
  type SandboxTaskOptions = {
5
4
  local: SandboxTaskDefinitionOptions;
6
5
  provider: VercelSandboxTaskDriverOptions;
@@ -9,4 +8,4 @@ export declare function resolveVercelTaskSandbox(options: SandboxTaskOptions): P
9
8
  provider: "vercel";
10
9
  resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
11
10
  }>;
12
- //#endregion
11
+ export {};