Skip to main content

brainos_core/
lib.rs

1//! # Brain Core
2//!
3//! Orchestrator that wires all brain subsystems together.
4//!
5//! Provides:
6//! - Configuration management (figment + YAML)
7//! - Subsystem initialization and dependency injection
8//! - Message pipeline: Thalamus → Hippocampus → Cortex → Response
9//! - Error handling and graceful degradation
10
11pub mod auth;
12pub mod config;
13pub mod cors;
14pub mod security;
15
16pub use auth::{check_auth, AuthResult};
17pub use config::{
18    AccessConfig, AgentEntry, AgentsConfig, ApiKeyConfig, BrainConfig, ClientRateLimitConfig,
19    DeliveryConfig, LlmConfig, LogFormat, LogRotation, LoggingConfig, ProviderEntry,
20};
21pub use security::ActionTier;
22
23/// Standard timeout constants for HTTP clients across Brain OS.
24pub mod timeouts {
25    use std::time::Duration;
26
27    pub const EMBEDDING_OLLAMA: Duration = Duration::from_secs(120);
28    pub const EMBEDDING_OPENAI: Duration = Duration::from_secs(60);
29    /// 90s caps chat-style requests so a flaky upstream LLM can't pin
30    /// the inbound pipeline (Telegram/HTTP) indefinitely. Long-running
31    /// orchestration steps that legitimately need more time should run
32    /// the LLM call themselves with a wider per-request timeout.
33    pub const LLM_GENERATE: Duration = Duration::from_secs(90);
34    pub const HEALTH_CHECK: Duration = Duration::from_secs(2);
35    pub const DAEMON_SETUP: Duration = Duration::from_secs(30);
36    pub const STATUS_CHECK: Duration = Duration::from_secs(2);
37}
38
39/// Normalize a keyword for matching: trim non-alphanumeric edges, lowercase.
40pub fn normalize_keyword(word: &str) -> String {
41    word.trim_matches(|c: char| !c.is_alphanumeric())
42        .to_lowercase()
43}