<?php
declare(strict_types=1);
namespace UseCases\Chat;
// @responsibility: Retrieves chat session data
use Domain\Entity\ChatMessage;
use Domain\Entity\ChatSession;
use Domain\Repository\ChatMessageRepositoryInterface;
use Domain\Repository\ChatSessionRepositoryInterface;
use Domain\Repository\CollectionRepositoryInterface;
use Domain\Repository\ContentConfigRepositoryInterface;
final class GetChatSessionUseCase implements GetChatSessionUseCaseInterface
{
private ?array $collectionsCache = null;
public function __construct(
private ChatSessionRepositoryInterface $sessionRepo,
private ChatMessageRepositoryInterface $messageRepo,
private ContentConfigRepositoryInterface $configRepo,
private CollectionRepositoryInterface $collectionRepo
) {
}
public function getSession(string $uuid): ?ChatSession
{
return $this->sessionRepo->findByUuid($uuid);
}
/**
* @return array<int, ChatSession>
*/
public function getAllSessions(int $limit = 50): array
{
return $this->sessionRepo->findAll($limit);
}
/**
* @return array<int, array<string, mixed>>
*/
public function getAllSessionsWithStats(int $limit = 50): array
{
return $this->sessionRepo->findAllWithStats($limit);
}
/**
* @return array<int, ChatMessage>
*/
public function getMessages(int $sessionId): array
{
return $this->messageRepo->findBySessionId($sessionId);
}
public function getAuthorProfiles(): array
{
return $this->configRepo->getAuthorProfiles();
}
public function getSystemPrompts(): array
{
return $this->configRepo->getSystemPrompts();
}
public function getOutputStructures(): array
{
return $this->configRepo->getStructures();
}
public function getStructure(int $id): ?array
{
return $this->configRepo->getStructure($id);
}
public function getAvailableCollections(): array
{
if ($this->collectionsCache === null) {
$this->collectionsCache = $this->collectionRepo->getSearchable();
if ($this->collectionsCache === []) {
$this->collectionsCache = [
['collection_id' => 'documents', 'display_name' => 'Dokumente', 'points_count' => 0, 'vector_size' => 1024],
];
}
}
return $this->collectionsCache;
}
public function getDefaultSystemPrompt(): string
{
return <<<'PROMPT'
Du bist ein hilfreicher Assistent für Fragen zu systemischem Teamcoaching und Teamentwicklung.
Beantworte die Frage des Nutzers basierend auf dem bereitgestellten Kontext.
- Antworte auf Deutsch
- Sei präzise und hilfreich
- Wenn der Kontext die Frage nicht beantwortet, sage das ehrlich
- Verweise auf die Quellen wenn passend
PROMPT;
}
}