// Costs Page Module class CostsPage { constructor() { this.costData = null; this.init(); } async init() { // Load data await Promise.all([ this.loadCostStats(), this.loadCostsChart(), this.loadBudgetTracking(), this.loadPricingTable() ]); // Setup event listeners this.setupEventListeners(); } async loadCostStats() { try { const data = await window.api.get('/usage/summary'); this.costData = { totalCost: data.total_cost, todayCost: data.today_cost, weekCost: data.total_cost * 0.4, // Placeholder for weekly logic monthCost: data.total_cost, avgDailyCost: data.total_cost / 30, // Simplified costTrend: 5.2, budgetUsed: Math.min(Math.round((data.total_cost / 100) * 100), 100), // Assuming $100 budget projectedMonthEnd: data.today_cost * 30, cacheReadTokens: data.total_cache_read_tokens || 0, cacheWriteTokens: data.total_cache_write_tokens || 0, totalTokens: data.total_tokens || 0, }; this.renderCostStats(); } catch (error) { console.error('Error loading cost stats:', error); } } renderCostStats() { const container = document.getElementById('cost-stats'); if (!container) return; const cacheHitRate = this.costData.totalTokens > 0 ? ((this.costData.cacheReadTokens / this.costData.totalTokens) * 100).toFixed(1) : '0.0'; container.innerHTML = `
${row.id}