import type { GenerateRequest, HealthResponse } from '../types' export async function generateAudio( req: GenerateRequest, signal: AbortSignal, ): Promise { const res = await fetch('/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(req), signal, }) if (!res.ok) { const ct = res.headers.get('content-type') ?? '' if (ct.includes('json')) { const body = await res.json() as { detail: string | Array<{ msg: string }> } const detail = Array.isArray(body.detail) ? body.detail.map(e => e.msg).join('; ') : body.detail throw new Error(detail) } throw new Error(await res.text()) } return res.blob() } export async function fetchHealth(): Promise { const res = await fetch('/health') if (!res.ok) throw new Error(`Health check returned ${res.status}`) return res.json() as Promise }