Skip to content

feat add onParts support for chat API and processing functions #6385

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

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

Conversation

NoelJacob
Copy link

Currently this is made for my personal use. It's a hook for any transformation when each part of stream is recieved. Also made prepareBody support async functions. Currently only onFilePart is added and only on react.

Would this feature be appreciated? If so I can make a proper PR.

@lgrammel
Copy link
Collaborator

thanks - in ai sdk 5 you can implement your own ChatTransport and transform incoming UIMessageStreamPart streams.

@NoelJacob
Copy link
Author

I saw the blog but any docs for it? Where can learn what functions to use and stuff?

@zhm
Copy link

zhm commented May 21, 2025

@NoelJacob I got a custom onPart working in v5 with this custom transport that overrides the default transport.

https://gist.github.com/zhm/ae4ede57ead9712820340e2f1248c21a

A few notes:

  • adds onPart param to the chat store factory
  • UIDataPartSchemas and InferUIDataParts types don't seem to be exported (yet), but I might be missing something
  • Would be far less boilerplate if defaultChatStore() accepted an optional transport
  • Perhaps onPart should just be baked into defaultChatStore with onFinish, seems fairly reasonable

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