repository->findById($pipelineId); if ($pipeline === null) { return false; } foreach ($pipeline['steps'] as $step) { if ((int) $step['id'] === $stepId) { $this->repository->updateStep($stepId, [ 'enabled' => $step['enabled'] ? 0 : 1, ]); return true; } } return false; } /** * Update the model for a step. * * @return array{success: bool, error?: string, model?: string, label?: string} */ public function updateModel(int $pipelineId, int $stepId, string $model): array { $pipeline = $this->repository->findById($pipelineId); if ($pipeline === null) { return ['success' => false, 'error' => 'Pipeline nicht gefunden']; } $model = trim($model); if ($model === '' || !ModelConfig::isValid($model)) { return ['success' => false, 'error' => 'Ungültiges Modell']; } foreach ($pipeline['steps'] as $step) { if ((int) $step['id'] === $stepId) { $config = $step['config'] ?? []; // Determine provider from model $provider = ModelConfig::isLocal($model) ? 'ollama' : 'anthropic'; // Update config with new model $config['model'] = ModelConfig::isLocal($model) ? substr($model, 7) // Remove 'ollama:' prefix : $model; $config['provider'] = $provider; $this->repository->updateStep($stepId, [ 'config' => $config, ]); return [ 'success' => true, 'model' => $model, 'label' => ModelConfig::getLabel($model), ]; } } return ['success' => false, 'error' => 'Schritt nicht gefunden']; } /** * Update the collection for a step. * * @return array{success: bool, error?: string, collection?: string, label?: string} */ public function updateCollection(int $pipelineId, int $stepId, string $collection): array { $pipeline = $this->repository->findById($pipelineId); if ($pipeline === null) { return ['success' => false, 'error' => 'Pipeline nicht gefunden']; } $collection = trim($collection); $validCollections = array_keys(PipelineStepConfig::getCollections()); if ($collection === '' || !in_array($collection, $validCollections, true)) { return ['success' => false, 'error' => 'Ungültige Collection']; } foreach ($pipeline['steps'] as $step) { if ((int) $step['id'] === $stepId) { $config = $step['config'] ?? []; $config['collection'] = $collection; $this->repository->updateStep($stepId, [ 'config' => $config, ]); $collections = PipelineStepConfig::getCollections(); return [ 'success' => true, 'collection' => $collection, 'label' => $collections[$collection] ?? $collection, ]; } } return ['success' => false, 'error' => 'Schritt nicht gefunden']; } /** * Create default steps for a new pipeline. */ public function createDefaultSteps(int $pipelineId): void { foreach (PipelineStepConfig::getDefaultSteps() as $step) { $this->repository->addStep($pipelineId, $step); } } }