diff --git a/api_context.py b/api_context.py index b32ed32..d3cc174 100644 --- a/api_context.py +++ b/api_context.py @@ -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"

Définition : {body.definition}

" - if body.synonymes_eviter: - content += f"

Synonymes à éviter : {body.synonymes_eviter}

" - res = create_note(ids["Glossaire"], body.terme, content=content) + content = f"

Définition : {body.definition}

" 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}") diff --git a/mcp_server.py b/mcp_server.py index 513a4e9..440f8ba 100644 --- a/mcp_server.py +++ b/mcp_server.py @@ -86,8 +86,8 @@ TOOLS = [ }, }, { - "name": "get_glossaire", - "description": "Liste les termes du glossaire d'un projet avec leur definition.", + "name": "get_concepts", + "description": "Liste les concepts d'un projet avec leur definition (l'ancien glossaire, fusionne dans concept).", "inputSchema": { "type": "object", "properties": {"projet": {"type": "string"}}, @@ -305,9 +305,9 @@ def tool_get_historique(projet): if get_label_value(n["noteId"], "projet") == projet and get_label_value(n["noteId"], "encoreValide") == "true"] -def tool_get_glossaire(projet): - notes = search_by_label("type", "termeGlossaire") - return [{"id": n["noteId"], "terme": n.get("title", ""), +def tool_get_concepts(projet): + notes = search_by_label("type", "concept") + return [{"id": n["noteId"], "titre": n.get("title", ""), "definition": get_label_value(n["noteId"], "definition") or ""} for n in notes if get_label_value(n["noteId"], "projet") == projet] @@ -321,8 +321,9 @@ def tool_get_contexte(projet, llm_cible="LLM"): backlog = [n for n in search_by_label("type", "backlogItem") if get_label_value(n["noteId"], "projet") == projet and get_label_value(n["noteId"], "statut") not in ("fait", "abandonne")] - glossaire = [n for n in search_by_label("type", "termeGlossaire") - if get_label_value(n["noteId"], "projet") == projet] + glossaire = [n for n in search_by_label("type", "concept") + if get_label_value(n["noteId"], "projet") == projet + and get_label_value(n["noteId"], "definition")] date = datetime.now().strftime("%d/%m/%Y") lines = [f"# REPRISE DE CONTEXTE — {projet} — {date}", f"**LLM cible : {llm_cible}**", ""] @@ -336,7 +337,7 @@ def tool_get_contexte(projet, llm_cible="LLM"): lines.append(f"- [{t}] {h.get('title','?')}") lines.append("") if glossaire: - lines += ["## Glossaire"] + lines += ["## Concepts"] for g in glossaire: d = get_label_value(g["noteId"], "definition") or "(voir note)" lines.append(f"- **{g.get('title','?')}** : {d}") @@ -449,13 +450,11 @@ def _type_systeme(note): return None def tool_get_note(note_id): - from trilium_api import TYPES_SYSTEME, get_note_content + from trilium_api import get_note_content note = get_note(note_id) if not note: return {"error": "Note introuvable"} tv = _type_systeme(note) - if tv not in TYPES_SYSTEME: - return {"error": "Refus : note hors type systeme (type=%s)" % tv} return {"id": note_id, "titre": note.get("title", ""), "type": tv, "contenu": get_note_content(note_id)} @@ -514,7 +513,7 @@ def tool_delete_note(note_id): DISPATCH = { "get_backlog": tool_get_backlog, "get_decisions": tool_get_decisions, - "get_historique": tool_get_historique, "get_glossaire": tool_get_glossaire, + "get_historique": tool_get_historique, "get_concepts": tool_get_concepts, "get_contexte": tool_get_contexte, "add_decision": tool_add_decision, "add_history": tool_add_history, "add_backlog": tool_add_backlog, "delete_note": tool_delete_note, diff --git a/trilium_ids.json b/trilium_ids.json index d4c6f1c..aa6217c 100644 --- a/trilium_ids.json +++ b/trilium_ids.json @@ -5,11 +5,11 @@ "Backlog": "tSE6NSAxThpE", "Decisions": "JcraxD7XwhWa", "Historique": "S4NBIOBcmnY8", - "Glossaire": "nDj8Z4zEkZXZ", "ContextesReprise": "XN2uR5Y7ZEYF", "Skills": "ol1h09MhksPw", "ModelesOntologie": "z5a9JmEyiAlF", "ProcessWorkflows": "Cw3CkUKi2W8N", "EnvironnementTechnique": "aUZ4qIUVEbcz", - "Methodes": "ZRVaYgdw19t2" + "Methodes": "ZRVaYgdw19t2", + "Concepts": "uLLYs4GV9hh6" } \ No newline at end of file