feat: MicroDAO Rooms Integration

Backend:
- GET /city/microdao/{slug}/agents - list agents with roles
- Seed: 6 rooms for DAARION, 3+ rooms for each District

Task doc: TASK_PHASE_MICRODAO_ROOMS_INTEGRATION_v1.md
This commit is contained in:
Apple
2025-11-30 11:48:44 -08:00
parent 6908569ac7
commit a7adddb60d
2 changed files with 420 additions and 0 deletions

View File

@@ -2777,6 +2777,71 @@ async def get_microdao_rooms_endpoint(slug: str):
raise HTTPException(status_code=500, detail="Failed to get microdao rooms")
@router.get("/microdao/{slug}/agents")
async def get_microdao_agents_endpoint(slug: str):
"""
Отримати всіх агентів MicroDAO.
Повертає список агентів з їх ролями та статусами.
"""
try:
# Get microdao by slug
dao = await repo_city.get_microdao_by_slug(slug)
if not dao:
raise HTTPException(status_code=404, detail=f"MicroDAO not found: {slug}")
# Get agents from microdao_agents
pool = await repo_city.get_pool()
query = """
SELECT
a.id,
a.display_name as name,
a.kind,
a.status,
a.avatar_url,
a.gov_level,
ma.role,
ma.is_core
FROM agents a
JOIN microdao_agents ma ON ma.agent_id = a.id
WHERE ma.microdao_id = $1
AND COALESCE(a.is_archived, false) = false
AND a.deleted_at IS NULL
ORDER BY
ma.is_core DESC,
CASE ma.role
WHEN 'orchestrator' THEN 0
WHEN 'district_lead' THEN 1
WHEN 'core_team' THEN 2
ELSE 3
END,
a.display_name
"""
rows = await pool.fetch(query, dao["id"])
return {
"microdao_id": dao["id"],
"microdao_slug": dao["slug"],
"agents": [
{
"id": r["id"],
"name": r["name"],
"kind": r["kind"],
"status": r["status"],
"avatar_url": r.get("avatar_url"),
"gov_level": r.get("gov_level"),
"role": r["role"],
"is_core": r["is_core"]
}
for r in rows
]
}
except HTTPException:
raise
except Exception as e:
logger.error(f"Failed to get microdao agents for {slug}: {e}")
raise HTTPException(status_code=500, detail="Failed to get microdao agents")
@router.post("/microdao/{slug}/rooms/attach-existing", response_model=CityRoomSummary)
async def attach_existing_room_endpoint(
slug: str,