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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user