-
Notifications
You must be signed in to change notification settings - Fork 75
chore: Upgrade AI SDK from 4.x to 6.x #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Upgrade to AI SDK 6.x to support MCP protocol version 2025-11-25. Package changes: - ai: ^4.3.16 → ^6.0.64 - agents: ^0.2.23 → ^0.3.6 - @ai-sdk/anthropic: ^1.2.12 → ^3.0.33 - @ai-sdk/openai: ^1.3.22 → ^3.0.23 - @ai-sdk/react: ^1.2.12 → ^3.0.66 - @ai-sdk/mcp: (new) ^1.0.16 - @modelcontextprotocol/sdk: ^1.21.0 → ^1.25.3 API migrations: - MCP client imports: "ai" → "@ai-sdk/mcp" - Type rename: LanguageModelV1 → LanguageModel - generateText/streamText: maxSteps → stopWhen(stepCountIs(N)) - tool() API: parameters → inputSchema, execute(params) → execute(input) - Tool call capture: toolCall.args → toolCall.input Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
26f48ec to
72cd2af
Compare
The AI SDK 6.x migration renamed toolCall.args to toolCall.input. This was correctly updated in callEmbeddedAgent.ts but missed in the test client's agent.ts, causing logTool to receive undefined instead of the actual tool arguments. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Migrate the cloudflare chat UI to be compatible with AI SDK 5+/6.x: **Client-side changes:** - Replace `Message` type with `UIMessage` (requires `parts` array) - Migrate `useChat` to new API: - Use `DefaultChatTransport` with `api` option - Manage input state manually (removed from hook) - `append` → `sendMessage` - `reload` → `regenerate` - `handleInputChange`/`handleSubmit` → manual handlers - Update all components to use `UIMessage` type - Import from `@ai-sdk/react` instead of `ai/react` **Server-side changes:** - `maxTokens` → `maxOutputTokens` - `toDataStreamResponse` → `toUIMessageStreamResponse` **Dependency fixes:** - Add pnpm override for `@modelcontextprotocol/sdk: ^1.25.3` to fix version mismatch between direct dep (1.25.3) and `agents` package (1.25.2) which caused TypeScript type conflicts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Additional fixes for UIMessage type changes in AI SDK 5+/6.x:
- Remove `content` property usage (UIMessage always uses `parts` array)
- Replace `data` with `metadata` for custom message metadata
- Remove `createdAt` property (no longer in UIMessage interface)
- Update tool part handling to support AI SDK 6 format where tool
type is `tool-${toolName}` with properties directly on the part
- Remove legacy content fallback in processMessages
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactored the isValidMessage callback to use early return pattern, which fixes the TypeScript error where msg.parts was narrowed to type 'never' in the else branch. Since UIMessage.parts is a required property, the previous if/else structure was flagged by TypeScript as having unreachable code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
packages/mcp-cloudflare/src/client/components/chat/chat-message.tsx
Outdated
Show resolved
Hide resolved
Addresses Cursor Bugbot feedback: 1. Legacy tool-invocation parts from persisted messages (AI SDK 4/5 format) now render correctly instead of being silently ignored 2. Tool output conversion now properly handles MCP-format objects with content arrays, strings, and other objects - avoiding [object Object] Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Legacy AI SDK 4/5 tool-invocation parts have structure:
{ type: "tool-invocation", toolInvocation: {...} }
The previous fix incorrectly cast the entire part to ChatToolInvocation
instead of accessing part.toolInvocation. This caused undefined values
for toolName, toolCallId, args, state, and result.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added migration logic to convert persisted messages from AI SDK 4.x format (using `content` string) to AI SDK 6 format (using `parts` array). This prevents silent data loss when users upgrade, as their chat history will be automatically migrated instead of being filtered out. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
packages/mcp-cloudflare/src/client/components/chat/chat-message.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
…igration 1. Fixed state mapping for AI SDK 6 tool parts to correctly handle 'partial-call' state during streaming, preventing message persistence failures and incorrect UI rendering. 2. Updated migration function to preserve metadata from both legacy 'data' property and new 'metadata' property, preventing loss of custom properties like type, hasSlashCommands, simulateStreaming. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing-guidelines
testing-guidelines: Found 2 issues (2 medium)
⏱ 433.7s · 2.1M in / 34.8k out · $4.38
| return msg as UIMessage; | ||
| } | ||
|
|
||
| export function usePersistedChat(isAuthenticated: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 No tests for usePersistedChat hook entry point (high confidence)
The usePersistedChat hook is exported and used in the Chat component as a user entry point, but has no test coverage. Per guidelines, every entry point should have at least one basic test.
warden: testing-guidelines
| } | ||
|
|
||
| // Migrate legacy messages (AI SDK 4.x format with `content`) to new format (with `parts`) | ||
| function migrateMessage(msg: LegacyMessage): UIMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 No tests for migrateMessage migration function (high confidence)
The new migrateMessage function handles SDK version migration for persisted messages. This is a pure function with complex logic for converting legacy format to new format - ideal for unit testing to ensure migration correctness.
warden: testing-guidelines
Upgrade to AI SDK 6.x to support MCP protocol version
2025-11-25.This upgrade enables compatibility with
agents@0.3.5+which is required for the latest MCP protocol features.Package Changes
aiagents@ai-sdk/anthropic@ai-sdk/openai@ai-sdk/react@ai-sdk/mcp@modelcontextprotocol/sdkAPI Migrations
experimental_createMCPClientmoved from"ai"to"@ai-sdk/mcp"LanguageModelV1→LanguageModel(now a union type)maxSteps: N→stopWhen: stepCountIs(N)parameters→inputSchema,execute(params)→execute(input, options)toolCall.args→toolCall.inputThis branch includes a revert of #759 as the base, then applies the full AI SDK 6.x migration on top.