Skip to content

fix(js/ai): fixed GenerateStreamResponse output typing #1827

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Feb 4, 2025

No description provided.

Copy link
Collaborator

@mbleigh mbleigh left a comment

Choose a reason for hiding this comment

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

  1. I think the stream type needs to be a separate generic (in array format, stream chunks are z.infer<O>[] for example)
  2. I'd prefer that the output response be entirely unaware of Zod -- it should be perhaps GenerateStreamResponse<O = unknown, S = Partial<O>>. Use z.infer when declaring the type from somewhere that already has Zod types.

@mbleigh
Copy link
Collaborator

mbleigh commented Feb 5, 2025

  1. I think the stream type needs to be a separate generic (in array format, stream chunks are z.infer<O>[] for example)
  2. I'd prefer that the output response be entirely unaware of Zod -- it should be perhaps GenerateStreamResponse<O = unknown, S = Partial<O>>. Use z.infer when declaring the type from somewhere that already has Zod types.

Thinking on it more, I think it is actually always a partial of the output schema...you might be able to get away with:

O extends any[] ? Partial<O[number]>[] : Partial<O>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants