pub struct A2aClient { /* private fields */ }Expand description
HTTP client for the A2A protocol.
A2aClient wraps a reqwest::Client and provides typed methods for the four
A2A JSON-RPC operations: message/send, message/stream, tasks/get, and
tasks/cancel. Each call optionally accepts a bearer token for authentication.
§Security
Use with_security to harden the client for
production deployments:
require_tls = truerejects anyhttp://endpoint before connecting.ssrf_protection = trueresolves the endpoint’s hostname via DNS and rejects addresses in private/loopback ranges (10/8, 172.16/12, 192.168/16, 127/8, etc.).
§Examples
use zeph_a2a::{A2aClient, SendMessageParams, Message};
let client = A2aClient::new(reqwest::Client::new())
.with_security(true, true); // require HTTPS, block SSRF
let params = SendMessageParams {
message: Message::user_text("Summarize this page."),
configuration: None,
};
let task = client.send_message("https://agent.example.com/a2a", params, Some("tok")).await?;
println!("Task state: {:?}", task.status.state);Implementations§
Source§impl A2aClient
impl A2aClient
Sourcepub fn new(client: Client) -> Self
pub fn new(client: Client) -> Self
Create a new A2aClient with no security restrictions.
Security features are disabled by default for local/dev usage. Enable them
with with_security for production deployments.
Sourcepub fn with_security(self, require_tls: bool, ssrf_protection: bool) -> Self
pub fn with_security(self, require_tls: bool, ssrf_protection: bool) -> Self
Configure TLS enforcement and SSRF protection for this client.
Both flags default to false. This method uses the builder pattern and
can be chained directly after new.
require_tls: reject any endpoint that does not start withhttps://.ssrf_protection: resolve the endpoint hostname via DNS and reject private IP ranges.
§Examples
use zeph_a2a::A2aClient;
let client = A2aClient::new(reqwest::Client::new())
.with_security(true, true);Sourcepub async fn send_message(
&self,
endpoint: &str,
params: SendMessageParams,
token: Option<&str>,
) -> Result<Task, A2aError>
pub async fn send_message( &self, endpoint: &str, params: SendMessageParams, token: Option<&str>, ) -> Result<Task, A2aError>
§Errors
Returns A2aError on network, JSON, or JSON-RPC errors.
Sourcepub async fn stream_message(
&self,
endpoint: &str,
params: SendMessageParams,
token: Option<&str>,
) -> Result<TaskEventStream, A2aError>
pub async fn stream_message( &self, endpoint: &str, params: SendMessageParams, token: Option<&str>, ) -> Result<TaskEventStream, A2aError>
§Errors
Returns A2aError on network failure or if the SSE connection cannot be established.
Sourcepub async fn get_task(
&self,
endpoint: &str,
params: TaskIdParams,
token: Option<&str>,
) -> Result<Task, A2aError>
pub async fn get_task( &self, endpoint: &str, params: TaskIdParams, token: Option<&str>, ) -> Result<Task, A2aError>
§Errors
Returns A2aError on network, JSON, or JSON-RPC errors.
Sourcepub async fn cancel_task(
&self,
endpoint: &str,
params: TaskIdParams,
token: Option<&str>,
) -> Result<Task, A2aError>
pub async fn cancel_task( &self, endpoint: &str, params: TaskIdParams, token: Option<&str>, ) -> Result<Task, A2aError>
§Errors
Returns A2aError on network, JSON, or JSON-RPC errors.