feat(админка): очередь внимания

This commit is contained in:
anor
2026-11-06 21:15:28 +10:00
parent b658ac347b
commit 0e7fd76fa1
6 changed files with 237 additions and 1 deletions
+25
View File
@@ -266,6 +266,9 @@ def init_db():
"ON account_entries(username, ts)")
conn.execute("CREATE TABLE IF NOT EXISTS admin_visits ("
"email TEXT PRIMARY KEY, last_seen REAL NOT NULL)")
conn.execute("CREATE TABLE IF NOT EXISTS attention_state ("
"key TEXT PRIMARY KEY, status TEXT NOT NULL, "
"snooze_until REAL, updated_at REAL NOT NULL)")
# Что просили у движка смет и что он ответил — пишет ОСНОВНОЙ процесс, а не агент.
# Всё, что лежит в рабочей папке вкладки, агенту доступно на запись: 14.09.2026 он
# переписал файл запрета и выгрузил неполную смету для экспертизы. База ему недоступна.
@@ -1643,6 +1646,28 @@ def record_admin_visit(email: str, now: float | None = None) -> dict:
return {"previous": previous, "now": ts}
def get_attention_states() -> dict:
with _conn() as conn:
rows = conn.execute("SELECT key, status, snooze_until FROM attention_state").fetchall()
return {r["key"]: {"status": r["status"], "snooze_until": r["snooze_until"]} for r in rows}
def clear_attention_state(key: str) -> None:
with _conn() as conn:
conn.execute("DELETE FROM attention_state WHERE key = ?", (key,))
def set_attention_state(key: str, status: str, snooze_until: float | None = None,
now: float | None = None) -> None:
ts = time.time() if now is None else now
with _conn() as conn:
conn.execute("INSERT INTO attention_state (key, status, snooze_until, updated_at) "
"VALUES (?,?,?,?) ON CONFLICT(key) DO UPDATE SET "
"status=excluded.status, snooze_until=excluded.snooze_until, "
"updated_at=excluded.updated_at",
(key, status, snooze_until, ts))
def get_admin_visit(email: str) -> float | None:
with _conn() as conn:
row = conn.execute("SELECT last_seen FROM admin_visits WHERE email = ?",