@cloudflare/codemode 0.1.3 → 0.2.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.
@@ -1,6 +1,4 @@
1
- import { asSchema } from "ai";
2
- import * as acorn from "acorn";
3
- //#region src/types.ts
1
+ //#region src/utils.ts
4
2
  const JS_RESERVED = new Set([
5
3
  "abstract",
6
4
  "arguments",
@@ -82,64 +80,10 @@ function sanitizeToolName(name) {
82
80
  if (JS_RESERVED.has(sanitized)) sanitized = sanitized + "_";
83
81
  return sanitized;
84
82
  }
85
- function toCamelCase(str) {
83
+ function toPascalCase(str) {
86
84
  return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
87
85
  }
88
86
  /**
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 conforms to the Standard Schema protocol (~standard).
104
- * This catches Zod v3 schemas (which expose ~standard but not _zod).
105
- */
106
- function isStandardSchema(value) {
107
- return value !== null && typeof value === "object" && "~standard" in value && value["~standard"] !== void 0;
108
- }
109
- /**
110
- * Check if a value is an AI SDK jsonSchema wrapper.
111
- * The jsonSchema wrapper has a [Symbol] with jsonSchema property.
112
- */
113
- function isJsonSchemaWrapper(value) {
114
- if (value === null || typeof value !== "object") return false;
115
- if ("jsonSchema" in value) return true;
116
- const symbols = Object.getOwnPropertySymbols(value);
117
- for (const sym of symbols) {
118
- const symValue = value[sym];
119
- if (symValue && typeof symValue === "object" && "jsonSchema" in symValue) return true;
120
- }
121
- return false;
122
- }
123
- /**
124
- * Extract JSON schema from an AI SDK jsonSchema wrapper.
125
- */
126
- function extractJsonSchema(wrapper) {
127
- if (wrapper === null || typeof wrapper !== "object") return null;
128
- if ("jsonSchema" in wrapper) return wrapper.jsonSchema;
129
- const symbols = Object.getOwnPropertySymbols(wrapper);
130
- for (const sym of symbols) {
131
- const symValue = wrapper[sym];
132
- if (symValue && typeof symValue === "object" && "jsonSchema" in symValue) return symValue.jsonSchema;
133
- }
134
- return null;
135
- }
136
- /**
137
- * Check if a property name needs quoting in TypeScript.
138
- */
139
- function needsQuotes(name) {
140
- return !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
141
- }
142
- /**
143
87
  * Escape a character as a unicode escape sequence if it is a control character.
144
88
  */
145
89
  function escapeControlChar(ch) {
@@ -152,7 +96,7 @@ function escapeControlChar(ch) {
152
96
  * Escapes backslashes, quotes, and control characters.
153
97
  */
154
98
  function quoteProp(name) {
155
- if (needsQuotes(name)) {
99
+ if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)) {
156
100
  let escaped = "";
157
101
  for (const ch of name) if (ch === "\\") escaped += "\\\\";
158
102
  else if (ch === "\"") escaped += "\\\"";
@@ -168,7 +112,6 @@ function quoteProp(name) {
168
112
  }
169
113
  /**
170
114
  * Escape a string for use inside a double-quoted TypeScript string literal.
171
- * Handles backslashes, quotes, newlines, control characters, and line/paragraph separators.
172
115
  */
173
116
  function escapeStringLiteral(s) {
174
117
  let out = "";
@@ -189,6 +132,8 @@ function escapeStringLiteral(s) {
189
132
  function escapeJsDoc(text) {
190
133
  return text.replace(/\*\//g, "*\\/");
191
134
  }
135
+ //#endregion
136
+ //#region src/json-schema-types.ts
192
137
  /**
193
138
  * Resolve an internal JSON Pointer $ref (e.g. #/definitions/Foo) against the root schema.
194
139
  * Returns null for external URLs or unresolvable paths.
@@ -208,6 +153,13 @@ function resolveRef(ref, root) {
208
153
  return current;
209
154
  }
210
155
  /**
156
+ * Apply OpenAPI 3.0 `nullable: true` to a type result.
157
+ */
158
+ function applyNullable(result, schema) {
159
+ if (result !== "unknown" && result !== "never" && schema?.nullable === true) return `${result} | null`;
160
+ return result;
161
+ }
162
+ /**
211
163
  * Convert a JSON Schema to a TypeScript type string.
212
164
  * This is a direct conversion without going through Zod.
213
165
  */
@@ -305,97 +257,66 @@ function jsonSchemaToTypeString(schema, indent, ctx) {
305
257
  }
306
258
  }
307
259
  /**
308
- * Apply OpenAPI 3.0 `nullable: true` to a type result.
260
+ * Convert a JSON Schema to a TypeScript type declaration.
309
261
  */
310
- function applyNullable(result, schema) {
311
- if (result !== "unknown" && result !== "never" && schema?.nullable === true) return `${result} | null`;
312
- return result;
262
+ function jsonSchemaToType(schema, typeName) {
263
+ return `type ${typeName} = ${jsonSchemaToTypeString(schema, "", {
264
+ root: schema,
265
+ depth: 0,
266
+ seen: /* @__PURE__ */ new Set(),
267
+ maxDepth: 20
268
+ })}`;
313
269
  }
314
270
  /**
315
- * Extract field descriptions from a schema.
316
- * Works with Zod schemas (via .shape) and jsonSchema wrappers (via .properties).
271
+ * Extract field descriptions from a JSON Schema's properties.
317
272
  */
318
- function extractDescriptions(schema) {
273
+ function extractJsonSchemaDescriptions(schema) {
319
274
  const descriptions = {};
320
- const shape = schema.shape;
321
- if (shape && typeof shape === "object") {
322
- for (const [fieldName, fieldSchema] of Object.entries(shape)) {
323
- let s = fieldSchema;
324
- while (!s.description && typeof s.unwrap === "function") s = s.unwrap();
325
- if (s.description) descriptions[fieldName] = s.description;
326
- }
327
- return descriptions;
328
- }
329
- if (isJsonSchemaWrapper(schema)) {
330
- const jsonSchema = extractJsonSchema(schema);
331
- if (jsonSchema?.properties) {
332
- for (const [fieldName, propSchema] of Object.entries(jsonSchema.properties)) if (propSchema && typeof propSchema === "object" && propSchema.description) descriptions[fieldName] = propSchema.description;
333
- }
275
+ if (schema.properties) {
276
+ for (const [fieldName, propSchema] of Object.entries(schema.properties)) if (propSchema && typeof propSchema === "object" && propSchema.description) descriptions[fieldName] = propSchema.description;
334
277
  }
335
278
  return descriptions;
336
279
  }
337
280
  /**
338
- * Safely convert a schema to TypeScript type string.
339
- * Handles Zod schemas (v3/v4) and AI SDK jsonSchema wrappers.
340
- * Returns "unknown" if the schema cannot be represented in TypeScript.
341
- */
342
- function safeSchemaToTs(schema, typeName) {
343
- try {
344
- if (isZodSchema(schema) || isStandardSchema(schema)) {
345
- const jsonSchema = asSchema(schema).jsonSchema;
346
- if (jsonSchema) return `type ${typeName} = ${jsonSchemaToTypeString(jsonSchema, "", {
347
- root: jsonSchema,
348
- depth: 0,
349
- seen: /* @__PURE__ */ new Set(),
350
- maxDepth: 20
351
- })}`;
352
- }
353
- if (isJsonSchemaWrapper(schema)) {
354
- const jsonSchema = extractJsonSchema(schema);
355
- if (jsonSchema) return `type ${typeName} = ${jsonSchemaToTypeString(jsonSchema, "", {
356
- root: jsonSchema,
357
- depth: 0,
358
- seen: /* @__PURE__ */ new Set(),
359
- maxDepth: 20
360
- })}`;
361
- }
362
- return `type ${typeName} = unknown`;
363
- } catch {
364
- return `type ${typeName} = unknown`;
365
- }
366
- }
367
- /**
368
- * Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.
369
- * These types can be included in tool descriptions to help LLMs write correct code.
281
+ * Generate TypeScript type definitions from tool descriptors with JSON Schema.
282
+ * This function has NO dependency on the AI SDK or Zod — it works purely with
283
+ * JSON Schema objects.
284
+ *
285
+ * Use this when you have raw JSON Schema (e.g. from OpenAPI specs, MCP tool
286
+ * definitions, etc.) and don't need the AI SDK.
370
287
  */
371
- function generateTypes(tools) {
288
+ function generateTypesFromJsonSchema(tools) {
372
289
  let availableTools = "";
373
290
  let availableTypes = "";
374
291
  for (const [toolName, tool] of Object.entries(tools)) {
375
292
  const safeName = sanitizeToolName(toolName);
376
- const camelName = toCamelCase(safeName);
293
+ const typeName = toPascalCase(safeName);
377
294
  try {
378
- const inputSchema = "inputSchema" in tool ? tool.inputSchema : tool.parameters;
379
- const outputSchema = "outputSchema" in tool ? tool.outputSchema : void 0;
380
- const description = tool.description;
381
- const inputType = safeSchemaToTs(inputSchema, `${camelName}Input`);
382
- const outputType = outputSchema ? safeSchemaToTs(outputSchema, `${camelName}Output`) : `type ${camelName}Output = unknown`;
295
+ const inputType = jsonSchemaToType(tool.inputSchema, `${typeName}Input`);
296
+ const outputType = tool.outputSchema ? jsonSchemaToType(tool.outputSchema, `${typeName}Output`) : `type ${typeName}Output = unknown`;
383
297
  availableTypes += `\n${inputType.trim()}`;
384
298
  availableTypes += `\n${outputType.trim()}`;
385
- const paramDescs = inputSchema ? extractParamDescriptions(inputSchema) : [];
299
+ const paramLines = (() => {
300
+ try {
301
+ const paramDescs = extractJsonSchemaDescriptions(tool.inputSchema);
302
+ return Object.entries(paramDescs).map(([fieldName, desc]) => `@param input.${fieldName} - ${desc}`);
303
+ } catch {
304
+ return [];
305
+ }
306
+ })();
386
307
  const jsdocLines = [];
387
- if (description?.trim()) jsdocLines.push(escapeJsDoc(description.trim().replace(/\r?\n/g, " ")));
308
+ if (tool.description?.trim()) jsdocLines.push(escapeJsDoc(tool.description.trim().replace(/\r?\n/g, " ")));
388
309
  else jsdocLines.push(escapeJsDoc(toolName));
389
- for (const pd of paramDescs) jsdocLines.push(escapeJsDoc(pd.replace(/\r?\n/g, " ")));
310
+ for (const pd of paramLines) jsdocLines.push(escapeJsDoc(pd.replace(/\r?\n/g, " ")));
390
311
  const jsdocBody = jsdocLines.map((l) => `\t * ${l}`).join("\n");
391
312
  availableTools += `\n\t/**\n${jsdocBody}\n\t */`;
392
- availableTools += `\n\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;
313
+ availableTools += `\n\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;
393
314
  availableTools += "\n";
394
315
  } catch {
395
- availableTypes += `\ntype ${camelName}Input = unknown`;
396
- availableTypes += `\ntype ${camelName}Output = unknown`;
316
+ availableTypes += `\ntype ${typeName}Input = unknown`;
317
+ availableTypes += `\ntype ${typeName}Output = unknown`;
397
318
  availableTools += `\n\t/**\n\t * ${escapeJsDoc(toolName)}\n\t */`;
398
- availableTools += `\n\t${safeName}: (input: ${camelName}Input) => Promise<${camelName}Output>;`;
319
+ availableTools += `\n\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;
399
320
  availableTools += "\n";
400
321
  }
401
322
  }
@@ -406,46 +327,6 @@ ${availableTools}
406
327
  `.trim();
407
328
  }
408
329
  //#endregion
409
- //#region src/normalize.ts
410
- /**
411
- * Strip markdown code fences that LLMs commonly wrap code in.
412
- * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.
413
- */
414
- function stripCodeFences(code) {
415
- const match = code.match(/^```(?:js|javascript|typescript|ts|tsx|jsx)?\s*\n([\s\S]*?)```\s*$/);
416
- return match ? match[1] : code;
417
- }
418
- function normalizeCode(code) {
419
- const trimmed = stripCodeFences(code.trim());
420
- if (!trimmed.trim()) return "async () => {}";
421
- const source = trimmed.trim();
422
- try {
423
- const ast = acorn.parse(source, {
424
- ecmaVersion: "latest",
425
- sourceType: "module"
426
- });
427
- if (ast.body.length === 1 && ast.body[0].type === "ExpressionStatement") {
428
- if (ast.body[0].expression.type === "ArrowFunctionExpression") return source;
429
- }
430
- if (ast.body.length === 1 && ast.body[0].type === "ExportDefaultDeclaration") {
431
- const decl = ast.body[0].declaration;
432
- const inner = source.slice(decl.start, decl.end);
433
- if (decl.type === "FunctionDeclaration" && !decl.id) return `async () => {\nreturn (${inner})();\n}`;
434
- if (decl.type === "ClassDeclaration" && !decl.id) return `async () => {\nreturn (${inner});\n}`;
435
- return normalizeCode(inner);
436
- }
437
- if (ast.body.length === 1 && ast.body[0].type === "FunctionDeclaration") return `async () => {\n${source}\nreturn ${ast.body[0].id?.name ?? "fn"}();\n}`;
438
- const last = ast.body[ast.body.length - 1];
439
- if (last?.type === "ExpressionStatement") {
440
- const exprStmt = last;
441
- return `async () => {\n${source.slice(0, last.start)}return (${source.slice(exprStmt.expression.start, exprStmt.expression.end)})\n}`;
442
- }
443
- return `async () => {\n${source}\n}`;
444
- } catch {
445
- return `async () => {\n${source}\n}`;
446
- }
447
- }
448
- //#endregion
449
- export { generateTypes as n, sanitizeToolName as r, normalizeCode as t };
330
+ export { sanitizeToolName as a, escapeJsDoc as i, jsonSchemaToType as n, toPascalCase as o, jsonSchemaToTypeString as r, generateTypesFromJsonSchema as t };
450
331
 
451
- //# sourceMappingURL=normalize-Dy5d7PfI.js.map
332
+ //# sourceMappingURL=json-schema-types-DoQ0VISs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema-types-DoQ0VISs.js","names":[],"sources":["../src/utils.ts","../src/json-schema-types.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"],"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;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,SAAgB,iBAAiB,MAAsB;AACrD,KAAI,CAAC,KAAM,QAAO;CAGlB,IAAI,YAAY,KAAK,QAAQ,WAAW,IAAI;AAG5C,aAAY,UAAU,QAAQ,mBAAmB,GAAG;AAEpD,KAAI,CAAC,UAAW,QAAO;AAGvB,KAAI,SAAS,KAAK,UAAU,CAC1B,aAAY,MAAM;AAIpB,KAAI,YAAY,IAAI,UAAU,CAC5B,aAAY,YAAY;AAG1B,QAAO;;AAGT,SAAgB,aAAa,KAAa;AACxC,QAAO,IACJ,QAAQ,cAAc,GAAG,WAAW,OAAO,aAAa,CAAC,CACzD,QAAQ,WAAW,WAAW,OAAO,aAAa,CAAC;;;;;AAMxD,SAAS,kBAAkB,IAAoB;CAC7C,MAAM,OAAO,GAAG,WAAW,EAAE;AAC7B,KAAI,QAAQ,MAAQ,SAAS,IAC3B,QAAO,QAAQ,KAAK,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI;AAEnD,QAAO;;;;;;AAOT,SAAgB,UAAU,MAAsB;AAC9C,KAAI,CA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C/B,OAAI,KAAK,aAAa,MAAM,CAC1B,YAAW,KACT,YAAY,KAAK,YAAY,MAAM,CAAC,QAAQ,UAAU,IAAI,CAAC,CAC5D;OAED,YAAW,KAAK,YAAY,SAAS,CAAC;AAExC,QAAK,MAAM,MAAM,WACf,YAAW,KAAK,YAAY,GAAG,QAAQ,UAAU,IAAI,CAAC,CAAC;GAGzD,MAAM,YAAY,WAAW,KAAK,MAAM,QAAQ,IAAI,CAAC,KAAK,KAAK;AAC/D,qBAAkB,YAAY,UAAU;AACxC,qBAAkB,OAAO,SAAS,YAAY,SAAS,oBAAoB,SAAS;AACpF,qBAAkB;UACZ;AACN,qBAAkB,UAAU,SAAS;AACrC,qBAAkB,UAAU,SAAS;AAErC,qBAAkB,iBAAiB,YAAY,SAAS,CAAC;AACzD,qBAAkB,OAAO,SAAS,YAAY,SAAS,oBAAoB,SAAS;AACpF,qBAAkB;;;AAItB,kBAAiB,8BAA8B,eAAe;AAE9D,QAAO;EACP,eAAe;EACf,eAAe;IACb,MAAM"}
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { i as Executor } from "./executor-6RSFUhUk.js";
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+
4
+ //#region src/mcp.d.ts
5
+ /**
6
+ * Wrap an existing MCP server with a single codemode `code` tool.
7
+ *
8
+ * Connects to the upstream server via in-memory transport, discovers its
9
+ * tools, and returns a new MCP server with a `code` tool that exposes
10
+ * all upstream tools as typed methods.
11
+ */
12
+ interface CodeMcpServerOptions {
13
+ server: McpServer;
14
+ executor: Executor;
15
+ }
16
+ declare function codeMcpServer(
17
+ options: CodeMcpServerOptions
18
+ ): Promise<McpServer>;
19
+ interface RequestOptions {
20
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
21
+ path: string;
22
+ query?: Record<string, string | number | boolean | undefined>;
23
+ body?: unknown;
24
+ contentType?: string;
25
+ rawBody?: boolean;
26
+ }
27
+ interface OpenApiMcpServerOptions {
28
+ spec: Record<string, unknown>;
29
+ executor: Executor;
30
+ request: (options: RequestOptions) => Promise<unknown>;
31
+ name?: string;
32
+ version?: string;
33
+ description?: string;
34
+ }
35
+ /**
36
+ * Create an MCP server with search + execute tools from an OpenAPI spec.
37
+ *
38
+ * The search tool lets the LLM query the spec to find endpoints.
39
+ * The execute tool lets the LLM call the API via a user-provided
40
+ * request function that runs on the host (auth never enters the sandbox).
41
+ */
42
+ declare function openApiMcpServer(options: OpenApiMcpServerOptions): McpServer;
43
+ //#endregion
44
+ export {
45
+ CodeMcpServerOptions,
46
+ OpenApiMcpServerOptions,
47
+ RequestOptions,
48
+ codeMcpServer,
49
+ openApiMcpServer
50
+ };
51
+ //# sourceMappingURL=mcp.d.ts.map