@questpie/sandbox 3.26.2 → 3.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@questpie/sandbox",
3
- "version": "3.26.2",
3
+ "version": "3.27.0",
4
4
  "private": false,
5
5
  "description": "Hardened isolated-script execution for QUESTPIE",
6
6
  "repository": {
@@ -73,8 +73,8 @@
73
73
  "test": "bun test"
74
74
  },
75
75
  "dependencies": {
76
- "@questpie/mcp": "^3.26.2",
77
- "questpie": "^3.26.2"
76
+ "@questpie/mcp": "^3.27.0",
77
+ "questpie": "^3.27.0"
78
78
  },
79
79
  "devDependencies": {
80
80
  "bun-types": "latest",
@@ -82,6 +82,6 @@
82
82
  "zod": "^4.2.1"
83
83
  },
84
84
  "peerDependencies": {
85
- "questpie": "^3.26.2"
85
+ "questpie": "^3.27.0"
86
86
  }
87
87
  }
@@ -23,6 +23,23 @@
23
23
  /** Transport: send one binding RPC, resolve with its brokered value or reject. */
24
24
  export type HostCall = (method: string, args: unknown) => Promise<unknown>;
25
25
 
26
+ /** Relay brokered fetch and retain a rejected host call as the fetch error cause. */
27
+ export async function callBrokeredFetch<T>(
28
+ hostCall: HostCall,
29
+ request: unknown,
30
+ ): Promise<T> {
31
+ try {
32
+ return (await hostCall("http.fetch", request)) as T;
33
+ } catch (error) {
34
+ throw new TypeError(
35
+ error instanceof Error ? error.message : String(error),
36
+ {
37
+ cause: error,
38
+ },
39
+ );
40
+ }
41
+ }
42
+
26
43
  /**
27
44
  * Per-collection access surface. Reads (`find`/`findOne`) are always available;
28
45
  * writes (`create`/`update`/`delete`) are dispatched ONLY where the host wires a
@@ -40,7 +40,7 @@
40
40
 
41
41
  import nodeProcess from "node:process";
42
42
 
43
- import { buildGuestBindings } from "./guest-bindings.ts";
43
+ import { buildGuestBindings, callBrokeredFetch } from "./guest-bindings.ts";
44
44
 
45
45
  /** Marker so the supervisor can pick the result line out of guest stdout noise. */
46
46
  const RESULT_MARKER = "__QP_SANDBOX_RESULT__";
@@ -336,6 +336,7 @@ function installFetchShim(
336
336
  } catch (e) {
337
337
  throw new TypeError(
338
338
  `Failed to construct fetch request: ${e instanceof Error ? e.message : String(e)}`,
339
+ { cause: e },
339
340
  );
340
341
  }
341
342
 
@@ -367,12 +368,7 @@ function installFetchShim(
367
368
  // Relay over the existing stdio RPC channel. A structured broker error
368
369
  // (network failure / blocked target / oversize) arrives as a rejected
369
370
  // hostCall — surface it as a fetch-like TypeError, NOT a fake 5xx Response.
370
- let value: HttpFetchResponse;
371
- try {
372
- value = (await hostCall("http.fetch", request)) as HttpFetchResponse;
373
- } catch (e) {
374
- throw new TypeError(e instanceof Error ? e.message : String(e));
375
- }
371
+ const value = await callBrokeredFetch<HttpFetchResponse>(hostCall, request);
376
372
 
377
373
  const status = typeof value?.status === "number" ? value.status : 0;
378
374
  const body = value?.bodyBase64
@@ -1,5 +1,5 @@
1
1
  const GUEST_BINDINGS_IMPORT =
2
- 'import { buildGuestBindings } from "./guest-bindings.ts";';
2
+ 'import { buildGuestBindings, callBrokeredFetch } from "./guest-bindings.ts";';
3
3
  const HTTP_BODY_CAP_MARKER = "__QP_HTTP_FETCH_BODY_CAP_BYTES__";
4
4
 
5
5
  /** Inline the trusted dependency so the guest entry needs no host path/socket. */