quivr/frontend/lib/api/chat/chat.ts
Mamadou DICKO 10af0c949a
feat: add notifications components (#1148)
* feat: rename ChatMessages to MessagesDialog

* feat: rename history to messages

* feat: add notifications to ChatContext

* feat: add getNotificationsFromChatHistory

* feat: add getMergedChatHistoryWithReducedNotifications

* refactor: update useActionBar

* refactor: update <ChatMessage />-n

* feat: update crawler and endpoint notifications content

* feat: display notifications

* test: update <MessageDialog /> tests

* feat: rename ChatMessage to QADisplay

* feat: rename ChatHistory to ChatMessage

* feat(upload): throw error when file missing

* feat: rename getMergedChatHistoryWithReducedNotifications to getMergedChatMessagesWithReducedNotifications

* feat: change history wording to message

* feat: move getFileIcon to lib

* refactor(NotificationDisplayer): move types to types.ts

* chore: improve ux

* feat: rename MessagesDialog to ChatDialogue
2023-09-12 17:44:15 +02:00

73 lines
1.6 KiB
TypeScript

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