@cloudflare/codemode 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +2 -2
- package/dist/ai.js +13 -4
- package/dist/ai.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types-CpkEgXwN.js +392 -0
- package/dist/types-CpkEgXwN.js.map +1 -0
- package/package.json +2 -2
- package/src/tests/schema-conversion.test.ts +1068 -0
- package/src/tests/types.test.ts +275 -0
- package/src/tool.ts +25 -4
- package/src/types.ts +527 -52
- package/dist/types-B9g5T2nd.js +0 -138
- package/dist/types-B9g5T2nd.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @cloudflare/codemode
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#962](https://github.com/cloudflare/agents/pull/962) [`ef46d68`](https://github.com/cloudflare/agents/commit/ef46d68e9c381b7541c4aa803014144abce4fb72) Thanks [@tumberger](https://github.com/tumberger)! - Validate tool arguments against Zod schema before execution in codemode sandbox
|
|
8
|
+
|
|
9
|
+
- [#973](https://github.com/cloudflare/agents/pull/973) [`969fbff`](https://github.com/cloudflare/agents/commit/969fbff702d5702c1f0ea6faaecb3dfd0431a01b) Thanks [@threepointone](https://github.com/threepointone)! - Update dependencies
|
|
10
|
+
|
|
11
|
+
- [#960](https://github.com/cloudflare/agents/pull/960) [`179b8cb`](https://github.com/cloudflare/agents/commit/179b8cbc60bc9e6ac0d2ee26c430d842950f5f08) Thanks [@mattzcarey](https://github.com/mattzcarey)! - Harden JSON Schema to TypeScript converter for production use
|
|
12
|
+
- Add depth and circular reference guards to prevent stack overflows on recursive or deeply nested schemas
|
|
13
|
+
- Add `$ref` resolution for internal JSON Pointers (`#/definitions/...`, `#/$defs/...`, `#`)
|
|
14
|
+
- Add tuple support (`prefixItems` for JSON Schema 2020-12, array `items` for draft-07)
|
|
15
|
+
- Add OpenAPI 3.0 `nullable: true` support across all schema branches
|
|
16
|
+
- Fix string escaping in enum/const values, property names (control chars, U+2028/U+2029), and JSDoc comments (`*/`)
|
|
17
|
+
- Add per-tool error isolation in `generateTypes()` so one malformed schema cannot crash the pipeline
|
|
18
|
+
- Guard missing `inputSchema` in `getAITools()` with a fallback to `{ type: "object" }`
|
|
19
|
+
- Add per-tool error isolation in `getAITools()` so one bad MCP tool does not break the entire tool set
|
|
20
|
+
|
|
21
|
+
- [#961](https://github.com/cloudflare/agents/pull/961) [`f6aa79f`](https://github.com/cloudflare/agents/commit/f6aa79f3bf86922db73b4d33439262aefcbcf817) Thanks [@mattzcarey](https://github.com/mattzcarey)! - Updated default tool prompt to explicitly request JavaScript code from LLMs, preventing TypeScript syntax errors in the Dynamic Worker executor.
|
|
22
|
+
|
|
3
23
|
## 0.1.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
|
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 code but only contrived tool-calling examples.
|
|
4
4
|
|
|
5
|
-
Code Mode
|
|
5
|
+
Code Mode generates TypeScript type definitions from your tools for LLM context, and executes the generated JavaScript in secure, isolated sandboxes with millisecond startup times.
|
|
6
6
|
|
|
7
7
|
> **Experimental** — may have breaking changes. Use with caution in production.
|
|
8
8
|
|
package/dist/ai.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as sanitizeToolName, t as generateTypes } from "./types-
|
|
2
|
-
import { tool } from "ai";
|
|
1
|
+
import { n as sanitizeToolName, t as generateTypes } from "./types-CpkEgXwN.js";
|
|
2
|
+
import { asSchema, tool } from "ai";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import * as acorn from "acorn";
|
|
5
5
|
|
|
@@ -9,7 +9,8 @@ const DEFAULT_DESCRIPTION = `Execute code to achieve a goal.
|
|
|
9
9
|
Available:
|
|
10
10
|
{{types}}
|
|
11
11
|
|
|
12
|
-
Write an async arrow function that returns the result.
|
|
12
|
+
Write an async arrow function in JavaScript that returns the result.
|
|
13
|
+
Do NOT use TypeScript syntax — no type annotations, interfaces, or generics.
|
|
13
14
|
Do NOT define named functions then call them — just write the arrow function body directly.
|
|
14
15
|
|
|
15
16
|
Example: async () => { const r = await codemode.searchWeb({ query: "test" }); return r; }`;
|
|
@@ -56,7 +57,15 @@ function createCodeTool(options) {
|
|
|
56
57
|
const fns = {};
|
|
57
58
|
for (const [name, t] of Object.entries(tools)) {
|
|
58
59
|
const execute = "execute" in t ? t.execute : void 0;
|
|
59
|
-
if (execute)
|
|
60
|
+
if (execute) {
|
|
61
|
+
const rawSchema = "inputSchema" in t ? t.inputSchema : "parameters" in t ? t.parameters : void 0;
|
|
62
|
+
const schema = rawSchema != null ? asSchema(rawSchema) : void 0;
|
|
63
|
+
fns[sanitizeToolName(name)] = schema?.validate ? async (args) => {
|
|
64
|
+
const result = await schema.validate(args);
|
|
65
|
+
if (!result.success) throw result.error;
|
|
66
|
+
return execute(result.value);
|
|
67
|
+
} : execute;
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
const normalizedCode = normalizeCode(code);
|
|
62
71
|
const executeResult = await executor.execute(normalizedCode, fns);
|
package/dist/ai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.js","names":[],"sources":["../src/tool.ts"],"sourcesContent":["import { tool, type Tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport * as acorn from \"acorn\";\nimport { generateTypes, sanitizeToolName, type ToolDescriptors } from \"./types\";\nimport type { Executor } from \"./executor\";\n\nconst DEFAULT_DESCRIPTION = `Execute code to achieve a goal.\n\nAvailable:\n{{types}}\n\nWrite an async arrow function that returns the result.\nDo NOT define named functions then call them — just write the arrow function body directly.\n\nExample: async () => { const r = await codemode.searchWeb({ query: \"test\" }); return r; }`;\n\nexport interface CreateCodeToolOptions {\n tools: ToolDescriptors | ToolSet;\n executor: Executor;\n /**\n * Custom tool description. Use {{types}} as a placeholder for the generated type definitions.\n */\n description?: string;\n}\n\nconst codeSchema = z.object({\n code: z.string().describe(\"JavaScript async arrow function to execute\")\n});\n\ntype CodeInput = z.infer<typeof codeSchema>;\ntype CodeOutput = { code: string; result: unknown; logs?: string[] };\n\nfunction normalizeCode(code: string): string {\n const trimmed = code.trim();\n if (!trimmed) return \"async () => {}\";\n\n try {\n const ast = acorn.parse(trimmed, {\n ecmaVersion: \"latest\",\n sourceType: \"module\"\n });\n\n // Already an arrow function — pass through\n if (ast.body.length === 1 && ast.body[0].type === \"ExpressionStatement\") {\n const expr = (ast.body[0] as acorn.ExpressionStatement).expression;\n if (expr.type === \"ArrowFunctionExpression\") return trimmed;\n }\n\n // Last statement is expression → splice in return\n const last = ast.body[ast.body.length - 1];\n if (last?.type === \"ExpressionStatement\") {\n const exprStmt = last as acorn.ExpressionStatement;\n const before = trimmed.slice(0, last.start);\n const exprText = trimmed.slice(\n exprStmt.expression.start,\n exprStmt.expression.end\n );\n return `async () => {\\n${before}return (${exprText})\\n}`;\n }\n\n return `async () => {\\n${trimmed}\\n}`;\n } catch {\n return `async () => {\\n${trimmed}\\n}`;\n }\n}\n\n/**\n * Create a codemode tool that allows LLMs to write and execute code\n * with access to your tools in a sandboxed environment.\n *\n * Returns an AI SDK compatible tool.\n */\nfunction hasNeedsApproval(t: Record<string, unknown>): boolean {\n return \"needsApproval\" in t && t.needsApproval != null;\n}\n\nexport function createCodeTool(\n options: CreateCodeToolOptions\n): Tool<CodeInput, CodeOutput> {\n const tools: ToolDescriptors | ToolSet = {};\n for (const [name, t] of Object.entries(options.tools)) {\n if (!hasNeedsApproval(t as Record<string, unknown>)) {\n (tools as Record<string, unknown>)[name] = t;\n }\n }\n\n const types = generateTypes(tools);\n const executor = options.executor;\n\n const description = (options.description ?? DEFAULT_DESCRIPTION).replace(\n \"{{types}}\",\n types\n );\n\n return tool({\n description,\n inputSchema: codeSchema,\n execute: async ({ code }) => {\n // Extract execute functions from tools, keyed by name\n const fns: Record<string, (...args: unknown[]) => Promise<unknown>> = {};\n\n for (const [name, t] of Object.entries(tools)) {\n const execute =\n \"execute\" in t\n ? (t.execute as (args: unknown) => Promise<unknown>)\n : undefined;\n if (execute) {\n fns[sanitizeToolName(name)] = execute;\n }\n }\n\n const normalizedCode = normalizeCode(code);\n\n const executeResult = await executor.execute(normalizedCode, fns);\n\n if (executeResult.error) {\n const logCtx = executeResult.logs?.length\n ? `\\n\\nConsole output:\\n${executeResult.logs.join(\"\\n\")}`\n : \"\";\n throw new Error(\n `Code execution failed: ${executeResult.error}${logCtx}`\n );\n }\n\n const output: CodeOutput = { code, result: executeResult.result };\n if (executeResult.logs) output.logs = executeResult.logs;\n return output;\n }\n });\n}\n"],"mappings":";;;;;;AAOA,MAAM,sBAAsB
|
|
1
|
+
{"version":3,"file":"ai.js","names":[],"sources":["../src/tool.ts"],"sourcesContent":["import { tool, type Tool, asSchema } from \"ai\";\nimport { z } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport * as acorn from \"acorn\";\nimport { generateTypes, sanitizeToolName, type ToolDescriptors } from \"./types\";\nimport type { Executor } from \"./executor\";\n\nconst DEFAULT_DESCRIPTION = `Execute code to achieve a goal.\n\nAvailable:\n{{types}}\n\nWrite an async arrow function in JavaScript that returns the result.\nDo NOT use TypeScript syntax — no type annotations, interfaces, or generics.\nDo NOT define named functions then call them — just write the arrow function body directly.\n\nExample: async () => { const r = await codemode.searchWeb({ query: \"test\" }); return r; }`;\n\nexport interface CreateCodeToolOptions {\n tools: ToolDescriptors | ToolSet;\n executor: Executor;\n /**\n * Custom tool description. Use {{types}} as a placeholder for the generated type definitions.\n */\n description?: string;\n}\n\nconst codeSchema = z.object({\n code: z.string().describe(\"JavaScript async arrow function to execute\")\n});\n\ntype CodeInput = z.infer<typeof codeSchema>;\ntype CodeOutput = { code: string; result: unknown; logs?: string[] };\n\nfunction normalizeCode(code: string): string {\n const trimmed = code.trim();\n if (!trimmed) return \"async () => {}\";\n\n try {\n const ast = acorn.parse(trimmed, {\n ecmaVersion: \"latest\",\n sourceType: \"module\"\n });\n\n // Already an arrow function — pass through\n if (ast.body.length === 1 && ast.body[0].type === \"ExpressionStatement\") {\n const expr = (ast.body[0] as acorn.ExpressionStatement).expression;\n if (expr.type === \"ArrowFunctionExpression\") return trimmed;\n }\n\n // Last statement is expression → splice in return\n const last = ast.body[ast.body.length - 1];\n if (last?.type === \"ExpressionStatement\") {\n const exprStmt = last as acorn.ExpressionStatement;\n const before = trimmed.slice(0, last.start);\n const exprText = trimmed.slice(\n exprStmt.expression.start,\n exprStmt.expression.end\n );\n return `async () => {\\n${before}return (${exprText})\\n}`;\n }\n\n return `async () => {\\n${trimmed}\\n}`;\n } catch {\n return `async () => {\\n${trimmed}\\n}`;\n }\n}\n\n/**\n * Create a codemode tool that allows LLMs to write and execute code\n * with access to your tools in a sandboxed environment.\n *\n * Returns an AI SDK compatible tool.\n */\nfunction hasNeedsApproval(t: Record<string, unknown>): boolean {\n return \"needsApproval\" in t && t.needsApproval != null;\n}\n\nexport function createCodeTool(\n options: CreateCodeToolOptions\n): Tool<CodeInput, CodeOutput> {\n const tools: ToolDescriptors | ToolSet = {};\n for (const [name, t] of Object.entries(options.tools)) {\n if (!hasNeedsApproval(t as Record<string, unknown>)) {\n (tools as Record<string, unknown>)[name] = t;\n }\n }\n\n const types = generateTypes(tools);\n const executor = options.executor;\n\n const description = (options.description ?? DEFAULT_DESCRIPTION).replace(\n \"{{types}}\",\n types\n );\n\n return tool({\n description,\n inputSchema: codeSchema,\n execute: async ({ code }) => {\n // Extract execute functions from tools, keyed by name.\n // Wrap each with its schema so arguments from the sandbox\n // are validated before reaching the tool function.\n const fns: Record<string, (...args: unknown[]) => Promise<unknown>> = {};\n\n for (const [name, t] of Object.entries(tools)) {\n const execute =\n \"execute\" in t\n ? (t.execute as (args: unknown) => Promise<unknown>)\n : undefined;\n if (execute) {\n const rawSchema =\n \"inputSchema\" in t\n ? t.inputSchema\n : \"parameters\" in t\n ? (t as Record<string, unknown>).parameters\n : undefined;\n\n // Use AI SDK's asSchema() to normalize any schema type\n // (Zod v3/v4, Standard Schema, JSON Schema) into a unified\n // Schema with an optional .validate() method.\n const schema = rawSchema != null ? asSchema(rawSchema) : undefined;\n\n fns[sanitizeToolName(name)] = schema?.validate\n ? async (args: unknown) => {\n const result = await schema.validate!(args);\n if (!result.success) throw result.error;\n return execute(result.value);\n }\n : execute;\n }\n }\n\n const normalizedCode = normalizeCode(code);\n\n const executeResult = await executor.execute(normalizedCode, fns);\n\n if (executeResult.error) {\n const logCtx = executeResult.logs?.length\n ? `\\n\\nConsole output:\\n${executeResult.logs.join(\"\\n\")}`\n : \"\";\n throw new Error(\n `Code execution failed: ${executeResult.error}${logCtx}`\n );\n }\n\n const output: CodeOutput = { code, result: executeResult.result };\n if (executeResult.logs) output.logs = executeResult.logs;\n return output;\n }\n });\n}\n"],"mappings":";;;;;;AAOA,MAAM,sBAAsB;;;;;;;;;;AAoB5B,MAAM,aAAa,EAAE,OAAO,EAC1B,MAAM,EAAE,QAAQ,CAAC,SAAS,6CAA6C,EACxE,CAAC;AAKF,SAAS,cAAc,MAAsB;CAC3C,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AAErB,KAAI;EACF,MAAM,MAAM,MAAM,MAAM,SAAS;GAC/B,aAAa;GACb,YAAY;GACb,CAAC;AAGF,MAAI,IAAI,KAAK,WAAW,KAAK,IAAI,KAAK,GAAG,SAAS,uBAEhD;OADc,IAAI,KAAK,GAAiC,WAC/C,SAAS,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SAAS,QAAQ,gBAAgB,IAAI;AAEjE,OAAI,cAAc,OAAO;IACvB,MAAM,SAAS,cAAc,MAAM,SAC/B,wBAAwB,cAAc,KAAK,KAAK,KAAK,KACrD;AACJ,UAAM,IAAI,MACR,0BAA0B,cAAc,QAAQ,SACjD;;GAGH,MAAM,SAAqB;IAAE;IAAM,QAAQ,cAAc;IAAQ;AACjE,OAAI,cAAc,KAAM,QAAO,OAAO,cAAc;AACpD,UAAO;;EAEV,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { createAuxiliaryTypeStore, createTypeAlias, printNode, zodToTs } from "zod-to-ts";
|
|
2
|
+
|
|
3
|
+
//#region src/types.ts
|
|
4
|
+
const JS_RESERVED = new Set([
|
|
5
|
+
"abstract",
|
|
6
|
+
"arguments",
|
|
7
|
+
"await",
|
|
8
|
+
"boolean",
|
|
9
|
+
"break",
|
|
10
|
+
"byte",
|
|
11
|
+
"case",
|
|
12
|
+
"catch",
|
|
13
|
+
"char",
|
|
14
|
+
"class",
|
|
15
|
+
"const",
|
|
16
|
+
"continue",
|
|
17
|
+
"debugger",
|
|
18
|
+
"default",
|
|
19
|
+
"delete",
|
|
20
|
+
"do",
|
|
21
|
+
"double",
|
|
22
|
+
"else",
|
|
23
|
+
"enum",
|
|
24
|
+
"eval",
|
|
25
|
+
"export",
|
|
26
|
+
"extends",
|
|
27
|
+
"false",
|
|
28
|
+
"final",
|
|
29
|
+
"finally",
|
|
30
|
+
"float",
|
|
31
|
+
"for",
|
|
32
|
+
"function",
|
|
33
|
+
"goto",
|
|
34
|
+
"if",
|
|
35
|
+
"implements",
|
|
36
|
+
"import",
|
|
37
|
+
"in",
|
|
38
|
+
"instanceof",
|
|
39
|
+
"int",
|
|
40
|
+
"interface",
|
|
41
|
+
"let",
|
|
42
|
+
"long",
|
|
43
|
+
"native",
|
|
44
|
+
"new",
|
|
45
|
+
"null",
|
|
46
|
+
"package",
|
|
47
|
+
"private",
|
|
48
|
+
"protected",
|
|
49
|
+
"public",
|
|
50
|
+
"return",
|
|
51
|
+
"short",
|
|
52
|
+
"static",
|
|
53
|
+
"super",
|
|
54
|
+
"switch",
|
|
55
|
+
"synchronized",
|
|
56
|
+
"this",
|
|
57
|
+
"throw",
|
|
58
|
+
"throws",
|
|
59
|
+
"transient",
|
|
60
|
+
"true",
|
|
61
|
+
"try",
|
|
62
|
+
"typeof",
|
|
63
|
+
"undefined",
|
|
64
|
+
"var",
|
|
65
|
+
"void",
|
|
66
|
+
"volatile",
|
|
67
|
+
"while",
|
|
68
|
+
"with",
|
|
69
|
+
"yield"
|
|
70
|
+
]);
|
|
71
|
+
/**
|
|
72
|
+
* Sanitize a tool name into a valid JavaScript identifier.
|
|
73
|
+
* Replaces hyphens, dots, and spaces with `_`, strips other invalid chars,
|
|
74
|
+
* prefixes digit-leading names with `_`, and appends `_` to JS reserved words.
|
|
75
|
+
*/
|
|
76
|
+
function sanitizeToolName(name) {
|
|
77
|
+
if (!name) return "_";
|
|
78
|
+
let sanitized = name.replace(/[-.\s]/g, "_");
|
|
79
|
+
sanitized = sanitized.replace(/[^a-zA-Z0-9_$]/g, "");
|
|
80
|
+
if (!sanitized) return "_";
|
|
81
|
+
if (/^[0-9]/.test(sanitized)) sanitized = "_" + sanitized;
|
|
82
|
+
if (JS_RESERVED.has(sanitized)) sanitized = sanitized + "_";
|
|
83
|
+
return sanitized;
|
|
84
|
+
}
|
|
85
|
+
function toCamelCase(str) {
|
|
86
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract field descriptions from a schema and format as @param lines.
|
|
90
|
+
* Returns an array of `@param input.fieldName - description` lines.
|
|
91
|
+
*/
|
|
92
|
+
function extractParamDescriptions(schema) {
|
|
93
|
+
const descriptions = extractDescriptions(schema);
|
|
94
|
+
return Object.entries(descriptions).map(([fieldName, desc]) => `@param input.${fieldName} - ${desc}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if a value is a Zod schema (has _zod property).
|
|
98
|
+
*/
|
|
99
|
+
function isZodSchema(value) {
|
|
100
|
+
return value !== null && typeof value === "object" && "_zod" in value && value._zod !== void 0;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if a value is an AI SDK jsonSchema wrapper.
|
|
104
|
+
* The jsonSchema wrapper has a [Symbol] with jsonSchema property.
|
|
105
|
+
*/
|
|
106
|
+
function isJsonSchemaWrapper(value) {
|
|
107
|
+
if (value === null || typeof value !== "object") return false;
|
|
108
|
+
if ("jsonSchema" in value) return true;
|
|
109
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
110
|
+
for (const sym of symbols) {
|
|
111
|
+
const symValue = value[sym];
|
|
112
|
+
if (symValue && typeof symValue === "object" && "jsonSchema" in symValue) return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Extract JSON schema from an AI SDK jsonSchema wrapper.
|
|
118
|
+
*/
|
|
119
|
+
function extractJsonSchema(wrapper) {
|
|
120
|
+
if (wrapper === null || typeof wrapper !== "object") return null;
|
|
121
|
+
if ("jsonSchema" in wrapper) return wrapper.jsonSchema;
|
|
122
|
+
const symbols = Object.getOwnPropertySymbols(wrapper);
|
|
123
|
+
for (const sym of symbols) {
|
|
124
|
+
const symValue = wrapper[sym];
|
|
125
|
+
if (symValue && typeof symValue === "object" && "jsonSchema" in symValue) return symValue.jsonSchema;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a property name needs quoting in TypeScript.
|
|
131
|
+
*/
|
|
132
|
+
function needsQuotes(name) {
|
|
133
|
+
return !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Escape a character as a unicode escape sequence if it is a control character.
|
|
137
|
+
*/
|
|
138
|
+
function escapeControlChar(ch) {
|
|
139
|
+
const code = ch.charCodeAt(0);
|
|
140
|
+
if (code <= 31 || code === 127) return "\\u" + code.toString(16).padStart(4, "0");
|
|
141
|
+
return ch;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Quote a property name if needed.
|
|
145
|
+
* Escapes backslashes, quotes, and control characters.
|
|
146
|
+
*/
|
|
147
|
+
function quoteProp(name) {
|
|
148
|
+
if (needsQuotes(name)) {
|
|
149
|
+
let escaped = "";
|
|
150
|
+
for (const ch of name) if (ch === "\\") escaped += "\\\\";
|
|
151
|
+
else if (ch === "\"") escaped += "\\\"";
|
|
152
|
+
else if (ch === "\n") escaped += "\\n";
|
|
153
|
+
else if (ch === "\r") escaped += "\\r";
|
|
154
|
+
else if (ch === " ") escaped += "\\t";
|
|
155
|
+
else if (ch === "\u2028") escaped += "\\u2028";
|
|
156
|
+
else if (ch === "\u2029") escaped += "\\u2029";
|
|
157
|
+
else escaped += escapeControlChar(ch);
|
|
158
|
+
return `"${escaped}"`;
|
|
159
|
+
}
|
|
160
|
+
return name;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Escape a string for use inside a double-quoted TypeScript string literal.
|
|
164
|
+
* Handles backslashes, quotes, newlines, control characters, and line/paragraph separators.
|
|
165
|
+
*/
|
|
166
|
+
function escapeStringLiteral(s) {
|
|
167
|
+
let out = "";
|
|
168
|
+
for (const ch of s) if (ch === "\\") out += "\\\\";
|
|
169
|
+
else if (ch === "\"") out += "\\\"";
|
|
170
|
+
else if (ch === "\n") out += "\\n";
|
|
171
|
+
else if (ch === "\r") out += "\\r";
|
|
172
|
+
else if (ch === " ") out += "\\t";
|
|
173
|
+
else if (ch === "\u2028") out += "\\u2028";
|
|
174
|
+
else if (ch === "\u2029") out += "\\u2029";
|
|
175
|
+
else out += escapeControlChar(ch);
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Escape a string for use inside a JSDoc comment.
|
|
180
|
+
* Prevents premature comment closure from star-slash sequences.
|
|
181
|
+
*/
|
|
182
|
+
function escapeJsDoc(text) {
|
|
183
|
+
return text.replace(/\*\//g, "*\\/");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Resolve an internal JSON Pointer $ref (e.g. #/definitions/Foo) against the root schema.
|
|
187
|
+
* Returns null for external URLs or unresolvable paths.
|
|
188
|
+
*/
|
|
189
|
+
function resolveRef(ref, root) {
|
|
190
|
+
if (ref === "#") return root;
|
|
191
|
+
if (!ref.startsWith("#/")) return null;
|
|
192
|
+
const segments = ref.slice(2).split("/").map((s) => s.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
193
|
+
let current = root;
|
|
194
|
+
for (const seg of segments) {
|
|
195
|
+
if (current === null || typeof current !== "object") return null;
|
|
196
|
+
current = current[seg];
|
|
197
|
+
if (current === void 0) return null;
|
|
198
|
+
}
|
|
199
|
+
if (typeof current === "boolean") return current;
|
|
200
|
+
if (current === null || typeof current !== "object") return null;
|
|
201
|
+
return current;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Convert a JSON Schema to a TypeScript type string.
|
|
205
|
+
* This is a direct conversion without going through Zod.
|
|
206
|
+
*/
|
|
207
|
+
function jsonSchemaToTypeString(schema, indent, ctx) {
|
|
208
|
+
if (typeof schema === "boolean") return schema ? "unknown" : "never";
|
|
209
|
+
if (ctx.depth >= ctx.maxDepth) return "unknown";
|
|
210
|
+
if (ctx.seen.has(schema)) return "unknown";
|
|
211
|
+
const nextCtx = {
|
|
212
|
+
...ctx,
|
|
213
|
+
depth: ctx.depth + 1,
|
|
214
|
+
seen: new Set([...ctx.seen, schema])
|
|
215
|
+
};
|
|
216
|
+
if (schema.$ref) {
|
|
217
|
+
const resolved = resolveRef(schema.$ref, ctx.root);
|
|
218
|
+
if (!resolved) return "unknown";
|
|
219
|
+
return applyNullable(jsonSchemaToTypeString(resolved, indent, nextCtx), schema);
|
|
220
|
+
}
|
|
221
|
+
if (schema.anyOf) return applyNullable(schema.anyOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" | "), schema);
|
|
222
|
+
if (schema.oneOf) return applyNullable(schema.oneOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" | "), schema);
|
|
223
|
+
if (schema.allOf) return applyNullable(schema.allOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" & "), schema);
|
|
224
|
+
if (schema.enum) {
|
|
225
|
+
if (schema.enum.length === 0) return "never";
|
|
226
|
+
return applyNullable(schema.enum.map((v) => {
|
|
227
|
+
if (v === null) return "null";
|
|
228
|
+
if (typeof v === "string") return "\"" + escapeStringLiteral(v) + "\"";
|
|
229
|
+
if (typeof v === "object") return JSON.stringify(v) ?? "unknown";
|
|
230
|
+
return String(v);
|
|
231
|
+
}).join(" | "), schema);
|
|
232
|
+
}
|
|
233
|
+
if (schema.const !== void 0) return applyNullable(schema.const === null ? "null" : typeof schema.const === "string" ? "\"" + escapeStringLiteral(schema.const) + "\"" : typeof schema.const === "object" ? JSON.stringify(schema.const) ?? "unknown" : String(schema.const), schema);
|
|
234
|
+
const type = schema.type;
|
|
235
|
+
if (type === "string") return applyNullable("string", schema);
|
|
236
|
+
if (type === "number" || type === "integer") return applyNullable("number", schema);
|
|
237
|
+
if (type === "boolean") return applyNullable("boolean", schema);
|
|
238
|
+
if (type === "null") return "null";
|
|
239
|
+
if (type === "array") {
|
|
240
|
+
const prefixItems = schema.prefixItems;
|
|
241
|
+
if (Array.isArray(prefixItems)) return applyNullable(`[${prefixItems.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(", ")}]`, schema);
|
|
242
|
+
if (Array.isArray(schema.items)) return applyNullable(`[${schema.items.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(", ")}]`, schema);
|
|
243
|
+
if (schema.items) return applyNullable(`${jsonSchemaToTypeString(schema.items, indent, nextCtx)}[]`, schema);
|
|
244
|
+
return applyNullable("unknown[]", schema);
|
|
245
|
+
}
|
|
246
|
+
if (type === "object" || schema.properties) {
|
|
247
|
+
const props = schema.properties || {};
|
|
248
|
+
const required = new Set(schema.required || []);
|
|
249
|
+
const lines = [];
|
|
250
|
+
for (const [propName, propSchema] of Object.entries(props)) {
|
|
251
|
+
if (typeof propSchema === "boolean") {
|
|
252
|
+
const boolType = propSchema ? "unknown" : "never";
|
|
253
|
+
const optionalMark = required.has(propName) ? "" : "?";
|
|
254
|
+
lines.push(`${indent} ${quoteProp(propName)}${optionalMark}: ${boolType};`);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const isRequired = required.has(propName);
|
|
258
|
+
const propType = jsonSchemaToTypeString(propSchema, indent + " ", nextCtx);
|
|
259
|
+
const desc = propSchema.description;
|
|
260
|
+
const format = propSchema.format;
|
|
261
|
+
if (desc || format) {
|
|
262
|
+
const descText = desc ? escapeJsDoc(desc.replace(/\r?\n/g, " ")) : void 0;
|
|
263
|
+
const formatTag = format ? `@format ${escapeJsDoc(format)}` : void 0;
|
|
264
|
+
if (descText && formatTag) {
|
|
265
|
+
lines.push(`${indent} /**`);
|
|
266
|
+
lines.push(`${indent} * ${descText}`);
|
|
267
|
+
lines.push(`${indent} * ${formatTag}`);
|
|
268
|
+
lines.push(`${indent} */`);
|
|
269
|
+
} else lines.push(`${indent} /** ${descText ?? formatTag} */`);
|
|
270
|
+
}
|
|
271
|
+
const quotedName = quoteProp(propName);
|
|
272
|
+
const optionalMark = isRequired ? "" : "?";
|
|
273
|
+
lines.push(`${indent} ${quotedName}${optionalMark}: ${propType};`);
|
|
274
|
+
}
|
|
275
|
+
if (schema.additionalProperties) {
|
|
276
|
+
const valueType = schema.additionalProperties === true ? "unknown" : jsonSchemaToTypeString(schema.additionalProperties, indent + " ", nextCtx);
|
|
277
|
+
lines.push(`${indent} [key: string]: ${valueType};`);
|
|
278
|
+
}
|
|
279
|
+
if (lines.length === 0) {
|
|
280
|
+
if (schema.additionalProperties === false) return applyNullable("{}", schema);
|
|
281
|
+
return applyNullable("Record<string, unknown>", schema);
|
|
282
|
+
}
|
|
283
|
+
return applyNullable(`{\n${lines.join("\n")}\n${indent}}`, schema);
|
|
284
|
+
}
|
|
285
|
+
if (Array.isArray(type)) return applyNullable(type.map((t) => {
|
|
286
|
+
if (t === "string") return "string";
|
|
287
|
+
if (t === "number" || t === "integer") return "number";
|
|
288
|
+
if (t === "boolean") return "boolean";
|
|
289
|
+
if (t === "null") return "null";
|
|
290
|
+
if (t === "array") return "unknown[]";
|
|
291
|
+
if (t === "object") return "Record<string, unknown>";
|
|
292
|
+
return "unknown";
|
|
293
|
+
}).join(" | "), schema);
|
|
294
|
+
return "unknown";
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Apply OpenAPI 3.0 `nullable: true` to a type result.
|
|
298
|
+
*/
|
|
299
|
+
function applyNullable(result, schema) {
|
|
300
|
+
if (result !== "unknown" && result !== "never" && schema?.nullable === true) return `${result} | null`;
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Extract field descriptions from a schema.
|
|
305
|
+
* Works with Zod schemas (via .shape) and jsonSchema wrappers (via .properties).
|
|
306
|
+
*/
|
|
307
|
+
function extractDescriptions(schema) {
|
|
308
|
+
const descriptions = {};
|
|
309
|
+
const shape = schema.shape;
|
|
310
|
+
if (shape && typeof shape === "object") {
|
|
311
|
+
for (const [fieldName, fieldSchema] of Object.entries(shape)) {
|
|
312
|
+
const desc = fieldSchema.description;
|
|
313
|
+
if (desc) descriptions[fieldName] = desc;
|
|
314
|
+
}
|
|
315
|
+
return descriptions;
|
|
316
|
+
}
|
|
317
|
+
if (isJsonSchemaWrapper(schema)) {
|
|
318
|
+
const jsonSchema = extractJsonSchema(schema);
|
|
319
|
+
if (jsonSchema?.properties) {
|
|
320
|
+
for (const [fieldName, propSchema] of Object.entries(jsonSchema.properties)) if (propSchema && typeof propSchema === "object" && propSchema.description) descriptions[fieldName] = propSchema.description;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return descriptions;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Safely convert a schema to TypeScript type string.
|
|
327
|
+
* Handles Zod schemas and AI SDK jsonSchema wrappers.
|
|
328
|
+
* Returns "unknown" if the schema cannot be represented in TypeScript.
|
|
329
|
+
*/
|
|
330
|
+
function safeSchemaToTs(schema, typeName, auxiliaryTypeStore) {
|
|
331
|
+
try {
|
|
332
|
+
if (isZodSchema(schema)) return printNode(createTypeAlias(zodToTs(schema, { auxiliaryTypeStore }).node, typeName));
|
|
333
|
+
if (isJsonSchemaWrapper(schema)) {
|
|
334
|
+
const jsonSchema = extractJsonSchema(schema);
|
|
335
|
+
if (jsonSchema) return `type ${typeName} = ${jsonSchemaToTypeString(jsonSchema, "", {
|
|
336
|
+
root: jsonSchema,
|
|
337
|
+
depth: 0,
|
|
338
|
+
seen: /* @__PURE__ */ new Set(),
|
|
339
|
+
maxDepth: 20
|
|
340
|
+
})}`;
|
|
341
|
+
}
|
|
342
|
+
return `type ${typeName} = unknown`;
|
|
343
|
+
} catch {
|
|
344
|
+
return `type ${typeName} = unknown`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.
|
|
349
|
+
* These types can be included in tool descriptions to help LLMs write correct code.
|
|
350
|
+
*/
|
|
351
|
+
function generateTypes(tools) {
|
|
352
|
+
let availableTools = "";
|
|
353
|
+
let availableTypes = "";
|
|
354
|
+
const auxiliaryTypeStore = createAuxiliaryTypeStore();
|
|
355
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
356
|
+
const safeName = sanitizeToolName(toolName);
|
|
357
|
+
const camelName = toCamelCase(safeName);
|
|
358
|
+
try {
|
|
359
|
+
const inputSchema = "inputSchema" in tool ? tool.inputSchema : tool.parameters;
|
|
360
|
+
const outputSchema = "outputSchema" in tool ? tool.outputSchema : void 0;
|
|
361
|
+
const description = tool.description;
|
|
362
|
+
const inputType = safeSchemaToTs(inputSchema, `${camelName}Input`, auxiliaryTypeStore);
|
|
363
|
+
const outputType = outputSchema ? safeSchemaToTs(outputSchema, `${camelName}Output`, auxiliaryTypeStore) : `type ${camelName}Output = unknown`;
|
|
364
|
+
availableTypes += `\n${inputType.trim()}`;
|
|
365
|
+
availableTypes += `\n${outputType.trim()}`;
|
|
366
|
+
const paramDescs = inputSchema ? extractParamDescriptions(inputSchema) : [];
|
|
367
|
+
const jsdocLines = [];
|
|
368
|
+
if (description?.trim()) jsdocLines.push(escapeJsDoc(description.trim().replace(/\r?\n/g, " ")));
|
|
369
|
+
else jsdocLines.push(escapeJsDoc(toolName));
|
|
370
|
+
for (const pd of paramDescs) jsdocLines.push(escapeJsDoc(pd.replace(/\r?\n/g, " ")));
|
|
371
|
+
const jsdocBody = jsdocLines.map((l) => `\t * ${l}`).join("\n");
|
|
372
|
+
availableTools += `\n\t/**\n${jsdocBody}\n\t */`;
|
|
373
|
+
availableTools += `\n\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;
|
|
374
|
+
availableTools += "\n";
|
|
375
|
+
} catch {
|
|
376
|
+
availableTypes += `\ntype ${camelName}Input = unknown`;
|
|
377
|
+
availableTypes += `\ntype ${camelName}Output = unknown`;
|
|
378
|
+
availableTools += `\n\t/**\n\t * ${escapeJsDoc(toolName)}\n\t */`;
|
|
379
|
+
availableTools += `\n\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;
|
|
380
|
+
availableTools += "\n";
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
availableTools = `\ndeclare const codemode: {${availableTools}}`;
|
|
384
|
+
return `
|
|
385
|
+
${availableTypes}
|
|
386
|
+
${availableTools}
|
|
387
|
+
`.trim();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
//#endregion
|
|
391
|
+
export { sanitizeToolName as n, generateTypes as t };
|
|
392
|
+
//# sourceMappingURL=types-CpkEgXwN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CpkEgXwN.js","names":["printNodeZodToTs"],"sources":["../src/types.ts"],"sourcesContent":["import {\n zodToTs,\n printNode as printNodeZodToTs,\n createTypeAlias,\n createAuxiliaryTypeStore\n} from \"zod-to-ts\";\nimport type { ZodType } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\n\ninterface ConversionContext {\n root: JSONSchema7;\n depth: number;\n seen: Set<unknown>;\n maxDepth: number;\n}\n\nconst JS_RESERVED = new Set([\n \"abstract\",\n \"arguments\",\n \"await\",\n \"boolean\",\n \"break\",\n \"byte\",\n \"case\",\n \"catch\",\n \"char\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"double\",\n \"else\",\n \"enum\",\n \"eval\",\n \"export\",\n \"extends\",\n \"false\",\n \"final\",\n \"finally\",\n \"float\",\n \"for\",\n \"function\",\n \"goto\",\n \"if\",\n \"implements\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"int\",\n \"interface\",\n \"let\",\n \"long\",\n \"native\",\n \"new\",\n \"null\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"return\",\n \"short\",\n \"static\",\n \"super\",\n \"switch\",\n \"synchronized\",\n \"this\",\n \"throw\",\n \"throws\",\n \"transient\",\n \"true\",\n \"try\",\n \"typeof\",\n \"undefined\",\n \"var\",\n \"void\",\n \"volatile\",\n \"while\",\n \"with\",\n \"yield\"\n]);\n\n/**\n * Sanitize a tool name into a valid JavaScript identifier.\n * Replaces hyphens, dots, and spaces with `_`, strips other invalid chars,\n * prefixes digit-leading names with `_`, and appends `_` to JS reserved words.\n */\nexport function sanitizeToolName(name: string): string {\n if (!name) return \"_\";\n\n // Replace common separators with underscores\n let sanitized = name.replace(/[-.\\s]/g, \"_\");\n\n // Strip any remaining non-identifier characters\n sanitized = sanitized.replace(/[^a-zA-Z0-9_$]/g, \"\");\n\n if (!sanitized) return \"_\";\n\n // Prefix with _ if starts with a digit\n if (/^[0-9]/.test(sanitized)) {\n sanitized = \"_\" + sanitized;\n }\n\n // Append _ to reserved words\n if (JS_RESERVED.has(sanitized)) {\n sanitized = sanitized + \"_\";\n }\n\n return sanitized;\n}\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\n/**\n * Extract field descriptions from a schema and format as @param lines.\n * Returns an array of `@param input.fieldName - description` lines.\n */\nfunction extractParamDescriptions(schema: unknown): string[] {\n const descriptions = extractDescriptions(schema);\n return Object.entries(descriptions).map(\n ([fieldName, desc]) => `@param input.${fieldName} - ${desc}`\n );\n}\n\nexport interface ToolDescriptor {\n description?: string;\n inputSchema: ZodType;\n outputSchema?: ZodType;\n execute?: (args: unknown) => Promise<unknown>;\n}\n\nexport type ToolDescriptors = Record<string, ToolDescriptor>;\n\n/**\n * Check if a value is a Zod schema (has _zod property).\n */\nfunction isZodSchema(value: unknown): value is ZodType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"_zod\" in value &&\n (value as { _zod?: unknown })._zod !== undefined\n );\n}\n\n/**\n * Check if a value is an AI SDK jsonSchema wrapper.\n * The jsonSchema wrapper has a [Symbol] with jsonSchema property.\n */\nfunction isJsonSchemaWrapper(\n value: unknown\n): value is { jsonSchema: JSONSchema7 } {\n if (value === null || typeof value !== \"object\") return false;\n\n // AI SDK jsonSchema wrapper stores data in a symbol property\n // but also exposes jsonSchema directly in some versions\n if (\"jsonSchema\" in value) {\n return true;\n }\n\n // Check for symbol-based storage (AI SDK internal)\n const symbols = Object.getOwnPropertySymbols(value);\n for (const sym of symbols) {\n const symValue = (value as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Extract JSON schema from an AI SDK jsonSchema wrapper.\n */\nfunction extractJsonSchema(wrapper: unknown): JSONSchema7 | null {\n if (wrapper === null || typeof wrapper !== \"object\") return null;\n\n // Direct property access\n if (\"jsonSchema\" in wrapper) {\n return (wrapper as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n\n // Symbol-based storage\n const symbols = Object.getOwnPropertySymbols(wrapper);\n for (const sym of symbols) {\n const symValue = (wrapper as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return (symValue as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n }\n\n return null;\n}\n\n/**\n * Check if a property name needs quoting in TypeScript.\n */\nfunction needsQuotes(name: string): boolean {\n // Valid JS identifier: starts with letter, $, or _, followed by letters, digits, $, _\n return !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);\n}\n\n/**\n * Escape a character as a unicode escape sequence if it is a control character.\n */\nfunction escapeControlChar(ch: string): string {\n const code = ch.charCodeAt(0);\n if (code <= 0x1f || code === 0x7f) {\n return \"\\\\u\" + code.toString(16).padStart(4, \"0\");\n }\n return ch;\n}\n\n/**\n * Quote a property name if needed.\n * Escapes backslashes, quotes, and control characters.\n */\nfunction quoteProp(name: string): string {\n if (needsQuotes(name)) {\n let escaped = \"\";\n for (const ch of name) {\n if (ch === \"\\\\\") escaped += \"\\\\\\\\\";\n else if (ch === '\"') escaped += '\\\\\"';\n else if (ch === \"\\n\") escaped += \"\\\\n\";\n else if (ch === \"\\r\") escaped += \"\\\\r\";\n else if (ch === \"\\t\") escaped += \"\\\\t\";\n else if (ch === \"\\u2028\") escaped += \"\\\\u2028\";\n else if (ch === \"\\u2029\") escaped += \"\\\\u2029\";\n else escaped += escapeControlChar(ch);\n }\n return `\"${escaped}\"`;\n }\n return name;\n}\n\n/**\n * Escape a string for use inside a double-quoted TypeScript string literal.\n * Handles backslashes, quotes, newlines, control characters, and line/paragraph separators.\n */\nfunction escapeStringLiteral(s: string): string {\n let out = \"\";\n for (const ch of s) {\n if (ch === \"\\\\\") out += \"\\\\\\\\\";\n else if (ch === '\"') out += '\\\\\"';\n else if (ch === \"\\n\") out += \"\\\\n\";\n else if (ch === \"\\r\") out += \"\\\\r\";\n else if (ch === \"\\t\") out += \"\\\\t\";\n else if (ch === \"\\u2028\") out += \"\\\\u2028\";\n else if (ch === \"\\u2029\") out += \"\\\\u2029\";\n else out += escapeControlChar(ch);\n }\n return out;\n}\n\n/**\n * Escape a string for use inside a JSDoc comment.\n * Prevents premature comment closure from star-slash sequences.\n */\nfunction escapeJsDoc(text: string): string {\n return text.replace(/\\*\\//g, \"*\\\\/\");\n}\n\n/**\n * Resolve an internal JSON Pointer $ref (e.g. #/definitions/Foo) against the root schema.\n * Returns null for external URLs or unresolvable paths.\n */\nfunction resolveRef(\n ref: string,\n root: JSONSchema7\n): JSONSchema7Definition | null {\n // \"#\" is a valid self-reference to the root schema\n if (ref === \"#\") return root;\n\n if (!ref.startsWith(\"#/\")) return null;\n\n const segments = ref\n .slice(2)\n .split(\"/\")\n .map((s) => s.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n\n let current: unknown = root;\n for (const seg of segments) {\n if (current === null || typeof current !== \"object\") return null;\n current = (current as Record<string, unknown>)[seg];\n if (current === undefined) return null;\n }\n\n // Allow both object schemas and boolean schemas (true = any, false = never)\n if (typeof current === \"boolean\") return current;\n if (current === null || typeof current !== \"object\") return null;\n return current as JSONSchema7;\n}\n\n/**\n * Convert a JSON Schema to a TypeScript type string.\n * This is a direct conversion without going through Zod.\n */\nfunction jsonSchemaToTypeString(\n schema: JSONSchema7Definition,\n indent: string,\n ctx: ConversionContext\n): string {\n // Handle boolean schemas\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n // Depth guard\n if (ctx.depth >= ctx.maxDepth) return \"unknown\";\n\n // Circular reference guard\n if (ctx.seen.has(schema)) return \"unknown\";\n\n const nextCtx: ConversionContext = {\n ...ctx,\n depth: ctx.depth + 1,\n seen: new Set([...ctx.seen, schema])\n };\n\n // Handle $ref\n if (schema.$ref) {\n const resolved = resolveRef(schema.$ref, ctx.root);\n if (!resolved) return \"unknown\";\n return applyNullable(\n jsonSchemaToTypeString(resolved, indent, nextCtx),\n schema\n );\n }\n\n // Handle anyOf/oneOf (union types)\n if (schema.anyOf) {\n const types = schema.anyOf.map((s) =>\n jsonSchemaToTypeString(s, indent, nextCtx)\n );\n return applyNullable(types.join(\" | \"), schema);\n }\n if (schema.oneOf) {\n const types = schema.oneOf.map((s) =>\n jsonSchemaToTypeString(s, indent, nextCtx)\n );\n return applyNullable(types.join(\" | \"), schema);\n }\n\n // Handle allOf (intersection types)\n if (schema.allOf) {\n const types = schema.allOf.map((s) =>\n jsonSchemaToTypeString(s, indent, nextCtx)\n );\n return applyNullable(types.join(\" & \"), schema);\n }\n\n // Handle enum\n if (schema.enum) {\n if (schema.enum.length === 0) return \"never\";\n const result = schema.enum\n .map((v) => {\n if (v === null) return \"null\";\n if (typeof v === \"string\") return '\"' + escapeStringLiteral(v) + '\"';\n if (typeof v === \"object\") return JSON.stringify(v) ?? \"unknown\";\n return String(v);\n })\n .join(\" | \");\n return applyNullable(result, schema);\n }\n\n // Handle const\n if (schema.const !== undefined) {\n const result =\n schema.const === null\n ? \"null\"\n : typeof schema.const === \"string\"\n ? '\"' + escapeStringLiteral(schema.const) + '\"'\n : typeof schema.const === \"object\"\n ? (JSON.stringify(schema.const) ?? \"unknown\")\n : String(schema.const);\n return applyNullable(result, schema);\n }\n\n // Handle type\n const type = schema.type;\n\n if (type === \"string\") return applyNullable(\"string\", schema);\n if (type === \"number\" || type === \"integer\")\n return applyNullable(\"number\", schema);\n if (type === \"boolean\") return applyNullable(\"boolean\", schema);\n if (type === \"null\") return \"null\";\n\n if (type === \"array\") {\n // Tuple support: prefixItems (JSON Schema 2020-12)\n const prefixItems = (schema as Record<string, unknown>)\n .prefixItems as JSONSchema7Definition[];\n if (Array.isArray(prefixItems)) {\n const types = prefixItems.map((s) =>\n jsonSchemaToTypeString(s, indent, nextCtx)\n );\n return applyNullable(`[${types.join(\", \")}]`, schema);\n }\n\n // Tuple support: items as array (draft-07)\n if (Array.isArray(schema.items)) {\n const types = schema.items.map((s) =>\n jsonSchemaToTypeString(s, indent, nextCtx)\n );\n return applyNullable(`[${types.join(\", \")}]`, schema);\n }\n\n if (schema.items) {\n const itemType = jsonSchemaToTypeString(schema.items, indent, nextCtx);\n return applyNullable(`${itemType}[]`, schema);\n }\n return applyNullable(\"unknown[]\", schema);\n }\n\n if (type === \"object\" || schema.properties) {\n const props = schema.properties || {};\n const required = new Set(schema.required || []);\n const lines: string[] = [];\n\n for (const [propName, propSchema] of Object.entries(props)) {\n if (typeof propSchema === \"boolean\") {\n const boolType = propSchema ? \"unknown\" : \"never\";\n const optionalMark = required.has(propName) ? \"\" : \"?\";\n lines.push(\n `${indent} ${quoteProp(propName)}${optionalMark}: ${boolType};`\n );\n continue;\n }\n\n const isRequired = required.has(propName);\n const propType = jsonSchemaToTypeString(\n propSchema,\n indent + \" \",\n nextCtx\n );\n const desc = propSchema.description;\n const format = propSchema.format;\n\n if (desc || format) {\n const descText = desc\n ? escapeJsDoc(desc.replace(/\\r?\\n/g, \" \"))\n : undefined;\n const formatTag = format ? `@format ${escapeJsDoc(format)}` : undefined;\n\n if (descText && formatTag) {\n // Multi-line JSDoc when both description and format are present\n lines.push(`${indent} /**`);\n lines.push(`${indent} * ${descText}`);\n lines.push(`${indent} * ${formatTag}`);\n lines.push(`${indent} */`);\n } else {\n lines.push(`${indent} /** ${descText ?? formatTag} */`);\n }\n }\n\n const quotedName = quoteProp(propName);\n const optionalMark = isRequired ? \"\" : \"?\";\n lines.push(`${indent} ${quotedName}${optionalMark}: ${propType};`);\n }\n\n // Handle additionalProperties\n // NOTE: In TypeScript, an index signature [key: string]: T requires all\n // named properties to be assignable to T. If any named property has an\n // incompatible type, the generated type is invalid. We emit it anyway\n // since it's more informative for LLMs consuming these types.\n if (schema.additionalProperties) {\n const valueType =\n schema.additionalProperties === true\n ? \"unknown\"\n : jsonSchemaToTypeString(\n schema.additionalProperties,\n indent + \" \",\n nextCtx\n );\n lines.push(`${indent} [key: string]: ${valueType};`);\n }\n\n if (lines.length === 0) {\n // additionalProperties: false means no keys allowed → empty object\n if (schema.additionalProperties === false) {\n return applyNullable(\"{}\", schema);\n }\n return applyNullable(\"Record<string, unknown>\", schema);\n }\n\n const result = `{\\n${lines.join(\"\\n\")}\\n${indent}}`;\n return applyNullable(result, schema);\n }\n\n // Handle array of types (e.g., [\"string\", \"null\"])\n if (Array.isArray(type)) {\n const types = type.map((t) => {\n if (t === \"string\") return \"string\";\n if (t === \"number\" || t === \"integer\") return \"number\";\n if (t === \"boolean\") return \"boolean\";\n if (t === \"null\") return \"null\";\n if (t === \"array\") return \"unknown[]\";\n if (t === \"object\") return \"Record<string, unknown>\";\n return \"unknown\";\n });\n return applyNullable(types.join(\" | \"), schema);\n }\n\n return \"unknown\";\n}\n\n/**\n * Apply OpenAPI 3.0 `nullable: true` to a type result.\n */\nfunction applyNullable(result: string, schema: unknown): string {\n if (\n result !== \"unknown\" &&\n result !== \"never\" &&\n (schema as Record<string, unknown>)?.nullable === true\n ) {\n return `${result} | null`;\n }\n return result;\n}\n\n/**\n * Extract field descriptions from a schema.\n * Works with Zod schemas (via .shape) and jsonSchema wrappers (via .properties).\n */\nfunction extractDescriptions(schema: unknown): Record<string, string> {\n const descriptions: Record<string, string> = {};\n\n // Try Zod schema shape\n const shape = (schema as { shape?: Record<string, ZodType> }).shape;\n if (shape && typeof shape === \"object\") {\n for (const [fieldName, fieldSchema] of Object.entries(shape)) {\n const desc = (fieldSchema as { description?: string }).description;\n if (desc) {\n descriptions[fieldName] = desc;\n }\n }\n return descriptions;\n }\n\n // Try JSON Schema properties (for jsonSchema wrapper)\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema?.properties) {\n for (const [fieldName, propSchema] of Object.entries(\n jsonSchema.properties\n )) {\n if (\n propSchema &&\n typeof propSchema === \"object\" &&\n propSchema.description\n ) {\n descriptions[fieldName] = propSchema.description;\n }\n }\n }\n }\n\n return descriptions;\n}\n\n/**\n * Safely convert a schema to TypeScript type string.\n * Handles Zod schemas and AI SDK jsonSchema wrappers.\n * Returns \"unknown\" if the schema cannot be represented in TypeScript.\n */\nfunction safeSchemaToTs(\n schema: unknown,\n typeName: string,\n auxiliaryTypeStore: ReturnType<typeof createAuxiliaryTypeStore>\n): string {\n try {\n // For Zod schemas, use zod-to-ts\n if (isZodSchema(schema)) {\n const result = zodToTs(schema, { auxiliaryTypeStore });\n return printNodeZodToTs(createTypeAlias(result.node, typeName));\n }\n\n // For JSON Schema wrapper, convert directly to TypeScript\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema) {\n const ctx: ConversionContext = {\n root: jsonSchema,\n depth: 0,\n seen: new Set(),\n maxDepth: 20\n };\n const typeBody = jsonSchemaToTypeString(jsonSchema, \"\", ctx);\n return `type ${typeName} = ${typeBody}`;\n }\n }\n\n return `type ${typeName} = unknown`;\n } catch {\n // If the schema cannot be represented, fall back to unknown\n return `type ${typeName} = unknown`;\n }\n}\n\n/**\n * Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.\n * These types can be included in tool descriptions to help LLMs write correct code.\n */\nexport function generateTypes(tools: ToolDescriptors | ToolSet): string {\n let availableTools = \"\";\n let availableTypes = \"\";\n\n const auxiliaryTypeStore = createAuxiliaryTypeStore();\n\n for (const [toolName, tool] of Object.entries(tools)) {\n const safeName = sanitizeToolName(toolName);\n const camelName = toCamelCase(safeName);\n\n try {\n // Handle both our ToolDescriptor and AI SDK Tool types\n const inputSchema =\n \"inputSchema\" in tool ? tool.inputSchema : tool.parameters;\n const outputSchema =\n \"outputSchema\" in tool ? tool.outputSchema : undefined;\n const description = tool.description;\n\n const inputType = safeSchemaToTs(\n inputSchema,\n `${camelName}Input`,\n auxiliaryTypeStore\n );\n\n const outputType = outputSchema\n ? safeSchemaToTs(outputSchema, `${camelName}Output`, auxiliaryTypeStore)\n : `type ${camelName}Output = unknown`;\n\n availableTypes += `\\n${inputType.trim()}`;\n availableTypes += `\\n${outputType.trim()}`;\n\n // Build JSDoc comment with description and param descriptions\n const paramDescs = inputSchema\n ? extractParamDescriptions(inputSchema)\n : [];\n const jsdocLines: string[] = [];\n if (description?.trim()) {\n jsdocLines.push(escapeJsDoc(description.trim().replace(/\\r?\\n/g, \" \")));\n } else {\n jsdocLines.push(escapeJsDoc(toolName));\n }\n for (const pd of paramDescs) {\n jsdocLines.push(escapeJsDoc(pd.replace(/\\r?\\n/g, \" \")));\n }\n\n const jsdocBody = jsdocLines.map((l) => `\\t * ${l}`).join(\"\\n\");\n availableTools += `\\n\\t/**\\n${jsdocBody}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;\n availableTools += \"\\n\";\n } catch {\n // One bad tool should not break the others — emit unknown types\n availableTypes += `\\ntype ${camelName}Input = unknown`;\n availableTypes += `\\ntype ${camelName}Output = unknown`;\n\n availableTools += `\\n\\t/**\\n\\t * ${escapeJsDoc(toolName)}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;\n availableTools += \"\\n\";\n }\n }\n\n availableTools = `\\ndeclare const codemode: {${availableTools}}`;\n\n return `\n${availableTypes}\n${availableTools}\n `.trim();\n}\n"],"mappings":";;;AAiBA,MAAM,cAAc,IAAI,IAAI;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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F,qBAAkB;UACZ;AAEN,qBAAkB,UAAU,UAAU;AACtC,qBAAkB,UAAU,UAAU;AAEtC,qBAAkB,iBAAiB,YAAY,SAAS,CAAC;AACzD,qBAAkB,OAAO,SAAS,YAAY,UAAU,oBAAoB,UAAU;AACtF,qBAAkB;;;AAItB,kBAAiB,8BAA8B,eAAe;AAE9D,QAAO;EACP,eAAe;EACf,eAAe;IACb,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/codemode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Code Mode: use LLMs to generate executable code that performs tool calls",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/codemode",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@playwright/test": "^1.58.2",
|
|
19
|
-
"ai": "^6.0.
|
|
19
|
+
"ai": "^6.0.97",
|
|
20
20
|
"vitest": "3.2.4",
|
|
21
21
|
"zod": "^4.3.6"
|
|
22
22
|
},
|