Backup #1301

ID1301
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Application/PipelineStepService.php
Version3
Typ modified
Größe4.2 KB
Hash321ba1136ffef3741868af559601547bc8849836b7f4b0c3b1df2e9c79fb30fb
Datum2025-12-25 13:28:45
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

declare(strict_types=1);

namespace Application;

// @responsibility: Service für Pipeline-Step-Operationen (Toggle, Konfiguration)

use Infrastructure\AI\ModelRegistry;
use Infrastructure\Config\PipelineStepConfig;
use Infrastructure\Persistence\PipelineRepository;

final class PipelineStepService
{
    public function __construct(
        private PipelineRepository $repository,
        private ModelRegistry $modelRegistry
    ) {
    }

    /**
     * Toggle a step's enabled status.
     *
     * @return bool True if toggled successfully
     */
    public function toggleStep(int $pipelineId, int $stepId): bool
    {
        $pipeline = $this->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);
        }
    }
}

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
1429 8 modified 4.6 KB 2025-12-25 16:59
1426 7 modified 4.5 KB 2025-12-25 16:59
1418 6 modified 4.5 KB 2025-12-25 16:59
1415 5 modified 4.4 KB 2025-12-25 16:59
1414 4 modified 4.3 KB 2025-12-25 16:58
1301 3 modified 4.2 KB 2025-12-25 13:28
1300 2 modified 4.2 KB 2025-12-25 13:28
824 1 modified 4.1 KB 2025-12-23 08:09

← Zurück zur Übersicht