-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add converter from type CoreMessage
to type Message
#4875
Comments
I strongly recommend not saving core messages. UI messages contain a lot of information that is required for correct persistence of UI state. |
I agree, but I argue it is better to save the messages state in DB as |
Would saving UI messages work for you if they included attachments? |
yep, but I'm personally not happy making my DB structure based on currently experimental attachments structure of UIMessage. I'm currently using something similar to |
I support @yudistiraashadi on making // if you begin with core message and want a ui message...
const coreMessage = ...
const uiMessage = convertCoreMessageToUiMessage(coreMessage) // fn suggested (not present in sdk as today)
const parsedUiMessage = uiMessageSchema.parse(uiMessage) // zod schema suggested (not present in sdk as today)
// opposite...
const uiMessage = ...
const coreMessage = convertToCoreMessage(uiMessage) // fn present in sdk as today
const parsedCoreMessage = coreMessageSchema.parse(coreMessage) // zod schema present in sdk as today |
Feature Description
Reason
For persistence data which we save messages data to the Database, I think saving the data as
Array<CoreMessage>
makes more sense instead of saving it asArray<Message>
as suggested on AI SDK docs.Array<CoreMessage>
is used on the server which communicates with the DB, and it is also easier to add files as context like this example.Solution
Add a converter from
CoreMessage
toMessage
to make it easier to translate the types. in AI Chatbot template they have a function calledconvertToUIMessages()
link which helps translate their DB which looks like a rawCoreMessage
toMessage
that is consumed by the UI. I think we can build something similar to that.Use Cases
On server
On client
Additional context
No response
The text was updated successfully, but these errors were encountered: