conductor/client/
conductor_client.rs1use crate::configuration::Configuration;
5use crate::error::Result;
6use crate::events::EventDispatcher;
7use crate::http::ApiClient;
8
9#[cfg(feature = "agents")]
10use super::AgentClient;
11use super::{
12 AuthorizationClient, EventClient, IntegrationClient, MetadataClient, OrkesMetadataClient,
13 PromptClient, SchedulerClient, SchemaClient, SecretClient, TaskClient, WorkflowClient,
14};
15
16#[derive(Clone)]
21pub struct ConductorClient {
22 api: ApiClient,
23 events: EventDispatcher,
28}
29
30impl ConductorClient {
31 pub fn new(config: Configuration) -> Result<Self> {
38 let api = ApiClient::new(config)?;
39 Ok(Self {
40 api,
41 events: EventDispatcher::default(),
42 })
43 }
44
45 #[must_use]
47 pub fn from_api_client(api: ApiClient) -> Self {
48 Self {
49 api,
50 events: EventDispatcher::default(),
51 }
52 }
53
54 #[must_use]
62 pub fn with_event_dispatcher(mut self, events: EventDispatcher) -> Self {
63 self.events = events;
64 self
65 }
66
67 #[must_use]
69 pub fn event_dispatcher(&self) -> &EventDispatcher {
70 &self.events
71 }
72
73 #[must_use]
75 pub fn task_client(&self) -> TaskClient {
76 TaskClient::new(self.api.clone())
77 }
78
79 #[must_use]
81 pub fn get_task_client(&self) -> TaskClient {
82 self.task_client()
83 }
84
85 #[must_use]
87 pub fn workflow_client(&self) -> WorkflowClient {
88 WorkflowClient::new_with_events(self.api.clone(), self.events.clone())
89 }
90
91 #[must_use]
93 pub fn get_workflow_client(&self) -> WorkflowClient {
94 self.workflow_client()
95 }
96
97 #[must_use]
99 pub fn metadata_client(&self) -> MetadataClient {
100 MetadataClient::new(self.api.clone())
101 }
102
103 #[must_use]
105 pub fn get_metadata_client(&self) -> MetadataClient {
106 self.metadata_client()
107 }
108
109 #[must_use]
114 pub fn orkes_metadata_client(&self) -> OrkesMetadataClient {
115 OrkesMetadataClient::new(self.api.clone())
116 }
117
118 #[must_use]
120 pub fn get_orkes_metadata_client(&self) -> OrkesMetadataClient {
121 self.orkes_metadata_client()
122 }
123
124 #[must_use]
126 pub fn scheduler_client(&self) -> SchedulerClient {
127 SchedulerClient::new(self.api.clone())
128 }
129
130 #[must_use]
132 pub fn get_scheduler_client(&self) -> SchedulerClient {
133 self.scheduler_client()
134 }
135
136 #[must_use]
138 pub fn secret_client(&self) -> SecretClient {
139 SecretClient::new(self.api.clone())
140 }
141
142 #[must_use]
144 pub fn get_secret_client(&self) -> SecretClient {
145 self.secret_client()
146 }
147
148 #[must_use]
150 pub fn authorization_client(&self) -> AuthorizationClient {
151 AuthorizationClient::new(self.api.clone())
152 }
153
154 #[must_use]
156 pub fn get_authorization_client(&self) -> AuthorizationClient {
157 self.authorization_client()
158 }
159
160 #[must_use]
162 pub fn integration_client(&self) -> IntegrationClient {
163 IntegrationClient::new(self.api.clone())
164 }
165
166 #[must_use]
168 pub fn get_integration_client(&self) -> IntegrationClient {
169 self.integration_client()
170 }
171
172 #[must_use]
174 pub fn prompt_client(&self) -> PromptClient {
175 PromptClient::new(self.api.clone())
176 }
177
178 #[must_use]
180 pub fn get_prompt_client(&self) -> PromptClient {
181 self.prompt_client()
182 }
183
184 #[must_use]
186 pub fn schema_client(&self) -> SchemaClient {
187 SchemaClient::new(self.api.clone())
188 }
189
190 #[must_use]
192 pub fn get_schema_client(&self) -> SchemaClient {
193 self.schema_client()
194 }
195
196 #[must_use]
198 pub fn event_client(&self) -> EventClient {
199 EventClient::new(self.api.clone())
200 }
201
202 #[must_use]
204 pub fn get_event_client(&self) -> EventClient {
205 self.event_client()
206 }
207
208 #[cfg(feature = "agents")]
212 #[must_use]
213 pub fn agent_client(&self) -> AgentClient {
214 AgentClient::new(self.api.clone())
215 }
216
217 #[cfg(feature = "agents")]
219 #[must_use]
220 pub fn get_agent_client(&self) -> AgentClient {
221 self.agent_client()
222 }
223
224 #[must_use]
226 pub fn api_client(&self) -> &ApiClient {
227 &self.api
228 }
229
230 pub async fn is_oss(&self) -> bool {
235 self.api.is_oss().await
236 }
237
238 pub async fn config(&self) -> Configuration {
240 self.api.get_config().await
241 }
242}
243
244pub struct ConductorClientBuilder {
246 config: Configuration,
247}
248
249impl ConductorClientBuilder {
250 #[must_use]
252 pub fn new() -> Self {
253 Self {
254 config: Configuration::default(),
255 }
256 }
257
258 #[must_use]
260 pub fn from_config(config: Configuration) -> Self {
261 Self { config }
262 }
263
264 #[must_use]
266 pub fn server_url(mut self, url: impl Into<String>) -> Self {
267 self.config.server_api_url = url.into();
268 self
269 }
270
271 #[must_use]
273 pub fn auth(mut self, key: impl Into<String>, secret: impl Into<String>) -> Self {
274 self.config.auth_key = Some(key.into());
275 self.config.auth_secret = Some(secret.into());
276 self
277 }
278
279 #[must_use]
281 pub fn debug(mut self, enabled: bool) -> Self {
282 self.config.debug = enabled;
283 self
284 }
285
286 pub fn build(self) -> Result<ConductorClient> {
292 ConductorClient::new(self.config)
293 }
294}
295
296impl Default for ConductorClientBuilder {
297 fn default() -> Self {
298 Self::new()
299 }
300}
301
302#[cfg(test)]
303mod tests {
304 use super::*;
305
306 #[test]
307 fn test_builder() {
308 let client = ConductorClientBuilder::new()
309 .server_url("http://localhost:8080/api")
310 .debug(true)
311 .build();
312
313 client.unwrap();
314 }
315
316 #[test]
317 fn test_client_creation() {
318 let config = Configuration::new("http://localhost:8080/api");
319 let client = ConductorClient::new(config);
320 client.unwrap();
321 }
322}