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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! # botcore
//!
//! A flexible and efficient bot engine framework for building event-driven bots in Rust.
//!
//! ## Overview
//!
//! `botcore` is a high-performance, type-safe framework for building event-driven bots in Rust.
//! It provides a modular architecture that makes it easy to create, test, and maintain bot
//! applications that can react to various events in real-time.
//!
//! ## Features
//!
//! - 🚀 **High Performance**
//! - Built on top of Tokio for maximum concurrency
//! - Efficient event processing pipeline
//! - Configurable channel capacities for backpressure control
//!
//! - 🔧 **Modular Architecture**
//! - Plug-and-play components
//! - Easy to extend and customize
//! - Clear separation of concerns
//!
//! - 📊 **Observability**
//! - Built-in Prometheus metrics
//! - Performance monitoring
//! - Error tracking and reporting
//!
//! ## Architecture
//!
//! The framework is built around three main traits:
//!
//! - [`Collector`](types::Collector): Sources that produce events
//! - [`Strategy`](types::Strategy): Components that process events and decide on actions
//! - [`Executor`](types::Executor): Components that execute actions
//!
//! These components are orchestrated by the [`Engine`], which manages
//! the flow of events and actions through the system.
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use botcore::{Engine, Result};
//! use botcore::types::{Collector, CollectorStream, Strategy, Executor};
//! use async_trait::async_trait;
//! use tokio_stream;
//!
//! # #[derive(Debug, Clone)]
//! # struct MyEvent;
//! # #[derive(Debug, Clone)]
//! # struct MyAction;
//! # struct MyCollector;
//! # #[async_trait]
//! # impl Collector<MyEvent> for MyCollector {
//! # async fn get_event_stream(&self) -> Result<CollectorStream<'_, MyEvent>> {
//! # let events = Vec::<MyEvent>::new();
//! # Ok(Box::pin(tokio_stream::iter(events)))
//! # }
//! # }
//! # struct MyStrategy;
//! # #[async_trait]
//! # impl Strategy<MyEvent, MyAction> for MyStrategy {
//! # async fn sync_state(&mut self) -> Result<()> {
//! # Ok(())
//! # }
//! # async fn process_event(&mut self, _event: MyEvent) -> Vec<MyAction> {
//! # vec![]
//! # }
//! # }
//! # struct MyExecutor;
//! # #[async_trait]
//! # impl Executor<MyAction> for MyExecutor {
//! # async fn execute(&self, _action: MyAction) -> Result<()> {
//! # Ok(())
//! # }
//! # }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! // Create a new engine with custom channel capacities
//! let mut engine = Engine::<MyEvent, MyAction>::new()
//! .with_event_channel_capacity(1024)
//! .with_action_channel_capacity(1024);
//!
//! // Add components
//! engine.add_collector(Box::new(MyCollector));
//! engine.add_strategy(Box::new(MyStrategy));
//! engine.add_executor(Box::new(MyExecutor));
//!
//! // Run the engine
//! let mut join_set = engine.run().await?;
//!
//! // Wait for all tasks to complete
//! while join_set.join_next().await.is_some() {}
//! Ok(())
//! }
//! ```
//!
//! ## Modules
//!
//! - [`engine`]: Core engine implementation that orchestrates event flow
//! - [`types`]: Core traits and types for building bots
//! - [`error`]: Error types and handling
//! - [`metrics`]: Prometheus metrics for monitoring
//!
//! ## Error Handling
//!
//! The crate uses a custom [`Result`] type that wraps [`BotError`]
//! for comprehensive error handling. All errors are categorized and include context
//! for easier debugging.
//!
//! ## Metrics
//!
//! The engine automatically collects Prometheus metrics for:
//!
//! - Event processing latency
//! - Action execution latency
//! - Queue sizes
//! - Error counts
//! - Total events processed
//! - Total actions executed
//!
//! ## Best Practices
//!
//! 1. **Event Design**
//! - Keep events small and focused
//! - Include necessary context
//! - Use appropriate serialization
//!
//! 2. **Strategy Implementation**
//! - Handle state carefully
//! - Implement proper error handling
//! - Keep processing logic modular
//!
//! 3. **Execution**
//! - Implement retries for transient failures
//! - Handle rate limiting
//! - Log important state changes
use criterion as _;
use futures as _;
/// Core engine implementation that orchestrates event flow.
///
/// This module provides the [`Engine`] type which is responsible for:
/// - Managing the lifecycle of collectors, strategies, and executors
/// - Coordinating the flow of events from collectors to strategies
/// - Coordinating the flow of actions from strategies to executors
/// - Handling errors and metrics collection
/// Error types and handling.
///
/// This module provides:
/// - [`BotError`]: The main error type
/// - [`Result`]: A type alias for `Result<T, BotError>`
/// - Various error creation and handling utilities
/// Prometheus metrics for monitoring.
///
/// This module provides metrics collection for:
/// - Event processing latency
/// - Action execution latency
/// - Queue sizes
/// - Error counts
/// - Total events processed
/// - Total actions executed
/// Core traits and types.
///
/// This module provides the core traits:
/// - [`Collector`](types::Collector): Sources that produce events
/// - [`Strategy`](types::Strategy): Components that process events
/// - [`Executor`](types::Executor): Components that execute actions
pub use Engine;
pub use ;