import React, { useEffect, useRef } from 'react'; import { Typography } from '@douyinfe/semi-ui'; import MarkdownRenderer from '../common/markdown/MarkdownRenderer'; import { ChevronRight, ChevronUp, Brain, Loader2 } from 'lucide-react'; import { useTranslation } from 'react-i18next'; const ThinkingContent = ({ message, finalExtractedThinkingContent, thinkingSource, styleState, onToggleReasoningExpansion }) => { const { t } = useTranslation(); const scrollRef = useRef(null); const lastContentRef = useRef(''); const isThinkingStatus = message.status === 'loading' || message.status === 'incomplete'; const headerText = (isThinkingStatus && !message.isThinkingComplete) ? t('思考中...') : t('思考过程'); useEffect(() => { if (scrollRef.current && finalExtractedThinkingContent && message.isReasoningExpanded) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [finalExtractedThinkingContent, message.isReasoningExpanded]); useEffect(() => { if (!isThinkingStatus) { lastContentRef.current = ''; } }, [isThinkingStatus]); if (!finalExtractedThinkingContent) return null; let prevLength = 0; if (isThinkingStatus && lastContentRef.current) { if (finalExtractedThinkingContent.startsWith(lastContentRef.current)) { prevLength = lastContentRef.current.length; } } if (isThinkingStatus) { lastContentRef.current = finalExtractedThinkingContent; } return (