You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@ai-sdk/codemod

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/codemod

The AI SDK provides automated code transformations (codemods) to help upgrade your codebase when features are deprecated, removed, or changed between versions.

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
272
-9.63%
Maintainers
0
Weekly downloads
 
Created
Source

AI SDK Codemods

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.

Quick Start

To run all codemods:

npx @ai-sdk/codemod upgrade

This will automatically detect and transform all applicable code patterns in your project.

Run Version-Specific Codemods

To run codemods for a specific version:

npx @ai-sdk/codemod v4

npx @ai-sdk/codemod v5

npx @ai-sdk/codemod upgrade

Run Individual Codemods

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 .

Available Codemods

v4 Codemods (v3 → v4 Migration)

CodemodDescription
v4/remove-ai-stream-methods-from-stream-text-resultTransforms v4/remove ai stream methods from stream text result
v4/remove-anthropic-facadeTransforms v4/remove anthropic facade
v4/remove-await-streamobjectTransforms v4/remove await streamobject
v4/remove-await-streamtextTransforms v4/remove await streamtext
v4/remove-deprecated-provider-registry-exportsTransforms v4/remove deprecated provider registry exports
v4/remove-experimental-ai-fn-exportsTransforms v4/remove experimental ai fn exports
v4/remove-experimental-message-typesTransforms v4/remove experimental message types
v4/remove-experimental-streamdataTransforms v4/remove experimental streamdata
v4/remove-experimental-toolTransforms v4/remove experimental tool
v4/remove-experimental-useassistantTransforms v4/remove experimental useassistant
v4/remove-google-facadeTransforms v4/remove google facade
v4/remove-isxxxerrorTransforms v4/remove isxxxerror
v4/remove-metadata-with-headersTransforms v4/remove metadata with headers
v4/remove-mistral-facadeTransforms v4/remove mistral facade
v4/remove-openai-facadeTransforms v4/remove openai facade
v4/rename-format-stream-partTransforms v4/rename format stream part
v4/rename-parse-stream-partTransforms v4/rename parse stream part
v4/replace-baseurlTransforms v4/replace baseurl
v4/replace-continuation-stepsTransforms v4/replace continuation steps
v4/replace-langchain-toaistreamTransforms v4/replace langchain toaistream
v4/replace-nanoidTransforms v4/replace nanoid
v4/replace-roundtrips-with-maxstepsTransforms v4/replace roundtrips with maxsteps
v4/replace-token-usage-typesTransforms v4/replace token usage types
v4/rewrite-framework-importsTransforms v4/rewrite framework imports

v5 Codemods (v4 → v5 Migration)

CodemodDescription
v5/flatten-streamtext-file-propertiesTransforms v5/flatten streamtext file properties
v5/import-LanguageModelV2-from-provider-packageTransforms v5/import LanguageModelV2 from provider package
v5/migrate-to-data-stream-protocol-v2Transforms v5/migrate to data stream protocol v2
v5/move-image-model-maxImagesPerCallTransforms v5/move image model maxImagesPerCall
v5/move-langchain-adapterTransforms v5/move langchain adapter
v5/move-provider-optionsTransforms v5/move provider options
v5/move-react-to-ai-sdkTransforms v5/move react to ai sdk
v5/move-ui-utils-to-aiTransforms v5/move ui utils to ai
v5/remove-experimental-wrap-language-modelTransforms v5/remove experimental wrap language model
v5/remove-get-ui-textTransforms v5/remove get ui text
v5/remove-openai-compatibilityTransforms v5/remove openai compatibility
v5/remove-sendExtraMessageFieldsTransforms v5/remove sendExtraMessageFields
v5/rename-converttocoremessages-to-converttomodelmessagesTransforms v5/rename converttocoremessages to converttomodelmessages
v5/rename-core-message-to-model-messageTransforms v5/rename core message to model message
v5/rename-datastream-transform-streamTransforms v5/rename datastream transform stream
v5/rename-languagemodelv1providermetadataTransforms v5/rename languagemodelv1providermetadata
v5/rename-max-tokens-to-max-output-tokensTransforms v5/rename max tokens to max output tokens
v5/rename-message-to-ui-messageTransforms v5/rename message to ui message
v5/rename-mime-type-to-media-typeTransforms v5/rename mime type to media type
v5/rename-pipedatastreamtoresponse-to-pipeuimessagestreamtoresponseTransforms v5/rename pipedatastreamtoresponse to pipeuimessagestreamtoresponse
v5/rename-reasoning-propertiesTransforms v5/rename reasoning properties
v5/rename-reasoning-to-reasoningTextTransforms v5/rename reasoning to reasoningText
v5/rename-request-optionsTransforms v5/rename request options
v5/rename-todatastreamresponse-to-touimessagestreamresponseTransforms v5/rename todatastreamresponse to touimessagestreamresponse
v5/rename-tool-parameters-to-inputschemaTransforms v5/rename tool parameters to inputschema
v5/replace-bedrock-snake-caseTransforms v5/replace bedrock snake case
v5/replace-content-with-partsTransforms v5/replace content with parts
v5/replace-experimental-provider-metadataTransforms v5/replace experimental provider metadata
v5/replace-generatetext-text-propertyTransforms v5/replace generatetext text property
v5/replace-image-type-with-file-typeTransforms v5/replace image type with file type
v5/replace-llamaindex-adapterTransforms v5/replace llamaindex adapter
v5/replace-oncompletion-with-onfinalTransforms v5/replace oncompletion with onfinal
v5/replace-provider-metadata-with-provider-optionsTransforms v5/replace provider metadata with provider options
v5/replace-rawresponse-with-responseTransforms v5/replace rawresponse with response
v5/replace-redacted-reasoning-typeTransforms v5/replace redacted reasoning type
v5/replace-simulate-streamingTransforms v5/replace simulate streaming
v5/replace-textdelta-with-textTransforms v5/replace textdelta with text
v5/replace-usage-token-propertiesTransforms v5/replace usage token properties
v5/restructure-file-stream-partsTransforms v5/restructure file stream parts
v5/restructure-source-stream-partsTransforms v5/restructure source stream parts
v5/rsc-packageTransforms v5/rsc package

CLI Options

Commands

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

Global Options

  • --dry - Preview changes without applying them
  • --print - Print transformed code to stdout
  • --verbose - Show detailed transformation logs

Examples

# 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

Best Practices

Before Running Codemods

  • Backup your code - Commit all changes to version control
  • Review current deprecation warnings - Fix any obvious issues first
  • Update dependencies - Ensure you're on the target AI SDK version

After Running Codemods

  • Review changes - Check the diff to understand what was transformed
  • Test your application - Ensure everything works as expected
  • Handle edge cases - Some complex patterns may need manual fixes
  • Run type checking - Fix any TypeScript errors that remain

Troubleshooting

If a codemod doesn't transform some code:

  • Check file extensions - Codemods work on .ts, .tsx, .js, .jsx files
  • Review patterns - Complex or unusual code patterns may need manual updates
  • Run specific codemods - Try running individual codemods for targeted fixes
  • Check documentation - Some changes may not have automated codemods

Contributing

Adding New Codemods

  • Create the codemod in src/codemods/
  • Add test fixtures in src/test/__testfixtures__/
  • Create tests in src/test/
  • Update the bundle in src/lib/upgrade.ts

Testing Codemods

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

Support

  • Documentation: AI SDK Migration Guides
  • Issues: GitHub Issues
  • Community: Discord

Version Compatibility

  • AI SDK 5.0: All codemods in this package
  • AI SDK 4.x: Use @ai-sdk/codemod@1.x
  • AI SDK 3.x: Manual migration required

For more detailed migration information, see the AI SDK 5.0 Migration Guide.

Keywords

ai

FAQs

Package last updated on 31 Jul 2025

Did you know?

Socket

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.

Install

Related posts