Webui / src /lib /services /convexSync.ts
oki692's picture
Upload folder using huggingface_hub
cfb0fa4 verified
import { convex, api } from '$lib/convexClient';
// ─── Settings ────────────────────────────────────────────────────────────────
export const syncSettings = async (userId: string, data: object): Promise<void> => {
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<object | null> => {
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<void> => {
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<object[]> => {
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<void> => {
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<void> => {
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<object | null> => {
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;
}
};