{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/StreamingChatMessageUseCase.php",
"offset": 134,
"limit": 100
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Chat\/StreamingChatMessageUseCase.php",
"content": "\n \/\/ Step 9: LLM Request\n $isOllama = str_starts_with($model, 'ollama:');\n $isClaude = str_starts_with($model, 'claude-');\n $hasContext = $context !== '';\n $modelLabel = $isOllama ? substr($model, 7) : $model;\n\n $this->emit('llm', \"Anfrage an {$modelLabel}...\");\n $this->startStep();\n $llmStart = microtime(true);\n\n try {\n if ($isClaude) {\n $userPrompt = $hasContext\n ? $this->claude->buildRagPrompt($message, $context)\n : $message;\n\n $effectiveSystemPrompt = $systemPrompt ?? ($hasContext\n ? $this->claude->getDefaultSystemPrompt()\n : 'Du bist ein hilfreicher Assistent. Antworte auf Deutsch, präzise und hilfreich.');\n\n if ($stylePrompt !== null && $stylePrompt !== '') {\n $effectiveSystemPrompt .= \"\\n\\n\" . $stylePrompt;\n }\n\n $llmResponse = $this->claude->ask($userPrompt, $effectiveSystemPrompt, $model, $maxTokens, $temperature);\n $answer = $llmResponse['text'];\n $usage = $llmResponse['usage'];\n } elseif ($isOllama) {\n $ollamaModel = substr($model, 7);\n $instructions = [];\n if ($systemPrompt !== null && $systemPrompt !== '') {\n $instructions[] = $systemPrompt;\n }\n if ($stylePrompt !== null && $stylePrompt !== '') {\n $instructions[] = $stylePrompt;\n }\n $instructionBlock = $instructions !== [] ? implode(\"\\n\\n\", $instructions) . \"\\n\\n\" : '';\n\n $userPrompt = $hasContext\n ? sprintf(\"%sKontext aus den Dokumenten:\\n\\n%s\\n\\n---\\n\\nFrage: %s\", $instructionBlock, $context, $message)\n : $instructionBlock . $message;\n\n $answer = $this->ollama->generate($userPrompt, $ollamaModel, $temperature);\n $usage = null;\n } else {\n $this->emit('error', \"Unbekanntes Modell: {$model}\");\n\n return ChatResponse::error(\"Unknown model \\\"{$model}\\\".\");\n }\n } catch (\\RuntimeException $e) {\n $this->emit('error', 'LLM-Fehler: ' . $e->getMessage());\n\n return ChatResponse::error('LLM request failed: ' . $e->getMessage());\n }\n\n $llmDuration = (int) round((microtime(true) - $llmStart) * Constants::MS_PER_SECOND);\n $tokenInfo = '';\n if ($usage !== null) {\n $tokenInfo = \" ({$usage['input_tokens']} in \/ {$usage['output_tokens']} out)\";\n }\n $this->emit('llm_done', \"Antwort erhalten{$tokenInfo}\", $llmDuration);\n\n \/\/ Step 10: Extract sources\n $this->emit('sources', 'Quellen extrahieren...');\n $this->startStep();\n $sources = $this->extractSources($searchResults);\n $this->endStep('sources_done', count($sources) . ' Quellen extrahiert');\n\n \/\/ Step 11: Save assistant message\n $this->emit('save_assistant', 'Antwort speichern...');\n $this->startStep();\n\n \/** @var array<int, non-empty-string> $sourcesForStorage *\/\n $sourcesForStorage = array_map(\n static fn (array $source): string => json_encode($source, JSON_THROW_ON_ERROR),\n $sources\n );\n\n $collectionsJson = json_encode($collections);\n $this->messageRepo->save(\n sessionId: $sessionId,\n role: 'assistant',\n content: $answer,\n model: $model,\n tokensInput: $usage['input_tokens'] ?? null,\n tokensOutput: $usage['output_tokens'] ?? null,\n sources: $sourcesForStorage,\n startMicrotime: $llmStart,\n endMicrotime: microtime(true),\n authorProfileId: $authorProfileId > 0 ? $authorProfileId : null,\n systemPromptId: $systemPromptId > 0 ? $systemPromptId : null,\n collectionsJson: $collectionsJson,\n contextLimit: $contextLimit\n );\n $this->endStep('save_assistant_done', 'Antwort gespeichert');\n\n \/\/ Step 12: Quality check\n $qualityValidation = null;\n if ($qualityCheck) {",
"numLines": 100,
"startLine": 134,
"totalLines": 374
}
}
}