Skip to main content

adk_studio/schema/
workflow.rs

1use serde::{Deserialize, Serialize};
2
3/// Workflow definition schema
4#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5pub struct WorkflowSchema {
6    #[serde(rename = "type", default)]
7    pub workflow_type: WorkflowType,
8    #[serde(default)]
9    pub edges: Vec<Edge>,
10    #[serde(default)]
11    pub conditions: Vec<Condition>,
12}
13
14/// Workflow type
15#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
16#[serde(rename_all = "snake_case")]
17pub enum WorkflowType {
18    #[default]
19    Single,
20    Sequential,
21    Parallel,
22    Graph,
23}
24
25/// Edge between nodes
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct Edge {
29    pub from: String,
30    pub to: String,
31    #[serde(default)]
32    pub condition: Option<String>,
33    /// Source port for multi-output nodes (e.g., Switch branch output_port)
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub from_port: Option<String>,
36    /// Target port for multi-input nodes (e.g., Merge)
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub to_port: Option<String>,
39}
40
41impl Edge {
42    pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
43        Self {
44            from: from.into(),
45            to: to.into(),
46            condition: None,
47            from_port: None,
48            to_port: None,
49        }
50    }
51
52    pub fn conditional(
53        from: impl Into<String>,
54        to: impl Into<String>,
55        condition: impl Into<String>,
56    ) -> Self {
57        Self {
58            from: from.into(),
59            to: to.into(),
60            condition: Some(condition.into()),
61            from_port: None,
62            to_port: None,
63        }
64    }
65
66    pub fn with_from_port(mut self, port: impl Into<String>) -> Self {
67        self.from_port = Some(port.into());
68        self
69    }
70}
71
72/// Condition definition
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct Condition {
75    pub id: String,
76    pub expression: String,
77    #[serde(default)]
78    pub description: String,
79}
80
81/// Special node identifiers
82pub const START: &str = "START";
83pub const END: &str = "END";