const PipelinesUI = { pipelines: [], agents: [], _editingId: null, _steps: [], async load() { try { const [pipelines, agents] = await Promise.all([ API.pipelines.list(), API.agents.list(), ]); PipelinesUI.pipelines = Array.isArray(pipelines) ? pipelines : []; PipelinesUI.agents = Array.isArray(agents) ? agents : []; PipelinesUI.render(); } catch (err) { Toast.error(`Erro ao carregar pipelines: ${err.message}`); } }, render() { const grid = document.getElementById('pipelines-grid'); if (!grid) return; const existingCards = grid.querySelectorAll('.pipeline-card'); existingCards.forEach((c) => c.remove()); const emptyState = grid.querySelector('.empty-state'); if (PipelinesUI.pipelines.length === 0) { if (!emptyState) { grid.insertAdjacentHTML('beforeend', PipelinesUI.renderEmpty()); } if (window.lucide) lucide.createIcons({ nodes: [grid] }); return; } if (emptyState) emptyState.remove(); const fragment = document.createDocumentFragment(); PipelinesUI.pipelines.forEach((pipeline) => { const wrapper = document.createElement('div'); wrapper.innerHTML = PipelinesUI.renderCard(pipeline); fragment.appendChild(wrapper.firstElementChild); }); grid.appendChild(fragment); if (window.lucide) lucide.createIcons({ nodes: [grid] }); }, renderEmpty() { return `
Crie seu primeiro pipeline para encadear agentes em fluxos automatizados.
${pipeline.description}
` : ''}