[Infra] WS Gateway server — central message hub for Matrix clients, agents, and bots #70
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The Matrix needs a central WebSocket server that all participants connect to: the 3D browser client, Timmy's cognitive bridge (#69), the Perplexity interview bot, and any future agents. This is the server-side complement to the client-side behavior system (#68).
Issue #48 scoped this for the interview use case. This issue expands it to be the permanent gateway for all Matrix communication.
What to build
server/gateway.py— WebSocket gatewayA lightweight Python (FastAPI or standalone
websockets) server:ws://0.0.0.0:8765/ws/matrix?token=<agent_token>query paramagent_registeron connect with theiragentIdandroletarget_idgo to all connected clientstarget_idroute only to that agent's connectionagent_state,bark,scene_*,agent_move,agent_behavior)/api/gateway/statusMessage flow
Supported message types (pass-through)
The gateway does NOT interpret messages — it routes them. All Matrix protocol messages pass through:
agent_state,agent_move,agent_behaviorbark,agent_messagescene_add,scene_update,scene_remove,scene_clear,scene_batchworld_register,world_load,world_unregisterzone_add,zone_removetask_created,task_update,task_actionpayment_flow,system_statuschat_message,visitor_messageConnection lifecycle
Acceptance Criteria
agent_state,bark,agent_movetarget_id) route only to the targetagent_joined/agent_leftbroadcast on connect/disconnect/api/gateway/statusreturns connected agents and their rolesWhere it lives
New
server/directory inperplexity/the-matrix. Lightweight enough to run alongside the Vite dev server or deploy independently.Supersedes
Dependencies
Closed by PR #72 —
server/gateway.pyis the central WS message hub. Configurable port (default 8765), optional token auth, broadcast+directed routing, agent_register/joined/left lifecycle, 30s heartbeat pruning, optional REST /api/gateway/status. Pure pass-through router — does not interpret messages. 10/10 integration tests pass. Supersedes #48.