Files
DevFlow/crates/df-workflow/src/dag_def.rs
绝尘 2de0c6ecb7 重构: 后端 df-ai/commands 拆分+df-nodes/workflow 改造+P0 bug 修复
- df-ai: context 历史中毒三档自愈 sanitize_messages(AC3)+anthropic_compat tool_use_id None 跳过(AC1/AC2)+删 router/stream 死码
- df-core: events 加 select_type+decisions 多选审批契约(F-260615-01)
- df-execute: shell run_command 工具复用(F-260615-05)
- df-nodes: human_node 多选校验+2 端到端测(F-01)+取消跳 set_failed(B-03b-R1/R2/R8)
- df-workflow: executor/dag/state cancel 闭环(B-06/07/03a/b)+provider approve options(R-PD-5)
- df-storage: find_path_conflict 抽公共(R-PD-11)+COLS 常量断言
- df-ideas: 删 IdeaPromoter/PromotionPolicy 死码(R-PD-14)
- src-tauri/commands/ai: secret keyring 迁移(FR-S1/R-PD-4)+GeneratingGuard RAII+disarm(B-09/26)+newConversation 软复位(B-10)+stream 心跳/stop select/空回复判错(B-02/04/05/15)+run_command(F-05)+mask audit(AR-3)
- src-tauri/commands/{project,task,workflow,mod,lib,state}: task detail IPC(F-02)+approve decisions+task list 联动(B-29)
- Cargo.lock+Cargo.toml 依赖同步
2026-06-15 05:14:42 +08:00

81 lines
2.0 KiB
Rust

//! DAG 定义 — 可序列化/反序列化,用于持久化和模板
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// DAG 定义 — 可序列化/反序列化,用于持久化和模板
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DagDef {
pub nodes: HashMap<String, NodeDef>,
pub edges: Vec<EdgeDef>,
}
/// 节点定义
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NodeDef {
pub id: String,
pub node_type: String,
pub config: serde_json::Value,
#[serde(default)]
pub label: Option<String>,
}
/// 边定义
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EdgeDef {
pub source: String,
pub target: String,
#[serde(default)]
pub condition: Option<String>,
}
impl DagDef {
/// 创建空的 DAG 定义
pub fn new() -> Self {
Self {
nodes: HashMap::new(),
edges: Vec::new(),
}
}
/// 添加节点定义
pub fn add_node(&mut self, id: impl Into<String>, node_type: impl Into<String>, config: serde_json::Value) {
let id = id.into();
self.nodes.insert(id.clone(), NodeDef {
id,
node_type: node_type.into(),
config,
label: None,
});
}
/// 添加边定义
pub fn add_edge(&mut self, source: impl Into<String>, target: impl Into<String>) {
self.edges.push(EdgeDef {
source: source.into(),
target: target.into(),
condition: None,
});
}
/// 添加带条件的边定义
pub fn add_edge_with_condition(
&mut self,
source: impl Into<String>,
target: impl Into<String>,
condition: impl Into<String>,
) {
self.edges.push(EdgeDef {
source: source.into(),
target: target.into(),
condition: Some(condition.into()),
});
}
}
impl Default for DagDef {
fn default() -> Self {
Self::new()
}
}