新增: 初始化 DevFlow 项目仓库

Tauri 2 + Vue 3 + Vite 6 桌面应用,Rust workspace 含 13 个 crate
(df-ai / df-storage / df-workflow / df-core / df-execute 等)。
核心能力:AI 聊天 agentic 循环(工具调用+人工审批)、工作流引擎、
任务/想法/项目/阶段管理、可追溯性,及配套前端组件。
This commit is contained in:
2026-06-12 01:31:05 +08:00
commit 98393b4908
178 changed files with 27859 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
//! DAG 定义 — 可序列化/反序列化,用于持久化和模板
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::dag::Dag;
/// 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()),
});
}
/// 从已有的运行时 Dag 提取定义(忽略节点实例,仅保留元数据)
///
/// 注意:此方法只能提取边的定义,节点配置无法从 trait object 反推
pub fn from_dag_edges(dag: &Dag) -> Self {
let edges: Vec<EdgeDef> = dag.edges.iter().map(|e| EdgeDef {
source: e.source.clone(),
target: e.target.clone(),
condition: e.condition.clone(),
}).collect();
let nodes: HashMap<String, NodeDef> = dag.nodes.iter().map(|(id, node)| {
(id.clone(), NodeDef {
id: id.clone(),
node_type: node.node_type().to_string(),
config: serde_json::Value::Null,
label: None,
})
}).collect();
Self { nodes, edges }
}
}
impl Default for DagDef {
fn default() -> Self {
Self::new()
}
}