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 default Redis connection configured through django-redis.

  • Verifies smarter_settings.app_dashboard_server_logs_enable before opening a

    stream.

  • Streams only the records at or above a minimum log level: the level

    query parameter, for example ?level=DEBUG, or by default smarter_settings.log_level. Smarter Chat’s Sandbox mode asks for DEBUG, and its Production mode for the default.

  • Streams only the records of one request, when the request_id query

    parameter is set: the records that the request’s X-Smarter-RequestId header tagged. See smarter.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 chat, when the session_key query

    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.

  • 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: 3000 is sent once when a client first connects.

  • Each log line is sent as data: <line> followed by a blank line.

  • : keepalive comments 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 level query parameter, for example ?level=DEBUG, are streamed. Without it, the level is smarter_settings.log_level. See _min_log_level().

With the request_id query parameter, only the records of that request are streamed. See _request_id(). With the session_key query 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 via django.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:

StreamingHttpResponse | HttpResponse

Status 200:

Streaming response created successfully.

Status 503:

Redis is unavailable and a stream cannot be created.

Responseheader Content-Type:

text/event-stream for streaming responses.

Responseheader Cache-Control:

no-cache for streaming responses.

Responseheader X-Accel-Buffering:

no for streaming responses.

Note:

If smarter_settings.app_dashboard_server_logs_enable is false, the function returns a plain-text response and does not connect to Redis.