@cloudflare/codemode 0.0.5 → 0.0.7
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 +23 -0
- package/README.md +3 -0
- package/dist/ai.d.ts +2 -1
- package/dist/ai.js +10 -10
- package/dist/ai.js.map +1 -1
- package/package.json +4 -4
- package/scripts/build.ts +2 -2
- package/src/ai.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @cloudflare/codemode
|
|
2
2
|
|
|
3
|
+
## 0.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#849](https://github.com/cloudflare/agents/pull/849) [`21a7977`](https://github.com/cloudflare/agents/commit/21a79778f5150aecd890f55a164d397f70db681e) Thanks [@Muhammad-Bin-Ali](https://github.com/Muhammad-Bin-Ali)! - Allow configurable model in `experimental_codemode` instead of hardcoded `gpt-4.1`
|
|
8
|
+
|
|
9
|
+
- [#859](https://github.com/cloudflare/agents/pull/859) [`3de98a3`](https://github.com/cloudflare/agents/commit/3de98a398d55aeca51c7b845ed4c5d6051887d6d) Thanks [@threepointone](https://github.com/threepointone)! - broaden peer deps
|
|
10
|
+
|
|
11
|
+
- [#865](https://github.com/cloudflare/agents/pull/865) [`c3211d0`](https://github.com/cloudflare/agents/commit/c3211d0b0cc36aa294c15569ae650d3afeab9926) Thanks [@threepointone](https://github.com/threepointone)! - update dependencies
|
|
12
|
+
|
|
13
|
+
## 0.0.6
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#813](https://github.com/cloudflare/agents/pull/813) [`7aebab3`](https://github.com/cloudflare/agents/commit/7aebab369d1bef6c685e05a4a3bd6627edcb87db) Thanks [@threepointone](https://github.com/threepointone)! - update dependencies
|
|
18
|
+
|
|
19
|
+
- [#800](https://github.com/cloudflare/agents/pull/800) [`a54edf5`](https://github.com/cloudflare/agents/commit/a54edf56b462856d1ef4f424c2363ac43a53c46e) Thanks [@threepointone](https://github.com/threepointone)! - Update dependencies
|
|
20
|
+
|
|
21
|
+
- [#818](https://github.com/cloudflare/agents/pull/818) [`7c74336`](https://github.com/cloudflare/agents/commit/7c743360d7e3639e187725391b9d5c114838bd18) Thanks [@threepointone](https://github.com/threepointone)! - update dependencies
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`0c3c9bb`](https://github.com/cloudflare/agents/commit/0c3c9bb62ceff66ed38d3bbd90c767600f1f3453), [`0c3c9bb`](https://github.com/cloudflare/agents/commit/0c3c9bb62ceff66ed38d3bbd90c767600f1f3453), [`d1a0c2b`](https://github.com/cloudflare/agents/commit/d1a0c2b73b1119d71e120091753a6bcca0e2faa9), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`fd79481`](https://github.com/cloudflare/agents/commit/fd7948180abf066fa3d27911a83ffb4c91b3f099), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`0c3c9bb`](https://github.com/cloudflare/agents/commit/0c3c9bb62ceff66ed38d3bbd90c767600f1f3453), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`e20da53`](https://github.com/cloudflare/agents/commit/e20da5319eb46bac6ac580edf71836b00ac6f8bb), [`f604008`](https://github.com/cloudflare/agents/commit/f604008957f136241815909319a552bad6738b58), [`7aebab3`](https://github.com/cloudflare/agents/commit/7aebab369d1bef6c685e05a4a3bd6627edcb87db), [`a54edf5`](https://github.com/cloudflare/agents/commit/a54edf56b462856d1ef4f424c2363ac43a53c46e), [`7c74336`](https://github.com/cloudflare/agents/commit/7c743360d7e3639e187725391b9d5c114838bd18), [`6218541`](https://github.com/cloudflare/agents/commit/6218541e9c1e40ccbaa25b2d9d93858c0ad81ffa), [`ded8d3e`](https://github.com/cloudflare/agents/commit/ded8d3e8aeba0358ebd4aecb5ba15344b5a21db1)]:
|
|
24
|
+
- agents@0.3.7
|
|
25
|
+
|
|
3
26
|
## 0.0.5
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ const tools = {
|
|
|
87
87
|
|
|
88
88
|
// Configure Code Mode
|
|
89
89
|
const { prompt, tools: wrappedTools } = await codemode({
|
|
90
|
+
model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
|
|
90
91
|
prompt: "You are a helpful assistant...",
|
|
91
92
|
tools,
|
|
92
93
|
globalOutbound: env.globalOutbound,
|
|
@@ -156,6 +157,7 @@ export class CodeModeAgent extends Agent<Env> {
|
|
|
156
157
|
};
|
|
157
158
|
|
|
158
159
|
const { prompt, tools: wrappedTools } = await codemode({
|
|
160
|
+
model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
|
|
159
161
|
prompt: "You are a helpful assistant...",
|
|
160
162
|
tools: allTools,
|
|
161
163
|
globalOutbound: env.globalOutbound,
|
|
@@ -293,6 +295,7 @@ Wraps your tools with Code Mode, converting them into a single code-generating t
|
|
|
293
295
|
- `globalOutbound: Fetcher` - Service binding for network access control
|
|
294
296
|
- `loader: WorkerLoader` - Worker Loader binding for code execution
|
|
295
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")`)
|
|
296
299
|
|
|
297
300
|
**Returns:**
|
|
298
301
|
|
package/dist/ai.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolSet } from "ai";
|
|
1
|
+
import { LanguageModel, ToolSet } from "ai";
|
|
2
2
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
3
3
|
|
|
4
4
|
//#region src/ai.d.ts
|
|
@@ -21,6 +21,7 @@ declare function experimental_codemode(options: {
|
|
|
21
21
|
globalOutbound: Fetcher;
|
|
22
22
|
loader: WorkerLoader;
|
|
23
23
|
proxy: Fetcher<CodeModeProxy>;
|
|
24
|
+
model?: LanguageModel;
|
|
24
25
|
}): Promise<{
|
|
25
26
|
prompt: string;
|
|
26
27
|
tools: ToolSet;
|
package/dist/ai.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { generateObject, tool } from "ai";
|
|
2
|
-
import { openai } from "@ai-sdk/openai";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { compile } from "json-schema-to-typescript";
|
|
5
4
|
import { createTypeAlias, printNode, zodToTs } from "zod-to-ts";
|
|
6
5
|
import { getAgentByName } from "agents";
|
|
7
6
|
import { WorkerEntrypoint, env } from "cloudflare:workers";
|
|
7
|
+
import { openai } from "@ai-sdk/openai";
|
|
8
8
|
|
|
9
9
|
//#region src/ai.ts
|
|
10
10
|
function toCamelCase(str) {
|
|
@@ -36,7 +36,7 @@ async function experimental_codemode(options) {
|
|
|
36
36
|
execute: async ({ functionDescription }) => {
|
|
37
37
|
try {
|
|
38
38
|
const response = await generateObject({
|
|
39
|
-
model: openai("gpt-4.1"),
|
|
39
|
+
model: options.model ? options.model : openai("gpt-4.1"),
|
|
40
40
|
schema: z.object({ code: z.string() }),
|
|
41
41
|
prompt: `You are a code generating machine.
|
|
42
42
|
|
|
@@ -114,20 +114,20 @@ export default class CodeModeWorker extends WorkerEntrypoint {
|
|
|
114
114
|
async function generateTypes(tools) {
|
|
115
115
|
let availableTools = "";
|
|
116
116
|
let availableTypes = "";
|
|
117
|
-
for (const [toolName, tool
|
|
118
|
-
const inputJsonType = tool
|
|
117
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
118
|
+
const inputJsonType = tool.inputSchema.jsonSchema ? await compile(tool.inputSchema.jsonSchema, `${toCamelCase(toolName)}Input`, {
|
|
119
119
|
format: false,
|
|
120
120
|
bannerComment: " "
|
|
121
|
-
}) : printNode(createTypeAlias(zodToTs(tool
|
|
122
|
-
const outputJsonType = tool
|
|
121
|
+
}) : printNode(createTypeAlias(zodToTs(tool.inputSchema, `${toCamelCase(toolName)}Input`).node, `${toCamelCase(toolName)}Input`));
|
|
122
|
+
const outputJsonType = tool.outputSchema?.jsonSchema ? await compile(tool.outputSchema?.jsonSchema, `${toCamelCase(toolName)}Output`, {
|
|
123
123
|
format: false,
|
|
124
124
|
bannerComment: " "
|
|
125
|
-
}) : tool
|
|
125
|
+
}) : tool.outputSchema ? printNode(createTypeAlias(zodToTs(tool.outputSchema, `${toCamelCase(toolName)}Output`).node, `${toCamelCase(toolName)}Output`)) : `interface ${toCamelCase(toolName)}Output { [key: string]: any }`;
|
|
126
126
|
const InputType = inputJsonType.trim().replace("export interface", "interface");
|
|
127
127
|
const OutputType = outputJsonType.trim().replace("export interface", "interface");
|
|
128
128
|
availableTypes += `\n${InputType}`;
|
|
129
129
|
availableTypes += `\n${OutputType}`;
|
|
130
|
-
availableTools += `\n\t/*\n\t${tool
|
|
130
|
+
availableTools += `\n\t/*\n\t${tool.description?.trim()}\n\t*/`;
|
|
131
131
|
availableTools += `\n\t${toolName}: (input: ${toCamelCase(toolName)}Input) => Promise<${toCamelCase(toolName)}Output>;`;
|
|
132
132
|
availableTools += "\n";
|
|
133
133
|
}
|
|
@@ -138,8 +138,8 @@ ${availableTools}
|
|
|
138
138
|
`;
|
|
139
139
|
}
|
|
140
140
|
function getToolDescriptions(tools) {
|
|
141
|
-
return Object.entries(tools).map(([_toolName, tool
|
|
142
|
-
return `\n- ${tool
|
|
141
|
+
return Object.entries(tools).map(([_toolName, tool]) => {
|
|
142
|
+
return `\n- ${tool.description?.trim()}`;
|
|
143
143
|
}).join("");
|
|
144
144
|
}
|
|
145
145
|
|
package/dist/ai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.js","names":["
|
|
1
|
+
{"version":3,"file":"ai.js","names":["compileJsonSchemaToTs","printNodeZodToTs"],"sources":["../src/ai.ts"],"sourcesContent":["import { generateObject, tool, type ToolSet, type LanguageModel } from \"ai\";\nimport { z } from \"zod\";\nimport { compile as compileJsonSchemaToTs } from \"json-schema-to-typescript\";\nimport {\n zodToTs,\n printNode as printNodeZodToTs,\n createTypeAlias\n} from \"zod-to-ts\";\nimport { getAgentByName } from \"agents\";\nimport { env, WorkerEntrypoint } from \"cloudflare:workers\";\nimport { openai } from \"@ai-sdk/openai\";\n\nfunction toCamelCase(str: string) {\n return str\n .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())\n .replace(/^[a-z]/, (letter) => letter.toUpperCase());\n}\n\nexport class CodeModeProxy extends WorkerEntrypoint<\n Cloudflare.Env,\n {\n binding: string;\n name: string;\n callback: string;\n }\n> {\n async callFunction(options: { functionName: string; args: unknown[] }) {\n const stub = (await getAgentByName(\n // @ts-expect-error\n env[this.ctx.props.binding] as DurableObjectNamespace<T>,\n this.ctx.props.name\n )) as DurableObjectStub;\n // @ts-expect-error\n return stub[this.ctx.props.callback](options.functionName, options.args);\n }\n}\n\nexport async function experimental_codemode(options: {\n tools: ToolSet;\n prompt: string;\n globalOutbound: Fetcher;\n loader: WorkerLoader;\n proxy: Fetcher<CodeModeProxy>;\n model?: LanguageModel;\n}): Promise<{\n prompt: string;\n tools: ToolSet;\n}> {\n const generatedTypes = await generateTypes(options.tools);\n const prompt = `${options.prompt}\n You are a helpful assistant. You have access to the \"codemode\" tool that can do different things: \n \n ${getToolDescriptions(options.tools)} \n \n If the user asks to do anything that be achieveable by the codemode tool, then simply pass over control to it by giving it a simple function description. Don't be too verbose.\n \n `;\n\n const codemodeTool = tool({\n description: \"codemode: a tool that can generate code to achieve a goal\",\n inputSchema: z.object({\n functionDescription: z.string()\n }),\n outputSchema: z.object({\n code: z.string(),\n result: z.any()\n }),\n execute: async ({ functionDescription }) => {\n try {\n const response = await generateObject({\n model: options.model ? options.model : openai(\"gpt-4.1\"),\n schema: z.object({\n code: z.string()\n }),\n prompt: `You are a code generating machine.\n\n In addition to regular javascript, you can also use the following functions:\n\n ${generatedTypes} \n\n Respond only with the code, nothing else. Output javascript code.\n\n Generate an async function that achieves the goal. This async function doesn't accept any arguments.\n\n Here is user input: ${functionDescription}` // insert ts types for the tools here\n });\n\n // console.log(\"args\", response.object.args);\n const evaluator = createEvaluator(response.object.code, {\n proxy: options.proxy,\n loader: options.loader\n });\n const result = await evaluator();\n return { code: response.object.code, result: result };\n } catch (error) {\n console.error(\"error\", error);\n throw error;\n // return { code: \"\", result: error };\n }\n }\n });\n\n return { prompt, tools: { codemode: codemodeTool } };\n}\n\nfunction createEvaluator(\n code: string,\n options: {\n loader: WorkerLoader;\n proxy: Fetcher<CodeModeProxy>;\n }\n) {\n return async () => {\n const worker = options.loader.get(`code-${Math.random()}`, () => {\n return {\n compatibilityDate: \"2025-06-01\",\n compatibilityFlags: [\"nodejs_compat\"],\n mainModule: \"foo.js\",\n modules: {\n \"foo.js\": `\nimport { env, WorkerEntrypoint } from \"cloudflare:workers\";\n\nexport default class CodeModeWorker extends WorkerEntrypoint {\n async evaluate() {\n try {\n const { CodeModeProxy } = env;\n const codemode = new Proxy(\n {},\n {\n get: (target, prop) => {\n return (args) => {\n return CodeModeProxy.callFunction({\n functionName: prop,\n args: args, \n });\n };\n }\n }\n );\n\n return await ${code}();\n } catch (err) {\n return {\n err: err.message,\n stack: err.stack\n };\n }\n }\n}\n \n `\n },\n env: {\n // insert keys and bindings to tools/ts functions here\n CodeModeProxy: options.proxy\n },\n globalOutbound: null\n };\n });\n\n // @ts-expect-error TODO: fix this\n return await worker.getEntrypoint().evaluate();\n };\n}\n\nasync function generateTypes(tools: ToolSet) {\n let availableTools = \"\";\n let availableTypes = \"\";\n\n for (const [toolName, tool] of Object.entries(tools)) {\n // @ts-expect-error TODO: fix this\n const inputJsonType = tool.inputSchema.jsonSchema\n ? await compileJsonSchemaToTs(\n // @ts-expect-error TODO: fix this\n tool.inputSchema.jsonSchema,\n `${toCamelCase(toolName)}Input`,\n {\n format: false,\n bannerComment: \" \"\n }\n )\n : printNodeZodToTs(\n createTypeAlias(\n zodToTs(\n // @ts-expect-error TODO: fix this\n tool.inputSchema,\n `${toCamelCase(toolName)}Input`\n ).node,\n `${toCamelCase(toolName)}Input`\n )\n );\n\n const outputJsonType =\n // @ts-expect-error TODO: fix this\n tool.outputSchema?.jsonSchema\n ? await compileJsonSchemaToTs(\n // @ts-expect-error TODO: fix this\n tool.outputSchema?.jsonSchema,\n `${toCamelCase(toolName)}Output`,\n {\n format: false,\n bannerComment: \" \"\n }\n )\n : tool.outputSchema\n ? printNodeZodToTs(\n createTypeAlias(\n zodToTs(\n // @ts-expect-error TODO: fix this\n tool.outputSchema,\n `${toCamelCase(toolName)}Output`\n ).node,\n `${toCamelCase(toolName)}Output`\n )\n )\n : `interface ${toCamelCase(toolName)}Output { [key: string]: any }`;\n\n const InputType = inputJsonType\n .trim()\n .replace(\"export interface\", \"interface\");\n\n const OutputType = outputJsonType\n .trim()\n .replace(\"export interface\", \"interface\");\n\n availableTypes += `\\n${InputType}`;\n availableTypes += `\\n${OutputType}`;\n availableTools += `\\n\\t/*\\n\\t${tool.description?.trim()}\\n\\t*/`;\n availableTools += `\\n\\t${toolName}: (input: ${toCamelCase(toolName)}Input) => Promise<${toCamelCase(toolName)}Output>;`;\n availableTools += \"\\n\";\n }\n\n availableTools = `\\ndeclare const codemode: {${availableTools}}`;\n\n return `\n${availableTypes}\n${availableTools}\n `;\n}\n\nfunction getToolDescriptions(tools: ToolSet) {\n return Object.entries(tools)\n .map(([_toolName, tool]) => {\n return `\\n- ${tool.description?.trim()}`;\n })\n .join(\"\");\n}\n"],"mappings":";;;;;;;;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G,oBAAkB;;AAGpB,kBAAiB,8BAA8B,eAAe;AAE9D,QAAO;EACP,eAAe;EACf,eAAe;;;AAIjB,SAAS,oBAAoB,OAAgB;AAC3C,QAAO,OAAO,QAAQ,MAAM,CACzB,KAAK,CAAC,WAAW,UAAU;AAC1B,SAAO,OAAO,KAAK,aAAa,MAAM;GACtC,CACD,KAAK,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/codemode",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Code Mode: use LLMs to generate executable code that performs tool calls",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/codemode",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"zod-to-ts": "^2.0.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"ai": "^6.0.
|
|
18
|
-
"zod": "^4.3.
|
|
17
|
+
"ai": "^6.0.77",
|
|
18
|
+
"zod": "^4.3.6"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"agents": "^0.
|
|
21
|
+
"agents": "^0.4.0",
|
|
22
22
|
"ai": "^6.0.0",
|
|
23
23
|
"zod": "^3.25.0 || ^4.0.0"
|
|
24
24
|
},
|
package/scripts/build.ts
CHANGED
|
@@ -13,8 +13,8 @@ async function main() {
|
|
|
13
13
|
fixedExtension: false
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
// then run
|
|
17
|
-
execSync("
|
|
16
|
+
// then run oxfmt on the generated .d.ts files
|
|
17
|
+
execSync("oxfmt --write ./dist/*.d.ts");
|
|
18
18
|
|
|
19
19
|
process.exit(0);
|
|
20
20
|
}
|
package/src/ai.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { generateObject, tool, type ToolSet } from "ai";
|
|
2
|
-
import { openai } from "@ai-sdk/openai";
|
|
1
|
+
import { generateObject, tool, type ToolSet, type LanguageModel } from "ai";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { compile as compileJsonSchemaToTs } from "json-schema-to-typescript";
|
|
5
4
|
import {
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
} from "zod-to-ts";
|
|
10
9
|
import { getAgentByName } from "agents";
|
|
11
10
|
import { env, WorkerEntrypoint } from "cloudflare:workers";
|
|
11
|
+
import { openai } from "@ai-sdk/openai";
|
|
12
12
|
|
|
13
13
|
function toCamelCase(str: string) {
|
|
14
14
|
return str
|
|
@@ -41,6 +41,7 @@ export async function experimental_codemode(options: {
|
|
|
41
41
|
globalOutbound: Fetcher;
|
|
42
42
|
loader: WorkerLoader;
|
|
43
43
|
proxy: Fetcher<CodeModeProxy>;
|
|
44
|
+
model?: LanguageModel;
|
|
44
45
|
}): Promise<{
|
|
45
46
|
prompt: string;
|
|
46
47
|
tools: ToolSet;
|
|
@@ -67,7 +68,7 @@ export async function experimental_codemode(options: {
|
|
|
67
68
|
execute: async ({ functionDescription }) => {
|
|
68
69
|
try {
|
|
69
70
|
const response = await generateObject({
|
|
70
|
-
model: openai("gpt-4.1"),
|
|
71
|
+
model: options.model ? options.model : openai("gpt-4.1"),
|
|
71
72
|
schema: z.object({
|
|
72
73
|
code: z.string()
|
|
73
74
|
}),
|