@cloudflare/codemode 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -12
- package/dist/ai.d.ts +26 -3
- package/dist/ai.js +154 -26
- package/dist/ai.js.map +1 -1
- package/dist/{executor-Czw9jKZH.d.ts → executor-BjlGw-Dd.d.ts} +1 -27
- package/dist/index.d.ts +49 -8
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/normalize-xNh5CsfI.js +373 -0
- package/dist/normalize-xNh5CsfI.js.map +1 -0
- package/package.json +12 -4
- package/dist/types-CpkEgXwN.js +0 -392
- package/dist/types-CpkEgXwN.js.map +0 -1
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import * as acorn from "acorn";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const JS_RESERVED = new Set([
|
|
4
|
+
"abstract",
|
|
5
|
+
"arguments",
|
|
6
|
+
"await",
|
|
7
|
+
"boolean",
|
|
8
|
+
"break",
|
|
9
|
+
"byte",
|
|
10
|
+
"case",
|
|
11
|
+
"catch",
|
|
12
|
+
"char",
|
|
13
|
+
"class",
|
|
14
|
+
"const",
|
|
15
|
+
"continue",
|
|
16
|
+
"debugger",
|
|
17
|
+
"default",
|
|
18
|
+
"delete",
|
|
19
|
+
"do",
|
|
20
|
+
"double",
|
|
21
|
+
"else",
|
|
22
|
+
"enum",
|
|
23
|
+
"eval",
|
|
24
|
+
"export",
|
|
25
|
+
"extends",
|
|
26
|
+
"false",
|
|
27
|
+
"final",
|
|
28
|
+
"finally",
|
|
29
|
+
"float",
|
|
30
|
+
"for",
|
|
31
|
+
"function",
|
|
32
|
+
"goto",
|
|
33
|
+
"if",
|
|
34
|
+
"implements",
|
|
35
|
+
"import",
|
|
36
|
+
"in",
|
|
37
|
+
"instanceof",
|
|
38
|
+
"int",
|
|
39
|
+
"interface",
|
|
40
|
+
"let",
|
|
41
|
+
"long",
|
|
42
|
+
"native",
|
|
43
|
+
"new",
|
|
44
|
+
"null",
|
|
45
|
+
"package",
|
|
46
|
+
"private",
|
|
47
|
+
"protected",
|
|
48
|
+
"public",
|
|
49
|
+
"return",
|
|
50
|
+
"short",
|
|
51
|
+
"static",
|
|
52
|
+
"super",
|
|
53
|
+
"switch",
|
|
54
|
+
"synchronized",
|
|
55
|
+
"this",
|
|
56
|
+
"throw",
|
|
57
|
+
"throws",
|
|
58
|
+
"transient",
|
|
59
|
+
"true",
|
|
60
|
+
"try",
|
|
61
|
+
"typeof",
|
|
62
|
+
"undefined",
|
|
63
|
+
"var",
|
|
64
|
+
"void",
|
|
65
|
+
"volatile",
|
|
66
|
+
"while",
|
|
67
|
+
"with",
|
|
68
|
+
"yield"
|
|
69
|
+
]);
|
|
70
|
+
/**
|
|
71
|
+
* Sanitize a tool name into a valid JavaScript identifier.
|
|
72
|
+
* Replaces hyphens, dots, and spaces with `_`, strips other invalid chars,
|
|
73
|
+
* prefixes digit-leading names with `_`, and appends `_` to JS reserved words.
|
|
74
|
+
*/
|
|
75
|
+
function sanitizeToolName(name) {
|
|
76
|
+
if (!name) return "_";
|
|
77
|
+
let sanitized = name.replace(/[-.\s]/g, "_");
|
|
78
|
+
sanitized = sanitized.replace(/[^a-zA-Z0-9_$]/g, "");
|
|
79
|
+
if (!sanitized) return "_";
|
|
80
|
+
if (/^[0-9]/.test(sanitized)) sanitized = "_" + sanitized;
|
|
81
|
+
if (JS_RESERVED.has(sanitized)) sanitized = sanitized + "_";
|
|
82
|
+
return sanitized;
|
|
83
|
+
}
|
|
84
|
+
function toPascalCase(str) {
|
|
85
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Escape a character as a unicode escape sequence if it is a control character.
|
|
89
|
+
*/
|
|
90
|
+
function escapeControlChar(ch) {
|
|
91
|
+
const code = ch.charCodeAt(0);
|
|
92
|
+
if (code <= 31 || code === 127) return "\\u" + code.toString(16).padStart(4, "0");
|
|
93
|
+
return ch;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Quote a property name if needed.
|
|
97
|
+
* Escapes backslashes, quotes, and control characters.
|
|
98
|
+
*/
|
|
99
|
+
function quoteProp(name) {
|
|
100
|
+
if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)) {
|
|
101
|
+
let escaped = "";
|
|
102
|
+
for (const ch of name) if (ch === "\\") escaped += "\\\\";
|
|
103
|
+
else if (ch === "\"") escaped += "\\\"";
|
|
104
|
+
else if (ch === "\n") escaped += "\\n";
|
|
105
|
+
else if (ch === "\r") escaped += "\\r";
|
|
106
|
+
else if (ch === " ") escaped += "\\t";
|
|
107
|
+
else if (ch === "\u2028") escaped += "\\u2028";
|
|
108
|
+
else if (ch === "\u2029") escaped += "\\u2029";
|
|
109
|
+
else escaped += escapeControlChar(ch);
|
|
110
|
+
return `"${escaped}"`;
|
|
111
|
+
}
|
|
112
|
+
return name;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Escape a string for use inside a double-quoted TypeScript string literal.
|
|
116
|
+
*/
|
|
117
|
+
function escapeStringLiteral(s) {
|
|
118
|
+
let out = "";
|
|
119
|
+
for (const ch of s) if (ch === "\\") out += "\\\\";
|
|
120
|
+
else if (ch === "\"") out += "\\\"";
|
|
121
|
+
else if (ch === "\n") out += "\\n";
|
|
122
|
+
else if (ch === "\r") out += "\\r";
|
|
123
|
+
else if (ch === " ") out += "\\t";
|
|
124
|
+
else if (ch === "\u2028") out += "\\u2028";
|
|
125
|
+
else if (ch === "\u2029") out += "\\u2029";
|
|
126
|
+
else out += escapeControlChar(ch);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Escape a string for use inside a JSDoc comment.
|
|
131
|
+
* Prevents premature comment closure from star-slash sequences.
|
|
132
|
+
*/
|
|
133
|
+
function escapeJsDoc(text) {
|
|
134
|
+
return text.replace(/\*\//g, "*\\/");
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/json-schema-types.ts
|
|
138
|
+
/**
|
|
139
|
+
* Resolve an internal JSON Pointer $ref (e.g. #/definitions/Foo) against the root schema.
|
|
140
|
+
* Returns null for external URLs or unresolvable paths.
|
|
141
|
+
*/
|
|
142
|
+
function resolveRef(ref, root) {
|
|
143
|
+
if (ref === "#") return root;
|
|
144
|
+
if (!ref.startsWith("#/")) return null;
|
|
145
|
+
const segments = ref.slice(2).split("/").map((s) => s.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
146
|
+
let current = root;
|
|
147
|
+
for (const seg of segments) {
|
|
148
|
+
if (current === null || typeof current !== "object") return null;
|
|
149
|
+
current = current[seg];
|
|
150
|
+
if (current === void 0) return null;
|
|
151
|
+
}
|
|
152
|
+
if (typeof current === "boolean") return current;
|
|
153
|
+
if (current === null || typeof current !== "object") return null;
|
|
154
|
+
return current;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Apply OpenAPI 3.0 `nullable: true` to a type result.
|
|
158
|
+
*/
|
|
159
|
+
function applyNullable(result, schema) {
|
|
160
|
+
if (result !== "unknown" && result !== "never" && schema?.nullable === true) return `${result} | null`;
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Convert a JSON Schema to a TypeScript type string.
|
|
165
|
+
* This is a direct conversion without going through Zod.
|
|
166
|
+
*/
|
|
167
|
+
function jsonSchemaToTypeString(schema, indent, ctx) {
|
|
168
|
+
if (typeof schema === "boolean") return schema ? "unknown" : "never";
|
|
169
|
+
if (ctx.depth >= ctx.maxDepth) return "unknown";
|
|
170
|
+
if (ctx.seen.has(schema)) return "unknown";
|
|
171
|
+
ctx.seen.add(schema);
|
|
172
|
+
const nextCtx = {
|
|
173
|
+
...ctx,
|
|
174
|
+
depth: ctx.depth + 1
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
if (schema.$ref) {
|
|
178
|
+
const resolved = resolveRef(schema.$ref, ctx.root);
|
|
179
|
+
if (!resolved) return "unknown";
|
|
180
|
+
return applyNullable(jsonSchemaToTypeString(resolved, indent, nextCtx), schema);
|
|
181
|
+
}
|
|
182
|
+
if (schema.anyOf) return applyNullable(schema.anyOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" | "), schema);
|
|
183
|
+
if (schema.oneOf) return applyNullable(schema.oneOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" | "), schema);
|
|
184
|
+
if (schema.allOf) return applyNullable(schema.allOf.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(" & "), schema);
|
|
185
|
+
if (schema.enum) {
|
|
186
|
+
if (schema.enum.length === 0) return "never";
|
|
187
|
+
return applyNullable(schema.enum.map((v) => {
|
|
188
|
+
if (v === null) return "null";
|
|
189
|
+
if (typeof v === "string") return "\"" + escapeStringLiteral(v) + "\"";
|
|
190
|
+
if (typeof v === "object") return JSON.stringify(v) ?? "unknown";
|
|
191
|
+
return String(v);
|
|
192
|
+
}).join(" | "), schema);
|
|
193
|
+
}
|
|
194
|
+
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);
|
|
195
|
+
const type = schema.type;
|
|
196
|
+
if (type === "string") return applyNullable("string", schema);
|
|
197
|
+
if (type === "number" || type === "integer") return applyNullable("number", schema);
|
|
198
|
+
if (type === "boolean") return applyNullable("boolean", schema);
|
|
199
|
+
if (type === "null") return "null";
|
|
200
|
+
if (type === "array") {
|
|
201
|
+
const prefixItems = schema.prefixItems;
|
|
202
|
+
if (Array.isArray(prefixItems)) return applyNullable(`[${prefixItems.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(", ")}]`, schema);
|
|
203
|
+
if (Array.isArray(schema.items)) return applyNullable(`[${schema.items.map((s) => jsonSchemaToTypeString(s, indent, nextCtx)).join(", ")}]`, schema);
|
|
204
|
+
if (schema.items) return applyNullable(`${jsonSchemaToTypeString(schema.items, indent, nextCtx)}[]`, schema);
|
|
205
|
+
return applyNullable("unknown[]", schema);
|
|
206
|
+
}
|
|
207
|
+
if (type === "object" || schema.properties) {
|
|
208
|
+
const props = schema.properties || {};
|
|
209
|
+
const required = new Set(schema.required || []);
|
|
210
|
+
const lines = [];
|
|
211
|
+
for (const [propName, propSchema] of Object.entries(props)) {
|
|
212
|
+
if (typeof propSchema === "boolean") {
|
|
213
|
+
const boolType = propSchema ? "unknown" : "never";
|
|
214
|
+
const optionalMark = required.has(propName) ? "" : "?";
|
|
215
|
+
lines.push(`${indent} ${quoteProp(propName)}${optionalMark}: ${boolType};`);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const isRequired = required.has(propName);
|
|
219
|
+
const propType = jsonSchemaToTypeString(propSchema, indent + " ", nextCtx);
|
|
220
|
+
const desc = propSchema.description;
|
|
221
|
+
const format = propSchema.format;
|
|
222
|
+
if (desc || format) {
|
|
223
|
+
const descText = desc ? escapeJsDoc(desc.replace(/\r?\n/g, " ")) : void 0;
|
|
224
|
+
const formatTag = format ? `@format ${escapeJsDoc(format)}` : void 0;
|
|
225
|
+
if (descText && formatTag) {
|
|
226
|
+
lines.push(`${indent} /**`);
|
|
227
|
+
lines.push(`${indent} * ${descText}`);
|
|
228
|
+
lines.push(`${indent} * ${formatTag}`);
|
|
229
|
+
lines.push(`${indent} */`);
|
|
230
|
+
} else lines.push(`${indent} /** ${descText ?? formatTag} */`);
|
|
231
|
+
}
|
|
232
|
+
const quotedName = quoteProp(propName);
|
|
233
|
+
const optionalMark = isRequired ? "" : "?";
|
|
234
|
+
lines.push(`${indent} ${quotedName}${optionalMark}: ${propType};`);
|
|
235
|
+
}
|
|
236
|
+
if (schema.additionalProperties) {
|
|
237
|
+
const valueType = schema.additionalProperties === true ? "unknown" : jsonSchemaToTypeString(schema.additionalProperties, indent + " ", nextCtx);
|
|
238
|
+
lines.push(`${indent} [key: string]: ${valueType};`);
|
|
239
|
+
}
|
|
240
|
+
if (lines.length === 0) {
|
|
241
|
+
if (schema.additionalProperties === false) return applyNullable("{}", schema);
|
|
242
|
+
return applyNullable("Record<string, unknown>", schema);
|
|
243
|
+
}
|
|
244
|
+
return applyNullable(`{\n${lines.join("\n")}\n${indent}}`, schema);
|
|
245
|
+
}
|
|
246
|
+
if (Array.isArray(type)) return applyNullable(type.map((t) => {
|
|
247
|
+
if (t === "string") return "string";
|
|
248
|
+
if (t === "number" || t === "integer") return "number";
|
|
249
|
+
if (t === "boolean") return "boolean";
|
|
250
|
+
if (t === "null") return "null";
|
|
251
|
+
if (t === "array") return "unknown[]";
|
|
252
|
+
if (t === "object") return "Record<string, unknown>";
|
|
253
|
+
return "unknown";
|
|
254
|
+
}).join(" | "), schema);
|
|
255
|
+
return "unknown";
|
|
256
|
+
} finally {
|
|
257
|
+
ctx.seen.delete(schema);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Convert a JSON Schema to a TypeScript type declaration.
|
|
262
|
+
*/
|
|
263
|
+
function jsonSchemaToType(schema, typeName) {
|
|
264
|
+
return `type ${typeName} = ${jsonSchemaToTypeString(schema, "", {
|
|
265
|
+
root: schema,
|
|
266
|
+
depth: 0,
|
|
267
|
+
seen: /* @__PURE__ */ new Set(),
|
|
268
|
+
maxDepth: 20
|
|
269
|
+
})}`;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Extract field descriptions from a JSON Schema's properties.
|
|
273
|
+
*/
|
|
274
|
+
function extractJsonSchemaDescriptions(schema) {
|
|
275
|
+
const descriptions = {};
|
|
276
|
+
if (schema.properties) {
|
|
277
|
+
for (const [fieldName, propSchema] of Object.entries(schema.properties)) if (propSchema && typeof propSchema === "object" && propSchema.description) descriptions[fieldName] = propSchema.description;
|
|
278
|
+
}
|
|
279
|
+
return descriptions;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Generate TypeScript type definitions from tool descriptors with JSON Schema.
|
|
283
|
+
* This function has NO dependency on the AI SDK or Zod — it works purely with
|
|
284
|
+
* JSON Schema objects.
|
|
285
|
+
*
|
|
286
|
+
* Use this when you have raw JSON Schema (e.g. from OpenAPI specs, MCP tool
|
|
287
|
+
* definitions, etc.) and don't need the AI SDK.
|
|
288
|
+
*/
|
|
289
|
+
function generateTypesFromJsonSchema(tools) {
|
|
290
|
+
let availableTools = "";
|
|
291
|
+
let availableTypes = "";
|
|
292
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
293
|
+
const safeName = sanitizeToolName(toolName);
|
|
294
|
+
const typeName = toPascalCase(safeName);
|
|
295
|
+
try {
|
|
296
|
+
const inputType = jsonSchemaToType(tool.inputSchema, `${typeName}Input`);
|
|
297
|
+
const outputType = tool.outputSchema ? jsonSchemaToType(tool.outputSchema, `${typeName}Output`) : `type ${typeName}Output = unknown`;
|
|
298
|
+
availableTypes += `\n${inputType.trim()}`;
|
|
299
|
+
availableTypes += `\n${outputType.trim()}`;
|
|
300
|
+
const paramLines = (() => {
|
|
301
|
+
try {
|
|
302
|
+
const paramDescs = extractJsonSchemaDescriptions(tool.inputSchema);
|
|
303
|
+
return Object.entries(paramDescs).map(([fieldName, desc]) => `@param input.${fieldName} - ${desc}`);
|
|
304
|
+
} catch {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
})();
|
|
308
|
+
const jsdocLines = [];
|
|
309
|
+
if (tool.description?.trim()) jsdocLines.push(escapeJsDoc(tool.description.trim().replace(/\r?\n/g, " ")));
|
|
310
|
+
else jsdocLines.push(escapeJsDoc(toolName));
|
|
311
|
+
for (const pd of paramLines) jsdocLines.push(escapeJsDoc(pd.replace(/\r?\n/g, " ")));
|
|
312
|
+
const jsdocBody = jsdocLines.map((l) => `\t * ${l}`).join("\n");
|
|
313
|
+
availableTools += `\n\t/**\n${jsdocBody}\n\t */`;
|
|
314
|
+
availableTools += `\n\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;
|
|
315
|
+
availableTools += "\n";
|
|
316
|
+
} catch {
|
|
317
|
+
availableTypes += `\ntype ${typeName}Input = unknown`;
|
|
318
|
+
availableTypes += `\ntype ${typeName}Output = unknown`;
|
|
319
|
+
availableTools += `\n\t/**\n\t * ${escapeJsDoc(toolName)}\n\t */`;
|
|
320
|
+
availableTools += `\n\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;
|
|
321
|
+
availableTools += "\n";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
availableTools = `\ndeclare const codemode: {${availableTools}}`;
|
|
325
|
+
return `
|
|
326
|
+
${availableTypes}
|
|
327
|
+
${availableTools}
|
|
328
|
+
`.trim();
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/normalize.ts
|
|
332
|
+
/**
|
|
333
|
+
* Strip markdown code fences that LLMs commonly wrap code in.
|
|
334
|
+
* Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.
|
|
335
|
+
*/
|
|
336
|
+
function stripCodeFences(code) {
|
|
337
|
+
const match = code.match(/^```(?:js|javascript|typescript|ts|tsx|jsx)?\s*\n([\s\S]*?)```\s*$/);
|
|
338
|
+
return match ? match[1] : code;
|
|
339
|
+
}
|
|
340
|
+
function normalizeCode(code) {
|
|
341
|
+
const trimmed = stripCodeFences(code.trim());
|
|
342
|
+
if (!trimmed.trim()) return "async () => {}";
|
|
343
|
+
const source = trimmed.trim();
|
|
344
|
+
try {
|
|
345
|
+
const ast = acorn.parse(source, {
|
|
346
|
+
ecmaVersion: "latest",
|
|
347
|
+
sourceType: "module"
|
|
348
|
+
});
|
|
349
|
+
if (ast.body.length === 1 && ast.body[0].type === "ExpressionStatement") {
|
|
350
|
+
if (ast.body[0].expression.type === "ArrowFunctionExpression") return source;
|
|
351
|
+
}
|
|
352
|
+
if (ast.body.length === 1 && ast.body[0].type === "ExportDefaultDeclaration") {
|
|
353
|
+
const decl = ast.body[0].declaration;
|
|
354
|
+
const inner = source.slice(decl.start, decl.end);
|
|
355
|
+
if (decl.type === "FunctionDeclaration" && !decl.id) return `async () => {\nreturn (${inner})();\n}`;
|
|
356
|
+
if (decl.type === "ClassDeclaration" && !decl.id) return `async () => {\nreturn (${inner});\n}`;
|
|
357
|
+
return normalizeCode(inner);
|
|
358
|
+
}
|
|
359
|
+
if (ast.body.length === 1 && ast.body[0].type === "FunctionDeclaration") return `async () => {\n${source}\nreturn ${ast.body[0].id?.name ?? "fn"}();\n}`;
|
|
360
|
+
const last = ast.body[ast.body.length - 1];
|
|
361
|
+
if (last?.type === "ExpressionStatement") {
|
|
362
|
+
const exprStmt = last;
|
|
363
|
+
return `async () => {\n${source.slice(0, last.start)}return (${source.slice(exprStmt.expression.start, exprStmt.expression.end)})\n}`;
|
|
364
|
+
}
|
|
365
|
+
return `async () => {\n${source}\n}`;
|
|
366
|
+
} catch {
|
|
367
|
+
return `async () => {\n${source}\n}`;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { escapeJsDoc as a, jsonSchemaToTypeString as i, generateTypesFromJsonSchema as n, sanitizeToolName as o, jsonSchemaToType as r, toPascalCase as s, normalizeCode as t };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=normalize-xNh5CsfI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-xNh5CsfI.js","names":[],"sources":["../src/utils.ts","../src/json-schema-types.ts","../src/normalize.ts"],"sourcesContent":["const 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\nexport function toPascalCase(str: string) {\n return str\n .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())\n .replace(/^[a-z]/, (letter) => letter.toUpperCase());\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 */\nexport function quoteProp(name: string): string {\n if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(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 */\nexport function 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 */\nexport function escapeJsDoc(text: string): string {\n return text.replace(/\\*\\//g, \"*\\\\/\");\n}\n","import type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport {\n sanitizeToolName,\n toPascalCase,\n escapeJsDoc,\n escapeStringLiteral,\n quoteProp\n} from \"./utils\";\n\nexport interface ConversionContext {\n root: JSONSchema7;\n depth: number;\n seen: Set<unknown>;\n maxDepth: number;\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 * 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 * Convert a JSON Schema to a TypeScript type string.\n * This is a direct conversion without going through Zod.\n */\nexport function 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 ctx.seen.add(schema);\n const nextCtx: ConversionContext = {\n ...ctx,\n depth: ctx.depth + 1\n };\n\n try {\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\n ? `@format ${escapeJsDoc(format)}`\n : undefined;\n\n if (descText && formatTag) {\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 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 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 } finally {\n ctx.seen.delete(schema);\n }\n}\n\n/**\n * Convert a JSON Schema to a TypeScript type declaration.\n */\nexport function jsonSchemaToType(\n schema: JSONSchema7,\n typeName: string\n): string {\n const ctx: ConversionContext = {\n root: schema,\n depth: 0,\n seen: new Set(),\n maxDepth: 20\n };\n const typeBody = jsonSchemaToTypeString(schema, \"\", ctx);\n return `type ${typeName} = ${typeBody}`;\n}\n\n/**\n * Extract field descriptions from a JSON Schema's properties.\n */\nfunction extractJsonSchemaDescriptions(\n schema: JSONSchema7\n): Record<string, string> {\n const descriptions: Record<string, string> = {};\n if (schema.properties) {\n for (const [fieldName, propSchema] of Object.entries(schema.properties)) {\n if (\n propSchema &&\n typeof propSchema === \"object\" &&\n propSchema.description\n ) {\n descriptions[fieldName] = propSchema.description;\n }\n }\n }\n return descriptions;\n}\n\n/**\n * A tool descriptor using plain JSON Schema (no Zod or AI SDK dependency).\n */\nexport interface JsonSchemaToolDescriptor {\n description?: string;\n inputSchema: JSONSchema7;\n outputSchema?: JSONSchema7;\n}\n\nexport type JsonSchemaToolDescriptors = Record<\n string,\n JsonSchemaToolDescriptor\n>;\n\n/**\n * Generate TypeScript type definitions from tool descriptors with JSON Schema.\n * This function has NO dependency on the AI SDK or Zod — it works purely with\n * JSON Schema objects.\n *\n * Use this when you have raw JSON Schema (e.g. from OpenAPI specs, MCP tool\n * definitions, etc.) and don't need the AI SDK.\n */\nexport function generateTypesFromJsonSchema(\n tools: JsonSchemaToolDescriptors\n): string {\n let availableTools = \"\";\n let availableTypes = \"\";\n\n for (const [toolName, tool] of Object.entries(tools)) {\n const safeName = sanitizeToolName(toolName);\n const typeName = toPascalCase(safeName);\n\n try {\n const inputType = jsonSchemaToType(tool.inputSchema, `${typeName}Input`);\n\n const outputType = tool.outputSchema\n ? jsonSchemaToType(tool.outputSchema, `${typeName}Output`)\n : `type ${typeName}Output = unknown`;\n\n availableTypes += `\\n${inputType.trim()}`;\n availableTypes += `\\n${outputType.trim()}`;\n\n const paramLines = (() => {\n try {\n const paramDescs = extractJsonSchemaDescriptions(tool.inputSchema);\n return Object.entries(paramDescs).map(\n ([fieldName, desc]) => `@param input.${fieldName} - ${desc}`\n );\n } catch {\n return [];\n }\n })();\n const jsdocLines: string[] = [];\n if (tool.description?.trim()) {\n jsdocLines.push(\n escapeJsDoc(tool.description.trim().replace(/\\r?\\n/g, \" \"))\n );\n } else {\n jsdocLines.push(escapeJsDoc(toolName));\n }\n for (const pd of paramLines) {\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: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n } catch {\n availableTypes += `\\ntype ${typeName}Input = unknown`;\n availableTypes += `\\ntype ${typeName}Output = unknown`;\n\n availableTools += `\\n\\t/**\\n\\t * ${escapeJsDoc(toolName)}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n }\n }\n\n availableTools = `\\ndeclare const codemode: {${availableTools}}`;\n\n return `\n${availableTypes}\n${availableTools}\n `.trim();\n}\n","import * as acorn from \"acorn\";\n\n/**\n * Strip markdown code fences that LLMs commonly wrap code in.\n * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.\n */\nfunction stripCodeFences(code: string): string {\n const fenced =\n /^```(?:js|javascript|typescript|ts|tsx|jsx)?\\s*\\n([\\s\\S]*?)```\\s*$/;\n const match = code.match(fenced);\n return match ? match[1] : code;\n}\n\nexport function normalizeCode(code: string): string {\n const trimmed = stripCodeFences(code.trim());\n if (!trimmed.trim()) return \"async () => {}\";\n\n const source = trimmed.trim();\n\n try {\n const ast = acorn.parse(source, {\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 source;\n }\n\n // export default <expression> → unwrap to just the expression\n if (\n ast.body.length === 1 &&\n ast.body[0].type === \"ExportDefaultDeclaration\"\n ) {\n const decl = (ast.body[0] as acorn.ExportDefaultDeclaration).declaration;\n const inner = source.slice(decl.start, decl.end);\n\n // Anonymous function/class declarations aren't valid as standalone\n // statements — wrap them as expressions directly.\n if (\n decl.type === \"FunctionDeclaration\" &&\n !(decl as acorn.FunctionDeclaration).id\n ) {\n return `async () => {\\nreturn (${inner})();\\n}`;\n }\n if (\n decl.type === \"ClassDeclaration\" &&\n !(decl as acorn.ClassDeclaration).id\n ) {\n return `async () => {\\nreturn (${inner});\\n}`;\n }\n\n return normalizeCode(inner);\n }\n\n // Single named function declaration → wrap and call it\n if (ast.body.length === 1 && ast.body[0].type === \"FunctionDeclaration\") {\n const fn = ast.body[0] as acorn.FunctionDeclaration;\n const name = fn.id?.name ?? \"fn\";\n return `async () => {\\n${source}\\nreturn ${name}();\\n}`;\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 = source.slice(0, last.start);\n const exprText = source.slice(\n exprStmt.expression.start,\n exprStmt.expression.end\n );\n return `async () => {\\n${before}return (${exprText})\\n}`;\n }\n\n return `async () => {\\n${source}\\n}`;\n } catch {\n return `async () => {\\n${source}\\n}`;\n }\n}\n"],"mappings":";;AAAA,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;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,OACpB,SAAS,WAAW,IACrB,CACkD;;AAGrD,SAAO,kBAAkB,OAAO;SAC1B;AACN,SAAO,kBAAkB,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/codemode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Code Mode: use LLMs to generate executable code that performs tool calls",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/codemode",
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"url": "https://github.com/cloudflare/agents/issues"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"@types/json-schema": "^7.0.15",
|
|
15
|
+
"acorn": "^8.16.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@playwright/test": "^1.58.2",
|
|
19
|
-
"ai": "^6.0.
|
|
19
|
+
"ai": "^6.0.116",
|
|
20
20
|
"vitest": "3.2.4",
|
|
21
21
|
"zod": "^4.3.6"
|
|
22
22
|
},
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
"ai": "^6.0.0",
|
|
25
25
|
"zod": "^3.25.0 || ^4.0.0"
|
|
26
26
|
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"ai": {
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
"zod": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
27
35
|
"types": "dist/index.d.ts",
|
|
28
36
|
"exports": {
|
|
29
37
|
".": {
|