yera.ui.fastapi_routes.streaming

Stream rendered session events and accept correlated user input.

Symbols

def register_streaming_routes — Register the SSE stream and HTMX input-submission routes.

register_streaming_routes

register_streaming_routes(
    app: FastAPI,
    resolve_session: ResolveSession,
    launch_runtime: LaunchRuntime,
    sse_stream: SSEStream,
    validate_request: ValidateRequest,
    session_store: BaseSessionStore,
) → None

Register the SSE stream and HTMX input-submission routes.

GET /sessions/{session_id}/stream resolves the runtime, launches it when appropriate, and returns an unbuffered event stream. The server callback decides whether the stream reads live fragments or replays persisted output.

POST /sessions/{session_id}/input canonicalizes the submitted JSON, constructs typed input data, and delegates correlation and schema validation to the server. Accepted input is persisted before it is pushed to the app. Secret form fields are redacted by the session runtime for the stored copy while the original event reaches the app.

Invalid serialization and typed payloads return a composer error with 422. Stale or mismatched requests are returned by validate_request without replacing the active composer. Successful submissions replace the composer with its idle state and reconnect the session listener.

Parameters

app
type: FastAPI

FastAPI application receiving the routes.

resolve_session
type: ResolveSession

Callback that resolves persisted identity to its in-process runtime.

launch_runtime
type: LaunchRuntime

Callback that starts an eligible runtime and reports whether this request launched it.

sse_stream
type: SSEStream

Callback that produces framed live or replay output.

validate_request
type: ValidateRequest

Callback that checks request correlation, input type, cancellation, and payload schema.

session_store
type: BaseSessionStore

Store that records accepted input and lifecycle state.