sessionRepo = $sessionRepo ?? new ChatSessionRepository(); $this->messageRepo = $messageRepo ?? new ChatMessageRepository(); } /** * Load session by UUID with all messages */ public function execute(string $uuid): ?ChatSessionDTO { $session = $this->sessionRepo->findByUuid($uuid); if ($session === null) { return null; } $messages = $this->messageRepo->findBySessionId($session['id']); return new ChatSessionDTO($session, $messages); } /** * Create a new session and return it */ public function createNew( string $model = 'claude-opus-4-5-20251101', array $collections = ['documents'], int $contextLimit = 5 ): ChatSessionDTO { $uuid = $this->sessionRepo->generateUuid(); $collectionsJson = json_encode($collections); $this->sessionRepo->create($uuid, $model, $collectionsJson, $contextLimit); // Load the freshly created session $session = $this->sessionRepo->findByUuid($uuid); return new ChatSessionDTO($session ?? [], []); } }