@meistrari/sandbox-sdk 1.0.0 → 1.0.1

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
@@ -288,7 +288,39 @@ class SandboxClient {
288
288
  if (!res.ok) {
289
289
  throw await FetchError.from(url, "POST", res);
290
290
  }
291
- yield* parseSSEStream(res);
291
+ let capturedRunId;
292
+ try {
293
+ for await (const event of parseSSEStream(res)) {
294
+ if (event.type === "run_created" && event.runId) {
295
+ capturedRunId = event.runId;
296
+ }
297
+ yield event;
298
+ }
299
+ } catch (error) {
300
+ if (!capturedRunId) {
301
+ throw error;
302
+ }
303
+ let run = await this.getRun(capturedRunId);
304
+ if (!run.isComplete) {
305
+ run = await run.waitForCompletion();
306
+ }
307
+ if (run.stdout) {
308
+ yield { type: "stdout", content: run.stdout };
309
+ }
310
+ if (run.stderr) {
311
+ yield { type: "stderr", content: run.stderr };
312
+ }
313
+ yield {
314
+ type: "done",
315
+ runId: capturedRunId,
316
+ sandboxId: run.sandboxId,
317
+ metadata: {
318
+ exitCode: run.exitCode ?? 0,
319
+ durationMs: run.durationMs,
320
+ errorMessage: run.errorMessage
321
+ }
322
+ };
323
+ }
292
324
  }
293
325
  async getRun(runId) {
294
326
  const response = await this.fetch(`/api/runs/${runId}`);
package/dist/index.mjs CHANGED
@@ -286,7 +286,39 @@ class SandboxClient {
286
286
  if (!res.ok) {
287
287
  throw await FetchError.from(url, "POST", res);
288
288
  }
289
- yield* parseSSEStream(res);
289
+ let capturedRunId;
290
+ try {
291
+ for await (const event of parseSSEStream(res)) {
292
+ if (event.type === "run_created" && event.runId) {
293
+ capturedRunId = event.runId;
294
+ }
295
+ yield event;
296
+ }
297
+ } catch (error) {
298
+ if (!capturedRunId) {
299
+ throw error;
300
+ }
301
+ let run = await this.getRun(capturedRunId);
302
+ if (!run.isComplete) {
303
+ run = await run.waitForCompletion();
304
+ }
305
+ if (run.stdout) {
306
+ yield { type: "stdout", content: run.stdout };
307
+ }
308
+ if (run.stderr) {
309
+ yield { type: "stderr", content: run.stderr };
310
+ }
311
+ yield {
312
+ type: "done",
313
+ runId: capturedRunId,
314
+ sandboxId: run.sandboxId,
315
+ metadata: {
316
+ exitCode: run.exitCode ?? 0,
317
+ durationMs: run.durationMs,
318
+ errorMessage: run.errorMessage
319
+ }
320
+ };
321
+ }
290
322
  }
291
323
  async getRun(runId) {
292
324
  const response = await this.fetch(`/api/runs/${runId}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/sandbox-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {