import type { Chat, CreateEntryResponse } from "../types"; const BASE = "/api/rag"; export async function createChat(token: string): Promise { const res = await fetch(`${BASE}/chat/new?title=DevOps%20Chat`, { method: "POST", headers: { Authorization: `Bearer ${token}` }, }); if (!res.ok) throw new Error(`Failed to create chat: ${res.status}`); return res.json() as Promise; } export async function sendMessage( token: string, chatId: number, content: string ): Promise { const res = await fetch(`${BASE}/entry/${chatId}`, { method: "POST", headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, body: JSON.stringify({ content, onlyContext: true }), }); if (!res.ok) throw new Error(`Failed to send message: ${res.status}`); return res.json() as Promise; }