Class: A2A::Client::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(streaming: true, polling: false, supported_transports: nil, use_client_preference: true, accepted_output_modes: nil, push_notification_configs: nil, timeout: 30, retry_attempts: 3, retry_delay: 1.0, max_retry_delay: 60.0, backoff_multiplier: 2.0, endpoint_url: nil, authentication: nil, headers: nil, user_agent: nil) ⇒ Config

Initialize a new client configuration

Parameters:

  • streaming (Boolean) (defaults to: true)

    Enable streaming responses (default: true)

  • polling (Boolean) (defaults to: false)

    Enable polling for task updates (default: false)

  • supported_transports (Array<String>) (defaults to: nil)

    Supported transport protocols

  • use_client_preference (Boolean) (defaults to: true)

    Use client transport preference (default: true)

  • accepted_output_modes (Array<String>) (defaults to: nil)

    Accepted output modes

  • push_notification_configs (Array<Hash>) (defaults to: nil)

    Push notification configurations

  • timeout (Integer) (defaults to: 30)

    Request timeout in seconds (default: 30)

  • retry_attempts (Integer) (defaults to: 3)

    Number of retry attempts (default: 3)

  • retry_delay (Float) (defaults to: 1.0)

    Initial retry delay in seconds (default: 1.0)

  • max_retry_delay (Float) (defaults to: 60.0)

    Maximum retry delay in seconds (default: 60.0)

  • backoff_multiplier (Float) (defaults to: 2.0)

    Backoff multiplier for retries (default: 2.0)

  • endpoint_url (String) (defaults to: nil)

    Base endpoint URL

  • authentication (Hash) (defaults to: nil)

    Authentication configuration

  • headers (Hash) (defaults to: nil)

    Additional HTTP headers

  • user_agent (String) (defaults to: nil)

    User agent string



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/a2a/client/config.rb', line 37

def initialize(streaming: true, polling: false, supported_transports: nil,
               use_client_preference: true, accepted_output_modes: nil,
               push_notification_configs: nil, timeout: 30, retry_attempts: 3,
               retry_delay: 1.0, max_retry_delay: 60.0, backoff_multiplier: 2.0,
               endpoint_url: nil, authentication: nil, headers: nil, user_agent: nil)
  @streaming = streaming
  @polling = polling
  @supported_transports = supported_transports || [A2A::Types::TRANSPORT_JSONRPC]
  @use_client_preference = use_client_preference
  @accepted_output_modes = accepted_output_modes || %w[text file data]
  @push_notification_configs = push_notification_configs || []
  @timeout = timeout
  @retry_attempts = retry_attempts
  @retry_delay = retry_delay
  @max_retry_delay = max_retry_delay
  @backoff_multiplier = backoff_multiplier
  @endpoint_url = endpoint_url
  @authentication = authentication || {}
  @headers = headers || {}
  @user_agent = user_agent || "a2a-ruby/#{A2A::VERSION}"

  validate!
end

Instance Attribute Details

#accepted_output_modesObject

Returns the value of attribute accepted_output_modes.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def accepted_output_modes
  @accepted_output_modes
end

#authenticationObject

Returns the value of attribute authentication.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def authentication
  @authentication
end

#backoff_multiplierObject

Returns the value of attribute backoff_multiplier.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def backoff_multiplier
  @backoff_multiplier
end

#endpoint_urlObject

Returns the value of attribute endpoint_url.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def endpoint_url
  @endpoint_url
end

#headersObject

Returns the value of attribute headers.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def headers
  @headers
end

#max_retry_delayObject

Returns the value of attribute max_retry_delay.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def max_retry_delay
  @max_retry_delay
end

#pollingObject

Returns the value of attribute polling.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def polling
  @polling
end

#push_notification_configsObject

Returns the value of attribute push_notification_configs.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def push_notification_configs
  @push_notification_configs
end

#retry_attemptsObject

Returns the value of attribute retry_attempts.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def retry_attempts
  @retry_attempts
end

#retry_delayObject

Returns the value of attribute retry_delay.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def retry_delay
  @retry_delay
end

#streamingObject

Returns the value of attribute streaming.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def streaming
  @streaming
end

#supported_transportsObject

Returns the value of attribute supported_transports.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def supported_transports
  @supported_transports
end

#timeoutObject

Returns the value of attribute timeout.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def timeout
  @timeout
end

#use_client_preferenceObject

Returns the value of attribute use_client_preference.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def use_client_preference
  @use_client_preference
end

#user_agentObject

Returns the value of attribute user_agent.



14
15
16
# File 'lib/a2a/client/config.rb', line 14

def user_agent
  @user_agent
end

Instance Method Details

#add_transport(transport) ⇒ Object

Add a supported transport

Parameters:

  • transport (String)

    The transport to add



106
107
108
# File 'lib/a2a/client/config.rb', line 106

def add_transport(transport)
  @supported_transports << transport unless @supported_transports.include?(transport)
end

#all_headersHash

Get all HTTP headers including authentication headers

Returns:

  • (Hash)

    All HTTP headers



140
141
142
143
# File 'lib/a2a/client/config.rb', line 140

def all_headers
  auth_headers = build_auth_headers
  @headers.merge(auth_headers)
end

#auth_config(type) ⇒ Hash?

Get authentication configuration for a specific type

Parameters:

  • type (String)

    The authentication type

Returns:

  • (Hash, nil)

    The authentication configuration



123
124
125
# File 'lib/a2a/client/config.rb', line 123

def auth_config(type)
  @authentication[type]
end

#build_auth_headersObject (private)



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/a2a/client/config.rb', line 183

def build_auth_headers
  headers = {}

  # Add API key authentication
  if (api_key_config = @authentication["api_key"])
    case api_key_config["in"]
    when "header"
      headers[api_key_config["name"]] = api_key_config["value"]
    end
  end

  # Add bearer token authentication
  if (bearer_config = @authentication["bearer"])
    headers["Authorization"] = "Bearer #{bearer_config['token']}"
  end

  # Add basic authentication
  if (basic_config = @authentication["basic"])
    require "base64"
    credentials = Base64.strict_encode64("#{basic_config['username']}:#{basic_config['password']}")
    headers["Authorization"] = "Basic #{credentials}"
  end

  headers
end

#dupConfig

Create a copy of the configuration

Returns:

  • (Config)

    A new configuration instance



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/a2a/client/config.rb', line 149

def dup
  self.class.new(
    streaming: @streaming,
    polling: @polling,
    supported_transports: @supported_transports.dup,
    use_client_preference: @use_client_preference,
    accepted_output_modes: @accepted_output_modes.dup,
    push_notification_configs: @push_notification_configs.dup,
    timeout: @timeout,
    retry_attempts: @retry_attempts,
    retry_delay: @retry_delay,
    max_retry_delay: @max_retry_delay,
    backoff_multiplier: @backoff_multiplier,
    endpoint_url: @endpoint_url,
    authentication: @authentication.dup,
    headers: @headers.dup,
    user_agent: @user_agent
  )
end

#polling?Boolean

Check if polling is enabled

Returns:

  • (Boolean)

    True if polling is enabled



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

def polling?
  @polling
end

#preferred_transportString

Get the preferred transport protocol

Returns:

  • (String)

    The preferred transport protocol



89
90
91
# File 'lib/a2a/client/config.rb', line 89

def preferred_transport
  @supported_transports.first
end

#remove_transport(transport) ⇒ Object

Remove a supported transport

Parameters:

  • transport (String)

    The transport to remove



114
115
116
# File 'lib/a2a/client/config.rb', line 114

def remove_transport(transport)
  @supported_transports.delete(transport)
end

#set_auth_config(type, config) ⇒ Object

Set authentication configuration

Parameters:

  • type (String)

    The authentication type

  • config (Hash)

    The authentication configuration



132
133
134
# File 'lib/a2a/client/config.rb', line 132

def set_auth_config(type, config)
  @authentication[type] = config
end

#streaming?Boolean

Check if streaming is enabled

Returns:

  • (Boolean)

    True if streaming is enabled



65
66
67
# File 'lib/a2a/client/config.rb', line 65

def streaming?
  @streaming
end

#supports_transport?(transport) ⇒ Boolean

Check if a transport is supported

Parameters:

  • transport (String)

    The transport to check

Returns:

  • (Boolean)

    True if the transport is supported



98
99
100
# File 'lib/a2a/client/config.rb', line 98

def supports_transport?(transport)
  @supported_transports.include?(transport)
end

#use_client_preference?Boolean

Check if client preference should be used for transport negotiation

Returns:

  • (Boolean)

    True if client preference should be used



81
82
83
# File 'lib/a2a/client/config.rb', line 81

def use_client_preference?
  @use_client_preference
end

#validate!Object (private)

Raises:

  • (ArgumentError)


171
172
173
174
175
176
177
178
179
180
181
# File 'lib/a2a/client/config.rb', line 171

def validate!
  raise ArgumentError, "timeout must be positive" if @timeout <= 0
  raise ArgumentError, "retry_attempts must be non-negative" if @retry_attempts.negative?
  raise ArgumentError, "retry_delay must be positive" if @retry_delay <= 0
  raise ArgumentError, "max_retry_delay must be positive" if @max_retry_delay <= 0
  raise ArgumentError, "backoff_multiplier must be positive" if @backoff_multiplier <= 0

  @supported_transports.each do |transport|
    raise ArgumentError, "unsupported transport: #{transport}" unless A2A::Types::VALID_TRANSPORTS.include?(transport)
  end
end