@iso4/sandbox 0.1.0 → 0.2.0
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.d.mts +32 -1
- package/dist/index.mjs +20 -9
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -448,8 +448,22 @@ interface RunOptions {
|
|
|
448
448
|
signal?: AbortSignal;
|
|
449
449
|
filename?: string;
|
|
450
450
|
}
|
|
451
|
-
|
|
451
|
+
/**
|
|
452
|
+
* Why a run was aborted — whatever value was passed to the aborting
|
|
453
|
+
* `AbortController.abort(reason)` (or left `undefined`). Opaque to iso4 and
|
|
454
|
+
* surfaced verbatim on {@link RunAborted.reason}; a consumer built on top
|
|
455
|
+
* (e.g. a durable-workflow kernel expressing "suspend") gives it meaning.
|
|
456
|
+
*/
|
|
457
|
+
type AbortReason = unknown;
|
|
458
|
+
type RunResult = RunSuccess | RunFailure | RunAborted;
|
|
459
|
+
/**
|
|
460
|
+
* `status` is the primary discriminant across all three outcomes; `ok` is kept
|
|
461
|
+
* as a convenience alias for `status === 'completed'`, so the common guard
|
|
462
|
+
* stays `if (result.ok)`. Reach for `switch (result.status)` when a deliberate
|
|
463
|
+
* abort must be told apart from a genuine failure.
|
|
464
|
+
*/
|
|
452
465
|
interface RunSuccess {
|
|
466
|
+
status: "completed";
|
|
453
467
|
ok: true;
|
|
454
468
|
exports: SandboxExports;
|
|
455
469
|
stdout: string[];
|
|
@@ -457,8 +471,25 @@ interface RunSuccess {
|
|
|
457
471
|
durationMs: number;
|
|
458
472
|
}
|
|
459
473
|
interface RunFailure {
|
|
474
|
+
status: "failed";
|
|
475
|
+
ok: false;
|
|
476
|
+
error: RunError;
|
|
477
|
+
stdout: string[];
|
|
478
|
+
stderr: string[];
|
|
479
|
+
durationMs: number;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* The run was stopped by an abort — a pre-aborted or mid-run `signal` passed to
|
|
483
|
+
* `run()`, or a host handler that aborted the run. A deliberate outcome, not a
|
|
484
|
+
* crash: `error` is retained (its `code` is always `ERR_ABORTED`) so existing
|
|
485
|
+
* `!result.ok` / `error.code` checks keep working, and `reason` carries the
|
|
486
|
+
* value handed to `abort(reason)`.
|
|
487
|
+
*/
|
|
488
|
+
interface RunAborted {
|
|
489
|
+
status: "aborted";
|
|
460
490
|
ok: false;
|
|
461
491
|
error: RunError;
|
|
492
|
+
reason?: AbortReason;
|
|
462
493
|
stdout: string[];
|
|
463
494
|
stderr: string[];
|
|
464
495
|
durationMs: number;
|
package/dist/index.mjs
CHANGED
|
@@ -225,6 +225,7 @@ function decodeRunCompletionPayload(buf) {
|
|
|
225
225
|
return {
|
|
226
226
|
runId,
|
|
227
227
|
result: {
|
|
228
|
+
status: "completed",
|
|
228
229
|
ok: true,
|
|
229
230
|
exports: wireObjectToExports(exportsRaw),
|
|
230
231
|
stdout,
|
|
@@ -247,6 +248,7 @@ function decodeRunCompletionPayload(buf) {
|
|
|
247
248
|
return {
|
|
248
249
|
runId,
|
|
249
250
|
result: {
|
|
251
|
+
status: "failed",
|
|
250
252
|
ok: false,
|
|
251
253
|
error: {
|
|
252
254
|
code,
|
|
@@ -743,9 +745,12 @@ function formatByte(byte) {
|
|
|
743
745
|
* `RunResult`.
|
|
744
746
|
*/
|
|
745
747
|
var RunAbortedError = class extends Error {
|
|
746
|
-
|
|
748
|
+
/** The value passed to `AbortController.abort(reason)`, if any. */
|
|
749
|
+
reason;
|
|
750
|
+
constructor(reason, message = "run was aborted") {
|
|
747
751
|
super(message);
|
|
748
752
|
this.name = "RunAbortedError";
|
|
753
|
+
this.reason = reason;
|
|
749
754
|
}
|
|
750
755
|
};
|
|
751
756
|
var RuntimeIpcClient = class RuntimeIpcClient {
|
|
@@ -885,7 +890,7 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
885
890
|
async drainUntilResult(dispatcher, signal) {
|
|
886
891
|
if (signal?.aborted) {
|
|
887
892
|
this.abortConnection();
|
|
888
|
-
throw new RunAbortedError();
|
|
893
|
+
throw new RunAbortedError(signal.reason);
|
|
889
894
|
}
|
|
890
895
|
const onAbort = () => {
|
|
891
896
|
this.abortConnection();
|
|
@@ -894,7 +899,7 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
894
899
|
try {
|
|
895
900
|
return await this.drainFrames(dispatcher);
|
|
896
901
|
} catch (error) {
|
|
897
|
-
if (signal?.aborted) throw new RunAbortedError();
|
|
902
|
+
if (signal?.aborted) throw new RunAbortedError(signal.reason);
|
|
898
903
|
throw error;
|
|
899
904
|
} finally {
|
|
900
905
|
signal?.removeEventListener("abort", onAbort);
|
|
@@ -1474,16 +1479,20 @@ function toWireLimits(limits) {
|
|
|
1474
1479
|
* The `RunResult` returned when a run is aborted — whether the signal was
|
|
1475
1480
|
* already aborted at run entry or fired mid-flight (surfaced as a
|
|
1476
1481
|
* `RunAbortedError` from the client). Shared so both paths produce an
|
|
1477
|
-
* identical shape.
|
|
1482
|
+
* identical shape. `error` (code `ERR_ABORTED`) is retained for backward
|
|
1483
|
+
* compatibility; `reason` carries whatever was passed to `abort(reason)`.
|
|
1484
|
+
* @param reason
|
|
1478
1485
|
*/
|
|
1479
|
-
function abortedResult() {
|
|
1486
|
+
function abortedResult(reason) {
|
|
1480
1487
|
return {
|
|
1488
|
+
status: "aborted",
|
|
1481
1489
|
ok: false,
|
|
1482
1490
|
error: {
|
|
1483
1491
|
code: "ERR_ABORTED",
|
|
1484
1492
|
name: "AbortError",
|
|
1485
1493
|
message: "run was aborted"
|
|
1486
1494
|
},
|
|
1495
|
+
reason,
|
|
1487
1496
|
stdout: [],
|
|
1488
1497
|
stderr: [],
|
|
1489
1498
|
durationMs: 0
|
|
@@ -1506,7 +1515,7 @@ var SandboxImpl = class {
|
|
|
1506
1515
|
return this._alive;
|
|
1507
1516
|
}
|
|
1508
1517
|
async run(options) {
|
|
1509
|
-
if (options.signal?.aborted) return abortedResult();
|
|
1518
|
+
if (options.signal?.aborted) return abortedResult(options.signal.reason);
|
|
1510
1519
|
const { bridgeGlobals, preamble } = processGlobals(options.globals ?? {});
|
|
1511
1520
|
const { bindings, registry, shape: _shape } = processImports(options.imports);
|
|
1512
1521
|
const allGlobals = registry.size > 0 ? {
|
|
@@ -1525,7 +1534,7 @@ var SandboxImpl = class {
|
|
|
1525
1534
|
})).result).result;
|
|
1526
1535
|
});
|
|
1527
1536
|
} catch (error) {
|
|
1528
|
-
if (error instanceof RunAbortedError) return abortedResult();
|
|
1537
|
+
if (error instanceof RunAbortedError) return abortedResult(error.reason);
|
|
1529
1538
|
throw error;
|
|
1530
1539
|
}
|
|
1531
1540
|
}
|
|
@@ -1609,6 +1618,7 @@ var PrefixImpl = class {
|
|
|
1609
1618
|
}
|
|
1610
1619
|
async run(options) {
|
|
1611
1620
|
if (!this._alive) return {
|
|
1621
|
+
status: "failed",
|
|
1612
1622
|
ok: false,
|
|
1613
1623
|
error: {
|
|
1614
1624
|
code: "ERR_PREFIX_DISPOSED",
|
|
@@ -1619,13 +1629,14 @@ var PrefixImpl = class {
|
|
|
1619
1629
|
stderr: [],
|
|
1620
1630
|
durationMs: 0
|
|
1621
1631
|
};
|
|
1622
|
-
if (options.signal?.aborted) return abortedResult();
|
|
1632
|
+
if (options.signal?.aborted) return abortedResult(options.signal.reason);
|
|
1623
1633
|
const bridgeGlobals = extractBridgeGlobals(options.globals ?? {}, this.defaultGlobals);
|
|
1624
1634
|
let registry;
|
|
1625
1635
|
try {
|
|
1626
1636
|
registry = extractRebindImports(options.imports, this.defaultRegistry, this.declaredImportShape);
|
|
1627
1637
|
} catch (e) {
|
|
1628
1638
|
if (e instanceof UndeclaredImportBindingError) return {
|
|
1639
|
+
status: "failed",
|
|
1629
1640
|
ok: false,
|
|
1630
1641
|
error: {
|
|
1631
1642
|
code: "ERR_UNDECLARED_BINDING",
|
|
@@ -1654,7 +1665,7 @@ var PrefixImpl = class {
|
|
|
1654
1665
|
})).result).result;
|
|
1655
1666
|
});
|
|
1656
1667
|
} catch (error) {
|
|
1657
|
-
if (error instanceof RunAbortedError) return abortedResult();
|
|
1668
|
+
if (error instanceof RunAbortedError) return abortedResult(error.reason);
|
|
1658
1669
|
throw error;
|
|
1659
1670
|
}
|
|
1660
1671
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iso4/sandbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fast, sandboxed V8 isolate runtime for agent-generated JavaScript. Two-process architecture for crash isolation.",
|
|
6
6
|
"keywords": [
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"vitest": "^4.1.5"
|
|
48
48
|
},
|
|
49
49
|
"optionalDependencies": {
|
|
50
|
-
"@iso4/v8-darwin-arm64": "^0.
|
|
51
|
-
"@iso4/v8-darwin-x64": "^0.
|
|
52
|
-
"@iso4/v8-linux-arm64-gnu": "^0.
|
|
53
|
-
"@iso4/v8-linux-x64-gnu": "^0.
|
|
50
|
+
"@iso4/v8-darwin-arm64": "^0.2.0",
|
|
51
|
+
"@iso4/v8-darwin-x64": "^0.2.0",
|
|
52
|
+
"@iso4/v8-linux-arm64-gnu": "^0.2.0",
|
|
53
|
+
"@iso4/v8-linux-x64-gnu": "^0.2.0"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=24.0.0"
|