Files
ServerKit/backend/app/constants.py
T
Juan DenisandClaude Fable 5 00eac38d5d feat(realtime): one room grammar + mirrored event constants (plan 77 E3)
app/sockets_rooms.py owns every Socket.IO room-name builder (the grammar
lived in ~25 scattered f-strings); app/constants.py SOCKET_EVENTS is
mirrored verbatim by frontend/src/constants/events.js and a contract
test parses the JS so a renamed event fails in CI instead of silently
killing a stream. sockets.py / agent_gateway / notification bus and the
two frontend components that hand-derived rooms now use the builders;
ratchet forbids new room f-strings in the realtime layer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 04:58:49 -04:00

43 lines
1.3 KiB
Python

"""Shared wire-protocol constants (plan 77 E3).
``SOCKET_EVENTS`` is mirrored verbatim by ``frontend/src/constants/events.js``
so a renamed event cannot fail silently — ``tests/test_socket_contract.py``
parses the JS file and asserts the two tables are identical. Add or rename an
event in BOTH files (the test tells you when you forgot).
"""
SOCKET_EVENTS = {
# lifecycle / control plane
'CONNECTED': 'connected',
'ERROR': 'error',
'SUBSCRIBED': 'subscribed',
'UNSUBSCRIBED': 'unsubscribed',
'JOINED': 'joined',
'LEFT': 'left',
# broadcast channels
'METRICS': 'metrics',
'CONTAINER_STATUS': 'container_status',
'NOTIFICATION': 'notification',
# file log streaming
'LOG_LINE': 'log_line',
'LOG_ERROR': 'log_error',
# deploy console (legacy names, dual-emitted with the run envelope)
'DEPLOY_LOG': 'deploy_log',
'DEPLOY_STATUS': 'deploy_status',
# generalized run envelope (plan 77 E1) — one event pair for every run kind
'RUN_LOG': 'run_log',
'RUN_STATUS': 'run_status',
# container log streaming
'CONTAINER_LOG': 'container_log',
'CONTAINER_LOG_ERROR': 'container_log_error',
'CONTAINER_LOG_ENDED': 'container_log_ended',
# agent stream rebroadcast (metrics / PTY / arbitrary channels)
'SERVER_STREAM': 'server_stream',
}