Skip to content

Upgrade ai sdk v6#208

Draft
zboyles wants to merge 54 commits intoget-convex:mainfrom
zboyles:upgrade-ai-sdk-v6
Draft

Upgrade ai sdk v6#208
zboyles wants to merge 54 commits intoget-convex:mainfrom
zboyles:upgrade-ai-sdk-v6

Conversation

@zboyles
Copy link
Contributor

@zboyles zboyles commented Jan 15, 2026

This draft pull request upgrades the @convex-dev/agent package to version 0.6.0, aligning it with AI SDK v6 for improved compatibility and developer clarity. It introduces breaking changes, updates dependencies, and revises internal APIs and documentation to match the new AI SDK v6 standards. The most important changes are grouped at the bottom.

Consider this an extremely rough draft that could use with people testing it. Anyone interested, use the pkg-pr-new below or whatever the most recent version. If you do find yourself installing to help test, follow the Vercel v6 migration guide. I've performed very minimal testing so far and haven't tried functionality like the approval-requested state so please try the new features and provide feedback.

npm i https://pkg.pr.new/zboyles/agent/@convex-dev/agent@e43c4b9

Versioning and Compatibility

  • The package version jumps from 0.3.2 to 0.6.0 to match the AI SDK v6 major version, signaling clear compatibility. This release drops support for AI SDK v5 and requires projects to upgrade their dependencies to v6. [1] [2] [3] [4] [5]

API and Type Updates

  • Updates message and tool invocation types to align with AI SDK v6, reducing the need for casting/adapters in integrations. Internal helpers now use AI SDK v6 request/response shapes and error handling semantics. [1] [2] [3] [4] [5] [6]
  • Removes references to deprecated APIs and updates code to use new type signatures, such as ToolExecutionOptions instead of ToolCallOptions and inputSchema instead of parameters. [1] [2] [3] [4] [5] [6] [7]

Dependency and Example Updates

  • Updates peer and dev dependencies to the latest AI SDK v6-compatible versions. Removes support for OpenRouter provider in examples and updates model selection logic to use new APIs. [1] [2] [3]
  • Updates TypeScript configuration for compatibility with new tooling (moduleResolution: "bundler").

Documentation Improvements

  • Updates documentation to reflect new API usage, such as replacing maxSteps with stopWhen: stepCountIs(...) and updating tool definitions to use inputSchema. [1] [2] [3] [4]

Internal Refactoring and Bugfixes

  • Refactors internal message conversion logic to be asynchronous, fixes handling of tool-result parts, and updates type handling for better robustness. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

These changes collectively ensure that the package is fully compatible with AI SDK v6, simplifies integration, and provides clearer guidance and improved developer experience.

This pull request is a major release (v0.6.0) of the @convex-dev/agent package, aligning its versioning with AI SDK v6 for clearer compatibility. It drops support for AI SDK v5, updates dependencies and types to match the new SDK, and revises documentation and examples to reflect these changes. There are also improvements to tool definitions, internal helper functions, and type usage for better integration and developer experience.

Versioning and Compatibility Updates

  • The package version jumps to 0.6.0 to match AI SDK v6, with clear documentation about the versioning strategy and migration steps. Support for AI SDK v5 is dropped, requiring all projects to upgrade their dependencies before updating this package. (CHANGELOG.md, package.json) [1] [2]

Dependency and Type Updates

  • Peer and dev dependencies are updated to AI SDK v6 and related packages, ensuring compatibility. All references to AI SDK v5 types and APIs are replaced with their v6 equivalents, including changes to model and embedding types. (package.json, example/convex/modelsForDemo.ts) [1] [2] [3] [4]

Tool Definition and Usage Improvements

  • Tool definitions are updated to use inputSchema instead of parameters, and the tool handler options now use ToolExecutionOptions (from AI SDK v6) instead of the deprecated ToolCallOptions. Documentation and examples are revised to demonstrate these changes. (docs/agent-usage.mdx, docs/tools.mdx, src/client/createTool.ts) [1] [2] [3]

Agent Configuration and API Changes

  • The agent configuration now uses stopWhen: stepCountIs(n) instead of maxSteps, and examples are updated to show the new usage pattern. (docs/agent-usage.mdx, docs/getting-started.mdx) [1] [2]

Internal Helper and Type Improvements

  • Internal helpers and type usage are updated to match AI SDK v6 request/response shapes and error handling semantics. The embedding model selection is now centralized via a new getEmbeddingModel method. (src/client/index.ts)

zboyles and others added 17 commits December 24, 2025 12:27
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Document version alignment strategy with AI SDK in CHANGELOG
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
- Update LanguageModelV2 to LanguageModelV3 in mockModel.ts
- Update example type declarations to use LanguageModelV3
- Add embeddingModel to Config (deprecate textEmbeddingModel)
- Update Agent class to support both embeddingModel and textEmbeddingModel
- Remove mode field from generateObject call (deprecated in v6)
- Update search.ts and saveInputMessages.ts to support both embedding fields

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Remove @openrouter/ai-sdk-provider dependency and migrate to AI SDK v3
Trigger pkg pr new build for the AI SDK v6 update
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
…referred key

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Update AI SDK packages to latest versions
@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zboyles
Copy link
Contributor Author

zboyles commented Jan 15, 2026

#202

@nilskroe
Copy link

🔥

sethconvex and others added 8 commits January 16, 2026 07:36
Two fixes:

1. normalizeToolResult in mapping.ts was stripping the isError flag.
   Now preserves isError when transforming tool result parts.

2. createAssistantUIMessage in UIMessages.ts now checks contentPart.isError
   in addition to message.error when determining tool state.

This ensures tool results with isError: true show "output-error" state
instead of incorrectly showing "output-available".

Fixes get-convex#162

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…mpatibility

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
@zboyles
Copy link
Contributor Author

zboyles commented Jan 16, 2026

Merged recent PRs, #211, #212, & #213 from @sethconvex, applying minor compatibility update to support AI SDK v6

@zboyles
Copy link
Contributor Author

zboyles commented Jan 16, 2026

To help test these latest additions, replace your @convex-dev/agent package via:

npm i https://pkg.pr.new/zboyles/agent/@convex-dev/agent@e03ecf6

# or with bun, etc
bun add https://pkg.pr.new/zboyles/agent/@convex-dev/agent@e03ecf6

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
@alioftech
Copy link

Hey this is great. When will it be ready?

zboyles and others added 8 commits January 17, 2026 20:51
…in generated types. Ran `convex codegen --component-dir ./src/component`.
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
…esult output types

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
…plan

Fix AI SDK v6 type errors: tool-call input/args union type and tool-result output types
[WIP] Update createTool to support AI SDK v5 and v6 features
- Implemented handling of `tool-approval-request` and `tool-approval-response` in `deltas.ts` to update tool state accordingly.
- Enhanced tests in `deltas.test.ts` and `toUIMessages.test.ts` to verify the approval workflow, including state transitions for approval requests and responses.
- Updated `UIMessages.ts` to manage tool approval states and responses, ensuring correct state updates for tool calls based on approval outcomes.
@zboyles
Copy link
Contributor Author

zboyles commented Jan 18, 2026

Hey this is great. When will it be ready?

@alioftech
It's difficult to say because it depends on how complete the support is. Some of those earlier PR builds from yesterday would get you in a position where you could update your project to AI SDK v6, including all the providers, without schema, runtime, or type errors. That's because unsupported features would be dropped, similar to how some AI SDK v5 features are dropped in the current stable version of @convex-dev/agent.

That said, the zboyles/ai-sdk-v6/add-tool-approval branch is trying to plug the gaps in tool approval support. The latest commit has the tests passing and I've installed in into my project locally without any schema warnings or type errors (other than the preexisting @convex-dev/rag type errors). I'm about to setup an approval test so we'll see how that goes.

If you want to join in to help test an approval process, install with:

npm i https://pkg.pr.new/zboyles/agent/@convex-dev/agent@502d9d8

Let me know if you get any schema warnings or type errors - and hopefully any success.

And obviously backup and all that 😉

@zboyles
Copy link
Contributor Author

zboyles commented Jan 18, 2026

@alioftech

The latest update has the tool call approval coming through correctly and the AI-Elements components handle the state as you'd expect. I need to have the approval/deny buttons create a tool-approval-response and save/start streaming the message response to finish testing the rest of the flow but I might be done for the night. So far it looks promising.

Here's the relevant section from the AI SDK v6 docs, we just need to try to send the message via our Convex Action and the new type should now be supported in the message validator.

import { type ToolApprovalResponse } from 'ai';

const approvals: ToolApprovalResponse[] = [];

for (const part of result.content) {
  if (part.type === 'tool-approval-request') {
    const response: ToolApprovalResponse = {
      type: 'tool-approval-response',
      approvalId: part.approvalId,
      approved: true, // or false to deny
      reason: 'User confirmed the command', // Optional context for the model
    };
    approvals.push(response);
  }
}

// add approvals to messages
messages.push({ role: 'tool', content: approvals });

There's also the message deduplication issue I remember reading in another issue so you could have the UIMessage[] array contain two messages with the same tool call and one is the input-available state but that should be an easy fix.

npm i https://pkg.pr.new/zboyles/agent/@convex-dev/agent@d0a161c
image

zboyles and others added 5 commits January 18, 2026 20:40
…tToolApprovals`. Without the fix, the tool call was being filtered out because it had no tool-result, even though it had an approval response - which caused the SDK to fail at line 91 in `ai/src/generate-text/collect-tool-approvals.ts`.
…result errors since stored messages have the complete data.
… tool approval, as stored messages contain complete context.
Tool approval flow is working to the point a call is approved, assuming the user sends the tool approval response (save message/start streaming), this will automatically execute the tool and save the results to messages and stops the response before sharing the results with the model.

Need to investigate continuing the stream as in multi-step tool calls.
@zboyles
Copy link
Contributor Author

zboyles commented Jan 19, 2026

@ianmacartney @sethconvex The approval flow works correctly, when needsApproval is set to true or is a function that returns true, the approval process begins and assuming the UI supports it - ie using AI-Elements - the user can approve or reject the tool call. The approval process is handled by sending a tool-approval-response tool message (save message + start streaming) and this has the tool run or not, with the approval and optional tool results saved to the messages table however the streaming stops unlike multi-step responses. How might either of you handle continuing the streaming response, is it possible or must this manually be triggered AFTER the approval message is sent and streamed and tool executed and results saved to messages?

The AI SDK has the helper function addToolApprovalResponse, perhaps it's a convention we could use to put everything together, assuming it's possible?

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 21, 2026

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/agent/@convex-dev/agent@208

commit: 3875c45

@sethconvex
Copy link
Contributor

I'll be taking a look at this pr today @zboyles what outstanding tasks do you think are left to get it over the finish line?

@zboyles
Copy link
Contributor Author

zboyles commented Jan 22, 2026

Hey @sethconvex,

The MVP work is essentially done, with the build and tests completing without errors, the validators all setup with unions for schema backwards compatibility for existing data, and createTool has been updated to support passing all current AI SDK v6 arguments. The remaining tasks relate to the nice-to-have features that can be added in future updates.

Remaining Questions (Nice-to-have)

The one open item I'd really like to improve prior to a merge is tool call approval continuation. Technically tool approvals are functional however the execution stops at an inconvenient time.

When a user approves a tool call, it executes and results are saved to messages, but the streaming stops there. Unlike regular multi-step tool calls, the model doesn't automatically continue responding after the results are added.

If you have a chance and could take a look at it, I'd appreciate it. The AI SDK has an optional helper function addToolApprovalResponse, and if it were determined necessary/possible to package - saving the approval response + ensure continued streaming - it's addition to the Agent class would fit the current convention perfectly.

The other high priority feature, but one that can wait for a future update, is streaming data parts. I was hoping to look into it today but was held up with other tasks.

Other Issues

  • The @convex-dev/rag package needs to be updated to support the new v3 providers from @ai-sdk/provider@3
  • There's a failure to the example test example/convex/setup.test.ts unrelated to this PR - it's missing a dependency to @convex-dev/workpool

@delta575
Copy link

When a user approves a tool call, it executes and results are saved to messages, but the streaming stops there. Unlike regular multi-step tool calls, the model doesn't automatically continue responding after the results are added.

@zboyles this could be related vercel/ai#11966

@sethconvex sethconvex mentioned this pull request Jan 25, 2026
5 tasks
@sethconvex
Copy link
Contributor

I've built an rc branch on top of this, and have a WIP PR that adds tool approval #217

@zboyles
Copy link
Contributor Author

zboyles commented Jan 31, 2026

@delta575 I think the issue was caused by the native process handling the tool execution as it would add the result without the tool approval response tool content part. The AI SDK docs tell you to just add it but they have functions that modify the message, in our situation, it was being added as a separate message and staying separate. Seth made a function that executes the tool then puts all the tool content parts together in the same message.

sethconvex added a commit that referenced this pull request Feb 20, 2026
## Summary
Upgrades `@convex-dev/agent` to support AI SDK v6, dropping support for AI SDK v5.
Fixes #202 

Based on @zboyles's work in #208, merged with latest main and lint/typecheck fixes.

## Breaking Changes
- Requires AI SDK v6 (`ai@^6.0.35`)
- Drops support for AI SDK v5
- Package version jumps to 0.6.0 to align with AI SDK major version

## Key Changes
- Updates message and tool invocation types to align with AI SDK v6
- Adds tool approval workflow support (`tool-approval-request`, `tool-approval-response`)
- `inputSchema` replaces `parameters` in tool definitions
- `input` replaces `args` in tool calls (with backwards compat)
- `mediaType` replaces `mimeType` (with backwards compat)
- New `embeddingModel` config option (deprecates `textEmbeddingModel`)

## Migration
See the [AI SDK v6 migration guide](https://ai-sdk.dev/docs/migration-guides/migration-guide-6-0) for details on AI SDK changes.

## Test plan
- [x] `npm run typecheck` passes
- [x] `npm run lint` passes
- [x] All 212 tests pass
- [ ] Manual testing with real providers (OpenAI, Anthropic)
- [ ] Test tool approval workflow

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

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Tool approval workflow (request/response/denial), richer tool hooks, inputSchema/input support, and needsApproval.
  * Unified embeddingModel support and LanguageModel V3 mock behavior.

* **Breaking Changes**
  * Bumped to 0.6.0; AI SDK v6 required.
  * textEmbeddingModel → embeddingModel; args → input (deprecated).
  * mimeType → mediaType for file metadata; stopWhen/stepCountIs replaces maxSteps.

* **Bug Fixes**
  * Improved streaming, async message handling, error suppression, and orphaned tool-message handling.

* **Documentation**
  * Added MIGRATION.md, updated usage and agent/docs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

6 participants