1use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8use std::time::{Duration, SystemTime};
9
10pub use super::config::OrchestrateConfig;
12
13#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct Agent {
16 #[serde(rename = "id")]
18 pub agent_id: String,
19 #[serde(rename = "display_name")]
21 pub name: String,
22}
23
24#[derive(Clone, Debug, Serialize, Deserialize)]
26pub struct CustomAssistant {
27 pub id: String,
29 pub name: String,
31 pub description: Option<String>,
33 pub status: AssistantStatus,
35 pub created_at: Option<SystemTime>,
37 pub updated_at: Option<SystemTime>,
39 pub config: AssistantConfig,
41 pub skills: Vec<Skill>,
43 pub tools: Vec<Tool>,
45}
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
49pub enum AssistantStatus {
50 Active,
52 Inactive,
54 Training,
56 Error,
58 Deploying,
60}
61
62#[derive(Clone, Debug, Serialize, Deserialize)]
64pub struct AssistantConfig {
65 pub model_id: String,
67 pub system_prompt: Option<String>,
69 pub max_tokens: u32,
71 pub temperature: f32,
73 pub top_p: f32,
75 pub enable_streaming: bool,
77 pub custom_params: HashMap<String, serde_json::Value>,
79}
80
81impl Default for AssistantConfig {
82 fn default() -> Self {
83 Self {
84 model_id: "ibm/granite-3.0-8b-instruct".to_string(),
85 system_prompt: None,
86 max_tokens: 2048,
87 temperature: 0.7,
88 top_p: 0.9,
89 enable_streaming: true,
90 custom_params: HashMap::new(),
91 }
92 }
93}
94
95#[derive(Clone, Debug, Serialize, Deserialize)]
97pub struct Skill {
98 pub id: String,
100 pub name: String,
102 pub description: Option<String>,
104 pub skill_type: SkillType,
106 pub config: SkillConfig,
108 pub enabled: bool,
110 pub version: Option<String>,
112}
113
114#[derive(Clone, Debug, Serialize, Deserialize)]
116pub enum SkillType {
117 TextProcessing,
119 CodeGeneration,
121 DataAnalysis,
123 DocumentProcessing,
125 Custom(String),
127}
128
129#[derive(Clone, Debug, Serialize, Deserialize)]
131pub struct SkillConfig {
132 pub input_params: HashMap<String, ParameterDefinition>,
134 pub output_params: HashMap<String, ParameterDefinition>,
136 pub timeout: Duration,
138 pub retry_config: Option<OrchestrateRetryConfig>,
140 pub custom_settings: HashMap<String, serde_json::Value>,
142}
143
144#[derive(Clone, Debug, Serialize, Deserialize)]
146pub struct ParameterDefinition {
147 pub name: String,
149 pub param_type: ParameterType,
151 pub required: bool,
153 pub default_value: Option<serde_json::Value>,
155 pub description: Option<String>,
157 pub validation: Option<ValidationRules>,
159}
160
161#[derive(Clone, Debug, Serialize, Deserialize)]
163pub enum ParameterType {
164 String,
166 Integer,
168 Float,
170 Boolean,
172 Array,
174 Object,
176 File,
178}
179
180#[derive(Clone, Debug, Serialize, Deserialize)]
182pub struct ValidationRules {
183 pub min_value: Option<f64>,
185 pub max_value: Option<f64>,
187 pub min_length: Option<usize>,
189 pub max_length: Option<usize>,
191 pub allowed_values: Option<Vec<serde_json::Value>>,
193 pub pattern: Option<String>,
195}
196
197#[derive(Clone, Debug, Serialize, Deserialize)]
199pub struct Tool {
200 pub id: String,
202 pub name: String,
204 pub description: Option<String>,
206 #[serde(default)]
208 pub tool_type: Option<ToolType>,
209 #[serde(default)]
211 pub config: Option<ToolConfig>,
212 #[serde(default)]
214 pub enabled: bool,
215 pub version: Option<String>,
217}
218
219#[derive(Clone, Debug, Serialize, Deserialize)]
221pub enum ToolType {
222 Api,
224 Database,
226 FileSystem,
228 WebScraping,
230 Custom(String),
232}
233
234#[derive(Clone, Debug, Serialize, Deserialize)]
236pub struct ToolConfig {
237 pub endpoint: Option<String>,
239 pub auth: Option<AuthConfig>,
241 pub headers: HashMap<String, String>,
243 pub timeout: Duration,
245 pub retry_config: Option<OrchestrateRetryConfig>,
247 pub custom_settings: HashMap<String, serde_json::Value>,
249}
250
251#[derive(Clone, Debug, Serialize, Deserialize)]
253pub struct AuthConfig {
254 pub auth_type: AuthType,
256 pub credentials: HashMap<String, String>,
258}
259
260#[derive(Clone, Debug, Serialize, Deserialize)]
262pub enum AuthType {
263 ApiKey,
265 Bearer,
267 Basic,
269 OAuth,
271 None,
273}
274
275#[derive(Clone, Debug, Serialize, Deserialize)]
277pub struct DocumentCollection {
278 pub id: String,
280 pub name: String,
282 pub description: Option<String>,
284 pub status: CollectionStatus,
286 pub created_at: Option<SystemTime>,
288 pub updated_at: Option<SystemTime>,
290 pub document_count: u32,
292 pub vector_index: Option<VectorIndexConfig>,
294}
295
296#[derive(Clone, Debug, Serialize, Deserialize)]
298pub enum CollectionStatus {
299 Active,
301 Inactive,
303 Processing,
305 Error,
307}
308
309#[derive(Clone, Debug, Serialize, Deserialize)]
311pub struct VectorIndexConfig {
312 pub id: String,
314 pub embedding_model: String,
316 pub dimensions: u32,
318 pub index_type: IndexType,
320 pub similarity_metric: SimilarityMetric,
322}
323
324#[derive(Clone, Debug, Serialize, Deserialize)]
326pub enum IndexType {
327 Hnsw,
329 Ivf,
331 Flat,
333}
334
335#[derive(Clone, Debug, Serialize, Deserialize)]
337pub enum SimilarityMetric {
338 Cosine,
340 Euclidean,
342 InnerProduct,
344}
345
346#[derive(Clone, Debug, Serialize, Deserialize)]
348pub struct Document {
349 pub id: String,
351 pub title: String,
353 pub content: String,
355 pub metadata: HashMap<String, serde_json::Value>,
357 pub document_type: DocumentType,
359 pub created_at: Option<SystemTime>,
361 pub updated_at: Option<SystemTime>,
363 pub embedding: Option<Vec<f32>>,
365}
366
367#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
369pub enum DocumentType {
370 Text,
372 Pdf,
374 Markdown,
376 Html,
378 Json,
380 Csv,
382}
383
384#[derive(Clone, Debug, Serialize, Deserialize)]
386pub struct Message {
387 pub role: String,
388 pub content: String,
389}
390
391#[derive(Clone, Debug, Serialize, Deserialize)]
393pub struct MessagePayload {
394 pub message: Message,
395 #[serde(skip_serializing_if = "HashMap::is_empty")]
396 pub additional_properties: HashMap<String, serde_json::Value>,
397 #[serde(skip_serializing_if = "HashMap::is_empty")]
398 pub context: HashMap<String, serde_json::Value>,
399 pub agent_id: String,
400 #[serde(skip_serializing_if = "Option::is_none")]
401 pub thread_id: Option<String>,
402}
403
404#[derive(Clone, Debug, Serialize, Deserialize)]
406pub struct ThreadInfo {
407 pub thread_id: String,
409 pub agent_id: Option<String>,
411 pub title: Option<String>,
413 pub created_at: Option<String>,
415 pub updated_at: Option<String>,
417 pub message_count: Option<u32>,
419}
420
421#[derive(Clone, Debug, Serialize, Deserialize)]
423pub struct ChatMessage {
424 pub id: String,
426 pub role: MessageRole,
428 pub content: String,
430 pub timestamp: SystemTime,
432 pub metadata: HashMap<String, serde_json::Value>,
434}
435
436#[derive(Clone, Debug, Serialize, Deserialize)]
438pub enum MessageRole {
439 System,
441 User,
443 Assistant,
445 Tool,
447}
448
449#[derive(Clone, Debug, Serialize, Deserialize)]
451pub struct ChatSession {
452 pub id: String,
454 pub assistant_id: String,
456 pub messages: Vec<ChatMessage>,
458 pub metadata: HashMap<String, serde_json::Value>,
460 pub created_at: SystemTime,
462 pub updated_at: SystemTime,
464}
465
466#[derive(Clone, Debug, Serialize)]
468pub struct CreateAssistantRequest {
469 pub name: String,
471 pub description: Option<String>,
473 pub config: AssistantConfig,
475 pub skills: Option<Vec<String>>,
477 pub tools: Option<Vec<String>>,
479}
480
481#[derive(Clone, Debug, Serialize)]
483pub struct UpdateAssistantRequest {
484 pub name: Option<String>,
486 pub description: Option<String>,
488 pub config: Option<AssistantConfig>,
490 pub add_skills: Option<Vec<String>>,
492 pub remove_skills: Option<Vec<String>>,
494 pub add_tools: Option<Vec<String>>,
496 pub remove_tools: Option<Vec<String>>,
498}
499
500#[derive(Clone, Debug, Serialize)]
502pub struct ChatRequest {
503 pub message: String,
505 pub session_id: Option<String>,
507 pub metadata: Option<HashMap<String, serde_json::Value>>,
509 pub stream: bool,
511}
512
513#[derive(Clone, Debug, Serialize, Deserialize)]
515pub struct ChatResponse {
516 pub message: String,
518 pub session_id: String,
520 pub message_id: String,
522 pub metadata: HashMap<String, serde_json::Value>,
524 pub tool_calls: Option<Vec<ToolCall>>,
526}
527
528#[derive(Clone, Debug, Serialize, Deserialize)]
530pub struct ToolCall {
531 pub id: String,
533 pub tool_name: String,
535 pub parameters: HashMap<String, serde_json::Value>,
537 pub result: Option<serde_json::Value>,
539}
540
541#[derive(Clone, Debug, Serialize)]
543pub struct CreateCollectionRequest {
544 pub name: String,
546 pub description: Option<String>,
548 pub vector_index: Option<VectorIndexConfig>,
550}
551
552#[derive(Clone, Debug, Serialize)]
554pub struct AddDocumentsRequest {
555 pub documents: Vec<Document>,
557 pub async_processing: bool,
559}
560
561#[derive(Clone, Debug, Serialize)]
563pub struct SearchRequest {
564 pub query: String,
566 pub limit: Option<u32>,
568 pub threshold: Option<f32>,
570 pub filters: Option<HashMap<String, serde_json::Value>>,
572}
573
574#[derive(Clone, Debug, Serialize, Deserialize)]
576pub struct SearchResult {
577 pub document_id: String,
579 pub title: String,
581 pub content_snippet: String,
583 pub similarity_score: f32,
585 pub metadata: HashMap<String, serde_json::Value>,
587}
588
589#[derive(Clone, Debug, Serialize, Deserialize)]
591pub struct SearchResponse {
592 pub results: Vec<SearchResult>,
594 pub total_results: u32,
596 pub metadata: HashMap<String, serde_json::Value>,
598}
599
600#[derive(Clone, Debug, Serialize, Deserialize)]
602pub struct OrchestrateRetryConfig {
603 pub max_attempts: u32,
605 pub base_delay: Duration,
607 pub max_delay: Duration,
609 pub backoff_multiplier: f32,
611 pub retry_on_errors: Vec<String>,
613}
614
615impl Default for OrchestrateRetryConfig {
616 fn default() -> Self {
617 Self {
618 max_attempts: 3,
619 base_delay: Duration::from_secs(1),
620 max_delay: Duration::from_secs(30),
621 backoff_multiplier: 2.0,
622 retry_on_errors: vec!["timeout".to_string(), "network_error".to_string()],
623 }
624 }
625}
626
627#[derive(Clone, Debug, Serialize, Deserialize)]
629pub struct RunInfo {
630 pub run_id: String,
632 pub thread_id: String,
634 pub agent_id: Option<String>,
636 pub status: RunStatus,
638 pub created_at: Option<String>,
640 pub completed_at: Option<String>,
642 pub metadata: HashMap<String, serde_json::Value>,
644}
645
646#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
648pub enum RunStatus {
649 #[serde(rename = "queued")]
651 Queued,
652 #[serde(rename = "in_progress")]
654 InProgress,
655 #[serde(rename = "completed")]
657 Completed,
658 #[serde(rename = "failed")]
660 Failed,
661 #[serde(rename = "cancelled")]
663 Cancelled,
664}
665
666#[derive(Clone, Debug, Serialize)]
668pub struct ToolExecutionRequest {
669 pub tool_id: String,
671 pub parameters: HashMap<String, serde_json::Value>,
673 pub context: Option<HashMap<String, serde_json::Value>>,
675}
676
677#[derive(Clone, Debug, Serialize, Deserialize)]
679pub struct ToolExecutionResult {
680 pub tool_id: String,
682 pub status: String,
684 pub result: serde_json::Value,
686 pub execution_time_ms: Option<u64>,
688 pub error: Option<String>,
690}
691
692#[derive(Clone, Debug, Serialize)]
694pub struct ToolUpdateRequest {
695 pub name: Option<String>,
697 pub description: Option<String>,
699 pub config: Option<ToolConfig>,
701 pub enabled: Option<bool>,
703 pub metadata: Option<HashMap<String, serde_json::Value>>,
705}
706
707#[derive(Clone, Debug, Deserialize)]
709pub struct ToolVersion {
710 pub id: String,
712 pub version: String,
714 pub created_at: Option<String>,
716 pub updated_at: Option<String>,
718 pub metadata: Option<HashMap<String, serde_json::Value>>,
720}
721
722#[derive(Clone, Debug, Deserialize)]
724pub struct ToolExecutionHistory {
725 pub id: String,
727 pub tool_id: String,
729 pub status: String,
731 pub timestamp: Option<String>,
733 pub execution_time_ms: Option<u64>,
735 pub input: Option<serde_json::Value>,
737 pub output: Option<serde_json::Value>,
739 pub error: Option<String>,
741}
742
743#[derive(Clone, Debug, Serialize)]
745pub struct ToolTestRequest {
746 pub tool_id: String,
748 pub input: serde_json::Value,
750 pub metadata: Option<HashMap<String, serde_json::Value>>,
752}
753
754#[derive(Clone, Debug, Deserialize)]
756pub struct ToolTestResult {
757 pub status: String,
759 pub output: Option<serde_json::Value>,
761 pub error: Option<String>,
763 pub execution_time_ms: Option<u64>,
765}
766
767#[derive(Clone, Debug, Serialize)]
769pub struct BatchMessageRequest {
770 pub messages: Vec<Message>,
772 pub agent_id: String,
774 pub thread_id: Option<String>,
776 pub metadata: Option<HashMap<String, serde_json::Value>>,
778}
779
780#[derive(Clone, Debug, Serialize, Deserialize)]
782pub struct BatchMessageResponse {
783 pub batch_id: String,
785 pub responses: Vec<BatchMessageResult>,
787 pub metadata: HashMap<String, serde_json::Value>,
789}
790
791#[derive(Clone, Debug, Serialize, Deserialize)]
793pub struct BatchMessageResult {
794 pub message_index: usize,
796 pub response: String,
798 pub processing_time_ms: Option<u64>,
800 pub error: Option<String>,
802}
803
804#[derive(Clone, Debug, Serialize)]
806pub struct AgentExecutionConfig {
807 pub max_execution_time: Option<u32>,
809 pub enable_tools: bool,
811 pub allowed_tools: Vec<String>,
813 pub custom_params: HashMap<String, serde_json::Value>,
815}
816
817impl Default for AgentExecutionConfig {
818 fn default() -> Self {
819 Self {
820 max_execution_time: Some(300),
821 enable_tools: true,
822 allowed_tools: Vec::new(),
823 custom_params: HashMap::new(),
824 }
825 }
826}
827
828#[derive(Clone, Debug, Serialize)]
830pub struct ChatWithDocsRequest {
831 pub message: String,
833 pub document_content: Option<String>,
835 pub document_path: Option<String>,
837 pub context: Option<HashMap<String, serde_json::Value>>,
839}
840
841#[derive(Clone, Debug, Deserialize)]
843pub struct ChatWithDocsResponse {
844 pub message: String,
846 pub documents_used: Option<Vec<String>>,
848 pub confidence: Option<f64>,
850 pub metadata: Option<HashMap<String, serde_json::Value>>,
852}
853
854#[derive(Clone, Debug, Deserialize)]
856pub struct ChatWithDocsStatus {
857 pub status: String,
859 pub document_count: Option<u32>,
861 pub last_updated: Option<String>,
863 pub error_message: Option<String>,
865 pub metadata: Option<HashMap<String, serde_json::Value>>,
867}