Class: A2A::Client
- Inherits:
-
Object
- Object
- A2A::Client
- Defined in:
- lib/a2a/client.rb
Constant Summary collapse
- SUPPORTED_BINDINGS =
[AgentInterface::JSONRPC, AgentInterface::HTTP_JSON].freeze
Class Method Summary collapse
-
.from_agent_card(card, headers: {}, extensions: [], preference: SUPPORTED_BINDINGS) ⇒ Object
§5.2, §8.3.2 — constructs a Client from an AgentCard by negotiating the protocol binding.
Instance Method Summary collapse
- #cancel_task(id, metadata: nil, tenant: nil) ⇒ Object
- #create_task_push_notification_config(config, tenant: nil) ⇒ Object
- #delete_task_push_notification_config(task_id:, id:, tenant: nil) ⇒ Object
- #get_extended_agent_card(tenant: nil) ⇒ Object
- #get_task(id, history_length: nil, tenant: nil) ⇒ Object
- #get_task_push_notification_config(task_id:, id:, tenant: nil) ⇒ Object
-
#initialize(protocol:, capabilities: nil) ⇒ Client
constructor
A new instance of Client.
- #list_task_push_notification_configs(task_id:, page_size: nil, page_token: nil, tenant: nil) ⇒ Object
- #list_tasks ⇒ Object
- #send_message(message, configuration: {}, metadata: nil, tenant: nil) ⇒ Object
- #send_streaming_message(message, configuration: {}, metadata: nil, tenant: nil) ⇒ Object
- #subscribe_to_task(id, tenant: nil) ⇒ Object
Constructor Details
#initialize(protocol:, capabilities: nil) ⇒ Client
Returns a new instance of Client.
31 32 33 34 |
# File 'lib/a2a/client.rb', line 31 def initialize(protocol:, capabilities: nil) @protocol = protocol @capabilities = capabilities end |
Class Method Details
.from_agent_card(card, headers: {}, extensions: [], preference: SUPPORTED_BINDINGS) ⇒ Object
§5.2, §8.3.2 — constructs a Client from an AgentCard by negotiating the protocol binding. The agent’s supportedInterfaces order is respected: the first interface whose protocolBinding appears in ‘preference` wins.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/a2a/client.rb', line 10 def self.from_agent_card(card, headers: {}, extensions: [], preference: SUPPORTED_BINDINGS) iface = card.preferred_interface(preference: preference) unless iface found = card.supported_interfaces.map(&:protocol_binding).join(", ") raise UnsupportedOperationError, "no supported interface in agent card (available: #{found})" end Versioning.validate!(iface.protocol_version) protocol = build_protocol(iface, headers: headers, extensions: extensions) new(protocol: protocol, capabilities: card.capabilities) end |
Instance Method Details
#cancel_task(id, metadata: nil, tenant: nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/a2a/client.rb', line 54 def cancel_task(id, metadata: nil, tenant: nil) if id.is_a?(Task) && id.terminal? raise TaskNotCancelableError, "task #{id.id} is already in a terminal state (#{id.status.state})" end task_id = id.is_a?(Task) ? id.id : id run Operation::CancelTask.new(id: task_id, metadata:, tenant:) end |
#create_task_push_notification_config(config, tenant: nil) ⇒ Object
67 68 69 70 |
# File 'lib/a2a/client.rb', line 67 def create_task_push_notification_config(config, tenant: nil) require_push_notifications! run Operation::CreateTaskPushNotificationConfig.new(config, tenant:) end |
#delete_task_push_notification_config(task_id:, id:, tenant: nil) ⇒ Object
82 83 84 85 |
# File 'lib/a2a/client.rb', line 82 def delete_task_push_notification_config(task_id:, id:, tenant: nil) require_push_notifications! run Operation::DeleteTaskPushNotificationConfig.new(task_id:, id:, tenant:) end |
#get_extended_agent_card(tenant: nil) ⇒ Object
87 88 89 90 |
# File 'lib/a2a/client.rb', line 87 def get_extended_agent_card(tenant: nil) require_extended_agent_card! run Operation::GetExtendedAgentCard.new(tenant:) end |
#get_task(id, history_length: nil, tenant: nil) ⇒ Object
46 47 48 |
# File 'lib/a2a/client.rb', line 46 def get_task(id, history_length: nil, tenant: nil) run Operation::GetTask.new(id:, history_length:, tenant:) end |
#get_task_push_notification_config(task_id:, id:, tenant: nil) ⇒ Object
72 73 74 75 |
# File 'lib/a2a/client.rb', line 72 def get_task_push_notification_config(task_id:, id:, tenant: nil) require_push_notifications! run Operation::GetTaskPushNotificationConfig.new(task_id:, id:, tenant:) end |
#list_task_push_notification_configs(task_id:, page_size: nil, page_token: nil, tenant: nil) ⇒ Object
77 78 79 80 |
# File 'lib/a2a/client.rb', line 77 def list_task_push_notification_configs(task_id:, page_size: nil, page_token: nil, tenant: nil) require_push_notifications! run Operation::ListTaskPushNotificationConfigs.new(task_id:, page_size:, page_token:, tenant:) end |
#list_tasks ⇒ Object
50 51 52 |
# File 'lib/a2a/client.rb', line 50 def list_tasks(**) run Operation::ListTasks.new(**) end |
#send_message(message, configuration: {}, metadata: nil, tenant: nil) ⇒ Object
36 37 38 |
# File 'lib/a2a/client.rb', line 36 def (, configuration: {}, metadata: nil, tenant: nil) run Operation::SendMessage.new(, configuration: configuration, metadata: , tenant: tenant) end |
#send_streaming_message(message, configuration: {}, metadata: nil, tenant: nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/a2a/client.rb', line 40 def (, configuration: {}, metadata: nil, tenant: nil, &) op = Operation::SendStreamingMessage.new(, configuration: configuration, metadata: , tenant: tenant) run(op, &) end |
#subscribe_to_task(id, tenant: nil) ⇒ Object
63 64 65 |
# File 'lib/a2a/client.rb', line 63 def subscribe_to_task(id, tenant: nil, &) run(Operation::SubscribeToTask.new(id:, tenant:), &) end |