1use std::collections::HashMap;
2
3use serde::Deserialize;
4
5#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
7#[serde(rename_all = "snake_case")]
8pub enum OutputType {
9 #[default]
10 Text,
11 Json,
12 Integer,
13 Lines,
14 Boolean,
15}
16
17#[derive(Debug, Clone, Deserialize)]
19pub struct WorkflowDef {
20 pub name: String,
21 #[serde(default)]
22 pub version: u32,
23 pub description: Option<String>,
24 #[serde(default)]
25 pub config: WorkflowConfig,
26 pub prompts_dir: Option<String>,
27 #[serde(default)]
28 pub scopes: HashMap<String, ScopeDef>,
29 pub steps: Vec<StepDef>,
30}
31
32#[derive(Debug, Clone, Default, Deserialize)]
34pub struct WorkflowConfig {
35 #[serde(default)]
36 pub global: HashMap<String, serde_yaml::Value>,
37 #[serde(default)]
38 pub agent: HashMap<String, serde_yaml::Value>,
39 #[serde(default)]
40 pub cmd: HashMap<String, serde_yaml::Value>,
41 #[serde(default)]
42 pub chat: HashMap<String, serde_yaml::Value>,
43 #[serde(default)]
44 pub gate: HashMap<String, serde_yaml::Value>,
45 #[serde(default)]
46 pub patterns: HashMap<String, HashMap<String, serde_yaml::Value>>,
47 #[serde(default)]
49 pub plugins: Vec<PluginDef>,
50 pub events: Option<EventsConfig>,
52}
53
54#[derive(Debug, Clone, Default, Deserialize)]
56pub struct PluginDef {
57 pub name: String,
59 pub path: String,
61}
62
63#[derive(Debug, Clone, Default, Deserialize)]
65pub struct EventsConfig {
66 pub webhook: Option<String>,
68 pub file: Option<String>,
70}
71
72#[derive(Debug, Clone, Deserialize)]
74pub struct ScopeDef {
75 pub steps: Vec<StepDef>,
76 pub outputs: Option<String>,
77}
78
79#[derive(Debug, Clone, Deserialize)]
81pub struct StepDef {
82 pub name: String,
83 #[serde(rename = "type")]
84 pub step_type: StepType,
85
86 pub run: Option<String>,
88
89 pub prompt: Option<String>,
91
92 pub condition: Option<String>,
94 pub on_pass: Option<String>,
95 pub on_fail: Option<String>,
96 pub message: Option<String>,
97
98 pub scope: Option<String>,
100 pub max_iterations: Option<usize>,
101 pub initial_value: Option<serde_yaml::Value>,
102
103 pub items: Option<String>,
105 pub parallel: Option<usize>,
106
107 pub steps: Option<Vec<StepDef>>,
109
110 #[serde(default)]
112 pub config: HashMap<String, serde_yaml::Value>,
113
114 pub outputs: Option<String>,
116
117 pub output_type: Option<OutputType>,
119
120 #[serde(default)]
122 pub async_exec: Option<bool>,
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
129#[serde(rename_all = "snake_case")]
130pub enum StepType {
131 Cmd,
133 Agent,
135 Chat,
137 Gate,
139 Repeat,
141 Map,
143 Parallel,
145 Call,
147 Template,
149 Script,
151}
152
153impl std::fmt::Display for StepType {
154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
155 match self {
156 StepType::Cmd => write!(f, "cmd"),
157 StepType::Agent => write!(f, "agent"),
158 StepType::Chat => write!(f, "chat"),
159 StepType::Gate => write!(f, "gate"),
160 StepType::Repeat => write!(f, "repeat"),
161 StepType::Map => write!(f, "map"),
162 StepType::Parallel => write!(f, "parallel"),
163 StepType::Call => write!(f, "call"),
164 StepType::Template => write!(f, "template"),
165 StepType::Script => write!(f, "script"),
166 }
167 }
168}