// Thin REST client around the FastAPI backend. // In dev, Vite proxies /api → http://127.0.0.1:7860/api. In prod the backend // serves this bundle, so same-origin relative paths Just Work. const BASE = import.meta.env.VITE_API_BASE ?? "/api"; export interface HealthResponse { status: string; version: string; qiskit_version: string; torch_version: string; ibm_token_configured: boolean; live_ibm_allowed: boolean; } export interface BackendInfo { name: string; kind: "fake" | "live"; num_qubits: number; description: string; } export interface SampleCircuit { key: string; display_name: string; description: string; num_qubits: number; depth: number; size: number; num_parameters: number; diagram_text: string; source: string; } export interface CircuitInfo { circuit_id: string; name: string; num_qubits: number; num_clbits: number; depth: number; size: number; num_parameters: number; ops: Record; diagram_text: string; } export type StepStatus = "ok" | "skipped" | "error"; export interface StepResult { node_id: string; node_type: string; label: string; status: StepStatus; started_at: number; finished_at: number; summary: Record; message: string | null; } export interface RunResponse { circuit_id: string; ok: boolean; from_cache: boolean; steps: StepResult[]; final_metrics: Record; } export interface FlowNodePayload { id: string; type: string; data: Record; } export interface FlowEdgePayload { id: string; source: string; target: string; } export interface RunRequest { circuit_id: string; nodes: FlowNodePayload[]; edges: FlowEdgePayload[]; } async function json(res: Response): Promise { if (!res.ok) { const body = await res.text().catch(() => ""); throw new Error(`HTTP ${res.status} ${res.statusText}: ${body || "(no body)"}`); } return res.json(); } export const api = { health: () => fetch(`${BASE}/health`).then((r) => json(r)), backends: () => fetch(`${BASE}/backends`).then((r) => json(r)), listSamples: () => fetch(`${BASE}/circuits/samples`).then((r) => json(r)), loadSample: (key: string) => fetch(`${BASE}/circuits/samples/${encodeURIComponent(key)}`, { method: "POST" }).then( (r) => json(r), ), upload: (file: File) => { const fd = new FormData(); fd.append("file", file); return fetch(`${BASE}/circuits/upload`, { method: "POST", body: fd }).then( (r) => json(r), ); }, getCircuit: (circuit_id: string) => fetch(`${BASE}/circuits/${encodeURIComponent(circuit_id)}`).then( (r) => json(r), ), run: (body: RunRequest) => fetch(`${BASE}/workflow/run`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }).then((r) => json(r)), };