import { useEffect, useState } from 'react'; import { Bot, CheckCircle2, ChevronDown, Info, Sparkles, UserRound, Wrench } from 'lucide-react'; import MarkdownRenderer from '../MarkdownRenderer'; import { useTheme } from '../../contexts/ThemeContext'; interface ConversationStep { text: string; subText?: string; status: 'done' | 'processing'; } interface ToolCall { id: string; name: string; input?: Record; output?: string; } interface ConversationMessage { id: string; role: 'user' | 'assistant'; content: string; steps?: ConversationStep[]; thinkings?: Array<{ duration: number; content: string }>; toolCalls?: ToolCall[]; } interface SkillCreatorConversationItemProps { message: ConversationMessage; isConnecting?: boolean; } function MessageAvatar({ role, active = false }: { role: 'user' | 'assistant'; active?: boolean }) { const { theme } = useTheme(); const isDarkMode = theme === 'dark'; const Icon = role === 'assistant' ? Bot : UserRound; return (
{role === 'assistant' && active && ( )}
); } function StepsSummary({ steps }: { steps: ConversationStep[] }) { const { theme } = useTheme(); const isDarkMode = theme === 'dark'; const [open, setOpen] = useState(true); const doneCount = steps.filter((step) => step.status === 'done').length; return (
{steps.map((step, index) => { const done = step.status === 'done'; return (
{done ? ( ) : ( )}
第 {index + 1} 步:{step.text}
{step.subText && (
{step.subText}
)}
); })}
); } function ThinkingPanel({ duration, content }: { duration: number; content: string }) { const { theme } = useTheme(); const isDarkMode = theme === 'dark'; const [open, setOpen] = useState(true); useEffect(() => { if (duration > 0) setOpen(false); }, [duration]); return (
{content}
); } function ToolCallPanel({ toolCall }: { toolCall: ToolCall }) { const { theme } = useTheme(); const isDarkMode = theme === 'dark'; const [open, setOpen] = useState(false); const details = { input: toolCall.input && Object.keys(toolCall.input).length > 0 ? JSON.stringify(toolCall.input, null, 2) : '', output: toolCall.output ?? '', }; const hasDetails = Boolean(details.input || details.output); return (
{hasDetails && (
{details.input && (

请求参数

{details.input}
)} {details.output && (

返回结果

{details.output}
)}
)}
); } export default function SkillCreatorConversationItem({ message, isConnecting = false }: SkillCreatorConversationItemProps) { const { theme } = useTheme(); const isDarkMode = theme === 'dark'; if (message.role === 'user') { return (
{message.content}
); } return (
{message.steps && message.steps.length > 0 && } {message.thinkings?.map((thinking, index) => ( ))} {message.toolCalls?.map((toolCall) => ( ))} {isConnecting && (
正在连接技能服务...
)} {message.content && ( )}
); }