Spaces:
Sleeping
Sleeping
Update Copilot to use Supabase for session storage (like HuggingChat)
Browse filesChanges:
- Copilot now uses Supabase provider_sessions (not file-based)
- Sessions persist across server restarts like HuggingChat
- Unlimited conversations (999999 limit)
- 30-day session duration (720 hours)
- Added copilot to ProviderSessionManager defaults
Now Copilot sessions are stored in Supabase just like HuggingChat!
The portal doesn't need Supabase since it's just for interactive admin use.
- provider_sessions.py +2 -0
- providers/copilot_provider.py +11 -7
provider_sessions.py
CHANGED
|
@@ -26,6 +26,7 @@ DEFAULT_MAX_CONVERSATIONS = {
|
|
| 26 |
"huggingchat": 50,
|
| 27 |
"zai": 100,
|
| 28 |
"gemini": 100,
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
# Session duration per provider (hours)
|
|
@@ -33,6 +34,7 @@ DEFAULT_SESSION_DURATION = {
|
|
| 33 |
"huggingchat": 24,
|
| 34 |
"zai": 48,
|
| 35 |
"gemini": 48,
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
|
|
|
|
| 26 |
"huggingchat": 50,
|
| 27 |
"zai": 100,
|
| 28 |
"gemini": 100,
|
| 29 |
+
"copilot": 999999, # Unlimited for Copilot
|
| 30 |
}
|
| 31 |
|
| 32 |
# Session duration per provider (hours)
|
|
|
|
| 34 |
"huggingchat": 24,
|
| 35 |
"zai": 48,
|
| 36 |
"gemini": 48,
|
| 37 |
+
"copilot": 720, # 30 days for Copilot
|
| 38 |
}
|
| 39 |
|
| 40 |
|
providers/copilot_provider.py
CHANGED
|
@@ -17,7 +17,7 @@ import re
|
|
| 17 |
from typing import Optional, Dict, Any
|
| 18 |
from providers.base import BaseProvider
|
| 19 |
from config import PROVIDER_MODELS
|
| 20 |
-
from
|
| 21 |
|
| 22 |
logger = logging.getLogger("kai_api.copilot")
|
| 23 |
|
|
@@ -147,10 +147,10 @@ class CopilotProvider(BaseProvider):
|
|
| 147 |
|
| 148 |
await self._ensure_browser()
|
| 149 |
selected_model = model or "copilot-gpt-4"
|
| 150 |
-
session_mgr =
|
| 151 |
|
| 152 |
-
# Check if we have a valid session
|
| 153 |
-
session_data = session_mgr.
|
| 154 |
|
| 155 |
# Create context with cookies if we have them
|
| 156 |
context = await _browser.new_context(
|
|
@@ -265,11 +265,15 @@ class CopilotProvider(BaseProvider):
|
|
| 265 |
if not response_text:
|
| 266 |
raise ValueError("Empty response from Copilot")
|
| 267 |
|
| 268 |
-
# Save cookies after successful request
|
| 269 |
try:
|
| 270 |
cookies = await context.cookies()
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
except Exception as e:
|
| 274 |
logger.warning(f"Failed to save cookies: {e}")
|
| 275 |
|
|
|
|
| 17 |
from typing import Optional, Dict, Any
|
| 18 |
from providers.base import BaseProvider
|
| 19 |
from config import PROVIDER_MODELS
|
| 20 |
+
from provider_sessions import get_provider_session_manager
|
| 21 |
|
| 22 |
logger = logging.getLogger("kai_api.copilot")
|
| 23 |
|
|
|
|
| 147 |
|
| 148 |
await self._ensure_browser()
|
| 149 |
selected_model = model or "copilot-gpt-4"
|
| 150 |
+
session_mgr = get_provider_session_manager()
|
| 151 |
|
| 152 |
+
# Check if we have a valid session from Supabase
|
| 153 |
+
session_data = session_mgr.get_session("copilot")
|
| 154 |
|
| 155 |
# Create context with cookies if we have them
|
| 156 |
context = await _browser.new_context(
|
|
|
|
| 265 |
if not response_text:
|
| 266 |
raise ValueError("Empty response from Copilot")
|
| 267 |
|
| 268 |
+
# Save cookies after successful request to Supabase
|
| 269 |
try:
|
| 270 |
cookies = await context.cookies()
|
| 271 |
+
cookies_dict = [{k: v for k, v in cookie.items()} for cookie in cookies]
|
| 272 |
+
# Get current conversation count
|
| 273 |
+
session = session_mgr.get_session("copilot")
|
| 274 |
+
conv_count = session.get("conversation_count", 0) if session else 0
|
| 275 |
+
session_mgr.save_session("copilot", cookies_dict, conversation_count=conv_count + 1)
|
| 276 |
+
logger.info("✅ Copilot: Saved session cookies to Supabase")
|
| 277 |
except Exception as e:
|
| 278 |
logger.warning(f"Failed to save cookies: {e}")
|
| 279 |
|