@meistrari/sandbox-sdk 1.0.3 → 1.0.5

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
@@ -292,6 +292,46 @@ class SandboxClient {
292
292
  let receivedDone = false;
293
293
  let stdoutCharsEmitted = 0;
294
294
  let stderrCharsEmitted = 0;
295
+ const recoverViaPolling = async function* (client, runId, stdoutOffset, stderrOffset) {
296
+ let run;
297
+ try {
298
+ run = await client.getRun(runId);
299
+ if (!run.isComplete) {
300
+ run = await run.waitForCompletion();
301
+ }
302
+ } catch (pollError) {
303
+ yield {
304
+ type: "error",
305
+ runId,
306
+ content: pollError instanceof Error ? pollError.message : "Polling fallback failed"
307
+ };
308
+ return;
309
+ }
310
+ if (run.status !== "completed") {
311
+ yield {
312
+ type: "error",
313
+ runId,
314
+ content: run.errorMessage ?? `Run ${run.status}`
315
+ };
316
+ return;
317
+ }
318
+ if (run.stdout && run.stdout.length > stdoutOffset) {
319
+ yield { type: "stdout", content: run.stdout.slice(stdoutOffset) };
320
+ }
321
+ if (run.stderr && run.stderr.length > stderrOffset) {
322
+ yield { type: "stderr", content: run.stderr.slice(stderrOffset) };
323
+ }
324
+ yield {
325
+ type: "done",
326
+ runId,
327
+ sandboxId: run.sandboxId,
328
+ metadata: {
329
+ exitCode: run.exitCode,
330
+ durationMs: run.durationMs,
331
+ errorMessage: run.errorMessage
332
+ }
333
+ };
334
+ };
295
335
  try {
296
336
  for await (const event of parseSSEStream(res)) {
297
337
  if (event.type === "run_created" && event.runId) {
@@ -315,34 +355,11 @@ class SandboxClient {
315
355
  if (!capturedRunId) {
316
356
  throw error;
317
357
  }
318
- let run = await this.getRun(capturedRunId);
319
- if (!run.isComplete) {
320
- run = await run.waitForCompletion();
321
- }
322
- if (run.status !== "completed") {
323
- yield {
324
- type: "error",
325
- runId: capturedRunId,
326
- content: run.errorMessage ?? `Run ${run.status}`
327
- };
328
- return;
329
- }
330
- if (run.stdout && run.stdout.length > stdoutCharsEmitted) {
331
- yield { type: "stdout", content: run.stdout.slice(stdoutCharsEmitted) };
332
- }
333
- if (run.stderr && run.stderr.length > stderrCharsEmitted) {
334
- yield { type: "stderr", content: run.stderr.slice(stderrCharsEmitted) };
335
- }
336
- yield {
337
- type: "done",
338
- runId: capturedRunId,
339
- sandboxId: run.sandboxId,
340
- metadata: {
341
- exitCode: run.exitCode,
342
- durationMs: run.durationMs,
343
- errorMessage: run.errorMessage
344
- }
345
- };
358
+ yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
359
+ return;
360
+ }
361
+ if (!receivedDone && capturedRunId) {
362
+ yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
346
363
  }
347
364
  }
348
365
  async getRun(runId) {
package/dist/index.mjs CHANGED
@@ -290,6 +290,46 @@ class SandboxClient {
290
290
  let receivedDone = false;
291
291
  let stdoutCharsEmitted = 0;
292
292
  let stderrCharsEmitted = 0;
293
+ const recoverViaPolling = async function* (client, runId, stdoutOffset, stderrOffset) {
294
+ let run;
295
+ try {
296
+ run = await client.getRun(runId);
297
+ if (!run.isComplete) {
298
+ run = await run.waitForCompletion();
299
+ }
300
+ } catch (pollError) {
301
+ yield {
302
+ type: "error",
303
+ runId,
304
+ content: pollError instanceof Error ? pollError.message : "Polling fallback failed"
305
+ };
306
+ return;
307
+ }
308
+ if (run.status !== "completed") {
309
+ yield {
310
+ type: "error",
311
+ runId,
312
+ content: run.errorMessage ?? `Run ${run.status}`
313
+ };
314
+ return;
315
+ }
316
+ if (run.stdout && run.stdout.length > stdoutOffset) {
317
+ yield { type: "stdout", content: run.stdout.slice(stdoutOffset) };
318
+ }
319
+ if (run.stderr && run.stderr.length > stderrOffset) {
320
+ yield { type: "stderr", content: run.stderr.slice(stderrOffset) };
321
+ }
322
+ yield {
323
+ type: "done",
324
+ runId,
325
+ sandboxId: run.sandboxId,
326
+ metadata: {
327
+ exitCode: run.exitCode,
328
+ durationMs: run.durationMs,
329
+ errorMessage: run.errorMessage
330
+ }
331
+ };
332
+ };
293
333
  try {
294
334
  for await (const event of parseSSEStream(res)) {
295
335
  if (event.type === "run_created" && event.runId) {
@@ -313,34 +353,11 @@ class SandboxClient {
313
353
  if (!capturedRunId) {
314
354
  throw error;
315
355
  }
316
- let run = await this.getRun(capturedRunId);
317
- if (!run.isComplete) {
318
- run = await run.waitForCompletion();
319
- }
320
- if (run.status !== "completed") {
321
- yield {
322
- type: "error",
323
- runId: capturedRunId,
324
- content: run.errorMessage ?? `Run ${run.status}`
325
- };
326
- return;
327
- }
328
- if (run.stdout && run.stdout.length > stdoutCharsEmitted) {
329
- yield { type: "stdout", content: run.stdout.slice(stdoutCharsEmitted) };
330
- }
331
- if (run.stderr && run.stderr.length > stderrCharsEmitted) {
332
- yield { type: "stderr", content: run.stderr.slice(stderrCharsEmitted) };
333
- }
334
- yield {
335
- type: "done",
336
- runId: capturedRunId,
337
- sandboxId: run.sandboxId,
338
- metadata: {
339
- exitCode: run.exitCode,
340
- durationMs: run.durationMs,
341
- errorMessage: run.errorMessage
342
- }
343
- };
356
+ yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
357
+ return;
358
+ }
359
+ if (!receivedDone && capturedRunId) {
360
+ yield* recoverViaPolling(this, capturedRunId, stdoutCharsEmitted, stderrCharsEmitted);
344
361
  }
345
362
  }
346
363
  async getRun(runId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/sandbox-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {