ai-persistence/server

Persist server-side chat transcripts, runs, and interrupts with TanStack AI middleware.

3.1k|316|Updated Oct 8, 2025
One-click install
npx skills add https://github.com/TanStack/ai --skill ai-persistence-server
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-persistence/server
Source: https://github.com/TanStack/ai/tree/main/packages/ai-persistence/skills/ai-persistence/server
Command: npx skills add https://github.com/TanStack/ai --skill ai-persistence-server

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/ai, @tanstack/ai-persistence.

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.

Frequently Asked Questions about ai-persistence/server

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I persist TanStack AI chat history on the server?

Add withPersistence(persistence) from @tanstack/ai-persistence to the chat middleware array and pass threadId and runId from chatParamsFromRequest. The middleware writes the canonical transcript, run status, and interrupts to your backend store at each lifecycle boundary.

How do I reload a chat thread for the client in TanStack AI?

Call reconstructChat(persistence, request, { authorize }) from @tanstack/ai-persistence in a GET handler. It returns messages, activeRun, and pending interrupts for the threadId, and the authorize callback prevents unauthorized transcript access.

Does withPersistence reconnect a dropped stream?

No, withPersistence handles state persistence, not delivery durability. Reconnecting a dropped stream requires resumable-stream infrastructure, which is a separate concern from saving transcripts and run records.

Why does withPersistence throw when I add an interrupts store?

The interrupts store requires the runs store to track run status for interrupt durability. If you provide interrupts without runs, withPersistence throws; add a runs implementation or remove the interrupts store.

What happens to a run when the client disconnects in TanStack AI?

onAbort writes 'aborted' only for explicit cancels or non-detachable runs. For detachable runs backed by a sandbox or journal, the record stays 'running' so a later attach can take over, so never assume a disconnect finalizes the run.