@meistrari/sandbox-sdk 1.0.0 → 1.0.2

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,62 @@ 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
+ let receivedDone = false;
293
+ let stdoutBytesEmitted = 0;
294
+ let stderrBytesEmitted = 0;
295
+ try {
296
+ for await (const event of parseSSEStream(res)) {
297
+ if (event.type === "run_created" && event.runId) {
298
+ capturedRunId = event.runId;
299
+ }
300
+ if (event.type === "done" || event.type === "error") {
301
+ receivedDone = true;
302
+ }
303
+ if (event.type === "stdout" && event.content) {
304
+ stdoutBytesEmitted += event.content.length;
305
+ }
306
+ if (event.type === "stderr" && event.content) {
307
+ stderrBytesEmitted += event.content.length;
308
+ }
309
+ yield event;
310
+ }
311
+ } catch (error) {
312
+ if (receivedDone) {
313
+ return;
314
+ }
315
+ if (!capturedRunId) {
316
+ throw error;
317
+ }
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 > stdoutBytesEmitted) {
331
+ yield { type: "stdout", content: run.stdout.slice(stdoutBytesEmitted) };
332
+ }
333
+ if (run.stderr && run.stderr.length > stderrBytesEmitted) {
334
+ yield { type: "stderr", content: run.stderr.slice(stderrBytesEmitted) };
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
+ };
346
+ }
292
347
  }
293
348
  async getRun(runId) {
294
349
  const response = await this.fetch(`/api/runs/${runId}`);
package/dist/index.mjs CHANGED
@@ -286,7 +286,62 @@ 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
+ let receivedDone = false;
291
+ let stdoutBytesEmitted = 0;
292
+ let stderrBytesEmitted = 0;
293
+ try {
294
+ for await (const event of parseSSEStream(res)) {
295
+ if (event.type === "run_created" && event.runId) {
296
+ capturedRunId = event.runId;
297
+ }
298
+ if (event.type === "done" || event.type === "error") {
299
+ receivedDone = true;
300
+ }
301
+ if (event.type === "stdout" && event.content) {
302
+ stdoutBytesEmitted += event.content.length;
303
+ }
304
+ if (event.type === "stderr" && event.content) {
305
+ stderrBytesEmitted += event.content.length;
306
+ }
307
+ yield event;
308
+ }
309
+ } catch (error) {
310
+ if (receivedDone) {
311
+ return;
312
+ }
313
+ if (!capturedRunId) {
314
+ throw error;
315
+ }
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 > stdoutBytesEmitted) {
329
+ yield { type: "stdout", content: run.stdout.slice(stdoutBytesEmitted) };
330
+ }
331
+ if (run.stderr && run.stderr.length > stderrBytesEmitted) {
332
+ yield { type: "stderr", content: run.stderr.slice(stderrBytesEmitted) };
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
+ };
344
+ }
290
345
  }
291
346
  async getRun(runId) {
292
347
  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.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {