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(''); if (!finalExtractedThinkingContent) return null; const isThinkingStatus = message.status === 'loading' || message.status === 'incomplete'; const headerText = (isThinkingStatus && !message.isThinkingComplete) ? t('思考中...') : t('思考过程'); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [finalExtractedThinkingContent, message.isReasoningExpanded]); // 流式状态结束时重置 useEffect(() => { if (!isThinkingStatus) { lastContentRef.current = ''; } }, [isThinkingStatus]); // 获取上一次的内容长度 let prevLength = 0; if (isThinkingStatus && lastContentRef.current) { if (finalExtractedThinkingContent.startsWith(lastContentRef.current)) { prevLength = lastContentRef.current.length; } } // 更新最后内容的引用 if (isThinkingStatus) { lastContentRef.current = finalExtractedThinkingContent; } return (