Spaces:
Runtime error
Runtime error
Fix supabase
Browse files- ai-agent-ui/style.css +20 -5
- config/settings.py +1 -1
- database/supabase_manager.py +58 -8
- requirements.txt +1 -1
ai-agent-ui/style.css
CHANGED
|
@@ -573,13 +573,14 @@ textarea:focus {
|
|
| 573 |
.toggle-group {
|
| 574 |
display: flex;
|
| 575 |
flex-direction: column;
|
| 576 |
-
gap: var(--space-
|
| 577 |
margin-bottom: var(--space-lg);
|
| 578 |
}
|
| 579 |
|
| 580 |
.toggle-wrapper {
|
| 581 |
display: flex;
|
| 582 |
align-items: center;
|
|
|
|
| 583 |
}
|
| 584 |
|
| 585 |
.toggle-switch {
|
|
@@ -589,18 +590,30 @@ textarea:focus {
|
|
| 589 |
.toggle-label {
|
| 590 |
display: flex;
|
| 591 |
align-items: center;
|
| 592 |
-
|
|
|
|
| 593 |
cursor: pointer;
|
| 594 |
user-select: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
}
|
| 596 |
|
| 597 |
.toggle-slider {
|
| 598 |
width: 52px;
|
| 599 |
height: 28px;
|
| 600 |
-
background: var(--color-gray-
|
| 601 |
border-radius: var(--radius-full);
|
| 602 |
position: relative;
|
| 603 |
transition: all var(--transition-normal);
|
|
|
|
| 604 |
}
|
| 605 |
|
| 606 |
.toggle-slider::before {
|
|
@@ -610,10 +623,10 @@ textarea:focus {
|
|
| 610 |
left: 2px;
|
| 611 |
width: 24px;
|
| 612 |
height: 24px;
|
| 613 |
-
background: var(--color-
|
| 614 |
border-radius: var(--radius-full);
|
| 615 |
transition: all var(--transition-normal);
|
| 616 |
-
box-shadow: var(--shadow-
|
| 617 |
}
|
| 618 |
|
| 619 |
.toggle-switch:checked + .toggle-label .toggle-slider {
|
|
@@ -622,12 +635,14 @@ textarea:focus {
|
|
| 622 |
|
| 623 |
.toggle-switch:checked + .toggle-label .toggle-slider::before {
|
| 624 |
transform: translateX(24px);
|
|
|
|
| 625 |
}
|
| 626 |
|
| 627 |
.toggle-text {
|
| 628 |
font-size: var(--font-size-sm);
|
| 629 |
font-weight: 600;
|
| 630 |
color: var(--color-gray-700);
|
|
|
|
| 631 |
}
|
| 632 |
|
| 633 |
.schedule-info {
|
|
|
|
| 573 |
.toggle-group {
|
| 574 |
display: flex;
|
| 575 |
flex-direction: column;
|
| 576 |
+
gap: var(--space-lg);
|
| 577 |
margin-bottom: var(--space-lg);
|
| 578 |
}
|
| 579 |
|
| 580 |
.toggle-wrapper {
|
| 581 |
display: flex;
|
| 582 |
align-items: center;
|
| 583 |
+
width: 100%;
|
| 584 |
}
|
| 585 |
|
| 586 |
.toggle-switch {
|
|
|
|
| 590 |
.toggle-label {
|
| 591 |
display: flex;
|
| 592 |
align-items: center;
|
| 593 |
+
justify-content: space-between;
|
| 594 |
+
width: 100%;
|
| 595 |
cursor: pointer;
|
| 596 |
user-select: none;
|
| 597 |
+
padding: var(--space-md);
|
| 598 |
+
background: rgba(255, 255, 255, 0.5);
|
| 599 |
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
| 600 |
+
border-radius: var(--radius-lg);
|
| 601 |
+
transition: all var(--transition-normal);
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
.toggle-label:hover {
|
| 605 |
+
background: rgba(255, 255, 255, 0.8);
|
| 606 |
+
transform: translateY(-1px);
|
| 607 |
}
|
| 608 |
|
| 609 |
.toggle-slider {
|
| 610 |
width: 52px;
|
| 611 |
height: 28px;
|
| 612 |
+
background: var(--color-gray-400);
|
| 613 |
border-radius: var(--radius-full);
|
| 614 |
position: relative;
|
| 615 |
transition: all var(--transition-normal);
|
| 616 |
+
flex-shrink: 0;
|
| 617 |
}
|
| 618 |
|
| 619 |
.toggle-slider::before {
|
|
|
|
| 623 |
left: 2px;
|
| 624 |
width: 24px;
|
| 625 |
height: 24px;
|
| 626 |
+
background: var(--color-gray-100);
|
| 627 |
border-radius: var(--radius-full);
|
| 628 |
transition: all var(--transition-normal);
|
| 629 |
+
box-shadow: var(--shadow-md);
|
| 630 |
}
|
| 631 |
|
| 632 |
.toggle-switch:checked + .toggle-label .toggle-slider {
|
|
|
|
| 635 |
|
| 636 |
.toggle-switch:checked + .toggle-label .toggle-slider::before {
|
| 637 |
transform: translateX(24px);
|
| 638 |
+
background: var(--color-white);
|
| 639 |
}
|
| 640 |
|
| 641 |
.toggle-text {
|
| 642 |
font-size: var(--font-size-sm);
|
| 643 |
font-weight: 600;
|
| 644 |
color: var(--color-gray-700);
|
| 645 |
+
flex: 1;
|
| 646 |
}
|
| 647 |
|
| 648 |
.schedule-info {
|
config/settings.py
CHANGED
|
@@ -42,7 +42,7 @@ class Settings:
|
|
| 42 |
if not self.supabase_url:
|
| 43 |
missing.append("SUPABASE_URL")
|
| 44 |
if not self.supabase_key:
|
| 45 |
-
missing.append("
|
| 46 |
|
| 47 |
return missing
|
| 48 |
|
|
|
|
| 42 |
if not self.supabase_url:
|
| 43 |
missing.append("SUPABASE_URL")
|
| 44 |
if not self.supabase_key:
|
| 45 |
+
missing.append("SUPABASE_ANON_KEY")
|
| 46 |
|
| 47 |
return missing
|
| 48 |
|
database/supabase_manager.py
CHANGED
|
@@ -13,9 +13,17 @@ import logging
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
from supabase import create_client, Client
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
Client = None
|
|
|
|
|
|
|
| 19 |
|
| 20 |
from config.settings import settings
|
| 21 |
|
|
@@ -31,24 +39,62 @@ class SupabaseManager:
|
|
| 31 |
|
| 32 |
def _init_client(self):
|
| 33 |
"""Initialize the Supabase client"""
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return
|
| 37 |
|
| 38 |
-
if
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
return
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
try:
|
| 43 |
self.client = create_client(settings.supabase_url, settings.supabase_key)
|
| 44 |
-
logger.info("Supabase client initialized successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
except Exception as e:
|
| 46 |
-
logger.error(f"Failed to initialize Supabase client: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def save_user_preferences(self, email: str, search_criteria: str,
|
| 49 |
system_prompt: str, preferences: str) -> Dict[str, Any]:
|
| 50 |
"""Save or update user preferences"""
|
| 51 |
if not self.client:
|
|
|
|
| 52 |
return {"success": False, "error": "Database not available"}
|
| 53 |
|
| 54 |
try:
|
|
@@ -81,6 +127,7 @@ class SupabaseManager:
|
|
| 81 |
def get_user_preferences(self, email: str) -> Dict[str, Any]:
|
| 82 |
"""Get user preferences by email"""
|
| 83 |
if not self.client:
|
|
|
|
| 84 |
return {"success": False, "error": "Database not available"}
|
| 85 |
|
| 86 |
try:
|
|
@@ -100,6 +147,7 @@ class SupabaseManager:
|
|
| 100 |
def update_schedule_status(self, email: str, enabled: bool) -> Dict[str, Any]:
|
| 101 |
"""Update scheduling status for a user"""
|
| 102 |
if not self.client:
|
|
|
|
| 103 |
return {"success": False, "error": "Database not available"}
|
| 104 |
|
| 105 |
try:
|
|
@@ -122,6 +170,7 @@ class SupabaseManager:
|
|
| 122 |
def get_scheduled_users(self) -> Dict[str, Any]:
|
| 123 |
"""Get all users with scheduling enabled"""
|
| 124 |
if not self.client:
|
|
|
|
| 125 |
return {"success": False, "error": "Database not available"}
|
| 126 |
|
| 127 |
try:
|
|
@@ -137,6 +186,7 @@ class SupabaseManager:
|
|
| 137 |
def delete_user_preferences(self, email: str) -> Dict[str, Any]:
|
| 138 |
"""Delete user preferences"""
|
| 139 |
if not self.client:
|
|
|
|
| 140 |
return {"success": False, "error": "Database not available"}
|
| 141 |
|
| 142 |
try:
|
|
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
from supabase import create_client, Client
|
| 16 |
+
SUPABASE_AVAILABLE = True
|
| 17 |
+
IMPORT_ERROR = None
|
| 18 |
+
except ImportError as e:
|
| 19 |
+
print(f"Warning: supabase-py import failed: {e}")
|
| 20 |
+
print("This may be due to:")
|
| 21 |
+
print(" - Package not installed: pip install supabase==2.9.1")
|
| 22 |
+
print(" - Version conflicts with other packages")
|
| 23 |
+
print(" - Missing system dependencies")
|
| 24 |
Client = None
|
| 25 |
+
SUPABASE_AVAILABLE = False
|
| 26 |
+
IMPORT_ERROR = str(e)
|
| 27 |
|
| 28 |
from config.settings import settings
|
| 29 |
|
|
|
|
| 39 |
|
| 40 |
def _init_client(self):
|
| 41 |
"""Initialize the Supabase client"""
|
| 42 |
+
logger.info("Initializing Supabase database client...")
|
| 43 |
+
|
| 44 |
+
# Check for missing environment variables
|
| 45 |
+
missing_vars = []
|
| 46 |
+
if not settings.supabase_url:
|
| 47 |
+
missing_vars.append("SUPABASE_URL")
|
| 48 |
+
if not settings.supabase_key:
|
| 49 |
+
missing_vars.append("SUPABASE_ANON_KEY")
|
| 50 |
+
|
| 51 |
+
if missing_vars:
|
| 52 |
+
logger.error(f"Missing required environment variables for Supabase: {', '.join(missing_vars)}")
|
| 53 |
+
logger.error("Database operations will fail. Please set these environment variables:")
|
| 54 |
+
for var in missing_vars:
|
| 55 |
+
logger.error(f" export {var}=your_value_here")
|
| 56 |
return
|
| 57 |
|
| 58 |
+
# Check if supabase-py is installed
|
| 59 |
+
if not SUPABASE_AVAILABLE:
|
| 60 |
+
logger.error("supabase-py package not available.")
|
| 61 |
+
logger.error(f"Import error: {IMPORT_ERROR}")
|
| 62 |
+
logger.error("This indicates the package is not properly installed or has dependency conflicts.")
|
| 63 |
+
logger.error("To fix this on Hugging Face Spaces:")
|
| 64 |
+
logger.error(" 1. Ensure 'supabase==2.9.1' is in requirements.txt")
|
| 65 |
+
logger.error(" 2. Restart the Space to reinstall dependencies")
|
| 66 |
+
logger.error(" 3. Check for conflicting package versions")
|
| 67 |
return
|
| 68 |
|
| 69 |
+
# Log configuration (without sensitive data)
|
| 70 |
+
logger.info(f"Supabase URL: {settings.supabase_url}")
|
| 71 |
+
logger.info(f"Supabase Key: {'*' * 10}...{settings.supabase_key[-4:] if settings.supabase_key else 'None'}")
|
| 72 |
+
|
| 73 |
try:
|
| 74 |
self.client = create_client(settings.supabase_url, settings.supabase_key)
|
| 75 |
+
logger.info("✅ Supabase client initialized successfully")
|
| 76 |
+
|
| 77 |
+
# Test the connection
|
| 78 |
+
logger.info("Testing database connection...")
|
| 79 |
+
test_result = self.health_check()
|
| 80 |
+
if test_result["success"]:
|
| 81 |
+
logger.info("✅ Database connection test passed")
|
| 82 |
+
else:
|
| 83 |
+
logger.warning(f"⚠️ Database connection test failed: {test_result['error']}")
|
| 84 |
+
|
| 85 |
except Exception as e:
|
| 86 |
+
logger.error(f"❌ Failed to initialize Supabase client: {type(e).__name__}: {e}")
|
| 87 |
+
logger.error("This could be due to:")
|
| 88 |
+
logger.error(" - Invalid SUPABASE_URL format")
|
| 89 |
+
logger.error(" - Invalid SUPABASE_ANON_KEY")
|
| 90 |
+
logger.error(" - Network connectivity issues")
|
| 91 |
+
logger.error(" - Supabase service unavailability")
|
| 92 |
|
| 93 |
def save_user_preferences(self, email: str, search_criteria: str,
|
| 94 |
system_prompt: str, preferences: str) -> Dict[str, Any]:
|
| 95 |
"""Save or update user preferences"""
|
| 96 |
if not self.client:
|
| 97 |
+
logger.error(f"Cannot save preferences for {email}: Database client not initialized. Check Supabase configuration.")
|
| 98 |
return {"success": False, "error": "Database not available"}
|
| 99 |
|
| 100 |
try:
|
|
|
|
| 127 |
def get_user_preferences(self, email: str) -> Dict[str, Any]:
|
| 128 |
"""Get user preferences by email"""
|
| 129 |
if not self.client:
|
| 130 |
+
logger.error(f"Cannot get preferences for {email}: Database client not initialized. Check Supabase configuration.")
|
| 131 |
return {"success": False, "error": "Database not available"}
|
| 132 |
|
| 133 |
try:
|
|
|
|
| 147 |
def update_schedule_status(self, email: str, enabled: bool) -> Dict[str, Any]:
|
| 148 |
"""Update scheduling status for a user"""
|
| 149 |
if not self.client:
|
| 150 |
+
logger.error(f"Cannot update schedule status for {email}: Database client not initialized. Check Supabase configuration.")
|
| 151 |
return {"success": False, "error": "Database not available"}
|
| 152 |
|
| 153 |
try:
|
|
|
|
| 170 |
def get_scheduled_users(self) -> Dict[str, Any]:
|
| 171 |
"""Get all users with scheduling enabled"""
|
| 172 |
if not self.client:
|
| 173 |
+
logger.error("Cannot get scheduled users: Database client not initialized. Check Supabase configuration.")
|
| 174 |
return {"success": False, "error": "Database not available"}
|
| 175 |
|
| 176 |
try:
|
|
|
|
| 186 |
def delete_user_preferences(self, email: str) -> Dict[str, Any]:
|
| 187 |
"""Delete user preferences"""
|
| 188 |
if not self.client:
|
| 189 |
+
logger.error(f"Cannot delete preferences for {email}: Database client not initialized. Check Supabase configuration.")
|
| 190 |
return {"success": False, "error": "Database not available"}
|
| 191 |
|
| 192 |
try:
|
requirements.txt
CHANGED
|
@@ -17,7 +17,7 @@ aiofiles
|
|
| 17 |
uvicorn
|
| 18 |
|
| 19 |
# Database and scheduling
|
| 20 |
-
supabase
|
| 21 |
apscheduler
|
| 22 |
|
| 23 |
# Email and communication
|
|
|
|
| 17 |
uvicorn
|
| 18 |
|
| 19 |
# Database and scheduling
|
| 20 |
+
supabase==2.9.1
|
| 21 |
apscheduler
|
| 22 |
|
| 23 |
# Email and communication
|