Logs Terminal Emulator Streams API
Server-side Event (SSE) Streams API for the Terminal Emulator React App.
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.app_dashboard_server_logs_enablebefore 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
- Streams only the records of one request, when the
request_idquery parameter is set: the records that the request’s
X-Smarter-RequestIdheader tagged. Seesmarter.lib.logging.middleware.SmarterRequestLogContextMiddleware. The Prompt Passthrough’s Server Logs tab streams the logs of each prompt that it sends this way.
- Streams only the records of one request, when the
- Streams only the records of one chat, when the
session_keyquery parameter is set: the records of the requests to an LLMClient’s api with that chat session key. The workbench’s Console streams the logs of its chat this way.
- Streams only the records of one chat, when 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().With the
request_idquery parameter, only the records of that request are streamed. See_request_id(). With thesession_keyquery parameter, only the records of that chat are streamed. See_session_key().The view’s own log entries identify the user by id, and mask the session key: the user context and the channel hold the username, and a session key lets anyone holding it continue the chat.
- 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.app_dashboard_server_logs_enableis false, the function returns a plain-text response and does not connect to Redis.