Class: A2A::AgentCard

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/agent_card.rb,
lib/a2a/agent_card/builder.rb,
lib/a2a/agent_card/verifier.rb,
lib/a2a/agent_card/signature.rb

Defined Under Namespace

Classes: Builder, Signature, Verifier

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, **kwargs) ⇒ AgentCard

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/a2a/agent_card.rb', line 15

def initialize(name:, description:, **kwargs)
  supported_interfaces = kwargs.fetch(:supported_interfaces)
  default_input_modes = kwargs.fetch(:default_input_modes)
  default_output_modes = kwargs.fetch(:default_output_modes)
  skills = kwargs.fetch(:skills)

  validate_required_collections!(supported_interfaces, default_input_modes, default_output_modes, skills)

  @name = name
  @description = description
  @supported_interfaces = supported_interfaces
  @version = kwargs.fetch(:version)
  @capabilities = kwargs.fetch(:capabilities)
  @default_input_modes = default_input_modes
  @default_output_modes = default_output_modes
  @skills = skills
  @provider = kwargs.fetch(:provider, nil)
  @documentation_url = kwargs.fetch(:documentation_url, nil)
  @security_schemes = kwargs.fetch(:security_schemes, nil)
  @security_requirements = kwargs.fetch(:security_requirements, nil)
  @signatures = kwargs.fetch(:signatures, nil)
  @icon_url = kwargs.fetch(:icon_url, nil)
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def capabilities
  @capabilities
end

#default_input_modesObject (readonly)

Returns the value of attribute default_input_modes.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def default_input_modes
  @default_input_modes
end

#default_output_modesObject (readonly)

Returns the value of attribute default_output_modes.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def default_output_modes
  @default_output_modes
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def description
  @description
end

#documentation_urlObject (readonly)

Returns the value of attribute documentation_url.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def documentation_url
  @documentation_url
end

#icon_urlObject (readonly)

Returns the value of attribute icon_url.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def icon_url
  @icon_url
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def name
  @name
end

#providerObject (readonly)

Returns the value of attribute provider.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def provider
  @provider
end

#security_requirementsObject (readonly)

Returns the value of attribute security_requirements.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def security_requirements
  @security_requirements
end

#security_schemesObject (readonly)

Returns the value of attribute security_schemes.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def security_schemes
  @security_schemes
end

#signaturesObject (readonly)

Returns the value of attribute signatures.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def signatures
  @signatures
end

#skillsObject (readonly)

Returns the value of attribute skills.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def skills
  @skills
end

#supported_interfacesObject (readonly)

Returns the value of attribute supported_interfaces.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def supported_interfaces
  @supported_interfaces
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/a2a/agent_card.rb', line 10

def version
  @version
end

Class Method Details

.from_h(hash) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/a2a/agent_card.rb', line 41

def self.from_h(hash)
  new(
    name: hash.fetch("name"),
    description: hash.fetch("description"),
    version: hash.fetch("version"),
    supported_interfaces: hash.fetch("supportedInterfaces").map { AgentInterface.from_h(it) },
    capabilities: AgentCapabilities.from_h(hash.fetch("capabilities")),
    skills: hash.fetch("skills").map { AgentSkill.from_h(it) },
    security_schemes: (hash["securitySchemes"] || {}).transform_values { SecurityScheme.from_h(it) },
    security_requirements: hash["security"],
    default_input_modes: hash.fetch("defaultInputModes"),
    default_output_modes: hash.fetch("defaultOutputModes"),
    provider: hash["provider"] && AgentProvider.from_h(hash["provider"]),
    documentation_url: hash["documentationUrl"],
    icon_url: hash["iconUrl"],
    signatures: hash["signatures"]&.map { Signature.from_h(it) }
  )
end

Instance Method Details

#canonical_jsonObject

§8.4.1 — RFC 8785 canonical JSON: to_h with “signatures” excluded and keys sorted recursively. Used as the payload for JWS signing/verification.



67
68
69
# File 'lib/a2a/agent_card.rb', line 67

def canonical_json
  JSON.generate(sort_keys_recursive(to_h.except("signatures")))
end

#preferred_interface(preference: [AgentInterface::JSONRPC, AgentInterface::HTTP_JSON]) ⇒ Object

§5.2 — returns the first interface whose protocolBinding the caller supports, preserving the agent’s declared preference order (index 0 = most preferred).



73
74
75
# File 'lib/a2a/agent_card.rb', line 73

def preferred_interface(preference: [AgentInterface::JSONRPC, AgentInterface::HTTP_JSON])
  supported_interfaces.find { |i| preference.include?(i.protocol_binding) }
end

#to_hObject

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



61
62
63
# File 'lib/a2a/agent_card.rb', line 61

def to_h
  required_fields.merge(optional_fields).compact
end