What problem does it solve?
Server-side AI chat applications need durable, authoritative storage of conversation history, run lifecycle state, and pending tool approvals so threads survive restarts, work across devices, and support human-in-the-loop flows.
Core Features & Use Cases
- Authoritative transcript persistence: The
withPersistence middleware writes the canonical message transcript, run status, and interrupts to a backend store on every lifecycle boundary.
- Interrupt and resume durability: Pending tool approvals are recorded and gated, so clients must submit matching resume batches before a run continues.
- Thread hydration:
reconstructChat loads messages, active runs, and pending interrupts by threadId for server-authoritative clients, with an authorize hook for multi-user security.
- Use Case: Build a multi-device support chatbot where the server owns history, users can approve tool calls after reconnecting, and any device can reload the full thread.
Quick Start
Add the withPersistence middleware from @tanstack/ai-persistence to my chat endpoint so conversation state is saved to my backend store.