import apiClient from './apiClient.js'; class DebugConsoleView { constructor(section, wsClient) { this.section = section; this.wsClient = wsClient; this.healthInfo = section.querySelector('[data-health-info]'); this.wsInfo = section.querySelector('[data-ws-info]'); this.requestLogBody = section.querySelector('[data-request-log]'); this.errorLogBody = section.querySelector('[data-error-log]'); this.wsLogBody = section.querySelector('[data-ws-log]'); this.refreshButton = section.querySelector('[data-refresh-health]'); } init() { this.refresh(); if (this.refreshButton) { this.refreshButton.addEventListener('click', () => this.refresh()); } apiClient.onLog(() => this.renderRequestLogs()); apiClient.onError(() => this.renderErrorLogs()); this.wsClient.onStatusChange(() => this.renderWsLogs()); this.wsClient.onMessage(() => this.renderWsLogs()); } async refresh() { const [health, providers] = await Promise.all([apiClient.getHealth(), apiClient.getProviders()]); // Update health info if (this.healthInfo) { if (health.ok) { const data = health.data || {}; this.healthInfo.innerHTML = `
Status: ${data.status || 'OK'}
Uptime: ${data.uptime || 'N/A'}
Version: ${data.version || 'N/A'}
`; } else { this.healthInfo.innerHTML = ``; } } // Update WebSocket info if (this.wsInfo) { const status = this.wsClient.status || 'disconnected'; const events = this.wsClient.getEvents(); this.wsInfo.innerHTML = `Status: ${status}
Events: ${events.length}
`; } this.renderRequestLogs(); this.renderErrorLogs(); this.renderWsLogs(); } renderRequestLogs() { if (!this.requestLogBody) return; const logs = apiClient.getLogs(); this.requestLogBody.innerHTML = logs .slice(-12) .reverse() .map( (log) => `