#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillSpec {
pub name: String,
pub description: String,
pub content: String,
pub is_user_invocable: bool,
}
pub struct SkillCreatorController {
name: String,
description: String,
content: String,
is_user_invocable: bool,
}
impl SkillCreatorController {
pub fn new() -> Self {
Self {
name: String::new(),
description: String::new(),
content: String::new(),
is_user_invocable: true,
}
}
pub fn set_name(&mut self, name: impl Into<String>) {
self.name = name.into();
}
pub fn name(&self) -> &str {
&self.name
}
pub fn set_description(&mut self, description: impl Into<String>) {
self.description = description.into();
}
pub fn description(&self) -> &str {
&self.description
}
pub fn set_content(&mut self, content: impl Into<String>) {
self.content = content.into();
}
pub fn content(&self) -> &str {
&self.content
}
pub fn set_user_invocable(&mut self, invocable: bool) {
self.is_user_invocable = invocable;
}
pub fn is_user_invocable(&self) -> bool {
self.is_user_invocable
}
pub fn validate(&self) -> Result<SkillSpec, String> {
if self.name.trim().is_empty() {
return Err("Skill name is required".into());
}
if self.description.trim().is_empty() {
return Err("Skill description is required".into());
}
if self.content.trim().is_empty() {
return Err("Skill content is required".into());
}
Ok(SkillSpec {
name: self.name.trim().to_string(),
description: self.description.trim().to_string(),
content: self.content.clone(),
is_user_invocable: self.is_user_invocable,
})
}
pub fn reset(&mut self) {
self.name.clear();
self.description.clear();
self.content.clear();
self.is_user_invocable = true;
}
}
impl Default for SkillCreatorController {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
#[path = "skill_creator_tests.rs"]
mod tests;