import type { ApiResponse } from '../../types/api'; import type { PurgeRequestBody, PurgeResultData, SendMessageResponseData, SuggestQuestionsData, ThreadCreateData, ThreadDeleteData, ThreadMessagesData, ThreadsListData, } from '../../types/thread'; import { apiClient } from '../apiClient'; export const threadApi = { /** GET /threads — list all threads for the authenticated user */ getThreads: async (): Promise => { const response = await apiClient.get>('/threads'); return response.data; }, /** POST /threads — create a new thread */ createThread: async (chatId?: number): Promise => { const response = await apiClient.post>( '/threads', chatId != null ? { chatId } : undefined ); return response.data; }, /** GET /threads/:threadId/messages — get messages for a thread */ getThreadMessages: async (threadId: string): Promise => { const response = await apiClient.get>( `/threads/${encodeURIComponent(threadId)}/messages` ); return response.data; }, /** DELETE /threads/:threadId — delete a single thread */ deleteThread: async (threadId: string): Promise => { const response = await apiClient.delete>( `/threads/${encodeURIComponent(threadId)}` ); return response.data; }, /** POST /chat/sendMessage — send a user message to a thread and get the agent response */ sendMessage: async ( message: string, conversationId: string ): Promise => { const response = await apiClient.post>( '/chat/sendMessage', { message, conversationId } ); return response.data; }, /** GET /chat/autocomplete — suggested starter questions (e.g. for a new/empty thread) */ getSuggestQuestions: async (conversationId?: string): Promise => { const url = conversationId != null ? `/chat/autocomplete?conversationId=${encodeURIComponent(conversationId)}` : '/chat/autocomplete'; const response = await apiClient.get>(url); return response.data; }, /** POST /purge — purge messages and/or threads */ purge: async (body: PurgeRequestBody): Promise => { const response = await apiClient.post>('/purge', body); return response.data; }, };