{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/ChatController.php",
"oldString": "use Infrastructure\\AI\\ModelRegistry;\nuse Infrastructure\\Formatting\\ChatMessageFormatter;\nuse UseCases\\Chat\\ExportChatSessionUseCase;\nuse UseCases\\Chat\\ManageChatSessionsUseCase;\nuse UseCases\\Chat\\SendChatMessageUseCase;\n\nclass ChatController extends Controller\n{\n public function __construct(\n private ManageChatSessionsUseCase $sessionsUseCase,\n private SendChatMessageUseCase $messageUseCase,\n private ChatMessageFormatter $formatter,\n private ExportChatSessionUseCase $exportUseCase,\n private ModelRegistry $modelRegistry\n ) {\n }",
"newString": "use Domain\\Service\\ModelRegistryInterface;\nuse Infrastructure\\Formatting\\ChatMessageFormatter;\nuse UseCases\\Chat\\CreateChatSessionUseCaseInterface;\nuse UseCases\\Chat\\DeleteChatSessionUseCaseInterface;\nuse UseCases\\Chat\\ExportChatSessionUseCase;\nuse UseCases\\Chat\\GetChatSessionUseCaseInterface;\nuse UseCases\\Chat\\SendChatMessageUseCase;\nuse UseCases\\Chat\\UpdateChatSessionUseCaseInterface;\n\nclass ChatController extends Controller\n{\n public function __construct(\n private CreateChatSessionUseCaseInterface $createSessionUseCase,\n private GetChatSessionUseCaseInterface $getSessionUseCase,\n private UpdateChatSessionUseCaseInterface $updateSessionUseCase,\n private DeleteChatSessionUseCaseInterface $deleteSessionUseCase,\n private SendChatMessageUseCase $messageUseCase,\n private ChatMessageFormatter $formatter,\n private ExportChatSessionUseCase $exportUseCase,\n private ModelRegistryInterface $modelRegistry\n ) {\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für KI-Chat (Sessions, Nachrichten, Export)\n\nuse Framework\\Controller;\nuse Infrastructure\\AI\\ModelRegistry;\nuse Infrastructure\\Formatting\\ChatMessageFormatter;\nuse UseCases\\Chat\\ExportChatSessionUseCase;\nuse UseCases\\Chat\\ManageChatSessionsUseCase;\nuse UseCases\\Chat\\SendChatMessageUseCase;\n\nclass ChatController extends Controller\n{\n public function __construct(\n private ManageChatSessionsUseCase $sessionsUseCase,\n private SendChatMessageUseCase $messageUseCase,\n private ChatMessageFormatter $formatter,\n private ExportChatSessionUseCase $exportUseCase,\n private ModelRegistry $modelRegistry\n ) {\n }\n\n public function index(): void\n {\n $uuid = $this->sessionsUseCase->createSession();\n header('Location: \/chat\/' . $uuid);\n exit;\n }\n\n public function show(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session === null) {\n header('Location: \/chat');\n exit;\n }\n\n \/\/ Convert entities to arrays for views\n $messages = $this->sessionsUseCase->getMessages($session->getId() ?? 0);\n $messagesArray = array_map(fn ($m) => $m->toArray(), $messages);\n\n $this->view('chat.index', [\n 'title' => $session->getTitle() ?? 'KI-Chat',\n 'session' => $session->toArray(),\n 'messages' => $messagesArray,\n 'sessions' => $this->sessionsUseCase->getAllSessionsWithStats(),\n 'authorProfiles' => $this->sessionsUseCase->getAuthorProfiles(),\n 'systemPrompts' => $this->sessionsUseCase->getSystemPrompts(),\n 'outputStructures' => $this->sessionsUseCase->getOutputStructures(),\n 'collections' => $this->sessionsUseCase->getAvailableCollections(),\n 'models' => $this->modelRegistry->getChatModels(),\n 'defaultModel' => $this->modelRegistry->getDefaultChatModel(),\n ]);\n }\n\n public function sessionList(): void\n {\n $this->view('chat.partials.session-list', [\n 'sessions' => $this->sessionsUseCase->getAllSessionsWithStats(),\n 'currentUuid' => $this->getString('current') ?: null,\n ]);\n }\n\n public function message(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session === null) {\n $this->view('chat.partials.error', ['error' => 'Session nicht gefunden.']);\n\n return;\n }\n\n $sessionId = $session->getId() ?? 0;\n $question = trim($_POST['message'] ?? '');\n $requestedModel = $_POST['model'] ?? $session->getModel();\n $model = $this->modelRegistry->isValid($requestedModel)\n ? $requestedModel\n : $this->modelRegistry->getDefaultChatModel();\n $sessionCollections = $session->getCollections();\n $collections = $_POST['collections'] ?? $sessionCollections;\n $contextLimit = (int) ($_POST['context_limit'] ?? $session->getContextLimit());\n $authorProfileId = (int) ($_POST['author_profile_id'] ?? $session->getAuthorProfileId() ?? 0);\n $systemPromptId = (int) ($_POST['system_prompt_id'] ?? $session->getSystemPromptId() ?? 1);\n $structureId = (int) ($_POST['structure_id'] ?? 0);\n $temperature = (float) ($_POST['temperature'] ?? $session->getTemperature());\n $maxTokens = (int) ($_POST['max_tokens'] ?? $session->getMaxTokens());\n\n if ($this->sessionsUseCase->settingsHaveChanged($session, $model, $collections, $contextLimit, $authorProfileId, $temperature, $maxTokens)) {\n $this->sessionsUseCase->updateSettings($sessionId, $model, $collections, $contextLimit, $authorProfileId, $temperature, $maxTokens);\n }\n\n if ($question === '') {\n $this->view('chat.partials.error', ['error' => 'Bitte gib eine Frage ein.']);\n\n return;\n }\n\n if (!empty($collections)) {\n $compatibility = $this->sessionsUseCase->validateCollectionCompatibility($collections);\n if (!$compatibility['valid']) {\n $this->view('chat.partials.error', [\n 'error' => 'Collection-Fehler: ' . $compatibility['error'],\n 'details' => 'Bitte wähle nur Collections mit gleichem Embedding-Modell.',\n ]);\n\n return;\n }\n }\n\n $qualityCheck = isset($_POST['quality_check']) && $_POST['quality_check'] === '1';\n\n $response = $this->messageUseCase->execute(\n sessionUuid: $uuid,\n message: $question,\n model: $model,\n collections: $collections,\n contextLimit: $contextLimit,\n authorProfileId: $authorProfileId,\n systemPromptId: $systemPromptId,\n temperature: $temperature,\n maxTokens: $maxTokens,\n structureId: $structureId,\n qualityCheck: $qualityCheck\n );\n\n if ($response->hasError()) {\n $this->view('chat.partials.error', ['error' => $response->getError()]);\n\n return;\n }\n\n $result = $response->toArray();\n $this->view('chat.partials.response', [\n 'question' => $question,\n 'result' => $result,\n 'model' => $model,\n 'formattedAnswer' => $this->formatter->formatAnswer($result['answer'] ?? ''),\n ]);\n }\n\n public function updateTitle(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session === null) {\n $this->notFound('Session nicht gefunden');\n }\n\n $title = $this->sessionsUseCase->updateTitle($session->getId() ?? 0, $_POST['title'] ?? '');\n $this->html(htmlspecialchars($title));\n }\n\n public function systemPrompt(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session === null) {\n $this->notFound('Session nicht gefunden');\n }\n\n $result = $this->sessionsUseCase->updateSystemPrompt($session->getId() ?? 0, $_POST['system_prompt'] ?? '');\n $this->view('chat.partials.success', ['message' => $result->message]);\n }\n\n public function getSystemPrompt(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session === null) {\n $this->notFound('Session nicht gefunden');\n }\n\n $this->view('chat.partials.system-prompt-modal', [\n 'session' => $session->toArray(),\n 'currentPrompt' => $session->getSystemPrompt() ?? '',\n 'defaultPrompt' => $this->sessionsUseCase->getDefaultSystemPrompt(),\n ]);\n }\n\n public function delete(string $uuid): void\n {\n $session = $this->sessionsUseCase->getSession($uuid);\n\n if ($session !== null) {\n $this->sessionsUseCase->deleteSession($session->getId() ?? 0);\n }\n\n $this->htmxRedirect('\/chat');\n }\n\n public function export(string $uuid): void\n {\n $format = $this->getString('format') ?: 'markdown';\n $filename = $this->exportUseCase->generateFilename($uuid, $format);\n\n if ($format === 'json') {\n $data = $this->exportUseCase->exportAsJson($uuid);\n\n if ($data === null) {\n $this->notFound('Session nicht gefunden');\n }\n\n $content = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);\n $this->download($content, $filename, 'application\/json');\n } else {\n $content = $this->exportUseCase->exportAsMarkdown($uuid);\n\n if ($content === null) {\n $this->notFound('Session nicht gefunden');\n }\n\n $this->download($content, $filename, 'text\/markdown');\n }\n }\n}\n",
"structuredPatch": [
{
"oldStart": 7,
"oldLines": 20,
"newStart": 7,
"newLines": 26,
"lines": [
" \/\/ @responsibility: HTTP-Endpunkte für KI-Chat (Sessions, Nachrichten, Export)",
" ",
" use Framework\\Controller;",
"-use Infrastructure\\AI\\ModelRegistry;",
"+use Domain\\Service\\ModelRegistryInterface;",
" use Infrastructure\\Formatting\\ChatMessageFormatter;",
"+use UseCases\\Chat\\CreateChatSessionUseCaseInterface;",
"+use UseCases\\Chat\\DeleteChatSessionUseCaseInterface;",
" use UseCases\\Chat\\ExportChatSessionUseCase;",
"-use UseCases\\Chat\\ManageChatSessionsUseCase;",
"+use UseCases\\Chat\\GetChatSessionUseCaseInterface;",
" use UseCases\\Chat\\SendChatMessageUseCase;",
"+use UseCases\\Chat\\UpdateChatSessionUseCaseInterface;",
" ",
" class ChatController extends Controller",
" {",
" public function __construct(",
"- private ManageChatSessionsUseCase $sessionsUseCase,",
"+ private CreateChatSessionUseCaseInterface $createSessionUseCase,",
"+ private GetChatSessionUseCaseInterface $getSessionUseCase,",
"+ private UpdateChatSessionUseCaseInterface $updateSessionUseCase,",
"+ private DeleteChatSessionUseCaseInterface $deleteSessionUseCase,",
" private SendChatMessageUseCase $messageUseCase,",
" private ChatMessageFormatter $formatter,",
" private ExportChatSessionUseCase $exportUseCase,",
"- private ModelRegistry $modelRegistry",
"+ private ModelRegistryInterface $modelRegistry",
" ) {",
" }",
" "
]
}
],
"userModified": false,
"replaceAll": false
}
}