@computesdk/sandbox0 1.0.21 → 1.0.23

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.js CHANGED
@@ -22543,10 +22543,11 @@ function normalizeMemory(value) {
22543
22543
  }
22544
22544
  function buildClaimOptions(config, options) {
22545
22545
  const providerOptions = options;
22546
- const ttl = optionalPositiveSeconds("ttl", providerOptions?.ttl ?? config.ttl);
22546
+ const timeoutSeconds = typeof options?.timeout === "number" && Number.isFinite(options.timeout) && options.timeout > 0 ? Math.ceil(options.timeout / 1e3) : void 0;
22547
+ const ttl = optionalPositiveSeconds("ttl", providerOptions?.ttl ?? timeoutSeconds ?? config.ttl);
22547
22548
  const hardTtl = optionalPositiveSeconds(
22548
22549
  "hardTtl",
22549
- providerOptions?.hardTtl ?? config.hardTtl
22550
+ providerOptions?.hardTtl ?? timeoutSeconds ?? config.hardTtl
22550
22551
  );
22551
22552
  const autoResume = providerOptions?.autoResume;
22552
22553
  if (autoResume !== void 0 && typeof autoResume !== "boolean") {
@@ -22874,17 +22875,44 @@ var _provider = (0, import_provider.defineProvider)({
22874
22875
  const second = await readViaCommand(`cat ${path}`);
22875
22876
  return Buffer.byteLength(second) >= Buffer.byteLength(first) ? second : first;
22876
22877
  };
22878
+ const readDirect = async () => {
22879
+ const decoder = new TextDecoder();
22880
+ const read = (suffix) => sandbox.readFile(`${base}.${suffix}`);
22881
+ try {
22882
+ const [out, err, outLen, errLen, code] = await withinCommandDeadline(
22883
+ Promise.all([read("out"), read("err"), read("outlen"), read("errlen"), read("code")]),
22884
+ deadline,
22885
+ timeout
22886
+ );
22887
+ const expected = (bytes) => Number.parseInt(decoder.decode(bytes).trim(), 10);
22888
+ if (out.byteLength !== expected(outLen) || err.byteLength !== expected(errLen)) {
22889
+ return void 0;
22890
+ }
22891
+ return [decoder.decode(out), decoder.decode(err), decoder.decode(code)];
22892
+ } catch (error) {
22893
+ if (error instanceof Sandbox0CommandTimeoutError) throw error;
22894
+ return void 0;
22895
+ }
22896
+ };
22877
22897
  let stdout;
22878
22898
  let stderr;
22879
22899
  let codeText;
22880
- try {
22881
- stdout = await readVerified(`${base}.out`, `${base}.outlen`);
22882
- stderr = await readVerified(`${base}.err`, `${base}.errlen`);
22883
- codeText = await readViaCommand(`cat ${base}.code 2>/dev/null`).catch(() => "");
22884
- } finally {
22885
- await readViaCommand(
22900
+ const direct = await readDirect();
22901
+ if (direct) {
22902
+ [stdout, stderr, codeText] = direct;
22903
+ void readViaCommand(
22886
22904
  `rm -f ${base}.out ${base}.err ${base}.outlen ${base}.errlen ${base}.code`
22887
22905
  ).catch(() => void 0);
22906
+ } else {
22907
+ try {
22908
+ stdout = await readVerified(`${base}.out`, `${base}.outlen`);
22909
+ stderr = await readVerified(`${base}.err`, `${base}.errlen`);
22910
+ codeText = await readViaCommand(`cat ${base}.code 2>/dev/null`).catch(() => "");
22911
+ } finally {
22912
+ await readViaCommand(
22913
+ `rm -f ${base}.out ${base}.err ${base}.outlen ${base}.errlen ${base}.code`
22914
+ ).catch(() => void 0);
22915
+ }
22888
22916
  }
22889
22917
  const fileExit = Number.parseInt(codeText.trim(), 10);
22890
22918
  return {