feat: add collapse/expand all tool calls toggle button

Adds a floating button in the chat area that lets users collapse or expand
all tool call details at once. Useful for long conversations with many tool
calls where scrolling through expanded results is tedious.

- New ToolCollapseContext provides global collapse/expand state
- ToolCall components react to global state changes via version tracking
- Toggle button appears only when conversation has tool calls
- Supports EN/FR i18n
This commit is contained in:
Nicolas Varrot
2026-02-12 19:36:53 +00:00
parent cab78db057
commit 2b1ca2d0c8
5 changed files with 84 additions and 7 deletions

View File

@@ -1,8 +1,9 @@
import { useState, useCallback, useMemo } from 'react';
import { useState, useCallback, useMemo, useEffect, useRef } from 'react';
import { ChevronRight, ChevronDown, Check, Copy } from 'lucide-react';
import hljs from 'highlight.js/lib/common';
import { useT } from '../hooks/useLocale';
import { ImageBlock } from './ImageBlock';
import { useToolCollapse } from '../contexts/ToolCollapseContext';
type ToolColor = { border: string; bg: string; text: string; icon: string; glow: string; expandBorder: string; expandBg: string };
@@ -217,8 +218,19 @@ function extractImageFromResult(result: string): { src: string; remaining: strin
export function ToolCall({ name, input, result }: { name: string; input?: Record<string, unknown>; result?: string }) {
const t = useT();
const [open, setOpen] = useState(false);
const { globalState, version } = useToolCollapse();
const lastVersion = useRef(version);
const c = getColor(name);
// Respond to global collapse/expand commands
useEffect(() => {
if (version !== lastVersion.current) {
lastVersion.current = version;
if (globalState === 'collapse-all') setOpen(false);
else if (globalState === 'expand-all') setOpen(true);
}
}, [globalState, version]);
const inputStr = input ? (typeof input === 'string' ? input : JSON.stringify(input, null, 2)) : '';
const hint = getContextHint(name, input);