-
+
+
+
| null = null
const SAVE_DEBOUNCE = 800
-// Server-side persistence via Vite dev middleware
+// Server-side persistence via Vite dev middleware (fallback for dev mode without IDB)
async function loadServerChats(): Promise<{ conversations: Map; activeId: string | null }> {
const empty = { conversations: new Map(), activeId: null }
if (!isDev) return empty
@@ -43,6 +51,19 @@ function saveServerChats(conversations: Map, activeId: str
}, SAVE_DEBOUNCE)
}
+// Debounced IDB save for a single conversation
+const idbSaveTimers = new Map>()
+
+function debouncedIDBSave(conv: Conversation) {
+ if (!useIDB) return
+ const existing = idbSaveTimers.get(conv.id)
+ if (existing) clearTimeout(existing)
+ idbSaveTimers.set(conv.id, setTimeout(() => {
+ idbSave(conv).catch(() => {})
+ idbSaveTimers.delete(conv.id)
+ }, SAVE_DEBOUNCE))
+}
+
export const useChatStore = defineStore('chat', () => {
const conversations = ref