Skip to main content

vtcode_llm/providers/gemini/wire/client/
config.rs

1use std::time::Duration;
2
3/// Configuration for HTTP client optimization
4#[derive(Clone)]
5pub struct ClientConfig {
6    /// Maximum number of idle connections per host
7    pub pool_max_idle_per_host: usize,
8    /// How long to keep idle connections alive
9    pub(crate) pool_idle_timeout: Duration,
10    /// TCP keepalive duration
11    pub(crate) tcp_keepalive: Duration,
12    /// Request timeout
13    pub(crate) request_timeout: Duration,
14    /// Connection timeout
15    pub(crate) connect_timeout: Duration,
16    /// User agent string
17    pub user_agent: String,
18}
19
20const USER_AGENT_DEFAULT: &str = "vtcode/1.0.0";
21const USER_AGENT_HIGH_THROUGHPUT: &str = "vtcode/1.0.0-high-throughput";
22const USER_AGENT_LOW_MEMORY: &str = "vtcode/1.0.0-low-memory";
23const USER_AGENT_ULTRA_LOW_MEMORY: &str = "vtcode/1.0.0-ultra-low-memory";
24const USER_AGENT_LOW_LATENCY: &str = "vtcode/1.0.0-low-latency";
25
26impl Default for ClientConfig {
27    fn default() -> Self {
28        Self {
29            pool_max_idle_per_host: 10,
30            pool_idle_timeout: Duration::from_secs(90),
31            tcp_keepalive: Duration::from_secs(60),
32            request_timeout: Duration::from_secs(60),
33            connect_timeout: Duration::from_secs(10),
34            user_agent: USER_AGENT_DEFAULT.into(),
35        }
36    }
37}
38
39impl ClientConfig {
40    /// Configuration optimized for high-throughput scenarios
41    pub fn high_throughput() -> Self {
42        Self {
43            pool_max_idle_per_host: 20,
44            pool_idle_timeout: Duration::from_secs(120),
45            tcp_keepalive: Duration::from_secs(60),
46            request_timeout: Duration::from_secs(120),
47            connect_timeout: Duration::from_secs(15),
48            user_agent: USER_AGENT_HIGH_THROUGHPUT.into(),
49        }
50    }
51
52    /// Configuration optimized for low memory usage (< 100MB target)
53    pub fn low_memory() -> Self {
54        Self {
55            pool_max_idle_per_host: 3,
56            pool_idle_timeout: Duration::from_secs(30),
57            tcp_keepalive: Duration::from_secs(30),
58            request_timeout: Duration::from_secs(60),
59            connect_timeout: Duration::from_secs(5),
60            user_agent: USER_AGENT_LOW_MEMORY.into(),
61        }
62    }
63
64    /// Configuration optimized for ultra-low memory (< 50MB target)
65    pub fn ultra_low_memory() -> Self {
66        Self {
67            pool_max_idle_per_host: 1,
68            pool_idle_timeout: Duration::from_secs(10),
69            tcp_keepalive: Duration::from_secs(15),
70            request_timeout: Duration::from_secs(30),
71            connect_timeout: Duration::from_secs(3),
72            user_agent: USER_AGENT_ULTRA_LOW_MEMORY.into(),
73        }
74    }
75
76    /// Configuration optimized for low-latency scenarios
77    pub fn low_latency() -> Self {
78        Self {
79            pool_max_idle_per_host: 5,
80            pool_idle_timeout: Duration::from_secs(30),
81            tcp_keepalive: Duration::from_secs(30),
82            request_timeout: Duration::from_secs(30),
83            connect_timeout: Duration::from_secs(5),
84            user_agent: USER_AGENT_LOW_LATENCY.into(),
85        }
86    }
87}