Vercel AI SDK : How can I stream from type-safe data parts from FastApi ?
Unanswered
Darkoplax posted this in #help-forum
I posted this on [GitHub discussions](https://github.com/vercel/ai/discussions/6452) but got barely any reply so would love if anyone tried this out and can help me out
Right now V5 allows type-safe custom data parts but how can I make this happen when streaming from a custom server and using the Data Stream Protocol like recommended in the docs ?
{ message.parts .filter(part => part.type === 'data-weather') // type-safe .map((part, index) => ( <Weather key={index} city={part.data.city} // type-safe weather={part.data.weather} // type-safe status={part.data.status} // type-safe /> )); }
Like can I pick a random tunnel other than the established ones (0 , g , i , 3 etc) to yield to on the server and how to expect it to come typesafe on the frontend ?
Right now V5 allows type-safe custom data parts but how can I make this happen when streaming from a custom server and using the Data Stream Protocol like recommended in the docs ?
// On the server
const stream = createUIMessageStream({
execute: writer => {
// Initial update
writer.write({
type: 'data-weather', // Custom type
id: toolCallId, // ID for updates
data: { city, status: 'loading' }, // Your data
});
// Later, update the same part
writer.write({
type: 'data-weather',
id: toolCallId,
data: { city, weather, status: 'success' },
});
},
}
{ message.parts .filter(part => part.type === 'data-weather') // type-safe .map((part, index) => ( <Weather key={index} city={part.data.city} // type-safe weather={part.data.weather} // type-safe status={part.data.status} // type-safe /> )); }
Like can I pick a random tunnel other than the established ones (0 , g , i , 3 etc) to yield to on the server and how to expect it to come typesafe on the frontend ?