Durable stream transport, proxy and AI SDK adapters.
-
transport-- protocol-agnostic transport library with proxy-aware fetch client and storage utilities -
proxy-- node service that proxies backend API requests via Durable Streams -
ai-transport-- Vercel AI SDK adapter -
tanstack-ai-transport-- TanStack AI adapter
Durable sessions use a TanStack DB collection as the data model. The durable stream is the source of truth, with messages materialized via a derived live query pipeline.
@electric-sql/durable-session-- framework-agnostic client, collections, and materialization@electric-sql/react-durable-session-- React bindings (useDurableChathook)@electric-sql/durable-session-proxy-- HTTP proxy for session management and agent invocation
The proxy, transport and ai-db packages should be protocol and reactivity framework agnostic.
- SDK adapters
- configure the chat UIs to use the durable fetchClient
- fetchClient
- routes the API request via the proxy
- the proxy
- proxies the request to the backend API
- writes the response to a Durable Stream as JSON events
- sends back stream urls to the fetchClient
- fetchClient
- consumes the Durable Stream
- emits the data stream as a standard response
Currently message persistence is all handled by the SDK adapters and localStorage.
There's no server-side persistence or specific protocol-aware proxy services.
- SDK adapters
- configure the chat UIs to reconnect with specific headers
- fetchClient
- records active generations in localStorage by default
- looks for headers like
X-Resume-Active-Generation - if present, resumes the active generation when requested
The transport layer uses Durable Streams with a single-stream JSON event protocol:
Event Types:
// Data chunk (wraps raw SSE from upstream API)
{ type: "data", payload: string }
// Stream completed successfully
{ type: "done", finishReason: string }
// Stream error
{ type: "error", message: string }Stream URL Pattern:
{durableStreamsUrl}/stream/{sessionId}/{requestId}
Resumption:
- Client stores stream URL and offset in localStorage
- On reconnect, resumes from stored offset (or replays from start for page reload)
- Single offset value (replaces the previous dual-stream handle + offset pattern)
See docs/DurableSessions.md for details.
Standard AI SDK demos adapted to use Durable Streams transport:
vercel-ai-sdk-durable-transport-- Vercel AI SDK + Durable Transporttanstack-ai-durable-transport-- TanStack AI + Durable Transport
Standard TanStack AI demo adapted to use TanStack DB and Durable Session:
tanstack-ai-durable-session-- TanStack AI + DB + Durable Session
These demos use Durable Streams as the backend:
pnpm i
pnpm build
pnpm backend:up # Starts Durable Streams server on port 3001
# In one terminal
pnpm dev:proxy
# In another terminal, run the default demo (vercel-ai-sdk-durable-transport)
pnpm dev:demo
# Or specify a demo by name
pnpm dev:demo tanstack-ai-durable-transportThis demo uses the Durable Streams server:
pnpm i
pnpm build
pnpm backend:up # Starts Durable Streams server on port 3001
# In one terminal
pnpm dev:session-proxy
# In another terminal
pnpm dev:demo tanstack-ai-durable-session| Script | Services | Port |
|---|---|---|
pnpm backend:up |
Durable Streams | 3001 |
vercel-ai-sdk-durable-transport: http://localhost:5173tanstack-ai-durable-transport: http://localhost:5174tanstack-ai-durable-session: http://localhost:5175
Start long generations. Disconnect, reconnect, refresh the page, etc.
With Durable Sessions, you can extend to show multi-user, multi-agent, multi-tab, multi-device etc.