Files
personal-ai-assistant/backend/app/api/v1/users.py
dolgolyov.alexei 03afb7a075 Phase 3: Skills & Context — skill system, personal context, context layering
Backend:
- Skill model + migration (with FK on chats.skill_id)
- Personal + general skill CRUD services with access isolation
- Admin skill CRUD endpoints (POST/GET/PATCH/DELETE /admin/skills)
- User skill CRUD endpoints (POST/GET/PATCH/DELETE /skills/)
- Personal context GET/PUT at /users/me/context
- Extended context assembly: primary + personal context + skill prompt
- Chat creation/update now accepts skill_id with validation

Frontend:
- Skill selector dropdown in chat header (grouped: general + personal)
- Reusable skill editor form component
- Admin skills management page (/admin/skills)
- Personal skills page (/skills)
- Personal context editor page (/profile/context)
- Updated sidebar: Skills, My Context nav items + admin skills link
- English + Russian translations for all skill/context UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:55:02 +03:00

34 lines
1.1 KiB
Python

from typing import Annotated
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from app.api.deps import get_current_user
from app.database import get_db
from app.models.user import User
from app.schemas.chat import ContextFileResponse, UpdateContextRequest
from app.services import context_service
router = APIRouter(prefix="/users", tags=["users"])
@router.get("/me/context", response_model=ContextFileResponse | None)
async def get_personal_context(
user: Annotated[User, Depends(get_current_user)],
db: Annotated[AsyncSession, Depends(get_db)],
):
ctx = await context_service.get_personal_context(db, user.id)
if not ctx:
return None
return ContextFileResponse.model_validate(ctx)
@router.put("/me/context", response_model=ContextFileResponse)
async def update_personal_context(
data: UpdateContextRequest,
user: Annotated[User, Depends(get_current_user)],
db: Annotated[AsyncSession, Depends(get_db)],
):
ctx = await context_service.upsert_personal_context(db, user.id, data.content)
return ContextFileResponse.model_validate(ctx)