Skip to content

Conversation

@agcty
Copy link
Contributor

@agcty agcty commented Dec 9, 2025

Summary

  • Move ai and @ai-sdk/openai from direct dependencies to peer dependencies
  • Add @ai-sdk/react as optional peer dependency (was previously undeclared despite being imported)
  • Allow consumers to control their own AI SDK versions

Problem

Currently, ai and @ai-sdk/openai are pinned as direct dependencies ("ai": "5.0.103"). This causes issues for consumers using different AI SDK versions (e.g., AI SDK 6):

  • Duplicate packages get installed (one for the consumer's code, one for agents)
  • Bundle bloat from including two versions
  • Potential type mismatches when passing messages between consumer code and AIChatAgent

Additionally, @ai-sdk/react is imported in ai-react.tsx but was never declared in package.json, relying on consumers having it installed transitively.

Solution

  • ai: required peer dep (>=5.0.0) - core AI SDK types and functions
  • @ai-sdk/openai: optional peer dep (>=2.0.0) - only needed for codemode feature
  • @ai-sdk/react: optional peer dep (>=1.0.0) - only needed for React hooks

All three packages are also added to devDependencies for local development and testing.

Breaking Changes

Consumers who don't already have ai installed will need to add it explicitly. In practice, anyone using the AI features is already installing ai separately anyway.

Closes #42

🤖 Generated with Claude Code

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: 463ef46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@722

commit: 23a83b2

@whoiskatrin
Copy link
Contributor

@agcty don't merge it just yet, please

agcty and others added 3 commits December 21, 2025 12:02
Move `ai`, `@ai-sdk/openai`, and `@ai-sdk/react` from direct dependencies
to peer dependencies, allowing consumers to control their own versions.

This prevents duplicate package installations when consumers use different
AI SDK versions (e.g., AI SDK 6) and reduces bundle bloat.

- `ai`: required peer dep (>=5.0.0)
- `@ai-sdk/openai`: optional peer dep (only needed for codemode)
- `@ai-sdk/react`: optional peer dep (only needed for React hooks)
  - Note: this package was previously not declared at all despite being
    imported in ai-react.tsx, which could cause issues for consumers

Closes discussion cloudflare#42

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Moved '@ai-sdk/openai' and 'ai' from dependencies to devDependencies and peerDependencies in packages/agents/package.json. Marked 'ai' as an optional peer dependency to improve flexibility for consumers.
@threepointone threepointone merged commit 57b7f2e into cloudflare:main Dec 21, 2025
@github-actions github-actions bot mentioned this pull request Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants