ri_agent_graph/
command.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4
5#[derive(Debug, Clone)]
7pub enum NodeOutput {
8 Done,
10 Command(Command),
12}
13
14#[derive(Debug, Clone)]
16pub struct Command {
17 pub update: Option<HashMap<String, Value>>,
19 pub goto: Navigation,
21}
22
23#[derive(Debug, Clone)]
25pub enum Navigation {
26 Node(String),
28 Nodes(Vec<String>),
30 End,
32 Send(Vec<SendOp>),
34 Default,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct SendOp {
41 pub node: String,
43 pub state: HashMap<String, Value>,
45}
46
47impl Command {
48 pub fn goto(node: impl Into<String>) -> Self {
50 Self {
51 update: None,
52 goto: Navigation::Node(node.into()),
53 }
54 }
55
56 pub fn end() -> Self {
58 Self {
59 update: None,
60 goto: Navigation::End,
61 }
62 }
63
64 pub fn update(updates: HashMap<String, Value>) -> Self {
66 Self {
67 update: Some(updates),
68 goto: Navigation::Default,
69 }
70 }
71
72 pub fn with_update(mut self, updates: HashMap<String, Value>) -> Self {
74 self.update = Some(updates);
75 self
76 }
77
78 pub fn with_goto(mut self, goto: Navigation) -> Self {
80 self.goto = goto;
81 self
82 }
83}
84
85impl NodeOutput {
86 pub fn goto(node: impl Into<String>) -> Self {
88 NodeOutput::Command(Command::goto(node))
89 }
90
91 pub fn end() -> Self {
93 NodeOutput::Command(Command::end())
94 }
95}
96
97impl From<()> for NodeOutput {
98 fn from((): ()) -> Self {
99 NodeOutput::Done
100 }
101}