@cloudflare/codemode 0.0.7 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @cloudflare/codemode
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#879](https://github.com/cloudflare/agents/pull/879) [`90e54da`](https://github.com/cloudflare/agents/commit/90e54dab21f7c2c783aac117693918765e8b254b) Thanks [@mattzcarey](https://github.com/mattzcarey)! - Remove experimental_codemode() and CodeModeProxy. Replace with createCodeTool() from @cloudflare/codemode/ai which returns a standard AI SDK Tool. The package no longer owns an LLM call or model choice. Users call streamText/generateText with their own model and pass the codemode tool.
8
+
9
+ The AI-dependent export (createCodeTool) is now at @cloudflare/codemode/ai. The root export (@cloudflare/codemode) contains the executor, type generation, and utilities which do not require the ai peer dependency.
10
+
11
+ ToolDispatcher (extends RpcTarget) replaces CodeModeProxy (extends WorkerEntrypoint) for dispatching tool calls from the sandbox back to the host. It is passed as a parameter to the dynamic worker's evaluate() method instead of being injected as an env binding, removing the need for CodeModeProxy and globalOutbound service bindings. Only a WorkerLoader binding is required now. globalOutbound on DynamicWorkerExecutor defaults to null which blocks fetch/connect at the runtime level. New Executor interface (execute(code, fns) => ExecuteResult) allows custom sandbox implementations. DynamicWorkerExecutor is the Cloudflare Workers implementation. Console output captured in ExecuteResult.logs. Configurable execution timeout.
12
+
13
+ AST-based code normalization via acorn replaces regex. sanitizeToolName() exported for converting MCP-style tool names to valid JS identifiers.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#954](https://github.com/cloudflare/agents/pull/954) [`943c407`](https://github.com/cloudflare/agents/commit/943c4070992bb836625abb5bf4e3271a6f52f7a2) Thanks [@threepointone](https://github.com/threepointone)! - update dependencies
18
+
19
+ ## 0.0.8
20
+
21
+ ### Patch Changes
22
+
23
+ - [#916](https://github.com/cloudflare/agents/pull/916) [`24e16e0`](https://github.com/cloudflare/agents/commit/24e16e025b82dbd7b321339a18c6d440b2879136) Thanks [@threepointone](https://github.com/threepointone)! - Widen peer dependency ranges across packages to prevent cascading major bumps during 0.x minor releases. Mark `@cloudflare/ai-chat` and `@cloudflare/codemode` as optional peer dependencies of `agents` to fix unmet peer dependency warnings during installation.
24
+
3
25
  ## 0.0.7
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -1,75 +1,33 @@
1
- ### 💻 `@cloudflare/codemode` - Code Mode: The Better Way to Use MCP
1
+ # `@cloudflare/codemode`
2
2
 
3
- Instead of asking LLMs to call tools directly, Code Mode lets them write executable code that orchestrates multiple operations. **LLMs are better at writing code than calling tools** - they've seen millions of lines of real-world TypeScript but only contrived tool-calling examples.
3
+ Instead of asking LLMs to call tools directly, Code Mode lets them write executable code that orchestrates multiple operations. LLMs are better at writing code than calling tools they've seen millions of lines of real-world TypeScript but only contrived tool-calling examples.
4
4
 
5
- Code Mode converts your tools (especially MCP servers) into TypeScript APIs, enabling complex workflows, error handling, and multi-step operations that are natural in code but difficult with traditional tool calling.
5
+ Code Mode converts your tools into TypeScript APIs and executes the generated code in secure, isolated sandboxes with millisecond startup times.
6
6
 
7
- Built on Cloudflare's Worker Loader API, Code Mode executes generated code in secure, isolated sandboxes with millisecond startup times.
7
+ > **Experimental** may have breaking changes. Use with caution in production.
8
8
 
9
- > **⚠️ Experimental Feature**: Code Mode is currently experimental and may have breaking changes in future releases. Use with caution in production environments.
10
-
11
- ---
12
-
13
- ### 🌱 Installation
9
+ ## Installation
14
10
 
15
11
  ```sh
16
- npm install @cloudflare/codemode agents ai
12
+ npm install @cloudflare/codemode agents ai zod
17
13
  ```
18
14
 
19
- ### 📝 Your First Code Mode Agent
20
-
21
- Transform your tool-calling agent into a code-generating one:
15
+ ## Quick Start
22
16
 
23
- #### Before (Traditional Tool Calling)
17
+ `createCodeTool` takes your tools and an executor, and returns a single AI SDK tool that lets the LLM write code instead of making individual tool calls.
24
18
 
25
19
  ```ts
26
- import { streamText } from "ai";
27
- import { tool } from "ai";
20
+ import { createCodeTool } from "@cloudflare/codemode/ai";
21
+ import { DynamicWorkerExecutor } from "@cloudflare/codemode";
22
+ import { streamText, tool } from "ai";
28
23
  import { z } from "zod";
29
24
 
30
- const result = streamText({
31
- model: openai("gpt-4o"),
32
- messages,
33
- tools: {
34
- getWeather: tool({
35
- description: "Get weather for a location",
36
- inputSchema: z.object({ location: z.string() }),
37
- execute: async ({ location }) => {
38
- return `Weather in ${location}: 72°F, sunny`;
39
- }
40
- }),
41
- sendEmail: tool({
42
- description: "Send an email",
43
- inputSchema: z.object({
44
- to: z.string(),
45
- subject: z.string(),
46
- body: z.string()
47
- }),
48
- execute: async ({ to, subject, body }) => {
49
- // Send email logic
50
- return `Email sent to ${to}`;
51
- }
52
- })
53
- }
54
- });
55
- ```
56
-
57
- #### After (With Code Mode)
58
-
59
- ```ts
60
- import { experimental_codemode as codemode } from "@cloudflare/codemode/ai";
61
- import { streamText } from "ai";
62
- import { tool } from "ai";
63
- import { z } from "zod";
64
-
65
- // Define your tools as usual
25
+ // 1. Define your tools using the AI SDK tool() wrapper
66
26
  const tools = {
67
27
  getWeather: tool({
68
28
  description: "Get weather for a location",
69
29
  inputSchema: z.object({ location: z.string() }),
70
- execute: async ({ location }) => {
71
- return `Weather in ${location}: 72°F, sunny`;
72
- }
30
+ execute: async ({ location }) => `Weather in ${location}: 72°F, sunny`
73
31
  }),
74
32
  sendEmail: tool({
75
33
  description: "Send an email",
@@ -78,259 +36,228 @@ const tools = {
78
36
  subject: z.string(),
79
37
  body: z.string()
80
38
  }),
81
- execute: async ({ to, subject, body }) => {
82
- // Send email logic
83
- return `Email sent to ${to}`;
84
- }
39
+ execute: async ({ to, subject, body }) => `Email sent to ${to}`
85
40
  })
86
41
  };
87
42
 
88
- // Configure Code Mode
89
- const { prompt, tools: wrappedTools } = await codemode({
90
- model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
91
- prompt: "You are a helpful assistant...",
92
- tools,
93
- globalOutbound: env.globalOutbound,
94
- loader: env.LOADER,
95
- proxy: this.ctx.exports.CodeModeProxy({
96
- props: {
97
- binding: "MyAgent",
98
- name: this.name,
99
- callback: "callTool"
100
- }
101
- })
43
+ // 2. Create an executor (runs code in an isolated Worker)
44
+ const executor = new DynamicWorkerExecutor({
45
+ loader: env.LOADER
102
46
  });
103
47
 
104
- // Use the wrapped tools - now the LLM will generate code instead!
48
+ // 3. Create the codemode tool
49
+ const codemode = createCodeTool({ tools, executor });
50
+
51
+ // 4. Use it with streamText — the LLM writes code that calls your tools
105
52
  const result = streamText({
106
- model: openai("gpt-4o"),
107
- system: prompt,
53
+ model,
54
+ system: "You are a helpful assistant.",
108
55
  messages,
109
- tools: wrappedTools // Single "codemode" tool that generates code
56
+ tools: { codemode }
110
57
  });
111
58
  ```
112
59
 
113
- That's it! Your agent now generates executable code that orchestrates your tools.
114
-
115
- ### 🏰 Configuration
116
-
117
- Define the required bindings in your `wrangler.toml`:
60
+ The LLM sees a typed `codemode` object and writes code like:
118
61
 
119
- ```jsonc
120
- {
121
- "compatibility_flags": ["experimental", "enable_ctx_exports"],
122
- "worker_loaders": [
123
- {
124
- "binding": "LOADER"
125
- }
126
- ],
127
- "services": [
128
- {
129
- "binding": "globalOutbound",
130
- "service": "your-service",
131
- "entrypoint": "globalOutbound"
132
- },
133
- {
134
- "binding": "CodeModeProxy",
135
- "service": "your-service",
136
- "entrypoint": "CodeModeProxy"
137
- }
138
- ]
139
- }
62
+ ```js
63
+ async () => {
64
+ const weather = await codemode.getWeather({ location: "London" });
65
+ if (weather.includes("sunny")) {
66
+ await codemode.sendEmail({
67
+ to: "team@example.com",
68
+ subject: "Nice day!",
69
+ body: `It's ${weather}`
70
+ });
71
+ }
72
+ return { weather, notified: true };
73
+ };
140
74
  ```
141
75
 
142
- ### 🎭 Agent Integration
76
+ ## Architecture
143
77
 
144
- #### With MCP Servers
78
+ ### How it works
145
79
 
146
- ```ts
147
- import { Agent } from "agents";
148
- import { experimental_codemode as codemode } from "@cloudflare/codemode/ai";
149
- import { streamText, convertToModelMessages } from "ai";
150
- import { openai } from "@ai-sdk/openai";
80
+ ```
81
+ ┌─────────────┐ ┌──────────────────────────────────────┐
82
+ │ │ │ Dynamic Worker (isolated sandbox) │
83
+ │ Host │ RPC │ │
84
+ │ Worker │◄──────►│ LLM-generated code runs here │
85
+ │ │ │ codemode.myTool() → dispatcher.call()│
86
+ │ ToolDispatcher │ │
87
+ │ holds tool fns │ fetch() blocked by default │
88
+ └─────────────┘ └──────────────────────────────────────┘
89
+ ```
151
90
 
152
- export class CodeModeAgent extends Agent<Env> {
153
- async onChatMessage() {
154
- const allTools = {
155
- ...regularTools,
156
- ...this.mcp.getAITools() // Include MCP tools
157
- };
158
-
159
- const { prompt, tools: wrappedTools } = await codemode({
160
- model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
161
- prompt: "You are a helpful assistant...",
162
- tools: allTools,
163
- globalOutbound: env.globalOutbound,
164
- loader: env.LOADER,
165
- proxy: this.ctx.exports.CodeModeProxy({
166
- props: {
167
- binding: "CodeModeAgent",
168
- name: this.name,
169
- callback: "callTool"
170
- }
171
- })
172
- });
91
+ 1. `createCodeTool` generates TypeScript type definitions from your tools and builds a description the LLM can read
92
+ 2. The LLM writes an async arrow function that calls `codemode.toolName(args)`
93
+ 3. Code is normalized via AST parsing (acorn) and sent to the executor
94
+ 4. `DynamicWorkerExecutor` spins up an isolated Worker via `WorkerLoader`
95
+ 5. Inside the sandbox, a `Proxy` intercepts `codemode.*` calls and routes them back to the host via Workers RPC (`ToolDispatcher extends RpcTarget`)
96
+ 6. Console output is captured and returned alongside the result
173
97
 
174
- const result = streamText({
175
- model: openai("gpt-4o"),
176
- system: prompt,
177
- messages: await convertToModelMessages(this.messages),
178
- tools: wrappedTools
179
- });
98
+ ### Network isolation
180
99
 
181
- return result.toUIMessageStreamResponse();
182
- }
100
+ External `fetch()` and `connect()` are **blocked by default** — enforced at the Workers runtime level via `globalOutbound: null`. Sandboxed code can only interact with the host through `codemode.*` tool calls.
183
101
 
184
- callTool(functionName: string, args: unknown[]) {
185
- return this.tools[functionName]?.execute?.(args, {
186
- abortSignal: new AbortController().signal,
187
- toolCallId: "codemode",
188
- messages: []
189
- });
190
- }
191
- }
102
+ To allow controlled outbound access, pass a `Fetcher`:
192
103
 
193
- export { CodeModeProxy } from "@cloudflare/codemode/ai";
104
+ ```ts
105
+ const executor = new DynamicWorkerExecutor({
106
+ loader: env.LOADER,
107
+ globalOutbound: null // default — fully isolated
108
+ // globalOutbound: env.MY_OUTBOUND_SERVICE, // route through a Fetcher
109
+ });
194
110
  ```
195
111
 
196
- ### 🌊 Generated Code Example
197
-
198
- Code Mode enables complex workflows that chain multiple operations:
112
+ ## The Executor Interface
199
113
 
200
- ```javascript
201
- // Example generated code orchestrating multiple MCP servers:
202
- async function executeTask() {
203
- const files = await codemode.listFiles({ path: "/projects" });
204
- const recentProject = files
205
- .filter((f) => f.type === "directory")
206
- .sort((a, b) => new Date(b.modified) - new Date(a.modified))[0];
114
+ The `Executor` interface is deliberately minimal — implement it to run code in any sandbox:
207
115
 
208
- const projectStatus = await codemode.queryDatabase({
209
- query: "SELECT * FROM projects WHERE name = ?",
210
- params: [recentProject.name]
211
- });
212
-
213
- if (projectStatus.length === 0 || projectStatus[0].status === "incomplete") {
214
- await codemode.createTask({
215
- title: `Review project: ${recentProject.name}`,
216
- priority: "high"
217
- });
218
- await codemode.sendEmail({
219
- to: "team@company.com",
220
- subject: "Project Review Needed"
221
- });
222
- }
116
+ ```ts
117
+ interface Executor {
118
+ execute(
119
+ code: string,
120
+ fns: Record<string, (...args: unknown[]) => Promise<unknown>>
121
+ ): Promise<ExecuteResult>;
122
+ }
223
123
 
224
- return { success: true, project: recentProject };
124
+ interface ExecuteResult {
125
+ result: unknown;
126
+ error?: string;
127
+ logs?: string[];
225
128
  }
226
129
  ```
227
130
 
228
- ### 🔒 Security
229
-
230
- Code runs in isolated Workers with millisecond startup times. No network access by default - only through explicit bindings. API keys are hidden in bindings, preventing leaks.
131
+ `DynamicWorkerExecutor` is the Cloudflare Workers implementation, but you can build your own for Node VM, QuickJS, containers, or anything else.
231
132
 
232
133
  ```ts
233
- export const globalOutbound = {
234
- fetch: async (input: string | URL | RequestInfo, init?: RequestInit) => {
235
- const url = new URL(typeof input === "string" ? input : input.toString());
236
- if (url.hostname === "example.com") {
237
- return new Response("Not allowed", { status: 403 });
134
+ // Example: a simple Node VM executor
135
+ class NodeVMExecutor implements Executor {
136
+ async execute(code, fns): Promise<ExecuteResult> {
137
+ try {
138
+ const fn = new AsyncFunction("codemode", `return await (${code})()`);
139
+ const result = await fn(fns);
140
+ return { result };
141
+ } catch (err) {
142
+ return { result: undefined, error: err.message };
238
143
  }
239
- return fetch(input, init);
240
144
  }
241
- };
145
+ }
242
146
  ```
243
147
 
244
- ### 🔧 Setup
148
+ ## Configuration
245
149
 
246
- **Required bindings:**
150
+ ### Wrangler bindings
247
151
 
248
- - `LOADER`: Worker Loader for code execution
249
- - `globalOutbound`: Service for network access control
250
- - `CodeModeProxy`: Service for tool execution proxy
152
+ ```jsonc
153
+ // wrangler.jsonc
154
+ {
155
+ "worker_loaders": [{ "binding": "LOADER" }],
156
+ "compatibility_flags": ["nodejs_compat"]
157
+ }
158
+ ```
251
159
 
252
- **Environment:**
160
+ ### DynamicWorkerExecutor options
253
161
 
254
- ```ts
255
- export const globalOutbound = {
256
- fetch: async (input: string | URL | RequestInfo, init?: RequestInit) => {
257
- // Your security policies
258
- return fetch(input, init);
259
- }
260
- };
162
+ | Option | Type | Default | Description |
163
+ | ---------------- | ----------------- | -------- | ------------------------------------------------------------ |
164
+ | `loader` | `WorkerLoader` | required | Worker Loader binding from `env.LOADER` |
165
+ | `timeout` | `number` | `30000` | Execution timeout in ms |
166
+ | `globalOutbound` | `Fetcher \| null` | `null` | Network access control. `null` = blocked, `Fetcher` = routed |
261
167
 
262
- export { CodeModeProxy } from "@cloudflare/codemode/ai";
263
- ```
168
+ ### createCodeTool options
264
169
 
265
- **Proxy configuration:**
170
+ | Option | Type | Default | Description |
171
+ | ------------- | ---------------------------- | -------------- | ------------------------------------------------------ |
172
+ | `tools` | `ToolSet \| ToolDescriptors` | required | Your tools (AI SDK `tool()` or raw descriptors) |
173
+ | `executor` | `Executor` | required | Where to run the generated code |
174
+ | `description` | `string` | auto-generated | Custom tool description. Use `{{types}}` for type defs |
266
175
 
267
- ```ts
268
- proxy: this.ctx.exports.CodeModeProxy({
269
- props: {
270
- binding: "YourAgentClass",
271
- name: this.name,
272
- callback: "callTool"
273
- }
274
- });
275
- ```
176
+ ## Agent Integration
276
177
 
277
- ### 🎯 Real-World Examples
178
+ The user sends a message, the agent passes it to an LLM with the codemode tool, and the LLM writes and executes code to fulfill the request.
278
179
 
279
- Explore these examples to see Code Mode in action:
180
+ ```ts
181
+ import { Agent } from "agents";
182
+ import { createCodeTool } from "@cloudflare/codemode/ai";
183
+ import { DynamicWorkerExecutor } from "@cloudflare/codemode";
184
+ import { streamText, convertToModelMessages, stepCountIs } from "ai";
280
185
 
281
- - **Complete Demo**: [`examples/codemode/`](../../examples/codemode/) - Full working example with MCP integration
282
- - **Documentation**: [`docs/codemode.md`](../../docs/codemode.md) - Detailed guide and examples
283
- - **Blog Post**: [Code Mode: the better way to use MCP](https://blog.cloudflare.com/code-mode/) - Deep dive into the philosophy and implementation
186
+ export class MyAgent extends Agent<Env, State> {
187
+ async onChatMessage() {
188
+ const executor = new DynamicWorkerExecutor({
189
+ loader: this.env.LOADER
190
+ });
191
+
192
+ const codemode = createCodeTool({
193
+ tools: myTools,
194
+ executor
195
+ });
284
196
 
285
- ### 📚 API Reference
197
+ const result = streamText({
198
+ model,
199
+ system: "You are a helpful assistant.",
200
+ messages: await convertToModelMessages(this.state.messages),
201
+ tools: { codemode },
202
+ stopWhen: stepCountIs(10)
203
+ });
286
204
 
287
- #### `experimental_codemode(options)`
205
+ // Stream response back to client...
206
+ }
207
+ }
208
+ ```
288
209
 
289
- Wraps your tools with Code Mode, converting them into a single code-generating tool.
210
+ ### With MCP tools
290
211
 
291
- **Options:**
212
+ MCP tools work the same way — just merge them into the tool set:
292
213
 
293
- - `tools: ToolSet` - Your tool definitions (including MCP tools)
294
- - `prompt: string` - System prompt for the LLM
295
- - `globalOutbound: Fetcher` - Service binding for network access control
296
- - `loader: WorkerLoader` - Worker Loader binding for code execution
297
- - `proxy: Fetcher<CodeModeProxy>` - Proxy binding for tool execution
298
- - `model?: LanguageModel` - The language model to use for code generation (optional, defaults to `openai("gpt-4.1")`)
214
+ ```ts
215
+ const codemode = createCodeTool({
216
+ tools: {
217
+ ...myTools,
218
+ ...this.mcp.getAITools()
219
+ },
220
+ executor
221
+ });
222
+ ```
299
223
 
300
- **Returns:**
224
+ ## Utilities
301
225
 
302
- - `prompt: string` - Enhanced system prompt
303
- - `tools: ToolSet` - Wrapped tools (single "codemode" tool)
226
+ ### `generateTypes(tools)`
304
227
 
305
- #### `CodeModeProxy`
228
+ Generates TypeScript type definitions from your tools. Used internally by `createCodeTool` but exported for custom use (e.g. displaying types in a frontend).
306
229
 
307
- Worker entrypoint that routes tool calls back to your agent.
230
+ ```ts
231
+ import { generateTypes } from "@cloudflare/codemode";
308
232
 
309
- **Props:**
233
+ const types = generateTypes(myTools);
234
+ // Returns TypeScript declarations like:
235
+ // type CreateProjectInput = { name: string; description?: string }
236
+ // declare const codemode: { createProject: (input: CreateProjectInput) => Promise<...>; }
237
+ ```
310
238
 
311
- - `binding: string` - Your agent class name
312
- - `name: string` - Agent instance name
313
- - `callback: string` - Method name to call for tool execution
239
+ ### `sanitizeToolName(name)`
314
240
 
315
- ### 🔗 Integration
241
+ Converts tool names into valid JavaScript identifiers. Handles hyphens, dots, digits, reserved words.
316
242
 
317
- `@cloudflare/codemode` integrates with the [`agents`](../agents/) framework and works with any agent that extends `Agent`, including MCP server integration via `Agent.mcp`.
243
+ ```ts
244
+ import { sanitizeToolName } from "@cloudflare/codemode";
318
245
 
319
- ### 🚀 Limitations
246
+ sanitizeToolName("my-tool"); // "my_tool"
247
+ sanitizeToolName("3d-render"); // "_3d_render"
248
+ sanitizeToolName("delete"); // "delete_"
249
+ ```
320
250
 
321
- - **Experimental**: Subject to breaking changes
322
- - **Requires Cloudflare Workers**: Uses Worker Loader API (beta)
323
- - **JavaScript Only**: Python support planned
251
+ ## Limitations
324
252
 
325
- ### Contributing
253
+ - **Tool approval (`needsApproval`) is not supported yet.** Tools with `needsApproval: true` execute immediately inside the sandbox without pausing for approval. Support for approval flows within codemode is planned. For now, do not pass approval-required tools to `createCodeTool` — use them through standard AI SDK tool calling instead.
254
+ - Requires Cloudflare Workers environment for `DynamicWorkerExecutor`
255
+ - Limited to JavaScript execution
326
256
 
327
- Contributions are welcome! Please:
257
+ ## Examples
328
258
 
329
- 1. Open an issue to discuss your proposal
330
- 2. Ensure your changes align with the package's goals
331
- 3. Include tests for new features
332
- 4. Update documentation as needed
259
+ - [`examples/codemode/`](../../examples/codemode/) Full working example with task management tools
333
260
 
334
- ### License
261
+ ## License
335
262
 
336
- MIT licensed. See the LICENSE file at the root of this repository for details.
263
+ MIT
package/dist/ai.d.ts CHANGED
@@ -1,31 +1,31 @@
1
- import { LanguageModel, ToolSet } from "ai";
2
- import { WorkerEntrypoint } from "cloudflare:workers";
1
+ import { i as Executor, s as ToolDescriptors } from "./executor-Czw9jKZH.js";
2
+ import { Tool, ToolSet } from "ai";
3
+ import { z } from "zod";
3
4
 
4
- //#region src/ai.d.ts
5
- declare class CodeModeProxy extends WorkerEntrypoint<
6
- Cloudflare.Env,
7
- {
8
- binding: string;
9
- name: string;
10
- callback: string;
11
- }
12
- > {
13
- callFunction(options: {
14
- functionName: string;
15
- args: unknown[];
16
- }): Promise<any>;
5
+ //#region src/tool.d.ts
6
+ interface CreateCodeToolOptions {
7
+ tools: ToolDescriptors | ToolSet;
8
+ executor: Executor;
9
+ /**
10
+ * Custom tool description. Use {{types}} as a placeholder for the generated type definitions.
11
+ */
12
+ description?: string;
17
13
  }
18
- declare function experimental_codemode(options: {
19
- tools: ToolSet;
20
- prompt: string;
21
- globalOutbound: Fetcher;
22
- loader: WorkerLoader;
23
- proxy: Fetcher<CodeModeProxy>;
24
- model?: LanguageModel;
25
- }): Promise<{
26
- prompt: string;
27
- tools: ToolSet;
28
- }>;
14
+ declare const codeSchema: z.ZodObject<
15
+ {
16
+ code: z.ZodString;
17
+ },
18
+ z.core.$strip
19
+ >;
20
+ type CodeInput = z.infer<typeof codeSchema>;
21
+ type CodeOutput = {
22
+ code: string;
23
+ result: unknown;
24
+ logs?: string[];
25
+ };
26
+ declare function createCodeTool(
27
+ options: CreateCodeToolOptions
28
+ ): Tool<CodeInput, CodeOutput>;
29
29
  //#endregion
30
- export { CodeModeProxy, experimental_codemode };
30
+ export { type CreateCodeToolOptions, createCodeTool };
31
31
  //# sourceMappingURL=ai.d.ts.map