Converting messages to AI-SDK format (v1 Client)
When using
client.listThreadMessages to retrieve message history, the messages are now returned as MastraDBMessage.
To use them to populate initial messages in useChat they need to be converted to AISdkV5 format, because it expects the messages to be UI_MESSAGE.
It seems the method needed to do that exists, but is currently not exported (only the chunk-based conversion for streaming is).
Would this be the correct way or am I missing something?
I just tried to replicate what I found in the playground UI and adapt it.
Thanks in advance for any help!7 Replies
My bad...
Had an old
moduleResolution setting in tsconfig.json and the export I was looking for was moved to a subpath >.<
For anyone looking - this is the correct path in v1:
๐ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10380
๐ If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly.
๐ Thank you for helping us improve Mastra!
Hey @Sebastian, i guess we haven't documented this well anywhere!!
Curious from your point of view, where in the docs you thought you'd find this?
@Abhi Aiyer I guess this won't happen to many people and would either happen while upgrading to v1 or for newcomers who are involved in legacy projects.
For people upgrading it could be helpful to have a troubleshooting section in the migration guide.
For newcomers it's a harder question. I think the Client SDKs are especially prone to this type of problem so it could make sense to have it close to the usage docs (e.g. on this page).
I've seen some libraries enforce settings like strict TypeScript config or module settings in code and either
process.exit() on detection or emitting a prominent warning. I have not looked into it, but maybe that could even be enforced during package install.
I should've known better because I've seen that problem a few times already. But other people might lose hours or days investigating issues like that, so an early exit would be a nicer solution than just documentation.Streaming -> Overview would be nice to have there.. i think in beta docs i found it under Storage.. but i was looking for it for forever
I was talking to @Tyler , we did have this at one point documented, i think we had some issue in docs state. I'll see if we can get it restored
GitHub
Add missing docs by abhiaiyer91 ยท Pull Request #10394 ยท mastra-ai...
Add missing docs about converting to aisdk v5 format