Newer
Older
navi-1 / navi / api / routes / admin / recalls.py
@Eugene Sukhodolskiy Eugene Sukhodolskiy 1 day ago 1 KB api: split the admin routes into a package
"""Scheduled recalls across all sessions."""

from typing import Annotated

from fastapi import Depends

from navi.api.deps import get_scheduler, require_admin
from navi.auth import User
from navi.core.scheduler import RecallScheduler

from ._router import router


@router.get("/recalls")
async def admin_list_recalls(
    user: Annotated[User, Depends(require_admin)],
    scheduler: Annotated[RecallScheduler, Depends(get_scheduler)],
    limit: int = 50,
    offset: int = 0,
    session_id: str | None = None,
    user_id: str | None = None,
):
    """Return all scheduled recalls with pagination and filtering."""
    recalls = await scheduler.list_recalls(
        session_id=session_id,
        user_id=user_id,
        is_admin=True,
        limit=limit,
        offset=offset,
    )
    return {
        "limit": limit,
        "offset": offset,
        "items": [
            {
                "id": r.id,
                "session_id": r.session_id,
                "call_type": r.call_type,
                "trigger_at": r.trigger_at.isoformat(),
                "interval_seconds": r.interval_seconds,
                "internal_comment": r.internal_comment,
                "additional_context_message": r.additional_context_message,
                "status": r.status,
                "created_at": r.created_at.isoformat(),
                "updated_at": r.updated_at.isoformat(),
            }
            for r in recalls
        ],
    }