1use std::{sync::Arc, time::Duration};
2
3#[derive(Clone, Debug)]
5pub struct SecurityConfig {
6 pub allowed_origins: Vec<String>,
8 pub max_body_size: usize,
10 pub request_timeout: Duration,
12 pub expose_error_details: bool,
14}
15
16impl Default for SecurityConfig {
17 fn default() -> Self {
18 Self {
19 allowed_origins: Vec::new(), max_body_size: 10 * 1024 * 1024, request_timeout: Duration::from_secs(30),
22 expose_error_details: false,
23 }
24 }
25}
26
27impl SecurityConfig {
28 pub fn development() -> Self {
30 Self {
31 allowed_origins: Vec::new(),
32 max_body_size: 10 * 1024 * 1024,
33 request_timeout: Duration::from_secs(60),
34 expose_error_details: true,
35 }
36 }
37
38 pub fn production(allowed_origins: Vec<String>) -> Self {
40 Self {
41 allowed_origins,
42 max_body_size: 10 * 1024 * 1024,
43 request_timeout: Duration::from_secs(30),
44 expose_error_details: false,
45 }
46 }
47}
48
49#[derive(Clone)]
51pub struct ServerConfig {
52 pub agent_loader: Arc<dyn adk_core::AgentLoader>,
53 pub session_service: Arc<dyn adk_session::SessionService>,
54 pub artifact_service: Option<Arc<dyn adk_artifact::ArtifactService>>,
55 pub backend_url: Option<String>,
56 pub security: SecurityConfig,
57}
58
59impl ServerConfig {
60 pub fn new(
61 agent_loader: Arc<dyn adk_core::AgentLoader>,
62 session_service: Arc<dyn adk_session::SessionService>,
63 ) -> Self {
64 Self {
65 agent_loader,
66 session_service,
67 artifact_service: None,
68 backend_url: None,
69 security: SecurityConfig::default(),
70 }
71 }
72
73 pub fn with_artifact_service(
74 mut self,
75 artifact_service: Arc<dyn adk_artifact::ArtifactService>,
76 ) -> Self {
77 self.artifact_service = Some(artifact_service);
78 self
79 }
80
81 pub fn with_artifact_service_opt(
82 mut self,
83 artifact_service: Option<Arc<dyn adk_artifact::ArtifactService>>,
84 ) -> Self {
85 self.artifact_service = artifact_service;
86 self
87 }
88
89 pub fn with_backend_url(mut self, backend_url: impl Into<String>) -> Self {
90 self.backend_url = Some(backend_url.into());
91 self
92 }
93
94 pub fn with_security(mut self, security: SecurityConfig) -> Self {
95 self.security = security;
96 self
97 }
98
99 pub fn with_allowed_origins(mut self, origins: Vec<String>) -> Self {
101 self.security.allowed_origins = origins;
102 self
103 }
104
105 pub fn with_max_body_size(mut self, size: usize) -> Self {
107 self.security.max_body_size = size;
108 self
109 }
110
111 pub fn with_request_timeout(mut self, timeout: Duration) -> Self {
113 self.security.request_timeout = timeout;
114 self
115 }
116
117 pub fn with_error_details(mut self, expose: bool) -> Self {
119 self.security.expose_error_details = expose;
120 self
121 }
122}