v0.131.0
Added
-
ObjectStreamResponse
andObjectStreamFromResponse
serialization functions for using server-generated object streams in web applications.Server example:
export async function POST(req: Request) { const { myArgs } = await req.json(); const objectStream = await streamObject({ // ... }); // serialize the object stream to a response: return new ObjectStreamResponse(objectStream); }
Client example:
const response = await fetch("/api/stream-object-openai", { method: "POST", body: JSON.stringify({ myArgs }), }); // deserialize (result object is simpler than the full response) const stream = ObjectStreamFromResponse({ schema: itinerarySchema, response, }); for await (const { partialObject } of stream) { // do something, e.g. setting a React state }
Changed
-
breaking change: rename
generateStructure
togenerateObject
andstreamStructure
tostreamObject
. Related names have been changed accordingly. -
breaking change: the
streamObject
result stream contains additional data. You need to usestream.partialObject
or destructuring to access it:const objectStream = await streamObject({ // ... }); for await (const { partialObject } of objectStream) { console.clear(); console.log(partialObject); }
-
breaking change: the result from successful
Schema
validations is stored in thevalue
property (before:data
).