Skip to main content

ironflow_engine/config/
mod.rs

1//! Serializable step configurations — one per operation type.
2//!
3//! These types mirror the builder options in [`ironflow_core`] operations but
4//! are fully serializable, allowing them to be stored as JSON in the database
5//! and reconstructed by the executor at runtime.
6
7mod agent;
8mod approval;
9mod artifact;
10mod http;
11mod shell;
12mod workflow;
13
14pub use agent::AgentStepConfig;
15pub use approval::ApprovalConfig;
16pub use artifact::{ArtifactInput, ArtifactOutput};
17pub use http::HttpConfig;
18pub use shell::ShellConfig;
19pub use workflow::WorkflowStepConfig;
20
21use ironflow_store::entities::StepKind;
22use serde::{Deserialize, Serialize};
23
24/// A serializable step configuration, wrapping one of the operation-specific configs.
25///
26/// Stored as JSON in the `steps.input` column and reconstructed by the
27/// executor at runtime.
28///
29/// # Examples
30///
31/// ```
32/// use ironflow_engine::config::{StepConfig, ShellConfig};
33///
34/// let config = StepConfig::Shell(ShellConfig::new("echo hello"));
35/// let json = serde_json::to_string(&config).unwrap();
36/// assert!(json.contains("echo hello"));
37/// ```
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(tag = "type", rename_all = "snake_case")]
40pub enum StepConfig {
41    /// A shell command step.
42    Shell(ShellConfig),
43    /// An HTTP request step.
44    Http(HttpConfig),
45    /// An AI agent step.
46    Agent(AgentStepConfig),
47    /// A sub-workflow invocation step.
48    Workflow(WorkflowStepConfig),
49    /// A human approval gate step.
50    Approval(ApprovalConfig),
51}
52
53impl StepConfig {
54    /// Get the kind of step this configuration represents.
55    ///
56    /// # Examples
57    ///
58    /// ```
59    /// use ironflow_engine::config::{StepConfig, ShellConfig};
60    /// use ironflow_store::entities::StepKind;
61    ///
62    /// let config = StepConfig::Shell(ShellConfig::new("echo test"));
63    /// assert_eq!(config.kind(), StepKind::Shell);
64    /// ```
65    pub fn kind(&self) -> StepKind {
66        match self {
67            StepConfig::Shell(_) => StepKind::Shell,
68            StepConfig::Http(_) => StepKind::Http,
69            StepConfig::Agent(_) => StepKind::Agent,
70            StepConfig::Workflow(_) => StepKind::Workflow,
71            StepConfig::Approval(_) => StepKind::Approval,
72        }
73    }
74}
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn serde_roundtrip() {
82        let configs = vec![
83            StepConfig::Shell(ShellConfig::new("echo test")),
84            StepConfig::Http(HttpConfig::get("http://example.com")),
85            StepConfig::Agent(AgentStepConfig::new("summarize")),
86            StepConfig::Workflow(WorkflowStepConfig::new("build", serde_json::json!({}))),
87            StepConfig::Approval(ApprovalConfig::new("Deploy to production?")),
88        ];
89
90        for config in configs {
91            let json = serde_json::to_string(&config).expect("serialize");
92            let back: StepConfig = serde_json::from_str(&json).expect("deserialize");
93            let json2 = serde_json::to_string(&back).expect("serialize2");
94            assert_eq!(json, json2);
95        }
96    }
97}