From bd3d756de9dd20e672c856b1a1adb392edaf5042 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 28 Nov 2025 08:07:20 -0800 Subject: [PATCH] fix: add get_agent_prompts and get_agent_public_profile methods --- services/city-service/repo_city.py | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/services/city-service/repo_city.py b/services/city-service/repo_city.py index ac7fb81d..1778ab54 100644 --- a/services/city-service/repo_city.py +++ b/services/city-service/repo_city.py @@ -460,6 +460,78 @@ async def update_agent_visibility( return result is not None +async def get_agent_prompts(agent_id: str) -> dict: + """Отримати системні промти агента""" + pool = await get_pool() + + query = """ + SELECT kind, content, version, created_at, note + FROM agent_prompts + WHERE agent_id = $1 + AND is_active = true + ORDER BY kind + """ + + rows = await pool.fetch(query, agent_id) + + result = { + "core": None, + "safety": None, + "governance": None, + "tools": None + } + + for row in rows: + kind = row["kind"] + if kind in result: + result[kind] = { + "content": row["content"], + "version": row["version"], + "created_at": row["created_at"].isoformat() if row["created_at"] else None, + "note": row.get("note") + } + + return result + + +async def get_agent_public_profile(agent_id: str) -> Optional[dict]: + """Отримати публічний профіль агента""" + pool = await get_pool() + + query = """ + SELECT + is_public, + public_slug, + public_title, + public_tagline, + COALESCE(public_skills, ARRAY[]::text[]) AS public_skills, + public_district, + public_primary_room_slug, + COALESCE(visibility_scope, 'city') AS visibility_scope, + COALESCE(is_listed_in_directory, true) AS is_listed_in_directory, + COALESCE(is_system, false) AS is_system + FROM agents + WHERE id = $1 + """ + + row = await pool.fetchrow(query, agent_id) + if not row: + return None + + return { + "is_public": row["is_public"], + "public_slug": row["public_slug"], + "public_title": row["public_title"], + "public_tagline": row["public_tagline"], + "public_skills": list(row["public_skills"] or []), + "public_district": row["public_district"], + "public_primary_room_slug": row["public_primary_room_slug"], + "visibility_scope": row["visibility_scope"], + "is_listed_in_directory": row["is_listed_in_directory"], + "is_system": row["is_system"] + } + + async def get_agents_with_home_node( kind: Optional[str] = None, node_id: Optional[str] = None,