// Typed client for the Case Zero game API (served by gradio.Server under /api). import type { InterrogateResult, PublicCase, VerdictResult } from './types' export interface CaseResponse { caseId: string runId: string case: PublicCase } async function postJSON(url: string, body: unknown): Promise { const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }) if (!res.ok) throw new Error(`POST ${url} failed: ${res.status}`) return (await res.json()) as T } async function getJSON(url: string): Promise { const res = await fetch(url) if (!res.ok) throw new Error(`GET ${url} failed: ${res.status}`) return (await res.json()) as T } export interface NewCaseRequest { seed?: number caseId?: string difficulty?: string } export function newCase(req: NewCaseRequest = {}): Promise { return postJSON('/api/case', req) } export function getCase(caseId: string): Promise { return getJSON(`/api/case/${encodeURIComponent(caseId)}`) } export interface InterrogateBody { questionId?: string freeText?: string presentEvidenceId?: string } export function interrogate( runId: string, suspectId: string, body: InterrogateBody, ): Promise { return postJSON( `/api/run/${encodeURIComponent(runId)}/interrogate/${encodeURIComponent(suspectId)}`, body, ) } export function getHint(runId: string, screen: string): Promise<{ hint: string }> { return getJSON<{ hint: string }>( `/api/run/${encodeURIComponent(runId)}/hint?screen=${encodeURIComponent(screen)}`, ) } export interface AccuseBody { suspectId: string motiveId: string evidenceIds: string[] } export function accuse(runId: string, body: AccuseBody): Promise { return postJSON(`/api/run/${encodeURIComponent(runId)}/accuse`, body) }