diff --git a/add-req.sh b/add-req.sh index 89f9a9f2..29ffae3d 100755 --- a/add-req.sh +++ b/add-req.sh @@ -20,25 +20,25 @@ done dirs=( # "auth" - # "automation" - # "basic" + "automation" + "basic" "bot" - "bootstrap" - #"package_manager" + # "bootstrap" + # "package_manager" # "channels" - # "config" - # "context" + "config" + "context" # "email" - "file" + # "file" # "llm" - "drive_monitor" + # "drive_monitor" # "llm_legacy" # "org" - # "session" - #"kb" + "session" + "kb" "shared" #"tests" - # "tools" + "tools" # "web_automation" # "whatsapp" ) diff --git a/prompts/dev/platform/ide.md b/prompts/dev/platform/ide.md new file mode 100644 index 00000000..8f0b6b8e --- /dev/null +++ b/prompts/dev/platform/ide.md @@ -0,0 +1,4 @@ +- On code return identifiers in english language. +- Do not emmit any comment, and remove any existants in Rust/html. +- Compact the code emission where possible. +- On change code, ensure cargo check cycle to remove warnings and errors. \ No newline at end of file diff --git a/src/automation/mod.rs b/src/automation/mod.rs index d452ec91..b03f717c 100644 --- a/src/automation/mod.rs +++ b/src/automation/mod.rs @@ -379,7 +379,6 @@ impl AutomationService { user_id: Uuid::new_v4(), bot_id, title: "Automation".to_string(), - answer_mode: 0, current_tool: None, context_data: serde_json::Value::Null, created_at: Utc::now(), diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 259a9ce9..bff1206f 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -229,20 +229,6 @@ impl BotOrchestrator { self.state.response_channels.lock().await.remove(session_id); } - pub async fn set_user_answer_mode( - &self, - user_id: &str, - bot_id: &str, - mode: i32, - ) -> Result<(), Box> { - info!( - "Setting answer mode for user {} with bot {} to mode {}", - user_id, bot_id, mode - ); - let mut session_manager = self.state.session_manager.lock().await; - session_manager.update_answer_mode(user_id, bot_id, mode)?; - Ok(()) - } pub async fn send_event( &self, @@ -447,7 +433,7 @@ impl BotOrchestrator { } - if session.answer_mode == 1 && session.current_tool.is_some() { + if session.current_tool.is_some() { self.state.tool_manager.provide_user_response( &message.user_id, &message.bot_id, @@ -641,7 +627,7 @@ impl BotOrchestrator { .parse::() .unwrap_or(0); - let current_context_length = 0usize; + let current_context_length = crate::shared::utils::estimate_token_count(&context_data); let final_msg = BotResponse { bot_id: message.bot_id, @@ -783,14 +769,14 @@ impl BotOrchestrator { user_id: "system".to_string(), session_id: session_id.to_string(), channel: channel.to_string(), - content: format!("⚠️ WARNING: {}", message), - message_type: 1, - stream_token: None, - is_complete: true, - suggestions: Vec::new(), - context_name: None, - context_length: 0, - context_max_length: 0, + content: format!("⚠️ WARNING: {}", message), + message_type: 1, + stream_token: None, + is_complete: true, + suggestions: Vec::new(), + context_name: None, + context_length: 0, + context_max_length: 0, }; adapter.send_message(warn_response).await } else { diff --git a/src/session/mod.rs b/src/session/mod.rs index fabe215e..7332c44e 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -167,7 +167,6 @@ impl SessionManager { bot_id.eq(bid), title.eq(session_title), context_data.eq(serde_json::json!({})), - answer_mode.eq(0), current_tool.eq(None::), created_at.eq(now), updated_at.eq(now), @@ -406,41 +405,6 @@ impl SessionManager { Ok(sessions) } - pub fn update_answer_mode( - &mut self, - uid: &str, - bid: &str, - mode: i32, - ) -> Result<(), Box> { - use crate::shared::models::user_sessions::dsl::*; - - let user_uuid = Uuid::parse_str(uid).map_err(|e| { - warn!("Invalid user ID format: {}", uid); - e - })?; - let bot_uuid = Uuid::parse_str(bid).map_err(|e| { - warn!("Invalid bot ID format: {}", bid); - e - })?; - - let updated_count = diesel::update( - user_sessions - .filter(user_id.eq(user_uuid)) - .filter(bot_id.eq(bot_uuid)), - ) - .set((answer_mode.eq(mode), updated_at.eq(chrono::Utc::now()))) - .execute(&mut self.conn)?; - - if updated_count == 0 { - warn!("No session found for user {} and bot {}", uid, bid); - } else { - info!( - "Answer mode updated to {} for user {} and bot {}", - mode, uid, bid - ); - } - Ok(()) - } pub fn update_user_id( &mut self, diff --git a/src/shared/models.rs b/src/shared/models.rs index 8859acab..7e429b88 100644 --- a/src/shared/models.rs +++ b/src/shared/models.rs @@ -82,7 +82,6 @@ pub struct UserSession { pub bot_id: Uuid, pub title: String, pub context_data: serde_json::Value, - pub answer_mode: i32, pub current_tool: Option, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, @@ -283,7 +282,6 @@ pub mod schema { bot_id -> Uuid, title -> Text, context_data -> Jsonb, - answer_mode -> Int4, current_tool -> Nullable, created_at -> Timestamptz, updated_at -> Timestamptz, diff --git a/src/shared/utils.rs b/src/shared/utils.rs index dfba3f20..6b33213b 100644 --- a/src/shared/utils.rs +++ b/src/shared/utils.rs @@ -192,6 +192,14 @@ pub async fn call_llm( Ok(format!("Generated response for: {}", prompt)) } +/// Estimates token count for text using simple heuristic (1 token ≈ 4 chars) +pub fn estimate_token_count(text: &str) -> usize { + // Basic token estimation - count whitespace-separated words + // Add 1 token for every 4 characters as a simple approximation + let char_count = text.chars().count(); + (char_count / 4).max(1) // Ensure at least 1 token +} + /// Establishes a PostgreSQL connection using DATABASE_URL environment variable pub fn establish_pg_connection() -> Result { let database_url = std::env::var("DATABASE_URL")