use serde_json::Value;
use crate::mcp::core::{error::WorkflowError, nodes::Node, task::TaskContext};
use async_trait::async_trait;
#[derive(Debug, Clone)]
pub struct SearchRouterNode;
#[async_trait]
impl Node for SearchRouterNode {
async fn execute(&self, input: Value, _context: &TaskContext) -> Result<Value, WorkflowError> {
let is_valid = input
.get("query_valid")
.and_then(|v| v.as_bool())
.unwrap_or(false);
let is_spam = input
.get("is_spam")
.and_then(|v| v.as_bool())
.unwrap_or(false);
if !is_valid || is_spam {
return Err(WorkflowError::ValidationError {
message: "Query failed validation or was detected as spam".to_string(),
});
}
Ok(serde_json::json!({
"search_initiated": true,
"notion_search_ready": true,
"helpscout_search_ready": true,
"slack_search_ready": true,
"event_data": input.get("event_data").cloned().unwrap_or(input.clone())
}))
}
fn name(&self) -> &str {
"SearchRouterNode"
}
}