use crate::BoxFuture;
use crate::agents::directive::Directive;
use serde_json::Value;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum DirectiveError {
#[error("Execution failed: {0}")]
ExecutionFailed(String),
#[error("Unsupported directive: {0}")]
Unsupported(String),
}
pub trait DirectiveExecutor: Send + Sync {
fn execute_directive(
&self,
directive: &Directive,
) -> BoxFuture<'_, Result<Option<Value>, DirectiveError>>;
}
#[derive(Debug, Default, Clone)]
pub struct NoOpExecutor;
impl DirectiveExecutor for NoOpExecutor {
fn execute_directive(
&self,
_directive: &Directive,
) -> BoxFuture<'_, Result<Option<Value>, DirectiveError>> {
Box::pin(async { Ok(None) })
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
#[tokio::test]
async fn test_noop_executor_returns_none() {
let executor = NoOpExecutor;
let directive = Directive::Stop { reason: None };
let result = executor
.execute_directive(&directive)
.await
.expect("execute");
assert!(result.is_none());
}
}