/** * ds-system-log.js * System health dashboard with DSS status, MCP health, and compiler metrics */ import toolBridge from '../../services/tool-bridge.js'; import { ComponentHelpers } from '../../utils/component-helpers.js'; class DSSystemLog extends HTMLElement { constructor() { super(); this.status = null; this.autoRefresh = false; this.refreshInterval = null; } connectedCallback() { this.render(); this.setupEventListeners(); this.loadStatus(); } disconnectedCallback() { if (this.refreshInterval) { clearInterval(this.refreshInterval); } } setupEventListeners() { const refreshBtn = this.querySelector('#system-refresh-btn'); if (refreshBtn) { refreshBtn.addEventListener('click', () => this.loadStatus()); } const autoRefreshToggle = this.querySelector('#system-auto-refresh'); if (autoRefreshToggle) { autoRefreshToggle.addEventListener('change', (e) => { this.autoRefresh = e.target.checked; if (this.autoRefresh) { this.refreshInterval = setInterval(() => this.loadStatus(), 5000); } else { if (this.refreshInterval) { clearInterval(this.refreshInterval); this.refreshInterval = null; } } }); } } async loadStatus() { const content = this.querySelector('#system-content'); if (!content) return; // Only show loading on first load if (!this.status) { content.innerHTML = ComponentHelpers.renderLoading('Loading system status...'); } try { const result = await toolBridge.getDSSStatus('json'); if (result) { this.status = result; this.renderStatus(); } else { content.innerHTML = ComponentHelpers.renderEmpty('No status data available', '📊'); } } catch (error) { console.error('Failed to load system status:', error); content.innerHTML = ComponentHelpers.renderError('Failed to load system status', error); } } getHealthBadge(isHealthy) { return isHealthy ? ComponentHelpers.createBadge('Healthy', 'success') : ComponentHelpers.createBadge('Degraded', 'error'); } renderStatus() { const content = this.querySelector('#system-content'); if (!content || !this.status) return; const health = this.status.health || {}; const config = this.status.configuration || {}; const metrics = this.status.metrics || {}; const recommendations = this.status.recommendations || []; content.innerHTML = `