omni_director/providers/
metadata.rs

1//! # Provider Metadata
2//!
3//! Metadata structures for providers and their capabilities.
4
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Provider metadata
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ProviderMetadata {
11    /// Provider name
12    pub name: String,
13    
14    /// Provider version
15    pub version: String,
16    
17    /// Provider description
18    pub description: String,
19    
20    /// Provider author
21    pub author: Option<String>,
22    
23    /// Provider license
24    pub license: Option<String>,
25    
26    /// Supported features
27    pub features: Vec<FeatureMetadata>,
28    
29    /// Provider settings schema
30    pub settings_schema: Option<serde_json::Value>,
31    
32    /// File path (for loaded providers)
33    pub file_path: Option<String>,
34    
35    /// Raw metadata from provider (for validation)
36    pub metadata: Option<serde_json::Value>,
37}
38
39/// Feature metadata within a provider
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct FeatureMetadata {
42    /// Feature name
43    pub name: String,
44    
45    /// Feature description
46    pub description: String,
47    
48    /// Feature version
49    pub version: String,
50    
51    /// Available operations
52    pub operations: Vec<OperationMetadata>,
53}
54
55/// Operation metadata within a feature
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct OperationMetadata {
58    /// Operation name
59    pub name: String,
60    
61    /// Operation description
62    pub description: String,
63    
64    /// Required arguments
65    pub arguments: Vec<ArgumentMetadata>,
66    
67    /// Return type description
68    pub return_type: String,
69    
70    /// Whether operation modifies state
71    pub is_mutating: bool,
72    
73    /// Estimated execution time in milliseconds
74    pub estimated_duration_ms: Option<u64>,
75}
76
77/// Argument metadata for operations
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct ArgumentMetadata {
80    /// Argument name
81    pub name: String,
82    
83    /// Argument description
84    pub description: String,
85    
86    /// Argument type
87    pub arg_type: ArgumentType,
88    
89    /// Whether argument is required
90    pub required: bool,
91    
92    /// Default value
93    pub default_value: Option<serde_json::Value>,
94    
95    /// Validation constraints
96    pub constraints: Option<ArgumentConstraints>,
97}
98
99/// Argument types
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(tag = "type")]
102pub enum ArgumentType {
103    String { max_length: Option<usize> },
104    Number { min: Option<f64>, max: Option<f64> },
105    Integer { min: Option<i64>, max: Option<i64> },
106    Boolean,
107    Array { item_type: Box<ArgumentType> },
108    Object { properties: HashMap<String, ArgumentType> },
109    Enum { values: Vec<String> },
110    Any,
111}
112
113/// Validation constraints for arguments
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct ArgumentConstraints {
116    /// Regex pattern for string validation
117    pub pattern: Option<String>,
118    
119    /// Minimum value for numbers
120    pub min: Option<f64>,
121    
122    /// Maximum value for numbers
123    pub max: Option<f64>,
124    
125    /// Allowed values
126    pub allowed_values: Option<Vec<serde_json::Value>>,
127    
128    /// Custom validation message
129    pub message: Option<String>,
130}
131
132impl ProviderMetadata {
133    /// Create new provider metadata
134    pub fn new(name: String, version: String, description: String) -> Self {
135        Self {
136            name,
137            version,
138            description,
139            author: None,
140            license: None,
141            features: Vec::new(),
142            settings_schema: None,
143            file_path: None,
144            metadata: None,
145        }
146    }
147    
148    /// Add a feature to the provider
149    pub fn add_feature(&mut self, feature: FeatureMetadata) {
150        self.features.push(feature);
151    }
152    
153    /// Get feature by name
154    pub fn get_feature(&self, name: &str) -> Option<&FeatureMetadata> {
155        self.features.iter().find(|f| f.name == name)
156    }
157    
158    /// Get all feature names
159    pub fn feature_names(&self) -> Vec<String> {
160        self.features.iter().map(|f| f.name.clone()).collect()
161    }
162}
163
164impl FeatureMetadata {
165    /// Create new feature metadata
166    pub fn new(name: String, description: String, version: String) -> Self {
167        Self {
168            name,
169            description,
170            version,
171            operations: Vec::new(),
172        }
173    }
174    
175    /// Add an operation to the feature
176    pub fn add_operation(&mut self, operation: OperationMetadata) {
177        self.operations.push(operation);
178    }
179    
180    /// Get operation by name
181    pub fn get_operation(&self, name: &str) -> Option<&OperationMetadata> {
182        self.operations.iter().find(|o| o.name == name)
183    }
184    
185    /// Get all operation names
186    pub fn operation_names(&self) -> Vec<String> {
187        self.operations.iter().map(|o| o.name.clone()).collect()
188    }
189}