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 #[cfg_attr(feature = "openapi", schema(value_type = Option<serde_json::Value>))]
65 pub debug_messages: Option<Value>,
66}
67
68impl StepResponse {
69 pub fn with_dependencies(step: Step, dependencies: Vec<Uuid>) -> Self {
71 StepResponse {
72 id: step.id,
73 run_id: step.run_id,
74 name: step.name,
75 kind: step.kind,
76 position: step.position,
77 status: step.status.state,
78 input: step.input,
79 output: step.output,
80 error: step.error,
81 duration_ms: step.duration_ms,
82 cost_usd: step.cost_usd,
83 input_tokens: step.input_tokens,
84 output_tokens: step.output_tokens,
85 created_at: step.created_at,
86 updated_at: step.updated_at,
87 started_at: step.started_at,
88 completed_at: step.completed_at,
89 dependencies,
90 debug_messages: step.debug_messages,
91 }
92 }
93}
94
95impl From<Step> for StepResponse {
96 fn from(step: Step) -> Self {
97 Self::with_dependencies(step, Vec::new())
98 }
99}