APIs
Consumers for the prompt app web console terminal logs tab, which handle WebSocket connections for real-time terminal logs and interactions.
Note
This module is currently reserved for future use in case bi-directional communication is needed between the terminal emulator React component and the Django backend.
Mostly GitHub Copilot vibecoded SSE log streaming views for dashboard clients.
This module provides a login-protected Django view,
stream_user_logs(), that streams server log output to the browser using
Server-Sent Events (SSE).
The view subscribes to a Redis Pub/Sub channel derived from the authenticated user context and forwards log records to connected clients in SSE format.
Behavior
Uses the
defaultRedis connection configured throughdjango-redis.- Verifies
smarter_settings.enable_dashboard_server_logsbefore opening a stream.
- Verifies
- Streams only the records at or above a minimum log level: the
level query parameter, for example
?level=DEBUG, or by defaultsmarter_settings.log_level. Smarter Chat’s Sandbox mode asks forDEBUG, and its Production mode for the default.
- Streams only the records at or above a minimum log level: the
- Emits a retry hint and keepalive comments to keep long-lived connections
healthy through intermediate proxies.
Closes the Redis Pub/Sub connection when the stream terminates.
SSE payload format
retry: 3000is sent once when a client first connects.Each log line is sent as
data: <line>followed by a blank line.: keepalivecomments are sent during idle periods.
See also
-mod:smarter.lib.logging.redis_log_handler
- smarter.apps.dashboard.views.terminal_emulator.api.streams.STREAM_TRANSPORT_LOGGERS = ('asyncio', 'redis', 'uvicorn', 'daphne')
Loggers of the libraries that carry the stream itself.
Their DEBUG records describe the stream’s own reads and writes, so forwarding them would echo each streamed record back into the stream.
('asyncio', 'redis', 'uvicorn', 'daphne')
- smarter.apps.dashboard.views.terminal_emulator.api.streams.stream_user_logs(request)[source]
Stream per-user server logs over Server-Sent Events (SSE).
This endpoint opens a Redis Pub/Sub subscription for the current user context and forwards incoming messages as SSE frames. When no message is available, keepalive comments are emitted so that long-lived connections remain active through reverse proxies.
Only the records at or above the
levelquery parameter, for example?level=DEBUG, are streamed. Without it, the level issmarter_settings.log_level. See_min_log_level().- Parameters:
request (
HttpRequest) – Incoming HTTP request. The view requires authentication viadjango.contrib.auth.decorators.login_required().- Returns:
A streaming SSE response when log streaming is available; otherwise a plain-text non-streaming response describing why streaming is disabled or unavailable.
- Return type:
- Status 200:
Streaming response created successfully.
- Status 503:
Redis is unavailable and a stream cannot be created.
- Responseheader Content-Type:
text/event-streamfor streaming responses.- Responseheader Cache-Control:
no-cachefor streaming responses.- Responseheader X-Accel-Buffering:
nofor streaming responses.- Note:
If
smarter_settings.enable_dashboard_server_logsis false, the function returns a plain-text response and does not connect to Redis.