feat: simplify Redis key format and clean up code
- Remove comments from launch.json configuration - Simplify Redis key format in set_current_context_keyword by removing context_name - Remove unused /api/start endpoint and related session start logic - Change log level from info to trace for config sync messages - Add trace logging to drive_monitor module The changes focus on code cleanup and simplification, particularly around session handling and logging. The Redis key format was simplified as the context_name was deemed unnecessary for uniqueness.
This commit is contained in:
parent
0342e1cac9
commit
acca68493f
9 changed files with 50 additions and 104 deletions
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
|
@ -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": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,10 +34,9 @@ pub fn set_current_context_keyword(state: Arc<AppState>, 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!(
|
||||
|
|
|
|||
|
|
@ -1286,80 +1286,6 @@ async fn websocket_handler(
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
#[actix_web::post("/api/start")]
|
||||
async fn start_session(
|
||||
data: web::Data<AppState>,
|
||||
info: web::Json<serde_json::Value>,
|
||||
) -> Result<HttpResponse> {
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -394,6 +394,44 @@ async fn get_sessions(data: web::Data<AppState>) -> Result<HttpResponse> {
|
|||
}
|
||||
}
|
||||
|
||||
#[actix_web::post("/api/sessions/{session_id}/start")]
|
||||
async fn start_session(
|
||||
data: web::Data<AppState>,
|
||||
path: web::Path<String>,
|
||||
) -> Result<HttpResponse> {
|
||||
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<AppState>,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue