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