feat(launch-Ф3): TG-алерты (alerts.py) + дашборд «Расходы LLM» в админке
- alerts.send_tg: ALERT_TG_* (те же ключи, что канарейка), no-op без ключей, никогда не raise; quotas подхватывает автоматически (гейт ImportError снят) - GET /api/admin/costs: день×юзер×путь×провайдер + agent_24h/капы; секция в админке (textContent для username — XSS-дисциплина) - 4 red-green теста (tests/test_alerts_costs.py) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,7 @@ document.addEventListener('DOMContentLoaded',applyThemeIcon);
|
||||
<a href="#audit" onclick="return showPage('audit')">Журнал</a>
|
||||
<a href="#feedback" onclick="return showPage('feedback')">Жалобы</a>
|
||||
<a href="#files" onclick="return showPage('files')">Файлы</a>
|
||||
<a href="#costs" onclick="return showPage('costs')">Расходы</a>
|
||||
<a href="#" id="theme-toggle" onclick="toggleTheme();return false">🌙 Тёмная тема</a>
|
||||
<a href="/" class="back">← Вернуться в чат</a>
|
||||
<div class="app-version" style="position:absolute;bottom:.5rem;left:1rem;font-size:.65rem;color:#999"></div>
|
||||
@@ -126,6 +127,15 @@ document.addEventListener('DOMContentLoaded',applyThemeIcon);
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Расходы LLM (Ф3 публичного запуска) -->
|
||||
<div class="page" id="page-costs">
|
||||
<h2>Расходы LLM</h2>
|
||||
<div id="costs-totals" style="margin:.4rem 0 .8rem;font-size:.85rem;color:var(--muted)"></div>
|
||||
<table id="costs">
|
||||
<tr><th>День</th><th>Пользователь</th><th>Путь</th><th>Провайдер</th><th>Запросов</th><th>Токены (in/out)</th><th>$</th></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Invites -->
|
||||
<div class="page" id="page-invites">
|
||||
<h2>Приглашения</h2>
|
||||
@@ -351,6 +361,34 @@ async function toggleKillswitch(cb) {
|
||||
}
|
||||
loadKillswitch();
|
||||
|
||||
// === Расходы LLM ===
|
||||
async function loadCosts() {
|
||||
try {
|
||||
const r = await fetch('/api/admin/costs?days=14', {headers: H});
|
||||
const d = await r.json();
|
||||
document.getElementById('costs-totals').textContent =
|
||||
'Агент за 24ч: $' + (d.totals.agent_24h || 0).toFixed(3) +
|
||||
' (глобальный кап $' + d.totals.global_cap + '/день, юзер-кап $' + d.totals.user_cap + '/день)';
|
||||
const t = document.getElementById('costs');
|
||||
t.innerHTML = '<tr><th>День</th><th>Пользователь</th><th>Путь</th><th>Провайдер</th><th>Запросов</th><th>Токены (in/out)</th><th>$</th></tr>';
|
||||
for (const row of d.daily) {
|
||||
const tr = document.createElement('tr');
|
||||
// username — пользовательские данные → только textContent (не innerHTML)
|
||||
const cells = [row.day, row.username, row.path, row.provider || '—',
|
||||
String(row.requests),
|
||||
row.input_tokens + ' / ' + row.output_tokens,
|
||||
row.cost_usd != null ? row.cost_usd.toFixed(4) : '—'];
|
||||
for (const c of cells) {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = c;
|
||||
tr.appendChild(td);
|
||||
}
|
||||
t.appendChild(tr);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
loadCosts();
|
||||
|
||||
// === Files (admin) ===
|
||||
function fmtSize(n){
|
||||
if (n < 1024) return n+' B';
|
||||
|
||||
Reference in New Issue
Block a user