2026-03-27 16:01:28 +08:00
|
|
|
"""Memory 策展与内部扩展 API。"""
|
2026-03-18 17:18:23 +08:00
|
|
|
|
2026-05-22 13:44:50 +08:00
|
|
|
from fastapi import APIRouter, Depends, status
|
2026-03-27 16:01:28 +08:00
|
|
|
from pydantic import BaseModel, Field
|
2026-03-18 17:18:23 +08:00
|
|
|
|
2026-05-22 13:44:50 +08:00
|
|
|
from app.core.deps_types import CurrentUserDep
|
|
|
|
|
from app.core.errors import NotFoundError
|
2026-03-27 16:01:28 +08:00
|
|
|
from app.features.memory.deps import get_memory_service
|
|
|
|
|
from app.features.memory.service import MemoryService
|
|
|
|
|
from app.features.user.models import User
|
|
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api/memory", tags=["memory"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExcludeBody(BaseModel):
|
|
|
|
|
reason: str = Field(default="", max_length=2000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RejectFactBody(BaseModel):
|
|
|
|
|
reason: str = Field(default="", max_length=2000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/chunks/{chunk_id}/exclude", status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
async def exclude_chunk(
|
|
|
|
|
chunk_id: str,
|
2026-05-22 13:44:50 +08:00
|
|
|
current_user: CurrentUserDep,
|
2026-03-27 16:01:28 +08:00
|
|
|
memory: MemoryService = Depends(get_memory_service),
|
2026-05-22 13:44:50 +08:00
|
|
|
body: ExcludeBody | None = None,
|
2026-03-27 16:01:28 +08:00
|
|
|
):
|
|
|
|
|
reason = (body.reason if body else "") or ""
|
|
|
|
|
ok = await memory.exclude_chunk(current_user.id, chunk_id, reason=reason)
|
|
|
|
|
if not ok:
|
2026-05-22 13:44:50 +08:00
|
|
|
raise NotFoundError("chunk 不存在")
|
2026-03-27 16:01:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/chunks/{chunk_id}/restore", status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
async def restore_chunk(
|
|
|
|
|
chunk_id: str,
|
2026-05-22 13:44:50 +08:00
|
|
|
current_user: CurrentUserDep,
|
2026-03-27 16:01:28 +08:00
|
|
|
memory: MemoryService = Depends(get_memory_service),
|
|
|
|
|
):
|
|
|
|
|
ok = await memory.restore_chunk(current_user.id, chunk_id)
|
|
|
|
|
if not ok:
|
2026-05-22 13:44:50 +08:00
|
|
|
raise NotFoundError("chunk 不存在")
|
2026-03-27 16:01:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/facts/{fact_id}/confirm", status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
async def confirm_fact(
|
|
|
|
|
fact_id: str,
|
2026-05-22 13:44:50 +08:00
|
|
|
current_user: CurrentUserDep,
|
2026-03-27 16:01:28 +08:00
|
|
|
memory: MemoryService = Depends(get_memory_service),
|
|
|
|
|
):
|
|
|
|
|
ok = await memory.confirm_fact(current_user.id, fact_id)
|
|
|
|
|
if not ok:
|
2026-05-22 13:44:50 +08:00
|
|
|
raise NotFoundError("fact 不存在")
|
2026-03-27 16:01:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/facts/{fact_id}/reject", status_code=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
async def reject_fact(
|
|
|
|
|
fact_id: str,
|
2026-05-22 13:44:50 +08:00
|
|
|
current_user: CurrentUserDep,
|
2026-03-27 16:01:28 +08:00
|
|
|
memory: MemoryService = Depends(get_memory_service),
|
2026-05-22 13:44:50 +08:00
|
|
|
body: RejectFactBody | None = None,
|
2026-03-27 16:01:28 +08:00
|
|
|
):
|
|
|
|
|
reason = (body.reason if body else "") or ""
|
|
|
|
|
ok = await memory.reject_fact(current_user.id, fact_id, reason=reason)
|
|
|
|
|
if not ok:
|
2026-05-22 13:44:50 +08:00
|
|
|
raise NotFoundError("fact 不存在")
|