diff --git a/src/renderer/src/App.test.tsx b/src/renderer/src/App.test.tsx index cc5043e..609dfc6 100644 --- a/src/renderer/src/App.test.tsx +++ b/src/renderer/src/App.test.tsx @@ -1325,6 +1325,36 @@ describe('App', () => { .closest('details') expect(streamingReasoning).toHaveAttribute('open') expect(screen.getByText('先检查项目结构')).toBeInTheDocument() + const reasoningContent = + streamingReasoning!.querySelector( + '.message-reasoning__content' + ) + if (!reasoningContent) { + throw new Error('Missing reasoning content') + } + const reasoningScrollTo = vi.fn() + reasoningContent.scrollTo = reasoningScrollTo + Object.defineProperty(reasoningContent, 'scrollHeight', { + configurable: true, + value: 640 + }) + + act(() => { + if (!request) { + throw new Error('Missing request') + } + agentListener?.({ + requestId: request.requestId, + type: 'reasoning', + delta: ',再确认依赖' + }) + }) + + expect(reasoningScrollTo).toHaveBeenLastCalledWith({ + top: 640, + behavior: 'auto' + }) + expect(screen.getByText('先检查项目结构,再确认依赖')).toBeInTheDocument() act(() => { if (!request) { diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 6a6682f..9cd781c 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -524,6 +524,43 @@ function groupMessageBlocks( return items } +function MessageReasoning({ + content, + streaming +}: { + content: string + streaming: boolean +}): React.JSX.Element { + const { t } = useTranslation('app') + const contentRef = useRef(null) + + useEffect(() => { + if (!streaming || !contentRef.current) { + return + } + contentRef.current.scrollTo({ + top: contentRef.current.scrollHeight, + behavior: 'auto' + }) + }, [content, streaming]) + + return ( +
+ + {streaming + ? t('chat.reasoning.streaming') + : t('chat.reasoning.complete')} + +
+ {content} +
+
+ ) +} + function ToolExecutionList({ tools }: { @@ -5380,22 +5417,11 @@ function App(): React.JSX.Element { tools={item.tools} /> ) : item.block.type === 'reasoning' ? ( -
- - {message.state === 'streaming' - ? t('chat.reasoning.streaming') - : t('chat.reasoning.complete')} - -
- - {item.block.content} - -
-
+ streaming={message.state === 'streaming'} + /> ) : (
{message.reasoning && ( -
- - {message.state === 'streaming' - ? t('chat.reasoning.streaming') - : t('chat.reasoning.complete')} - -
- - {message.reasoning} - -
-
+ streaming={message.state === 'streaming'} + /> )} {message.content && (