81468df9c0
Geteiltes Gedaechtnis: services/memory.py (SQLite/WAL, 5 Kategorien, Dedupe-Kurator deterministisch), routers/memory.py (CRUD/export/dedupe). MCP: mcp/mcp_memory.py (Guard-Beschreibungen gegen 14B-Loop) + mcp/mcp_mc.py NEU (Stack-Management fuer Hermes: list/discover/register/route/restart/ status). Frontend MemoryView (Add/Filter/Suche/Delete/Aufraeumen). Lokal verifiziert: CRUD + Dedupe (TestClient), MCP-Server syntax-OK, Frontend-Build + Browser (MemoryView). Docs aktualisiert. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
"""Memory-Endpoints (geteiltes Gedächtnis). LAN-only, kein Token in 2.0-Phase 3."""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from services import memory
|
|
|
|
router = APIRouter(prefix="/api")
|
|
|
|
|
|
class MemIn(BaseModel):
|
|
content: str
|
|
category: str = "stable"
|
|
source: str = "manual"
|
|
|
|
|
|
class MemUp(BaseModel):
|
|
content: str | None = None
|
|
category: str | None = None
|
|
|
|
|
|
class DedupeIn(BaseModel):
|
|
apply: bool = False
|
|
threshold: float = 0.85
|
|
|
|
|
|
@router.get("/memory/export")
|
|
def export() -> dict:
|
|
return memory.export_text()
|
|
|
|
|
|
@router.post("/memory/dedupe")
|
|
def dedupe(body: DedupeIn) -> dict:
|
|
return memory.dedupe(apply=body.apply, threshold=body.threshold)
|
|
|
|
|
|
@router.get("/memory")
|
|
def list_mem(q: str = "", category: str = "") -> list[dict]:
|
|
return memory.list_memories(q=q, category=category)
|
|
|
|
|
|
@router.post("/memory", status_code=201)
|
|
def add(body: MemIn) -> dict:
|
|
if body.category not in memory.CATEGORIES:
|
|
raise HTTPException(400, f"Kategorie '{body.category}' unbekannt.")
|
|
return memory.add_memory(body.content, body.category, body.source)
|
|
|
|
|
|
@router.put("/memory/{mid}")
|
|
def update(mid: str, body: MemUp) -> dict:
|
|
res = memory.update_memory(mid, content=body.content, category=body.category)
|
|
if not res:
|
|
raise HTTPException(404, "Eintrag nicht gefunden")
|
|
return res
|
|
|
|
|
|
@router.delete("/memory/{mid}")
|
|
def delete(mid: str) -> dict:
|
|
if not memory.delete_memory(mid):
|
|
raise HTTPException(404, "Eintrag nicht gefunden")
|
|
return {"ok": True}
|