@meistrari/sandbox-sdk 1.0.5 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -289,15 +289,21 @@ class SandboxClient {
289
289
  throw await FetchError.from(url, "POST", res);
290
290
  }
291
291
  let capturedRunId;
292
- let receivedDone = false;
292
+ let receivedTerminalEvent = false;
293
293
  let stdoutCharsEmitted = 0;
294
294
  let stderrCharsEmitted = 0;
295
+ const streamStartMs = Date.now();
296
+ const timeoutMs = this.timeout;
295
297
  const recoverViaPolling = async function* (client, runId, stdoutOffset, stderrOffset) {
296
298
  let run;
297
299
  try {
298
300
  run = await client.getRun(runId);
299
301
  if (!run.isComplete) {
300
- run = await run.waitForCompletion();
302
+ const elapsedMs = Date.now() - streamStartMs;
303
+ const remainingMs = timeoutMs - elapsedMs;
304
+ const intervalMs = 500;
305
+ const maxAttempts = Math.max(1, Math.floor(remainingMs / intervalMs));
306
+ run = await run.waitForCompletion({ intervalMs, maxAttempts });
301
307
  }
302
308
  } catch (pollError) {
303
309
  yield {
@@ -338,7 +344,7 @@ class SandboxClient {
338
344
  capturedRunId = event.runId;
339
345
  }
340
346
  if (event.type === "done" || event.type === "error") {
341
- receivedDone = true;
347
+ receivedTerminalEvent = true;
342
348
  }
343
349
  if (event.type === "stdout" && event.content) {
344
350
  stdoutCharsEmitted += event.content.length;
@@ -349,7 +355,7 @@ class SandboxClient {
349
355
  yield event;
350
356
  }
351
357
  } catch (error) {
352
- if (receivedDone) {
358
+ if (receivedTerminalEvent) {
353
359
  return;
354
360
  }
355
361
  if (!capturedRunId) {
@@ -358,7 +364,7 @@ class SandboxClient {
358
364
  yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
359
365
  return;
360
366
  }
361
- if (!receivedDone && capturedRunId) {
367
+ if (!receivedTerminalEvent && capturedRunId) {
362
368
  yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
363
369
  }
364
370
  }
package/dist/index.mjs CHANGED
@@ -287,15 +287,21 @@ class SandboxClient {
287
287
  throw await FetchError.from(url, "POST", res);
288
288
  }
289
289
  let capturedRunId;
290
- let receivedDone = false;
290
+ let receivedTerminalEvent = false;
291
291
  let stdoutCharsEmitted = 0;
292
292
  let stderrCharsEmitted = 0;
293
+ const streamStartMs = Date.now();
294
+ const timeoutMs = this.timeout;
293
295
  const recoverViaPolling = async function* (client, runId, stdoutOffset, stderrOffset) {
294
296
  let run;
295
297
  try {
296
298
  run = await client.getRun(runId);
297
299
  if (!run.isComplete) {
298
- run = await run.waitForCompletion();
300
+ const elapsedMs = Date.now() - streamStartMs;
301
+ const remainingMs = timeoutMs - elapsedMs;
302
+ const intervalMs = 500;
303
+ const maxAttempts = Math.max(1, Math.floor(remainingMs / intervalMs));
304
+ run = await run.waitForCompletion({ intervalMs, maxAttempts });
299
305
  }
300
306
  } catch (pollError) {
301
307
  yield {
@@ -336,7 +342,7 @@ class SandboxClient {
336
342
  capturedRunId = event.runId;
337
343
  }
338
344
  if (event.type === "done" || event.type === "error") {
339
- receivedDone = true;
345
+ receivedTerminalEvent = true;
340
346
  }
341
347
  if (event.type === "stdout" && event.content) {
342
348
  stdoutCharsEmitted += event.content.length;
@@ -347,7 +353,7 @@ class SandboxClient {
347
353
  yield event;
348
354
  }
349
355
  } catch (error) {
350
- if (receivedDone) {
356
+ if (receivedTerminalEvent) {
351
357
  return;
352
358
  }
353
359
  if (!capturedRunId) {
@@ -356,7 +362,7 @@ class SandboxClient {
356
362
  yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
357
363
  return;
358
364
  }
359
- if (!receivedDone && capturedRunId) {
365
+ if (!receivedTerminalEvent && capturedRunId) {
360
366
  yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
361
367
  }
362
368
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/sandbox-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {