use crate::error::AgentId;
use crate::types::task::Task;
#[derive(Debug, Clone)]
pub enum HookEvent {
TeammateIdle {
agent_id: AgentId,
name: String,
tasks_completed: usize,
},
TaskCreated {
task: Task,
},
TaskCompleted {
task: Task,
agent_id: AgentId,
},
}
#[derive(Debug, Clone)]
pub enum HookResult {
Continue,
Reject { feedback: String },
}
pub trait Hook: Send + Sync {
fn on_event(&self, event: &HookEvent) -> HookResult;
}
pub struct HookRegistry {
hooks: Vec<Box<dyn Hook>>,
}
impl HookRegistry {
pub fn new() -> Self {
Self { hooks: Vec::new() }
}
pub fn add(&mut self, hook: impl Hook + 'static) {
self.hooks.push(Box::new(hook));
}
pub fn evaluate(&self, event: &HookEvent) -> HookResult {
for hook in &self.hooks {
if let HookResult::Reject { feedback } = hook.on_event(event) {
return HookResult::Reject { feedback };
}
}
HookResult::Continue
}
pub fn is_empty(&self) -> bool {
self.hooks.is_empty()
}
}
impl Default for HookRegistry {
fn default() -> Self {
Self::new()
}
}