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

  • Verifies smarter_settings.enable_dashboard_server_logs 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.

  • 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().

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.enable_dashboard_server_logs is false, the function returns a plain-text response and does not connect to Redis.