1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! # phlow - A Dynamic Rule-Based Workflow Engine
//!
//! `phlow` is a **flexible and extensible** rule-based workflow engine written in Rust.
//! It allows users to define and execute **dynamic decision trees** and **conditional workflows**
//! using JSON-based configurations and embedded scripting via [`Rhai`](https://rhai.rs).
//!
//! ## Features
//! - **Dynamic workflows** with JSON-defined rules
//! - **Embedded scripting** with Rhai for advanced expressions
//! - **Conditional branching** with assert expressions
//! - **Step-based execution** with context-aware evaluation
//! - **Extensible engine** with pluggable functions
//!
//! ## Example: Decision Tree for Club Membership Approval
//!
//! This example demonstrates a **decision tree** to determine if a person can become a club member.
//!
//! ```rust
//! use phlow_engine::{Phlow, Context};
//! use phs::build_engine;
//! use valu3::prelude::*;
//! use valu3::json;
//! use std::sync::Arc;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let decision_tree = json!({
//! "steps": [
//! {
//! "assert": "{{ main.age >= 18 }}",
//! "then": {
//! "steps": [
//! {
//! "assert": "{{ main.income >= 5000.0 }}",
//! "then": {
//! "return": "Approved"
//! },
//! "else": {
//! "return": "Rejected - Insufficient income"
//! }
//! }
//! ]
//! },
//! "else": {
//! "return": "Rejected - Underage"
//! }
//! }
//! ]
//! });
//!
//! let phlow = Phlow::try_from_value(&decision_tree, None)?;
//! let mut context = Context::from_main(json!({ "age": 20, "income": 6000.0 }));
//! let result = phlow.execute(&mut context).await?;
//!
//! println!("Decision: {:?}", result);
//! # Ok(())
//! # }
//! ```
//!
//! ## Modules
//!
//! - [`phlow`] - Main structure containing pipelines and execution logic.
//! - [`context`] - Manages execution state and variable storage.
//! - [`pipeline`] - Defines sequential execution of processing steps.
//! - [`step_worker`] - Handles conditional logic and step execution.
//! - [`script`] - Integrates Rhai scripting for dynamic evaluation.
//! - [`engine`] - Configures and extends the scripting engine.
//! - [`condition`] - Evaluates assert expressions for branching.
//! - [`collector`] - Logs execution steps and tracks workflow state.
//!
//! ## Architecture Overview
//!
//! The `phlow` engine processes a **workflow pipeline** composed of steps. Each step can:
//! - Evaluate **conditions** (e.g., comparisons, regex matching)
//! - Execute **scripts** for computations
//! - **Branch** execution based on conditions
//! - Store and reference **previous step outputs**
//!
//! ### Execution Flow
//! 1. The engine receives an input **JSON workflow definition**.
//! 2. The `phlow` instance **parses** and **validates** the workflow.
//! 3. The workflow **executes step-by-step**, evaluating conditions and executing actions.
//! 4. The **final result** is returned to the caller.
//!
//! ## Advanced Usage
//!
//! ### Adding Custom Plugins
//!
//! Users can **extend phlow** by adding custom functions to the execution engine.
//! The phlow engine supports extending functionality through custom Rhai functions
//! and repositories that can be injected into the scripting environment.
//!
//! For detailed examples of extending the engine, see the `phs` module documentation
//! and the `build_engine` function.
//!
//! ### Handling Execution Errors
//!
//! Errors during workflow execution are returned as `Result<T, PhlowError>`:
//!
//! ```rust
//! use phlow_engine::{Phlow, Context};
//! use valu3::prelude::*;
//! use valu3::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let workflow = json!({
//! "steps": [
//! {
//! "return": "Success"
//! }
//! ]
//! });
//!
//! let phlow = Phlow::try_from_value(&workflow, None)?;
//! let mut context = Context::from_main(json!({"key": "value"}));
//!
//! match phlow.execute(&mut context).await {
//! Ok(result) => println!("Execution succeeded: {:?}", result),
//! Err(err) => eprintln!("Execution failed: {:?}", err),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## License
//!
//! This project is licensed under the **MIT License**.
pub use phs;
pub use Context;
pub use ;
pub use ;