File size: 1,576 Bytes
47203d3
 
 
 
ba9d176
47203d3
 
 
 
 
 
 
 
 
 
 
 
 
 
ba9d176
47203d3
 
 
 
 
 
 
 
 
 
 
c2de869
 
 
 
 
 
 
 
 
 
 
47203d3
 
 
 
 
 
 
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
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()
}