1#![forbid(unsafe_code)]
5#![allow(missing_docs)]
6#![doc = "SZ-Rust 工作流引擎 — 状态机/审批流/插件节点编排"]
7pub mod api;
23pub mod config;
24pub mod definition;
25pub mod deps;
26pub mod engine;
27pub mod error;
28pub mod guard;
29pub mod instance;
30pub mod integration;
31pub mod observability;
32pub mod repository;
33pub mod scheduling;
34
35pub use config::WorkflowConfig;
36pub use definition::{
37 ApprovalStrategyType, CandidateStrategy, DefinitionFormat, DefinitionParser,
38 DefinitionValidator, FaultStrategy, FlowDefinition, IssueSeverity, NodeConfig, NodeType,
39 StateMachineDefinition, Transition, ValidationIssue,
40};
41pub use deps::{WorkflowDeps, WorkflowDepsBuilder};
42pub use engine::WorkflowEngine;
43pub use error::{WorkflowError, WorkflowErrorCode, WorkflowResult};
44pub use instance::{
45 FlowInstance, HistoryEntry, InstanceStatus, PageRequest, PageResult, Task, TaskAction,
46 TaskStatus,
47};
48
49use axum::response::Json;
54use serde_json::json;
55use sz_rust_core::router::RouterBuilder;
56
57#[derive(Clone)]
59pub struct WorkflowState {
60 pub version: &'static str,
61}
62
63impl Default for WorkflowState {
64 fn default() -> Self {
65 Self {
66 version: env!("CARGO_PKG_VERSION"),
67 }
68 }
69}
70
71fn create_engine() -> WorkflowEngine {
72 let config = WorkflowConfig::default();
73 let deps = WorkflowDeps::default_for_test();
74 WorkflowEngine::new(config, deps)
75}
76
77pub fn register_routes<S>(builder: RouterBuilder<S>, state: WorkflowState) -> RouterBuilder<S>
79where
80 S: Clone + Send + Sync + 'static,
81{
82 let builder = builder.get("/api/workflow/health", {
83 let v = state.version;
84 move || async move {
85 let _engine = create_engine();
86 Json(json!({
87 "code": 1,
88 "msg": "success",
89 "data": {
90 "plugin": "workflow",
91 "status": "active",
92 "engine": "WorkflowEngine",
93 "version": v
94 }
95 }))
96 }
97 });
98
99 let builder = builder.get("/api/workflow/definitions", {
100 move || async move {
101 Json(json!({
102 "code": 1,
103 "msg": "success",
104 "data": {
105 "definitions": [],
106 "total": 0
107 }
108 }))
109 }
110 });
111
112 let builder = builder.get("/api/workflow/instances", {
113 move || async move {
114 let engine = create_engine();
115 let page = PageRequest::default();
116 let pending_tasks = engine
117 .query_tasks("", page)
118 .await
119 .map(|r| r.total)
120 .unwrap_or(0);
121 Json(json!({
122 "code": 1,
123 "msg": "success",
124 "data": {
125 "instances": [],
126 "total": 0,
127 "pending_tasks": pending_tasks
128 }
129 }))
130 }
131 });
132
133 builder
134}
135
136pub mod capability;
137pub use capability::WorkflowPlugin;