universal_bot_core/
lib.rs

1//! Universal Bot Core - Enterprise AI Automation Framework
2//!
3//! This crate provides the core functionality for the Universal Bot framework,
4//! including message pipelines, context management, and plugin architecture.
5//!
6//! # Example
7//!
8//! ```rust
9//! use universal_bot_core::{Bot, BotConfig, Message};
10//!
11//! # async fn example() -> anyhow::Result<()> {
12//! let config = BotConfig::builder()
13//!     .model("anthropic.claude-opus-4-1")
14//!     .temperature(0.1)
15//!     .build()?;
16//!
17//! let bot = Bot::new(config).await?;
18//! let response = bot.process(Message::text("Hello")).await?;
19//! println!("{}", response.content);
20//! # Ok(())
21//! # }
22//! ```
23
24#![deny(missing_docs, rust_2018_idioms, clippy::all)]
25#![warn(clippy::pedantic, clippy::nursery)]
26#![allow(
27    clippy::module_name_repetitions,
28    clippy::must_use_candidate,
29    clippy::missing_const_for_fn,
30    clippy::missing_errors_doc,
31    clippy::struct_excessive_bools,
32    clippy::cast_precision_loss,
33    clippy::unnecessary_literal_bound,
34    clippy::significant_drop_in_scrutinee
35)]
36
37pub mod bot;
38pub mod config;
39pub mod context;
40pub mod error;
41pub mod message;
42pub mod pipeline;
43pub mod plugin;
44
45// Re-exports
46pub use bot::{Bot, BotBuilder};
47pub use config::{BotConfig, BotConfigBuilder};
48pub use context::{Context, ContextManager, ContextStore};
49pub use error::{Error, Result};
50pub use message::{Message, MessageType, Response};
51pub use pipeline::{MessagePipeline, PipelineStage};
52pub use plugin::{Plugin, PluginRegistry};
53
54/// Library version
55pub const VERSION: &str = env!("CARGO_PKG_VERSION");
56
57/// Initialize the library with default settings
58///
59/// This function sets up logging, tracing, and other global configurations.
60///
61/// # Errors
62///
63/// Returns an error if initialization fails.
64///
65/// # Example
66///
67/// ```rust
68/// # fn main() -> anyhow::Result<()> {
69/// universal_bot_core::init()?;
70/// # Ok(())
71/// # }
72/// ```
73pub fn init() -> Result<()> {
74    use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
75
76    tracing_subscriber::registry()
77        .with(
78            tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
79        )
80        .with(tracing_subscriber::fmt::layer())
81        .try_init()
82        .map_err(|e| Error::Initialization(e.to_string()))?;
83
84    tracing::info!("Universal Bot Core v{} initialized", VERSION);
85    Ok(())
86}
87
88#[cfg(test)]
89mod tests {
90    use super::*;
91
92    #[test]
93    fn test_version() {
94        assert_eq!(VERSION, "1.0.0");
95        assert!(VERSION.contains('.'));
96    }
97
98    #[test]
99    fn test_init() {
100        // Initialize should work multiple times without error
101        let _ = init();
102        let _ = init();
103    }
104}