ATBIZLOVEABLE / api.ts
lattmamb's picture
Upload 14 files
7ee98c0 verified
import { apiRequest } from "./queryClient";
import type { Chat, ChatWithMessages, Message, ChatSettings } from "@shared/schema";
export async function createChat(title: string): Promise<Chat> {
const res = await apiRequest("POST", "/api/chats", { title });
return res.json();
}
export async function getChats(): Promise<Chat[]> {
const res = await apiRequest("GET", "/api/chats");
return res.json();
}
export async function getChat(id: number): Promise<ChatWithMessages> {
const res = await apiRequest("GET", `/api/chats/${id}`);
return res.json();
}
export async function deleteChat(id: number): Promise<void> {
await apiRequest("DELETE", `/api/chats/${id}`);
}
export async function sendMessage(chatId: number, content: string): Promise<{
userMessage: Message;
aiMessage: Message;
}> {
const res = await apiRequest("POST", "/api/messages", {
chatId,
role: "user",
content
});
return res.json();
}
export async function updateChatSettings(
chatId: number,
settings: Partial<ChatSettings>
): Promise<ChatSettings> {
const res = await apiRequest("POST", `/api/chats/${chatId}/settings`, settings);
return res.json();
}