fix: DAGI Router agents logic, MicroDAO logo URL handling
This commit is contained in:
@@ -190,7 +190,11 @@ export default function MicrodaoDetailPage() {
|
||||
<div className="w-24 h-24 rounded-2xl bg-slate-800 border border-white/10 flex items-center justify-center overflow-hidden shadow-xl">
|
||||
{microdao.logo_url ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={microdao.logo_url} alt={microdao.name} className="w-full h-full object-cover" />
|
||||
<img
|
||||
src={microdao.logo_url.startsWith('/api/static') ? microdao.logo_url : microdao.logo_url.startsWith('/static') ? `/api${microdao.logo_url}` : microdao.logo_url}
|
||||
alt={microdao.name}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Building2 className="w-10 h-10 text-slate-600" />
|
||||
)}
|
||||
|
||||
@@ -7,9 +7,13 @@
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/bin/python3</string>
|
||||
<string>/opt/homebrew/bin/python3</string>
|
||||
<string>/Users/apple/github-projects/microdao-daarion/scripts/node-guardian-loop.py</string>
|
||||
<string>--node-id=node-2-macbook-m4max</string>
|
||||
<string>--node-name=MacBook Pro M4 Max</string>
|
||||
<string>--city-url=https://daarion.space/api</string>
|
||||
<string>--environment=development</string>
|
||||
<string>--roles=development,gpu,ai_runtime,testing</string>
|
||||
</array>
|
||||
|
||||
<key>WorkingDirectory</key>
|
||||
@@ -17,8 +21,6 @@
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>CITY_API_URL</key>
|
||||
<string>https://daarion.space/api/city</string>
|
||||
<key>SWAPPER_URL</key>
|
||||
<string>http://localhost:8890</string>
|
||||
<key>PYTHONUNBUFFERED</key>
|
||||
|
||||
@@ -4167,8 +4167,9 @@ async def get_dagi_router_health(node_id: str):
|
||||
@router.get("/internal/node/{node_id}/dagi-router/agents")
|
||||
async def get_dagi_router_agents(node_id: str):
|
||||
"""
|
||||
Get list of agents registered with DAGI Router for a node.
|
||||
Compares with DB to identify phantom/stale agents.
|
||||
Get list of agents for a node.
|
||||
Since DAGI Router doesn't expose /agents endpoint, we use DB agents
|
||||
and check router health to determine status.
|
||||
"""
|
||||
import httpx
|
||||
|
||||
@@ -4178,68 +4179,54 @@ async def get_dagi_router_agents(node_id: str):
|
||||
}
|
||||
|
||||
base_url = NODE_ROUTER_URLS.get(node_id)
|
||||
router_agents = []
|
||||
router_healthy = False
|
||||
|
||||
# Try to get agents from router
|
||||
# Check if router is healthy
|
||||
if base_url:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
resp = await client.get(f"{base_url}/agents")
|
||||
async with httpx.AsyncClient(timeout=3.0) as client:
|
||||
resp = await client.get(f"{base_url}/health")
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
router_agents = data.get("agents", [])
|
||||
router_healthy = data.get("status") == "healthy"
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to get agents from router for {node_id}: {e}")
|
||||
logger.warning(f"Failed to check router health for {node_id}: {e}")
|
||||
|
||||
# Get agents from DB for this node
|
||||
try:
|
||||
db_agents = await repo_city.get_agents_for_node(node_id)
|
||||
db_agent_ids = {a.get("id") or a.get("slug") for a in db_agents}
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to get DB agents for {node_id}: {e}")
|
||||
db_agents = []
|
||||
db_agent_ids = set()
|
||||
|
||||
# Build combined list
|
||||
# Build agents list - if router is healthy, agents are "active", otherwise "stale"
|
||||
result_agents = []
|
||||
router_agent_ids = set()
|
||||
|
||||
for ra in router_agents:
|
||||
agent_id = ra.get("id") or ra.get("name") or ra.get("slug")
|
||||
for db_agent in db_agents:
|
||||
agent_id = db_agent.get("id") or db_agent.get("slug")
|
||||
if not agent_id:
|
||||
continue
|
||||
router_agent_ids.add(agent_id)
|
||||
|
||||
# Check if in DB
|
||||
has_db_record = agent_id in db_agent_ids
|
||||
status = "active" if has_db_record else "phantom"
|
||||
# Determine status based on router health and agent status
|
||||
agent_status = db_agent.get("status", "offline")
|
||||
if router_healthy and agent_status in ("online", "active"):
|
||||
status = "active"
|
||||
elif router_healthy:
|
||||
status = "stale" # Router up but agent offline
|
||||
else:
|
||||
status = "stale" # Router down
|
||||
|
||||
result_agents.append({
|
||||
"id": agent_id,
|
||||
"name": ra.get("name"),
|
||||
"kind": ra.get("kind"),
|
||||
"runtime": ra.get("runtime") or f"{node_id}-router",
|
||||
"name": db_agent.get("display_name") or db_agent.get("name"),
|
||||
"kind": db_agent.get("kind"),
|
||||
"runtime": f"{node_id}-router" if router_healthy else None,
|
||||
"node_id": node_id,
|
||||
"last_seen_at": ra.get("last_seen_at"),
|
||||
"last_seen_at": db_agent.get("last_seen_at"),
|
||||
"status": status,
|
||||
"has_db_record": has_db_record
|
||||
"has_db_record": True
|
||||
})
|
||||
|
||||
# Add stale agents (in DB but not in router)
|
||||
for db_agent in db_agents:
|
||||
agent_id = db_agent.get("id") or db_agent.get("slug")
|
||||
if agent_id and agent_id not in router_agent_ids:
|
||||
result_agents.append({
|
||||
"id": agent_id,
|
||||
"name": db_agent.get("display_name") or db_agent.get("name"),
|
||||
"kind": db_agent.get("kind"),
|
||||
"runtime": None,
|
||||
"node_id": node_id,
|
||||
"last_seen_at": None,
|
||||
"status": "stale",
|
||||
"has_db_record": True
|
||||
})
|
||||
|
||||
# Count by status
|
||||
active = sum(1 for a in result_agents if a["status"] == "active")
|
||||
phantom = sum(1 for a in result_agents if a["status"] == "phantom")
|
||||
|
||||
Reference in New Issue
Block a user