botserver/src/core/shared/state.rs
Rodrigo Rodriguez (Pragmatismo) 3add3ccbfa Fix typos in bot file extensions and keyword names
Changed incorrect references to .vbs files to .bas and corrected
USE_WEBSITE keyword naming. Also added missing fields to API response
structure and clarified that start.bas is optional for bots.
2025-11-26 22:54:22 -03:00

91 lines
3.3 KiB
Rust

use crate::core::bot::channels::{ChannelAdapter, VoiceAdapter, WebChannelAdapter};
use crate::core::config::AppConfig;
use crate::core::kb::KnowledgeBaseManager;
use crate::core::session::SessionManager;
#[cfg(feature = "directory")]
use crate::directory::AuthService;
#[cfg(feature = "llm")]
use crate::llm::LLMProvider;
use crate::shared::models::BotResponse;
use crate::shared::utils::DbPool;
#[cfg(feature = "drive")]
use aws_sdk_s3::Client as S3Client;
#[cfg(feature = "redis-cache")]
use redis::Client as RedisClient;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::mpsc;
pub struct AppState {
#[cfg(feature = "drive")]
pub drive: Option<S3Client>,
#[cfg(feature = "redis-cache")]
pub cache: Option<Arc<RedisClient>>,
pub bucket_name: String,
pub config: Option<AppConfig>,
pub conn: DbPool,
pub session_manager: Arc<tokio::sync::Mutex<SessionManager>>,
#[cfg(feature = "llm")]
pub llm_provider: Arc<dyn LLMProvider>,
#[cfg(feature = "directory")]
pub auth_service: Arc<tokio::sync::Mutex<AuthService>>,
pub channels: Arc<tokio::sync::Mutex<HashMap<String, Arc<dyn ChannelAdapter>>>>,
pub response_channels: Arc<tokio::sync::Mutex<HashMap<String, mpsc::Sender<BotResponse>>>>,
pub web_adapter: Arc<WebChannelAdapter>,
pub voice_adapter: Arc<VoiceAdapter>,
pub kb_manager: Option<Arc<KnowledgeBaseManager>>,
}
impl Clone for AppState {
fn clone(&self) -> Self {
Self {
#[cfg(feature = "drive")]
drive: self.drive.clone(),
bucket_name: self.bucket_name.clone(),
config: self.config.clone(),
conn: self.conn.clone(),
#[cfg(feature = "redis-cache")]
cache: self.cache.clone(),
session_manager: Arc::clone(&self.session_manager),
#[cfg(feature = "llm")]
llm_provider: Arc::clone(&self.llm_provider),
#[cfg(feature = "directory")]
auth_service: Arc::clone(&self.auth_service),
kb_manager: self.kb_manager.clone(),
channels: Arc::clone(&self.channels),
response_channels: Arc::clone(&self.response_channels),
web_adapter: Arc::clone(&self.web_adapter),
voice_adapter: Arc::clone(&self.voice_adapter),
}
}
}
impl std::fmt::Debug for AppState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut debug = f.debug_struct("AppState");
#[cfg(feature = "drive")]
debug.field("drive", &self.drive.is_some());
#[cfg(feature = "redis-cache")]
debug.field("cache", &self.cache.is_some());
debug
.field("bucket_name", &self.bucket_name)
.field("config", &self.config)
.field("conn", &"DbPool")
.field("session_manager", &"Arc<Mutex<SessionManager>>");
#[cfg(feature = "llm")]
debug.field("llm_provider", &"Arc<dyn LLMProvider>");
#[cfg(feature = "directory")]
debug.field("auth_service", &"Arc<Mutex<AuthService>>");
debug
.field("channels", &"Arc<Mutex<HashMap>>")
.field("response_channels", &"Arc<Mutex<HashMap>>")
.field("web_adapter", &self.web_adapter)
.field("voice_adapter", &self.voice_adapter)
.finish()
}
}