/** * 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 = `

System Health

${this.getHealthBadge(health.overall)}
MCP Server
${this.getHealthBadge(health.mcp_server)}
Context Compiler
${this.getHealthBadge(health.context_compiler)}
Browser Connection
${this.getHealthBadge(health.browser_connection)}
Dependencies
${this.getHealthBadge(health.dependencies)}

Configuration

Base Theme: ${ComponentHelpers.escapeHtml(config.base_theme || 'N/A')}
Active Skin: ${ComponentHelpers.escapeHtml(config.skin || 'None')}
Project Name: ${ComponentHelpers.escapeHtml(config.project_name || 'N/A')}
Cache Enabled: ${config.cache_enabled ? '✓ Yes' : '✗ No'}
${metrics.token_count !== undefined ? `

Metrics

${metrics.token_count || 0}
Design Tokens
${metrics.component_count || 0}
Components
${metrics.theme_count || 0}
Themes
${metrics.compilation_time ? `
${Math.round(metrics.compilation_time)}ms
Compilation Time
` : ''}
` : ''} ${recommendations.length > 0 ? `

Recommendations

${recommendations.map(rec => `
💡
${ComponentHelpers.escapeHtml(rec.title || rec)}
${rec.description ? `
${ComponentHelpers.escapeHtml(rec.description)}
` : ''}
`).join('')}
` : ''}
Last updated: ${ComponentHelpers.formatTimestamp(new Date())} ${this.autoRefresh ? '• Auto-refreshing every 5s' : ''}
`; } render() { this.innerHTML = `
${ComponentHelpers.renderLoading('Initializing...')}
`; } } customElements.define('ds-system-log', DSSystemLog); export default DSSystemLog;