diff --git a/src/api/mail_routes.py b/src/api/mail_routes.py index dddc62b..4de4038 100644 --- a/src/api/mail_routes.py +++ b/src/api/mail_routes.py @@ -100,6 +100,48 @@ async def list_mail( return {"mails": mails, "total": len(mails)} +@router.get("/agents/list") +async def list_mail_agents(): + """列出参与过 Mail 的所有 Agent(用于筛选)""" + q = _q() + conn = q._conn() + try: + senders = conn.execute( + "SELECT DISTINCT assigned_by FROM tasks WHERE assigned_by IS NOT NULL" + ).fetchall() + receivers = conn.execute( + "SELECT DISTINCT assignee FROM tasks WHERE assignee IS NOT NULL" + ).fetchall() + agents = list(set( + [r["assigned_by"] for r in senders] + + [r["assignee"] for r in receivers] + )) + agents.sort() + return {"agents": agents} + finally: + conn.close() + + +@router.get("/summary") +async def mail_summary(): + """Mail 摘要(未读数、总数)""" + bb = _bb() + all_tasks = bb.list_tasks() + + total = len(all_tasks) + unread = 0 + by_type: Dict[str, int] = {} + + for t in all_tasks: + meta = _mail_meta(t) + if not meta.get("is_read", False): + unread += 1 + mtype = meta.get("type", "inform") + by_type[mtype] = by_type.get(mtype, 0) + 1 + + return {"total": total, "unread": unread, "by_type": by_type} + + @router.get("/{mail_id}") async def get_mail(mail_id: str): """Mail 详情"""