@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,19 +1,20 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { r as markBuiltInSandboxRuntime } from "./runtime-DHp6ImeP.js";
3
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
4
- import { t as stopMarkedProcesses } from "./process-sweep-CMaujWE5.js";
5
- import { a as sandboxRequirementSecrets, i as sandboxRequirementPlan, n as collectSandboxRequirementOutput, o as sandboxRequirementSignal, r as sandboxRequirementError, s as materializeGitCheckout, t as createSandboxSession } from "./session-e0lyzjJ3.js";
6
- import { t as acquireFileLock } from "./file-lock-D0-XPogS.js";
7
- import { t as isTrustedHostReservedCommandEnvironmentKey } from "./trusted-host-environment-CWKJ7DD_.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
3
+ import { t as stopMarkedProcesses } from "./process-sweep-DVaTb2pO.js";
4
+ import { t as isTrustedHostReservedCommandEnvironmentKey } from "./trusted-host-environment-BJE5hGtQ.js";
5
+ import { a as sandboxRequirementSecrets, i as sandboxRequirementPlan, n as collectSandboxRequirementOutput, o as sandboxRequirementSignal, r as sandboxRequirementError, s as materializeGitCheckout, t as createSandboxSession } from "./session-DmUiyj4O.js";
6
+ import { r as markBuiltInSandboxRuntime } from "./runtime-EtWFVKud.js";
7
+ import { t as acquireFileLock } from "./file-lock-CqA7b491.js";
8
8
  import { createHash, randomUUID } from "node:crypto";
9
9
  import { access, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, symlink, writeFile } from "node:fs/promises";
10
10
  import { basename, delimiter, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
11
11
  import { execFile, spawn } from "node:child_process";
12
12
  import { promisify } from "node:util";
13
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
13
14
  import { tmpdir } from "node:os";
14
15
  import { constants } from "node:fs";
15
16
  import { Readable, Writable } from "node:stream";
16
- //#region src/internal/trusted-host.ts
17
+ // src/internal/trusted-host.ts
17
18
  var trusted_host_exports = /* @__PURE__ */ __exportAll({ createTrustedHostRuntime: () => createTrustedHostRuntime });
18
19
  const baseEnvironmentKeys = [
19
20
  "ComSpec",
@@ -144,10 +145,13 @@ async function createSession(input, options, createOptions) {
144
145
  env,
145
146
  home,
146
147
  async release() {
147
- if (initializationFailed) await Promise.all(initializedState.map((path) => rm(path, {
148
- force: true,
149
- recursive: true
150
- }).catch(() => void 0)));
148
+ if (initializationFailed) {
149
+ for (const path of initializedState) await rm(path, {
150
+ force: true,
151
+ recursive: true
152
+ });
153
+ initializedState.length = 0;
154
+ }
151
155
  await releases();
152
156
  },
153
157
  root,
@@ -165,10 +169,10 @@ async function createSession(input, options, createOptions) {
165
169
  } catch (error) {
166
170
  if (session) {
167
171
  initializationFailed = true;
168
- try {
169
- await session.destroy?.();
170
- } catch {
171
- retrySessionDestroy(session);
172
+ const cleanup = await destroyFailedSession(session);
173
+ if (cleanup) {
174
+ scheduleFailedSessionDestroy(session);
175
+ throw new AggregateError([error, cleanup.error], `[vitehub] Trusted-host Sandbox initialization failed: ${failureMessage(error)} Cleanup failed: ${failureMessage(cleanup.error)}`);
172
176
  }
173
177
  } else {
174
178
  await Promise.all(initializedState.map((path) => rm(path, {
@@ -184,16 +188,28 @@ async function createSession(input, options, createOptions) {
184
188
  throw error;
185
189
  }
186
190
  }
187
- async function retrySessionDestroy(session) {
188
- while (true) {
189
- await new Promise((resolvePromise) => {
190
- setTimeout(resolvePromise, 250).unref?.();
191
- });
191
+ const failedSessionDestroyAttempts = 3;
192
+ const failedSessionDestroyDelayMs = 250;
193
+ async function destroyFailedSession(session) {
194
+ let failure;
195
+ for (let attempt = 0; attempt < failedSessionDestroyAttempts; attempt++) {
196
+ if (failure) await setTimeout$1(failedSessionDestroyDelayMs);
192
197
  try {
193
- await session.destroy?.();
198
+ await session.destroy();
194
199
  return;
195
- } catch {}
200
+ } catch (error) {
201
+ failure = { error };
202
+ }
196
203
  }
204
+ return failure;
205
+ }
206
+ function scheduleFailedSessionDestroy(session) {
207
+ setTimeout(() => {
208
+ session.destroy().catch(() => scheduleFailedSessionDestroy(session));
209
+ }, failedSessionDestroyDelayMs).unref();
210
+ }
211
+ function failureMessage(error) {
212
+ return error instanceof Error ? error.message || error.name : String(error);
197
213
  }
198
214
  async function provisionTrustedHostToolchain(toolchain, directory, stateRoot, env, abortSignal) {
199
215
  const { hostToolchainCacheRoot, provisionHostToolchain, toolchainPath } = await import("./internal/host-toolchain.js");
@@ -703,5 +719,4 @@ function waitForExit(child) {
703
719
  if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve();
704
720
  return new Promise((resolvePromise) => child.once("close", () => resolvePromise()));
705
721
  }
706
- //#endregion
707
722
  export { trusted_host_exports as n, createTrustedHostRuntime as t };
@@ -1,4 +1,4 @@
1
- //#region src/internal/trusted-host-environment.ts
1
+ // src/internal/trusted-host-environment.ts
2
2
  const reservedCommandEnvironmentKeys = /* @__PURE__ */ new Set([
3
3
  "CODEX_HOME",
4
4
  "HOME",
@@ -12,5 +12,4 @@ const reservedCommandEnvironmentKeys = /* @__PURE__ */ new Set([
12
12
  function isTrustedHostReservedCommandEnvironmentKey(name) {
13
13
  return reservedCommandEnvironmentKeys.has(name);
14
14
  }
15
- //#endregion
16
15
  export { isTrustedHostReservedCommandEnvironmentKey as t };
@@ -1,18 +1,14 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { r as markBuiltInSandboxRuntime } from "./runtime-DHp6ImeP.js";
3
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
4
- import { t as shellQuote } from "./shell-quote-Q3u3plif.js";
5
- import { t as listCommandFiles } from "./file-listing-CHtRrfo1.js";
6
- import { i as resolveRemoteEnvironment, n as openRemoteSandbox, r as remoteSandboxPlan, t as collectProcessOutput } from "./remote-70ZVZZlq.js";
7
- import { n as killOnAbort } from "./abortable-CR01hzfi.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { t as listCommandFiles } from "./file-listing-BF122soX.js";
3
+ import { i as resolveRemoteEnvironment, n as openRemoteSandbox, r as remoteSandboxPlan, t as collectProcessOutput } from "./remote-DlyX1drC.js";
4
+ import { t as shellQuote } from "./shell-quote-MrD49m3N.js";
5
+ import { r as markBuiltInSandboxRuntime } from "./runtime-EtWFVKud.js";
6
+ import { n as killOnAbort } from "./abortable-DrHeTo1e.js";
7
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-CApUyzzu.js";
8
8
  import { randomUUID } from "node:crypto";
9
9
  import { posix } from "node:path";
10
- //#region src/vercel.ts
11
- var vercel_exports = /* @__PURE__ */ __exportAll({
12
- createVercelRuntime: () => createVercelRuntime,
13
- loadVercelSandbox: () => loadVercelSandbox
14
- });
15
- /** The signals that the Vercel Sandbox SDK sends by name. Other signals use their number. */
10
+ // src/vercel.ts
11
+ var vercel_exports = /* @__PURE__ */ __exportAll({ createVercelRuntime: () => createVercelRuntime });
16
12
  const vercelSignalNames = [
17
13
  "SIGHUP",
18
14
  "SIGINT",
@@ -283,7 +279,6 @@ function vercelProcess(process, stdin) {
283
279
  }
284
280
  };
285
281
  }
286
- /** Bounds each channel independently so an unread channel cannot stall its sibling. */
287
282
  function streamLogs(command) {
288
283
  const bufferLimit = 1048576;
289
284
  const encoder = new TextEncoder();
@@ -291,13 +286,16 @@ function streamLogs(command) {
291
286
  const iterator = command.logs({ signal: abort.signal })[Symbol.asyncIterator]();
292
287
  const open = /* @__PURE__ */ new Map();
293
288
  let stopped = false;
289
+ const isAbortReason = (error) => error === abort.signal.reason || error instanceof Error && error.name === "AbortError";
294
290
  const stop = async () => {
295
291
  if (stopped) return;
296
292
  stopped = true;
297
293
  abort.abort();
298
294
  try {
299
295
  await iterator.return?.();
300
- } catch {}
296
+ } catch (error) {
297
+ if (!isAbortReason(error)) throw error;
298
+ }
301
299
  };
302
300
  const stream = (name) => new ReadableStream({
303
301
  cancel() {
@@ -314,25 +312,32 @@ function streamLogs(command) {
314
312
  };
315
313
  (async () => {
316
314
  try {
317
- while (open.size > 0) {
318
- const entry = await iterator.next();
319
- if (entry.done) break;
320
- const line = entry.value;
321
- const controller = open.get(line.stream);
322
- if (!controller || line.data.length === 0) continue;
323
- const chunk = new Uint8Array(Math.min(line.data.length * 3, controller.desiredSize ?? 0));
324
- const { read, written } = encoder.encodeInto(line.data, chunk);
325
- if (read < line.data.length) {
326
- controller.error(sandboxErrorDiagnostics.SANDBOX_R0159({ message: `Vercel ${line.stream} exceeded the ${bufferLimit}-byte output buffer limit. Consume both streams concurrently or cancel unused output.` }));
327
- open.delete(line.stream);
328
- } else controller.enqueue(written === chunk.byteLength ? chunk : chunk.slice(0, written));
315
+ try {
316
+ while (open.size > 0) {
317
+ const entry = await iterator.next();
318
+ if (entry.done) break;
319
+ const line = entry.value;
320
+ const controller = open.get(line.stream);
321
+ if (!controller || line.data.length === 0) continue;
322
+ const chunk = new Uint8Array(Math.min(line.data.length * 3, controller.desiredSize ?? 0));
323
+ const { read, written } = encoder.encodeInto(line.data, chunk);
324
+ if (read < line.data.length) {
325
+ controller.error(sandboxErrorDiagnostics.SANDBOX_R0159({ message: `Vercel ${line.stream} exceeded the ${bufferLimit}-byte output buffer limit. Consume both streams concurrently or cancel unused output.` }));
326
+ open.delete(line.stream);
327
+ } else controller.enqueue(written === chunk.byteLength ? chunk : chunk.slice(0, written));
328
+ }
329
+ } catch (readError) {
330
+ await stop().catch((closeError) => {
331
+ throw new AggregateError([readError, closeError], "Vercel logs failed to read and close", { cause: readError });
332
+ });
333
+ throw readError;
329
334
  }
335
+ await stop();
330
336
  for (const controller of open.values()) controller.close();
331
337
  } catch (error) {
332
338
  for (const controller of open.values()) controller.error(error);
333
339
  } finally {
334
340
  open.clear();
335
- await stop();
336
341
  }
337
342
  })();
338
343
  return output;
@@ -348,5 +353,4 @@ function vercelSignal(signal) {
348
353
  });
349
354
  return known;
350
355
  }
351
- //#endregion
352
356
  export { loadVercelSandbox as n, vercel_exports as r, createVercelRuntime as t };
@@ -1,5 +1,5 @@
1
- import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-BNQwU9yq.js";
2
- //#region src/task/size.ts
1
+ import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-ClSiUwCm.js";
2
+ // src/task/size.ts
3
3
  const cloudflareInstanceTypes = [
4
4
  {
5
5
  name: "lite",
@@ -114,5 +114,19 @@ function resolveVercelSandboxTaskVcpus(options) {
114
114
  function formatRequest(cpu, memory) {
115
115
  return [cpu === void 0 ? "" : `cpu: ${cpu}`, memory === void 0 ? "" : `memory: ${memory}`].filter(Boolean).join(", ");
116
116
  }
117
- //#endregion
118
- export { resolveVercelSandboxTaskVcpus as a, resolveCloudflareSandboxTaskInstanceType as i, describeCloudflareInstanceType as n, readSandboxTaskSize as r, assertCloudflareInstanceTypeFits as t };
117
+ // src/task/vercel-credentials.ts
118
+ const vercelCredentialEnv = {
119
+ token: {
120
+ names: ["VITE_SANDBOX_TOKEN", "VERCEL_TOKEN"],
121
+ secret: true
122
+ },
123
+ teamId: {
124
+ names: ["VITE_SANDBOX_TEAM_ID", "VERCEL_TEAM_ID"],
125
+ secret: false
126
+ },
127
+ projectId: {
128
+ names: ["VITE_SANDBOX_PROJECT_ID", "VERCEL_PROJECT_ID"],
129
+ secret: false
130
+ }
131
+ };
132
+ export { resolveCloudflareSandboxTaskInstanceType as a, readSandboxTaskSize as i, assertCloudflareInstanceTypeFits as n, resolveVercelSandboxTaskVcpus as o, describeCloudflareInstanceType as r, vercelCredentialEnv as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/sandbox",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Portable, isolated Sandboxes for ViteHub Agents, and Sandbox Tasks that run named package projects in them.",
5
5
  "keywords": [
6
6
  "agent",
@@ -114,19 +114,19 @@
114
114
  }
115
115
  },
116
116
  "dependencies": {
117
- "@vite-hub/runtime": "0.4.1",
118
- "local-pkg": "^1.2.1",
117
+ "@vite-hub/runtime": "0.5.1",
118
+ "local-pkg": "^2.0.0",
119
119
  "mlly": "^1.8.2",
120
120
  "nostics": "1.4.0",
121
121
  "pathe": "^2.0.3",
122
122
  "picomatch": "^4.0.7",
123
- "semver": "^7.8.5",
124
- "unimport": "^6.5.0",
123
+ "semver": "^7.8.6",
124
+ "unimport": "^7.0.3",
125
125
  "yaml": "^2.9.1"
126
126
  },
127
127
  "devDependencies": {
128
128
  "@cloudflare/sandbox": "^1.0.3",
129
- "@types/node": "^24.19.1",
129
+ "@types/node": "^24.19.2",
130
130
  "@types/picomatch": "^4.0.3",
131
131
  "@types/semver": "^7.8.0",
132
132
  "@types/ssh2": "^1.15.6",
@@ -136,12 +136,12 @@
136
136
  "miniflare": "4.20260730.0",
137
137
  "ofetch": "^1.5.1",
138
138
  "publint": "^0.3.25",
139
- "rollup": "^4.64.0",
139
+ "rollup": "^4.68.8",
140
140
  "ssh2": "^1.17.0",
141
141
  "typescript": "^6.0.3",
142
- "vite": "^8.2.2",
143
- "vite-plus": "^0.3.3",
144
- "vitest": "^4.1.11",
142
+ "vite": "^8.3.8",
143
+ "vite-plus": "^1.7.0",
144
+ "vitest": "5.1.0",
145
145
  "zod": "^4.6.7"
146
146
  },
147
147
  "peerDependencies": {