WebSocket Protocols¶
Archety/Ikiro uses two WebSocket protocols:
- Edge Agent WebSocket (
/edge/ws) — backend ↔ Mac mini edge relay (../archety-edge) - MiniApp WebSocket (
/ws/miniapp/{session_id}) — backend ↔ browser MiniApp UI (../archety-web)
1) Edge Agent WebSocket (/edge/ws)¶
Purpose¶
- Real-time command delivery to the Mac mini edge relay (reflex bubbles, scheduling, context updates, etc.).
- Reduces latency vs HTTP polling via
/edge/sync.
Connection¶
Required headers¶
<edge_token> options (backend: app/edge/auth.py):
- Recommended: HMAC-derived Base64 token created by generate_edge_token(edge_agent_id, user_phone).
- Legacy fallback: raw EDGE_SECRET (only accepted when ENVIRONMENT != production).
Transport envelope¶
All messages are JSON:
Backend → edge message types¶
command— deliver anEdgeCommandpong— keepalive response
Edge → backend message types¶
ping— keepalive (typically every 30s)command_ack— acknowledge a commandstatus— periodic health/status update
command payload¶
Backend sends:
{
"type": "command",
"data": {
"command_id": "uuid",
"command_type": "send_message_now",
"payload": {},
"priority": "immediate",
"timestamp": "2026-02-16T00:00:00Z"
}
}
Current command types are defined in app/edge/schemas.py:
- send_message_now
- schedule_message
- set_rule
- cancel_scheduled
- context_update
- context_reset
- upload_retry
- emit_event
command_ack payload¶
Edge sends:
Allowed status values: received, executing, completed, failed.
HTTP fallback¶
If WebSocket is unavailable, edge agents can poll:
- POST /edge/sync (see app/api/edge_routes.py)
2) MiniApp WebSocket (/ws/miniapp/{session_id})¶
Purpose¶
Real-time updates for multiplayer MiniApp sessions in the web UI.
Connection¶
Authentication¶
The backend currently requires token=<jwt> as a query parameter and validates it via Supabase JWT verification:
- Backend: app/api/websocket_routes.py
- JWT verifier: app/dependencies.py::verify_jwt_token
Message types¶
Backend sends:
- connected — initial confirmation + connection count
- presence — peers joined/left
- state_update — state diffs (server or peer sourced)
- action — peer actions (for optimistic sync)
- pong — heartbeat response
Client sends:
- ping
- state_update
- action
- typing