diff --git a/services/dashboard/VoiceControls.jsx b/services/dashboard/VoiceControls.jsx index 7365cc7..491789f 100644 --- a/services/dashboard/VoiceControls.jsx +++ b/services/dashboard/VoiceControls.jsx @@ -22,7 +22,9 @@ const VoiceControls = ({ onCommand, hotkey = ' ' }) => { return; } - // Request microphone permission + // Note: We request permission on mount for better UX. + // Alternative: Request only on first use by removing this and letting + // startListening() handle the permission request requestMicrophonePermission(); // Setup hotkey listener diff --git a/services/hackgpt-api/app/config_validator.py b/services/hackgpt-api/app/config_validator.py index d2c4514..c4a8304 100644 --- a/services/hackgpt-api/app/config_validator.py +++ b/services/hackgpt-api/app/config_validator.py @@ -467,7 +467,10 @@ def _is_valid_target(target: str) -> bool: ip_pattern = r'^(\d{1,3}\.){3}\d{1,3}$' if re.match(ip_pattern, target): parts = target.split('.') - return all(0 <= int(part) <= 255 for part in parts) + try: + return all(0 <= int(part) <= 255 for part in parts) + except ValueError: + return False # CIDR notation if '/' in target: @@ -522,7 +525,10 @@ def _is_valid_ip_or_hostname(host: str) -> bool: ip_pattern = r'^(\d{1,3}\.){3}\d{1,3}$' if re.match(ip_pattern, host): parts = host.split('.') - return all(0 <= int(part) <= 255 for part in parts) + try: + return all(0 <= int(part) <= 255 for part in parts) + except ValueError: + return False # Hostname hostname_pattern = r'^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$' diff --git a/services/hackgpt-api/app/llm_help.py b/services/hackgpt-api/app/llm_help.py index 370e40a..fb2a733 100644 --- a/services/hackgpt-api/app/llm_help.py +++ b/services/hackgpt-api/app/llm_help.py @@ -11,7 +11,10 @@ import json # Store conversation history per session +# Note: In production, use Redis or similar with TTL for scalability +# This simple in-memory dict will grow unbounded - implement cleanup as needed conversation_contexts: Dict[str, List[Dict[str, str]]] = {} +MAX_SESSIONS = 1000 # Limit number of concurrent sessions async def chat_completion( @@ -87,6 +90,11 @@ Always emphasize ethical hacking practices and legal considerations.""" # Store in conversation history if session_id: if session_id not in conversation_contexts: + # Cleanup old sessions if limit reached + if len(conversation_contexts) >= MAX_SESSIONS: + # Remove oldest session (simple FIFO) + oldest_session = next(iter(conversation_contexts)) + del conversation_contexts[oldest_session] conversation_contexts[session_id] = [] conversation_contexts[session_id].append({"role": "user", "content": message}) conversation_contexts[session_id].append({"role": "assistant", "content": assistant_message}) diff --git a/services/hackgpt-api/app/voice.py b/services/hackgpt-api/app/voice.py index fe1d97d..3570cf9 100644 --- a/services/hackgpt-api/app/voice.py +++ b/services/hackgpt-api/app/voice.py @@ -91,8 +91,8 @@ def _transcribe_with_local_whisper(audio_data: bytes, format: str) -> Dict[str, # Clean up temp file try: os.unlink(temp_audio_path) - except: - pass + except (OSError, FileNotFoundError) as e: + print(f"Warning: Could not delete temp file: {e}") except ImportError: raise Exception("Whisper not installed. Install with: pip install openai-whisper")