Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1Panel dev MaxKB SSE Streaming

From Leeroopedia
Knowledge Sources
Domains SSE, API
Last Updated 2026-10-10 00:00 GMT

Overview

A communication pattern that delivers server-generated events to clients incrementally over a persistent HTTP connection using the Server-Sent Events (SSE) protocol.

Description

SSE streaming is MaxKB's primary response delivery mechanism for chat. Instead of waiting for the full LLM response, the server sends incremental chunks as `data: <json>\n\n` frames. Each chunk contains content text, metadata (node_id, view_type, reasoning_content, node_status), and usage tokens. The BaseToResponse abstract class defines the contract, with SystemToResponse implementing MaxKB's native protocol. The NodeChunkManage class manages a queue of node chunks, popping them one at a time to produce the SSE stream. This enables real-time token-by-token streaming from the LLM to the user.

Usage

Use this principle when designing:

  • Real-time chat streaming responses
  • LLM token-by-token output delivery
  • Progress reporting for long-running workflow nodes

Theoretical Basis

The SSE protocol uses HTTP with `Content-Type: text/event-stream` and frames delimited by `\n\n`:

# Abstract algorithm description (NOT real implementation)
def stream_response(llm_stream):
    for chunk in llm_stream:
        frame = json.dumps({
            "content": chunk.text,
            "is_end": False,
            "reasoning_content": chunk.reasoning,
        })
        yield f"data: {frame}\n\n"
    # Final end chunk
    yield f"data: {json.dumps({'is_end': True, 'usage': {...}})}\n\n"

MaxKB adds an `operate: True` flag to distinguish content chunks from control messages, and a `node_is_end` flag to signal when a specific node has finished (before the overall stream ends).

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment