flowbuilder_yaml/
config.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4/// 完整的工作流配置结构
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct WorkflowConfig {
7    pub workflow: Workflow,
8}
9
10/// 工作流定义
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Workflow {
13    pub version: String,
14    #[serde(default)]
15    pub env: HashMap<String, String>,
16    #[serde(default)]
17    pub vars: HashMap<String, serde_yaml::Value>,
18    #[serde(default)]
19    pub template: Option<Template>,
20    pub tasks: Vec<Task>,
21}
22
23/// 模板定义
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Template {
26    pub id: String,
27    pub name: String,
28    pub version: String,
29    pub description: String,
30}
31
32/// 任务定义
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct Task {
35    pub task: TaskDefinition,
36}
37
38/// 任务定义详情
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct TaskDefinition {
41    pub id: String,
42    pub name: String,
43    pub description: String,
44    #[serde(default)]
45    pub actions: Vec<Action>,
46}
47
48/// 动作定义
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct Action {
51    pub action: ActionDefinition,
52}
53
54/// 动作定义详情
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct ActionDefinition {
57    pub id: String,
58    pub name: String,
59    pub description: String,
60    #[serde(default)]
61    pub flow: FlowControl,
62    #[serde(default)]
63    pub outputs: HashMap<String, serde_yaml::Value>,
64    #[serde(rename = "type")]
65    pub action_type: ActionType,
66    #[serde(default)]
67    pub parameters: HashMap<String, Parameter>,
68}
69
70/// 流程控制
71#[derive(Debug, Clone, Serialize, Deserialize, Default)]
72pub struct FlowControl {
73    #[serde(default)]
74    pub next: Option<String>,
75    #[serde(default)]
76    pub next_if: Option<String>,
77    #[serde(default)]
78    pub while_util: Option<WhileUtil>,
79    #[serde(default)]
80    pub retry: Option<RetryConfig>,
81    #[serde(default)]
82    pub timeout: Option<TimeoutConfig>,
83    #[serde(default)]
84    pub on_error: Option<String>,
85    #[serde(default)]
86    pub on_timeout: Option<String>,
87}
88
89/// 循环控制
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct WhileUtil {
92    pub condition: String,
93    pub max_iterations: u32,
94}
95
96/// 重试配置
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct RetryConfig {
99    pub max_retries: u32,
100    pub delay: u64, // milliseconds
101}
102
103/// 超时配置
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct TimeoutConfig {
106    pub duration: u64, // milliseconds
107}
108
109/// 动作类型
110#[derive(Debug, Clone, Serialize, Deserialize, Default)]
111#[serde(rename_all = "lowercase")]
112pub enum ActionType {
113    Cmd,
114    Http,
115    #[default]
116    Builtin,
117    Wasm,
118}
119
120/// 参数定义
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct Parameter {
123    pub value: serde_yaml::Value,
124    #[serde(default)]
125    pub required: bool,
126}