Class: LLM::MCP::Transport::HTTP::EventHandler
- Inherits:
-
Object
- Object
- LLM::MCP::Transport::HTTP::EventHandler
- Defined in:
- lib/llm/mcp/transport/http/event_handler.rb
Overview
The LLM::MCP::Transport::HTTP::EventHandler class adapts generic server-sent event callbacks into decoded JSON-RPC messages for LLM::MCP::Transport::HTTP. It accumulates event data until a blank line terminates the current event, then parses the payload as JSON and yields it to the callback given at initialization.
Instance Method Summary collapse
- #initialize {|message| ... } ⇒ LLM::MCP::Transport::HTTP::EventHandler constructor
-
#on_chunk(event) ⇒ void
The generic event stream parser dispatches one line at a time.
-
#on_data(event) ⇒ void
Receives one line of SSE data.
-
#on_event(event) ⇒ void
Receives the SSE event name.
Constructor Details
#initialize {|message| ... } ⇒ LLM::MCP::Transport::HTTP::EventHandler
17 18 19 20 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 17 def initialize(&) @on_message = reset end |
Instance Method Details
#on_chunk(event) ⇒ void
This method returns an undefined value.
The generic event stream parser dispatches one line at a time. A blank line terminates the current SSE event.
45 46 47 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 45 def on_chunk(event) flush if event.chunk == "\n" end |
#on_data(event) ⇒ void
This method returns an undefined value.
Receives one line of SSE data.
36 37 38 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 36 def on_data(event) @data << event.value.to_s end |
#on_event(event) ⇒ void
This method returns an undefined value.
Receives the SSE event name.
27 28 29 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 27 def on_event(event) @event = event.value end |