enact_core/graph/node/
mod.rs1mod function;
4mod llm;
5
6use async_trait::async_trait;
7use serde_json::Value;
8use std::sync::Arc;
9
10pub use function::FunctionNode;
11pub use llm::LlmNode;
12
13#[derive(Debug, Clone, Default)]
15pub struct NodeState {
16 pub data: Value,
17}
18
19impl NodeState {
20 pub fn new() -> Self {
21 Self { data: Value::Null }
22 }
23
24 pub fn from_value(data: Value) -> Self {
25 Self { data }
26 }
27
28 pub fn from_string(s: &str) -> Self {
30 Self {
31 data: Value::String(s.to_string()),
32 }
33 }
34
35 pub fn as_str(&self) -> Option<&str> {
36 self.data.as_str()
37 }
38}
39
40#[async_trait]
42pub trait Node: Send + Sync {
43 fn name(&self) -> &str;
45
46 async fn execute(&self, state: NodeState) -> anyhow::Result<NodeState>;
48}
49
50pub type DynNode = Arc<dyn Node>;