feat: update codebase to use httpx2 and enhance docstrings for clarity

This commit is contained in:
grillazz
2026-10-22 13:42:10 +02:00
parent 96b383e391
commit 332324c861
10 changed files with 87 additions and 107 deletions
+9
View File
@@ -17,13 +17,17 @@ from app.schemas.chat import ChatMessage
@attrs.define(slots=True)
class ChatSession:
"""Conversation history associated with one websocket connection."""
id: UUID = attrs.field(factory=uuid4)
messages: list[ChatMessage] = attrs.field(factory=list)
def add(self, message: ChatMessage) -> None:
"""Append a message to this conversation."""
self.messages.append(message)
def history(self) -> list[ChatMessage]:
"""Return a copy of the conversation history."""
return list(self.messages)
@@ -35,23 +39,28 @@ class ChatSessionManager:
"""
def __init__(self) -> None:
"""Create an empty, lock-protected session registry."""
self._sessions: dict[UUID, ChatSession] = {}
self._lock = asyncio.Lock()
async def create(self) -> ChatSession:
"""Create and register a new conversation."""
session = ChatSession()
async with self._lock:
self._sessions[session.id] = session
return session
async def get(self, session_id: UUID) -> ChatSession | None:
"""Return the matching session, if it is active."""
async with self._lock:
return self._sessions.get(session_id)
async def remove(self, session_id: UUID) -> None:
"""Remove a session from the active registry."""
async with self._lock:
self._sessions.pop(session_id, None)
async def count(self) -> int:
"""Return the number of active sessions."""
async with self._lock:
return len(self._sessions)