Persistence adapter for ChatClient #374
DiegoGBrisa
started this conversation in
Ideas
Replies: 3 comments
-
|
I'm running to the issue of the stream being cancelled when clicking on an item and navigating to an item view, when you go back you lose all of the streamed items and it starts from the beginning. It looks like I need to wrap my entire app in a ChatProvider wrapper, but I don't love that so much |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Love this, will be implemented! |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
implemented here, awaiting merge: |
Beta Was this translation helpful? Give feedback.
0 replies
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