Files
JARVIS/backend/app/routers/brain.py
DESKTOP-72TV0V4\caoxiaozhu d2447ee635 Add brain memory services and APIs
Introduce the backend pieces for brain memory ingestion, routing, and
system telemetry so the new knowledge workflows can project data into a
brain view. The supporting tests lock in the new behavior and keep the
expanded backend surface stable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 13:47:34 +08:00

62 lines
1.8 KiB
Python

from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.models.user import User
from app.routers.auth import get_current_user
from app.schemas.brain import (
BrainEventOut,
BrainLearnRunOut,
BrainMemoryOut,
BrainOverviewOut,
BrainTagGroupsOut,
)
from app.services.brain_service import BrainService
router = APIRouter(prefix="/api/brain", tags=["知识大脑"])
@router.get("/overview", response_model=BrainOverviewOut)
async def get_brain_overview(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
service = BrainService(db)
return await service.get_overview(current_user.id)
@router.get("/memories", response_model=list[BrainMemoryOut])
async def list_brain_memories(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
service = BrainService(db)
return await service.list_memories(current_user.id)
@router.get("/tags", response_model=BrainTagGroupsOut)
async def list_brain_tags(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
service = BrainService(db)
return await service.list_tags(current_user.id)
@router.get("/events", response_model=list[BrainEventOut])
async def list_brain_events(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
service = BrainService(db)
return await service.list_events(current_user.id)
@router.post("/learn/run", response_model=BrainLearnRunOut)
async def run_brain_learning(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
service = BrainService(db)
return await service.run_learning(current_user.id)