/** * Enhanced Quality Badges System * Badges are earned based on prompt performance and quality */ export type QualityBadgeId = | 'verified-quality' | 'framework-compliant' | 'high-performance' | 'community-favorite' | 'trending' | 'most-remixed' | 'top-rated' | 'speed-demon' | 'token-efficient' | 'beginner-friendly' export interface QualityBadge { id: QualityBadgeId name: string description: string icon: string color: string bgColor: string criteria: string } export const QUALITY_BADGES: Record = { 'verified-quality': { id: 'verified-quality', name: 'Verified Quality', description: '95%+ success rate across all runs', icon: 'check-circle', color: 'text-blue-500', bgColor: 'bg-blue-100 dark:bg-blue-900/30', criteria: 'successRate >= 0.95' }, 'framework-compliant': { id: 'framework-compliant', name: 'Framework Compliant', description: 'Uses a recognized prompting framework', icon: 'clipboard-list', color: 'text-purple-500', bgColor: 'bg-purple-100 dark:bg-purple-900/30', criteria: 'usesFramework === true' }, 'high-performance': { id: 'high-performance', name: 'High Performance', description: 'Fast response times and efficient token usage', icon: 'zap', color: 'text-yellow-500', bgColor: 'bg-yellow-100 dark:bg-yellow-900/30', criteria: 'avgResponseTime < 3000 && tokenEfficiency > 0.8' }, 'community-favorite': { id: 'community-favorite', name: 'Community Favorite', description: 'Loved by the community with 50+ stars', icon: 'heart', color: 'text-red-500', bgColor: 'bg-red-100 dark:bg-red-900/30', criteria: 'stars >= 50' }, 'trending': { id: 'trending', name: 'Trending', description: 'Rapidly gaining popularity this week', icon: 'flame', color: 'text-orange-500', bgColor: 'bg-orange-100 dark:bg-orange-900/30', criteria: 'weeklyGrowth > 100%' }, 'most-remixed': { id: 'most-remixed', name: 'Most Remixed', description: 'Inspired 10+ remixes from the community', icon: 'shuffle', color: 'text-indigo-500', bgColor: 'bg-indigo-100 dark:bg-indigo-900/30', criteria: 'remixCount >= 10' }, 'top-rated': { id: 'top-rated', name: 'Top Rated', description: 'In the top 10% of all prompts', icon: 'star', color: 'text-amber-500', bgColor: 'bg-amber-100 dark:bg-amber-900/30', criteria: 'percentile >= 90' }, 'speed-demon': { id: 'speed-demon', name: 'Speed Demon', description: 'Average response time under 2 seconds', icon: 'rocket', color: 'text-cyan-500', bgColor: 'bg-cyan-100 dark:bg-cyan-900/30', criteria: 'avgResponseTime < 2000' }, 'token-efficient': { id: 'token-efficient', name: 'Token Efficient', description: 'Uses tokens efficiently while maintaining quality', icon: 'gem', color: 'text-emerald-500', bgColor: 'bg-emerald-100 dark:bg-emerald-900/30', criteria: 'tokenEfficiency > 0.9' }, 'beginner-friendly': { id: 'beginner-friendly', name: 'Beginner Friendly', description: 'Easy to understand and use for newcomers', icon: 'sprout', color: 'text-green-500', bgColor: 'bg-green-100 dark:bg-green-900/30', criteria: 'complexity <= 2 && hasExamples' } } /** * Calculate which badges a prompt has earned */ export function calculatePromptBadges(stats: { runs: number stars: number remixCount: number successRate?: number avgResponseTime?: number usesFramework?: boolean weeklyGrowth?: number percentile?: number tokenEfficiency?: number complexity?: number hasExamples?: boolean }): QualityBadge[] { const earned: QualityBadge[] = [] // Verified Quality if (stats.runs >= 100 && (stats.successRate ?? 0) >= 0.95) { earned.push(QUALITY_BADGES['verified-quality']) } // Framework Compliant if (stats.usesFramework) { earned.push(QUALITY_BADGES['framework-compliant']) } // High Performance if ((stats.avgResponseTime ?? 10000) < 3000 && (stats.tokenEfficiency ?? 0) > 0.8) { earned.push(QUALITY_BADGES['high-performance']) } // Community Favorite if (stats.stars >= 50) { earned.push(QUALITY_BADGES['community-favorite']) } // Trending if ((stats.weeklyGrowth ?? 0) > 100) { earned.push(QUALITY_BADGES['trending']) } // Most Remixed if (stats.remixCount >= 10) { earned.push(QUALITY_BADGES['most-remixed']) } // Top Rated if ((stats.percentile ?? 0) >= 90) { earned.push(QUALITY_BADGES['top-rated']) } // Speed Demon if ((stats.avgResponseTime ?? 10000) < 2000 && stats.runs >= 10) { earned.push(QUALITY_BADGES['speed-demon']) } // Token Efficient if ((stats.tokenEfficiency ?? 0) > 0.9) { earned.push(QUALITY_BADGES['token-efficient']) } // Beginner Friendly if ((stats.complexity ?? 5) <= 2 && stats.hasExamples) { earned.push(QUALITY_BADGES['beginner-friendly']) } return earned } /** * Get all available badges */ export function getAllBadges(): QualityBadge[] { return Object.values(QUALITY_BADGES) }