feat(ai): add support for Valibot schemas #3015
Draft
+91
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft PR as there are a few questions that need to be answered before I can finalize the implementation.
The initial idea is to support Valibot for the
parameters
property in addition to Zod. Valibot has seen extreme growth in recent months, increasing the likelihood that users of the AI SDK will want to use Valibot instead of raw JSON Schema or Zod. Our library offers the advantage that the API design is modular, and schemas typically require only a few hundred bytes.To make Valibot a great match with AI tools (we are also in exchange with OpenAI) we added a bunch of new features in the last weeks. Valibot now supports a
title
anddescription
metadata action that is compatible with JSON Schema. Furthermore, we implemented an officialtoJsonSchema
function that reliably converts our schemas to JSON Schema format.Valibot's API seems to be stable. We are just waiting with our v1 RC release as there are efforts in the background to make Zod, Valibot and other schema libraries more compatible with common interface properties, which would result in easier integration of these schema libraries.
This PR adds a
valibotSchema
function to theui-utils
package that works similar tozodSchema
. However, it is unclear to me whether it is preferable to exportvalibotSchema
in theai
package or to integrate it into theasSchema
function. The latter would allow users to pass Valibot schemas directly toparameters
without a wrapper function, resulting in a smoother DX.