From 4a405faf25b29840085ce95acfd7046e7b03c881 Mon Sep 17 00:00:00 2001 From: h Date: Thu, 21 May 2026 10:27:21 +0200 Subject: [PATCH] feat: more functionality for obsidian plugin --- .../frontends/markdown/frontend.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/beaver_gateway/frontends/markdown/frontend.py b/src/beaver_gateway/frontends/markdown/frontend.py index 701bc92..a82d698 100644 --- a/src/beaver_gateway/frontends/markdown/frontend.py +++ b/src/beaver_gateway/frontends/markdown/frontend.py @@ -134,6 +134,11 @@ class MarkdownFrontend(Frontend): async def healthz() -> dict[str, str]: return {"status": "ok"} + @app.get("/agents") + async def list_agents(request: Request) -> dict[str, Any]: + await require_token(request, runtime, scope="messages") + return {"agents": [{"name": a.name} for a in runtime.agents]} + @app.post("/chat") async def chat(request: Request) -> Any: token_name = await require_token(request, runtime, scope="messages") @@ -218,10 +223,18 @@ class MarkdownFrontend(Frontend): # When the parser produced no messages (file empty / only # frontmatter), there's nothing to dispatch. if not parsed.messages: - return {"status": "nothing_to_do", "reason": "empty file"} + return { + "status": "nothing_to_do", + "reason": "empty file", + "new_content": file_text, + } if parser.last_role(parsed.messages) == "assistant": - return {"status": "nothing_to_do", "reason": "last turn is assistant"} + return { + "status": "nothing_to_do", + "reason": "last turn is assistant", + "new_content": file_text, + } agent = runtime.agents.get(agent_name) if agent is None: @@ -281,9 +294,8 @@ class MarkdownFrontend(Frontend): updated_metadata = dict(parsed.metadata) updated_metadata["agent"] = agent.name updated_metadata["fingerprint"] = fingerprint_messages(updated_messages) - await _write_atomic( - file_path, _reattach_frontmatter(updated_metadata, new_body) - ) + new_content = _reattach_frontmatter(updated_metadata, new_body) + await _write_atomic(file_path, new_content) # Broadcast our own turn so other handlers (none today, but the # symmetry is worth keeping) see what happened. ``source`` marks @@ -301,7 +313,12 @@ class MarkdownFrontend(Frontend): except Exception: # noqa: BLE001 _log.exception("turn_log_handler raised; continuing") - return {"status": "ok", "turns_appended": 1, "agent": agent.name} + return { + "status": "ok", + "turns_appended": 1, + "agent": agent.name, + "new_content": new_content, + } # ---- helpers -------------------------------------------------------