Protokoll #7655

ID7655
Zeitstempel2025-12-23 08:20:56.925565
Clientroot
IP145.224.96.190
Modellclaude-sonnet-4-20250514
Statuspending
Tokens1,308 (Input: 1,308, Output: 0)
Dauer-
Request-Zeit2025-12-23 08:20:56.925565
Response-Zeit-

Request

{
    "event": "PostToolUse",
    "raw_data": {
        "session_id": "18ef5bf3-e872-4052-897e-53d6dc45b0b9",
        "transcript_path": "\/root\/.claude\/projects\/-var-www\/18ef5bf3-e872-4052-897e-53d6dc45b0b9.jsonl",
        "cwd": "\/var\/www\/dev.campus.systemische-tools.de",
        "permission_mode": "acceptEdits",
        "hook_event_name": "PostToolUse",
        "tool_name": "Read",
        "tool_input": {
            "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Task\/ExecuteAITaskUseCase.php"
        },
        "tool_response": {
            "type": "text",
            "file": {
                "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Task\/ExecuteAITaskUseCase.php",
                "content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Task;\n\n\/\/ @responsibility: Führt Tasks mit KI-Modellen aus (Ollama\/Anthropic)\n\nuse Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskResult;\nuse Domain\\Repository\\TaskRepositoryInterface;\nuse Domain\\ValueObject\\AssigneeType;\nuse Domain\\ValueObject\\TaskStatus;\nuse Infrastructure\\AI\\AIClientInterface;\nuse Infrastructure\\AI\\AnthropicClient;\nuse Infrastructure\\AI\\OllamaClient;\nuse Infrastructure\\Config\\CredentialService;\n\nclass ExecuteAITaskUseCase\n{\n    public function __construct(\n        private TaskRepositoryInterface $taskRepository,\n        private SaveTaskResultUseCase $saveResultUseCase,\n        private UpdateTaskStatusUseCase $updateStatusUseCase\n    ) {}\n\n    public function execute(int $taskId, array $options = []): TaskResult\n    {\n        $task = $this->taskRepository->find($taskId);\n        if ($task === null) {\n            throw new \\InvalidArgumentException(\"Task {$taskId} not found\");\n        }\n\n        $executorType = AssigneeType::from($options['executor_type'] ?? 'ollama');\n        $client = $this->getClient($executorType, $options);\n\n        if (!$client->isAvailable()) {\n            throw new \\RuntimeException(\"{$executorType->label()} is not available\");\n        }\n\n        if ($task->getStatus() === TaskStatus::PENDING) {\n            $this->updateStatusUseCase->startTask($taskId, $client->getClientName(), 'ai');\n        }\n\n        $prompt = $this->buildPrompt($task, $options);\n        $response = $client->execute($prompt, $options);\n\n        $resultData = [\n            'executor' => $client->getClientName(),\n            'executor_type' => $executorType->value,\n            'model_name' => $response->getModel() !== '' ? $response->getModel() : $client->getModelName(),\n            'request' => $prompt,\n            'response' => $response->getContent(),\n            'tokens_input' => $response->getTokensInput(),\n            'tokens_output' => $response->getTokensOutput(),\n            'duration_ms' => $response->getDurationMs(),\n            'status' => $response->isSuccess() ? 'success' : 'error',\n        ];\n\n        if (!$response->isSuccess()) {\n            $resultData['error_message'] = $response->getErrorMessage();\n        }\n\n        $metadata = $response->getMetadata();\n        if (isset($metadata['cost_usd'])) {\n            $resultData['cost_usd'] = $metadata['cost_usd'];\n        }\n\n        if (isset($options['assignment_id'])) {\n            $resultData['assignment_id'] = $options['assignment_id'];\n        }\n\n        $result = $this->saveResultUseCase->execute($taskId, $resultData);\n\n        if ($response->isSuccess() && ($options['auto_complete'] ?? false)) {\n            $this->updateStatusUseCase->completeTask($taskId, $client->getClientName(), 'ai');\n        }\n\n        return $result;\n    }\n\n    private function getClient(AssigneeType $type, array $options): AIClientInterface\n    {\n        return match ($type) {\n            AssigneeType::OLLAMA => new OllamaClient(\n                CredentialService::getOllamaHost(),\n                $options['model'] ?? 'mistral'\n            ),\n            AssigneeType::ANTHROPIC_API => new AnthropicClient(\n                $options['api_key'] ?? '',\n                $options['model'] ?? 'claude-sonnet-4-20250514'\n            ),\n            default => throw new \\InvalidArgumentException(\"Unsupported executor type: {$type->value}\")\n        };\n    }\n\n    private function buildPrompt(Task $task, array $options): string\n    {\n        $prompt = $task->getTitle();\n\n        if ($task->getDescription() !== null) {\n            $prompt .= \"\\n\\n\" . $task->getDescription();\n        }\n\n        if (isset($options['additional_context'])) {\n            $prompt .= \"\\n\\n\" . $options['additional_context'];\n        }\n\n        return $prompt;\n    }\n\n    public function executeWithOllama(int $taskId, string $model = 'mistral', array $options = []): TaskResult\n    {\n        return $this->execute($taskId, array_merge($options, [\n            'executor_type' => 'ollama',\n            'model' => $model,\n        ]));\n    }\n\n    public function executeWithAnthropic(int $taskId, string $model = 'claude-sonnet-4-20250514', array $options = []): TaskResult\n    {\n        return $this->execute($taskId, array_merge($options, [\n            'executor_type' => 'anthropic_api',\n            'model' => $model,\n        ]));\n    }\n}\n",
                "numLines": 128,
                "startLine": 1,
                "totalLines": 128
            }
        },
        "tool_use_id": "toolu_01JSFPEseZPUDgQKjaZbPUVE"
    }
}

Response

-
← Vorheriger Zur Liste Nächster →