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