Open History to see the last commit
1# TanStack AI codemods
2
3[jscodeshift](https://github.com/facebook/jscodeshift) transforms for migrating between API versions of `@tanstack/ai` and friends.
4
5Each codemod lives in its own subdirectory and is named after the migration it covers. Codemods are **opt-in modernizations** — the deprecated APIs they replace continue to work, so you can run them at your own pace.
6
7## Available codemods
8
9| Codemod | Migrates |
10| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11| [`ag-ui-compliance`](./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 })`. |
12| [`move-sampling-to-model-options`](./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`). |
13
14## Running a codemod
15
16You can run any codemod via `npx jscodeshift` directly against a remote URL — no clone or install needed in your project:
17
18```bash
19npx jscodeshift \
20 --parser=tsx \
21 -t https://raw.githubusercontent.com/TanStack/ai/main/codemods/ag-ui-compliance/transform.ts \
22 src/**/*.{ts,tsx}
23```
24
25Add `--dry --print` to preview the rewrite without modifying files.
26
27## Running locally (this repo)
28
29If you've cloned this repo (e.g., to apply a codemod to the bundled examples), use the top-level pnpm script:
30
31```bash
32pnpm codemod:ag-ui-compliance "examples/**/*.{ts,tsx}"
33```
34
35## Authoring a new codemod
36
371. Add a sibling directory `codemods/<your-codemod>/`.
382. Implement the transform in `transform.ts` — follow `ag-ui-compliance/transform.ts` for structure (import-source gating, conflict-safe property renames).
393. 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).
404. Add tests in `transform.test.ts` using the `expectFixture` helper.
415. Run `pnpm --filter @tanstack/ai-codemods test`.
426. Document the codemod in its own `README.md` and add a row to the table above.