Skip to content

feat(codemode): add TanStack AI integration#1149

Merged
threepointone merged 2 commits intomainfrom
tanstack-codemode
Mar 22, 2026
Merged

feat(codemode): add TanStack AI integration#1149
threepointone merged 2 commits intomainfrom
tanstack-codemode

Conversation

@threepointone
Copy link
Contributor

@threepointone threepointone commented Mar 22, 2026

Summary

  • Adds @cloudflare/codemode/tanstack-ai — a new entry point for using codemode with TanStack AI's chat() instead of the Vercel AI SDK's streamText()
  • Extracts framework-agnostic resolveProvider into resolve.ts so the main entry (@cloudflare/codemode) no longer pulls in the ai package at runtime
  • Exports CodeInput/CodeOutput types from @cloudflare/codemode/ai to fix downstream TS2742 errors (e.g. in @cloudflare/think)

New exports from @cloudflare/codemode/tanstack-ai

Export Purpose
createCodeTool(options) Returns a TanStack ServerTool via toolDefinition().server()
tanstackTools(tools, name?) Converts TanStackTool[] into a ToolProvider with pre-generated types
generateTypes(tools, namespace?) Generates TypeScript type definitions from TanStack AI tools
resolveProvider(provider) Framework-agnostic provider resolver (re-export)

Internal refactoring

  • src/resolve.ts — framework-agnostic filterTools, extractFns, resolveProvider (no ai dep)
  • src/shared.tsDEFAULT_DESCRIPTION, CreateCodeToolOptions, CodeInput, CodeOutput, normalizeProviders
  • src/tool.ts — now imports base helpers from resolve.ts, layers AI SDK schema validation on top

Test plan

  • 249 tests pass across 11 test files (4 new tests added for coverage gaps)
  • npm run check passes (sherif, export checks, oxfmt, oxlint, typecheck — all 65 projects)
  • @cloudflare/think builds successfully (verified TS2742 fix)
  • New test files: resolve.test.ts (13 tests), tanstack-ai.test.ts (31 tests), shared.test.ts (4 tests)
  • Covers: Zod schemas, plain JSON Schema tools, definition-only tools, needsApproval filtering, multiple namespaces, generateTypesFromRecord fallback, raw ToolProviderTools input

Made with Cursor


Open with Devin

Add a new TanStack AI entry point and related refactorings.

- New entry: @cloudflare/codemode/tanstack-ai (implements createCodeTool, tanstackTools, generateTypes, resolveProvider) so codemode can be used with @tanstack/ai's chat().
- Add framework-agnostic resolve.ts and shared.ts to extract provider resolution and shared constants/helpers (so the main entry no longer pulls in AI SDK runtime deps).
- Implement tanstack-ai.ts with type generation, tool wrapping, and ServerTool creation plus comprehensive tests for tanstack integration, resolve, and shared helpers.
- Update package.json exports/peerDeps and build script to include the new entrypoint and optional @tanstack/ai peer dep.
- Update README with usage docs and examples for TanStack AI.

This change adds the TanStack AI integration and internal cleanup to avoid pulling AI SDK dependencies into the core entry point.
The shared.ts refactor moved these types to an internal chunk,
causing downstream packages (e.g. @cloudflare/think) to fail
with TS2742 when inferring return types of createCodeTool.

Made-with: Cursor
@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2026

🦋 Changeset detected

Latest commit: ad0c214

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 Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 22, 2026

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1149

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: ad0c214

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

provider.types ?? generateTypesFromRecord(filtered, providerName);
typeBlocks.push(types);

resolvedProviders.push({ name: providerName, fns: extractFns(filtered) });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 positionalArgs dropped when building ResolvedProviders in createCodeTool

The new createCodeTool in tanstack-ai.ts builds ResolvedProvider objects at line 247 without forwarding the positionalArgs flag from the source ToolProvider. The DynamicWorkerExecutor relies on positionalArgs to choose between a single-arg proxy (async (args) =>, executor.ts:271) and a rest-args proxy (async (...args) =>, executor.ts:260). Without it, providers like stateTools from @cloudflare/shell/workers (which sets positionalArgs: true at packages/shell/src/workers.ts:34) will use the wrong proxy: multi-argument calls like state.writeFile("/path", "content") will silently lose all arguments after the first, because the single-arg proxy only captures one parameter.

Pre-existing identical bug in AI SDK version

The same bug exists at packages/codemode/src/tool.ts:105 (resolvedProviders.push({ name, fns: extractFns(filtered) })) — this is pre-existing but actively triggered by packages/think/src/tools/execute.ts:163-166 which passes stateToolsFromBackend() through createCodeTool. Both resolveProvider functions (tool.ts:82 and resolve.ts:63) correctly forward positionalArgs, but neither createCodeTool implementation uses resolveProvider internally.

Suggested change
resolvedProviders.push({ name: providerName, fns: extractFns(filtered) });
const resolved: ResolvedProvider = { name: providerName, fns: extractFns(filtered) };
if (provider.positionalArgs) resolved.positionalArgs = true;
resolvedProviders.push(resolved);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@threepointone threepointone merged commit 47ce125 into main Mar 22, 2026
3 checks passed
@threepointone threepointone deleted the tanstack-codemode branch March 22, 2026 15:49
@github-actions github-actions bot mentioned this pull request Mar 22, 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.

1 participant