mod function;
mod llm;
use async_trait::async_trait;
use serde_json::Value;
use std::sync::Arc;
pub use function::FunctionNode;
pub use llm::LlmNode;
#[derive(Debug, Clone, Default)]
pub struct NodeState {
pub data: Value,
}
impl NodeState {
pub fn new() -> Self {
Self { data: Value::Null }
}
pub fn from_value(data: Value) -> Self {
Self { data }
}
pub fn from_string(s: &str) -> Self {
Self {
data: Value::String(s.to_string()),
}
}
pub fn as_str(&self) -> Option<&str> {
self.data.as_str()
}
}
#[async_trait]
pub trait Node: Send + Sync {
fn name(&self) -> &str;
async fn execute(&self, state: NodeState) -> anyhow::Result<NodeState>;
}
pub type DynNode = Arc<dyn Node>;