1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum Domain {
10 Frontend,
12 Backend,
14 DevOps,
16 Mobile,
18 DataScience,
20 Security,
22 Database,
24 Api,
26 Testing,
28 Documentation,
30}
31
32impl Domain {
33 pub fn all() -> &'static [Domain] {
35 &[
36 Domain::Frontend,
37 Domain::Backend,
38 Domain::DevOps,
39 Domain::Mobile,
40 Domain::DataScience,
41 Domain::Security,
42 Domain::Database,
43 Domain::Api,
44 Domain::Testing,
45 Domain::Documentation,
46 ]
47 }
48
49 pub fn as_str(&self) -> &'static str {
51 match self {
52 Domain::Frontend => "frontend",
53 Domain::Backend => "backend",
54 Domain::DevOps => "devops",
55 Domain::Mobile => "mobile",
56 Domain::DataScience => "data_science",
57 Domain::Security => "security",
58 Domain::Database => "database",
59 Domain::Api => "api",
60 Domain::Testing => "testing",
61 Domain::Documentation => "documentation",
62 }
63 }
64
65 pub fn from_str(s: &str) -> Option<Self> {
67 match s.to_lowercase().as_str() {
68 "frontend" => Some(Domain::Frontend),
69 "backend" => Some(Domain::Backend),
70 "devops" => Some(Domain::DevOps),
71 "mobile" => Some(Domain::Mobile),
72 "data_science" | "datascience" => Some(Domain::DataScience),
73 "security" => Some(Domain::Security),
74 "database" => Some(Domain::Database),
75 "api" => Some(Domain::Api),
76 "testing" => Some(Domain::Testing),
77 "documentation" => Some(Domain::Documentation),
78 _ => None,
79 }
80 }
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct KnowledgeEntry {
86 pub id: String,
88 pub category: String,
90 pub title: String,
92 pub description: String,
94 pub tags: Vec<String>,
96 pub example: Option<String>,
98 pub references: Vec<String>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct KnowledgeBase {
105 pub domain: String,
107 pub version: String,
109 pub last_updated: String,
111 pub entries: Vec<KnowledgeEntry>,
113 pub metadata: HashMap<String, String>,
115}
116
117impl KnowledgeBase {
118 pub fn new(domain: &str, version: &str) -> Self {
120 Self {
121 domain: domain.to_string(),
122 version: version.to_string(),
123 last_updated: chrono::Utc::now().to_rfc3339(),
124 entries: Vec::new(),
125 metadata: HashMap::new(),
126 }
127 }
128
129 pub fn add_entry(&mut self, entry: KnowledgeEntry) {
131 self.entries.push(entry);
132 self.last_updated = chrono::Utc::now().to_rfc3339();
133 }
134
135 pub fn search_by_tag(&self, tag: &str) -> Vec<&KnowledgeEntry> {
137 self.entries
138 .iter()
139 .filter(|entry| entry.tags.iter().any(|t| t.contains(tag)))
140 .collect()
141 }
142
143 pub fn search_by_category(&self, category: &str) -> Vec<&KnowledgeEntry> {
145 self.entries
146 .iter()
147 .filter(|entry| entry.category == category)
148 .collect()
149 }
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct DomainAgentConfig {
155 pub domain: String,
157 pub name: String,
159 pub description: String,
161 pub system_prompt: String,
163 pub tools: Vec<String>,
165 pub model: Option<String>,
167 pub temperature: Option<f32>,
169 pub max_tokens: Option<usize>,
171 pub custom_config: HashMap<String, serde_json::Value>,
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct DomainAgentMetadata {
178 pub domain: String,
180 pub name: String,
182 pub version: String,
184 pub capabilities: Vec<String>,
186 pub required_tools: Vec<String>,
188 pub optional_tools: Vec<String>,
190}
191
192#[derive(Debug, Clone, Serialize, Deserialize)]
194pub struct DomainAgentRegistry {
195 pub agents: HashMap<String, DomainAgentMetadata>,
197 pub knowledge_bases: HashMap<String, String>, }
200
201impl DomainAgentRegistry {
202 pub fn new() -> Self {
204 Self {
205 agents: HashMap::new(),
206 knowledge_bases: HashMap::new(),
207 }
208 }
209
210 pub fn register_agent(&mut self, domain: &str, metadata: DomainAgentMetadata) {
212 self.agents.insert(domain.to_string(), metadata);
213 }
214
215 pub fn register_knowledge_base(&mut self, domain: &str, path: String) {
217 self.knowledge_bases.insert(domain.to_string(), path);
218 }
219
220 pub fn get_agent(&self, domain: &str) -> Option<&DomainAgentMetadata> {
222 self.agents.get(domain)
223 }
224
225 pub fn get_knowledge_base(&self, domain: &str) -> Option<&str> {
227 self.knowledge_bases.get(domain).map(|s| s.as_str())
228 }
229}
230
231impl Default for DomainAgentRegistry {
232 fn default() -> Self {
233 Self::new()
234 }
235}