-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore (provider-utils): replace zod with standard-schema where possible #6184
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
Conversation
schema: Schema<ELEMENT>, | ||
): OutputStrategy<ELEMENT[], ELEMENT[], AsyncIterableStream<ELEMENT>> => { | ||
const arrayOutputStrategy = <OBJECT>( | ||
schema: Schema<OBJECT>, |
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.
ELEMENT
was on purpose because it is an array element
6cf46ef
to
1d4bb39
Compare
@@ -19,7 +20,7 @@ export type Validator<OBJECT = unknown> = { | |||
* Optional. Validates that the structure of a value matches this schema, | |||
* and returns a typed version of the value if it does. | |||
*/ | |||
readonly validate?: (value: unknown) => ValidationResult<OBJECT>; | |||
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>; |
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 sure if making the validate()
method optionally async could cause any problems down the road, but it made the transition easier.
@@ -105,6 +105,7 @@ export function processUIMessageStream<MESSAGE_METADATA = unknown>({ | |||
if (messageMetadataSchema != null) { | |||
await validateTypes({ | |||
value: mergedMetadata, | |||
// @ts-ignore TODO: Couldn't figure this one out yet ~@gr2m |
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.
@lgrammel if you like have a look at this type error. It's probably something obvious that I'll figure out quickly after some rest.
…://github.com/vercel/ai into v5-gr2m/5766-replace-zod-with-standard-schema
zod
with standard-schema
Thanks for getting it over the line @lgrammel 🙏🏼 |
Background
Standard schema allows validation with any schema library that implements it. While we still need to support specific schema libraries in many places because of the JSONSchema conversion, switching to standard schema support where possible will increase the flexibility of the AI SDK.
Summary
Replace
zod
withstandard-schema
where users can pass their own schemas for validation.Related Issues
Closes #5766