Class: A2A::AgentInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/agent_interface.rb

Constant Summary collapse

JSONRPC =
"JSONRPC"
GRPC =
"GRPC"
HTTP_JSON =
"HTTP+JSON"
VALID_BINDINGS =
[JSONRPC, GRPC, HTTP_JSON].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, protocol_binding:, protocol_version:, tenant: nil) ⇒ AgentInterface

Returns a new instance of AgentInterface.



13
14
15
16
17
18
19
20
21
22
# File 'lib/a2a/agent_interface.rb', line 13

def initialize(url:, protocol_binding:, protocol_version:, tenant: nil)
  unless VALID_BINDINGS.include?(protocol_binding)
    raise ArgumentError, "protocol_binding must be one of #{VALID_BINDINGS.join(', ')}"
  end

  @url = url
  @protocol_binding = protocol_binding
  @protocol_version = protocol_version
  @tenant = tenant
end

Instance Attribute Details

#protocol_bindingObject (readonly)

Returns the value of attribute protocol_binding.



5
6
7
# File 'lib/a2a/agent_interface.rb', line 5

def protocol_binding
  @protocol_binding
end

#protocol_versionObject (readonly)

Returns the value of attribute protocol_version.



5
6
7
# File 'lib/a2a/agent_interface.rb', line 5

def protocol_version
  @protocol_version
end

#tenantObject (readonly)

Returns the value of attribute tenant.



5
6
7
# File 'lib/a2a/agent_interface.rb', line 5

def tenant
  @tenant
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/a2a/agent_interface.rb', line 5

def url
  @url
end

Class Method Details

.from_h(hash) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/a2a/agent_interface.rb', line 24

def self.from_h(hash)
  new(
    url: hash.fetch("url"),
    protocol_binding: hash.fetch("protocolBinding"),
    protocol_version: hash.fetch("protocolVersion"),
    tenant: hash["tenant"]
  )
end

Instance Method Details

#grpc?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/a2a/agent_interface.rb', line 46

def grpc?
  protocol_binding == GRPC
end

#http_json?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/a2a/agent_interface.rb', line 50

def http_json?
  protocol_binding == HTTP_JSON
end

#json_rpc?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/a2a/agent_interface.rb', line 42

def json_rpc?
  protocol_binding == JSONRPC
end

#to_hObject



33
34
35
36
37
38
39
40
# File 'lib/a2a/agent_interface.rb', line 33

def to_h
  {
    "url" => url,
    "protocolBinding" => protocol_binding,
    "protocolVersion" => protocol_version,
    "tenant" => tenant
  }.compact
end