fix(chat): export standalone reviver for workflow-safe deserialization#257
Conversation
Importing the Chat instance into Vercel Workflow files pulls in adapter packages that depend on Node.js modules, which aren't available in the workflow sandbox. This adds a standalone `reviver` function exported from `chat` that deserializes Thread/Channel/Message objects without needing a Chat instance or its adapter dependencies. Also updates the durable chat sessions guide to use the standalone reviver and dynamic bot imports inside step functions. Closes #243 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
bensabic
left a comment
There was a problem hiding this comment.
Thanks for working through the Workflow sandbox issue, @haydenbleasel! The standalone reviver direction makes sense, but I don’t think this is quite ready to merge yet.
I found two follow-ups that still need to be addressed:
-
ChannelImplhas the same lazy round-trip bug asThreadImpl. Achat:Channelrevived via the new standalonereviverstill can’t be serialized again without a registered singleton, becausetoJSON()derivesadapterNamefromthis.adapter.nameinstead of preserving the stored adapter name. This makes the new helper incomplete for channel payloads too. -
The docs are now internally inconsistent around the new API. The durable session guide points readers to the Chat API for
reviver, butapps/docs/content/docs/api/chat.mdxstill only documentsbot.reviver(), not the new root export.
If you fix the lazy serialization path by preserving adapterName on round-trip and update the API docs to cover the new export, this should be in a better shape.
Summary
reviverfunction exported fromchatthat deserializes Thread/Channel/Message objects without requiring a Chat instance (and its adapter Node.js dependencies)Chat.reviver()to delegate to the standalone function internallyreviverfromchatand dynamically importbotinside"use step"functionsCloses #243
Test plan
pnpm validatepasses (knip, lint, typecheck, tests, build)reviverinserialization.test.ts