feat: implement AI styling foundation and billing scope rework
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-06 20:01:58 +01:00
parent df00deb0df
commit 36bed12ff9
80 changed files with 8944 additions and 49 deletions

View File

@@ -0,0 +1,154 @@
<?php
namespace App\Filament\Resources\AiStyles;
use App\Filament\Clusters\RareAdmin\RareAdminCluster;
use App\Filament\Resources\AiStyles\Pages\ManageAiStyles;
use App\Models\AiStyle;
use App\Services\Audit\SuperAdminAuditLogger;
use BackedEnum;
use Filament\Actions;
use Filament\Forms\Components\KeyValue;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
use UnitEnum;
class AiStyleResource extends Resource
{
protected static ?string $model = AiStyle::class;
protected static ?string $cluster = RareAdminCluster::class;
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-paint-brush';
protected static UnitEnum|string|null $navigationGroup = null;
protected static ?int $navigationSort = 31;
public static function getNavigationGroup(): UnitEnum|string|null
{
return __('admin.nav.platform');
}
public static function getNavigationLabel(): string
{
return 'AI Styles';
}
public static function form(Schema $schema): Schema
{
return $schema->schema([
Section::make('Style Basics')
->schema([
TextInput::make('key')
->required()
->maxLength(120)
->unique(ignoreRecord: true),
TextInput::make('name')
->required()
->maxLength(120),
TextInput::make('category')
->maxLength(50),
TextInput::make('sort')
->numeric()
->default(0)
->required(),
Toggle::make('is_active')
->default(true),
Toggle::make('is_premium')
->default(false),
Toggle::make('requires_source_image')
->default(true),
])
->columns(3),
Section::make('Provider Binding')
->schema([
Select::make('provider')
->options([
'runware' => 'runware.ai',
])
->required()
->default('runware'),
TextInput::make('provider_model')
->maxLength(120),
])
->columns(2),
Section::make('Prompts')
->schema([
Textarea::make('description')
->rows(2),
Textarea::make('prompt_template')
->rows(5),
Textarea::make('negative_prompt_template')
->rows(4),
]),
Section::make('Metadata')
->schema([
KeyValue::make('metadata')
->nullable(),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('sort')
->columns([
Tables\Columns\TextColumn::make('key')
->searchable()
->copyable(),
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('provider')
->badge(),
Tables\Columns\TextColumn::make('provider_model')
->toggleable(),
Tables\Columns\IconColumn::make('is_active')
->boolean(),
Tables\Columns\IconColumn::make('is_premium')
->boolean(),
Tables\Columns\TextColumn::make('sort')
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->since()
->toggleable(),
])
->filters([
Tables\Filters\TernaryFilter::make('is_active'),
Tables\Filters\TernaryFilter::make('is_premium'),
])
->actions([
Actions\EditAction::make()
->after(fn (array $data, AiStyle $record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
'updated',
$record,
SuperAdminAuditLogger::fieldsMetadata(array_keys($data)),
static::class
)),
Actions\DeleteAction::make()
->after(fn (AiStyle $record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
'deleted',
$record,
source: static::class
)),
])
->bulkActions([
Actions\DeleteBulkAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => ManageAiStyles::route('/'),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Filament\Resources\AiStyles\Pages;
use App\Filament\Resources\AiStyles\AiStyleResource;
use App\Services\Audit\SuperAdminAuditLogger;
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;
class ManageAiStyles extends ManageRecords
{
protected static string $resource = AiStyleResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->after(fn (array $data, $record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
'created',
$record,
SuperAdminAuditLogger::fieldsMetadata(array_keys($data)),
static::class
)),
];
}
}

View File

@@ -465,6 +465,7 @@ class PackageResource extends Resource
'unlimited_sharing' => 'Unbegrenztes Teilen',
'no_watermark' => 'Kein Wasserzeichen',
'custom_branding' => 'Eigenes Branding',
'ai_styling' => 'AI-Styling',
'custom_tasks' => 'Eigene Aufgaben',
'reseller_dashboard' => 'Reseller-Dashboard',
'advanced_analytics' => 'Erweiterte Analytics',

View File

@@ -0,0 +1,177 @@
<?php
namespace App\Filament\SuperAdmin\Pages;
use App\Filament\Clusters\RareAdmin\RareAdminCluster;
use App\Models\AiEditingSetting;
use App\Services\Audit\SuperAdminAuditLogger;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class AiEditingSettingsPage extends Page
{
protected static null|string|\BackedEnum $navigationIcon = 'heroicon-o-sparkles';
protected static ?string $cluster = RareAdminCluster::class;
protected string $view = 'filament.super-admin.pages.ai-editing-settings-page';
protected static null|string|\UnitEnum $navigationGroup = null;
protected static ?int $navigationSort = 30;
public static function getNavigationGroup(): \UnitEnum|string|null
{
return __('admin.nav.platform');
}
public static function getNavigationLabel(): string
{
return 'AI Editing Settings';
}
public bool $is_enabled = true;
public string $default_provider = 'runware';
public ?string $fallback_provider = null;
public string $runware_mode = 'live';
public bool $queue_auto_dispatch = false;
public string $queue_name = 'default';
public int $queue_max_polls = 6;
/**
* @var array<int, string>
*/
public array $blocked_terms = [];
public ?string $status_message = null;
public function mount(): void
{
$settings = AiEditingSetting::current();
$this->is_enabled = (bool) $settings->is_enabled;
$this->default_provider = (string) ($settings->default_provider ?: 'runware');
$this->fallback_provider = $settings->fallback_provider ? (string) $settings->fallback_provider : null;
$this->runware_mode = (string) ($settings->runware_mode ?: 'live');
$this->queue_auto_dispatch = (bool) $settings->queue_auto_dispatch;
$this->queue_name = (string) ($settings->queue_name ?: 'default');
$this->queue_max_polls = max(1, (int) ($settings->queue_max_polls ?: 6));
$this->blocked_terms = array_values(array_filter(array_map(
static fn (mixed $term): string => trim((string) $term),
(array) $settings->blocked_terms
)));
$this->status_message = $settings->status_message ? (string) $settings->status_message : null;
}
public function form(Schema $schema): Schema
{
return $schema->schema([
Section::make('Global Availability')
->schema([
Forms\Components\Toggle::make('is_enabled')
->label('Enable AI editing globally'),
Forms\Components\Textarea::make('status_message')
->label('Disabled message')
->maxLength(255)
->rows(2)
->helperText('Shown to guest and tenant clients when the feature is disabled.')
->nullable(),
]),
Section::make('Provider')
->schema([
Forms\Components\Select::make('default_provider')
->label('Default provider')
->options([
'runware' => 'runware.ai',
])
->required(),
Forms\Components\TextInput::make('fallback_provider')
->label('Fallback provider')
->maxLength(40)
->helperText('Reserved for provider failover.'),
Forms\Components\Select::make('runware_mode')
->label('Runware mode')
->options([
'live' => 'Live API',
'fake' => 'Fake mode (internal testing)',
])
->required(),
])
->columns(2),
Section::make('Queue Orchestration')
->schema([
Forms\Components\Toggle::make('queue_auto_dispatch')
->label('Auto-dispatch jobs after request creation'),
Forms\Components\TextInput::make('queue_name')
->label('Queue name')
->required()
->maxLength(60),
Forms\Components\TextInput::make('queue_max_polls')
->label('Max provider polls')
->numeric()
->minValue(1)
->maxValue(50)
->required(),
])
->columns(2),
Section::make('Prompt Safety')
->schema([
Forms\Components\TagsInput::make('blocked_terms')
->label('Blocked prompt terms')
->helperText('Case-insensitive term match before queue dispatch.')
->placeholder('Add blocked term'),
]),
]);
}
public function save(): void
{
$this->validate();
$settings = AiEditingSetting::query()->firstOrNew(['id' => 1]);
$settings->is_enabled = $this->is_enabled;
$settings->default_provider = $this->default_provider;
$settings->fallback_provider = $this->nullableString($this->fallback_provider);
$settings->runware_mode = $this->runware_mode;
$settings->queue_auto_dispatch = $this->queue_auto_dispatch;
$settings->queue_name = $this->queue_name;
$settings->queue_max_polls = max(1, $this->queue_max_polls);
$settings->blocked_terms = array_values(array_filter(array_map(
static fn (mixed $term): string => trim((string) $term),
$this->blocked_terms
)));
$settings->status_message = $this->nullableString($this->status_message);
$settings->save();
$changed = $settings->getChanges();
if ($changed !== []) {
app(SuperAdminAuditLogger::class)->record(
'ai_editing.settings_updated',
$settings,
SuperAdminAuditLogger::fieldsMetadata(array_keys($changed)),
source: static::class
);
}
Notification::make()
->title('AI editing settings saved.')
->success()
->send();
}
private function nullableString(?string $value): ?string
{
$trimmed = trim((string) $value);
return $trimmed !== '' ? $trimmed : null;
}
}