@nodetool-ai/sandbox-runtime 0.0.0-stage → 0.8.9-beta.1

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.
Files changed (218) hide show
  1. package/README.md +24 -2
  2. package/dist/.nodetool-build-stamp +1 -0
  3. package/dist/host-access-gate.d.ts +24 -0
  4. package/dist/host-access-gate.d.ts.map +1 -0
  5. package/dist/host-access-gate.js +31 -0
  6. package/dist/host-access-gate.js.map +1 -0
  7. package/dist/index.d.ts +32 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +318 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/js-sandbox-worker/engine.d.ts +4 -0
  12. package/dist/js-sandbox-worker/engine.d.ts.map +1 -0
  13. package/dist/js-sandbox-worker/engine.js +82 -0
  14. package/dist/js-sandbox-worker/engine.js.map +1 -0
  15. package/dist/js-sandbox-worker/host.d.ts +136 -0
  16. package/dist/js-sandbox-worker/host.d.ts.map +1 -0
  17. package/dist/js-sandbox-worker/host.js +482 -0
  18. package/dist/js-sandbox-worker/host.js.map +1 -0
  19. package/dist/js-sandbox-worker/interpreter.d.ts +276 -0
  20. package/dist/js-sandbox-worker/interpreter.d.ts.map +1 -0
  21. package/dist/js-sandbox-worker/interpreter.js +1318 -0
  22. package/dist/js-sandbox-worker/interpreter.js.map +1 -0
  23. package/dist/js-sandbox-worker/protocol.d.ts +168 -0
  24. package/dist/js-sandbox-worker/protocol.d.ts.map +1 -0
  25. package/dist/js-sandbox-worker/protocol.js +217 -0
  26. package/dist/js-sandbox-worker/protocol.js.map +1 -0
  27. package/dist/js-sandbox-worker/worker-entry.d.ts +26 -0
  28. package/dist/js-sandbox-worker/worker-entry.d.ts.map +1 -0
  29. package/dist/js-sandbox-worker/worker-entry.js +308 -0
  30. package/dist/js-sandbox-worker/worker-entry.js.map +1 -0
  31. package/dist/limits.d.ts +77 -0
  32. package/dist/limits.d.ts.map +1 -0
  33. package/dist/limits.js +56 -0
  34. package/dist/limits.js.map +1 -0
  35. package/dist/sandbox-bootstrap-modules.d.ts +54 -0
  36. package/dist/sandbox-bootstrap-modules.d.ts.map +1 -0
  37. package/dist/sandbox-bootstrap-modules.js +104 -0
  38. package/dist/sandbox-bootstrap-modules.js.map +1 -0
  39. package/dist/sandbox-bytes.d.ts +43 -0
  40. package/dist/sandbox-bytes.d.ts.map +1 -0
  41. package/dist/sandbox-bytes.js +61 -0
  42. package/dist/sandbox-bytes.js.map +1 -0
  43. package/dist/sandbox-canvas-api.d.ts +30 -0
  44. package/dist/sandbox-canvas-api.d.ts.map +1 -0
  45. package/dist/sandbox-canvas-api.js +81 -0
  46. package/dist/sandbox-canvas-api.js.map +1 -0
  47. package/dist/sandbox-constants.d.ts +5 -0
  48. package/dist/sandbox-constants.d.ts.map +1 -0
  49. package/dist/sandbox-constants.js +13 -0
  50. package/dist/sandbox-constants.js.map +1 -0
  51. package/dist/sandbox-json-transport.d.ts +107 -0
  52. package/dist/sandbox-json-transport.d.ts.map +1 -0
  53. package/dist/sandbox-json-transport.js +324 -0
  54. package/dist/sandbox-json-transport.js.map +1 -0
  55. package/dist/timeline-capture.d.ts +21 -0
  56. package/dist/timeline-capture.d.ts.map +1 -0
  57. package/dist/timeline-capture.js +564 -0
  58. package/dist/timeline-capture.js.map +1 -0
  59. package/dist/utils/type-guards.d.ts +26 -0
  60. package/dist/utils/type-guards.d.ts.map +1 -0
  61. package/dist/utils/type-guards.js +44 -0
  62. package/dist/utils/type-guards.js.map +1 -0
  63. package/package.json +138 -4
  64. package/vendor/README.md +17 -0
  65. package/vendor/quickjs/LICENSE +21 -0
  66. package/vendor/quickjs/PROVENANCE.json +8 -0
  67. package/vendor/quickjs/adapter/fetch.d.ts +56 -0
  68. package/vendor/quickjs/adapter/fetch.js +140 -0
  69. package/vendor/quickjs/createTimeInterval.d.ts +9 -0
  70. package/vendor/quickjs/createTimeInterval.js +22 -0
  71. package/vendor/quickjs/createVirtualFileSystem.d.ts +13 -0
  72. package/vendor/quickjs/createVirtualFileSystem.js +191 -0
  73. package/vendor/quickjs/index.d.ts +77 -0
  74. package/vendor/quickjs/index.js +77 -0
  75. package/vendor/quickjs/loadAsyncQuickJs.d.ts +12 -0
  76. package/vendor/quickjs/loadAsyncQuickJs.js +66 -0
  77. package/vendor/quickjs/loadQuickJs.d.ts +12 -0
  78. package/vendor/quickjs/loadQuickJs.js +73 -0
  79. package/vendor/quickjs/modules/assert.d.ts +2 -0
  80. package/vendor/quickjs/modules/assert.js +47 -0
  81. package/vendor/quickjs/modules/buffer.d.ts +2 -0
  82. package/vendor/quickjs/modules/buffer.js +106 -0
  83. package/vendor/quickjs/modules/build/test-lib.js +2 -0
  84. package/vendor/quickjs/modules/events.d.ts +2 -0
  85. package/vendor/quickjs/modules/events.js +4 -0
  86. package/vendor/quickjs/modules/fs.d.ts +2 -0
  87. package/vendor/quickjs/modules/fs.js +76 -0
  88. package/vendor/quickjs/modules/fs_promises.d.ts +2 -0
  89. package/vendor/quickjs/modules/fs_promises.js +328 -0
  90. package/vendor/quickjs/modules/module.d.ts +2 -0
  91. package/vendor/quickjs/modules/module.js +33 -0
  92. package/vendor/quickjs/modules/nodeCompatibility/headers.d.ts +2 -0
  93. package/vendor/quickjs/modules/nodeCompatibility/headers.js +58 -0
  94. package/vendor/quickjs/modules/nodeCompatibility/request.d.ts +2 -0
  95. package/vendor/quickjs/modules/nodeCompatibility/request.js +5 -0
  96. package/vendor/quickjs/modules/nodeCompatibility/response.d.ts +2 -0
  97. package/vendor/quickjs/modules/nodeCompatibility/response.js +5 -0
  98. package/vendor/quickjs/modules/path.d.ts +2 -0
  99. package/vendor/quickjs/modules/path.js +504 -0
  100. package/vendor/quickjs/modules/process.d.ts +2 -0
  101. package/vendor/quickjs/modules/process.js +309 -0
  102. package/vendor/quickjs/modules/punycode.d.ts +2 -0
  103. package/vendor/quickjs/modules/punycode.js +443 -0
  104. package/vendor/quickjs/modules/querystring.d.ts +2 -0
  105. package/vendor/quickjs/modules/querystring.js +15 -0
  106. package/vendor/quickjs/modules/string_decoder.d.ts +2 -0
  107. package/vendor/quickjs/modules/string_decoder.js +223 -0
  108. package/vendor/quickjs/modules/timers.d.ts +2 -0
  109. package/vendor/quickjs/modules/timers.js +10 -0
  110. package/vendor/quickjs/modules/timers_promises.d.ts +2 -0
  111. package/vendor/quickjs/modules/timers_promises.js +40 -0
  112. package/vendor/quickjs/modules/url.d.ts +2 -0
  113. package/vendor/quickjs/modules/url.js +104 -0
  114. package/vendor/quickjs/modules/util.d.ts +2 -0
  115. package/vendor/quickjs/modules/util.js +233 -0
  116. package/vendor/quickjs/package.json +3 -0
  117. package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.d.ts +4 -0
  118. package/vendor/quickjs/sandbox/asyncVersion/createAsyncEvalCodeFunction.js +76 -0
  119. package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.d.ts +3 -0
  120. package/vendor/quickjs/sandbox/asyncVersion/createAsyncValidateCodeFunction.js +22 -0
  121. package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.d.ts +12 -0
  122. package/vendor/quickjs/sandbox/asyncVersion/executeAsyncSandboxFunction.js +9 -0
  123. package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.d.ts +4 -0
  124. package/vendor/quickjs/sandbox/asyncVersion/getAsyncModuleLoader.js +30 -0
  125. package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.d.ts +2 -0
  126. package/vendor/quickjs/sandbox/asyncVersion/modulePathNormalizerAsync.js +12 -0
  127. package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.d.ts +3 -0
  128. package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncNodeCompatibility.js +11 -0
  129. package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.d.ts +4 -0
  130. package/vendor/quickjs/sandbox/asyncVersion/prepareAsyncSandbox.js +10 -0
  131. package/vendor/quickjs/sandbox/expose/expose.d.ts +3 -0
  132. package/vendor/quickjs/sandbox/expose/expose.js +155 -0
  133. package/vendor/quickjs/sandbox/expose/isES2015Class.d.ts +1 -0
  134. package/vendor/quickjs/sandbox/expose/isES2015Class.js +4 -0
  135. package/vendor/quickjs/sandbox/expose/isObject.d.ts +1 -0
  136. package/vendor/quickjs/sandbox/expose/isObject.js +4 -0
  137. package/vendor/quickjs/sandbox/expose/pendingHostPromises.d.ts +6 -0
  138. package/vendor/quickjs/sandbox/expose/pendingHostPromises.js +40 -0
  139. package/vendor/quickjs/sandbox/getMaxIntervalAmount.d.ts +8 -0
  140. package/vendor/quickjs/sandbox/getMaxIntervalAmount.js +12 -0
  141. package/vendor/quickjs/sandbox/getMaxTimeoutAmount.d.ts +8 -0
  142. package/vendor/quickjs/sandbox/getMaxTimeoutAmount.js +12 -0
  143. package/vendor/quickjs/sandbox/handleEvalError.d.ts +2 -0
  144. package/vendor/quickjs/sandbox/handleEvalError.js +21 -0
  145. package/vendor/quickjs/sandbox/handleToNative/handleToNative.d.ts +9 -0
  146. package/vendor/quickjs/sandbox/handleToNative/handleToNative.js +153 -0
  147. package/vendor/quickjs/sandbox/handleToNative/serializer/index.d.ts +10 -0
  148. package/vendor/quickjs/sandbox/handleToNative/serializer/index.js +36 -0
  149. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.d.ts +2 -0
  150. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeArrayBuffer.js +4 -0
  151. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.d.ts +2 -0
  152. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeBuffer.js +16 -0
  153. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.d.ts +2 -0
  154. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeDate.js +16 -0
  155. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.d.ts +2 -0
  156. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeError.js +18 -0
  157. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.d.ts +2 -0
  158. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeHeaders.js +17 -0
  159. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.d.ts +2 -0
  160. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeMap.js +18 -0
  161. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.d.ts +2 -0
  162. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeSet.js +16 -0
  163. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.d.ts +2 -0
  164. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeURLSearchParams.js +17 -0
  165. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.d.ts +2 -0
  166. package/vendor/quickjs/sandbox/handleToNative/serializer/serializeUrl.js +17 -0
  167. package/vendor/quickjs/sandbox/helper.d.ts +2 -0
  168. package/vendor/quickjs/sandbox/helper.js +14 -0
  169. package/vendor/quickjs/sandbox/provide/provideConsole.d.ts +6 -0
  170. package/vendor/quickjs/sandbox/provide/provideConsole.js +53 -0
  171. package/vendor/quickjs/sandbox/provide/provideEnv.d.ts +3 -0
  172. package/vendor/quickjs/sandbox/provide/provideEnv.js +10 -0
  173. package/vendor/quickjs/sandbox/provide/provideFs.d.ts +4 -0
  174. package/vendor/quickjs/sandbox/provide/provideFs.js +159 -0
  175. package/vendor/quickjs/sandbox/provide/provideHttp.d.ts +9 -0
  176. package/vendor/quickjs/sandbox/provide/provideHttp.js +42 -0
  177. package/vendor/quickjs/sandbox/provide/provideTimingFunctions.d.ts +7 -0
  178. package/vendor/quickjs/sandbox/provide/provideTimingFunctions.js +119 -0
  179. package/vendor/quickjs/sandbox/setupFileSystem.d.ts +3 -0
  180. package/vendor/quickjs/sandbox/setupFileSystem.js +13 -0
  181. package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.d.ts +4 -0
  182. package/vendor/quickjs/sandbox/syncVersion/createEvalCodeFunction.js +76 -0
  183. package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.d.ts +3 -0
  184. package/vendor/quickjs/sandbox/syncVersion/createValidateCodeFunction.js +22 -0
  185. package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.d.ts +12 -0
  186. package/vendor/quickjs/sandbox/syncVersion/executeSandboxFunction.js +9 -0
  187. package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.d.ts +4 -0
  188. package/vendor/quickjs/sandbox/syncVersion/getModuleLoader.js +30 -0
  189. package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.d.ts +2 -0
  190. package/vendor/quickjs/sandbox/syncVersion/modulePathNormalizer.js +12 -0
  191. package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.d.ts +3 -0
  192. package/vendor/quickjs/sandbox/syncVersion/prepareNodeCompatibility.js +11 -0
  193. package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.d.ts +4 -0
  194. package/vendor/quickjs/sandbox/syncVersion/prepareSandbox.js +10 -0
  195. package/vendor/quickjs/types/CodeFunctionInput.d.ts +12 -0
  196. package/vendor/quickjs/types/CodeFunctionInput.js +1 -0
  197. package/vendor/quickjs/types/ErrorResponse.d.ts +9 -0
  198. package/vendor/quickjs/types/ErrorResponse.js +1 -0
  199. package/vendor/quickjs/types/LoadQuickJsOptions.d.ts +3 -0
  200. package/vendor/quickjs/types/LoadQuickJsOptions.js +1 -0
  201. package/vendor/quickjs/types/OkResponse.d.ts +4 -0
  202. package/vendor/quickjs/types/OkResponse.js +1 -0
  203. package/vendor/quickjs/types/OkResponseCheck.d.ts +3 -0
  204. package/vendor/quickjs/types/OkResponseCheck.js +1 -0
  205. package/vendor/quickjs/types/Prettify.d.ts +3 -0
  206. package/vendor/quickjs/types/Prettify.js +1 -0
  207. package/vendor/quickjs/types/RuntimeOptions.d.ts +87 -0
  208. package/vendor/quickjs/types/RuntimeOptions.js +1 -0
  209. package/vendor/quickjs/types/SandboxEvalCode.d.ts +5 -0
  210. package/vendor/quickjs/types/SandboxEvalCode.js +1 -0
  211. package/vendor/quickjs/types/SandboxFunction.d.ts +16 -0
  212. package/vendor/quickjs/types/SandboxFunction.js +1 -0
  213. package/vendor/quickjs/types/SandboxOptions.d.ts +152 -0
  214. package/vendor/quickjs/types/SandboxOptions.js +1 -0
  215. package/vendor/quickjs/types/SandboxValidateCode.d.ts +9 -0
  216. package/vendor/quickjs/types/SandboxValidateCode.js +1 -0
  217. package/vendor/quickjs/types/Serializer.d.ts +2 -0
  218. package/vendor/quickjs/types/Serializer.js +1 -0
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # Sandbox runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The shared QuickJS interpreter and worker isolation used by the full agent host
4
+ and the optional minimal Code feature. The lean host accepts workspace, secret,
5
+ asset and reporting callbacks. It never executes user JavaScript in Node.
6
+
7
+ Host and WASM imports require separately installed capability adapters. The lean
8
+ host can execute explicitly resolved guest JavaScript modules without a compiler.
9
+
10
+ The runtime ships the JavaScript-only ESM build of
11
+ `@sebastianwessel/quickjs@3.0.1` in `vendor/quickjs`, including its MIT license.
12
+ Upstream exposes only an aggregate entry whose optional TypeScript helper leaks
13
+ compiler types into declarations. This copy removes that helper, its exports
14
+ and compiler options, and uses identity transpilation in both loaders. The
15
+ engine, bridges, lifecycle and cancellation retain the upstream implementation.
16
+ TypeScript compilation belongs to the separately installed sandbox compiler.
17
+
18
+ Regenerate with `node scripts/vendor-quickjs-javascript.mjs` from the pinned dev
19
+ dependency, or pass the path to an unpacked upstream npm artifact. The generator
20
+ fails when its version, ESM/license hash or expected patch text changes.
21
+ `vendor/quickjs/PROVENANCE.json` records the pinned npm integrity and source hash.
22
+ The sandbox profile in
23
+ `scripts/minimal-packed-consumer.mjs` exercises Code, audits JavaScript and
24
+ declarations, checks compiler absence, then injects forbidden manifest,
25
+ JavaScript and declaration edges and verifies rejection before restoring them.
@@ -0,0 +1 @@
1
+ 2026-10-31T09:10:58.153Z
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Availability gate for the escape hatches that reach the server machine past
3
+ * a run's own workspace.
4
+ *
5
+ * - The sandbox's `filesystemAccess: "host"` and `allowPrivateNetwork` limits,
6
+ * which the Code node exposes as its "Allow Host Filesystem" and "Allow
7
+ * Local Network" properties. Whoever authors the graph sets them, so on a
8
+ * managed server any tenant could read the container's disk or reach its
9
+ * internal network.
10
+ * - `take_screenshot` without an operator `BROWSER_URL`, which launches a
11
+ * headless Chrome on the server and only checks the first URL, not where it
12
+ * redirects.
13
+ *
14
+ * Same switch that prunes the node catalog: `NODETOOL_NODE_PROFILE=cloud`, or
15
+ * `NODETOOL_ENV=production` with the profile unset. Under it the sandbox
16
+ * limits fall back to the workspace and the SSRF guard, and the screenshot
17
+ * refuses. A self-hosted install sets `NODETOOL_NODE_PROFILE=full` and keeps
18
+ * both, as does every local install.
19
+ */
20
+ /** Whether this deployment lets a run reach the server past its workspace. */
21
+ export declare function isHostAccessEnabled(): boolean;
22
+ /** What `take_screenshot` answers where it would launch a local browser. */
23
+ export declare const LOCAL_SCREENSHOT_DISABLED_ERROR: string;
24
+ //# sourceMappingURL=host-access-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-access-gate.d.ts","sourceRoot":"","sources":["../src/host-access-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH,8EAA8E;AAC9E,wBAAgB,mBAAmB,IAAI,OAAO,CAM7C;AAED,4EAA4E;AAC5E,eAAO,MAAM,+BAA+B,QAG4B,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Availability gate for the escape hatches that reach the server machine past
3
+ * a run's own workspace.
4
+ *
5
+ * - The sandbox's `filesystemAccess: "host"` and `allowPrivateNetwork` limits,
6
+ * which the Code node exposes as its "Allow Host Filesystem" and "Allow
7
+ * Local Network" properties. Whoever authors the graph sets them, so on a
8
+ * managed server any tenant could read the container's disk or reach its
9
+ * internal network.
10
+ * - `take_screenshot` without an operator `BROWSER_URL`, which launches a
11
+ * headless Chrome on the server and only checks the first URL, not where it
12
+ * redirects.
13
+ *
14
+ * Same switch that prunes the node catalog: `NODETOOL_NODE_PROFILE=cloud`, or
15
+ * `NODETOOL_ENV=production` with the profile unset. Under it the sandbox
16
+ * limits fall back to the workspace and the SSRF guard, and the screenshot
17
+ * refuses. A self-hosted install sets `NODETOOL_NODE_PROFILE=full` and keeps
18
+ * both, as does every local install.
19
+ */
20
+ import { CLOUD_PROFILE_ENV, NODE_ENV_VAR, isCloudProfileActive } from "@nodetool-ai/protocol";
21
+ /** Whether this deployment lets a run reach the server past its workspace. */
22
+ export function isHostAccessEnabled() {
23
+ if (typeof process === "undefined")
24
+ return true;
25
+ return !isCloudProfileActive(process.env[CLOUD_PROFILE_ENV], process.env[NODE_ENV_VAR]);
26
+ }
27
+ /** What `take_screenshot` answers where it would launch a local browser. */
28
+ export const LOCAL_SCREENSHOT_DISABLED_ERROR = "Screenshots are not available on this deployment. Taking one launches a " +
29
+ "browser on the server, so it is offered only where the machine belongs to " +
30
+ "its user: the desktop app, a local server, or a self-hosted install.";
31
+ //# sourceMappingURL=host-access-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-access-gate.js","sourceRoot":"","sources":["../src/host-access-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAE/B,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB;IACjC,IAAI,OAAO,OAAO,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,CAAC,oBAAoB,CAC1B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAC9B,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,+BAA+B,GAC1C,0EAA0E;IAC1E,4EAA4E;IAC5E,sEAAsE,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Workspace } from "@nodetool-ai/runtime-core";
2
+ import type { SandboxModuleResolution } from "@nodetool-ai/protocol";
3
+ import { type SandboxLimits } from "./limits.js";
4
+ export { resolveSandboxLimits, type SandboxLimits } from "./limits.js";
5
+ export interface SandboxOptions {
6
+ readonly code: string;
7
+ readonly globals?: Record<string, unknown>;
8
+ readonly signal?: AbortSignal;
9
+ readonly timeoutMs?: number;
10
+ readonly limits?: SandboxLimits;
11
+ readonly workspace?: Workspace;
12
+ readonly getSecret?: (name: string) => Promise<string | undefined>;
13
+ readonly readAsset?: (reference: unknown) => Promise<Uint8Array>;
14
+ readonly onLog?: (level: string, text: string) => void;
15
+ readonly onProgress?: (percent: number, text?: string) => void;
16
+ /** Already-resolved guest JavaScript only. Host/WASM capabilities require explicit adapters. */
17
+ readonly modules?: SandboxModuleResolution;
18
+ }
19
+ export interface SandboxResult {
20
+ readonly success: boolean;
21
+ readonly result?: unknown;
22
+ readonly error?: string;
23
+ readonly logs: readonly string[];
24
+ readonly outputs?: Record<string, unknown>;
25
+ readonly emitted?: readonly {
26
+ name: string;
27
+ value: unknown;
28
+ }[];
29
+ }
30
+ /** Execute on the canonical isolated QuickJS worker, with explicitly supplied bridges. */
31
+ export declare function runInSandbox(options: SandboxOptions): Promise<SandboxResult>;
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAQrE,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,KAAK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AAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAChE;AAiBD,0FAA0F;AAC1F,wBAAsB,YAAY,CAChC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CAqUxB"}
package/dist/index.js ADDED
@@ -0,0 +1,318 @@
1
+ import { safeFetch } from "@nodetool-ai/runtime-core/safe-url";
2
+ import { runInWorker } from "./js-sandbox-worker/host.js";
3
+ import { deriveBridgeShape } from "./js-sandbox-worker/protocol.js";
4
+ import { SANDBOX_INPUT_TAKE_BINDING, SANDBOX_STREAM_OPEN_BINDING, NO_INPUT_STREAM_MESSAGE } from "./js-sandbox-worker/interpreter.js";
5
+ import { resolveSandboxLimits, DEFAULT_TIMEOUT_MS, MAX_LOOP_ITERATIONS } from "./limits.js";
6
+ import { toGuestBytes, SANDBOX_BYTES_MARKER } from "./sandbox-bytes.js";
7
+ export { resolveSandboxLimits } from "./limits.js";
8
+ function nativeBytes(value) {
9
+ if (value instanceof Uint8Array) {
10
+ return value;
11
+ }
12
+ if (value &&
13
+ typeof value === "object" &&
14
+ SANDBOX_BYTES_MARKER in value &&
15
+ typeof value[SANDBOX_BYTES_MARKER] === "string") {
16
+ return new Uint8Array(Buffer.from(value[SANDBOX_BYTES_MARKER], "base64"));
17
+ }
18
+ throw new Error("Expected binary bytes");
19
+ }
20
+ /** Execute on the canonical isolated QuickJS worker, with explicitly supplied bridges. */
21
+ export async function runInSandbox(options) {
22
+ const limits = resolveSandboxLimits(options.limits);
23
+ const timeoutMs = Math.min(Math.max(Math.floor(options.timeoutMs ?? DEFAULT_TIMEOUT_MS), 1), 10 * 60 * 1000);
24
+ if (!Number.isFinite(timeoutMs)) {
25
+ throw new Error("Sandbox timeout must be finite");
26
+ }
27
+ if (options.modules?.modules.some((module) => module.kind !== "js")) {
28
+ throw new Error("Sandbox host and WASM modules require an explicitly installed capability adapter");
29
+ }
30
+ const logs = [];
31
+ const outputs = {};
32
+ const emitted = [];
33
+ let logBytes = 0;
34
+ let outputBytes = 0;
35
+ let fetchCalls = 0;
36
+ let progressCalls = 0;
37
+ let lastProgress = 0;
38
+ const assertOutput = (name, value) => {
39
+ if (typeof name !== "string" || !name) {
40
+ throw new Error("Output names must be nonempty strings");
41
+ }
42
+ const serialized = JSON.stringify(value);
43
+ outputBytes += Buffer.byteLength(serialized ?? "null");
44
+ if (outputBytes > limits.maxOutputSize) {
45
+ throw new Error("Sandbox output size limit exceeded");
46
+ }
47
+ return name;
48
+ };
49
+ const unavailable = async () => {
50
+ throw new Error("This capability is not installed in the sandbox host");
51
+ };
52
+ const requiredWorkspace = () => {
53
+ if (!options.workspace) {
54
+ throw new Error("Workspace is unavailable for this run");
55
+ }
56
+ return options.workspace;
57
+ };
58
+ const console = Object.fromEntries(["log", "info", "warn", "error"].map((level) => [
59
+ level,
60
+ (...args) => {
61
+ if (logs.length >= 5000 || logBytes >= 1_000_000) {
62
+ return;
63
+ }
64
+ const text = args
65
+ .map((value) => typeof value === "string" ? value : JSON.stringify(value))
66
+ .join(" ")
67
+ .slice(0, 4000);
68
+ logBytes += text.length;
69
+ logs.push(text);
70
+ try {
71
+ options.onLog?.(level, text);
72
+ }
73
+ catch {
74
+ /* Reporting cannot break execution. */
75
+ }
76
+ }
77
+ ]));
78
+ const bridges = {
79
+ console,
80
+ __maxIter: MAX_LOOP_ITERATIONS,
81
+ __secretScope: limits.secretScope,
82
+ [SANDBOX_INPUT_TAKE_BINDING]: async () => {
83
+ throw new Error(NO_INPUT_STREAM_MESSAGE);
84
+ },
85
+ [SANDBOX_STREAM_OPEN_BINDING]: () => false,
86
+ crypto: {
87
+ randomUUID: () => globalThis.crypto.randomUUID(),
88
+ getRandomValues: (length) => toGuestBytes(globalThis.crypto.getRandomValues(new Uint8Array(Math.min(Math.max(Math.floor(length), 0), 65536)))),
89
+ digest: async (algorithm, data) => toGuestBytes(new Uint8Array(await globalThis.crypto.subtle.digest(algorithm, new Uint8Array(nativeBytes(data))))),
90
+ hmac: unavailable
91
+ },
92
+ sleep: async (milliseconds) => {
93
+ const delay = Math.min(Math.max(Number(milliseconds), 0), timeoutMs);
94
+ await new Promise((resolve, reject) => {
95
+ const abort = () => {
96
+ clearTimeout(timer);
97
+ options.signal?.removeEventListener("abort", abort);
98
+ reject(new DOMException("Cancelled", "AbortError"));
99
+ };
100
+ const timer = setTimeout(() => {
101
+ options.signal?.removeEventListener("abort", abort);
102
+ resolve();
103
+ }, delay);
104
+ if (options.signal?.aborted) {
105
+ abort();
106
+ }
107
+ else {
108
+ options.signal?.addEventListener("abort", abort, { once: true });
109
+ }
110
+ });
111
+ },
112
+ getSecret: async (name) => {
113
+ if (limits.secretScope !== null && !limits.secretScope.includes(name)) {
114
+ throw new Error(`Secret ${name} is outside this run's scope`);
115
+ }
116
+ if (!options.getSecret) {
117
+ throw new Error("Secret access is unavailable for this run");
118
+ }
119
+ return options.getSecret(name);
120
+ },
121
+ workspace: {
122
+ read: async (path) => {
123
+ const text = await requiredWorkspace().readText(path);
124
+ if (text === null) {
125
+ throw new Error("File not found");
126
+ }
127
+ return text;
128
+ },
129
+ write: (path, text) => requiredWorkspace().write(path, text),
130
+ readBytes: async (path) => {
131
+ const bytes = await requiredWorkspace().read(path);
132
+ if (!bytes) {
133
+ throw new Error("File not found");
134
+ }
135
+ return toGuestBytes(bytes);
136
+ },
137
+ writeBytes: (path, value) => requiredWorkspace().write(path, nativeBytes(value)),
138
+ list: async (path) => (await requiredWorkspace().list(path)).map((entry) => entry.name),
139
+ stat: async (path) => {
140
+ const stat = await requiredWorkspace().stat(path);
141
+ return stat
142
+ ? {
143
+ exists: true,
144
+ size: stat.size,
145
+ isDirectory: stat.isDirectory,
146
+ isFile: !stat.isDirectory,
147
+ isSymlink: false,
148
+ modifiedMs: stat.modifiedAt
149
+ }
150
+ : { exists: false };
151
+ },
152
+ mkdir: (path) => requiredWorkspace().mkdir(path),
153
+ remove: (path) => requiredWorkspace().delete(path),
154
+ copy: (from, to) => requiredWorkspace().copy(from, to),
155
+ move: (from, to) => requiredWorkspace().move(from, to),
156
+ root: async () => "/workspace"
157
+ },
158
+ progress: (percent, message) => {
159
+ const now = Date.now();
160
+ if (progressCalls >= 1000 ||
161
+ (progressCalls > 0 && now - lastProgress < 100)) {
162
+ return;
163
+ }
164
+ progressCalls++;
165
+ lastProgress = now;
166
+ try {
167
+ options.onProgress?.(Math.min(Math.max(Number(percent) || 0, 0), 100), message?.slice(0, 500));
168
+ }
169
+ catch {
170
+ /* Reporting cannot break execution. */
171
+ }
172
+ },
173
+ emit: async (name, value) => {
174
+ if (emitted.length >= 10000) {
175
+ throw new Error("Sandbox emit limit exceeded");
176
+ }
177
+ emitted.push({ name: assertOutput(name, value), value });
178
+ },
179
+ output: async (name, value) => {
180
+ const handle = assertOutput(name, value);
181
+ if (Object.hasOwn(outputs, handle)) {
182
+ throw new Error(`Output ${handle} was already set`);
183
+ }
184
+ Object.defineProperty(outputs, handle, { value, enumerable: true });
185
+ },
186
+ fetch: async (url, init) => {
187
+ if (++fetchCalls > limits.maxFetchCalls) {
188
+ throw new Error("Sandbox fetch call limit exceeded");
189
+ }
190
+ const signal = options.signal
191
+ ? AbortSignal.any([
192
+ options.signal,
193
+ AbortSignal.timeout(limits.fetchTimeoutMs)
194
+ ])
195
+ : AbortSignal.timeout(limits.fetchTimeoutMs);
196
+ const response = await safeFetch(url, { ...init, signal });
197
+ const reader = response.body?.getReader();
198
+ const chunks = [];
199
+ let size = 0;
200
+ if (reader) {
201
+ try {
202
+ for (;;) {
203
+ const next = await reader.read();
204
+ if (next.done) {
205
+ break;
206
+ }
207
+ size += next.value.byteLength;
208
+ if (size > limits.maxResponseBodyBytes) {
209
+ throw new Error("Sandbox response size limit exceeded");
210
+ }
211
+ chunks.push(next.value);
212
+ }
213
+ }
214
+ finally {
215
+ await reader.cancel();
216
+ }
217
+ }
218
+ const bytes = Buffer.concat(chunks);
219
+ const body = bytes.toString("utf8");
220
+ let json = null;
221
+ try {
222
+ json = JSON.parse(body);
223
+ }
224
+ catch {
225
+ /* A non-JSON response remains text. */
226
+ }
227
+ return {
228
+ ok: response.ok,
229
+ status: response.status,
230
+ statusText: response.statusText,
231
+ headers: Object.fromEntries(response.headers),
232
+ body,
233
+ json,
234
+ bodyBytes: toGuestBytes(bytes)
235
+ };
236
+ },
237
+ assetToSandbox: unavailable,
238
+ sandboxToAsset: unavailable,
239
+ image: {},
240
+ audio: {},
241
+ video: {},
242
+ canvas: {},
243
+ format: {},
244
+ media: {
245
+ bytes: async (reference) => {
246
+ if (!options.readAsset) {
247
+ throw new Error("Asset access is unavailable for this run");
248
+ }
249
+ return toGuestBytes(await options.readAsset(reference));
250
+ },
251
+ text: async (reference) => {
252
+ if (!options.readAsset) {
253
+ throw new Error("Asset access is unavailable for this run");
254
+ }
255
+ return new TextDecoder().decode(await options.readAsset(reference));
256
+ }
257
+ }
258
+ };
259
+ const globals = {};
260
+ for (const [name, value] of Object.entries(options.globals ?? {})) {
261
+ if (!Object.hasOwn(bridges, name) && /^[A-Za-z_$][\w$]*$/.test(name)) {
262
+ globals[name] = value;
263
+ }
264
+ }
265
+ const message = await runInWorker({
266
+ run: {
267
+ runId: globalThis.crypto.randomUUID(),
268
+ code: options.code,
269
+ timeoutMs,
270
+ limits,
271
+ suspendAllowanceMs: 0,
272
+ hasClock: false,
273
+ engineTimeoutMs: timeoutMs,
274
+ streamOpenSeed: null,
275
+ bridgeShape: deriveBridgeShape({ bridges, dispatchers: [], globals }),
276
+ modules: options.modules
277
+ },
278
+ dispatch: bridges,
279
+ signal: options.signal,
280
+ onLog: () => { },
281
+ onProgress: () => { }
282
+ });
283
+ if (!message) {
284
+ return { success: false, error: "QuickJS worker is unavailable", logs };
285
+ }
286
+ for (const [name, value] of Object.entries(message.syncedGlobals ?? {})) {
287
+ const target = options.globals?.[name];
288
+ if (target &&
289
+ typeof target === "object" &&
290
+ value &&
291
+ typeof value === "object") {
292
+ for (const key of Object.keys(target)) {
293
+ Reflect.deleteProperty(target, key);
294
+ }
295
+ Object.assign(target, value);
296
+ }
297
+ }
298
+ if (options.signal?.aborted || message.failure === "cancelled") {
299
+ return { success: false, error: "Execution cancelled", logs };
300
+ }
301
+ if (!message.evalOk) {
302
+ return {
303
+ success: false,
304
+ error: message.errorMessage ?? "Sandbox execution failed",
305
+ logs
306
+ };
307
+ }
308
+ if (Buffer.byteLength(JSON.stringify(message.data) ?? "null") >
309
+ limits.maxOutputSize) {
310
+ return {
311
+ success: false,
312
+ error: "Sandbox output size limit exceeded",
313
+ logs
314
+ };
315
+ }
316
+ return { success: true, result: message.data, logs, outputs, emitted };
317
+ }
318
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAsB,MAAM,aAAa,CAAC;AAyBvE,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IACE,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,oBAAoB,IAAI,KAAK;QAC7B,OAAO,KAAK,CAAC,oBAAoB,CAAC,KAAK,QAAQ,EAC/C,CAAC;QACD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CA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AAC;IACD,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC/D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC;IAChE,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,OAAO,CAAC,YAAY,IAAI,0BAA0B;YACzD,IAAI;SACL,CAAC;IACJ,CAAC;IACD,IACE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC;QACzD,MAAM,CAAC,aAAa,EACpB,CAAC;QACD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,oCAAoC;YAC3C,IAAI;SACL,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { loadQuickJs } from "../../vendor/quickjs/index.js";
2
+ /** Load an engine with property-handle ownership fixes for quickjs@3.0.1. */
3
+ export declare function loadSandboxEngine(variant: Parameters<typeof loadQuickJs>[0]): ReturnType<typeof loadQuickJs>;
4
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/js-sandbox-worker/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAG5D,6EAA6E;AAC7E,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,GACzC,UAAU,CAAC,OAAO,WAAW,CAAC,CA0ChC"}
@@ -0,0 +1,82 @@
1
+ import { loadQuickJs } from "../../vendor/quickjs/index.js";
2
+ import { Scope } from "quickjs-emscripten-core";
3
+ /** Load an engine with property-handle ownership fixes for quickjs@3.0.1. */
4
+ export async function loadSandboxEngine(variant) {
5
+ const engine = await loadQuickJs(variant);
6
+ const newContext = engine.module.newContext.bind(engine.module);
7
+ engine.module.newContext = (...args) => {
8
+ const context = newContext(...args);
9
+ refreshPointerViews(context.runtime);
10
+ const getProp = context.getProp.bind(context);
11
+ const symbolDescriptions = new Scope();
12
+ const dispose = context.dispose.bind(context);
13
+ context.dispose = () => {
14
+ symbolDescriptions.dispose();
15
+ dispose();
16
+ };
17
+ // quickjs@3.0.1's handleToNative.setProperties returns early for missing
18
+ // descriptor fields and boolean flags without disposing their handles.
19
+ // Release those allocations here and return the equivalent static handles.
20
+ // StaticLifetime.dispose is a no-op, so callers that do dispose still work.
21
+ // Install before the wrapper bootstraps the context, on both execution paths.
22
+ context.getProp = (object, key) => {
23
+ const handle = getProp(object, key);
24
+ const type = context.typeof(handle);
25
+ if (type === "undefined" || type === "boolean") {
26
+ const value = type === "undefined"
27
+ ? context.undefined
28
+ : context.dump(handle) === true
29
+ ? context.true
30
+ : context.false;
31
+ handle.dispose();
32
+ return value;
33
+ }
34
+ // handleToNative also reads Symbol.description without disposing it.
35
+ // Scope skips handles already disposed by a caller and frees the rest
36
+ // while the context is still alive.
37
+ if (key === "description" && context.typeof(object) === "symbol") {
38
+ symbolDescriptions.manage(handle);
39
+ }
40
+ return handle;
41
+ };
42
+ return context;
43
+ };
44
+ return engine;
45
+ }
46
+ const REFRESHED = Symbol("nodetool.refreshedPointerViews");
47
+ /**
48
+ * quickjs-emscripten-core@0.31 reads output pointers through a typed-array
49
+ * view made before the C call. When the call grows the WASM heap, the view's
50
+ * buffer is detached and reads `undefined`. `executePendingJobs` then takes
51
+ * `undefined` for the job's context pointer and builds a brand-new context,
52
+ * which nothing frees, so the runtime aborts on free with
53
+ * `list_empty(&rt->gc_obj_list)`. Any guest that allocated a few megabytes
54
+ * after its first `await` hit it. The view is rebuilt over the current heap
55
+ * whenever the old one went stale.
56
+ */
57
+ function refreshPointerViews(runtime) {
58
+ const memory = runtime.memory;
59
+ if (!memory)
60
+ return;
61
+ const proto = Object.getPrototypeOf(memory);
62
+ if (proto[REFRESHED])
63
+ return;
64
+ const newTypedArray = proto.newTypedArray;
65
+ proto.newTypedArray = function (kind, length) {
66
+ const lifetime = newTypedArray.call(this, kind, length);
67
+ const holder = lifetime.value;
68
+ const heap = this.module;
69
+ let view = holder.typedArray;
70
+ Object.defineProperty(holder, "typedArray", {
71
+ get: () => {
72
+ if (view.buffer !== heap.HEAPU8.buffer) {
73
+ view = new kind(heap.HEAPU8.buffer, holder.ptr, length);
74
+ }
75
+ return view;
76
+ }
77
+ });
78
+ return lifetime;
79
+ };
80
+ proto[REFRESHED] = true;
81
+ }
82
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/js-sandbox-worker/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA0C;IAE1C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;QACpC,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC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