File size: 1,845 Bytes
25732fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import axios from 'axios'
import toast from 'react-hot-toast'
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000'
const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
withCredentials: true,
})
// Response interceptor for error handling
api.interceptors.response.use(
(response) => response,
(error) => {
const message = error.response?.data?.error || 'An error occurred'
toast.error(message)
return Promise.reject(error)
}
)
// Auth APIs
export const authAPI = {
login: (credentials) => api.post('/api/login', credentials),
register: (userData) => api.post('/api/register', userData),
logout: () => api.post('/api/logout'),
getCurrentUser: () => api.get('/api/current-user'),
}
// Topic APIs
export const topicAPI = {
getAll: () => api.get('/api/topics'),
getById: (id) => api.get(`/api/topics/${id}`),
}
// Learning APIs
export const learningAPI = {
generateLesson: (topicId) => api.post('/api/generate-lesson', { topic_id: topicId }),
checkCode: (code) => api.post('/api/check-code', { code }),
askHint: (data) => api.post('/api/ask-challenge-hint', data),
}
// Quiz APIs
export const quizAPI = {
generateQuiz: (topicId) => api.post('/api/generate-quiz', { topic_id: topicId }),
submitAnswer: (data) => api.post('/api/submit-answer', data),
}
// Progress APIs
export const progressAPI = {
getKnowledgeState: (topicId) => api.get(`/api/knowledge-state/${topicId}`),
getProgressSummary: () => api.get('/api/progress-summary'),
getStudyTips: () => api.get('/api/study-tips'),
getNextTopic: (currentTopicId) =>
api.get('/api/next-topic', { params: { current_topic_id: currentTopicId } }),
}
// Agent APIs
export const agentAPI = {
getStatus: () => api.get('/api/agent-status'),
}
export default api |