"""Chat management handlers for MAX surface.""" import uuid from adapter.max.store import ChatStore, RoomMeta class ChatHandler: def __init__(self, store: ChatStore): self.store = store def handle_new( self, max_chat_id: str, user_id: str, agent_id: str, name: str | None = None, *, workspace_path: str = "", ) -> str: platform_chat_id = str(uuid.uuid4()) room = RoomMeta( platform_chat_id=platform_chat_id, max_chat_id=max_chat_id, name=name or "New Chat", user_id=user_id, agent_id=agent_id, workspace_path=workspace_path, ) self.store.add_room(room) return platform_chat_id def handle_chats(self, user_id: str) -> str: rooms = self.store.list_rooms_for_user(user_id) if not rooms: return "Нет активных чатов." lines = [f" {i+1}. {r.name}" for i, r in enumerate(rooms)] return "\n".join(lines) def handle_rename(self, max_chat_id: str, new_name: str) -> str: room = self.store.get_room_by_max_chat_id(max_chat_id) if not room: return "Чат не найден." room.name = new_name return f"Чат переименован в: {new_name}" def handle_archive(self, max_chat_id: str) -> str: room = self.store.get_room_by_max_chat_id(max_chat_id) if not room: return "Чат не найден." self.store.remove_room(max_chat_id) return "Чат архивирован." def handle_clear(self, max_chat_id: str) -> str: room = self.store.get_room_by_max_chat_id(max_chat_id) if not room: return "Чат не найден." room.platform_chat_id = str(uuid.uuid4()) return "Контекст чата очищен."