worldinterface_core/flowspec/branch.rs
1//! Branch (conditional routing) node types for FlowSpec.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::id::NodeId;
7
8/// A conditional routing node. Evaluates a condition and directs flow
9/// to one of two target nodes.
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub struct BranchNode {
12 /// The condition to evaluate.
13 pub condition: BranchCondition,
14 /// Target node when condition is true.
15 pub then_edge: NodeId,
16 /// Target node when condition is false. None means the false branch
17 /// is skipped (flow continues past the branch).
18 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub else_edge: Option<NodeId>,
20}
21
22/// A condition that determines branch routing.
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "snake_case")]
25pub enum BranchCondition {
26 /// A runtime-evaluated expression string.
27 Expression(String),
28 /// Equality comparison between a referenced value and a literal.
29 Equals { left: ParamRef, right: Value },
30 /// True if the referenced value is non-null.
31 Exists(ParamRef),
32}
33
34/// A reference to a value available at runtime.
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
36#[serde(rename_all = "snake_case")]
37pub enum ParamRef {
38 /// Reference to a specific node's output at a JSON path.
39 NodeOutput {
40 node_id: NodeId,
41 /// Dot-notation path into the node's output value.
42 path: String,
43 },
44 /// Reference to a flow-level parameter at a JSON path.
45 FlowParam {
46 /// Dot-notation path into `FlowSpec.params`.
47 path: String,
48 },
49}