新增: 初始化 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,68 @@
//! 事件总线 — 基于 tokio::sync::broadcast 的发布/订阅
use tokio::sync::broadcast;
use tokio::sync::broadcast::error::SendError;
use df_core::events::{WorkflowEvent, HumanApprovalResponse};
/// 事件总线
#[derive(Debug)]
pub struct EventBus {
sender: broadcast::Sender<WorkflowEvent>,
}
/// 事件订阅者
pub type EventSubscriber = broadcast::Receiver<WorkflowEvent>;
/// 默认事件通道容量
const DEFAULT_CAPACITY: usize = 256;
impl EventBus {
/// 创建事件总线
pub fn new() -> Self {
let (sender, _) = broadcast::channel(DEFAULT_CAPACITY);
Self { sender }
}
/// 创建指定容量的事件总线
pub fn with_capacity(capacity: usize) -> Self {
let (sender, _) = broadcast::channel(capacity);
Self { sender }
}
/// 发送事件
pub async fn send(&self, event: WorkflowEvent) {
// broadcast::send 是同步的,忽略接收者已关闭的错误
let _ = self.sender.send(event);
}
/// 订阅事件
pub fn subscribe(&self) -> EventSubscriber {
self.sender.subscribe()
}
/// 发送人工审批请求
pub fn emit_human_approval_request(&self, event: WorkflowEvent) -> Result<usize, SendError<WorkflowEvent>> {
self.sender.send(event)
}
/// 尝试获取人工审批响应(简化版本,实际需要实现状态存储)
pub fn try_recv_human_approval(&self, _execution_id: &str, _node_id: &str) -> Option<HumanApprovalResponse> {
// TODO: 实现审批响应的存储和检索
// 目前返回 None需要配合前端实现
None
}
}
impl Default for EventBus {
fn default() -> Self {
Self::new()
}
}
impl Clone for EventBus {
fn clone(&self) -> Self {
Self {
sender: self.sender.clone(),
}
}
}