use std::sync::Arc; #[derive(Clone, Debug, PartialEq, Eq)] pub enum CreativeAgentCallbackKind { Stage, ToolStarted, ToolCompleted, ModelRequestStarted, ModelRequestCompleted, Error, } #[derive(Clone, Debug, PartialEq, Eq)] pub struct CreativeAgentCallbackEvent { pub kind: CreativeAgentCallbackKind, pub label: String, pub detail: Option, } type CreativeAgentCallbackFn = Arc; #[derive(Clone, Default)] pub struct CreativeAgentCallbacks { on_event: Option, } impl CreativeAgentCallbacks { pub fn new(on_event: F) -> Self where F: Fn(CreativeAgentCallbackEvent) + Send + Sync + 'static, { Self { on_event: Some(Arc::new(on_event)), } } pub fn noop() -> Self { Self::default() } pub fn emit(&self, event: CreativeAgentCallbackEvent) { if let Some(on_event) = &self.on_event { on_event(event); } } pub fn stage(&self, label: impl Into) { self.emit(CreativeAgentCallbackEvent { kind: CreativeAgentCallbackKind::Stage, label: label.into(), detail: None, }); } }