Class: A2A::Protocol::JsonRpc

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/protocol/json_rpc.rb,
lib/a2a/protocol/json_rpc/transport.rb

Defined Under Namespace

Classes: Transport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, version: Versioning::CURRENT, headers: {}, extensions: [], transport: Transport.new) ⇒ JsonRpc

Returns a new instance of JsonRpc.



11
12
13
14
15
16
17
18
# File 'lib/a2a/protocol/json_rpc.rb', line 11

def initialize(url:, version: Versioning::CURRENT, headers: {}, extensions: [], transport: Transport.new)
  @url = url
  @version = version
  @headers = headers
  @extensions = extensions
  @transport = transport
  @built_headers = build_headers
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



9
10
11
# File 'lib/a2a/protocol/json_rpc.rb', line 9

def extensions
  @extensions
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/a2a/protocol/json_rpc.rb', line 9

def headers
  @headers
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/a2a/protocol/json_rpc.rb', line 9

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/a2a/protocol/json_rpc.rb', line 9

def version
  @version
end

Instance Method Details

#post(method, params = {}) ⇒ Object



20
21
22
# File 'lib/a2a/protocol/json_rpc.rb', line 20

def post(method, params = {})
  @transport.post(@url, body: build_envelope(method, params), headers: @built_headers)
end

#stream(method, params = {}) ⇒ Object



24
25
26
27
# File 'lib/a2a/protocol/json_rpc.rb', line 24

def stream(method, params = {}, &)
  sse_headers = @built_headers.merge("Accept" => "text/event-stream")
  @transport.stream(@url, headers: sse_headers, method: :post, body: build_envelope(method, params), &)
end