| import type { AppConfig, ContentResponse, ContractMap, DemoResult } from "./types"; |
|
|
| async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> { |
| const response = await fetch(path, init); |
| if (!response.ok) { |
| throw new Error(`Request failed for ${path}`); |
| } |
| return (await response.json()) as T; |
| } |
|
|
| export async function getConfig(): Promise<AppConfig> { |
| return fetchJson<AppConfig>("/api/config"); |
| } |
|
|
| export async function getContent(): Promise<ContentResponse> { |
| return fetchJson<ContentResponse>("/api/content"); |
| } |
|
|
| export async function getContracts(): Promise<ContractMap> { |
| const [voiceRegistry, routeMatrix, seedLibrary, providerConfig] = await Promise.all([ |
| fetchJson<unknown>("/api/contracts/voice_registry"), |
| fetchJson<unknown>("/api/contracts/route_model_matrix"), |
| fetchJson<unknown>("/api/contracts/seed_voice_library"), |
| fetchJson<unknown>("/api/contracts/provider_config"), |
| ]); |
|
|
| return { |
| voice_registry: voiceRegistry, |
| route_model_matrix: routeMatrix, |
| seed_voice_library: seedLibrary, |
| provider_config: providerConfig, |
| }; |
| } |
|
|
| export async function runDemo(workflowId: string): Promise<DemoResult> { |
| return fetchJson<DemoResult>("/api/demo/simulate", { |
| method: "POST", |
| headers: { |
| "Content-Type": "application/json", |
| }, |
| body: JSON.stringify({ workflow_id: workflowId }), |
| }); |
| } |
|
|