import { api } from './http'; export interface RetrievedSnippet { fileName: string; chunkIndex: number; score: number; preview: string; } export interface ToolCallTrace { name: string; args: any; result: any; } export interface ModelOverrides { model?: string; model_id?: string; temperature?: number; topP?: number; maxTokens?: number; } export interface ChatMessage { id: string; role: 'user' | 'assistant' | 'agent' | 'system'; speaker?: { id: string; type: 'user' | 'agent'; }; content: string; reasoning?: string | null; parentId?: string | null; createdAt: number; agent_id?: string; meta?: { retrieved?: RetrievedSnippet[]; toolCalls?: ToolCallTrace[]; aborted?: boolean; reasoning?: string; error?: string; } | null; } export interface BranchInfo { total: number; activeIndex: number; ids: string[]; } export interface ChatHistoryResp { messages: ChatMessage[]; branches: Record; } export const ChatAPI = { history: (roomId: string) => api.get(`/rooms/${roomId}/messages`).then((r) => r.data), send: (roomId: string, content: string, targetAgentId: string, overrides?: ModelOverrides, imageUrls?: string[]) => api .post<{ user: ChatMessage; assistant: ChatMessage }>(`/rooms/${roomId}/messages`, { content, targetAgentId, ...overrides, imageUrls }) .then((r) => r.data), switchBranch: (agentId: string, userMsgId: string, branchId: string) => api.post(`/agents/${agentId}/messages/${userMsgId}/branches/${branchId}/switch`).then((r) => r.data), clear: (roomId: string) => api.delete(`/rooms/${roomId}/messages`).then((r) => r.data) }; export interface ChatAttachment { name: string; size: number; mime: string; text: string; truncated: boolean; } export const ChatAttachmentsAPI = { upload: (files: File[]) => { const fd = new FormData(); files.forEach((f) => fd.append('files', f)); return api.post<{ files: ChatAttachment[] }>('/chat/attachments', fd).then((r) => r.data); } };