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, chunk = nil) ⇒ void
The generic event stream parser dispatches one line at a time.
-
#on_data(event, chunk = nil) ⇒ void
Receives one line of SSE data.
-
#on_event(event, chunk = nil) ⇒ 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, chunk = nil) ⇒ 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.
47 48 49 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 47 def on_chunk(event, chunk = nil) flush if (chunk || event&.chunk || event) == "\n" end |
#on_data(event, chunk = nil) ⇒ void
This method returns an undefined value.
Receives one line of SSE data.
38 39 40 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 38 def on_data(event, chunk = nil) @data << (chunk ? event : event.value).to_s end |
#on_event(event, chunk = nil) ⇒ void
This method returns an undefined value.
Receives the SSE event name.
28 29 30 |
# File 'lib/llm/mcp/transport/http/event_handler.rb', line 28 def on_event(event, chunk = nil) @event = chunk ? event : event.value end |