@tangle-network/agent-app 0.55.6 → 0.55.7

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.
@@ -42,7 +42,7 @@ import {
42
42
  flattenHistory,
43
43
  readSandboxBinaryBytes,
44
44
  statSandboxFileSize
45
- } from "../chunk-OXDA7G4E.js";
45
+ } from "../chunk-73WE4UQG.js";
46
46
  import "../chunk-MCYJON3F.js";
47
47
  import "../chunk-LWSJK546.js";
48
48
  import "../chunk-7YLSF33A.js";
@@ -1770,16 +1770,32 @@ function stoppedBoxResumeError(box, cause) {
1770
1770
  async function resumeStoppedBox(box, timeoutMs, runtimeEnv, onProgress) {
1771
1771
  try {
1772
1772
  livenessVerifiedAt.delete(box.id);
1773
- await box.resume({
1774
- timeoutMs,
1775
- ...Object.keys(runtimeEnv).length > 0 ? { env: runtimeEnv } : {}
1776
- });
1773
+ await resumeWithRequiredRuntimeEnv(box, timeoutMs, runtimeEnv);
1777
1774
  await box.waitFor("running", { timeoutMs, ...onProgress ? { onProgress } : {} });
1778
1775
  return ok(box);
1779
1776
  } catch (cause) {
1780
1777
  return fail(stoppedBoxResumeError(box, cause));
1781
1778
  }
1782
1779
  }
1780
+ async function resumeWithRequiredRuntimeEnv(box, timeoutMs, runtimeEnv) {
1781
+ const deadline = Date.now() + timeoutMs;
1782
+ try {
1783
+ await box.resume({ timeoutMs });
1784
+ } catch (cause) {
1785
+ const missingEnvKeys = resumeEnvRequiredKeys(cause);
1786
+ if (!missingEnvKeys?.length || missingEnvKeys.some((key) => runtimeEnv[key] === void 0)) throw cause;
1787
+ await box.resume({
1788
+ timeoutMs: Math.max(1, deadline - Date.now()),
1789
+ env: Object.fromEntries(missingEnvKeys.map((key) => [key, runtimeEnv[key]]))
1790
+ });
1791
+ }
1792
+ }
1793
+ function resumeEnvRequiredKeys(cause) {
1794
+ if (typeof cause !== "object" || cause === null) return void 0;
1795
+ const { code, missingEnvKeys } = cause;
1796
+ if (code !== "RESUME_ENV_REQUIRED" || !Array.isArray(missingEnvKeys)) return void 0;
1797
+ return missingEnvKeys.filter((key) => typeof key === "string");
1798
+ }
1783
1799
  async function recoverUnresponsiveBox(client, box, probe, stage, name, resumeTimeout, runtimeEnv, onProgress) {
1784
1800
  try {
1785
1801
  await box.stop();
@@ -2853,4 +2869,4 @@ export {
2853
2869
  isTerminalPromptEvent,
2854
2870
  detectInteractiveQuestion
2855
2871
  };
2856
- //# sourceMappingURL=chunk-OXDA7G4E.js.map
2872
+ //# sourceMappingURL=chunk-73WE4UQG.js.map