Skip to content

feat(codemode): extract utilities into AI-free main entry point#1102

Merged
mattzcarey merged 2 commits intomainfrom
feat/codemode-extract-utils-without-ai-dep
Mar 13, 2026
Merged

feat(codemode): extract utilities into AI-free main entry point#1102
mattzcarey merged 2 commits intomainfrom
feat/codemode-extract-utils-without-ai-dep

Conversation

@mattzcarey
Copy link
Contributor

@mattzcarey mattzcarey commented Mar 13, 2026

Summary

The main entry point (@cloudflare/codemode) no longer requires the ai or zod peer dependencies. They are now optional and only needed when importing from @cloudflare/codemode/ai.

This lets projects like Cloudflare MCP use the tested utility functions (sanitizeToolName, normalizeCode, generateTypesFromJsonSchema, executors) without pulling in the AI SDK.

Changes

  • New utils.ts — pure helpers with zero deps: sanitizeToolName, toCamelCase, escapeJsDoc, escapeStringLiteral, quoteProp
  • New json-schema-types.ts — JSON Schema → TypeScript conversion + generateTypesFromJsonSchema (no AI SDK)
  • Renamed types.tstool-types.ts — AI-dependent generateTypes + ToolDescriptor/ToolDescriptors types
  • Updated ai.ts — now also exports generateTypes, ToolDescriptor, ToolDescriptors
  • Updated package.jsonai and zod peer deps marked optional: true, added json-schema as direct dep
  • Reorganized testsutils.test.ts, tool-types.test.ts, json-schema-types.test.ts (11 new tests for the AI-free APIs)
  • Updated README — documents new module structure, AI-free usage, and generateTypesFromJsonSchema

Breaking change

generateTypes and ToolDescriptor/ToolDescriptors types moved from the main entry to @cloudflare/codemode/ai:

// Before
import { generateTypes } from "@cloudflare/codemode";

// After
import { generateTypes } from "@cloudflare/codemode/ai";

Module structure

Module Requires ai/zod Exports
@cloudflare/codemode No sanitizeToolName, normalizeCode, generateTypesFromJsonSchema, jsonSchemaToType, DynamicWorkerExecutor, ToolDispatcher
@cloudflare/codemode/ai Yes createCodeTool, generateTypes, ToolDescriptor, ToolDescriptors

Source file layout

src/
├── utils.ts              # sanitizeToolName, escapeJsDoc, quoteProp, etc. (zero deps)
├── normalize.ts          # normalizeCode (acorn only)
├── json-schema-types.ts  # JSON Schema → TypeScript (no ai/zod)
├── executor.ts           # Executor, DynamicWorkerExecutor, ToolDispatcher
├── tool-types.ts         # generateTypes, ToolDescriptor (requires ai/zod)
├── tool.ts               # createCodeTool (requires ai/zod)
├── index.ts              # main entry — AI-free exports
├── ai.ts                 # ./ai entry — AI SDK exports
└── tests/
    ├── utils.test.ts
    ├── normalize.test.ts
    ├── json-schema-types.test.ts
    ├── schema-conversion.test.ts
    ├── tool-types.test.ts
    ├── tool.test.ts
    └── executor.test.ts

Test plan

  • All 164 tests pass across 7 test files
  • Build output verified: dist/index.js has no ai imports, only dist/ai.js does
  • Codex 5.3 review — addressed all findings (json-schema dep, leaky API, test gaps)
  • Verified codemode-server and cloudflare-mcp can import normalizeCode from the main entry without needing ai

Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: ccb9cfa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/codemode Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@threepointone
Copy link
Contributor

pass ci so I can merge this?

@mattzcarey
Copy link
Contributor Author

pass ci so I can merge this?

on it boss

@mattzcarey mattzcarey marked this pull request as ready for review March 13, 2026 14:19
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1102

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1102

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1102

hono-agents

npm i https://pkg.pr.new/hono-agents@1102

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1102

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1102

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1102

commit: cbc565e

devin-ai-integration[bot]

This comment was marked as resolved.

Move sanitizeToolName, JSON Schema conversion utilities, and a new
generateTypesFromJsonSchema function into a separate sanitize.ts module
with zero AI SDK dependencies. The main entry point (import from
"@cloudflare/codemode") no longer requires the ai or zod peer
dependencies — they are now optional and only needed when importing
from "@cloudflare/codemode/ai".

BREAKING: generateTypes and ToolDescriptor/ToolDescriptors types moved
from the main entry to "@cloudflare/codemode/ai".
@mattzcarey mattzcarey force-pushed the feat/codemode-extract-utils-without-ai-dep branch 2 times, most recently from 60e3c31 to 0cae03b Compare March 13, 2026 17:12
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey mattzcarey force-pushed the feat/codemode-extract-utils-without-ai-dep branch 2 times, most recently from 805e182 to 15f44a5 Compare March 13, 2026 17:56
Split the package so the main entry point has zero dependency on `ai`/`zod`:

- `utils.ts` — sanitizeToolName, toCamelCase, and string helpers
- `json-schema-types.ts` — JSON Schema → TypeScript type generation
- `tool-types.ts` — AI SDK dependent type generation (moved from types.ts)

The main entry (`@cloudflare/codemode`) now exports sanitizeToolName,
normalizeCode, generateTypesFromJsonSchema, jsonSchemaToType, and the
executor classes. The `/ai` entry point keeps createCodeTool and
generateTypes which require the ai/zod peer deps.

Also fixes duplicate type declarations when extractParamDescriptions
throws, and moves json-schema from runtime deps to @types/json-schema
in devDependencies.
@mattzcarey mattzcarey force-pushed the feat/codemode-extract-utils-without-ai-dep branch from 15f44a5 to ccb9cfa Compare March 13, 2026 17:57
@mattzcarey mattzcarey merged commit f07ef51 into main Mar 13, 2026
1 check passed
@mattzcarey mattzcarey deleted the feat/codemode-extract-utils-without-ai-dep branch March 13, 2026 18:11
@github-actions github-actions bot mentioned this pull request Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants