Protokoll #7197
| ID | 7197 |
|---|---|
| Zeitstempel | 2025-12-23 07:55:29.354407 |
| Client | root |
| IP | Warning: Undefined array key "request_ip" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13 Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13 |
| Modell | claude-sonnet-4-20250514 |
| Status | completed |
| Tokens | 2,874 (Input: 0, Output: 0) |
| Dauer | 95 ms |
| Request-Zeit | Warning: Undefined array key "request_timestamp" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 18 |
| Response-Zeit | - |
Warning: Undefined array key "error_message" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 22
Request
{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/ManageChatSessionsUseCase.php",
"old_string": "<?php\n\nnamespace UseCases\\Chat;\n\nuse Infrastructure\\AI\\ModelConfig;\nuse Infrastructure\\Persistence\\ChatMessageRepository;\nuse Infrastructure\\Persistence\\ChatSessionRepository;\nuse Infrastructure\\Persistence\\CollectionRepository;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase",
"new_string": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Chat;\n\n\/\/ @responsibility: Verwaltet Chat-Sessions (CRUD, Einstellungen, Collections)\n\nuse Infrastructure\\AI\\ModelConfig;\nuse Infrastructure\\Persistence\\ChatMessageRepository;\nuse Infrastructure\\Persistence\\ChatSessionRepository;\nuse Infrastructure\\Persistence\\CollectionRepository;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase"
}
}
Response
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/ManageChatSessionsUseCase.php",
"oldString": "<?php\n\nnamespace UseCases\\Chat;\n\nuse Infrastructure\\AI\\ModelConfig;\nuse Infrastructure\\Persistence\\ChatMessageRepository;\nuse Infrastructure\\Persistence\\ChatSessionRepository;\nuse Infrastructure\\Persistence\\CollectionRepository;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase",
"newString": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Chat;\n\n\/\/ @responsibility: Verwaltet Chat-Sessions (CRUD, Einstellungen, Collections)\n\nuse Infrastructure\\AI\\ModelConfig;\nuse Infrastructure\\Persistence\\ChatMessageRepository;\nuse Infrastructure\\Persistence\\ChatSessionRepository;\nuse Infrastructure\\Persistence\\CollectionRepository;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase",
"originalFile": "<?php\n\nnamespace UseCases\\Chat;\n\nuse Infrastructure\\AI\\ModelConfig;\nuse Infrastructure\\Persistence\\ChatMessageRepository;\nuse Infrastructure\\Persistence\\ChatSessionRepository;\nuse Infrastructure\\Persistence\\CollectionRepository;\nuse Infrastructure\\Persistence\\ContentConfigRepository;\nuse Infrastructure\\Validation\\CollectionValidator;\n\nfinal class ManageChatSessionsUseCase\n{\n private ChatSessionRepository $sessionRepo;\n private ChatMessageRepository $messageRepo;\n private ContentConfigRepository $configRepo;\n private CollectionRepository $collectionRepo;\n private CollectionValidator $collectionValidator;\n private ?array $collectionsCache = null;\n\n public function __construct(\n ?ChatSessionRepository $sessionRepo = null,\n ?ChatMessageRepository $messageRepo = null,\n ?ContentConfigRepository $configRepo = null,\n ?CollectionRepository $collectionRepo = null,\n ?CollectionValidator $collectionValidator = null\n ) {\n $this->sessionRepo = $sessionRepo ?? new ChatSessionRepository();\n $this->messageRepo = $messageRepo ?? new ChatMessageRepository();\n $this->configRepo = $configRepo ?? new ContentConfigRepository();\n $this->collectionRepo = $collectionRepo ?? new CollectionRepository();\n $this->collectionValidator = $collectionValidator ?? new CollectionValidator($this->collectionRepo);\n }\n\n public function createSession(): string\n {\n $uuid = $this->sessionRepo->generateUuid();\n $this->sessionRepo->create($uuid, 'claude-opus-4-5-20251101', '[\"documents\"]', 5);\n\n return $uuid;\n }\n\n public function getSession(string $uuid): ?array\n {\n return $this->sessionRepo->findByUuid($uuid);\n }\n\n public function getAllSessions(int $limit = 50): array\n {\n return $this->sessionRepo->findAll($limit);\n }\n\n public function getMessages(int $sessionId): array\n {\n return $this->messageRepo->findBySessionId($sessionId);\n }\n\n public function updateTitle(int $sessionId, string $title): string\n {\n $title = trim($title);\n\n if ($title === '') {\n $title = 'Neuer Chat';\n }\n\n $title = mb_substr($title, 0, 100);\n $this->sessionRepo->updateTitle($sessionId, $title);\n\n return $title;\n }\n\n public function updateSettings(\n int $sessionId,\n string $model,\n array $collections,\n int $contextLimit,\n int $authorProfileId,\n float $temperature,\n int $maxTokens\n ): void {\n $model = ModelConfig::validate($model);\n $collections = $this->validateCollections($collections);\n $contextLimit = $this->validateContextLimit($contextLimit);\n $authorProfileId = $this->validateAuthorProfileId($authorProfileId);\n $temperature = $this->validateTemperature($temperature);\n $maxTokens = $this->validateMaxTokens($maxTokens);\n\n $this->sessionRepo->updateSettings(\n $sessionId,\n $model,\n $collections,\n $contextLimit,\n $authorProfileId > 0 ? $authorProfileId : null,\n $temperature,\n $maxTokens\n );\n }\n\n public function updateSystemPrompt(int $sessionId, string $systemPrompt): ChatSessionResult\n {\n $maxLength = 2000;\n $wasTruncated = mb_strlen($systemPrompt) > $maxLength;\n $systemPrompt = trim(mb_substr($systemPrompt, 0, $maxLength));\n\n $this->logSystemPromptChange($systemPrompt, $wasTruncated);\n $this->sessionRepo->updateSystemPrompt($sessionId, $systemPrompt);\n\n return ChatSessionResult::success('System-Prompt gespeichert.');\n }\n\n public function deleteSession(int $sessionId): void\n {\n $this->sessionRepo->delete($sessionId);\n }\n\n public function getAuthorProfiles(): array\n {\n return $this->configRepo->getAuthorProfiles();\n }\n\n public function getSystemPrompts(): array\n {\n return $this->configRepo->getSystemPrompts();\n }\n\n public function getOutputStructures(): array\n {\n return $this->configRepo->getStructures();\n }\n\n public function getStructure(int $id): ?array\n {\n return $this->configRepo->getStructure($id);\n }\n\n public function getAvailableCollections(): array\n {\n if ($this->collectionsCache === null) {\n $this->collectionsCache = $this->collectionRepo->getSearchable();\n\n if ($this->collectionsCache === []) {\n $this->collectionsCache = [\n ['collection_id' => 'documents', 'display_name' => 'Dokumente', 'points_count' => 0, 'vector_size' => 1024],\n ];\n }\n }\n\n return $this->collectionsCache;\n }\n\n public function validateCollectionCompatibility(array $collectionIds): array\n {\n if (empty($collectionIds)) {\n return ['valid' => true, 'error' => null];\n }\n\n $result = $this->collectionValidator->validateSelection($collectionIds);\n\n return [\n 'valid' => $result->isValid(),\n 'error' => $result->getError(),\n ];\n }\n\n public function getDefaultSystemPrompt(): string\n {\n return <<<'PROMPT'\n Du bist ein hilfreicher Assistent für Fragen zu systemischem Teamcoaching und Teamentwicklung.\n\n Beantworte die Frage des Nutzers basierend auf dem bereitgestellten Kontext.\n - Antworte auf Deutsch\n - Sei präzise und hilfreich\n - Wenn der Kontext die Frage nicht beantwortet, sage das ehrlich\n - Verweise auf die Quellen wenn passend\n PROMPT;\n }\n\n public function settingsHaveChanged(array $session, string $model, array $collections, int $contextLimit, int $authorProfileId, float $temperature, int $maxTokens): bool\n {\n $currentModel = $session['model'] ?? '';\n $currentCollections = $session['collections'] ?? '[\"documents\"]';\n $currentLimit = (int) ($session['context_limit'] ?? 5);\n $currentProfileId = (int) ($session['author_profile_id'] ?? 0);\n $currentTemperature = (float) ($session['temperature'] ?? 0.7);\n $currentMaxTokens = (int) ($session['max_tokens'] ?? 4096);\n\n $collectionsJson = json_encode($collections);\n\n return $model !== $currentModel\n || $collectionsJson !== $currentCollections\n || $contextLimit !== $currentLimit\n || $authorProfileId !== $currentProfileId\n || $temperature !== $currentTemperature\n || $maxTokens !== $currentMaxTokens;\n }\n\n private function validateCollections(array|string $collections): array\n {\n $availableIds = array_column($this->getAvailableCollections(), 'collection_id');\n\n if (is_string($collections)) {\n $collections = [$collections];\n }\n\n $valid = array_filter($collections, fn ($c) => in_array($c, $availableIds, true));\n\n return array_values($valid);\n }\n\n private function validateContextLimit(int $limit): int\n {\n $allowedLimits = [3, 5, 10, 15];\n\n return in_array($limit, $allowedLimits, true) ? $limit : 5;\n }\n\n private function validateAuthorProfileId(int $profileId): int\n {\n if ($profileId === 0) {\n return 0;\n }\n\n $profile = $this->configRepo->getAuthorProfile($profileId);\n\n return $profile !== null ? $profileId : 0;\n }\n\n private function validateTemperature(float $temperature): float\n {\n return max(0.0, min(1.0, $temperature));\n }\n\n private function validateMaxTokens(int $maxTokens): int\n {\n $allowedValues = [1024, 2048, 4096, 8192];\n\n return in_array($maxTokens, $allowedValues, true) ? $maxTokens : 4096;\n }\n\n private function logSystemPromptChange(string $prompt, bool $wasTruncated): void\n {\n $logData = [\n 'prompt_length' => mb_strlen($prompt),\n 'truncated' => $wasTruncated,\n 'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',\n 'timestamp' => date('c'),\n ];\n\n try {\n $devDb = \\Infrastructure\\Config\\DatabaseFactory::dev();\n $stmt = $devDb->prepare(\n \"INSERT INTO mcp_log (tool, operation, parameters, result, logged_at)\n VALUES ('chat', 'system_prompt_change', :params, 'logged', NOW())\"\n );\n $stmt->execute(['params' => json_encode($logData)]);\n } catch (\\Exception $e) {\n \/\/ Silently fail\n }\n }\n}\n",
"structuredPatch": [
{
"oldStart": 1,
"oldLines": 7,
"newStart": 1,
"newLines": 11,
"lines": [
" <?php",
" ",
"+declare(strict_types=1);",
"+",
" namespace UseCases\\Chat;",
" ",
"+\/\/ @responsibility: Verwaltet Chat-Sessions (CRUD, Einstellungen, Collections)",
"+",
" use Infrastructure\\AI\\ModelConfig;",
" use Infrastructure\\Persistence\\ChatMessageRepository;",
" use Infrastructure\\Persistence\\ChatSessionRepository;"
]
}
],
"userModified": false,
"replaceAll": false
}
}