import { apiJson } from './http' export function listChats({ skip = 0, limit = 30 } = {}) { const q = new URLSearchParams({ skip: String(skip), limit: String(limit), }) return apiJson(`/list_chats?${q}`, { auth: true }) } export function createChat() { return apiJson('/get_new_chat', { method: 'POST', auth: true }) } /** Latest page: omit beforeIndex. Older: pass next_before_index from prior response. */ export function fetchChatPage(chatId, { beforeIndex = null, limit = 20 } = {}) { const q = new URLSearchParams({ limit: String(limit) }) if (beforeIndex != null) q.set('before_index', String(beforeIndex)) return apiJson(`/get_chat/${encodeURIComponent(chatId)}?${q}`, { auth: true }) } export function removeChat(chatId) { return apiJson(`/delete_chat/${encodeURIComponent(chatId)}`, { method: 'DELETE', auth: true, }) } export function sendMessage( chatId, question, { allowAugmentation = true, useWebSearch = false, } = {}, ) { return apiJson('/response', { method: 'POST', body: JSON.stringify({ chat_id: chatId, question, allow_augmentation: allowAugmentation, use_web_search: useWebSearch, }), auth: true, }) }