import { convex, api } from '$lib/convexClient'; // ─── Settings ──────────────────────────────────────────────────────────────── export const syncSettings = async (userId: string, data: object): Promise => { try { await convex.mutation(api.settings.save, { userId, data }); } catch (e) { console.error('[Convex] Failed to sync settings:', e); } }; export const loadSettings = async (userId: string): Promise => { try { const doc = await convex.query(api.settings.get, { userId }); return doc?.data ?? null; } catch (e) { console.error('[Convex] Failed to load settings:', e); return null; } }; // ─── Conversations ──────────────────────────────────────────────────────────── export const syncConversation = async ( userId: string, chatId: string, title: string, data: object ): Promise => { try { await convex.mutation(api.conversations.save, { userId, chatId, title, data }); } catch (e) { console.error('[Convex] Failed to sync conversation:', e); } }; export const loadConversations = async (userId: string): Promise => { try { return await convex.query(api.conversations.list, { userId }); } catch (e) { console.error('[Convex] Failed to load conversations:', e); return []; } }; export const removeConversation = async (chatId: string): Promise => { try { await convex.mutation(api.conversations.remove, { chatId }); } catch (e) { console.error('[Convex] Failed to remove conversation:', e); } }; // ─── Connections ────────────────────────────────────────────────────────────── export const syncConnections = async (userId: string, data: object): Promise => { try { await convex.mutation(api.connections.save, { userId, data }); } catch (e) { console.error('[Convex] Failed to sync connections:', e); } }; export const loadConnections = async (userId: string): Promise => { try { const doc = await convex.query(api.connections.get, { userId }); return doc?.data ?? null; } catch (e) { console.error('[Convex] Failed to load connections:', e); return null; } };