@agentkit-js/kernel-quickjs 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/LICENSE +186 -0
- package/README.md +31 -0
- package/dist/QuickJSKernel.d.ts +89 -0
- package/dist/QuickJSKernel.d.ts.map +1 -0
- package/dist/QuickJSKernel.js +265 -0
- package/dist/QuickJSKernel.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as defined by the copyright owner,
|
|
48
|
+
any work of authorship, including the original version of the Work and
|
|
49
|
+
any modifications or additions to that Work or Derivative Works of the
|
|
50
|
+
Work, that is intentionally submitted to the Licensor for inclusion in
|
|
51
|
+
the Work by the copyright owner or by an individual or Legal Entity
|
|
52
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
53
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
54
|
+
or written communication sent to the Licensor or its representatives,
|
|
55
|
+
including but not limited to communication on electronic mailing lists,
|
|
56
|
+
source code control systems, and issue tracking systems that are
|
|
57
|
+
managed by, or on behalf of, the Licensor for the purpose of
|
|
58
|
+
discussing and improving the Work, but excluding communication that is
|
|
59
|
+
conspicuously marked or otherwise designated in writing by the copyright
|
|
60
|
+
owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
63
|
+
whom a Contribution has been received by the Licensor and included
|
|
64
|
+
within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a cross-claim
|
|
83
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
84
|
+
Contribution embodied within the Work constitutes patent or
|
|
85
|
+
contributory patent infringement, then any patent licenses granted
|
|
86
|
+
to You under this License for that Work shall terminate as of the date
|
|
87
|
+
such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, You must include a readable copy of the
|
|
108
|
+
attribution notices contained within such NOTICE file, in
|
|
109
|
+
at least one of the following places: within a NOTICE text
|
|
110
|
+
file distributed as part of the Derivative Works; within
|
|
111
|
+
the Source form or documentation, if provided along with the
|
|
112
|
+
Derivative Works; or, within a display generated by the
|
|
113
|
+
Derivative Works, if and wherever such third-party notices
|
|
114
|
+
normally appear. The contents of the NOTICE file are for
|
|
115
|
+
informational purposes only and do not modify the License.
|
|
116
|
+
You may add Your own attribution notices within Derivative
|
|
117
|
+
Works that You distribute, alongside or as an addendum to
|
|
118
|
+
the NOTICE text from the Work, provided that such additional
|
|
119
|
+
attribution notices cannot be construed as modifying the License.
|
|
120
|
+
|
|
121
|
+
You may add Your own license statement for Your modifications and
|
|
122
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
123
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
124
|
+
Contribution, either alone or in combination with the Work.
|
|
125
|
+
|
|
126
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
127
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
128
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
129
|
+
this License, without any additional terms or conditions.
|
|
130
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
131
|
+
the terms of any separate license agreement you may have executed
|
|
132
|
+
with Licensor regarding such Contributions.
|
|
133
|
+
|
|
134
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
135
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
136
|
+
except as required for reasonable and customary use in describing the
|
|
137
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
138
|
+
|
|
139
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
140
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
141
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
142
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
143
|
+
implied, including, without limitation, any conditions of
|
|
144
|
+
TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
145
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
146
|
+
appropriateness of using or reproducing the Work and assume any
|
|
147
|
+
risks associated with Your exercise of permissions under this License.
|
|
148
|
+
|
|
149
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
150
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
151
|
+
unless required by applicable law (such as deliberate and grossly
|
|
152
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
153
|
+
liable to You for damages, including any direct, indirect, special,
|
|
154
|
+
incidental, or exemplary damages of any character arising as a
|
|
155
|
+
result of this License or out of the use or inability to use the
|
|
156
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
157
|
+
work stoppage, computer failure or malfunction, or all other
|
|
158
|
+
commercial damages or losses), even if such Contributor has been
|
|
159
|
+
advised of the possibility of such damages.
|
|
160
|
+
|
|
161
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
162
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
163
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
164
|
+
or other liability obligations and/or rights consistent with this
|
|
165
|
+
License. However, in accepting such obligations, You may act only
|
|
166
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
167
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
168
|
+
defend, and hold each Contributor harmless for any liability
|
|
169
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
170
|
+
of your accepting any such warranty or additional liability.
|
|
171
|
+
|
|
172
|
+
END OF TERMS AND CONDITIONS
|
|
173
|
+
|
|
174
|
+
Copyright 2026 agentkit-js contributors
|
|
175
|
+
|
|
176
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
177
|
+
you may not use this file except in compliance with the License.
|
|
178
|
+
You may obtain a copy of the License at
|
|
179
|
+
|
|
180
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
181
|
+
|
|
182
|
+
Unless required by applicable law or agreed to in writing, software
|
|
183
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
184
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
185
|
+
See the License for the specific language governing permissions and
|
|
186
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @agentkit-js/kernel-quickjs
|
|
2
|
+
|
|
3
|
+
QuickJS-in-WASM kernel — sandboxed JavaScript, edge-safe, no `node:vm` required.
|
|
4
|
+
|
|
5
|
+
> Part of [agentkit-js](https://github.com/telleroutlook/agentkit-js) — a TypeScript + WASM agent runtime.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @agentkit-js/kernel-quickjs @agentkit-js/core quickjs-emscripten @jitl/quickjs-wasmfile-release-sync
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { QuickJSKernel } from "@agentkit-js/kernel-quickjs";
|
|
17
|
+
|
|
18
|
+
const kernel = new QuickJSKernel();
|
|
19
|
+
const result = await kernel.run(`[1,2,3].reduce((a,b) => a+b, 0)`);
|
|
20
|
+
console.log(result.output); // 6
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Drop-in replacement for `VmKernel` on **Cloudflare Workers** (which forbids `node:vm`),
|
|
24
|
+
Vercel Edge, Deno Deploy, and any environment where you want true language-level sandboxing
|
|
25
|
+
without spinning up a microVM.
|
|
26
|
+
|
|
27
|
+
See the [kernel decision tree](https://github.com/telleroutlook/agentkit-js/blob/main/docs/kernels/comparison.md).
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
[Apache-2.0](./LICENSE) — © agentkit-js contributors
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { CapabilityManifest, KernelOptions, KernelResult, WasmKernel } from "@agentkit-js/core/executor";
|
|
2
|
+
type QHandle = object;
|
|
3
|
+
interface QuickJSContext {
|
|
4
|
+
evalCode(code: string, filename?: string): {
|
|
5
|
+
value: unknown;
|
|
6
|
+
tag?: number;
|
|
7
|
+
dispose?(): void;
|
|
8
|
+
};
|
|
9
|
+
unwrapResult(result: unknown): {
|
|
10
|
+
consume<T>(fn: (h: QHandle) => T): T;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
} & QHandle;
|
|
13
|
+
callFunction(fn: unknown, thisVal: unknown, ...args: unknown[]): {
|
|
14
|
+
value: unknown;
|
|
15
|
+
tag?: number;
|
|
16
|
+
};
|
|
17
|
+
getProp(obj: unknown, key: string): {
|
|
18
|
+
consume<T>(fn: (h: QHandle) => T): T;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
} & QHandle;
|
|
21
|
+
setProp(obj: unknown, key: string, value: unknown): void;
|
|
22
|
+
dump(handle: unknown): unknown;
|
|
23
|
+
typeof(handle: unknown): string;
|
|
24
|
+
getString(handle: unknown): string;
|
|
25
|
+
global: QHandle;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
}
|
|
28
|
+
interface QuickJSRuntime {
|
|
29
|
+
newContext(): QuickJSContext;
|
|
30
|
+
setInterruptHandler(fn: () => boolean): void;
|
|
31
|
+
hasPendingJob(): boolean;
|
|
32
|
+
executePendingJobs(maxJobs?: number): unknown;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
interface QuickJSModule {
|
|
36
|
+
newRuntime(): QuickJSRuntime;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* QuickJSKernel — runs agent JS code in a QuickJS (C, compiled to WASM) sandbox.
|
|
40
|
+
*
|
|
41
|
+
* Why this exists:
|
|
42
|
+
* JsKernel uses Node.js worker_threads + node:vm. Cloudflare Workers does not
|
|
43
|
+
* provide node:vm. QuickJS-emscripten is a pure WASM build — it works anywhere
|
|
44
|
+
* WebAssembly runs, including Cloudflare Workers and serverless edge runtimes.
|
|
45
|
+
*
|
|
46
|
+
* Key properties:
|
|
47
|
+
* - Persistent context: variables survive across run() calls (stateful kernel).
|
|
48
|
+
* - Timeout: QuickJS interrupt handler fires every ~10k instructions so
|
|
49
|
+
* while(true){} is interrupted after timeoutMs without blocking the event loop.
|
|
50
|
+
* - No Node.js APIs in the sandbox by default (deny-all baseline).
|
|
51
|
+
* - allowedHosts capability: a JS-side fetch wrapper enforces the host allow-list.
|
|
52
|
+
*
|
|
53
|
+
* Q3 — Cloudflare Workers compatibility:
|
|
54
|
+
* Workers prohibits runtime WASM compilation (same restriction as eval). The default
|
|
55
|
+
* `getQuickJS()` from quickjs-emscripten fetches and compiles a .wasm at runtime,
|
|
56
|
+
* which crashes in workerd with CompileError: WebAssembly code generation disallowed.
|
|
57
|
+
*
|
|
58
|
+
* The fix: pass a pre-compiled variant via the `variant` option. In the Cloudflare
|
|
59
|
+
* Worker, import the variant at build time and inject it:
|
|
60
|
+
*
|
|
61
|
+
* import cfVariant from "@jitl/quickjs-wasmfile-release-sync";
|
|
62
|
+
* import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core";
|
|
63
|
+
* new QuickJSKernel({ variant: cfVariant, variantLoader: newQuickJSWASMModuleFromVariant })
|
|
64
|
+
*
|
|
65
|
+
* The variant is bundled by wrangler at build time, so no runtime WASM compilation
|
|
66
|
+
* is needed. Node environments can omit variant/variantLoader and use the default.
|
|
67
|
+
*/
|
|
68
|
+
export interface QuickJSKernelOptions extends KernelOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Pre-compiled QuickJS variant for environments that prohibit runtime WASM
|
|
71
|
+
* compilation (Cloudflare Workers). Must be paired with variantLoader.
|
|
72
|
+
* Omit to use the default getQuickJS() which compiles at runtime (Node only).
|
|
73
|
+
*/
|
|
74
|
+
variant?: unknown;
|
|
75
|
+
/**
|
|
76
|
+
* Loader function for the pre-compiled variant, e.g.
|
|
77
|
+
* `newQuickJSWASMModuleFromVariant` from "quickjs-emscripten-core".
|
|
78
|
+
*/
|
|
79
|
+
variantLoader?: (variant: unknown) => Promise<QuickJSModule>;
|
|
80
|
+
}
|
|
81
|
+
export declare class QuickJSKernel implements WasmKernel {
|
|
82
|
+
#private;
|
|
83
|
+
constructor(opts?: QuickJSKernelOptions);
|
|
84
|
+
run(code: string, capabilities?: Partial<CapabilityManifest>): Promise<KernelResult>;
|
|
85
|
+
reset(): Promise<void>;
|
|
86
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=QuickJSKernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuickJSKernel.d.ts","sourceRoot":"","sources":["../src/QuickJSKernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,UAAU,EACX,MAAM,4BAA4B,CAAC;AAIpC,KAAK,OAAO,GAAG,MAAM,CAAC;AAEtB,UAAU,cAAc;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,IAAI,IAAI,CAAA;KAAE,CAAC;IAC9F,YAAY,CACV,MAAM,EAAE,OAAO,GACd;QAAE,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QAAC,OAAO,IAAI,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC;IACvE,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClG,OAAO,CACL,GAAG,EAAE,OAAO,EACZ,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FpF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4DtB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB7C"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
export class QuickJSKernel {
|
|
2
|
+
#runtime = null;
|
|
3
|
+
#ctx = null;
|
|
4
|
+
#module = null;
|
|
5
|
+
#timeoutMs;
|
|
6
|
+
#variant;
|
|
7
|
+
#variantLoader;
|
|
8
|
+
#logs = [];
|
|
9
|
+
// Q4: cache the in-flight init promise so concurrent callers share one runtime.
|
|
10
|
+
#initPromise = null;
|
|
11
|
+
// Q1: flag set by interrupt handler so interrupt detection does not rely on
|
|
12
|
+
// parsing the error message string (which is an emscripten implementation detail).
|
|
13
|
+
#timedOut = false;
|
|
14
|
+
// Cached handles to JSON.stringify — initialised once per context, disposed on reset.
|
|
15
|
+
#jsonObj = null;
|
|
16
|
+
#stringify = null;
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.#timeoutMs = opts?.timeoutMs ?? 5_000;
|
|
19
|
+
this.#variant = opts?.variant;
|
|
20
|
+
this.#variantLoader = opts?.variantLoader;
|
|
21
|
+
}
|
|
22
|
+
async #ensureContext() {
|
|
23
|
+
if (this.#ctx)
|
|
24
|
+
return this.#ctx;
|
|
25
|
+
// Q4: return the in-flight promise if init is already in progress.
|
|
26
|
+
if (this.#initPromise)
|
|
27
|
+
return this.#initPromise;
|
|
28
|
+
this.#initPromise = (async () => {
|
|
29
|
+
if (this.#variant && this.#variantLoader) {
|
|
30
|
+
// Q3: Workers-safe path — use pre-compiled variant (no runtime WASM compilation).
|
|
31
|
+
this.#module = await this.#variantLoader(this.#variant);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Default Node.js path — getQuickJS() fetches and compiles .wasm at runtime.
|
|
35
|
+
// This will fail in Cloudflare Workers (WASM compilation is disallowed).
|
|
36
|
+
const { getQuickJS } = await import("quickjs-emscripten");
|
|
37
|
+
this.#module = (await getQuickJS());
|
|
38
|
+
}
|
|
39
|
+
this.#runtime = this.#module.newRuntime();
|
|
40
|
+
this.#ctx = this.#runtime.newContext();
|
|
41
|
+
this.#jsonObj = this.#ctx.getProp(this.#ctx.global, "JSON");
|
|
42
|
+
this.#stringify = this.#ctx.getProp(this.#jsonObj, "stringify");
|
|
43
|
+
this.#injectConsole(this.#ctx);
|
|
44
|
+
return this.#ctx;
|
|
45
|
+
})();
|
|
46
|
+
return this.#initPromise;
|
|
47
|
+
}
|
|
48
|
+
#injectConsole(ctx) {
|
|
49
|
+
const result = ctx.evalCode(`
|
|
50
|
+
var __logs__ = [];
|
|
51
|
+
var console = {
|
|
52
|
+
log: function() { __logs__.push(Array.prototype.join.call(arguments, " ")); },
|
|
53
|
+
warn: function() { console.log.apply(console, arguments); },
|
|
54
|
+
error: function() { console.log.apply(console, arguments); },
|
|
55
|
+
};
|
|
56
|
+
`);
|
|
57
|
+
if (result && typeof result.dispose === "function") {
|
|
58
|
+
result.dispose();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Serialise a QuickJS handle to a JS value using JSON.stringify inside QuickJS.
|
|
63
|
+
*
|
|
64
|
+
* Uses callFunction(JSON.stringify) — does not write to the global namespace (Q1).
|
|
65
|
+
* Circular references throw KernelSerializationError (Q3).
|
|
66
|
+
* Functions and Symbols also throw — JSON.stringify silently returns undefined for
|
|
67
|
+
* these types, which would produce isFinalAnswer=true with output=undefined if not
|
|
68
|
+
* caught here (Q2). We detect them with typeof before calling stringify.
|
|
69
|
+
*/
|
|
70
|
+
#serialize(ctx, scope, handle, label) {
|
|
71
|
+
// Q2: catch functions and symbols before stringify silently drops them.
|
|
72
|
+
const t = ctx.typeof(handle);
|
|
73
|
+
if (t === "function" || t === "symbol") {
|
|
74
|
+
throw new Error(`KernelSerializationError: ${label} is a ${t} and cannot be serialised. ` +
|
|
75
|
+
"Return only JSON-serialisable values from agent code.");
|
|
76
|
+
}
|
|
77
|
+
let jsonResult;
|
|
78
|
+
try {
|
|
79
|
+
jsonResult = scope.manage(ctx.unwrapResult(ctx.callFunction(this.#stringify, ctx.global, handle)));
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
// JSON.stringify throws inside QuickJS for circular references.
|
|
83
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
84
|
+
throw new Error(`KernelSerializationError: ${label} contains a value that cannot be serialised ` +
|
|
85
|
+
`(${msg}). Return only JSON-serialisable values from agent code.`);
|
|
86
|
+
}
|
|
87
|
+
// JSON.stringify(undefined) returns QuickJS undefined — typeof check before getString.
|
|
88
|
+
if (ctx.typeof(jsonResult) === "undefined") {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const jsonStr = ctx.getString(jsonResult);
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(jsonStr);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new Error(`KernelSerializationError: ${label} contains a value that cannot be serialised ` +
|
|
97
|
+
"(non-JSON type). Return only JSON-serialisable values from agent code.");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async run(code, capabilities) {
|
|
101
|
+
const ctx = await this.#ensureContext();
|
|
102
|
+
const { Scope } = await import("quickjs-emscripten");
|
|
103
|
+
const ScopeStatic = Scope;
|
|
104
|
+
this.#logs = [];
|
|
105
|
+
ctx
|
|
106
|
+
.evalCode("__logs__ = []; var __finalAnswer__ = undefined; var __final_answer__ = undefined;")
|
|
107
|
+
?.dispose?.();
|
|
108
|
+
if (capabilities?.allowedHosts?.length) {
|
|
109
|
+
this.#injectFetchWrapper(ctx, capabilities.allowedHosts);
|
|
110
|
+
}
|
|
111
|
+
// Q1: use a flag instead of message-string matching to detect interrupts.
|
|
112
|
+
// The interrupt handler sets #timedOut = true before the QuickJS error propagates.
|
|
113
|
+
this.#timedOut = false;
|
|
114
|
+
const deadline = Date.now() + this.#timeoutMs;
|
|
115
|
+
this.#runtime?.setInterruptHandler(() => {
|
|
116
|
+
if (Date.now() > deadline) {
|
|
117
|
+
this.#timedOut = true;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
});
|
|
122
|
+
// Q5: Scope.withScopeAsync automatically disposes all scope.manage()'d handles
|
|
123
|
+
// when the block exits, whether by return or throw. No manual .dispose() needed.
|
|
124
|
+
return ScopeStatic.withScopeAsync(async (scope) => {
|
|
125
|
+
let output;
|
|
126
|
+
let isFinalAnswer = false;
|
|
127
|
+
try {
|
|
128
|
+
const resultHandle = scope.manage(ctx.unwrapResult(ctx.evalCode(code, "agent-step.js")));
|
|
129
|
+
// Q1/Q3: serialise output via callFunction(JSON.stringify) — no global writes,
|
|
130
|
+
// and circular refs / functions throw KernelSerializationError here.
|
|
131
|
+
output = this.#serialize(ctx, scope, resultHandle, "output");
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
135
|
+
// Q1: check #timedOut flag set by interrupt handler — more reliable than
|
|
136
|
+
// matching the emscripten error message string "interrupted".
|
|
137
|
+
if (this.#timedOut) {
|
|
138
|
+
await this.reset();
|
|
139
|
+
throw new Error(`KernelError: Script execution timed out after ${this.#timeoutMs}ms`);
|
|
140
|
+
}
|
|
141
|
+
if (msg.startsWith("KernelSerializationError"))
|
|
142
|
+
throw err;
|
|
143
|
+
throw new Error(`KernelError: ${msg}`);
|
|
144
|
+
}
|
|
145
|
+
const logsHandle = scope.manage(ctx.unwrapResult(ctx.evalCode("JSON.stringify(__logs__)")));
|
|
146
|
+
this.#logs = JSON.parse(ctx.getString(logsHandle));
|
|
147
|
+
// Q2/Q5: check both sentinels — camelCase (__finalAnswer__) and snake_case (__final_answer__).
|
|
148
|
+
// Both spellings are initialised to undefined above; whichever the agent sets is used.
|
|
149
|
+
// This lets agent code work regardless of which kernel backend (JS vs Python convention).
|
|
150
|
+
const faCamelHandle = scope.manage(ctx.unwrapResult(ctx.evalCode("__finalAnswer__")));
|
|
151
|
+
const faSnakeHandle = scope.manage(ctx.unwrapResult(ctx.evalCode("__final_answer__")));
|
|
152
|
+
const faCamelSet = ctx.typeof(faCamelHandle) !== "undefined";
|
|
153
|
+
const faSnakeSet = ctx.typeof(faSnakeHandle) !== "undefined";
|
|
154
|
+
isFinalAnswer = faCamelSet || faSnakeSet;
|
|
155
|
+
const faHandle = faCamelSet ? faCamelHandle : faSnakeHandle;
|
|
156
|
+
let finalOutput = output;
|
|
157
|
+
if (isFinalAnswer) {
|
|
158
|
+
finalOutput = this.#serialize(ctx, scope, faHandle, "__finalAnswer__");
|
|
159
|
+
}
|
|
160
|
+
return { output: finalOutput, logs: this.#logs, isFinalAnswer };
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
#injectFetchWrapper(ctx, allowedHosts) {
|
|
164
|
+
const hostsJson = JSON.stringify(allowedHosts);
|
|
165
|
+
ctx
|
|
166
|
+
.evalCode(`
|
|
167
|
+
var __allowed_hosts__ = ${hostsJson};
|
|
168
|
+
function __check_host__(host) {
|
|
169
|
+
var ok = __allowed_hosts__.some(function(h) {
|
|
170
|
+
if (h.startsWith("*.")) return host.endsWith(h.slice(1));
|
|
171
|
+
return host === h;
|
|
172
|
+
});
|
|
173
|
+
if (!ok) throw new Error("CapabilityDenied: fetch to \\"" + host + "\\" not in allowedHosts");
|
|
174
|
+
}
|
|
175
|
+
`)
|
|
176
|
+
?.dispose?.();
|
|
177
|
+
}
|
|
178
|
+
async reset() {
|
|
179
|
+
this.#disposeContextHandles();
|
|
180
|
+
this.#drainPendingJobs();
|
|
181
|
+
if (this.#ctx) {
|
|
182
|
+
try {
|
|
183
|
+
this.#ctx.dispose();
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
/* ignore */
|
|
187
|
+
}
|
|
188
|
+
this.#ctx = null;
|
|
189
|
+
}
|
|
190
|
+
// After an interrupt/timeout, the QuickJS runtime may have live GC objects
|
|
191
|
+
// that cause a native assertion if we call runtime.dispose(). Skip dispose
|
|
192
|
+
// in that case and let the WASM module clean up when the process exits.
|
|
193
|
+
if (this.#runtime && !this.#timedOut) {
|
|
194
|
+
try {
|
|
195
|
+
this.#runtime.dispose();
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
/* ignore */
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
this.#runtime = null;
|
|
202
|
+
// Q4: clear initPromise so #ensureContext rebuilds cleanly after dispose.
|
|
203
|
+
this.#initPromise = null;
|
|
204
|
+
this.#timedOut = false;
|
|
205
|
+
await this.#ensureContext();
|
|
206
|
+
this.#logs = [];
|
|
207
|
+
}
|
|
208
|
+
#disposeContextHandles() {
|
|
209
|
+
if (this.#stringify) {
|
|
210
|
+
try {
|
|
211
|
+
this.#stringify.dispose();
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
/* ignore */
|
|
215
|
+
}
|
|
216
|
+
this.#stringify = null;
|
|
217
|
+
}
|
|
218
|
+
if (this.#jsonObj) {
|
|
219
|
+
try {
|
|
220
|
+
this.#jsonObj.dispose();
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
/* ignore */
|
|
224
|
+
}
|
|
225
|
+
this.#jsonObj = null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Drain any pending QuickJS microjobs before disposing runtime to prevent GC assertion failures. */
|
|
229
|
+
#drainPendingJobs() {
|
|
230
|
+
if (!this.#runtime)
|
|
231
|
+
return;
|
|
232
|
+
try {
|
|
233
|
+
while (this.#runtime.hasPendingJob()) {
|
|
234
|
+
this.#runtime.executePendingJobs(1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
/* ignore errors from aborted/interrupted scripts */
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async [Symbol.asyncDispose]() {
|
|
242
|
+
this.#disposeContextHandles();
|
|
243
|
+
this.#drainPendingJobs();
|
|
244
|
+
if (this.#ctx) {
|
|
245
|
+
try {
|
|
246
|
+
this.#ctx.dispose();
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
/* ignore */
|
|
250
|
+
}
|
|
251
|
+
this.#ctx = null;
|
|
252
|
+
}
|
|
253
|
+
if (this.#runtime && !this.#timedOut) {
|
|
254
|
+
try {
|
|
255
|
+
this.#runtime.dispose();
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
/* ignore */
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
this.#runtime = null;
|
|
262
|
+
this.#initPromise = null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=QuickJSKernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuickJSKernel.js","sourceRoot":"","sources":["../src/QuickJSKernel.ts"],"names":[],"mappings":"AA6FA,MAAM,OAAO,aAAa;IACxB,QAAQ,GAA0B,IAAI,CAAC;IACvC,IAAI,GAA0B,IAAI,CAAC;IACnC,OAAO,GAAyB,IAAI,CAAC;IAC5B,UAAU,CAAS;IACnB,QAAQ,CAAU;IAClB,cAAc,CAAuD;IAC9E,KAAK,GAAa,EAAE,CAAC;IAErB,gFAAgF;IAChF,YAAY,GAAmC,IAAI,CAAC;IAEpD,4EAA4E;IAC5E,mFAAmF;IACnF,SAAS,GAAG,KAAK,CAAC;IAElB,sFAAsF;IACtF,QAAQ,GAA2C,IAAI,CAAC;IACxD,UAAU,GAA2C,IAAI,CAAC;IAE1D,YAAY,IAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,SAAS,IAAI,KAAK,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,IAAI,EAAE,aAAa,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC;Q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BAAsB,EAAE,CAAC;QAC9B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC;gBACH,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;YACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentkit-js/kernel-quickjs",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "QuickJS-in-WASM kernel for agentkit-js — safe for Cloudflare Workers and serverless environments that lack node:vm",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"clean": "rm -rf dist .turbo"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@agentkit-js/core": "workspace:*"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"quickjs-emscripten": ">=0.29.0",
|
|
25
|
+
"quickjs-emscripten-core": ">=0.29.0",
|
|
26
|
+
"@jitl/quickjs-wasmfile-release-sync": ">=0.29.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"quickjs-emscripten-core": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@jitl/quickjs-wasmfile-release-sync": {
|
|
33
|
+
"optional": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
|
38
|
+
"quickjs-emscripten": "0.32.0",
|
|
39
|
+
"quickjs-emscripten-core": "0.32.0",
|
|
40
|
+
"typescript": "^5.7.0",
|
|
41
|
+
"vitest": "^2.1.0"
|
|
42
|
+
},
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/telleroutlook/agentkit-js.git",
|
|
47
|
+
"directory": "packages/kernel-quickjs"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/telleroutlook/agentkit-js/tree/main/packages/kernel-quickjs#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/telleroutlook/agentkit-js/issues"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20.0.0"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"agentkit",
|
|
58
|
+
"agent",
|
|
59
|
+
"ai",
|
|
60
|
+
"llm"
|
|
61
|
+
],
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist",
|
|
67
|
+
"LICENSE",
|
|
68
|
+
"README.md"
|
|
69
|
+
],
|
|
70
|
+
"author": "agentkit-js contributors"
|
|
71
|
+
}
|