export interface Capability { key: string name: string group: string endpoint: string desc: string inputs: string[] output: string model_key: string cost: number tips: string[] sample: string } export interface ModelInfo { key: string file: string arch: string params_m: number size_mb: number input: string output: string quant: string note: string loaded_ok: boolean } export interface CapabilityPayload { capabilities: Capability[] models: ModelInfo[] summary: { capability_count: number model_count: number total_params_m: string total_size_mb: string groups: string[] runtime: string } } export function getToken(): string { return localStorage.getItem('token') || '' } export async function api(path: string, init: RequestInit = {}): Promise { const headers: Record = { ...(init.body ? { 'Content-Type': 'application/json' } : {}), ...((init.headers as Record) || {}), } const t = getToken() if (t) headers['Authorization'] = `Bearer ${t}` const res = await fetch(path, { ...init, headers }) const text = await res.text() let data: unknown = null try { data = text ? JSON.parse(text) : null } catch { data = { raw: text } } if (!res.ok) { let msg = `HTTP ${res.status}` if (data && typeof data === 'object' && 'error' in data) { msg = String((data as { error: unknown }).error) } throw new Error(msg) } return data as T } export interface TrainTask { id: number name: string kind: string base_model: string dataset_id: number status: string progress: number epoch: number total_epochs: number metric_json: string log_path: string artifact_path: string error_msg: string created_at: string } export interface Dataset { id: number name: string kind: string images: number labels: number size_mb: number path: string note: string created_at: string }