1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// Copyright {{.Year}} Conductor OSS
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
use crate::configuration::Configuration;
use crate::error::Result;
use crate::events::EventDispatcher;
use crate::http::ApiClient;
#[cfg(feature = "agents")]
use super::AgentClient;
use super::{
AuthorizationClient, EventClient, IntegrationClient, MetadataClient, OrkesMetadataClient,
PromptClient, SchedulerClient, SchemaClient, SecretClient, TaskClient, WorkflowClient,
};
/// Main Conductor client combining all API clients.
///
/// This is the primary entry point for interacting with the Conductor API.
/// Also available as the `OrkesClients` alias.
#[derive(Clone)]
pub struct ConductorClient {
api: ApiClient,
/// Shared event dispatcher used by service clients that emit events
/// (currently [`WorkflowClient`]). Defaults to an empty dispatcher;
/// replace with [`Self::with_event_dispatcher`] to wire up listeners
/// such as the metrics collector.
events: EventDispatcher,
}
impl ConductorClient {
/// Create a new Conductor client with the given configuration.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the underlying `reqwest` client fails to build
/// (e.g. TLS backend initialization failure) -- this doesn't make any network request.
pub fn new(config: Configuration) -> Result<Self> {
let api = ApiClient::new(config)?;
Ok(Self {
api,
events: EventDispatcher::default(),
})
}
/// Create from an existing API client.
#[must_use]
pub fn from_api_client(api: ApiClient) -> Self {
Self {
api,
events: EventDispatcher::default(),
}
}
/// Share an [`EventDispatcher`] with this client so that service clients
/// (such as [`WorkflowClient`]) publish events to it.
///
/// Typically used to route workflow-lifecycle events through the same
/// dispatcher as [`TaskHandler`](crate::worker::TaskHandler), allowing a
/// single `MetricsCollector` to observe both task- and workflow-level
/// metrics.
#[must_use]
pub fn with_event_dispatcher(mut self, events: EventDispatcher) -> Self {
self.events = events;
self
}
/// Access the shared event dispatcher.
#[must_use]
pub fn event_dispatcher(&self) -> &EventDispatcher {
&self.events
}
/// Get the task client for polling and updating tasks.
#[must_use]
pub fn task_client(&self) -> TaskClient {
TaskClient::new(self.api.clone())
}
/// Alias for `task_client()`.
#[must_use]
pub fn get_task_client(&self) -> TaskClient {
self.task_client()
}
/// Get the workflow client for workflow operations.
#[must_use]
pub fn workflow_client(&self) -> WorkflowClient {
WorkflowClient::new_with_events(self.api.clone(), self.events.clone())
}
/// Alias for `workflow_client()`.
#[must_use]
pub fn get_workflow_client(&self) -> WorkflowClient {
self.workflow_client()
}
/// Get the metadata client for managing definitions.
#[must_use]
pub fn metadata_client(&self) -> MetadataClient {
MetadataClient::new(self.api.clone())
}
/// Alias for `metadata_client()`.
#[must_use]
pub fn get_metadata_client(&self) -> MetadataClient {
self.metadata_client()
}
/// Get the Orkes metadata client with tagging APIs.
///
/// This client extends `MetadataClient` with Orkes-specific features
/// like workflow and task tagging. Access base methods via Deref.
#[must_use]
pub fn orkes_metadata_client(&self) -> OrkesMetadataClient {
OrkesMetadataClient::new(self.api.clone())
}
/// Alias for `orkes_metadata_client()`.
#[must_use]
pub fn get_orkes_metadata_client(&self) -> OrkesMetadataClient {
self.orkes_metadata_client()
}
/// Get the scheduler client for managing workflow schedules.
#[must_use]
pub fn scheduler_client(&self) -> SchedulerClient {
SchedulerClient::new(self.api.clone())
}
/// Alias for `scheduler_client()`.
#[must_use]
pub fn get_scheduler_client(&self) -> SchedulerClient {
self.scheduler_client()
}
/// Get the secret client for managing secrets.
#[must_use]
pub fn secret_client(&self) -> SecretClient {
SecretClient::new(self.api.clone())
}
/// Alias for `secret_client()`.
#[must_use]
pub fn get_secret_client(&self) -> SecretClient {
self.secret_client()
}
/// Get the authorization client for users, groups, and permissions.
#[must_use]
pub fn authorization_client(&self) -> AuthorizationClient {
AuthorizationClient::new(self.api.clone())
}
/// Alias for `authorization_client()`.
#[must_use]
pub fn get_authorization_client(&self) -> AuthorizationClient {
self.authorization_client()
}
/// Get the integration client for external system integrations.
#[must_use]
pub fn integration_client(&self) -> IntegrationClient {
IntegrationClient::new(self.api.clone())
}
/// Alias for `integration_client()`.
#[must_use]
pub fn get_integration_client(&self) -> IntegrationClient {
self.integration_client()
}
/// Get the prompt client for AI prompt templates.
#[must_use]
pub fn prompt_client(&self) -> PromptClient {
PromptClient::new(self.api.clone())
}
/// Alias for `prompt_client()`.
#[must_use]
pub fn get_prompt_client(&self) -> PromptClient {
self.prompt_client()
}
/// Get the schema client for schema definitions.
#[must_use]
pub fn schema_client(&self) -> SchemaClient {
SchemaClient::new(self.api.clone())
}
/// Alias for `schema_client()`.
#[must_use]
pub fn get_schema_client(&self) -> SchemaClient {
self.schema_client()
}
/// Get the event client for event queue configurations.
#[must_use]
pub fn event_client(&self) -> EventClient {
EventClient::new(self.api.clone())
}
/// Alias for `event_client()`.
#[must_use]
pub fn get_event_client(&self) -> EventClient {
self.event_client()
}
/// Get the agent client for the Agent Runtime control-plane API (`/agent/*`).
///
/// Requires the `agents` Cargo feature.
#[cfg(feature = "agents")]
#[must_use]
pub fn agent_client(&self) -> AgentClient {
AgentClient::new(self.api.clone())
}
/// Alias for `agent_client()`.
#[cfg(feature = "agents")]
#[must_use]
pub fn get_agent_client(&self) -> AgentClient {
self.agent_client()
}
/// Get the underlying API client.
#[must_use]
pub fn api_client(&self) -> &ApiClient {
&self.api
}
/// Check whether the server is OSS Conductor (vs Orkes Enterprise).
///
/// The result is cached after the first call. See [`ApiClient::is_oss`] for
/// details on the detection mechanism.
pub async fn is_oss(&self) -> bool {
self.api.is_oss().await
}
/// Get configuration.
pub async fn config(&self) -> Configuration {
self.api.get_config().await
}
}
/// Builder for `ConductorClient`.
pub struct ConductorClientBuilder {
config: Configuration,
}
impl ConductorClientBuilder {
/// Create a new builder with default configuration.
#[must_use]
pub fn new() -> Self {
Self {
config: Configuration::default(),
}
}
/// Create a builder from an existing configuration.
#[must_use]
pub fn from_config(config: Configuration) -> Self {
Self { config }
}
/// Set the server URL.
#[must_use]
pub fn server_url(mut self, url: impl Into<String>) -> Self {
self.config.server_api_url = url.into();
self
}
/// Set authentication credentials.
#[must_use]
pub fn auth(mut self, key: impl Into<String>, secret: impl Into<String>) -> Self {
self.config.auth_key = Some(key.into());
self.config.auth_secret = Some(secret.into());
self
}
/// Enable debug mode.
#[must_use]
pub fn debug(mut self, enabled: bool) -> Self {
self.config.debug = enabled;
self
}
/// Build the client.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub fn build(self) -> Result<ConductorClient> {
ConductorClient::new(self.config)
}
}
impl Default for ConductorClientBuilder {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_builder() {
let client = ConductorClientBuilder::new()
.server_url("http://localhost:8080/api")
.debug(true)
.build();
client.unwrap();
}
#[test]
fn test_client_creation() {
let config = Configuration::new("http://localhost:8080/api");
let client = ConductorClient::new(config);
client.unwrap();
}
}