
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
@ai-sdk/codemod
Advanced tools
The AI SDK provides automated code transformations (codemods) to help upgrade your codebase when features are deprecated, removed, or changed between versions.
The AI SDK provides automated code transformations (codemods) to help upgrade your codebase when features are deprecated, removed, or changed between versions.
Codemods are transformations that run on your codebase programmatically, allowing you to easily apply many changes without manually editing every file.
To run all codemods:
npx @ai-sdk/codemod upgrade
This will automatically detect and transform all applicable code patterns in your project.
To run codemods for a specific version:
npx @ai-sdk/codemod v4
npx @ai-sdk/codemod v5
npx @ai-sdk/codemod upgrade
To run a specific codemod:
npx @ai-sdk/codemod <codemod-name> <path>
Examples:
# Transform a specific file
npx @ai-sdk/codemod v4/remove-experimental-ai-fn-exports src/app/api/chat/route.ts
# Transform a directory
npx @ai-sdk/codemod v4/replace-baseurl src/lib/
# Transform entire project
npx @ai-sdk/codemod v5/rename-format-stream-part .
Codemod | Description |
---|---|
v4/remove-ai-stream-methods-from-stream-text-result | Transforms v4/remove ai stream methods from stream text result |
v4/remove-anthropic-facade | Transforms v4/remove anthropic facade |
v4/remove-await-streamobject | Transforms v4/remove await streamobject |
v4/remove-await-streamtext | Transforms v4/remove await streamtext |
v4/remove-deprecated-provider-registry-exports | Transforms v4/remove deprecated provider registry exports |
v4/remove-experimental-ai-fn-exports | Transforms v4/remove experimental ai fn exports |
v4/remove-experimental-message-types | Transforms v4/remove experimental message types |
v4/remove-experimental-streamdata | Transforms v4/remove experimental streamdata |
v4/remove-experimental-tool | Transforms v4/remove experimental tool |
v4/remove-experimental-useassistant | Transforms v4/remove experimental useassistant |
v4/remove-google-facade | Transforms v4/remove google facade |
v4/remove-isxxxerror | Transforms v4/remove isxxxerror |
v4/remove-metadata-with-headers | Transforms v4/remove metadata with headers |
v4/remove-mistral-facade | Transforms v4/remove mistral facade |
v4/remove-openai-facade | Transforms v4/remove openai facade |
v4/rename-format-stream-part | Transforms v4/rename format stream part |
v4/rename-parse-stream-part | Transforms v4/rename parse stream part |
v4/replace-baseurl | Transforms v4/replace baseurl |
v4/replace-continuation-steps | Transforms v4/replace continuation steps |
v4/replace-langchain-toaistream | Transforms v4/replace langchain toaistream |
v4/replace-nanoid | Transforms v4/replace nanoid |
v4/replace-roundtrips-with-maxsteps | Transforms v4/replace roundtrips with maxsteps |
v4/replace-token-usage-types | Transforms v4/replace token usage types |
v4/rewrite-framework-imports | Transforms v4/rewrite framework imports |
Codemod | Description |
---|---|
v5/flatten-streamtext-file-properties | Transforms v5/flatten streamtext file properties |
v5/import-LanguageModelV2-from-provider-package | Transforms v5/import LanguageModelV2 from provider package |
v5/migrate-to-data-stream-protocol-v2 | Transforms v5/migrate to data stream protocol v2 |
v5/move-image-model-maxImagesPerCall | Transforms v5/move image model maxImagesPerCall |
v5/move-langchain-adapter | Transforms v5/move langchain adapter |
v5/move-provider-options | Transforms v5/move provider options |
v5/move-react-to-ai-sdk | Transforms v5/move react to ai sdk |
v5/move-ui-utils-to-ai | Transforms v5/move ui utils to ai |
v5/remove-experimental-wrap-language-model | Transforms v5/remove experimental wrap language model |
v5/remove-get-ui-text | Transforms v5/remove get ui text |
v5/remove-openai-compatibility | Transforms v5/remove openai compatibility |
v5/remove-sendExtraMessageFields | Transforms v5/remove sendExtraMessageFields |
v5/rename-converttocoremessages-to-converttomodelmessages | Transforms v5/rename converttocoremessages to converttomodelmessages |
v5/rename-core-message-to-model-message | Transforms v5/rename core message to model message |
v5/rename-datastream-transform-stream | Transforms v5/rename datastream transform stream |
v5/rename-languagemodelv1providermetadata | Transforms v5/rename languagemodelv1providermetadata |
v5/rename-max-tokens-to-max-output-tokens | Transforms v5/rename max tokens to max output tokens |
v5/rename-message-to-ui-message | Transforms v5/rename message to ui message |
v5/rename-mime-type-to-media-type | Transforms v5/rename mime type to media type |
v5/rename-pipedatastreamtoresponse-to-pipeuimessagestreamtoresponse | Transforms v5/rename pipedatastreamtoresponse to pipeuimessagestreamtoresponse |
v5/rename-reasoning-properties | Transforms v5/rename reasoning properties |
v5/rename-reasoning-to-reasoningText | Transforms v5/rename reasoning to reasoningText |
v5/rename-request-options | Transforms v5/rename request options |
v5/rename-todatastreamresponse-to-touimessagestreamresponse | Transforms v5/rename todatastreamresponse to touimessagestreamresponse |
v5/rename-tool-parameters-to-inputschema | Transforms v5/rename tool parameters to inputschema |
v5/replace-bedrock-snake-case | Transforms v5/replace bedrock snake case |
v5/replace-content-with-parts | Transforms v5/replace content with parts |
v5/replace-experimental-provider-metadata | Transforms v5/replace experimental provider metadata |
v5/replace-generatetext-text-property | Transforms v5/replace generatetext text property |
v5/replace-image-type-with-file-type | Transforms v5/replace image type with file type |
v5/replace-llamaindex-adapter | Transforms v5/replace llamaindex adapter |
v5/replace-oncompletion-with-onfinal | Transforms v5/replace oncompletion with onfinal |
v5/replace-provider-metadata-with-provider-options | Transforms v5/replace provider metadata with provider options |
v5/replace-rawresponse-with-response | Transforms v5/replace rawresponse with response |
v5/replace-redacted-reasoning-type | Transforms v5/replace redacted reasoning type |
v5/replace-simulate-streaming | Transforms v5/replace simulate streaming |
v5/replace-textdelta-with-text | Transforms v5/replace textdelta with text |
v5/replace-usage-token-properties | Transforms v5/replace usage token properties |
v5/restructure-file-stream-parts | Transforms v5/restructure file stream parts |
v5/restructure-source-stream-parts | Transforms v5/restructure source stream parts |
v5/rsc-package | Transforms v5/rsc package |
npx @ai-sdk/codemod@beta <command> [options]
Available Commands:
upgrade
- Apply all codemods (v4 + v5)v4
- Apply v4 codemods (v3 → v4 migration)v5
- Apply v5 codemods (v4 → v5 migration)<codemod-name> <path>
- Apply specific codemod--dry
- Preview changes without applying them--print
- Print transformed code to stdout--verbose
- Show detailed transformation logs# Preview all changes without applying
npx @ai-sdk/codemod@beta --dry upgrade
# Preview v4 changes only
npx @ai-sdk/codemod@beta --dry v4
# Preview v5 changes only
npx @ai-sdk/codemod@beta --dry v5
# Show verbose output for specific codemod
npx @ai-sdk/codemod@beta --verbose v4/remove-experimental-ai-fn-exports src/
# Print transformed code for specific codemod
npx @ai-sdk/codemod@beta --print v4/replace-baseurl src/config.ts
If a codemod doesn't transform some code:
.ts
, .tsx
, .js
, .jsx
filessrc/codemods/
src/test/__testfixtures__/
src/test/
src/lib/upgrade.ts
First, navigate to the codemod directory:
cd packages/codemod
Then run the tests:
# Run all tests
pnpm test
# Run specific codemod tests
pnpm test <codemod-name>
# Test in development
pnpm test:watch
@ai-sdk/codemod@1.x
For more detailed migration information, see the AI SDK 5.0 Migration Guide.
FAQs
The AI SDK provides automated code transformations (codemods) to help upgrade your codebase when features are deprecated, removed, or changed between versions.
The npm package @ai-sdk/codemod receives a total of 245 weekly downloads. As such, @ai-sdk/codemod popularity was classified as not popular.
We found that @ai-sdk/codemod demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.