Class: A2A::Client::Config
- Inherits:
-
Object
- Object
- A2A::Client::Config
- Defined in:
- lib/a2a/client/config.rb
Instance Attribute Summary collapse
-
#accepted_output_modes ⇒ Object
Returns the value of attribute accepted_output_modes.
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#backoff_multiplier ⇒ Object
Returns the value of attribute backoff_multiplier.
-
#endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#max_retry_delay ⇒ Object
Returns the value of attribute max_retry_delay.
-
#polling ⇒ Object
Returns the value of attribute polling.
-
#push_notification_configs ⇒ Object
Returns the value of attribute push_notification_configs.
-
#retry_attempts ⇒ Object
Returns the value of attribute retry_attempts.
-
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
-
#streaming ⇒ Object
Returns the value of attribute streaming.
-
#supported_transports ⇒ Object
Returns the value of attribute supported_transports.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#use_client_preference ⇒ Object
Returns the value of attribute use_client_preference.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#add_transport(transport) ⇒ Object
Add a supported transport.
-
#all_headers ⇒ Hash
Get all HTTP headers including authentication headers.
-
#auth_config(type) ⇒ Hash?
Get authentication configuration for a specific type.
- #build_auth_headers ⇒ Object private
-
#dup ⇒ Config
Create a copy of the configuration.
-
#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
constructor
Initialize a new client configuration.
-
#polling? ⇒ Boolean
Check if polling is enabled.
-
#preferred_transport ⇒ String
Get the preferred transport protocol.
-
#remove_transport(transport) ⇒ Object
Remove a supported transport.
-
#set_auth_config(type, config) ⇒ Object
Set authentication configuration.
-
#streaming? ⇒ Boolean
Check if streaming is enabled.
-
#supports_transport?(transport) ⇒ Boolean
Check if a transport is supported.
-
#use_client_preference? ⇒ Boolean
Check if client preference should be used for transport negotiation.
- #validate! ⇒ Object private
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
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_modes ⇒ Object
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 |
#authentication ⇒ Object
Returns the value of attribute authentication.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def authentication @authentication end |
#backoff_multiplier ⇒ Object
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_url ⇒ Object
Returns the value of attribute endpoint_url.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def endpoint_url @endpoint_url end |
#headers ⇒ Object
Returns the value of attribute headers.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def headers @headers end |
#max_retry_delay ⇒ Object
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 |
#polling ⇒ Object
Returns the value of attribute polling.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def polling @polling end |
#push_notification_configs ⇒ Object
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_attempts ⇒ Object
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_delay ⇒ Object
Returns the value of attribute retry_delay.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def retry_delay @retry_delay end |
#streaming ⇒ Object
Returns the value of attribute streaming.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def streaming @streaming end |
#supported_transports ⇒ Object
Returns the value of attribute supported_transports.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def supported_transports @supported_transports end |
#timeout ⇒ Object
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/a2a/client/config.rb', line 14 def timeout @timeout end |
#use_client_preference ⇒ Object
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_agent ⇒ Object
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
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_headers ⇒ Hash
Get all HTTP headers including authentication 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
123 124 125 |
# File 'lib/a2a/client/config.rb', line 123 def auth_config(type) @authentication[type] end |
#build_auth_headers ⇒ Object (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 |
#dup ⇒ Config
Create a copy of the configuration
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
73 74 75 |
# File 'lib/a2a/client/config.rb', line 73 def polling? @polling end |
#preferred_transport ⇒ String
Get 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
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
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
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
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
81 82 83 |
# File 'lib/a2a/client/config.rb', line 81 def use_client_preference? @use_client_preference end |
#validate! ⇒ Object (private)
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 |