import React, { useState, useEffect } from 'react'; import { backupAPI } from '../../api/backup-api'; interface PersonaPromotionInfo { persona_name: string; canonical_name: string; promotion_status: 'testing-only' | 'staging-ready' | 'production-ready' | 'fully-promoted' | 'needs-sync'; environments: { testing?: { persona_id: string; last_updated: string }; staging?: { persona_id: string; last_updated: string }; production?: { persona_id: string; last_updated: string }; }; differences?: { system_prompt_diff?: boolean; voice_settings_diff?: boolean; other_settings_diff?: boolean; }; } interface PromotionAnalysis { success: boolean; analysis?: { summary: { total_personas: number; testing_only: number; staging_ready: number; production_ready: number; fully_promoted: number; needs_sync: number; promotion_workflows_available: number; }; persona_details: PersonaPromotionInfo[]; promotion_workflows: { source_environment: string; target_environment: string; persona_name: string; promotion_type: string; changes_summary: string[]; }[]; }; error?: string; } interface PersonaPromotionAnalysisProps { onBack: () => void; } export function PersonaPromotionAnalysis({ onBack }: PersonaPromotionAnalysisProps) { const [analysis, setAnalysis] = useState(null); const [_loading, setLoading] = useState(false); const [error, setError] = useState(null); const [selectedEnvironments, setSelectedEnvironments] = useState<('testing' | 'staging' | 'production')[]>(['testing', 'staging', 'production']); useEffect(() => { void loadPromotionAnalysis(); }, [selectedEnvironments]); const loadPromotionAnalysis = async () => { try { setLoading(true); setError(null); const result = await backupAPI.analyzePromotionOpportunities(selectedEnvironments); setAnalysis(result); } catch (_err) { setError(_err instanceof Error ? _err.message : 'Failed to load promotion analysis'); } finally { setLoading(false); } }; const getStatusColor = (status: string) => { switch (status) { case 'testing-only': return 'bg-blue-100 text-blue-800'; case 'staging-ready': return 'bg-yellow-100 text-yellow-800'; case 'production-ready': return 'bg-purple-100 text-purple-800'; case 'fully-promoted': return 'bg-green-100 text-green-800'; case 'needs-sync': return 'bg-red-100 text-red-800'; default: return 'bg-gray-100 text-gray-800'; } }; const getEnvironmentBadge = (environment: string) => { const colors: Record = { testing: 'bg-blue-100 text-blue-800', staging: 'bg-yellow-100 text-yellow-800', production: 'bg-green-100 text-green-800' }; return colors[environment] || 'bg-gray-100 text-gray-800'; }; return (
{/* Header */}

Persona Promotion Analysis

{/* Environment Filter */}

Analyze Environments

{(['testing', 'staging', 'production'] as const).map((env) => ( ))}
{/* Error Display */} {error && (
{error}
)} {/* Loading State */} {loading && (
Analyzing persona promotion opportunities...
)} {/* Analysis Results */} {analysis && analysis.success && analysis.analysis && ( <> {/* Summary Cards */}
{analysis.analysis.summary.total_personas}
Total Personas
{analysis.analysis.summary.staging_ready}
Staging Ready
{analysis.analysis.summary.production_ready}
Production Ready
{analysis.analysis.summary.needs_sync}
Needs Sync
{/* Promotion Workflows */} {analysis.analysis.promotion_workflows.length > 0 && (

Recommended Promotion Workflows

{analysis.analysis.promotion_workflows.map((workflow, index) => (

{workflow.persona_name}

{workflow.source_environment} {workflow.target_environment} {workflow.promotion_type}
    {workflow.changes_summary.map((change, changeIndex) => (
  • {change}
  • ))}
))}
)} {/* Persona Details */} {analysis.analysis.persona_details.length > 0 && (

Persona Details

{analysis.analysis.persona_details.map((persona, index) => (

{persona.persona_name}

{persona.promotion_status.replace('-', ' ')}
Environments:
{Object.entries(persona.environments).map(([env, data]) => ( data && ( {env} ) ))}
{persona.differences && Object.values(persona.differences).some(diff => diff) && (
Configuration Differences Detected:
    {persona.differences.system_prompt_diff &&
  • • System prompt differences
  • } {persona.differences.voice_settings_diff &&
  • • Voice settings differences
  • } {persona.differences.other_settings_diff &&
  • • Other configuration differences
  • }
)}
))}
)} {/* No Data State */} {analysis.analysis.persona_details.length === 0 && (
No Personas Found

No personas were found in the selected environments or the Tavus API keys are not available.

Make sure the backup-workflows API server has access to the Tavus API keys.

)} )} {/* API Error State */} {analysis && !analysis.success && (
Analysis Failed

{analysis.error}

)}
); }