"""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) -> 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, ) 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 "No active chats." 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 "Chat not found." room.name = new_name return f"Chat renamed to: {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 "Chat not found." self.store.remove_room(max_chat_id) return "Chat archived." 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 "Chat not found." room.platform_chat_id = str(uuid.uuid4()) return "Chat context cleared."