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
76impl From<ShellConfig> for StepConfig {
77    fn from(c: ShellConfig) -> Self {
78        StepConfig::Shell(c)
79    }
80}
81
82impl From<HttpConfig> for StepConfig {
83    fn from(c: HttpConfig) -> Self {
84        StepConfig::Http(c)
85    }
86}
87
88impl From<AgentStepConfig> for StepConfig {
89    fn from(c: AgentStepConfig) -> Self {
90        StepConfig::Agent(c)
91    }
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97
98    #[test]
99    fn serde_roundtrip() {
100        let configs = vec![
101            StepConfig::Shell(ShellConfig::new("echo test")),
102            StepConfig::Http(HttpConfig::get("http://example.com")),
103            StepConfig::Agent(AgentStepConfig::new("summarize")),
104            StepConfig::Workflow(WorkflowStepConfig::new("build", serde_json::json!({}))),
105            StepConfig::Approval(ApprovalConfig::new("Deploy to production?")),
106        ];
107
108        for config in configs {
109            let json = serde_json::to_string(&config).expect("serialize");
110            let back: StepConfig = serde_json::from_str(&json).expect("deserialize");
111            let json2 = serde_json::to_string(&back).expect("serialize2");
112            assert_eq!(json, json2);
113        }
114    }
115}