ironflow_api/entities/
step.rs1use 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#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
19#[derive(Debug, Serialize, Deserialize)]
20pub struct StepResponse {
21 pub id: Uuid,
23 pub run_id: Uuid,
25 pub name: String,
27 #[cfg_attr(feature = "openapi", schema(value_type = String))]
29 pub kind: StepKind,
30 pub position: u32,
32 pub status: StepStatus,
34 #[cfg_attr(feature = "openapi", schema(value_type = Option<std::collections::HashMap<String, serde_json::Value>>))]
36 pub input: Option<Value>,
37 #[cfg_attr(feature = "openapi", schema(value_type = Option<std::collections::HashMap<String, serde_json::Value>>))]
39 pub output: Option<Value>,
40 pub error: Option<String>,
42 pub duration_ms: u64,
44 #[cfg_attr(feature = "openapi", schema(value_type = f64))]
46 pub cost_usd: Decimal,
47 pub input_tokens: Option<u64>,
49 pub output_tokens: Option<u64>,
51 pub created_at: DateTime<Utc>,
53 pub updated_at: DateTime<Utc>,
55 pub started_at: Option<DateTime<Utc>>,
57 pub completed_at: Option<DateTime<Utc>>,
59 pub dependencies: Vec<Uuid>,
61}
62
63impl StepResponse {
64 pub fn with_dependencies(step: Step, dependencies: Vec<Uuid>) -> Self {
66 StepResponse {
67 id: step.id,
68 run_id: step.run_id,
69 name: step.name,
70 kind: step.kind,
71 position: step.position,
72 status: step.status.state,
73 input: step.input,
74 output: step.output,
75 error: step.error,
76 duration_ms: step.duration_ms,
77 cost_usd: step.cost_usd,
78 input_tokens: step.input_tokens,
79 output_tokens: step.output_tokens,
80 created_at: step.created_at,
81 updated_at: step.updated_at,
82 started_at: step.started_at,
83 completed_at: step.completed_at,
84 dependencies,
85 }
86 }
87}
88
89impl From<Step> for StepResponse {
90 fn from(step: Step) -> Self {
91 Self::with_dependencies(step, Vec::new())
92 }
93}