codemods
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
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#
| Codemod | Migrates |
|---|---|
ag-ui-compliance | Client-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-options | Moves 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#
- Add a sibling directory
codemods/<your-codemod>/. - Implement the transform in
transform.ts— followag-ui-compliance/transform.tsfor structure (import-source gating, conflict-safe property renames). - 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). - Add tests in
transform.test.tsusing theexpectFixturehelper. - Run
pnpm --filter @tanstack/ai-codemods test. - Document the codemod in its own
README.mdand add a row to the table above.