feat(launch-Ф1): гейт агентного пути (users.agent_access) + kill-switch (app_settings)
Подготовка к открытию (docs/PUBLIC_LAUNCH_PLAN.md, Ф1): - users.agent_access: миграция grandfather=1 существующим; новым — дефолт схемы 0, саморегистрация из env AGENT_ACCESS_DEFAULT (сейчас 1, в день открытия → 0 без деплоя) - app_settings в БД + agent_killswitch: POST/GET /api/admin/killswitch, переживает рестарт - agent_provider.agent_allowed(): владелец всегда да (даже killswitch — стоп ЧУЖИХ денег); сбой БД = fail-closed (дорогой путь режем, Q&A работает) - enforcement в hybrid-wrapper: агентный запрос без доступа → Q&A-ответ + приписка ДО done - админка: колонка «Агент» (чекбокс) + тумблер kill-switch; эндпоинт agent-access (404-контракт) - 13 red-green тестов (tests/test_agent_gate.py) с mutation-заметками; suite 407 passed Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+46
-2
@@ -114,8 +114,15 @@ document.addEventListener('DOMContentLoaded',applyThemeIcon);
|
||||
<!-- Users -->
|
||||
<div class="page" id="page-users">
|
||||
<h2>Пользователи</h2>
|
||||
<div id="killswitch-bar" style="margin:.4rem 0 .8rem;font-size:.85rem">
|
||||
<label style="cursor:pointer">
|
||||
<input type="checkbox" id="killswitch-cb" onchange="toggleKillswitch(this)">
|
||||
<b>Kill-switch агента</b> — аварийно выключить агентный путь для всех (кроме владельцев)
|
||||
</label>
|
||||
<span id="killswitch-state" style="margin-left:.5rem;color:var(--muted)"></span>
|
||||
</div>
|
||||
<table id="users">
|
||||
<tr><th>Email</th><th>Роль</th><th>Статус</th><th>Провайдер</th><th>Создан</th><th>Действия</th></tr>
|
||||
<tr><th>Email</th><th>Роль</th><th>Статус</th><th>Провайдер</th><th>Агент</th><th>Создан</th><th>Действия</th></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -257,7 +264,7 @@ async function userAction(action, email, data={}) {
|
||||
function loadUsers() {
|
||||
fetch('/api/admin/users', {headers: H}).then(r=>r.json()).then(users => {
|
||||
const t = document.getElementById('users');
|
||||
t.innerHTML = '<tr><th>Email</th><th>Роль</th><th>Статус</th><th>Провайдер</th><th>Создан</th><th>Действия</th></tr>';
|
||||
t.innerHTML = '<tr><th>Email</th><th>Роль</th><th>Статус</th><th>Провайдер</th><th>Агент</th><th>Создан</th><th>Действия</th></tr>';
|
||||
for (const u of users) {
|
||||
const d = new Date(u.created_at < 1e12 ? u.created_at*1000 : u.created_at);
|
||||
const tr = document.createElement('tr');
|
||||
@@ -288,6 +295,19 @@ function loadUsers() {
|
||||
};
|
||||
provTd.appendChild(sel);
|
||||
tr.appendChild(provTd);
|
||||
// Агент: доступ к дорогому агентному пути (Ф1 публичного запуска). Владелец — всегда да.
|
||||
const agTd = document.createElement('td');
|
||||
const agCb = document.createElement('input');
|
||||
agCb.type = 'checkbox';
|
||||
agCb.checked = u.is_owner || !!u.agent_access;
|
||||
if (u.is_owner) { agCb.disabled = true; agCb.title = 'Владелец: доступ всегда'; }
|
||||
agCb.onchange = () => {
|
||||
if (!agCb.checked || confirm('Выдать ' + u.email + ' доступ к агентным функциям (Docker+LLM, платно)?')) {
|
||||
userAction('agent-access', u.email, {enabled: agCb.checked});
|
||||
} else { agCb.checked = false; }
|
||||
};
|
||||
agTd.appendChild(agCb);
|
||||
tr.appendChild(agTd);
|
||||
const createdTd = document.createElement('td');
|
||||
createdTd.className = 'time';
|
||||
createdTd.textContent = ts;
|
||||
@@ -307,6 +327,30 @@ function loadUsers() {
|
||||
}
|
||||
loadUsers();
|
||||
|
||||
// === Kill-switch агента ===
|
||||
async function loadKillswitch() {
|
||||
try {
|
||||
const r = await fetch('/api/admin/killswitch', {headers: H});
|
||||
const d = await r.json();
|
||||
const cb = document.getElementById('killswitch-cb');
|
||||
cb.checked = (d.state === 'on');
|
||||
document.getElementById('killswitch-state').textContent =
|
||||
d.state === 'on' ? '⛔ агент ВЫКЛЮЧЕН для всех (кроме владельцев)' : 'агент работает';
|
||||
} catch (e) {}
|
||||
}
|
||||
async function toggleKillswitch(cb) {
|
||||
const on = cb.checked;
|
||||
if (on && !confirm('Аварийно ВЫКЛЮЧИТЬ агентный путь для всех пользователей (кроме владельцев)?')) {
|
||||
cb.checked = false; return;
|
||||
}
|
||||
const r = await fetch('/api/admin/killswitch', {method:'POST',
|
||||
headers:{...H,'Content-Type':'application/json'}, body:JSON.stringify({state: on ? 'on' : 'off'})});
|
||||
const d = await r.json();
|
||||
if (!d.ok) alert(d.detail || 'Ошибка');
|
||||
loadKillswitch();
|
||||
}
|
||||
loadKillswitch();
|
||||
|
||||
// === Files (admin) ===
|
||||
function fmtSize(n){
|
||||
if (n < 1024) return n+' B';
|
||||
|
||||
Reference in New Issue
Block a user