feat: more functionality for obsidian plugin
This commit is contained in:
@@ -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 -------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user