add get_recent_activity endpoint

This commit is contained in:
phernandez
2024-12-30 20:32:55 -06:00
parent 7a06b87bd1
commit 1507875785
10 changed files with 445 additions and 99 deletions
+2
View File
@@ -9,6 +9,7 @@ from basic_memory import db
from .routers import documents
from .routers import knowledge
from .routers import discovery
from .routers.activity_router import router as activity_router
@asynccontextmanager
@@ -32,3 +33,4 @@ app = FastAPI(
app.include_router(knowledge.router)
app.include_router(documents.router)
app.include_router(discovery.router)
app.include_router(activity_router)
@@ -0,0 +1,50 @@
"""Activity router for tracking recent changes."""
from typing import List, Optional
from fastapi import APIRouter, Depends, Query
from loguru import logger
from basic_memory.deps import get_activity_service
from basic_memory.services.activity_service import ActivityService
from basic_memory.schemas.activity import RecentActivity, ActivityType
router = APIRouter(
prefix="/activity",
tags=["activity"]
)
@router.get(
"/recent",
response_model=RecentActivity,
summary="Get recent activity"
)
async def get_recent_activity(
activity_service: ActivityService = Depends(get_activity_service),
timeframe: str = "1d",
activity_types: Optional[List[str]] = Query(None), # Use Query for array params
include_content: bool = True
) -> RecentActivity:
"""
Get recent activity across the knowledge base.
Args:
timeframe: Time window to look back (1h, 1d, 1w, 1m)
activity_types: Optional list of types to include
include_content: Whether to include full content
Returns:
RecentActivity with changes and summary
"""
logger.debug(
f"Getting recent activity (timeframe={timeframe}, "
f"types={activity_types}, include_content={include_content})"
)
return await activity_service.get_recent_activity(
timeframe=timeframe,
activity_types=activity_types,
include_content=include_content
)