@meistrari/sandbox-sdk 1.0.1 → 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 +28 -5
- package/dist/index.mjs +28 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -289,14 +289,29 @@ class SandboxClient {
|
|
|
289
289
|
throw await FetchError.from(url, "POST", res);
|
|
290
290
|
}
|
|
291
291
|
let capturedRunId;
|
|
292
|
+
let receivedDone = false;
|
|
293
|
+
let stdoutBytesEmitted = 0;
|
|
294
|
+
let stderrBytesEmitted = 0;
|
|
292
295
|
try {
|
|
293
296
|
for await (const event of parseSSEStream(res)) {
|
|
294
297
|
if (event.type === "run_created" && event.runId) {
|
|
295
298
|
capturedRunId = event.runId;
|
|
296
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
|
+
}
|
|
297
309
|
yield event;
|
|
298
310
|
}
|
|
299
311
|
} catch (error) {
|
|
312
|
+
if (receivedDone) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
300
315
|
if (!capturedRunId) {
|
|
301
316
|
throw error;
|
|
302
317
|
}
|
|
@@ -304,18 +319,26 @@ class SandboxClient {
|
|
|
304
319
|
if (!run.isComplete) {
|
|
305
320
|
run = await run.waitForCompletion();
|
|
306
321
|
}
|
|
307
|
-
if (run.
|
|
308
|
-
yield {
|
|
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) };
|
|
309
332
|
}
|
|
310
|
-
if (run.stderr) {
|
|
311
|
-
yield { type: "stderr", content: run.stderr };
|
|
333
|
+
if (run.stderr && run.stderr.length > stderrBytesEmitted) {
|
|
334
|
+
yield { type: "stderr", content: run.stderr.slice(stderrBytesEmitted) };
|
|
312
335
|
}
|
|
313
336
|
yield {
|
|
314
337
|
type: "done",
|
|
315
338
|
runId: capturedRunId,
|
|
316
339
|
sandboxId: run.sandboxId,
|
|
317
340
|
metadata: {
|
|
318
|
-
exitCode: run.exitCode
|
|
341
|
+
exitCode: run.exitCode,
|
|
319
342
|
durationMs: run.durationMs,
|
|
320
343
|
errorMessage: run.errorMessage
|
|
321
344
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -287,14 +287,29 @@ class SandboxClient {
|
|
|
287
287
|
throw await FetchError.from(url, "POST", res);
|
|
288
288
|
}
|
|
289
289
|
let capturedRunId;
|
|
290
|
+
let receivedDone = false;
|
|
291
|
+
let stdoutBytesEmitted = 0;
|
|
292
|
+
let stderrBytesEmitted = 0;
|
|
290
293
|
try {
|
|
291
294
|
for await (const event of parseSSEStream(res)) {
|
|
292
295
|
if (event.type === "run_created" && event.runId) {
|
|
293
296
|
capturedRunId = event.runId;
|
|
294
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
|
+
}
|
|
295
307
|
yield event;
|
|
296
308
|
}
|
|
297
309
|
} catch (error) {
|
|
310
|
+
if (receivedDone) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
298
313
|
if (!capturedRunId) {
|
|
299
314
|
throw error;
|
|
300
315
|
}
|
|
@@ -302,18 +317,26 @@ class SandboxClient {
|
|
|
302
317
|
if (!run.isComplete) {
|
|
303
318
|
run = await run.waitForCompletion();
|
|
304
319
|
}
|
|
305
|
-
if (run.
|
|
306
|
-
yield {
|
|
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) };
|
|
307
330
|
}
|
|
308
|
-
if (run.stderr) {
|
|
309
|
-
yield { type: "stderr", content: run.stderr };
|
|
331
|
+
if (run.stderr && run.stderr.length > stderrBytesEmitted) {
|
|
332
|
+
yield { type: "stderr", content: run.stderr.slice(stderrBytesEmitted) };
|
|
310
333
|
}
|
|
311
334
|
yield {
|
|
312
335
|
type: "done",
|
|
313
336
|
runId: capturedRunId,
|
|
314
337
|
sandboxId: run.sandboxId,
|
|
315
338
|
metadata: {
|
|
316
|
-
exitCode: run.exitCode
|
|
339
|
+
exitCode: run.exitCode,
|
|
317
340
|
durationMs: run.durationMs,
|
|
318
341
|
errorMessage: run.errorMessage
|
|
319
342
|
}
|