// Każda funkcja = jedno zapytanie (łatwy prefetch i równoległość) export const api = { snapshot: (node) => fetch(`/api/info?node=${encodeURIComponent(node||'')}`).then(r=>r.json()), // lżejsze mikro-endpointy: clusterBrief: () => fetch('/api/cluster').then(r=>r.json()), nodesSummary: () => fetch('/api/nodes/summary').then(r=>r.json()), units: (node) => fetch(`/api/units?node=${encodeURIComponent(node||'')}`).then(r=>r.json()), replicationAll: () => fetch('/api/replication/all').then(r=>r.json()), vmDetail: (sid) => fetch('/api/vm?sid=' + encodeURIComponent(sid)).then(r=>r.json()), nodeDetail: (name) => fetch('/api/node?name=' + encodeURIComponent(name)).then(r=>r.json()), listNonHA: () => fetch('/api/list-vmct').then(r=>r.json()), listAllVmct: () => fetch('/api/list-all-vmct').then(r=>r.json()), action: (act, node) => fetch('/api/'+act, {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({node})}).then(r=>r.json()), vmAction: (sid, action, target) => { const body = { sid, action }; if (target) body.target = target; return fetch('/api/vm-action', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body)}).then(r=>r.json()); }, wsTaskURL: (upid, node) => { const proto = (location.protocol === 'https:') ? 'wss' : 'ws'; return `${proto}://${location.host}/ws/task?upid=${encodeURIComponent(upid)}&node=${encodeURIComponent(node)}`; }, // NEW: wsObserveURL: (sid) => { const proto = (location.protocol === 'https:') ? 'wss' : 'ws'; return `${proto}://${location.host}/ws/observe?sid=${encodeURIComponent(sid)}`; } };