use async_trait::async_trait;
use serde_json::Value;
use crate::mcp::clients::notion::NotionClientNode;
use crate::mcp::core::{error::WorkflowError, nodes::Node, task::TaskContext};
#[derive(Debug)]
pub struct NotionSearchNode {
pub notion_client: Option<NotionClientNode>,
}
impl Default for NotionSearchNode {
fn default() -> Self {
Self {
notion_client: None,
}
}
}
impl NotionSearchNode {
pub fn new() -> Self {
Self::default()
}
pub fn with_client(mut self, client: NotionClientNode) -> Self {
self.notion_client = Some(client);
self
}
}
#[async_trait]
impl Node for NotionSearchNode {
async fn execute(&self, input: Value, _context: &TaskContext) -> Result<Value, WorkflowError> {
let user_query = input
.get("user_query")
.or_else(|| input.get("event_data").and_then(|ed| ed.get("user_query")))
.and_then(|v| v.as_str())
.unwrap_or("");
let mock_results = serde_json::json!({
"source": "notion",
"query": user_query,
"results_found": 3,
"pages": [
{
"title": "Related Documentation",
"url": "https://notion.so/page1",
"relevance": 85
},
{
"title": "FAQ Entry",
"url": "https://notion.so/page2",
"relevance": 72
}
]
});
Ok(serde_json::json!({
"notion_search_results": mock_results,
"notion_search_completed": true
}))
}
fn name(&self) -> &str {
"NotionSearchNode"
}
}