// ========================================
// InsightsPanel Component
// ========================================
// AI insights panel for prompt history analysis
import { useIntl } from 'react-intl';
import { cn } from '@/lib/utils';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card';
import { Badge } from '@/components/ui/Badge';
import { Button } from '@/components/ui/Button';
import {
Sparkles,
AlertTriangle,
Lightbulb,
Wand2,
Loader2,
RefreshCw,
} from 'lucide-react';
import type { PromptInsight, Pattern, Suggestion } from '@/types/store';
export interface InsightsPanelProps {
/** Available insights */
insights?: PromptInsight[];
/** Detected patterns */
patterns?: Pattern[];
/** AI suggestions */
suggestions?: Suggestion[];
/** Currently selected tool */
selectedTool: 'gemini' | 'qwen' | 'codex';
/** Called when tool selection changes */
onToolChange: (tool: 'gemini' | 'qwen' | 'codex') => void;
/** Called when analyze is triggered */
onAnalyze: () => void;
/** Loading state */
isAnalyzing?: boolean;
/** Optional className */
className?: string;
}
const toolConfig = {
gemini: {
label: 'Gemini',
color: 'text-blue-500',
bgColor: 'bg-blue-500/10',
},
qwen: {
label: 'Qwen',
color: 'text-purple-500',
bgColor: 'bg-purple-500/10',
},
codex: {
label: 'Codex',
color: 'text-green-500',
bgColor: 'bg-green-500/10',
},
};
/**
* InsightCard component for displaying a single insight
*/
function InsightCard({ insight }: { insight: PromptInsight }) {
const { formatMessage } = useIntl();
const typeConfig = {
suggestion: {
icon: Lightbulb,
variant: 'info' as const,
color: 'text-blue-500',
},
optimization: {
icon: Sparkles,
variant: 'success' as const,
color: 'text-green-500',
},
warning: {
icon: AlertTriangle,
variant: 'warning' as const,
color: 'text-orange-500',
},
};
const config = typeConfig[insight.type];
const Icon = config.icon;
return (
{insight.content}
{Math.round(insight.confidence * 100)}% {formatMessage({ id: 'prompts.insights.confidence' })}
);
}
/**
* PatternCard component for displaying a detected pattern
*/
function PatternCard({ pattern }: { pattern: Pattern }) {
return (
{pattern.name}
{pattern.description}
{pattern.example && (
{pattern.example}
)}
{pattern.severity && (
{pattern.severity}
)}
);
}
/**
* SuggestionCard component for displaying a suggestion
*/
function SuggestionCard({ suggestion }: { suggestion: Suggestion }) {
const { formatMessage } = useIntl();
const typeConfig = {
refactor: { color: 'text-blue-500', label: formatMessage({ id: 'prompts.suggestions.types.refactor' }) },
optimize: { color: 'text-green-500', label: formatMessage({ id: 'prompts.suggestions.types.optimize' }) },
fix: { color: 'text-orange-500', label: formatMessage({ id: 'prompts.suggestions.types.fix' }) },
document: { color: 'text-purple-500', label: formatMessage({ id: 'prompts.suggestions.types.document' }) },
};
const config = typeConfig[suggestion.type];
return (
{suggestion.title}
{config.label}
{suggestion.description}
{suggestion.code && (
{suggestion.code}
)}
{suggestion.effort && (
{formatMessage({ id: 'prompts.suggestions.effort' })}: {suggestion.effort}
)}
);
}
/**
* InsightsPanel component - AI analysis panel for prompt history
*/
export function InsightsPanel({
insights = [],
patterns = [],
suggestions = [],
selectedTool,
onToolChange,
onAnalyze,
isAnalyzing = false,
className,
}: InsightsPanelProps) {
const { formatMessage } = useIntl();
const hasContent = insights.length > 0 || patterns.length > 0 || suggestions.length > 0;
return (
{formatMessage({ id: 'prompts.insights.title' })}
{/* Tool selector */}
{formatMessage({ id: 'prompts.insights.selectTool' })}:
{(Object.keys(toolConfig) as Array).map((tool) => (
))}
{!hasContent && !isAnalyzing ? (
{formatMessage({ id: 'prompts.insights.empty.title' })}
{formatMessage({ id: 'prompts.insights.empty.message' })}
) : (
{/* Insights section */}
{insights.length > 0 && (
{formatMessage({ id: 'prompts.insights.sections.insights' })}
{insights.map((insight) => (
))}
)}
{/* Patterns section */}
{patterns.length > 0 && (
{formatMessage({ id: 'prompts.insights.sections.patterns' })}
{patterns.map((pattern) => (
))}
)}
{/* Suggestions section */}
{suggestions.length > 0 && (
{formatMessage({ id: 'prompts.insights.sections.suggestions' })}
{suggestions.map((suggestion) => (
))}
)}
{isAnalyzing && (
{formatMessage({ id: 'prompts.insights.analyzing' })}
)}
)}
);
}
export default InsightsPanel;