@computesdk/sandbox0 1.0.16 → 1.0.18

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/dist/index.mjs CHANGED
@@ -22474,7 +22474,7 @@ var SandboxRuntimeMetricName2 = models.SandboxRuntimeMetricName;
22474
22474
  var SandboxRuntimeMetricStatistic2 = models.SandboxRuntimeMetricStatistic;
22475
22475
 
22476
22476
  // src/index.ts
22477
- import { defineProvider, resolveVolumeRef, withVolumeSettle } from "@computesdk/provider";
22477
+ import { defineProvider, resolveVolumeRef, isUnifiedVolumeMounts, withVolumeSettle } from "@computesdk/provider";
22478
22478
  var observations = /* @__PURE__ */ new WeakMap();
22479
22479
  function env(name) {
22480
22480
  return typeof process !== "undefined" ? process.env?.[name] : void 0;
@@ -22542,7 +22542,7 @@ function buildClaimOptions(config, options) {
22542
22542
  ...Object.keys(sandboxConfig).length > 0 ? { config: sandboxConfig } : {},
22543
22543
  ...options?.snapshotId ? { snapshotId: options.snapshotId } : {},
22544
22544
  // Unified mounts → claim's [{sandboxvolumeId, mountPoint}] wire shape.
22545
- ...Array.isArray(options?.volumes) && options.volumes.length > 0 ? {
22545
+ ...isUnifiedVolumeMounts(options?.volumes) ? {
22546
22546
  mounts: options.volumes.map((m) => {
22547
22547
  const ref = resolveVolumeRef(m.volume);
22548
22548
  const sandboxvolumeId = ref.id ?? ref.name;
@@ -22578,6 +22578,12 @@ function isRetryable(error) {
22578
22578
  const status = statusCode(error);
22579
22579
  return status === 429 || status !== void 0 && status >= 500 && status <= 599;
22580
22580
  }
22581
+ function isRateLimited(error) {
22582
+ return statusCode(error) === 429;
22583
+ }
22584
+ function isRuntimeNotReady(error) {
22585
+ return error instanceof Error && /not ready for this generation/i.test(error.message);
22586
+ }
22581
22587
  function retryDelay(error, attempt) {
22582
22588
  const retryAfter = error instanceof APIError ? error.retryAfter : void 0;
22583
22589
  if (retryAfter !== void 0) {
@@ -22782,13 +22788,25 @@ var _provider = defineProvider({
22782
22788
  const timeout = options?.timeout ?? observations.get(sandbox)?.commandTimeout;
22783
22789
  const ttlSec = commandTimeoutSeconds(timeout);
22784
22790
  const deadline = timeout !== void 0 && timeout > 0 ? startedAt + timeout : void 0;
22785
- const started = await sandbox.cmd(command, {
22786
- command: ["sh", "-lc", command],
22787
- wait: false,
22788
- cwd: options?.cwd,
22789
- envVars: options?.env,
22790
- ttlSec
22791
- });
22791
+ let started;
22792
+ for (let attempt = 0; ; attempt += 1) {
22793
+ try {
22794
+ started = await sandbox.cmd(command, {
22795
+ command: ["sh", "-lc", command],
22796
+ wait: false,
22797
+ cwd: options?.cwd,
22798
+ envVars: options?.env,
22799
+ ttlSec
22800
+ });
22801
+ break;
22802
+ } catch (error) {
22803
+ const remaining = deadline === void 0 ? Number.POSITIVE_INFINITY : deadline - Date.now();
22804
+ if (!isRuntimeNotReady(error) && !isRateLimited(error) || remaining <= 0 || attempt >= 5) {
22805
+ throw error;
22806
+ }
22807
+ await sleep(Math.min(retryDelay(error, attempt), Math.max(1, remaining)));
22808
+ }
22809
+ }
22792
22810
  if (options?.background) {
22793
22811
  return {
22794
22812
  stdout: started.stdout || "",