Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🪝 refactor: Supply Auto-Expand Tools to Tool Cards From the Message Host (#16951)

Marco Berettabea55e7848fb
diff --git a/client/src/Providers/MessagePartsHostContext.tsx b/client/src/Providers/MessagePartsHostContext.tsx
index 0dae1dc782..8923c7c467 100644
--- a/client/src/Providers/MessagePartsHostContext.tsx
+++ b/client/src/Providers/MessagePartsHostContext.tsx
@@ -95,6 +95,7 @@ export const appMessagePartsHost: MessagePartsHost = {
useMessage: useAppMessage,
useFontSize: () => useAtomValue(fontSizeAtom),
useShowThinking: () => useAtomValue(showThinkingAtom),
+ useAutoExpandTools: () => useRecoilValue<boolean>(store.autoExpandTools),
useUserTextPreferences: useAppUserTextPreferences,
/* The atom rather than the auth context: AuthContextProvider mirrors the user into it, and the
* public share route mounts outside that provider. */
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/host.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/host.test.tsx
index 85237fdf38..15df2364d5 100644
--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/host.test.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/host.test.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { render, screen, fireEvent } from '@testing-library/react';
+import { render, renderHook, screen, fireEvent } from '@testing-library/react';
import type { TAttachment } from 'librechat-data-provider';
import type {
MessagePartArtifactPanel,
@@ -8,6 +8,7 @@ import type {
} from '~/hooks/Chat/contract';
import type { Artifact, PtcTrace } from '~/common';
import { MessagePartsHostProvider, appMessagePartsHost } from '~/Providers/MessagePartsHostContext';
+import { SoleToolContext, useToolAutoExpand } from '../../disclosure';
import ToolArtifactCard from '../ToolArtifactCard';
import PtcToolTrace from '../PtcToolTrace';
import TextPart from '../Text';
@@ -38,6 +39,7 @@ function createHost(overrides: Partial<MessagePartsHost> = {}): MessagePartsHost
useMessage: () => message,
useFontSize: () => 'text-base',
useShowThinking: () => false,
+ useAutoExpandTools: () => false,
useUserTextPreferences: () => ({
usernameDisplay: false,
enableUserMsgMarkdown: false,
@@ -171,4 +173,25 @@ describe('message parts host', () => {
);
expect(panel.register).toHaveBeenCalledWith(artifact);
});
+
+ it('opens tool cards by default from the host preference without an app store', () => {
+ const withHost =
+ (host: MessagePartsHost, sole?: boolean) =>
+ ({ children }: { children: React.ReactNode }) => (
+ <MessagePartsHostProvider host={host}>
+ <SoleToolContext.Provider value={sole}>{children}</SoleToolContext.Provider>
+ </MessagePartsHostProvider>
+ );
+
+ const off = renderHook(() => useToolAutoExpand(), { wrapper: withHost(createHost()) });
+ expect(off.result.current).toBe(false);
+
+ const on = renderHook(() => useToolAutoExpand(), {
+ wrapper: withHost(createHost({ useAutoExpandTools: () => true })),
+ });
+ expect(on.result.current).toBe(true);
+
+ const sole = renderHook(() => useToolAutoExpand(), { wrapper: withHost(createHost(), true) });
+ expect(sole.result.current).toBe(true);
+ });
});
diff --git a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
index b7f5bfe548..53493a6a1f 100644
--- a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
@@ -1,5 +1,4 @@
import { useState, useRef, useMemo, useEffect, useContext, useCallback } from 'react';
-import { useRecoilValue } from 'recoil';
import { Tools, Constants, ContentTypes } from 'librechat-data-provider';
import { ChevronDown, ListChecks, MessageCircleQuestion, Users } from 'lucide-react';
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
@@ -30,6 +29,7 @@ import {
} from './reveal';
import { useLocalize, useExpandCollapse, scheduleMessageContentLayoutReconcile } from '~/hooks';
import { ASK_USER_QUESTION, getSubmittedAskAnswer } from '~/utils/approval';
+import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
import { ToolAuthWarning, ToolAuthWarningContext } from './auth';
import { LoneGroupContext, SoleToolContext } from './disclosure';
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
@@ -42,7 +42,6 @@ import { StackedToolIcons } from './ToolOutput';
import { mapAttachments } from '~/utils/map';
import { getSourceDomains } from './sources';
import SearchVerticals from './verticals';
-import store from '~/store';
interface ToolCallGroupProps {
parts: PartWithIndex[];
@@ -318,7 +317,7 @@ export default function ToolCallGroup({
return raw ? raw.charAt(0).toUpperCase() + raw.slice(1) : '';
}, [toolMetadata, localize, mcpServerNames]);
- const autoExpand = useRecoilValue(store.autoExpandTools);
+ const autoExpand = useMessagePartsHost().useAutoExpandTools();
/** A labeled activity block is summarized by its header, so it collapses
* even at a single tool call — agent runs are full of one-call batches,
* and leaving those expanded defeats the grouping. */
diff --git a/client/src/components/Chat/Messages/Content/Wakeup.tsx b/client/src/components/Chat/Messages/Content/Wakeup.tsx
index e7f21ec7ff..93983ef427 100644
--- a/client/src/components/Chat/Messages/Content/Wakeup.tsx
+++ b/client/src/components/Chat/Messages/Content/Wakeup.tsx
@@ -1,5 +1,4 @@
import { memo, useCallback, useMemo, useState } from 'react';
-import { useRecoilValue } from 'recoil';
import { Button } from '@librechat/client';
import type { WakeupDisplay, WakeupTask } from './Parts/wakeup';
import type { TranslationKeys } from '~/hooks';
@@ -9,13 +8,13 @@ import SystemEventHeader, {
} from '~/components/Chat/Messages/ui/SystemEvent';
import { subagentStatusIcon, subagentStatusLabelKey } from '~/components/Chat/Subagents/status';
import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
+import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
import { useSubagentTaskPanel } from '~/components/Chat/Subagents/task';
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
import BackgroundTaskCard from './BackgroundTaskCard';
import { cn, getToolDisplayLabel } from '~/utils';
import { StackedToolIcons } from './ToolOutput';
import MarkdownLite from './MarkdownLite';
-import store from '~/store';
const SUBAGENT_HEADER_KEYS = {
completed: 'com_ui_wakeup_subagent_completed',
@@ -109,7 +108,7 @@ const Wakeup = memo(function Wakeup({
const localize = useLocalize();
const mcpIconMap = useMCPIconMap();
const mcpServerNames = useMCPServerNames();
- const autoExpand = useRecoilValue(store.autoExpandTools);
+ const autoExpand = useMessagePartsHost().useAutoExpandTools();
const [isExpanded, setIsExpanded] = useState(autoExpand);
const { style: expandStyle, ref: expandRef } = useExpandCollapse(isExpanded);
const { shouldRenderBody, mountBody, handleTransitionEnd } = useLazyCollapseBody(isExpanded);
diff --git a/client/src/components/Chat/Messages/Content/disclosure.ts b/client/src/components/Chat/Messages/Content/disclosure.ts
index d6cc0737e1..34df97cd15 100644
--- a/client/src/components/Chat/Messages/Content/disclosure.ts
+++ b/client/src/components/Chat/Messages/Content/disclosure.ts
@@ -1,8 +1,7 @@
import { createContext, useContext, useEffect, useMemo } from 'react';
import { atom, useAtom } from 'jotai';
-import { useRecoilValue } from 'recoil';
import type { PrimitiveAtom } from 'jotai';
-import store from '~/store';
+import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';
export type ReasoningDisclosures = Map<number, PrimitiveAtom<boolean | undefined>>;
@@ -71,7 +70,7 @@ export const LoneGroupContext = createContext<boolean>(false);
/** Whether a tool card opens by default: the user's "auto-expand tools"
* preference, or being the only call inside its group. */
export function useToolAutoExpand() {
- const autoExpand = useRecoilValue(store.autoExpandTools);
+ const autoExpand = useMessagePartsHost().useAutoExpandTools();
const soleTool = useContext(SoleToolContext);
return autoExpand || soleTool === true;
}
diff --git a/client/src/hooks/Chat/contract.ts b/client/src/hooks/Chat/contract.ts
index 79663fb9d6..878e66acaa 100644
--- a/client/src/hooks/Chat/contract.ts
+++ b/client/src/hooks/Chat/contract.ts
@@ -302,6 +302,8 @@ export type MessagePartsHost = {
useFontSize: () => string;
/** Whether the viewer wants reasoning expanded by default. */
useShowThinking: () => boolean;
+ /** Whether the viewer wants tool cards and tool groups expanded by default. */
+ useAutoExpandTools: () => boolean;
/** How the viewer prefers user-authored text to display. */
useUserTextPreferences: () => MessagePartsUserTextPreferences;
/** The signed-in user. */
diff --git a/e2e/specs/mock/scenarios/auto-expand-tools-setting.spec.ts b/e2e/specs/mock/scenarios/auto-expand-tools-setting.spec.ts
new file mode 100644
index 0000000000..e3b2d54e75
--- /dev/null
+++ b/e2e/specs/mock/scenarios/auto-expand-tools-setting.spec.ts
@@ -0,0 +1,129 @@
+import { expect, test } from '@playwright/test';
+import type { Locator, Page, Route } from '@playwright/test';
+import { messagesView } from '../helpers';
+import { openSidebar } from './sidebar';
+
+/**
+ * The "Auto-expand tool details" setting reaches the tool cards through the message parts host.
+ * A finished message with two tool calls stays folded with the setting off, and opens with its
+ * outputs showing once the setting is turned on in Settings and the conversation is reloaded.
+ */
+test.describe.configure({ timeout: 120_000 });
+
+const NO_PARENT = '00000000-0000-0000-0000-000000000000';
+const unique = (prefix: string) => `${prefix}-${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
+const escapeRe = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+const OUTPUTS = ['alpha-tool-output', 'beta-tool-output'];
+
+async function routeToolConversation(page: Page): Promise<string> {
+ const conversationId = unique('e2e-auto-expand');
+ const now = new Date(0).toISOString();
+ const message = {
+ messageId: `${conversationId}-msg`,
+ conversationId,
+ parentMessageId: NO_PARENT,
+ isCreatedByUser: false,
+ sender: 'Assistant',
+ endpoint: 'Mock Provider A',
+ model: 'mock-model-a',
+ text: '',
+ content: OUTPUTS.map((output, index) => ({
+ type: 'tool_call',
+ tool_call: {
+ id: `${conversationId}-tool-${index}`,
+ name: `lookup_records_${index}`,
+ args: JSON.stringify({ query: output }),
+ output,
+ progress: 1,
+ },
+ })),
+ createdAt: now,
+ updatedAt: now,
+ };
+ const conversation = {
+ conversationId,
+ title: 'Auto-expand tools',
+ endpoint: 'Mock Provider A',
+ endpointType: 'custom',
+ model: 'mock-model-a',
+ createdAt: now,
+ updatedAt: now,
+ };
+ const convoIdRe = escapeRe(conversationId);
+ await page.route(new RegExp(`/api/convos/${convoIdRe}(?:\\?.*)?$`), (route: Route) =>
+ route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify(conversation),
+ }),
+ );
+ await page.route(new RegExp(`/api/messages/${convoIdRe}(?:\\?.*)?$`), (route: Route) =>
+ route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify([message]),
+ }),
+ );
+ return conversationId;
+}
+
+const outputs = (page: Page): Locator[] =>
+ OUTPUTS.map((output) => messagesView(page).locator('pre', { hasText: output }).first());
+
+async function setAutoExpand(page: Page, on: boolean) {
+ await openSidebar(page);
+ await page.getByTestId('nav-user').filter({ visible: true }).first().click();
+ await page.getByRole('menuitem', { name: 'Settings' }).click();
+ const dialog = page.getByRole('dialog');
+ await expect(dialog.getByRole('heading', { name: 'Settings', exact: true })).toBeVisible({
+ timeout: 15000,
+ });
+ await dialog.getByRole('tab', { name: 'Chat' }).click();
+ const control = dialog.getByRole('switch', { name: 'Auto-expand tool details' });
+ await expect(control).toBeVisible();
+ if ((await control.getAttribute('aria-checked')) !== String(on)) {
+ await control.click();
+ }
+ await expect(control).toHaveAttribute('aria-checked', String(on));
+ await page.keyboard.press('Escape');
+ await expect(dialog).toBeHidden();
+}
+
+test('the auto-expand tools setting opens tool cards @scenario:auto-expand-tools-setting-opens-tool-cards', async ({
+ page,
+}) => {
+ await page.addInitScript(() => {
+ if (sessionStorage.getItem('e2e-auto-expand-seeded') == null) {
+ localStorage.removeItem('autoExpandTools');
+ sessionStorage.setItem('e2e-auto-expand-seeded', '1');
+ }
+ });
+ const conversationId = await routeToolConversation(page);
+ await page.goto(`/c/${conversationId}`, { timeout: 30000 });
+ await expect(
+ messagesView(page).getByText('lookup_records_0', { exact: false }).first(),
+ ).toBeVisible({
+ timeout: 20000,
+ });
+
+ for (const output of outputs(page)) {
+ await expect(output).toBeHidden();
+ }
+
+ await setAutoExpand(page, true);
+ await page.reload();
+ for (const output of outputs(page)) {
+ await expect(output).toBeVisible({ timeout: 20000 });
+ }
+
+ await setAutoExpand(page, false);
+ await page.reload();
+ await expect(
+ messagesView(page).getByText('lookup_records_0', { exact: false }).first(),
+ ).toBeVisible({
+ timeout: 20000,
+ });
+ for (const output of outputs(page)) {
+ await expect(output).toBeHidden();
+ }
+});