Persistence adapter for ChatClient #374
DiegoGBrisa
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Right now there's no way to persist conversations on the client — if the page reloads or the user navigates away, the chat history is gone. You can wire it up manually through initialMessages and onFinish, but it's easy to miss edge cases (like clear(), tool results, or approval flows), and everyone ends up writing the same boilerplate.
This is especially relevant for SPAs, Electron apps, and offline-first setups where there's no server managing conversation state — the client is the source of truth.
Proposal
A simple, optional persistence option on ChatClient — same getItem/setItem/removeItem shape as ToolCacheStorage:
When provided, ChatClient hydrates from getItem(id) on construction, saves on message changes, and clears on clear(). When omitted, everything works exactly as it does today — no breaking changes.
Where it lives
The interface and integration live in @tanstack/ai-client on ChatClient. Framework wrappers just pass it through as another option.
Usage
Custom adapter example
Users implement the three methods for whatever storage backend they need — IndexedDB, SQLite, a database, anything:
Happy to help with implementation if there's interest.
Beta Was this translation helpful? Give feedback.
All reactions