@wasmagent/openai-agents 0.1.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 ADDED
@@ -0,0 +1,201 @@
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, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated 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 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
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date 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
95
+ Derivative 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, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 agentkit-js contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # /openai-agents
2
+
3
+ > Drop wasmagent sandbox kernels into the **OpenAI Agents JS SDK** as a
4
+ > native `tool`. Edge-safe code execution, one capability manifest, runs on
5
+ > Cloudflare Workers / Vercel Edge / Node — no E2B sandbox required.
6
+
7
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/WasmAgent/wasmagent-js/tree/main/examples/openai-agents-quickjs?file=index.mjs)
8
+
9
+ ## Why this exists
10
+
11
+ The 2026-04 OpenAI Agents JS release introduced a first-party
12
+ [`SandboxAgent`](https://openai.github.io/openai-agents-js/) with
13
+ Unix-local, Docker, and hosted-container execution clients. That covers
14
+ the case where a host process is available and you want OS-level
15
+ isolation. It does **not** cover:
16
+
17
+ - Cloudflare Workers / Vercel Edge / browser tabs (no host process for
18
+ Unix-local; Docker isn't a thing on the edge).
19
+ - Air-gapped / offline deployments where reaching a hosted container is
20
+ not allowed.
21
+ - Workloads where 50 ms is too long for cold start and per-second container
22
+ billing dominates the cost.
23
+
24
+ The agentkit kernels live below the OS line — QuickJS-in-WASM, Pyodide-in-WASM,
25
+ or Wasmtime — so they run wherever JS runs. This package binds them to the
26
+ Agents JS `Tool` shape.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ npm install @openai/agents /openai-agents /kernel-quickjs \
32
+ quickjs-emscripten @jitl/quickjs-wasmfile-release-sync zod
33
+ ```
34
+
35
+ ## One-shot snippet evaluation
36
+
37
+ ```ts
38
+ import { Agent } from "@openai/agents";
39
+ import { sandboxedJsAgentTool } from "/openai-agents";
40
+ import { QuickJSKernel } from "/kernel-quickjs";
41
+
42
+ const agent = new Agent({
43
+ name: "math-helper",
44
+ tools: [
45
+ sandboxedJsAgentTool({
46
+ kernel: new QuickJSKernel(),
47
+ capabilities: { cpuMs: 5000 },
48
+ }),
49
+ ],
50
+ });
51
+ ```
52
+
53
+ ## Code-mode: collapse N tools
54
+
55
+ ```ts
56
+ import { codeModeAgentTool } from "/openai-agents";
57
+ import { ToolRegistry } from "/core";
58
+
59
+ const tools = new ToolRegistry();
60
+ // …register downstream tools…
61
+
62
+ const portalTool = codeModeAgentTool({
63
+ kernel: new QuickJSKernel(),
64
+ tools,
65
+ capabilities: { allowedHosts: ["api.example.com"] },
66
+ });
67
+
68
+ const agent = new Agent({ name: "ops", tools: [portalTool] });
69
+ // Model sees ONE tool; in-sandbox scripts call N tools via callTool(...).
70
+ ```
71
+
72
+ ## Kernel selection — pick the right tier
73
+
74
+ `sandboxedJsAgentTool()` and `codeModeAgentTool()` accept any agentkit
75
+ kernel. The choice is independent of the SDK adapter — swap kernels in
76
+ one line, the rest of your code is unchanged:
77
+
78
+ | Kernel | When to pick it | Edge-safe |
79
+ | ------ | --------------- | --------- |
80
+ | `QuickJSKernel` (`/kernel-quickjs`) | Default. JS/TS workloads. ~2 MB cold start. | ✅ |
81
+ | `PyodideKernel` (`/kernel-pyodide`) | Model emits Python (numpy, pandas, regex-heavy). | ✅ (heavy) |
82
+ | `WasmtimeKernel` (`/kernel-wasmtime`) | Multi-language WASM modules / Javy-compiled JS for max isolation. | ✅ |
83
+ | `RemoteSandboxKernel` (`/kernel-remote`) | Need full POSIX, native binaries, multi-tenant trust. Backed by E2B / Cloudflare Sandbox. | n/a |
84
+
85
+ Swap is a one-liner — `kernel: new QuickJSKernel()` becomes `kernel: new PyodideKernel()`. Same `CapabilityManifest`, same OpenAI Agents JS `Tool<T>` shape.
86
+
87
+ ## Capability manifest
88
+
89
+ Same `CapabilityManifest` as the other adapters — see
90
+ [`docs/guides/code-mode.md`](https://github.com/WasmAgent/wasmagent-js/blob/main/docs/guides/code-mode.md#security-policy-face).
91
+
92
+ ## When to pick this over `SandboxAgent`
93
+
94
+ | Need | OpenAI `SandboxAgent` | `/openai-agents` |
95
+ |---|---|---|
96
+ | Cloudflare Workers / Vercel Edge | ❌ requires host process | ✅ WASM kernel runs in-isolate |
97
+ | Native binaries / full POSIX | ✅ Docker / hosted | ❌ language-level only |
98
+ | Cold start | ~200–800 ms (container) | ~50 ms (WASM) |
99
+ | Cost per call | per-second container billing | $0 (in-process) |
100
+ | Offline / air-gapped | ❌ | ✅ |
101
+
102
+ Use both: `SandboxAgent` for "I need bash + git", `codeModeAgentTool` for
103
+ "the model wants to do math / parse JSON / chain tool calls".
104
+
105
+ ## See also
106
+
107
+ - [`/aisdk`](https://www.npmjs.com/package//aisdk) — same kernels for Vercel AI SDK
108
+ - [`/claude-agent-sdk`](https://www.npmjs.com/package//claude-agent-sdk) — same kernels for Anthropic Claude Agent SDK
109
+ - [`/mastra-sandbox`](https://www.npmjs.com/package//mastra-sandbox) — same kernels as a Mastra sandbox provider
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @wasmagent/openai-agents — agentkit kernels as OpenAI Agents JS tools.
3
+ *
4
+ * The OpenAI Agents JS SDK (`@openai/agents`) accepts a `Tool`-shaped
5
+ * definition: `{ name, description, parameters (Zod), execute(input) }`.
6
+ * Functionally identical to Vercel AI SDK's `tool()` shape with field
7
+ * renaming. Rather than ask consumers to reach for a different package
8
+ * for each upstream, we ship a thin adapter that produces the
9
+ * structurally-typed tool object and lets them drop it into
10
+ * `agent({ tools: […] })` directly.
11
+ *
12
+ * - {@link sandboxedJsAgentTool} — one-shot JS evaluator. The agent
13
+ * calls it; the kernel runs the snippet; output is `{ output, logs }`.
14
+ *
15
+ * - {@link codeModeAgentTool} — code-mode tool. The agent emits a
16
+ * snippet that may call `callTool(name, args)` against any
17
+ * registered downstream tool; only the script's final return value
18
+ * re-enters the model context.
19
+ *
20
+ * Both honour the unified `CapabilityManifest` (allowedHosts /
21
+ * allowedReadPaths / allowedWritePaths / env / cpuMs /
22
+ * memoryLimitBytes), so a security policy you wrote for the MCP server
23
+ * works here verbatim — see
24
+ * [`docs/strategy/security-face.md`](../../docs/strategy/security-face.md).
25
+ *
26
+ * Peer-dep: `@openai/agents` >= 0.1 (declared optional so unit tests
27
+ * can run without it). The package only emits the tool's shape; it
28
+ * does not import `@openai/agents` at runtime.
29
+ *
30
+ * Why a separate package from `@wasmagent/aisdk`: although the AI
31
+ * SDK and OpenAI Agents JS shapes are nearly identical, version
32
+ * matrices and bundle expectations differ. Keeping them apart lets
33
+ * upstream documentation in each ecosystem link to the package that
34
+ * matches *their* idiom — see
35
+ * [`docs/strategy/2026-06-competitiveness.md`](../../docs/strategy/2026-06-competitiveness.md)
36
+ * for the upstream-first distribution play.
37
+ */
38
+ import { type CapabilityManifest, type ToolRegistry, type WasmKernel } from "@wasmagent/core";
39
+ import { z } from "zod";
40
+ /**
41
+ * Structural type matching `@openai/agents` `Tool<T>` exactly. The two
42
+ * peer-versions of `@openai/agents` we expect to see in the wild
43
+ * (0.1.x and forthcoming 0.2.x) keep this shape; we type it
44
+ * structurally so we are not pinned to a specific major.
45
+ */
46
+ export interface OpenAiAgentTool<TIn, TOut> {
47
+ name: string;
48
+ description: string;
49
+ parameters: z.ZodType<TIn>;
50
+ execute(input: TIn): Promise<TOut>;
51
+ }
52
+ export interface SandboxedJsAgentToolOptions {
53
+ /** Tool name surfaced to the model. Default: `sandboxed_js`. */
54
+ name?: string;
55
+ /** Override the tool description shown to the model. */
56
+ description?: string;
57
+ /**
58
+ * Kernel that runs the snippet. Use `QuickJSKernel` for edge-safe
59
+ * execution on Workers / Vercel Edge; `JsKernel` for Node-only quick
60
+ * prototypes; `RemoteSandboxKernel` (E2B / Cloudflare Sandbox) for
61
+ * full process isolation.
62
+ */
63
+ kernel: WasmKernel;
64
+ /** Optional capability allow-list; defaults to deny-all. */
65
+ capabilities?: Partial<CapabilityManifest>;
66
+ }
67
+ /**
68
+ * One-shot sandboxed JS execution as an OpenAI Agents tool.
69
+ * Mirrors `sandboxedJsTool()` from `@wasmagent/aisdk` field-for-field;
70
+ * only the surface (`OpenAiAgentTool` vs Vercel AI SDK's `tool()`)
71
+ * differs.
72
+ */
73
+ export declare function sandboxedJsAgentTool(opts: SandboxedJsAgentToolOptions): OpenAiAgentTool<{
74
+ code: string;
75
+ }, {
76
+ output: unknown;
77
+ logs: string[];
78
+ }>;
79
+ export interface CodeModeAgentToolOptions extends SandboxedJsAgentToolOptions {
80
+ /**
81
+ * Tools the snippet may invoke via `callTool(name, args)`. Mirrors
82
+ * the registry passed to `createCodeModeServer` in the MCP server
83
+ * package and the `tools` field on the AI SDK / Claude adapters.
84
+ */
85
+ tools: ToolRegistry;
86
+ }
87
+ /**
88
+ * Code-mode OpenAI Agents tool: collapses N user-defined tools into a
89
+ * single `execute_code` entry point on the model side. The model sees
90
+ * this one tool; inside, the script can call any of the registered
91
+ * tools and chain them without re-entering the model context for each
92
+ * step. See
93
+ * [`examples/benchmarks/code-mode-tokens.mjs`](../../examples/benchmarks/code-mode-tokens.mjs)
94
+ * for the token-savings benchmark (≤14% of direct-tool-use at N=30).
95
+ */
96
+ export declare function codeModeAgentTool(opts: CodeModeAgentToolOptions): OpenAiAgentTool<{
97
+ code: string;
98
+ }, {
99
+ output: string;
100
+ toolCallCount: number;
101
+ }>;
102
+ export type { MemoryToolOptions } from "./memory.js";
103
+ export { memoryAgentTool, ObservationalMemory } from "./memory.js";
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EACL,KAAK,kBAAkB,EAEvB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,GAAG,EAAE,IAAI;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAaD,MAAM,WAAW,2BAA2B;IAC1C,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,EAAE,UAAU,CAAC;IACnB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,2BAA2B,GAChC,eAAe,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAcxE;AAcD,MAAM,WAAW,wBAAyB,SAAQ,2BAA2B;IAC3E;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,wBAAwB,GAC7B,eAAe,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CA0B9E;AAED,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @wasmagent/openai-agents — agentkit kernels as OpenAI Agents JS tools.
3
+ *
4
+ * The OpenAI Agents JS SDK (`@openai/agents`) accepts a `Tool`-shaped
5
+ * definition: `{ name, description, parameters (Zod), execute(input) }`.
6
+ * Functionally identical to Vercel AI SDK's `tool()` shape with field
7
+ * renaming. Rather than ask consumers to reach for a different package
8
+ * for each upstream, we ship a thin adapter that produces the
9
+ * structurally-typed tool object and lets them drop it into
10
+ * `agent({ tools: […] })` directly.
11
+ *
12
+ * - {@link sandboxedJsAgentTool} — one-shot JS evaluator. The agent
13
+ * calls it; the kernel runs the snippet; output is `{ output, logs }`.
14
+ *
15
+ * - {@link codeModeAgentTool} — code-mode tool. The agent emits a
16
+ * snippet that may call `callTool(name, args)` against any
17
+ * registered downstream tool; only the script's final return value
18
+ * re-enters the model context.
19
+ *
20
+ * Both honour the unified `CapabilityManifest` (allowedHosts /
21
+ * allowedReadPaths / allowedWritePaths / env / cpuMs /
22
+ * memoryLimitBytes), so a security policy you wrote for the MCP server
23
+ * works here verbatim — see
24
+ * [`docs/strategy/security-face.md`](../../docs/strategy/security-face.md).
25
+ *
26
+ * Peer-dep: `@openai/agents` >= 0.1 (declared optional so unit tests
27
+ * can run without it). The package only emits the tool's shape; it
28
+ * does not import `@openai/agents` at runtime.
29
+ *
30
+ * Why a separate package from `@wasmagent/aisdk`: although the AI
31
+ * SDK and OpenAI Agents JS shapes are nearly identical, version
32
+ * matrices and bundle expectations differ. Keeping them apart lets
33
+ * upstream documentation in each ecosystem link to the package that
34
+ * matches *their* idiom — see
35
+ * [`docs/strategy/2026-06-competitiveness.md`](../../docs/strategy/2026-06-competitiveness.md)
36
+ * for the upstream-first distribution play.
37
+ */
38
+ import { ProgrammaticOrchestrator, } from "@wasmagent/core";
39
+ import { z } from "zod";
40
+ // ── sandboxedJsAgentTool ─────────────────────────────────────────────────────
41
+ const sandboxedJsInput = z.object({
42
+ code: z
43
+ .string()
44
+ .describe("JavaScript expression or block. The value of the final expression " +
45
+ "(or the value assigned to `__finalAnswer__`) is returned."),
46
+ });
47
+ /**
48
+ * One-shot sandboxed JS execution as an OpenAI Agents tool.
49
+ * Mirrors `sandboxedJsTool()` from `@wasmagent/aisdk` field-for-field;
50
+ * only the surface (`OpenAiAgentTool` vs Vercel AI SDK's `tool()`)
51
+ * differs.
52
+ */
53
+ export function sandboxedJsAgentTool(opts) {
54
+ return {
55
+ name: opts.name ?? "sandboxed_js",
56
+ description: opts.description ??
57
+ "Run a JavaScript snippet inside a sandbox. Use for arithmetic, JSON " +
58
+ "manipulation, or short scripts the user asks for. Cannot reach the host " +
59
+ "machine — network and FS access are gated by capability.",
60
+ parameters: sandboxedJsInput,
61
+ async execute({ code }) {
62
+ const result = await opts.kernel.run(code, opts.capabilities);
63
+ return { output: result.output, logs: result.logs };
64
+ },
65
+ };
66
+ }
67
+ // ── codeModeAgentTool ────────────────────────────────────────────────────────
68
+ const codeModeInput = z.object({
69
+ code: z
70
+ .string()
71
+ .describe("JavaScript snippet. May call `callTool(name, args)` against any " +
72
+ "registered downstream tool. Return the final value (or assign to " +
73
+ "`__finalAnswer__`); intermediate tool outputs are discarded."),
74
+ });
75
+ /**
76
+ * Code-mode OpenAI Agents tool: collapses N user-defined tools into a
77
+ * single `execute_code` entry point on the model side. The model sees
78
+ * this one tool; inside, the script can call any of the registered
79
+ * tools and chain them without re-entering the model context for each
80
+ * step. See
81
+ * [`examples/benchmarks/code-mode-tokens.mjs`](../../examples/benchmarks/code-mode-tokens.mjs)
82
+ * for the token-savings benchmark (≤14% of direct-tool-use at N=30).
83
+ */
84
+ export function codeModeAgentTool(opts) {
85
+ return {
86
+ name: opts.name ?? "execute_code",
87
+ description: opts.description ??
88
+ "Run a JavaScript snippet that orchestrates multiple downstream tools " +
89
+ "via `callTool(name, args)`. Use this when one task needs more than 2-3 " +
90
+ "tool calls — chaining them in code is dramatically faster than " +
91
+ "separate tool rounds and saves tokens.",
92
+ parameters: codeModeInput,
93
+ async execute({ code }) {
94
+ const orchestrator = new ProgrammaticOrchestrator(opts.kernel, opts.tools, opts.capabilities ?? {});
95
+ const result = await orchestrator.run(code);
96
+ return {
97
+ output: typeof result.finalOutput === "string"
98
+ ? result.finalOutput
99
+ : JSON.stringify(result.finalOutput),
100
+ toolCallCount: result.toolCallCount,
101
+ };
102
+ },
103
+ };
104
+ }
105
+ // ── D3 (2026-06-13): cross-framework memory product surface ─────────────────
106
+ export { memoryAgentTool, ObservationalMemory } from "./memory.js";
107
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAEL,wBAAwB,GAGzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB,gFAAgF;AAEhF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,QAAQ,CACP,oEAAoE;QAClE,2DAA2D,CAC9D;CACJ,CAAC,CAAC;AAkBH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAiC;IAEjC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,cAAc;QACjC,WAAW,EACT,IAAI,CAAC,WAAW;YAChB,sEAAsE;gBACpE,0EAA0E;gBAC1E,0DAA0D;QAC9D,UAAU,EAAE,gBAAgB;QAC5B,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE;YACpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACtD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,gFAAgF;AAEhF,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,QAAQ,CACP,kEAAkE;QAChE,mEAAmE;QACnE,8DAA8D,CACjE;CACJ,CAAC,CAAC;AAWH;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAA8B;IAE9B,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,cAAc;QACjC,WAAW,EACT,IAAI,CAAC,WAAW;YAChB,uEAAuE;gBACrE,yEAAyE;gBACzE,iEAAiE;gBACjE,wCAAwC;QAC5C,UAAU,EAAE,aAAa;QACzB,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE;YACpB,MAAM,YAAY,GAAG,IAAI,wBAAwB,CAC/C,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,YAAY,IAAI,EAAE,CACxB,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO;gBACL,MAAM,EACJ,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ;oBACpC,CAAC,CAAC,MAAM,CAAC,WAAW;oBACpB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;gBACxC,aAAa,EAAE,MAAM,CAAC,aAAa;aACpC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,+EAA+E;AAC/E,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @wasmagent/openai-agents — Memory tool adapter (D3, 2026-06-13).
3
+ *
4
+ * Exposes agentkit's `createMemoryTool` (cross-session KV-backed memory)
5
+ * as an OpenAI Agents JS Tool.
6
+ *
7
+ * See `@wasmagent/aisdk/memory` for the rationale (D3 cross-framework
8
+ * memory product surface).
9
+ */
10
+ import { type MemoryToolOptions } from "@wasmagent/core";
11
+ import type { OpenAiAgentTool } from "./index.js";
12
+ export declare function memoryAgentTool(opts: MemoryToolOptions): OpenAiAgentTool<unknown, string>;
13
+ export { ObservationalMemory } from "@wasmagent/core";
14
+ export type { MemoryToolOptions };
15
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAUzF;AAED,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
package/dist/memory.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @wasmagent/openai-agents — Memory tool adapter (D3, 2026-06-13).
3
+ *
4
+ * Exposes agentkit's `createMemoryTool` (cross-session KV-backed memory)
5
+ * as an OpenAI Agents JS Tool.
6
+ *
7
+ * See `@wasmagent/aisdk/memory` for the rationale (D3 cross-framework
8
+ * memory product surface).
9
+ */
10
+ import { createMemoryTool as createMemoryToolCore, } from "@wasmagent/core";
11
+ export function memoryAgentTool(opts) {
12
+ const core = createMemoryToolCore(opts);
13
+ return {
14
+ name: "memory",
15
+ description: core.description,
16
+ parameters: core.inputSchema,
17
+ async execute(input) {
18
+ return core.forward(input);
19
+ },
20
+ };
21
+ }
22
+ export { ObservationalMemory } from "@wasmagent/core";
23
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,gBAAgB,IAAI,oBAAoB,GAEzC,MAAM,iBAAiB,CAAC;AAKzB,MAAM,UAAU,eAAe,CAAC,IAAuB;IACrD,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,WAAiC;QAClD,KAAK,CAAC,OAAO,CAAC,KAAK;YACjB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAc,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@wasmagent/openai-agents",
3
+ "version": "0.1.0",
4
+ "description": "Drop wasmagent sandbox kernels into the OpenAI Agents JS SDK as a Tool — edge-safe code execution with one capability manifest, no E2B sandbox needed",
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
+ "@wasmagent/core": "workspace:*"
22
+ },
23
+ "peerDependencies": {
24
+ "@openai/agents": ">=0.1.0",
25
+ "zod": "^3.22.0 || ^4.0.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "@openai/agents": {
29
+ "optional": true
30
+ },
31
+ "zod": {
32
+ "optional": false
33
+ }
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.0.0",
37
+ "typescript": "^5.7.0",
38
+ "vitest": "^2.1.0",
39
+ "zod": "^3.22.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=20.0.0"
43
+ },
44
+ "keywords": [
45
+ "openai",
46
+ "agents",
47
+ "agent",
48
+ "sandbox",
49
+ "code-execution",
50
+ "tool",
51
+ "wasmagent"
52
+ ],
53
+ "license": "Apache-2.0",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/WasmAgent/wasmagent-js.git",
57
+ "directory": "packages/openai-agents"
58
+ },
59
+ "homepage": "https://github.com/WasmAgent/wasmagent-js/tree/main/packages/openai-agents#readme",
60
+ "bugs": {
61
+ "url": "https://github.com/WasmAgent/wasmagent-js/issues"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public",
65
+ "provenance": false
66
+ },
67
+ "files": [
68
+ "dist",
69
+ "LICENSE",
70
+ "README.md"
71
+ ],
72
+ "author": "wasmagent contributors"
73
+ }