import type { ChatSession, ChatMessage } from "./types" const BASE = "/api/chat" export async function createSession(): Promise { const r = await fetch(`${BASE}/sessions`, { method: "POST" }) return r.json() } export async function listSessions(): Promise { const r = await fetch(`${BASE}/sessions`) return r.json() } export async function getSession(id: number): Promise { const r = await fetch(`${BASE}/sessions/${id}`) return r.json() } export async function deleteSession(id: number): Promise { await fetch(`${BASE}/sessions/${id}`, { method: "DELETE" }) } export async function renameSession(id: number, title: string): Promise { const r = await fetch(`${BASE}/sessions/${id}/rename`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title }), }) return r.json() } export async function sendMessage(sessionId: number, message: string): Promise { const r = await fetch(`${BASE}/sessions/${sessionId}/messages`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message }), }) return r.json() }