diff --git a/src/automation/mod.rs b/src/automation/mod.rs index 40a47ec3..7d5148e7 100644 --- a/src/automation/mod.rs +++ b/src/automation/mod.rs @@ -182,14 +182,14 @@ impl AutomationService { } } -pub async fn execute_compact_prompt() -> Result<(), Box> { +pub async fn execute_compact_prompt(state: Arc) -> Result<(), Box> { use crate::shared::models::system_automations::dsl::{is_active, system_automations}; use diesel::prelude::*; use log::info; use std::sync::Arc; - let state = Arc::new(crate::shared::state::AppState::default()); - let service = AutomationService::new(Arc::clone(&state)); + let state_clone = state.clone(); +let service = AutomationService::new(state_clone); let mut conn = state .conn diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 9596e520..ef8fa382 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -625,14 +625,15 @@ let compact_enabled = config_manager .parse::() .unwrap_or(0); if compact_enabled > 0 { - tokio::task::spawn_blocking(move || { - loop { - if let Err(e) = tokio::runtime::Handle::current().block_on(crate::automation::execute_compact_prompt()) { - error!("Failed to execute compact prompt: {}", e); - } - std::thread::sleep(Duration::from_secs(60)); +let state = self.state.clone(); +tokio::task::spawn_blocking(move || { + loop { + if let Err(e) = tokio::runtime::Handle::current().block_on(crate::automation::execute_compact_prompt(state.clone())) { + error!("Failed to execute compact prompt: {}", e); } - }); + std::thread::sleep(Duration::from_secs(60)); + } +}); } // Save final message with short lock scope @@ -881,10 +882,7 @@ if compact_enabled > 0 { impl Default for BotOrchestrator { fn default() -> Self { - Self { - state: Arc::new(AppState::default()), - mounted_bots: Arc::new(AsyncMutex::new(HashMap::new())), - } + panic!("BotOrchestrator::default is not supported; instantiate with BotOrchestrator::new(state)"); } } diff --git a/src/shared/state.rs b/src/shared/state.rs index 8586c184..eb8ff400 100644 --- a/src/shared/state.rs +++ b/src/shared/state.rs @@ -45,34 +45,3 @@ impl Clone for AppState { } } } - -impl Default for AppState { - fn default() -> Self { - Self { - drive: None, - bucket_name: "default.gbai".to_string(), - config: None, - conn: Arc::new(Mutex::new( - diesel::PgConnection::establish("postgres://localhost/test").unwrap(), - )), - - cache: None, - session_manager: Arc::new(tokio::sync::Mutex::new(SessionManager::new( - diesel::PgConnection::establish("postgres://localhost/test").unwrap(), - None, - ))), - llm_provider: Arc::new(crate::llm::OpenAIClient::new( - "empty".to_string(), - Some("http://localhost:8081".to_string()), - )), - auth_service: Arc::new(tokio::sync::Mutex::new(AuthService::new( - - ))), - channels: Arc::new(Mutex::new(HashMap::new())), - response_channels: Arc::new(tokio::sync::Mutex::new(HashMap::new())), - web_adapter: Arc::new(WebChannelAdapter::new()), - voice_adapter: Arc::new(VoiceAdapter::new( - )), - } - } -}