import { AxiosInstance } from "axios"; import { ChatEntity, ChatItem, ChatMessage, ChatQuestion, } from "@/app/chat/[chatId]/types"; export const createChat = async ( name: string, axiosInstance: AxiosInstance ): Promise => { const createdChat = ( await axiosInstance.post("/chat", { name: name }) ).data; return createdChat; }; export const getChats = async ( axiosInstance: AxiosInstance ): Promise => { const response = await axiosInstance.get<{ chats: ChatEntity[]; }>(`/chat`); return response.data.chats; }; export const deleteChat = async ( chatId: string, axiosInstance: AxiosInstance ): Promise => { await axiosInstance.delete(`/chat/${chatId}`); }; export type AddQuestionParams = { chatId: string; chatQuestion: ChatQuestion; brainId: string; }; export const addQuestion = async ( { chatId, chatQuestion, brainId }: AddQuestionParams, axiosInstance: AxiosInstance ): Promise => { const response = await axiosInstance.post( `/chat/${chatId}/question?brain_id=${brainId}`, chatQuestion ); return response.data; }; export const getChatItems = async ( chatId: string, axiosInstance: AxiosInstance ): Promise => (await axiosInstance.get(`/chat/${chatId}/history`)).data; export type ChatUpdatableProperties = { chat_name?: string; }; export const updateChat = async ( chatId: string, chat: ChatUpdatableProperties, axiosInstance: AxiosInstance ): Promise => { return (await axiosInstance.put(`/chat/${chatId}/metadata`, chat)) .data; };