|
6 | 6 | //! - Python (via pyo3)
|
7 | 7 | //! - Regular expressions (via regex)
|
8 | 8 | //! - UUID generation (via uuid)
|
| 9 | +//! |
| 10 | +//! ## Core Types |
| 11 | +//! |
| 12 | +//! The foundation of the script execution system consists of four main types: |
| 13 | +//! |
| 14 | +//! - [`ScriptConfig`] - Configuration for script execution (timeouts, security settings) |
| 15 | +//! - [`ScriptContext`] - Runtime context passed to scripts (request/response data, metadata) |
| 16 | +//! - [`ScriptResult`] - Standardized result type for script execution outcomes |
| 17 | +//! - [`ScriptError`] - Comprehensive error handling for script execution failures |
| 18 | +//! |
| 19 | +//! ## Example Usage |
| 20 | +//! |
| 21 | +//! ```rust |
| 22 | +//! use mandrel_mcp_th::script_engines::{ScriptConfig, ScriptContext, ScriptResult, LogLevel}; |
| 23 | +//! use serde_json::json; |
| 24 | +//! |
| 25 | +//! // Create a secure configuration |
| 26 | +//! let config = ScriptConfig::new(); |
| 27 | +//! assert_eq!(config.timeout_ms, 5000); |
| 28 | +//! assert!(!config.allow_network); |
| 29 | +//! |
| 30 | +//! // Create a script context |
| 31 | +//! let context = ScriptContext::new( |
| 32 | +//! json!({"input": "test_data"}), |
| 33 | +//! "test_case".to_string(), |
| 34 | +//! "test_tool".to_string(), |
| 35 | +//! config, |
| 36 | +//! ); |
| 37 | +//! |
| 38 | +//! // Create a successful result |
| 39 | +//! let result = ScriptResult::success(json!({"output": "success"}), 150) |
| 40 | +//! .add_log(LogLevel::Info, "Script executed successfully".to_string()) |
| 41 | +//! .with_memory_usage(2.5); |
| 42 | +//! |
| 43 | +//! assert!(result.success); |
| 44 | +//! assert_eq!(result.duration_ms, 150); |
| 45 | +//! ``` |
9 | 46 |
|
10 | 47 | pub mod js_engine;
|
11 | 48 | pub mod lua_engine;
|
12 | 49 | pub mod python_engine;
|
| 50 | +pub mod types; |
13 | 51 | pub mod utilities;
|
14 | 52 |
|
| 53 | +// Re-export core types for easier access |
| 54 | +pub use types::{ |
| 55 | + ContextMetadata, LogEntry, LogLevel, ScriptConfig, ScriptContext, ScriptError, ScriptResult, |
| 56 | + ServerInfo, |
| 57 | +}; |
| 58 | + |
15 | 59 | #[cfg(test)]
|
16 | 60 | mod dependency_tests {
|
17 | 61 | use std::time::Instant;
|
|
0 commit comments