import axios from "axios"; export const config = { API_BASE_URL: typeof window !== "undefined" ? (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" ? `${window.location.protocol}//${window.location.hostname}:8001` : window.location.origin) : "http://localhost:8001", }; const client = axios.create({ baseURL: typeof window !== "undefined" ? (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" ? `${window.location.protocol}//${window.location.hostname}:8001/api` : "/api") : `${config.API_BASE_URL}/api`, timeout: 3600000, // Increased timeout for slow local LLMs and evaluation requests }); export default { // Project Management async getProjects() { const response = await client.get("/projects"); return response.data; }, async getProject(id: string) { const response = await client.get(`/projects/${id}`); return response.data; }, async deleteProject(id: string) { const response = await client.delete(`/projects/${id}`); return response.data; }, // Generation async startGeneration(data: any) { const response = await client.post("/generate", data); return response.data; }, async stopGeneration(sessionId: string, deleteDir: boolean = false) { const response = await client.post( `/generate/stop/${sessionId}?delete_dir=${deleteDir}`, ); return response.data; }, async retryScene(projectId: string, sceneNumber: number, data: any) { const response = await client.post( `/projects/${projectId}/retry-scene/${sceneNumber}`, data, ); return response.data; }, async continueGeneration(projectId: string, data: any) { const response = await client.post(`/projects/${projectId}/continue`, data); return response.data; }, // File Management async getProjectFile(projectId: string, filePath: string) { const response = await client.get( `/projects/${projectId}/files/${filePath}`, ); return response.data; }, // Evaluation async evaluateProject(projectId: string, evaluationConfig: any) { const response = await client.post(`/projects/${projectId}/evaluate`, { project_id: projectId, ...evaluationConfig, }); return response.data; }, // System async getModels() { const response = await client.get("/models"); return response.data; }, async getSystemStatus() { const response = await client.get("/system/status"); return response.data; }, async validateApiKeys(data: { openai_api_key?: string; anthropic_api_key?: string; gemini_api_key?: string; }) { const response = await client.post("/validate-keys", data); return response.data; }, async getActiveSessions() { const response = await client.get("/sessions/active"); return response.data; }, async getVoices() { const response = await client.get("/voices"); return response.data; }, async previewVoice(voiceId: string): Promise { const response = await client.post( "/voices/preview", { voice_id: voiceId }, { responseType: "blob" }, ); return URL.createObjectURL(response.data); }, async draftPlan(data: any) { // Axios doesn't handle streams as easily as fetch for simple text/plain streams const response = await fetch(`${config.API_BASE_URL}/api/assist/plan`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response; }, async testApiKey(data: any) { const response = await client.post("/assist/test-key", data); return response.data; }, // Interactive Learning async chat(projectId: string, data: any) { const response = await client.post(`/assist/chat`, { project_id: projectId, ...data, }); return response.data; }, async chatSuggestions(projectId: string, data: any) { const response = await client.post( `/projects/${projectId}/chat/suggestions`, data, ); return response.data; }, async generateQuiz(payload: any, axiosConfig: any) { const response = await client.post("/assist/quiz", payload, axiosConfig); return response.data; }, // Plan Approval Workflow async generatePlan(data: any) { const response = await client.post("/generate/plan", data); return response.data; }, async revisePlan( projectId: string, data: any, ) { const response = await client.post(`/projects/${projectId}/revise-plan`, data); return response.data; }, async approvePlan(projectId: string, data: any = {}) { const response = await client.post(`/projects/${projectId}/approve`, data); return response.data; }, };