Skip to content
Source
Sign inSign up
TanStack/ai

codemods

README.md

TanStack AI codemods

jscodeshift transforms for migrating between API versions of @tanstack/ai and friends.

Each codemod lives in its own subdirectory and is named after the migration it covers. In 1.0 the old names that these codemods replace are removed, so run the codemods as part of the upgrade.

Available codemods

CodemodMigrates
ag-ui-complianceClient-side renames introduced by the AG-UI client/server compliance release: body → forwardedProps on useChat / ChatClient / updateOptions, Svelte's updateBody → updateForwardedProps, and chat({ conversationId }) → chat({ threadId }).
move-sampling-to-model-optionsMoves root temperature / topP / maxTokens off chat() / ai() / generate() / createChatOptions() into provider-native modelOptions, renamed per provider (with ollama nesting under options).

Running a codemod

You can run any codemod via npx jscodeshift directly against a remote URL — no clone or install needed in your project:

npx jscodeshift \
  --parser=tsx \
  -t https://raw.githubusercontent.com/TanStack/ai/main/codemods/ag-ui-compliance/transform.ts \
  src/**/*.{ts,tsx}

Add --dry --print to preview the rewrite without modifying files.

Running locally (this repo)

If you've cloned this repo (e.g., to apply a codemod to the bundled examples), use the top-level pnpm script:

pnpm codemod:ag-ui-compliance "examples/**/*.{ts,tsx}"

Authoring a new codemod

  1. Add a sibling directory codemods/<your-codemod>/.
  2. Implement the transform in transform.ts — follow ag-ui-compliance/transform.ts for structure (import-source gating, conflict-safe property renames).
  3. Add fixtures under __testfixtures__/<case>.input.{ts,tsx} and matching .output.{ts,tsx}. Cover at least one positive case per transformation, one negative case (file should be left alone), and one conflict case (legacy + canonical names both present).
  4. Add tests in transform.test.ts using the expectFixture helper.
  5. Run pnpm --filter @tanstack/ai-codemods test.
  6. Document the codemod in its own README.md and add a row to the table above.