Skip to main content

a2a_protocol_client/config/
setters.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3
4//! The `with_*` setters of [`ClientConfig`], one per field. Kept apart from the
5//! struct so the file that documents the fields stays under the 500-line limit.
6
7use std::time::Duration;
8
9use super::{ClientConfig, TlsConfig};
10
11impl ClientConfig {
12    /// Sets [`preferred_bindings`](Self::preferred_bindings), which nothing
13    /// reads; see the field.
14    #[must_use]
15    #[deprecated(
16        since = "0.15.0",
17        note = "nothing reads `preferred_bindings`: `from_card` follows the card's interface \
18                order (spec ยง8.3.2); pass a ranking to `ClientBuilder::from_card_preferring`"
19    )]
20    #[allow(deprecated)]
21    pub fn with_preferred_bindings(mut self, bindings: Vec<String>) -> Self {
22        self.preferred_bindings = bindings;
23        self
24    }
25
26    /// Sets the MIME types advertised in `acceptedOutputModes`.
27    #[must_use]
28    pub fn with_accepted_output_modes(mut self, modes: Vec<String>) -> Self {
29        self.accepted_output_modes = modes;
30        self
31    }
32
33    /// Sets the history length requested; `None` uses the agent's default.
34    #[must_use]
35    pub const fn with_history_length(mut self, length: Option<u32>) -> Self {
36        self.history_length = length;
37        self
38    }
39
40    /// Sets whether `send_message` returns as soon as the task is submitted.
41    #[must_use]
42    pub const fn with_return_immediately(mut self, val: bool) -> Self {
43        self.return_immediately = val;
44        self
45    }
46
47    /// Sets [`blocking_over_stream`](Self::blocking_over_stream).
48    #[must_use]
49    pub const fn with_blocking_over_stream(mut self, val: bool) -> Self {
50        self.blocking_over_stream = val;
51        self
52    }
53
54    /// Sets the per-request timeout for non-streaming calls.
55    #[must_use]
56    pub const fn with_request_timeout(mut self, timeout: Duration) -> Self {
57        self.request_timeout = timeout;
58        self
59    }
60
61    /// Sets [`send_timeout`](Self::send_timeout).
62    #[must_use]
63    pub const fn with_send_timeout(mut self, timeout: Duration) -> Self {
64        self.send_timeout = timeout;
65        self
66    }
67
68    /// Sets the timeout for establishing a stream (headers, or an error
69    /// body). See [`stream_connect_timeout`](Self::stream_connect_timeout).
70    #[must_use]
71    pub const fn with_stream_connect_timeout(mut self, timeout: Duration) -> Self {
72        self.stream_connect_timeout = timeout;
73        self
74    }
75
76    /// Sets how long an established stream may wait for its first data. See
77    /// [`stream_first_event_timeout`](Self::stream_first_event_timeout).
78    #[must_use]
79    pub const fn with_stream_first_event_timeout(mut self, timeout: Duration) -> Self {
80        self.stream_first_event_timeout = timeout;
81        self
82    }
83
84    /// Sets the TCP connection timeout (DNS + handshake).
85    #[must_use]
86    pub const fn with_connection_timeout(mut self, timeout: Duration) -> Self {
87        self.connection_timeout = timeout;
88        self
89    }
90
91    /// Sets how long an established stream may receive nothing before it is
92    /// failed with a timeout; `None` disables the bound. See
93    /// [`stream_idle_timeout`](Self::stream_idle_timeout).
94    #[must_use]
95    pub const fn with_stream_idle_timeout(mut self, timeout: Option<Duration>) -> Self {
96        self.stream_idle_timeout = timeout;
97        self
98    }
99
100    /// Sets the buffered response body cap. See
101    /// [`max_response_size`](Self::max_response_size) for which transports
102    /// it reaches.
103    #[must_use]
104    pub const fn with_max_response_size(mut self, max_bytes: usize) -> Self {
105        self.max_response_size = max_bytes;
106        self
107    }
108
109    /// Sets the largest single stream event accepted. See
110    /// [`max_event_size`](Self::max_event_size).
111    #[must_use]
112    pub const fn with_max_event_size(mut self, max_bytes: usize) -> Self {
113        self.max_event_size = max_bytes;
114        self
115    }
116
117    /// Sets the TLS configuration.
118    // Const only without `tls-rustls`: with it `TlsConfig` holds an `Arc`,
119    // whose destructor a const fn cannot run.
120    #[cfg_attr(not(feature = "tls-rustls"), allow(clippy::missing_const_for_fn))]
121    #[must_use]
122    pub fn with_tls(mut self, tls: TlsConfig) -> Self {
123        self.tls = tls;
124        self
125    }
126
127    /// Sets the default tenant; `None` sends none unless a request names one.
128    #[must_use]
129    pub fn with_tenant(mut self, tenant: Option<String>) -> Self {
130        self.tenant = tenant;
131        self
132    }
133}