@iso4/sandbox 0.6.1 → 0.6.3
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/README.md +10 -5
- package/dist/index.d.mts +40 -19
- package/dist/index.mjs +85 -32
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -354,15 +354,20 @@ type RunResult
|
|
|
354
354
|
// durationMs — wall-clock time of the run; cpuTimeMs — active V8 execution
|
|
355
355
|
// time (bridge waits excluded). Both measured in the runtime, µs resolution.
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
type BridgeCallEntry = { // recorded in the Rust runtime; one per attempt, in order
|
|
358
358
|
name: string // 'fetch', 'myTool', or '<specifier>.<path>' for host-module imports
|
|
359
359
|
startMs: number // offset from run start (same clock as durationMs)
|
|
360
360
|
durationMs: number // round-trip the sandbox waited (handler + IPC)
|
|
361
361
|
argBytes: number // serialized call payload size
|
|
362
|
-
responseBytes: number // serialized response value size (0
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
362
|
+
responseBytes: number // serialized response value size (0 unless ok)
|
|
363
|
+
} & (
|
|
364
|
+
| { ok: true }
|
|
365
|
+
| { ok: false, reason: 'blocked' | 'error' | 'unanswered' | 'dropped' }
|
|
366
|
+
)
|
|
367
|
+
// blocked: refused runtime-side (limit, function argument, ...), never reached the host
|
|
368
|
+
// error: the handler threw / rejected, or the host could not decode or encode a value
|
|
369
|
+
// unanswered: no answer when the run ended (handler still ran)
|
|
370
|
+
// dropped: the run was already aborted, the handler was never called
|
|
366
371
|
|
|
367
372
|
interface RunError {
|
|
368
373
|
code: RunErrorCode
|
package/dist/index.d.mts
CHANGED
|
@@ -356,7 +356,7 @@ type RebindGlobals<G extends HostGlobals> = { [K in keyof G as G[K] extends stri
|
|
|
356
356
|
type Imports<M extends Record<string, ImportValue> = Record<string, ImportValue>> = M;
|
|
357
357
|
/**
|
|
358
358
|
* A single import value. String = source module. Object = host module
|
|
359
|
-
* description (
|
|
359
|
+
* description (nested up to 64 levels, see {@link HostModuleObject}).
|
|
360
360
|
*/
|
|
361
361
|
type ImportValue = string | HostModuleObject;
|
|
362
362
|
/**
|
|
@@ -373,6 +373,11 @@ type ImportValue = string | HostModuleObject;
|
|
|
373
373
|
* path: V8's format would carry them, but only as their own enumerable
|
|
374
374
|
* properties, so the methods you meant to send would vanish silently. Copy
|
|
375
375
|
* what you mean to send into a plain object.
|
|
376
|
+
*
|
|
377
|
+
* Shapes may nest at most 64 levels (a node's path length from its top-level
|
|
378
|
+
* export). A deeper shape is rejected at registration, naming the path. Plain
|
|
379
|
+
* objects always describe shape, so this cap also applies to deep plain-object
|
|
380
|
+
* data; data in any other container is bounded only by V8's deserializer.
|
|
376
381
|
*/
|
|
377
382
|
interface HostModuleObject {
|
|
378
383
|
[name: string]: HostModuleValue;
|
|
@@ -1155,7 +1160,35 @@ interface CallSuccess {
|
|
|
1155
1160
|
* an entry (~100 bytes); consumers that only care about a subset filter the
|
|
1156
1161
|
* list themselves.
|
|
1157
1162
|
*/
|
|
1158
|
-
|
|
1163
|
+
type BridgeCallEntry = BridgeCallEntryBase & ({
|
|
1164
|
+
ok: true;
|
|
1165
|
+
} | {
|
|
1166
|
+
ok: false;
|
|
1167
|
+
reason: BridgeCallFailureReason;
|
|
1168
|
+
});
|
|
1169
|
+
/**
|
|
1170
|
+
* Why a bridge call did not succeed ({@link BridgeCallEntry} with
|
|
1171
|
+
* `ok: false`).
|
|
1172
|
+
*
|
|
1173
|
+
* - `blocked`: refused inside the runtime (`maxBridgeCalls`, payload over
|
|
1174
|
+
* `maxBridgeCallBytes`, function argument, invalid import handle, failed
|
|
1175
|
+
* write). Never reached the host; the sandbox promise rejected.
|
|
1176
|
+
* - `error`: the host answered with an error — the handler threw or
|
|
1177
|
+
* rejected, the host could not decode the arguments, or the return value
|
|
1178
|
+
* could not be serialized. The sandbox promise rejected.
|
|
1179
|
+
* - `unanswered`: sent, but no answer by the time these records were taken —
|
|
1180
|
+
* abort, a limit, an uncaught throw, or the sandbox never awaited it. The
|
|
1181
|
+
* handler ran (or is still running); its answer is discarded. On a run
|
|
1182
|
+
* with pending `waitUntil` work the Result's records are a snapshot, so a
|
|
1183
|
+
* call still in flight shows here even if it settles during the epilogue.
|
|
1184
|
+
* - `dropped`: the run's signal was already aborted when the call reached
|
|
1185
|
+
* the host, so the handler was never invoked.
|
|
1186
|
+
*/
|
|
1187
|
+
type BridgeCallFailureReason = "blocked" | "error" | "unanswered" | "dropped";
|
|
1188
|
+
/**
|
|
1189
|
+
* Fields shared by every {@link BridgeCallEntry}.
|
|
1190
|
+
*/
|
|
1191
|
+
interface BridgeCallEntryBase {
|
|
1159
1192
|
/**
|
|
1160
1193
|
* The name sandbox code called. Plain globals appear as-is (`fetch`),
|
|
1161
1194
|
* shimmed globals under their public name (not the private stub), and
|
|
@@ -1170,8 +1203,8 @@ interface BridgeCallEntry {
|
|
|
1170
1203
|
startMs: number;
|
|
1171
1204
|
/**
|
|
1172
1205
|
* Round-trip time the sandbox waited for the response (host handler + IPC),
|
|
1173
|
-
* in milliseconds. For
|
|
1174
|
-
*
|
|
1206
|
+
* in milliseconds. For `unanswered` and `dropped` calls: the time until
|
|
1207
|
+
* the run ended. `0` for blocked attempts.
|
|
1175
1208
|
*/
|
|
1176
1209
|
durationMs: number;
|
|
1177
1210
|
/**
|
|
@@ -1185,18 +1218,6 @@ interface BridgeCallEntry {
|
|
|
1185
1218
|
* handler failed or the call never settled.
|
|
1186
1219
|
*/
|
|
1187
1220
|
responseBytes: number;
|
|
1188
|
-
/**
|
|
1189
|
-
* `true` when the host handler resolved and its response reached the
|
|
1190
|
-
* sandbox. `false` for handler errors, blocked attempts, and calls still
|
|
1191
|
-
* in flight when the run ended.
|
|
1192
|
-
*/
|
|
1193
|
-
ok: boolean;
|
|
1194
|
-
/**
|
|
1195
|
-
* `true` when the attempt was blocked inside the runtime (`maxBridgeCalls`
|
|
1196
|
-
* exceeded, payload over `maxBridgeCallBytes`, function argument) and never
|
|
1197
|
-
* reached the host.
|
|
1198
|
-
*/
|
|
1199
|
-
blocked: boolean;
|
|
1200
1221
|
}
|
|
1201
1222
|
/**
|
|
1202
1223
|
* Outcome of a run's `waitUntil` grace phase, delivered through
|
|
@@ -1318,8 +1339,8 @@ interface RunSuccess {
|
|
|
1318
1339
|
queueWaitMs?: number;
|
|
1319
1340
|
/**
|
|
1320
1341
|
* One entry per bridge call the sandbox attempted, in attempt order —
|
|
1321
|
-
* including attempts
|
|
1322
|
-
* Recorded by the Rust runtime.
|
|
1342
|
+
* including attempts that never reached the host (see
|
|
1343
|
+
* {@link BridgeCallFailureReason}). Recorded by the Rust runtime.
|
|
1323
1344
|
*/
|
|
1324
1345
|
bridgeCalls: BridgeCallEntry[];
|
|
1325
1346
|
/**
|
|
@@ -1445,4 +1466,4 @@ type RunErrorCode = "ERR_USER_CODE" | "ERR_MEMORY_LIMIT" | "ERR_CPU_TIMEOUT" | "
|
|
|
1445
1466
|
//#region src/index.d.ts
|
|
1446
1467
|
declare function createSandbox(options?: SandboxOptions): Promise<Sandbox>;
|
|
1447
1468
|
//#endregion
|
|
1448
|
-
export { type BridgeCallEntry, type BridgeGlobal, type BridgeWithShim, type CallResult, type CallSuccess, type CallTarget, type CreateSandbox, type DataGlobal, type GlobalOptions, type HostExportData, type HostExportFunction, type HostGlobalValue, type HostGlobals, type HostModuleObject, type HostModuleValue, type ImportValue, type Imports, type MemoryLimit, type OneOffResourceLimits, type PrecompileOptions, type Prefix, type PrefixCallOptions, type PrefixRunOptions, type ReadExportsOptions, type ReadExportsResult, type RebindGlobals, type RebindHostModule, type RebindImports, type RebindValue, type ResetCause, type ResourceLimits, type RunCallOptions, type RunError, type RunErrorCode, type RunFailure, type RunOptions, type RunResult, type RunSuccess, type Sandbox, type SandboxExports, type SandboxOptions, type SandboxStats, type StringGlobal, type WaitUntilResult, createSandbox };
|
|
1469
|
+
export { type BridgeCallEntry, type BridgeCallEntryBase, type BridgeCallFailureReason, type BridgeGlobal, type BridgeWithShim, type CallResult, type CallSuccess, type CallTarget, type CreateSandbox, type DataGlobal, type GlobalOptions, type HostExportData, type HostExportFunction, type HostGlobalValue, type HostGlobals, type HostModuleObject, type HostModuleValue, type ImportValue, type Imports, type MemoryLimit, type OneOffResourceLimits, type PrecompileOptions, type Prefix, type PrefixCallOptions, type PrefixRunOptions, type ReadExportsOptions, type ReadExportsResult, type RebindGlobals, type RebindHostModule, type RebindImports, type RebindValue, type ResetCause, type ResourceLimits, type RunCallOptions, type RunError, type RunErrorCode, type RunFailure, type RunOptions, type RunResult, type RunSuccess, type Sandbox, type SandboxExports, type SandboxOptions, type SandboxStats, type StringGlobal, type WaitUntilResult, createSandbox };
|
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { fileURLToPath } from "node:url";
|
|
|
9
9
|
import { createConnection } from "node:net";
|
|
10
10
|
import { Buffer } from "node:buffer";
|
|
11
11
|
import v8 from "node:v8";
|
|
12
|
+
import { types } from "node:util";
|
|
12
13
|
//#region src/binary.ts
|
|
13
14
|
function resolveRuntimeBinary(options = {}) {
|
|
14
15
|
if (options.binaryPath) return options.binaryPath;
|
|
@@ -310,11 +311,6 @@ async function toDescriptor(value, brandKey, streams) {
|
|
|
310
311
|
};
|
|
311
312
|
}
|
|
312
313
|
/**
|
|
313
|
-
* Depth cap, matching `MAX_DEPTH` in `webcodec.rs`. Cycles are handled by the
|
|
314
|
-
* `seen` map, so this only bounds pathologically deep graphs.
|
|
315
|
-
*/
|
|
316
|
-
const MAX_DEPTH = 32;
|
|
317
|
-
/**
|
|
318
314
|
* Replace every `Request`/`Response`/`Headers` anywhere in `value` with a
|
|
319
315
|
* branded plain object, returning a graph ordinary serialization can write.
|
|
320
316
|
*
|
|
@@ -324,18 +320,43 @@ const MAX_DEPTH = 32;
|
|
|
324
320
|
* instance and do not reuse it afterwards (streams cannot cross the boundary,
|
|
325
321
|
* so the body must be buffered rather than forwarded). Object identity and
|
|
326
322
|
* cycles are preserved through `seen`. `Map`/`Set` are rebuilt because a host
|
|
327
|
-
* type can hide in either.
|
|
323
|
+
* type can hide in either. A value with no host type (and no Proxy) anywhere
|
|
324
|
+
* is returned as is, so the common case costs one scan and no copy. Depth is not capped:
|
|
325
|
+
* the scan is iterative and every level of the rebuild suspends on an
|
|
326
|
+
* `await`, so neither deepens the call stack.
|
|
328
327
|
* @param value the value to transform
|
|
329
328
|
* @param brandKey the sandbox's session brand key ({@link brandKeyForToken});
|
|
330
329
|
* the runtime rehydrates only descriptors stamped with it
|
|
331
330
|
* @param streams
|
|
332
331
|
*/
|
|
333
332
|
async function materializeHostTypes(value, brandKey, streams) {
|
|
334
|
-
|
|
333
|
+
if (!hasHostType(value)) return value;
|
|
334
|
+
return transform(value, brandKey, streams, /* @__PURE__ */ new Map());
|
|
335
|
+
}
|
|
336
|
+
function hasHostType(value) {
|
|
337
|
+
const seen = /* @__PURE__ */ new Set();
|
|
338
|
+
const stack = [];
|
|
339
|
+
const push = (v) => {
|
|
340
|
+
if (v !== null && typeof v === "object") stack.push(v);
|
|
341
|
+
};
|
|
342
|
+
push(value);
|
|
343
|
+
for (let v = stack.pop(); v !== void 0; v = stack.pop()) {
|
|
344
|
+
if (seen.has(v)) continue;
|
|
345
|
+
seen.add(v);
|
|
346
|
+
if (v instanceof globalThis.Response || v instanceof globalThis.Request || v instanceof globalThis.Headers || types.isProxy(v)) return true;
|
|
347
|
+
if (ArrayBuffer.isView(v) || v instanceof ArrayBuffer || v instanceof Date || v instanceof RegExp || v instanceof Error) continue;
|
|
348
|
+
if (Array.isArray(v)) for (const item of v) push(item);
|
|
349
|
+
else if (v instanceof Map) for (const [k, item] of v) {
|
|
350
|
+
push(k);
|
|
351
|
+
push(item);
|
|
352
|
+
}
|
|
353
|
+
else if (v instanceof Set) for (const item of v) push(item);
|
|
354
|
+
else for (const item of Object.values(v)) push(item);
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
335
357
|
}
|
|
336
|
-
async function transform(value, brandKey, streams, seen
|
|
358
|
+
async function transform(value, brandKey, streams, seen) {
|
|
337
359
|
if (value === null || typeof value !== "object") return value;
|
|
338
|
-
if (depth > MAX_DEPTH) throw new HostTypeError(`[iso4] value nests deeper than ${MAX_DEPTH} levels; cannot scan it for host types`);
|
|
339
360
|
const existing = seen.get(value);
|
|
340
361
|
if (existing !== void 0) return existing;
|
|
341
362
|
const descriptor = await toDescriptor(value, brandKey, streams);
|
|
@@ -347,24 +368,24 @@ async function transform(value, brandKey, streams, seen, depth) {
|
|
|
347
368
|
if (Array.isArray(value)) {
|
|
348
369
|
const out = [];
|
|
349
370
|
seen.set(value, out);
|
|
350
|
-
for (const item of value) out.push(await transform(item, brandKey, streams, seen
|
|
371
|
+
for (const item of value) out.push(await transform(item, brandKey, streams, seen));
|
|
351
372
|
return out;
|
|
352
373
|
}
|
|
353
374
|
if (value instanceof Map) {
|
|
354
375
|
const out = /* @__PURE__ */ new Map();
|
|
355
376
|
seen.set(value, out);
|
|
356
|
-
for (const [k, v] of value) out.set(await transform(k, brandKey, streams, seen
|
|
377
|
+
for (const [k, v] of value) out.set(await transform(k, brandKey, streams, seen), await transform(v, brandKey, streams, seen));
|
|
357
378
|
return out;
|
|
358
379
|
}
|
|
359
380
|
if (value instanceof Set) {
|
|
360
381
|
const out = /* @__PURE__ */ new Set();
|
|
361
382
|
seen.set(value, out);
|
|
362
|
-
for (const v of value) out.add(await transform(v, brandKey, streams, seen
|
|
383
|
+
for (const v of value) out.add(await transform(v, brandKey, streams, seen));
|
|
363
384
|
return out;
|
|
364
385
|
}
|
|
365
386
|
const out = Object.create(null);
|
|
366
387
|
seen.set(value, out);
|
|
367
|
-
for (const [k, v] of Object.entries(value)) out[k] = await transform(v, brandKey, streams, seen
|
|
388
|
+
for (const [k, v] of Object.entries(value)) out[k] = await transform(v, brandKey, streams, seen);
|
|
368
389
|
return out;
|
|
369
390
|
}
|
|
370
391
|
function readStr(des) {
|
|
@@ -1330,8 +1351,10 @@ function encodeBridgeResponsePayload(runId, callId, ok, encodedValue, error) {
|
|
|
1330
1351
|
/**
|
|
1331
1352
|
* Decode a `RunComplete` frame payload.
|
|
1332
1353
|
* @param buf the frame payload
|
|
1354
|
+
* @param droppedCallIds bridge calls the client skipped because the run was
|
|
1355
|
+
* already aborted; their records are reported as `dropped`
|
|
1333
1356
|
*/
|
|
1334
|
-
function decodeRunCompletePayload(buf) {
|
|
1357
|
+
function decodeRunCompletePayload(buf, droppedCallIds) {
|
|
1335
1358
|
const reader = new PayloadReader(buf);
|
|
1336
1359
|
const runId = reader.readU32();
|
|
1337
1360
|
const statusByte = reader.readU8();
|
|
@@ -1346,7 +1369,7 @@ function decodeRunCompletePayload(buf) {
|
|
|
1346
1369
|
const cpuTimeMs = reader.readF64();
|
|
1347
1370
|
const stdout = reader.readStringList();
|
|
1348
1371
|
const stderr = reader.readStringList();
|
|
1349
|
-
const bridgeCalls = readBridgeCallRecords(reader);
|
|
1372
|
+
const bridgeCalls = readBridgeCallRecords(reader, droppedCallIds);
|
|
1350
1373
|
const error = reader.readU8() === 1 ? {
|
|
1351
1374
|
name: reader.readString(),
|
|
1352
1375
|
message: reader.readString()
|
|
@@ -1544,7 +1567,7 @@ function peekRunCompletionSlotAllowance(buf) {
|
|
|
1544
1567
|
if (buf.byteLength < 8) return 0;
|
|
1545
1568
|
return (buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7]) >>> 0;
|
|
1546
1569
|
}
|
|
1547
|
-
function decodeRunCompletionPayload(buf, resultKind) {
|
|
1570
|
+
function decodeRunCompletionPayload(buf, resultKind, droppedCallIds) {
|
|
1548
1571
|
const reader = new PayloadReader(buf);
|
|
1549
1572
|
const runId = reader.readU32();
|
|
1550
1573
|
const slotAllowance = reader.readU32();
|
|
@@ -1557,7 +1580,7 @@ function decodeRunCompletionPayload(buf, resultKind) {
|
|
|
1557
1580
|
const durationMs = reader.readF64();
|
|
1558
1581
|
const wallTimeMs = reader.readF64();
|
|
1559
1582
|
const cpuTimeMs = reader.readF64();
|
|
1560
|
-
const bridgeCalls = readBridgeCallRecords(reader);
|
|
1583
|
+
const bridgeCalls = readBridgeCallRecords(reader, droppedCallIds);
|
|
1561
1584
|
const heapUsedBytes = reader.readOptionalU64();
|
|
1562
1585
|
const backgroundFlags = reader.readU8();
|
|
1563
1586
|
reader.readU8();
|
|
@@ -1611,7 +1634,7 @@ function decodeRunCompletionPayload(buf, resultKind) {
|
|
|
1611
1634
|
const durationMs = reader.readF64();
|
|
1612
1635
|
const wallTimeMs = reader.readF64();
|
|
1613
1636
|
const cpuTimeMs = reader.readF64();
|
|
1614
|
-
const bridgeCalls = readBridgeCallRecords(reader);
|
|
1637
|
+
const bridgeCalls = readBridgeCallRecords(reader, droppedCallIds);
|
|
1615
1638
|
const heapUsedBytes = reader.readOptionalU64();
|
|
1616
1639
|
reader.assertDone();
|
|
1617
1640
|
return {
|
|
@@ -1668,8 +1691,9 @@ function readResetInfo(reader) {
|
|
|
1668
1691
|
* already resolved — the runtime owns the import handle table and the shim
|
|
1669
1692
|
* naming convention, so no client-side mapping remains.
|
|
1670
1693
|
* @param reader
|
|
1694
|
+
* @param droppedCallIds
|
|
1671
1695
|
*/
|
|
1672
|
-
function readBridgeCallRecords(reader) {
|
|
1696
|
+
function readBridgeCallRecords(reader, droppedCallIds) {
|
|
1673
1697
|
const count = reader.readU32();
|
|
1674
1698
|
const entries = [];
|
|
1675
1699
|
for (let i = 0; i < count; i++) {
|
|
@@ -1678,16 +1702,38 @@ function readBridgeCallRecords(reader) {
|
|
|
1678
1702
|
const durationMs = reader.readF64();
|
|
1679
1703
|
const argBytes = reader.readU32();
|
|
1680
1704
|
const responseBytes = reader.readU32();
|
|
1681
|
-
const
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1705
|
+
const callId = reader.readU32();
|
|
1706
|
+
const outcome = reader.readU8();
|
|
1707
|
+
const base = {
|
|
1684
1708
|
name,
|
|
1685
1709
|
startMs,
|
|
1686
1710
|
durationMs,
|
|
1687
1711
|
argBytes,
|
|
1688
|
-
responseBytes
|
|
1689
|
-
|
|
1690
|
-
|
|
1712
|
+
responseBytes
|
|
1713
|
+
};
|
|
1714
|
+
let reason;
|
|
1715
|
+
switch (outcome) {
|
|
1716
|
+
case 0:
|
|
1717
|
+
entries.push({
|
|
1718
|
+
...base,
|
|
1719
|
+
ok: true
|
|
1720
|
+
});
|
|
1721
|
+
continue;
|
|
1722
|
+
case 1:
|
|
1723
|
+
reason = "blocked";
|
|
1724
|
+
break;
|
|
1725
|
+
case 2:
|
|
1726
|
+
reason = "error";
|
|
1727
|
+
break;
|
|
1728
|
+
case 3:
|
|
1729
|
+
reason = droppedCallIds?.has(callId) ? "dropped" : "unanswered";
|
|
1730
|
+
break;
|
|
1731
|
+
default: throw new PayloadDecodeError(`unknown bridge call outcome byte: ${outcome}`);
|
|
1732
|
+
}
|
|
1733
|
+
entries.push({
|
|
1734
|
+
...base,
|
|
1735
|
+
ok: false,
|
|
1736
|
+
reason
|
|
1691
1737
|
});
|
|
1692
1738
|
}
|
|
1693
1739
|
return entries;
|
|
@@ -1832,8 +1878,6 @@ function parseRustToTsMessageType(byte) {
|
|
|
1832
1878
|
function formatByte(byte) {
|
|
1833
1879
|
return `0x${byte.toString(16).padStart(2, "0")}`;
|
|
1834
1880
|
}
|
|
1835
|
-
//#endregion
|
|
1836
|
-
//#region src/imports.ts
|
|
1837
1881
|
/**
|
|
1838
1882
|
* The dispatch-map key for one host-module function leaf. The NUL separator
|
|
1839
1883
|
* cannot collide with anything a specifier or dot-joined path can contain in
|
|
@@ -1900,6 +1944,7 @@ function processImports(imports) {
|
|
|
1900
1944
|
* @param seen
|
|
1901
1945
|
*/
|
|
1902
1946
|
function lowerNode(specifier, value, path, handlers, seen = /* @__PURE__ */ new Set()) {
|
|
1947
|
+
if (path.length > 64) throw new Error(`[@iso4/sandbox] imports['${specifier}'].${path.join(".")}: host-module shapes may nest at most 64 levels deep`);
|
|
1903
1948
|
if (typeof value === "function") {
|
|
1904
1949
|
handlers.set(importHandlerKey(specifier, path.join(".")), value);
|
|
1905
1950
|
return { kind: "function" };
|
|
@@ -2656,7 +2701,8 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
2656
2701
|
entry.resolve({
|
|
2657
2702
|
result: payload,
|
|
2658
2703
|
graceWork: false,
|
|
2659
|
-
outStreams: entry.outStreams
|
|
2704
|
+
outStreams: entry.outStreams,
|
|
2705
|
+
...entry.droppedCallIds && { droppedCallIds: entry.droppedCallIds }
|
|
2660
2706
|
});
|
|
2661
2707
|
return;
|
|
2662
2708
|
}
|
|
@@ -2688,7 +2734,8 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
2688
2734
|
result: payload,
|
|
2689
2735
|
epilogue,
|
|
2690
2736
|
graceWork: (flags & 1) !== 0,
|
|
2691
|
-
outStreams: entry.outStreams
|
|
2737
|
+
outStreams: entry.outStreams,
|
|
2738
|
+
...entry.droppedCallIds && { droppedCallIds: entry.droppedCallIds }
|
|
2692
2739
|
});
|
|
2693
2740
|
}
|
|
2694
2741
|
/**
|
|
@@ -2698,7 +2745,8 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
2698
2745
|
* @param payload
|
|
2699
2746
|
*/
|
|
2700
2747
|
routeRunComplete(payload) {
|
|
2701
|
-
const
|
|
2748
|
+
const runId = peekRunCompletionRunId(payload);
|
|
2749
|
+
const report = decodeRunCompletePayload(payload, runId === void 0 ? void 0 : this.runs.get(runId)?.droppedCallIds);
|
|
2702
2750
|
const entry = this.runs.get(report.runId);
|
|
2703
2751
|
if (entry === void 0 || entry.epilogue === void 0) throw new ProtocolDesyncError(`RunComplete frame carries runId ${report.runId} but no run with that id is in its waitUntil grace phase on this connection`);
|
|
2704
2752
|
this.runs.delete(report.runId);
|
|
@@ -2805,6 +2853,11 @@ var RuntimeIpcClient = class RuntimeIpcClient {
|
|
|
2805
2853
|
*/
|
|
2806
2854
|
async dispatchBridgeCallFrame(payload, entry, runId) {
|
|
2807
2855
|
const { dispatcher, streams } = entry;
|
|
2856
|
+
if (entry.signal?.aborted || entry.hardAbortSignal?.aborted) {
|
|
2857
|
+
const callId = peekBridgeCallId(payload);
|
|
2858
|
+
if (callId !== void 0) (entry.droppedCallIds ??= /* @__PURE__ */ new Set()).add(callId);
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2808
2861
|
let call;
|
|
2809
2862
|
try {
|
|
2810
2863
|
call = decodeBridgeCallPayload(payload);
|
|
@@ -3850,7 +3903,7 @@ var SandboxImpl = class {
|
|
|
3850
3903
|
call,
|
|
3851
3904
|
streams
|
|
3852
3905
|
});
|
|
3853
|
-
const decoded = withBodyStreamBinder((id) => raw.outStreams.attach(id), () => call === void 0 ? decodeRunCompletionPayload(raw.result).result : decodeRunCompletionPayload(raw.result, "call").result);
|
|
3906
|
+
const decoded = withBodyStreamBinder((id) => raw.outStreams.attach(id), () => call === void 0 ? decodeRunCompletionPayload(raw.result, void 0, raw.droppedCallIds).result : decodeRunCompletionPayload(raw.result, "call", raw.droppedCallIds).result);
|
|
3854
3907
|
if (raw.epilogue !== void 0 && raw.graceWork && decoded.ok) decoded.waitUntil = raw.epilogue.then(waitUntilResultFrom);
|
|
3855
3908
|
if (decoded.status === "failed" && decoded.error.code === "ERR_ABORTED") {
|
|
3856
3909
|
if (options.signal?.aborted) return abortedResult(options.signal.reason, decoded);
|
|
@@ -4122,7 +4175,7 @@ var PrefixImpl = class {
|
|
|
4122
4175
|
call: payload.call,
|
|
4123
4176
|
streams
|
|
4124
4177
|
});
|
|
4125
|
-
const decoded = withBodyStreamBinder((id) => raw.outStreams.attach(id), () => payload.call === void 0 ? decodeRunCompletionPayload(raw.result).result : decodeRunCompletionPayload(raw.result, "call").result);
|
|
4178
|
+
const decoded = withBodyStreamBinder((id) => raw.outStreams.attach(id), () => payload.call === void 0 ? decodeRunCompletionPayload(raw.result, void 0, raw.droppedCallIds).result : decodeRunCompletionPayload(raw.result, "call", raw.droppedCallIds).result);
|
|
4126
4179
|
if (raw.epilogue !== void 0 && raw.graceWork && decoded.ok) decoded.waitUntil = raw.epilogue.then(waitUntilResultFrom);
|
|
4127
4180
|
if (decoded.status === "failed" && decoded.error.code === "ERR_ABORTED") {
|
|
4128
4181
|
if (options.signal?.aborted) return abortedResult(options.signal.reason, decoded);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iso4/sandbox",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
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": [
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"vitest": "^4.1.5"
|
|
50
50
|
},
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"@iso4/v8-darwin-arm64": "^0.6.
|
|
53
|
-
"@iso4/v8-darwin-x64": "^0.6.
|
|
54
|
-
"@iso4/v8-linux-arm64-gnu": "^0.6.
|
|
55
|
-
"@iso4/v8-linux-x64-gnu": "^0.6.
|
|
52
|
+
"@iso4/v8-darwin-arm64": "^0.6.3",
|
|
53
|
+
"@iso4/v8-darwin-x64": "^0.6.3",
|
|
54
|
+
"@iso4/v8-linux-arm64-gnu": "^0.6.3",
|
|
55
|
+
"@iso4/v8-linux-x64-gnu": "^0.6.3"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=24.0.0"
|