8000 feat: enforce zod/json-ness of propSchema prop by alecf · Pull Request #276 · tambo-ai/tambo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: enforce zod/json-ness of propSchema prop #276

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

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

alecf
Copy link
Contributor
@alecf alecf commented Apr 4, 2025

No description provided.

Copy link
vercel bot commented Apr 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
showcase ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2025 9:46pm

Copy link
@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

The changes improve schema handling but introduce duplicated checks for Zod schemas and error handling that only logs issues without a clear fallback. By consolidating these checks and improving error handling, the code’s maintainability and clarity can be enhanced.

Summary of changes

Summary of Changes

  • component-metadata.ts: Updated the type of propsSchema to accept both Zod schemas (z.ZodTypeAny) and JSON schemas (JSONSchema7), and deprecated the propsDefinition property with an added JSDoc @deprecated annotation.
  • tambo-registry-provider.tsx: Replaced inline props schema serialization with a helper function getSerializedProps. This function now handles conversion of props definitions by detecting whether the provided schema is a Zod schema or a JSON schema, with added helper functions isJSONSchema and isZodSchema.

Comment on lines +206 to +209
if (propsSchema instanceof ZodSchema || propsSchema instanceof z.ZodObject) {
return zodToJsonSchema(propsSchema);
}

Copy link

Choose a reason for hiding this comment

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

The check for propsSchema being a Zod schema is duplicated: first using instanceof ZodSchema || instanceof z.ZodObject and then via the isZodSchema helper. This duplication reduces clarity and increases maintenance overhead. Consider consolidating these checks to streamline the logic.

Merge the Zod schema detection into a single check – for instance, always use isZodSchema and then perform the conversion with proper error handling. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.

Comment on lines +210 to +218
if (isZodSchema(propsSchema)) {
try {
return zodToJsonSchema(propsSchema);
} catch (error) {
console.error(
`Error converting ${name} props schema to JSON Schema:`,
error,
);
}
Copy link

Choose a reason for hiding this comment

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

Within the try-catch block for converting a Zod schema (lines 210-218), the catch clause only logs the error without returning any fallback value, which leads to a generic error throw later. This approach might obscure the underlying conversion issue.

Consider either rethrowing the caught error or returning a specific fallback value to make troubleshooting easier. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.

@charliecreates charliecreates bot removed the request for review from CharlieHelps April 4, 2025 21:46
@alecf alecf merged commit a717c9f into main Apr 4, 2025
6 checks passed
@alecf alecf deleted the alecf/enforce-zod-or-json-schema branch April 4, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0