Spaces:
Building
Building
import uuid | |
import threading | |
from utils import log | |
class Session: | |
def __init__(self, project_name): | |
self.session_id = str(uuid.uuid4()) | |
self.project_name = project_name | |
self.last_intent = None | |
self.variables = {} # Extracted parameters | |
self.awaiting_parameters = [] # Still-missing parameters | |
self.state = "intent_detection" # intent_detection, parameter_extraction, api_call, humanization | |
self.chat_history = [] # [{'role': 'user'/'assistant', 'content': text}] | |
self.auth_tokens = {} # Per-API auth tokens | |
class SessionStore: | |
def __init__(self): | |
self.sessions = {} | |
self.lock = threading.Lock() | |
def create_session(self, project_name): | |
with self.lock: | |
session = Session(project_name) | |
self.sessions[session.session_id] = session | |
log(f"π Created session: {session.session_id} for project: {project_name}") | |
return session | |
def get_session(self, session_id): | |
with self.lock: | |
return self.sessions.get(session_id) | |
def update_session(self, session_id, **kwargs): | |
with self.lock: | |
session = self.sessions.get(session_id) | |
if not session: | |
return None | |
for key, value in kwargs.items(): | |
setattr(session, key, value) | |
log(f"π Updated session: {session_id} with {kwargs}") | |
return session | |
def remove_session(self, session_id): | |
with self.lock: | |
if session_id in self.sessions: | |
del self.sessions[session_id] | |
log(f"β Removed session: {session_id}") | |