|
| 1 | +--- |
| 2 | +'@tanstack/ai-persistence': minor |
| 3 | +'@tanstack/ai-client': minor |
| 4 | +--- |
| 5 | + |
| 6 | +Server-authoritative reconnect is now automatic and keyed on the thread, not the run. |
| 7 | + |
| 8 | +A chat's durable identity is its **thread**; run ids are ephemeral (a single turn |
| 9 | +can span several runs via interrupts or tool continuations), so basing reconnect |
| 10 | +on a client-cached run id goes stale the moment a turn rolls to a new run. This |
| 11 | +moves the whole reconnect story onto the stable thread id, resolved by the server. |
| 12 | + |
| 13 | +- **`RunStore.findActiveRun(threadId)`** — new optional, feature-detected store |
| 14 | + method returning the most recent `'running'` run for a thread. Implemented by |
| 15 | + the in-memory reference backend and covered by the conformance testkit, so any |
| 16 | + adapter that provides it is held to the same invariants (most-recent-running |
| 17 | + wins, thread-scoped, null when idle). |
| 18 | +- **`reconstructChat` now returns `{ messages, activeRun, interrupts }`** (was a |
| 19 | + bare message array): the stored transcript as UI messages, a cursor to an |
| 20 | + in-flight run if one exists, and any pending human-in-the-loop interrupts (tool |
| 21 | + approvals / waits) plus the run they paused. It reads the active run before the |
| 22 | + transcript so observing "no active run" guarantees the transcript is final |
| 23 | + (closing a finish-window race). |
| 24 | +- **`@tanstack/ai-client` hydrates itself on mount.** In server-authoritative |
| 25 | + mode (`persistence: true`) the client caches no transcript and no run |
| 26 | + pointer: on mount `useChat`/`ChatClient` calls the connection's new |
| 27 | + `hydrate(threadId)` (a JSON GET against the same endpoint), paints the returned |
| 28 | + transcript, and — if a run is in flight — tails it via the existing `joinRun` |
| 29 | + durability replay. A reload and the same thread opened on another device are the |
| 30 | + identical, server-resolved path. No loader, no `initialMessages`, no |
| 31 | + `initialResumeSnapshot`, no app-side fetching required. |
| 32 | +- **Interrupts reconstruct from the server too.** A paused approval (a tool with |
| 33 | + `needsApproval`) is restored from `reconstructChat`'s `interrupts` exactly as a |
| 34 | + persisted resume snapshot would be, so a reload — or another device — re-prompts |
| 35 | + the same approve/reject decision and resumes the run it paused. Previously the |
| 36 | + pending interrupt was only recoverable from client storage, so a fresh client |
| 37 | + showed the paused tool call with no way to resolve it. |
| 38 | + |
| 39 | +Apps keep the single GET endpoint they already have (durability replay when a |
| 40 | +resume cursor is present, else `reconstructChat`); everything else is handled by |
| 41 | +the hook. |
0 commit comments