fix(desktop): show "已思考" label after thinking completes (#732)

The thinking block title always rendered the static "思考中"/"Thinking"
label; isActive only toggled the animated dots. Once thinking finished
the dots disappeared but the in-progress text stayed. Switch the label
to "已思考"/"Thought" when the block is no longer active.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-06-04 20:18:43 +08:00
parent 5688fe10a7
commit 449ff0b0ff
4 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,42 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { ThinkingBlock } from './ThinkingBlock'
import { useSettingsStore } from '../../stores/settingsStore'
describe('ThinkingBlock', () => {
beforeEach(() => {
useSettingsStore.setState({ locale: 'zh' })
})
afterEach(() => {
cleanup()
useSettingsStore.setState({ locale: 'zh' })
})
it('shows the in-progress label while thinking is active', () => {
render(<ThinkingBlock content="reasoning..." isActive />)
expect(screen.getByRole('button')).toHaveTextContent('思考中')
expect(screen.getByRole('button')).not.toHaveTextContent('已思考')
})
it('shows the done label once thinking has completed', () => {
render(<ThinkingBlock content="reasoning..." isActive={false} />)
expect(screen.getByRole('button')).toHaveTextContent('已思考')
expect(screen.getByRole('button')).not.toHaveTextContent('思考中')
})
it('defaults to the done label when isActive is omitted', () => {
render(<ThinkingBlock content="reasoning..." />)
expect(screen.getByRole('button')).toHaveTextContent('已思考')
})
it('localizes both labels in English', () => {
useSettingsStore.setState({ locale: 'en' })
const { rerender } = render(<ThinkingBlock content="reasoning..." isActive />)
expect(screen.getByRole('button')).toHaveTextContent('Thinking')
rerender(<ThinkingBlock content="reasoning..." isActive={false} />)
expect(screen.getByRole('button')).toHaveTextContent('Thought')
})
})

View File

@ -28,7 +28,7 @@ export function ThinkingBlock({ content, isActive = false }: { content: string;
{expanded ? '\u25BE' : '\u25B8'}
</span>
<span className="shrink-0 font-medium italic">
{t('thinking.label')}
{isActive ? t('thinking.label') : t('thinking.labelDone')}
{isActive && <span className="thinking-dots" />}
</span>
</button>

View File

@ -1304,6 +1304,7 @@ export const en = {
// ─── Thinking Block ──────────────────────────────────────
'thinking.label': 'Thinking',
'thinking.labelDone': 'Thought',
// ─── Tool Calls ──────────────────────────────────────
'tool.errorOutput': 'Error Output',

View File

@ -1306,6 +1306,7 @@ export const zh: Record<TranslationKey, string> = {
// ─── Thinking Block ──────────────────────────────────────
'thinking.label': '思考中',
'thinking.labelDone': '已思考',
// ─── Tool Calls ──────────────────────────────────────
'tool.errorOutput': '错误输出',