Class: LLM::A2A::Transport::HTTP
- Inherits:
-
Object
- Object
- LLM::A2A::Transport::HTTP
- Includes:
- Transport::Utils
- Defined in:
- lib/llm/a2a/transport/http.rb
Overview
The HTTP class provides the HTTP+JSON/REST protocol binding for the A2A protocol. It sends JSON payloads to A2A agent endpoints and handles both synchronous responses and Server-Sent Events for streaming operations.
This transport implements the HTTP+JSON/REST binding as defined in the A2A specification (Section 11).
Instance Method Summary collapse
-
#initialize(url:, headers: {}, timeout: nil, transport: nil, protocol_version: "1.0") ⇒ HTTP
constructor
A new instance of HTTP.
-
#get(path, accept: "application/json") ⇒ Hash
Sends a GET request.
-
#post(path, body, content_type: "application/json", accept: "application/json") ⇒ Hash
Sends a POST request.
-
#delete(path, accept: "application/json") ⇒ Hash
Sends a DELETE request.
-
#get_stream(path) {|event| ... } ⇒ void
Sends a GET request with a streaming (SSE) response.
-
#post_stream(path, body, content_type: "application/json") {|event| ... } ⇒ void
Sends a POST request with a streaming (SSE) response.
Constructor Details
#initialize(url:, headers: {}, timeout: nil, transport: nil, protocol_version: "1.0") ⇒ HTTP
Returns a new instance of HTTP.
22 23 24 25 26 27 |
# File 'lib/llm/a2a/transport/http.rb', line 22 def initialize(url:, headers: {}, timeout: nil, transport: nil, protocol_version: "1.0") @uri = URI.parse(url) @headers = headers @protocol_version = protocol_version @transport = resolve_transport(@uri, transport, timeout) end |
Instance Method Details
#get(path, accept: "application/json") ⇒ Hash
Sends a GET request.
33 34 35 36 37 |
# File 'lib/llm/a2a/transport/http.rb', line 33 def get(path, accept: "application/json") req = Net::HTTP::Get.new(request_path(path), headers(accept:)) res = transport.request(req, owner: self) parse_response(res) end |
#post(path, body, content_type: "application/json", accept: "application/json") ⇒ Hash
Sends a POST request.
44 45 46 47 48 49 |
# File 'lib/llm/a2a/transport/http.rb', line 44 def post(path, body, content_type: "application/json", accept: "application/json") req = Net::HTTP::Post.new(request_path(path), headers(content_type:, accept:)) req.body = LLM.json.dump(body) res = transport.request(req, owner: self) parse_response(res) end |
#delete(path, accept: "application/json") ⇒ Hash
Sends a DELETE request.
55 56 57 58 59 |
# File 'lib/llm/a2a/transport/http.rb', line 55 def delete(path, accept: "application/json") req = Net::HTTP::Delete.new(request_path(path), headers(accept:)) res = transport.request(req, owner: self) parse_response(res) end |
#get_stream(path) {|event| ... } ⇒ void
This method returns an undefined value.
Sends a GET request with a streaming (SSE) response.
The block is called for each event parsed from the event stream.
68 69 70 71 |
# File 'lib/llm/a2a/transport/http.rb', line 68 def get_stream(path, &on_event) req = Net::HTTP::Get.new(request_path(path), headers(accept: "text/event-stream")) stream(req, &on_event) end |
#post_stream(path, body, content_type: "application/json") {|event| ... } ⇒ void
This method returns an undefined value.
Sends a POST request with a streaming (SSE) response.
The block is called for each event parsed from the event stream.
81 82 83 84 85 |
# File 'lib/llm/a2a/transport/http.rb', line 81 def post_stream(path, body, content_type: "application/json", &on_event) req = Net::HTTP::Post.new(request_path(path), headers(content_type:, accept: "text/event-stream")) req.body = LLM.json.dump(body) stream(req, &on_event) end |