Skip to content

Update createTool to support AI SDK v5 & 6 features like tool approval#6

Merged
zboyles merged 28 commits intoupgrade-ai-sdk-v6from
zboyles/ai-sdk-v6/add-tool-approval
Jan 19, 2026
Merged

Update createTool to support AI SDK v5 & 6 features like tool approval#6
zboyles merged 28 commits intoupgrade-ai-sdk-v6from
zboyles/ai-sdk-v6/add-tool-approval

Conversation

@zboyles
Copy link
Owner

@zboyles zboyles commented Jan 17, 2026

This pull request introduces a major refactor and extension of the createTool API in src/client/createTool.ts, making tool definitions more flexible and feature-rich. The changes focus on improving type safety, enabling more advanced tool behaviors (such as approval workflows and custom output conversion), and supporting additional metadata for tools.

Tool API Extensions and Refactor

Tool Definition Flexibility and Type Safety

  • Refactored the tool input and output definition types to support both legacy and new schema properties (inputSchema/args, execute/handler), improving backwards compatibility and type safety. Added utility types (NeverOptional, ToolInputProperties, ToolOutputPropertiesCtx) for more robust type handling.

Advanced Tool Behaviors

  • Added support for tool approval workflows via the new needsApproval property, which can be a boolean or a function that determines if a tool call requires approval before execution. [1] [2]
  • Added support for strict mode, input examples, and provider-specific options, allowing more control over tool invocation and integration with providers.

Output Handling Improvements

  • Added an optional toModelOutput conversion function to allow custom mapping of tool results to model output, enhancing integration with language models and streamlining result formatting. [1] [2]

Internal API Changes

  • Refactored the internal logic of createTool to handle the new options and behaviors, including proper error handling when required properties are missing and correct binding of context for event handlers and output conversion. [1] [2]

Type Import Updates

  • Updated type imports to reflect the new usage and type requirements, ensuring all relevant types (ToolResultOutput, ModelMessage, etc.) are available in the module.

These changes make it easier to define complex tools for AI agents, support advanced workflows, and ensure better type safety and extensibility.

…and context handling

- Introduced new types for tool execution and approval functions.
- Added support for input examples, strict mode, and tool approval logic.
- Updated the function signature to accommodate new properties and ensure compatibility with existing functionality.
Copilot AI review requested due to automatic review settings January 17, 2026 03:29
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 17, 2026

Open in StackBlitz

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

commit: f07fdd5

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the createTool API to support AI SDK v5 & 6 features, including tool approval workflows, custom output conversion, and improved type safety. The changes maintain backwards compatibility while adding significant new functionality.

Changes:

  • Added support for tool approval workflows via needsApproval property (boolean or function)
  • Added optional toModelOutput conversion function for custom result formatting
  • Introduced new properties: title, strict, inputExamples, and providerOptions
  • Refactored type definitions to support both legacy (args/handler) and new (inputSchema/execute) API with proper type safety
  • Added utility types (NeverOptional, ToolInputProperties, ToolOutputPropertiesCtx) for robust type handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zboyles
Copy link
Owner Author

zboyles commented Jan 17, 2026

@copilot I need you to go through all, non generated, references to mimeType under src/component/* and update them to use mediaType while trying to maintain backwards compatibility where possible. The main goal is to resolve the type errors with all these functions but avoid forcing people to update their functions to use mediaType.

Copy link

Copilot AI commented Jan 17, 2026

@zboyles I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 15 commits January 17, 2026 06:09
- Updated component schema to use optional mediaType and mimeType
- Updated files.ts addFile mutation to accept both mediaType and mimeType
- Updated client files.ts to use mediaType when calling component
- Updated getFile to support both mediaType and mimeType from database
- Updated mapping.ts to return mediaType instead of mimeType
- Maintained backwards compatibility throughout

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
- Updated all file part definitions in generated component.ts
- Changed mimeType from required to optional
- Added mediaType as optional field
- Resolved all TypeScript type errors related to mimeType/mediaType

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

Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
Co-authored-by: zboyles <2215540+zboyles@users.noreply.github.com>
…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
@zboyles
Copy link
Owner Author

zboyles commented Jan 18, 2026

@copilot Create a plan with one or more approaches to add an ability for additional data to be streamed alongside a streaming response as per Streaming Custom Data. The approaches should focus on best practice and ease of use. Maybe it could be a callback that's triggered on every step starting or perhaps there's a way it can run in parallel. Don't limit your investigation to my random thoughts.

Copy link

Copilot AI commented Jan 18, 2026

@zboyles I've opened a new pull request, #9, to work on those changes. Once the pull request is ready, I'll request review from you.

- 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.
…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.
@zboyles zboyles merged commit 3875c45 into upgrade-ai-sdk-v6 Jan 19, 2026
1 of 2 checks passed
@zboyles zboyles deleted the zboyles/ai-sdk-v6/add-tool-approval branch January 19, 2026 03:17
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