{{-- Page header --}}

{{ __('AI Configuration') }}

{{ __('Configure how AI responds across each channel. Provider and billing apply globally; behavior is per-channel.') }}

@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif {{-- ════════════════════════════════════════════════════════════════ PLAN STATUS — explains which premium AI features the user's current plan unlocks. Shown only when at least one premium feature is locked, so paying customers don't see clutter. ════════════════════════════════════════════════════════════════ --}} @php $allUnlocked = ($planFeatures['ai_own_key'] ?? false) && ($planFeatures['ai_per_channel'] ?? false) && ($planFeatures['ai_auto_escalation'] ?? false); @endphp @if(!$allUnlocked)

{{ __('Some AI features require a higher plan') }}

    @if(!($planFeatures['ai_own_key'] ?? false))
  • • {{ __('Use your own OpenAI / Anthropic API key — Pro plan') }}
  • @endif @if(!($planFeatures['ai_per_channel'] ?? false))
  • • {{ __('Per-channel AI customization (different prompts/modes for email vs WhatsApp etc.) — Pro plan') }}
  • @endif @if(!($planFeatures['ai_auto_escalation'] ?? false))
  • • {{ __('Auto-escalation to human when AI confidence is low — Pro plan') }}
  • @endif
{{ __('Upgrade plan →') }}
@endif {{-- ════════════════════════════════════════════════════════════════ GLOBAL: PROVIDER & BILLING ════════════════════════════════════════════════════════════════ --}}

{{ __('AI Provider & Billing') }}

{{ __('These settings apply to every channel — they control which LLM you pay for.') }}

@php $canOwnKey = $planFeatures['ai_own_key'] ?? false; @endphp
@if(!$canOwnKey)

{{ __('Locked to platform default. Upgrade to Pro to choose your own provider.') }}

@endif
@php // Source models directly from each provider's AVAILABLE_MODELS // constant — that's the same list AIManager hands to the API, // so the dropdown can't drift from what's actually callable. $providerClasses = [ 'openai' => \App\Services\AI\Providers\OpenAIProvider::class, 'anthropic' => \App\Services\AI\Providers\AnthropicProvider::class, 'gemini' => \App\Services\AI\Providers\GeminiProvider::class, 'mistral' => \App\Services\AI\Providers\MistralProvider::class, ]; $providerClass = $providerClasses[$provider] ?? $providerClasses['openai']; $availableModels = $providerClass::AVAILABLE_MODELS; @endphp @if(!$canOwnKey)

{{ __('Set by your administrator. Upgrade to Pro to override the model.') }}

@endif
@php $canOwnKey = $planFeatures['ai_own_key'] ?? false; @endphp

@if($canOwnKey) {{ __('When ON: your key is used (you pay the LLM bill). When OFF: platform admin keys are used (we pay).') }} @else {{ __('Your plan uses our platform API keys. Upgrade to Pro to plug in your own OpenAI / Anthropic key.') }} @endif

@if($useOwnKey && $canOwnKey)
@if($testResult) @php [$status, $msg] = explode(':', $testResult, 2) + [null, null]; @endphp

{{ $msg }}

@endif
@endif
$

{{ __('Set to 0 for unlimited. Applies across all channels.') }}

{{-- ════════════════════════════════════════════════════════════════ PER-CHANNEL CARDS One card per supported channel. Each has its own enable toggle, prompt, send mode, confidence threshold, escalation, and skip filters. Cards collapse when not expanded so the page stays scan-able. ════════════════════════════════════════════════════════════════ --}}

{{ __('Per-Channel AI Behavior') }}

{{ __('Each channel has its own AI settings. Click a card to expand.') }}

@foreach($channelMeta as $ch => $meta) @php $state = $channels[$ch] ?? []; $isExpanded = $expanded === $ch; $isOn = $state['enabled'] ?? false; // Plan-gate: lower plans get email-only customization. Other // channel cards are locked behind Pro. $channelLocked = $ch !== 'email' && !($planFeatures['ai_per_channel'] ?? false); $iconMap = [ 'email' => '', 'whatsapp' => '', 'sms' => '', 'live_chat' => '', 'telegram' => '', ]; @endphp
{{-- Card header — always visible --}}
{!! $iconMap[$ch] ?? '' !!}

{{ $meta['label'] }}

@if($channelLocked) {{ __('Pro') }} @endif

@if($channelLocked) {{ __('Upgrade to Pro to enable per-channel AI on') }} {{ $meta['label'] }}. @else {{ $meta['blurb'] }} @endif

{{-- Per-channel ENABLE toggle (disabled when locked) --}} @if(!$channelLocked) @endif
{{-- Expanded body --}} @if($isExpanded)
{{-- Send mode + Personality --}}
{{-- Custom prompt --}} @if(($state['personality_preset'] ?? '') === 'custom')
@endif
{{-- Confidence + reply length + delay --}}
{{-- Reliability filters (channel-specific behavior) --}}

{{ __('Reliability — when to SKIP replying') }}

{{ __("Avoid replying to messages that don't deserve a response. Email needs strict filters; chat usually doesn't.") }}

@if($ch === 'email') @endif
{{-- Conversation rules --}}
{{-- Auto-escalation (per-channel, plan-gated) --}} @php $canEscalate = $planFeatures['ai_auto_escalation'] ?? false; @endphp

{{ __('Escalate to human when unsure') }}

@if(!$canEscalate) {{ __('Pro') }} @endif

@if($canEscalate) {{ __('When confidence drops below the threshold: assign conversation, tag, and notify the assignee.') }} @else {{ __('Upgrade to Pro to auto-hand-off low-confidence conversations to a human teammate.') }} @endif

@if(($state['escalation_enabled'] ?? false) && $canEscalate)
@endif
@endif
@endforeach
{{-- Save --}}