ai-interview-mentor / frontend /src /api /interview.ts
adeshboudh16
bug fix for dynamic routing logic
c2de869
import { apiFetch } from './client'
export async function startInterview(
topicId: string,
): Promise<{ session_id: string; message: string; turn_count: number }> {
const res = await apiFetch('/interview/start', {
method: 'POST',
body: JSON.stringify({ topic_id: topicId }),
})
if (!res.ok) {
const err = await res.json()
throw new Error(err.detail ?? 'Failed to start interview')
}
return res.json()
}
export async function sendTurn(
sessionId: string,
studentMessage: string,
): Promise<{ message: string; turn_count: number; is_counter_q: boolean; is_complete: boolean; feedback?: Record<string, unknown> }> {
const res = await apiFetch('/interview/turn', {
method: 'POST',
body: JSON.stringify({ session_id: sessionId, student_message: studentMessage }),
})
if (!res.ok) {
const err = await res.json()
throw new Error(err.detail ?? 'Failed to send answer')
}
return res.json()
}
export async function finishSession(
sessionId: string,
): Promise<{ score: number; feedback: Record<string, unknown> }> {
const res = await apiFetch(`/interview/finish/${sessionId}`, { method: 'POST' })
if (!res.ok) {
const err = await res.json()
throw new Error(err.detail ?? 'Failed to finish session')
}
return res.json()
}
export async function getInterviewState(
sessionId: string,
): Promise<{ status: string; turn_count: number; last_message: string | null }> {
const res = await apiFetch(`/interview/state/${sessionId}`)
if (!res.ok) throw new Error('Failed to load session')
return res.json()
}