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 metrics;
15pub mod security;
16
17pub use auth::{check_auth, AuthResult};
18pub use config::{
19    AccessConfig, AgentEntry, AgentsConfig, ApiKeyConfig, BrainConfig, DeliveryConfig, LlmConfig,
20    ProviderEntry,
21};
22pub use security::ActionTier;
23
24/// Standard timeout constants for HTTP clients across Brain OS.
25pub mod timeouts {
26    use std::time::Duration;
27
28    pub const EMBEDDING_OLLAMA: Duration = Duration::from_secs(120);
29    pub const EMBEDDING_OPENAI: Duration = Duration::from_secs(60);
30    /// 90s caps chat-style requests so a flaky upstream LLM can't pin
31    /// the inbound pipeline (Telegram/HTTP) indefinitely. Long-running
32    /// orchestration steps that legitimately need more time should run
33    /// the LLM call themselves with a wider per-request timeout.
34    pub const LLM_GENERATE: Duration = Duration::from_secs(90);
35    pub const HEALTH_CHECK: Duration = Duration::from_secs(2);
36    pub const DAEMON_SETUP: Duration = Duration::from_secs(30);
37    pub const STATUS_CHECK: Duration = Duration::from_secs(2);
38}
39
40/// Normalize a keyword for matching: trim non-alphanumeric edges, lowercase.
41pub fn normalize_keyword(word: &str) -> String {
42    word.trim_matches(|c: char| !c.is_alphanumeric())
43        .to_lowercase()
44}