feat(ui): collapsible thinking blocks with merged per-turn view and user toggle (#1273)

* feat: add collapsible reasoning traces with animated labels

* feat(ui): redesign reasoning blocks with merged collapsible Thought view

- Replace per-part reasoning blocks with a single merged block per turn
  (VSCode Copilot pattern), controlled by new `groupReasoningBlocks` store flag
- `ReasoningTimelineBlock` redesigned: chevron toggle, summary preview on
  collapsed header, 'Thinking'/'Justification' label when expanded, BusyDots
  while streaming, auto-scroll to bottom during live streaming
- Short texts (< 120 chars) render inline without a toggle
- Summary now strips markdown and truncates at a word boundary with ellipsis
- New `MergedReasoningPart` component merges all reasoning parts for a message
  into one block at the position of the first reasoning part
- `defaultExpanded` prop lets callers override initial expand state
- Remove `.thinking-dot` CSS animation (replaced by BusyDots component)
- Fix reasoning markdown font-size: use `--text-markdown` instead of `--text-meta`

* refactor(ui): scope working phrases inside useAssistantStatus and simplify reasoning status

- Move WORKING_PHRASES array and getRandomWorkingPhrase() inside the hook
  so they are no longer exported (were only consumed by ReasoningPart which
  no longer needs them)
- Change the 'reasoning' activity status text from a random working phrase
  to the deterministic string 'thinking' — matches the new UI label

* test(ui): expand ReasoningPart tests for new collapsible and summary behavior

- Update baseline test to use text long enough to trigger the collapsible
  path (short texts now render inline) and assert on the correct aria markup
- Add test for 'Justification' label when pre-expanded via defaultExpanded
- Add test for 'Thinking' label for the thinking variant when expanded
- Add test verifying summary is a word-boundary-truncated excerpt ending with
  an ellipsis character

* i18n: rename 'Reasoning Traces' to 'Thinking Blocks' and add thought key

- Rename settings label from 'Show Reasoning Traces' → 'Show Thinking Blocks'
  across all supported locales (en, es, ko, pl, pt-BR, uk, zh-CN)
- Add `chat.reasoningTrace.thought` key to all locales (used by merged
  reasoning block header in completed state)

* feat(ui): add collapsibleThinkingBlocks setting with full persistence wiring

- New boolean store field `collapsibleThinkingBlocks` (default true) with
  `setCollapsibleThinkingBlocks` action; persisted to localStorage
- Threaded through DesktopSettings, SettingsPayload (API types), desktop
  persistence (sanitize + apply), web appearance persistence, appearance
  auto-save watcher, and server-side settings-helpers sanitize/format
- Server defaults to true when the field is absent in formatSettingsResponse
- MessageBody reads the flag: false → render reasoning as plain AssistantTextPart;
  true → existing collapsible/merged block path

* feat(settings): expose Collapsible Reasoning Blocks toggle in visual settings

Add a checkbox under the 'Show Thinking Blocks' row (visible only when
showReasoningTraces is enabled) that toggles the collapsibleThinkingBlocks
preference. Follows the existing toggle pattern: div role=button, keyboard
handler for Enter/Space, Checkbox primitive, aria-pressed attribute.

* i18n: revert showReasoningTraces label rename and add collapsibleThinkingBlocks strings

- Revert 'Show Reasoning Traces' → 'Show Thinking Blocks' rename (the
  collapsibleThinkingBlocks toggle is now a separate control, so the parent
  label stays as 'Reasoning Traces' for clarity)
- Add `collapsibleThinkingBlocks` / `collapsibleThinkingBlocksAria` strings
  across all seven supported locales (en, es, ko, pl, pt-BR, uk, zh-CN)

* test(server): add settings-helpers coverage for collapsibleThinkingBlocks

- Verify sanitizeSettingsUpdate accepts boolean true/false and rejects
  non-boolean values (string, number)
- Verify formatSettingsResponse forwards the value correctly for both true
  and false, and defaults to true when the field is absent

* fix(ui): respect defaultExpanded prop and remove dead alwaysShowActions from ReasoningTimelineBlock

The useEffect on [isStreaming] was firing on mount and immediately calling
setIsExpanded(false) (since isStreaming is false for completed blocks),
overriding any defaultExpanded={true} passed by callers. The fix uses a
prevIsStreamingRef so the effect only collapses the block on a true→false
transition and is a no-op on initial mount.

Also removes alwaysShowActions from ReasoningTimelineBlockProps — the new
header design always shows the chevron, making the prop obsolete. The prop
was already absent from the component destructuring (a dead type entry) and
was silently ignored at runtime. Removed it from ReasoningPartProps,
MergedReasoningPartProps, and the two call-sites in MessageBody as well.

* chore: remove unused reasoningpresentation module and test

* fix(ui): polish collapsible reasoning block UI

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
Erman HAVUÇ
2026-05-16 17:20:16 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent 00c112077d
commit e1977bbe63
28 changed files with 544 additions and 90 deletions
+1
View File
@@ -580,6 +580,7 @@ export interface SettingsPayload {
securityScopedBookmarks?: string[];
pinnedDirectories?: string[];
showReasoningTraces?: boolean;
collapsibleThinkingBlocks?: boolean;
showDeletionDialog?: boolean;
nativeNotificationsEnabled?: boolean;
notificationMode?: 'always' | 'hidden-only';
@@ -6,6 +6,7 @@ import type { MobileKeyboardMode } from '@/lib/mobileKeyboardMode';
type AppearanceSlice = {
showReasoningTraces: boolean;
collapsibleThinkingBlocks: boolean;
showDeletionDialog: boolean;
nativeNotificationsEnabled: boolean;
notificationMode: 'always' | 'hidden-only';
@@ -50,6 +51,7 @@ export const startAppearanceAutoSave = (): void => {
let previous: AppearanceSlice = {
showReasoningTraces: useUIStore.getState().showReasoningTraces,
collapsibleThinkingBlocks: useUIStore.getState().collapsibleThinkingBlocks,
showDeletionDialog: useUIStore.getState().showDeletionDialog,
nativeNotificationsEnabled: useUIStore.getState().nativeNotificationsEnabled,
notificationMode: useUIStore.getState().notificationMode,
@@ -101,6 +103,7 @@ export const startAppearanceAutoSave = (): void => {
useUIStore.subscribe((state) => {
const current: AppearanceSlice = {
showReasoningTraces: state.showReasoningTraces,
collapsibleThinkingBlocks: state.collapsibleThinkingBlocks,
showDeletionDialog: state.showDeletionDialog,
nativeNotificationsEnabled: state.nativeNotificationsEnabled,
notificationMode: state.notificationMode,
@@ -134,6 +137,9 @@ export const startAppearanceAutoSave = (): void => {
if (current.showReasoningTraces !== previous.showReasoningTraces) {
diff.showReasoningTraces = current.showReasoningTraces;
}
if (current.collapsibleThinkingBlocks !== previous.collapsibleThinkingBlocks) {
diff.collapsibleThinkingBlocks = current.collapsibleThinkingBlocks;
}
if (current.showDeletionDialog !== previous.showDeletionDialog) {
diff.showDeletionDialog = current.showDeletionDialog;
}
@@ -2,10 +2,12 @@ import { useUIStore } from '@/stores/useUIStore';
export interface AppearancePreferences {
showReasoningTraces?: boolean;
collapsibleThinkingBlocks?: boolean;
}
type RawAppearancePayload = {
showReasoningTraces?: unknown;
collapsibleThinkingBlocks?: unknown;
};
const sanitizePreferences = (payload?: RawAppearancePayload | null): AppearancePreferences | null => {
@@ -19,6 +21,10 @@ const sanitizePreferences = (payload?: RawAppearancePayload | null): AppearanceP
result.showReasoningTraces = payload.showReasoningTraces;
}
if (typeof payload.collapsibleThinkingBlocks === 'boolean') {
result.collapsibleThinkingBlocks = payload.collapsibleThinkingBlocks;
}
return Object.keys(result).length > 0 ? result : null;
};
@@ -30,6 +36,7 @@ const extractRawAppearance = (data: unknown): RawAppearancePayload | null => {
const candidate = data as Record<string, unknown>;
const payload: RawAppearancePayload = {
showReasoningTraces: candidate.showReasoningTraces,
collapsibleThinkingBlocks: candidate.collapsibleThinkingBlocks,
};
return payload;
@@ -54,6 +61,10 @@ export const applyAppearancePreferences = (preferences: AppearancePreferences):
if (typeof preferences.showReasoningTraces === 'boolean') {
store.setShowReasoningTraces(preferences.showReasoningTraces);
}
if (typeof preferences.collapsibleThinkingBlocks === 'boolean') {
store.setCollapsibleThinkingBlocks(preferences.collapsibleThinkingBlocks);
}
};
export const loadAppearancePreferences = async (): Promise<AppearancePreferences | null> => {
+1
View File
@@ -58,6 +58,7 @@ export type DesktopSettings = {
securityScopedBookmarks?: string[];
pinnedDirectories?: string[];
showReasoningTraces?: boolean;
collapsibleThinkingBlocks?: boolean;
showDeletionDialog?: boolean;
nativeNotificationsEnabled?: boolean;
notificationMode?: 'always' | 'hidden-only';
@@ -1434,6 +1434,8 @@ export const settingsDict = {
'settings.openchamber.visual.field.diffViewModeAria': 'Diff view mode: {option}',
'settings.openchamber.visual.field.showReasoningTracesAria': 'Show reasoning traces',
'settings.openchamber.visual.field.showReasoningTraces': 'Show Reasoning Traces',
'settings.openchamber.visual.field.collapsibleThinkingBlocksAria': 'Enable collapsible reasoning blocks',
'settings.openchamber.visual.field.collapsibleThinkingBlocks': 'Enable Collapsible Reasoning Blocks',
'settings.openchamber.visual.field.stickyUserHeaderAria': 'Sticky user header',
'settings.openchamber.visual.field.stickyUserHeader': 'Sticky User Header',
'settings.openchamber.visual.field.wideChatLayoutAria': 'Wide chat layout',
+6
View File
@@ -1686,6 +1686,12 @@ export const dict = {
'chat.modelControls.modeValue.subagent': 'Subagent',
'chat.modelControls.modeValue.all': 'All',
'chat.modelControls.modeValue.none': '—',
'chat.reasoningTrace.thinking': 'Thinking',
'chat.reasoningTrace.reasoning': 'Reasoning',
'chat.reasoningTrace.justification': 'Justification',
'chat.reasoningTrace.expandAria': 'Expand reasoning trace',
'chat.reasoningTrace.collapseAria': 'Collapse reasoning trace',
'chat.reasoningTrace.thought': 'Thought',
'chat.messageBody.subtask.title': 'Delegated task',
'chat.messageBody.subtask.hidePrompt': 'Hide prompt',
'chat.messageBody.subtask.showPrompt': 'Show prompt',
@@ -1434,6 +1434,8 @@ export const settingsDict = {
"settings.openchamber.visual.field.diffViewModeAria": "Modo de vista de comparación: {option}",
"settings.openchamber.visual.field.showReasoningTracesAria": "Mostrar rastros de razonamiento",
"settings.openchamber.visual.field.showReasoningTraces": "Mostrar trazas de razonamiento",
"settings.openchamber.visual.field.collapsibleThinkingBlocksAria": "Habilitar bloques de razonamiento colapsables",
"settings.openchamber.visual.field.collapsibleThinkingBlocks": "Habilitar Bloques de Razonamiento Colapsables",
"settings.openchamber.visual.field.stickyUserHeaderAria": "Encabezado del usuario fijo",
"settings.openchamber.visual.field.stickyUserHeader": "Encabezado de usuario fijo",
"settings.openchamber.visual.field.wideChatLayoutAria": "Diseño de chat ancho",
+6
View File
@@ -1652,6 +1652,12 @@ export const dict: Record<I18nKey, string> = {
"chat.modelControls.modeValue.subagent": "Subagente",
"chat.modelControls.modeValue.all": "Todos",
"chat.modelControls.modeValue.none": "—",
"chat.reasoningTrace.thinking": "Pensando",
"chat.reasoningTrace.reasoning": "Razonando",
"chat.reasoningTrace.justification": "Justificación",
"chat.reasoningTrace.expandAria": "Expandir traza de razonamiento",
"chat.reasoningTrace.collapseAria": "Contraer traza de razonamiento",
"chat.reasoningTrace.thought": "Pensó",
"chat.messageBody.subtask.title": "Tarea delegada",
"chat.messageBody.subtask.hidePrompt": "Ocultar prompt",
"chat.messageBody.subtask.showPrompt": "Mostrar prompt",
@@ -1434,6 +1434,8 @@ export const settingsDict = {
'settings.openchamber.visual.field.diffViewModeAria': 'Diff 보기 모드: {option}',
'settings.openchamber.visual.field.showReasoningTracesAria': 'Reasoning trace 표시',
'settings.openchamber.visual.field.showReasoningTraces': 'Reasoning Trace 표시',
'settings.openchamber.visual.field.collapsibleThinkingBlocksAria': '접을 수 있는 추론 블록 활성화',
'settings.openchamber.visual.field.collapsibleThinkingBlocks': '접을 수 있는 추론 블록 활성화',
'settings.openchamber.visual.field.stickyUserHeaderAria': '고정 사용자 헤더',
'settings.openchamber.visual.field.stickyUserHeader': '고정 사용자 헤더',
'settings.openchamber.visual.field.wideChatLayoutAria': '넓은 채팅 레이아웃',
+6
View File
@@ -1686,6 +1686,12 @@ export const dict: Record<I18nKey, string> = {
'chat.modelControls.modeValue.subagent': '서브 에이전트',
'chat.modelControls.modeValue.all': '전체',
'chat.modelControls.modeValue.none': '—',
'chat.reasoningTrace.thinking': '추론',
'chat.reasoningTrace.reasoning': '추론 중',
'chat.reasoningTrace.justification': '근거',
'chat.reasoningTrace.expandAria': '추론 트레이스 펼치기',
'chat.reasoningTrace.collapseAria': '추론 트레이스 접기',
'chat.reasoningTrace.thought': '추론 완료',
'chat.messageBody.subtask.title': '위임된 작업',
'chat.messageBody.subtask.hidePrompt': '숨기기 프롬프트',
'chat.messageBody.subtask.showPrompt': '표시 프롬프트',
@@ -840,6 +840,8 @@ export const settingsDict = {
'settings.openchamber.visual.field.showMobileStatusBarAria': 'Pokaż mobilny pasek statusu',
'settings.openchamber.visual.field.showReasoningTraces': 'Pokaż ślady rozumowania',
'settings.openchamber.visual.field.showReasoningTracesAria': 'Pokaż ślady rozumowania',
'settings.openchamber.visual.field.collapsibleThinkingBlocks': 'Włącz zwijalne bloki rozumowania',
'settings.openchamber.visual.field.collapsibleThinkingBlocksAria': 'Włącz zwijalne bloki rozumowania',
'settings.openchamber.visual.field.showSplitAssistantMessageActions': 'Akcje asystenta w treści',
'settings.openchamber.visual.field.showSplitAssistantMessageActionsAria': 'Akcje asystenta w treści',
'settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip': 'Pokaż Kopiuj odpowiedź, Zapisz jako obraz i Odczytaj na głos w blokach tekstu asystenta, które pojawiają się przed późniejszymi wywołaniami narzędzi w tej samej odpowiedzi.',
+6
View File
@@ -889,6 +889,12 @@ export const dict: Record<I18nKey, string> = {
'chat.messageBody.subtask.openSession': 'Otwórz sesję podzadania',
'chat.messageBody.subtask.showPrompt': 'Pokaż prompt',
'chat.messageBody.subtask.title': 'Zadanie delegowane',
'chat.reasoningTrace.thinking': 'Myślenie',
'chat.reasoningTrace.reasoning': 'Rozumowanie',
'chat.reasoningTrace.justification': 'Uzasadnienie',
'chat.reasoningTrace.expandAria': 'Rozwiń ślad rozumowania',
'chat.reasoningTrace.collapseAria': 'Zwiń ślad rozumowania',
'chat.reasoningTrace.thought': 'Przemyślał',
'chat.mobileStatus.editProjects.empty': 'Brak projektów do edycji',
'chat.mobileStatus.editProjects.footer': 'Przeciągnij elementy, aby zmienić kolejność, lub użyj strzałek do przesuwania. Dotknij „edytuj”, aby zmienić szczegóły.',
'chat.mobileStatus.editProjects.title': 'Edytuj projekty',
@@ -1434,6 +1434,8 @@ export const settingsDict = {
"settings.openchamber.visual.field.diffViewModeAria": "Modo de visualização de comparação: {option}",
"settings.openchamber.visual.field.showReasoningTracesAria": "Mostrar rastros de raciocínio",
"settings.openchamber.visual.field.showReasoningTraces": "Mostrar rastros de raciocínio",
"settings.openchamber.visual.field.collapsibleThinkingBlocksAria": "Habilitar blocos de raciocínio recolhíveis",
"settings.openchamber.visual.field.collapsibleThinkingBlocks": "Habilitar Blocos de Raciocínio Recolhíveis",
"settings.openchamber.visual.field.stickyUserHeaderAria": "Cabeçalho do usuário fixo",
"settings.openchamber.visual.field.stickyUserHeader": "Cabeçalho do usuário fixo",
"settings.openchamber.visual.field.wideChatLayoutAria": "Layout de chat amplo",
@@ -1652,6 +1652,12 @@ export const dict: Record<I18nKey, string> = {
"chat.modelControls.modeValue.subagent": "Subagente",
"chat.modelControls.modeValue.all": "Todos",
"chat.modelControls.modeValue.none": "—",
"chat.reasoningTrace.thinking": "Pensando",
"chat.reasoningTrace.reasoning": "Raciocinando",
"chat.reasoningTrace.justification": "Justificativa",
"chat.reasoningTrace.expandAria": "Expandir rastro de raciocínio",
"chat.reasoningTrace.collapseAria": "Recolher rastro de raciocínio",
"chat.reasoningTrace.thought": "Pensou",
"chat.messageBody.subtask.title": "Tarefa delegada",
"chat.messageBody.subtask.hidePrompt": "Ocultar prompt",
"chat.messageBody.subtask.showPrompt": "Mostrar prompt",
@@ -1434,6 +1434,8 @@ export const settingsDict = {
"settings.openchamber.visual.field.diffViewModeAria": "Режим перегляду diff: {option}",
"settings.openchamber.visual.field.showReasoningTracesAria": "Показати сліди міркувань",
"settings.openchamber.visual.field.showReasoningTraces": "Показати сліди міркувань",
"settings.openchamber.visual.field.collapsibleThinkingBlocksAria": "Увімкнути згортальні блоки міркувань",
"settings.openchamber.visual.field.collapsibleThinkingBlocks": "Увімкнути згортальні блоки міркувань",
"settings.openchamber.visual.field.stickyUserHeaderAria": "Закріплений заголовок користувача",
"settings.openchamber.visual.field.stickyUserHeader": "Закріплений заголовок користувача",
"settings.openchamber.visual.field.wideChatLayoutAria": "Широкий макет чату",
+6
View File
@@ -1652,6 +1652,12 @@ export const dict: Record<I18nKey, string> = {
"chat.modelControls.modeValue.subagent": "Субагент",
"chat.modelControls.modeValue.all": "всі",
"chat.modelControls.modeValue.none": "—",
"chat.reasoningTrace.thinking": "Міркування",
"chat.reasoningTrace.reasoning": "Міркую",
"chat.reasoningTrace.justification": "Обґрунтування",
"chat.reasoningTrace.expandAria": "Розгорнути слід міркування",
"chat.reasoningTrace.collapseAria": "Згорнути слід міркування",
"chat.reasoningTrace.thought": "Обдумав",
"chat.messageBody.subtask.title": "Делеговане завдання",
"chat.messageBody.subtask.hidePrompt": "Приховати промпт",
"chat.messageBody.subtask.showPrompt": "Показати промпт",
@@ -1434,6 +1434,8 @@ export const settingsDict = {
'settings.openchamber.visual.field.diffViewModeAria': 'Diff 视图模式:{option}',
'settings.openchamber.visual.field.showReasoningTracesAria': '显示推理轨迹',
'settings.openchamber.visual.field.showReasoningTraces': '显示推理轨迹',
'settings.openchamber.visual.field.collapsibleThinkingBlocksAria': '启用可折叠推理块',
'settings.openchamber.visual.field.collapsibleThinkingBlocks': '启用可折叠推理块',
'settings.openchamber.visual.field.stickyUserHeaderAria': '固定用户消息头',
'settings.openchamber.visual.field.stickyUserHeader': '固定用户消息头',
'settings.openchamber.visual.field.wideChatLayoutAria': '宽聊天布局',
@@ -1652,6 +1652,12 @@ export const dict: Record<I18nKey, string> = {
'chat.modelControls.modeValue.subagent': '子智能体',
'chat.modelControls.modeValue.all': '全部',
'chat.modelControls.modeValue.none': '—',
'chat.reasoningTrace.thinking': '思考',
'chat.reasoningTrace.reasoning': '推理',
'chat.reasoningTrace.justification': '理由',
'chat.reasoningTrace.expandAria': '展开推理轨迹',
'chat.reasoningTrace.collapseAria': '折叠推理轨迹',
'chat.reasoningTrace.thought': '已思考',
'chat.messageBody.subtask.title': '委派任务',
'chat.messageBody.subtask.hidePrompt': '隐藏提示',
'chat.messageBody.subtask.showPrompt': '显示提示',
+6
View File
@@ -345,6 +345,9 @@ const applyDesktopUiPreferences = (settings: DesktopSettings) => {
if (typeof settings.showReasoningTraces === 'boolean' && settings.showReasoningTraces !== store.showReasoningTraces) {
store.setShowReasoningTraces(settings.showReasoningTraces);
}
if (typeof settings.collapsibleThinkingBlocks === 'boolean' && settings.collapsibleThinkingBlocks !== store.collapsibleThinkingBlocks) {
store.setCollapsibleThinkingBlocks(settings.collapsibleThinkingBlocks);
}
if (typeof settings.autoDeleteEnabled === 'boolean' && settings.autoDeleteEnabled !== store.autoDeleteEnabled) {
store.setAutoDeleteEnabled(settings.autoDeleteEnabled);
}
@@ -639,6 +642,9 @@ const sanitizeWebSettings = (payload: unknown): DesktopSettings | null => {
if (typeof candidate.showReasoningTraces === 'boolean') {
result.showReasoningTraces = candidate.showReasoningTraces;
}
if (typeof candidate.collapsibleThinkingBlocks === 'boolean') {
result.collapsibleThinkingBlocks = candidate.collapsibleThinkingBlocks;
}
if (typeof candidate.autoDeleteEnabled === 'boolean') {
result.autoDeleteEnabled = candidate.autoDeleteEnabled;
}