Appearance
Data Persistence
The Advisor Console persists chat history and session state in IndexedDB, providing offline capability and session restoration.
Why IndexedDB
| Feature | IndexedDB | localStorage |
|---|---|---|
| Storage | Large (hundreds of MB) | Small (5-10 MB) |
| Data Types | Structured (objects, arrays) | Strings only |
| API | Async (non-blocking) | Sync (blocking) |
| Indexing | Yes (fast queries) | No |
| Transactions | Yes (ACID) | No |
IndexedDB is the right choice for chat history, which involves structured data, potentially large sessions, and async operations.
Chat History Schema
typescript
interface ChatSession {
id: string;
title: string;
createdAt: Date;
updatedAt: Date;
messages: Message[];
context: ContextReference[];
detectedType: string;
location: string;
searchFilters: SearchFilters;
results: SearchResult[];
dataSources: DataSource[];
}
interface Message {
id: string;
role: 'user' | 'assistant';
content: string;
timestamp: Date;
}CRUD Operations
The chatHistory.ts module provides:
createSession()— Create a new chat sessiongetSession(id)— Retrieve a session by IDupdateSession(id, data)— Update session datadeleteSession(id)— Delete a sessionlistSessions()— List all sessions with grouping (RECENT/EARLIER)
Auto-Save
Sessions auto-save with a 2-second debounce. Every message, context change, or filter update triggers a save. The debounced save prevents excessive writes during rapid interactions.
Session Restoration
When an advisor returns to the console:
- IndexedDB loads the last active session
- Messages, context references, and search results restore
- The advisor picks up exactly where they left off
Future: Server-Side Storage
Current implementation uses client-side IndexedDB only. A future enhancement may sync sessions to the server for cross-device access. This introduces complexity around:
- Conflict resolution (multiple devices editing the same session)
- Authentication (server must verify advisor identity)
- Data privacy (chat content must be encrypted at rest)