Class: A2A::SSE::JsonRpcStream
- Defined in:
- lib/a2a/sse/json_rpc_stream.rb
Overview
SSE stream that wraps each event in a JSON-RPC 2.0 response envelope.
Per the A2A spec, JSON-RPC streaming returns SSE where each ‘data:` line is a full JSON-RPC response: “jsonrpc”:“2.0”,“id”:N,“result”:{…}
Usage:
stream = A2A::SSE::JsonRpcStream.new(
task_id: "t1", context_id: "c1", json_rpc_id: 1
)
Async do
stream.task(status: { state: "TASK_STATE_WORKING", timestamp: "..." })
stream.finish
end
[200, A2A::SSE::Stream.headers, stream]
Constant Summary
Constants inherited from Stream
Instance Attribute Summary
Attributes inherited from Stream
Instance Method Summary collapse
-
#event(data, **opts) ⇒ Object
Emit an SSE event wrapped in a JSON-RPC envelope.
-
#initialize(json_rpc_id:, **options) ⇒ JsonRpcStream
constructor
A new instance of JsonRpcStream.
Methods inherited from Stream
Constructor Details
#initialize(json_rpc_id:, **options) ⇒ JsonRpcStream
Returns a new instance of JsonRpcStream.
26 27 28 29 |
# File 'lib/a2a/sse/json_rpc_stream.rb', line 26 def initialize(json_rpc_id:, **) @json_rpc_id = json_rpc_id super(**) end |
Instance Method Details
#event(data, **opts) ⇒ Object
Emit an SSE event wrapped in a JSON-RPC envelope.
35 36 37 38 39 40 41 42 |
# File 'lib/a2a/sse/json_rpc_stream.rb', line 35 def event(data, **opts) envelope = { "jsonrpc" => "2.0", "id" => @json_rpc_id, "result" => data.respond_to?(:to_h) ? data.to_h : data, } super(envelope, **opts) end |