Skip to main content

ironflow_api/entities/
step.rs

1//! Step-related DTOs.
2
3use chrono::{DateTime, Utc};
4use ironflow_store::models::{Step, StepKind, StepStatus};
5use rust_decimal::Decimal;
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8use uuid::Uuid;
9
10/// Step response DTO — public API representation of a step.
11///
12/// # Examples
13///
14/// ```
15/// use ironflow_store::models::Step;
16/// use ironflow_api::entities::StepResponse;
17/// ```
18#[derive(Debug, Serialize, Deserialize)]
19pub struct StepResponse {
20    /// Unique step identifier.
21    pub id: Uuid,
22    /// Parent run ID.
23    pub run_id: Uuid,
24    /// Step name.
25    pub name: String,
26    /// Step operation type.
27    pub kind: StepKind,
28    /// Execution order (0-based).
29    pub position: u32,
30    /// Current status.
31    pub status: StepStatus,
32    /// Input configuration.
33    pub input: Option<Value>,
34    /// Step output.
35    pub output: Option<Value>,
36    /// Optional error message.
37    pub error: Option<String>,
38    /// Execution duration in milliseconds.
39    pub duration_ms: u64,
40    /// Cost in USD.
41    pub cost_usd: Decimal,
42    /// Input token count (agent steps).
43    pub input_tokens: Option<u64>,
44    /// Output token count (agent steps).
45    pub output_tokens: Option<u64>,
46    /// When created.
47    pub created_at: DateTime<Utc>,
48    /// When updated.
49    pub updated_at: DateTime<Utc>,
50    /// When execution started.
51    pub started_at: Option<DateTime<Utc>>,
52    /// When execution completed.
53    pub completed_at: Option<DateTime<Utc>>,
54    /// IDs of steps this step depends on (direct dependencies).
55    pub dependencies: Vec<Uuid>,
56}
57
58impl StepResponse {
59    /// Build a response from a step entity with pre-resolved dependencies.
60    pub fn with_dependencies(step: Step, dependencies: Vec<Uuid>) -> Self {
61        StepResponse {
62            id: step.id,
63            run_id: step.run_id,
64            name: step.name,
65            kind: step.kind,
66            position: step.position,
67            status: step.status.state,
68            input: step.input,
69            output: step.output,
70            error: step.error,
71            duration_ms: step.duration_ms,
72            cost_usd: step.cost_usd,
73            input_tokens: step.input_tokens,
74            output_tokens: step.output_tokens,
75            created_at: step.created_at,
76            updated_at: step.updated_at,
77            started_at: step.started_at,
78            completed_at: step.completed_at,
79            dependencies,
80        }
81    }
82}
83
84impl From<Step> for StepResponse {
85    fn from(step: Step) -> Self {
86        Self::with_dependencies(step, Vec::new())
87    }
88}