Feature Request: Allow Filtering/Customizing Streamed Chunk Types in mergeIntoDataStream
Unanswered
Black Catbird posted this in #help-forum
Black CatbirdOP
Re: the AI SDK’s streaming stuff.
I’m using
For my use case, I just wanna send the final text and maybe usage, but I don’t wanna leak all the tool-calling internals to the frontend.
Right now, I’m working around it by basically re-implementing the merge logic (stole the code from https://github.com/vercel/ai/blob/main/packages/ai/core/generate-text/stream-text.ts#L1629) and filtering out those chunk types myself, but it feels hacky.
Is there a reason those are always included?
Would it be aligned with your pipeline goal if we introduce chunk filtering mechanism or overriding
Happy to PR this if it’s something you’d want!
Any suggestions is appreciated, Thanks a ton! 🙏
I’m using
mergeIntoDataStream
to pipe results to my client (similar to the example here https://mastra.ai/en/docs/frameworks/agentic-uis/ai-sdk#createdatastream), but I noticed it always includes tool-call
and tool-result
chunks in the stream. There’s no way to turn those off (unlike the flags for reasoning or sources).For my use case, I just wanna send the final text and maybe usage, but I don’t wanna leak all the tool-calling internals to the frontend.
Right now, I’m working around it by basically re-implementing the merge logic (stole the code from https://github.com/vercel/ai/blob/main/packages/ai/core/generate-text/stream-text.ts#L1629) and filtering out those chunk types myself, but it feels hacky.
Is there a reason those are always included?
Would it be aligned with your pipeline goal if we introduce chunk filtering mechanism or overriding
formatDataStreamPart
in it? Basically I am trying to give more freedom to opt-in or out of this different chunktype.Happy to PR this if it’s something you’d want!
Any suggestions is appreciated, Thanks a ton! 🙏