diff --git a/.vscode/launch.json b/.vscode/launch.json index ef4168dd..0c6b0aa8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,4 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { diff --git a/src/basic/keywords/set_current_context.rs b/src/basic/keywords/set_current_context.rs index eefd4fc4..385bebdf 100644 --- a/src/basic/keywords/set_current_context.rs +++ b/src/basic/keywords/set_current_context.rs @@ -34,10 +34,9 @@ pub fn set_current_context_keyword(state: Arc, user: UserSession, engi // Build a Redis key that is unique per user and session. let redis_key = format!( - "context:{}:{}:{}", + "context:{}:{}", user.user_id, - user.id, - context_name + user.id ); trace!( diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 6b226ef5..e94cf1f8 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1286,80 +1286,6 @@ async fn websocket_handler( Ok(res) } -#[actix_web::post("/api/start")] -async fn start_session( - data: web::Data, - info: web::Json, -) -> Result { - let session_id = info - .get("session_id") - .and_then(|s| s.as_str()) - .unwrap_or(""); - - let token = info - .get("token") - .and_then(|t| t.as_str()) - .map(|s| s.to_string()); - - let session_uuid = match Uuid::parse_str(session_id) { - Ok(uuid) => uuid, - Err(_) => { - warn!("Invalid session ID format: {}", session_id); - return Ok( - HttpResponse::BadRequest().json(serde_json::json!({"error": "Invalid session ID"})) - ); - } - }; - - let session = { - let mut session_manager = data.session_manager.lock().await; - match session_manager.get_session_by_id(session_uuid) { - Ok(Some(s)) => s, - Ok(None) => { - warn!("Session not found: {}", session_uuid); - return Ok(HttpResponse::NotFound() - .json(serde_json::json!({"error": "Session not found"}))); - } - Err(e) => { - error!("Error retrieving session {}: {}", session_uuid, e); - return Ok(HttpResponse::InternalServerError() - .json(serde_json::json!({"error": "Failed to retrieve session"}))); - } - } - }; - - let result = BotOrchestrator::run_start_script(&session, Arc::clone(&data), token).await; - - match result { - Ok(true) => { - info!( - "Start script completed successfully for session: {}", - session_id - ); - Ok(HttpResponse::Ok().json(serde_json::json!({ - "status": "started", - "session_id": session.id, - "result": "success" - }))) - } - Ok(false) => { - warn!("Start script returned false for session: {}", session_id); - Ok(HttpResponse::Ok().json(serde_json::json!({ - "status": "started", - "session_id": session.id, - "result": "failed" - }))) - } - Err(e) => { - error!( - "Error running start script for session {}: {}", - session_id, e - ); - Ok(HttpResponse::InternalServerError() - .json(serde_json::json!({"error": e.to_string()}))) - } - } -} #[actix_web::post("/api/warn")] async fn send_warning_handler( diff --git a/src/config/mod.rs b/src/config/mod.rs index 49aae185..033eaed3 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,6 +1,6 @@ use diesel::prelude::*; use diesel::sql_types::Text; -use log::{info, warn}; +use log::{info, trace, warn}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fs::OpenOptions; @@ -473,7 +473,7 @@ impl ConfigManager { } } - info!( + trace!( "Synced {} config values for bot {}", updated, bot_id); Ok(updated) diff --git a/src/drive_monitor/mod.rs b/src/drive_monitor/mod.rs index a7b1b514..9ec871db 100644 --- a/src/drive_monitor/mod.rs +++ b/src/drive_monitor/mod.rs @@ -4,6 +4,7 @@ use crate::kb::embeddings; use crate::kb::qdrant_client; use crate::shared::state::AppState; use aws_sdk_s3::Client; +use log::trace; use log::{debug, error, info, warn}; use std::collections::HashMap; use std::error::Error; @@ -322,12 +323,12 @@ impl DriveMonitor { _ = config_manager.sync_gbot_config(&self.bot_id, &csv_content); if restart_needed { - info!("Detected llm- configuration change, restarting LLaMA servers..."); + trace!("Detected llm- configuration change, restarting LLaMA servers..."); if let Err(e) = ensure_llama_servers_running(&self.state).await { error!("Failed to restart LLaMA servers after llm- config change: {}", e); } } else { - info!("No llm- property changes detected; skipping LLaMA server restart."); + trace!("No llm- property changes detected; skipping LLaMA server restart."); } } else diff --git a/src/main.rs b/src/main.rs index 326a3da0..66e4462c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ mod create_bucket; use crate::auth::auth_handler; use crate::automation::AutomationService; use crate::bootstrap::BootstrapManager; -use crate::bot::{start_session, websocket_handler}; +use crate::bot::{websocket_handler}; use crate::channels::{VoiceAdapter, WebChannelAdapter}; use crate::config::AppConfig; #[cfg(feature = "email")] @@ -54,7 +54,7 @@ use crate::llm_legacy::llm_local::{ }; use crate::meet::{voice_start, voice_stop}; use crate::package_manager::InstallMode; -use crate::session::{create_session, get_session_history, get_sessions}; +use crate::session::{create_session, get_session_history, get_sessions, start_session}; use crate::shared::state::AppState; use crate::web_server::{bot_index, index, static_files}; use crate::whatsapp::whatsapp_webhook_verify; diff --git a/src/package_manager/installer.rs b/src/package_manager/installer.rs index d92db177..b9bd4170 100644 --- a/src/package_manager/installer.rs +++ b/src/package_manager/installer.rs @@ -802,6 +802,8 @@ post_install_cmds_linux: vec![ .arg(&rendered_cmd) .spawn(); + std::thread::sleep(std::time::Duration::from_secs(2)); + match child { Ok(c) => Ok(c), Err(e) => { diff --git a/src/session/mod.rs b/src/session/mod.rs index abe2c7ff..17eb7b5d 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -394,6 +394,44 @@ async fn get_sessions(data: web::Data) -> Result { } } +#[actix_web::post("/api/sessions/{session_id}/start")] +async fn start_session( + data: web::Data, + path: web::Path, +) -> Result { + let session_id = path.into_inner(); + let user_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001").unwrap(); + + match Uuid::parse_str(&session_id) { + Ok(session_uuid) => { + let mut session_manager = data.session_manager.lock().await; + match session_manager.get_session_by_id(session_uuid) { + Ok(Some(session)) => { + session_manager.mark_waiting(session_uuid); + Ok(HttpResponse::Ok().json(serde_json::json!({ + "status": "started", + "session_id": session_id + }))) + } + Ok(None) => { + Ok(HttpResponse::NotFound().json(serde_json::json!({ + "error": "Session not found" + }))) + } + Err(e) => { + error!("Failed to start session {}: {}", session_id, e); + Ok(HttpResponse::InternalServerError() + .json(serde_json::json!({"error": e.to_string()}))) + } + } + } + Err(_) => { + warn!("Invalid session ID format: {}", session_id); + Ok(HttpResponse::BadRequest().json(serde_json::json!({"error": "Invalid session ID"}))) + } + } +} + #[actix_web::get("/api/sessions/{session_id}")] async fn get_session_history( data: web::Data, diff --git a/web/html/index.html b/web/html/index.html index 4ad20f8b..9e2492e3 100644 --- a/web/html/index.html +++ b/web/html/index.html @@ -1152,7 +1152,7 @@ async function initializeAuth() { try { updateConnectionStatus("connecting"); - // Extract bot name from URL path (first segment after /) + // Extract bot name from URL path (first segment after / const pathSegments = window.location.pathname.split('/').filter(s => s); const botName = pathSegments.length > 0 ? pathSegments[0] : 'default'; @@ -1162,7 +1162,6 @@ currentSessionId = authData.session_id; connectWebSocket(); loadSessions(); - await triggerStartScript(); } catch (error) { console.error("Failed to initialize auth:", error); updateConnectionStatus("disconnected"); @@ -1170,20 +1169,6 @@ } } - async function triggerStartScript() { - if (!currentSessionId) return; - try { - await fetch("/api/start", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - session_id: currentSessionId, - }), - }); - } catch (error) { - console.error("Failed to trigger start script:", error); - } - } async function loadSessions() { try { @@ -1218,7 +1203,6 @@ if (isVoiceMode) { await startVoiceSession(); } - await triggerStartScript(); // Close sidebar on mobile after creating new chat if (window.innerWidth <= 768) { @@ -1282,7 +1266,6 @@ } clearTimeout(reconnectTimeout); - const wsUrl = getWebSocketUrl(); ws = new WebSocket(wsUrl);