refactor: fusion glossaire vers concept (code API + MCP)

- api_context.py : ConceptCreate/Patch, routes /api/concepts, briefing 'Concepts'
- mcp_server.py : get_concepts (ex get_glossaire), tool_get_note garde-fou lecture retire
- redirige type=termeGlossaire vers type=concept partout (lecture, creation, briefing)
- section briefing filtree sur concepts ayant une definition (role lexical)
Corrige le 'glossaire vide' vu au test Phase 3 (code cherchait un type mort).
This commit is contained in:
2026-07-01 21:10:19 +02:00
parent 3631f11362
commit 9ab6bbf116
3 changed files with 45 additions and 44 deletions
+32 -30
View File
@@ -124,15 +124,15 @@ class ConversationPatch(BaseModel):
synthese_cloture: Optional[str] = Field(None, max_length=500)
statut: Optional[str] = Field(None, pattern="^(en-cours|clos)$")
class GlossaireCreate(BaseModel):
class ConceptCreate(BaseModel):
projet: str
terme: str
definition: str
synonymes_eviter: Optional[str] = None
class GlossairePatch(BaseModel):
titre: str
definition: Optional[str] = None
synonymes_eviter: Optional[str] = None
source: Optional[str] = None
class ConceptPatch(BaseModel):
definition: Optional[str] = None
source: Optional[str] = None
class SkillCreate(BaseModel):
titre: str
@@ -416,40 +416,41 @@ def patch_conversation(note_id: str, body: ConversationPatch, llm: str = Depends
return {"id": note_id, "updated_by": llm}
# ---------------------------------------------------------------------------
# Routes — Glossaire
# Routes — Concepts
# ---------------------------------------------------------------------------
@app.get("/api/glossaire/{projet}", tags=["Glossaire"])
def list_glossaire(projet: str, llm: str = Depends(get_llm)):
@app.get("/api/concepts/{projet}", tags=["Concepts"])
def list_concepts(projet: str, llm: str = Depends(get_llm)):
from trilium_api import search_by_label, get_label_value
notes = search_by_label("type", "termeGlossaire")
termes = [n for n in notes
if get_label_value(n["noteId"], "projet") == projet]
return [note_to_dict(n, with_content=True) for n in termes]
notes = search_by_label("type", "concept")
concepts = [n for n in notes
if get_label_value(n["noteId"], "projet") == projet]
return [note_to_dict(n, with_content=True) for n in concepts]
@app.post("/api/glossaire", tags=["Glossaire"], status_code=201)
def create_glossaire(body: GlossaireCreate, llm: str = Depends(get_llm)):
@app.post("/api/concepts", tags=["Concepts"], status_code=201)
def create_concept(body: ConceptCreate, llm: str = Depends(get_llm)):
import json
from trilium_api import create_note, get_note_id, set_label
with open(os.path.expanduser("~/App/Context_continuity/trilium_ids.json")) as f:
ids = json.load(f)
content = f"<p><b>Définition</b> : {body.definition}</p>"
if body.synonymes_eviter:
content += f"<p><b>Synonymes à éviter</b> : {body.synonymes_eviter}</p>"
res = create_note(ids["Glossaire"], body.terme, content=content)
content = f"<p><b>Définition</b> : {body.definition}</p>" if body.definition else " "
res = create_note(ids["Concepts"], body.titre, content=content)
nid = get_note_id(res)
set_label(nid, "type", "termeGlossaire")
set_label(nid, "projet", body.projet)
set_label(nid, "definition", body.definition)
return {"id": nid, "terme": body.terme, "created_by": llm}
set_label(nid, "type", "concept")
set_label(nid, "projet", body.projet)
if body.definition:
set_label(nid, "definition", body.definition)
if body.source:
set_label(nid, "source", body.source)
return {"id": nid, "titre": body.titre, "created_by": llm}
@app.patch("/api/glossaire/{note_id}", tags=["Glossaire"])
def patch_glossaire(note_id: str, body: GlossairePatch, llm: str = Depends(get_llm)):
@app.patch("/api/concepts/{note_id}", tags=["Concepts"])
def patch_concept(note_id: str, body: ConceptPatch, llm: str = Depends(get_llm)):
from trilium_api import get_note, set_label, get_note_content, update_note_content
try:
get_note(note_id)
except Exception:
raise HTTPException(status_code=404, detail="Terme introuvable")
raise HTTPException(status_code=404, detail="Concept introuvable")
if body.definition:
set_label(note_id, "definition", body.definition)
content = get_note_content(note_id)
@@ -489,9 +490,10 @@ def get_contexte(projet: str, llm_cible: str = "LLM",
if get_label_value(b["noteId"], "projet") == projet
and get_label_value(b["noteId"], "statut") not in ("fait", "abandonne")]
glossaire = search_by_label("type", "termeGlossaire")
glossaire = search_by_label("type", "concept")
glossaire = [g for g in glossaire
if get_label_value(g["noteId"], "projet") == projet]
if get_label_value(g["noteId"], "projet") == projet
and get_label_value(g["noteId"], "definition")]
date = datetime.now().strftime("%d/%m/%Y")
lines = [
@@ -513,7 +515,7 @@ def get_contexte(projet: str, llm_cible: str = "LLM",
lines.append("")
if glossaire:
lines += ["## Glossaire"]
lines += ["## Concepts"]
for g in glossaire:
defn = get_label_value(g["noteId"], "definition") or "(voir note)"
lines.append(f"- **{g.get('title','?')}** : {defn}")