omni_director/providers/
metadata.rs1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ProviderMetadata {
11 pub name: String,
13
14 pub version: String,
16
17 pub description: String,
19
20 pub author: Option<String>,
22
23 pub license: Option<String>,
25
26 pub features: Vec<FeatureMetadata>,
28
29 pub settings_schema: Option<serde_json::Value>,
31
32 pub file_path: Option<String>,
34
35 pub metadata: Option<serde_json::Value>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct FeatureMetadata {
42 pub name: String,
44
45 pub description: String,
47
48 pub version: String,
50
51 pub operations: Vec<OperationMetadata>,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct OperationMetadata {
58 pub name: String,
60
61 pub description: String,
63
64 pub arguments: Vec<ArgumentMetadata>,
66
67 pub return_type: String,
69
70 pub is_mutating: bool,
72
73 pub estimated_duration_ms: Option<u64>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct ArgumentMetadata {
80 pub name: String,
82
83 pub description: String,
85
86 pub arg_type: ArgumentType,
88
89 pub required: bool,
91
92 pub default_value: Option<serde_json::Value>,
94
95 pub constraints: Option<ArgumentConstraints>,
97}
98
99#[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#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct ArgumentConstraints {
116 pub pattern: Option<String>,
118
119 pub min: Option<f64>,
121
122 pub max: Option<f64>,
124
125 pub allowed_values: Option<Vec<serde_json::Value>>,
127
128 pub message: Option<String>,
130}
131
132impl ProviderMetadata {
133 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 pub fn add_feature(&mut self, feature: FeatureMetadata) {
150 self.features.push(feature);
151 }
152
153 pub fn get_feature(&self, name: &str) -> Option<&FeatureMetadata> {
155 self.features.iter().find(|f| f.name == name)
156 }
157
158 pub fn feature_names(&self) -> Vec<String> {
160 self.features.iter().map(|f| f.name.clone()).collect()
161 }
162}
163
164impl FeatureMetadata {
165 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 pub fn add_operation(&mut self, operation: OperationMetadata) {
177 self.operations.push(operation);
178 }
179
180 pub fn get_operation(&self, name: &str) -> Option<&OperationMetadata> {
182 self.operations.iter().find(|o| o.name == name)
183 }
184
185 pub fn operation_names(&self) -> Vec<String> {
187 self.operations.iter().map(|o| o.name.clone()).collect()
188 }
189}