Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(chat): option to fold image-read tool calls into the call list (#23069)

YuTengjing162d8e9d95ab
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index 95f31c7984c..1dc0b3de294 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -1727,6 +1727,8 @@
"settingChatAppearance.mermaidTheme.title": "Mermaid Theme",
"settingChatAppearance.pasteAutoConvert.desc": "Pasted Markdown turns into formatted text in the input. Turn this off to keep text exactly as copied. Press ⇧⌘V (Ctrl+Shift+V on Windows) to paste plain text anytime.",
"settingChatAppearance.pasteAutoConvert.title": "Format Markdown on Paste",
+ "settingChatAppearance.showImageReadPreview.desc": "When off, tool calls that read an image fold in with the other calls and stay collapsed until clicked.",
+ "settingChatAppearance.showImageReadPreview.title": "Show Image Reads on Their Own",
"settingChatAppearance.title": "Chat Appearance",
"settingChatAppearance.transitionMode.desc": "Choose how chat messages appear",
"settingChatAppearance.transitionMode.options.fadeIn": "Fade In",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index e94b8a536e1..319fbfa191e 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -1727,6 +1727,8 @@
"settingChatAppearance.mermaidTheme.title": "Mermaid 主题",
"settingChatAppearance.pasteAutoConvert.desc": "粘贴的 Markdown 会在输入框中显示为格式化文本。关闭后按原文粘贴。随时可按 ⇧⌘V(Windows 为 Ctrl+Shift+V)粘贴纯文本。",
"settingChatAppearance.pasteAutoConvert.title": "粘贴时转换 Markdown",
+ "settingChatAppearance.showImageReadPreview.desc": "关闭后,读取图片的工具调用会和其他调用一起折叠,不再默认展开图片。",
+ "settingChatAppearance.showImageReadPreview.title": "单独展示读取的图片",
"settingChatAppearance.title": "聊天外观",
"settingChatAppearance.transitionMode.desc": "选择聊天消息的显示方式",
"settingChatAppearance.transitionMode.options.fadeIn": "淡入",
diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.ts
index f0e46a2e07b..1f25c64c5e9 100644
--- a/packages/locales/src/default/setting.ts
+++ b/packages/locales/src/default/setting.ts
@@ -1577,6 +1577,9 @@ export default {
'settingChatAppearance.pasteAutoConvert.desc':
'Pasted Markdown turns into formatted text in the input. Turn this off to keep text exactly as copied. Press ⇧⌘V (Ctrl+Shift+V on Windows) to paste plain text anytime.',
'settingChatAppearance.pasteAutoConvert.title': 'Format Markdown on Paste',
+ 'settingChatAppearance.showImageReadPreview.desc':
+ 'When off, tool calls that read an image fold in with the other calls and stay collapsed until clicked.',
+ 'settingChatAppearance.showImageReadPreview.title': 'Show Image Reads on Their Own',
'settingChatAppearance.title': 'Chat Appearance',
'settingChatAppearance.transitionMode.desc': 'Choose how chat messages appear',
'settingChatAppearance.transitionMode.options.fadeIn': 'Fade In',
diff --git a/packages/types/src/user/settings/general.ts b/packages/types/src/user/settings/general.ts
index bc209ebed5a..95f7e87b645 100644
--- a/packages/types/src/user/settings/general.ts
+++ b/packages/types/src/user/settings/general.ts
@@ -46,6 +46,13 @@ export interface UserGeneralConfig {
neutralColor?: NeutralColors;
primaryColor?: LobePrimaryColor;
responseLanguage?: string;
+ /**
+ * Whether a tool call that only reads an image (e.g. Claude Code `Read` of a
+ * PNG) gets its own row with the image expanded. Off folds it into the
+ * "N calls" collapse like any other call, collapsed until clicked.
+ * @default true
+ */
+ showImageReadPreview?: boolean;
telemetry: boolean;
timezone?: string;
transitionMode?: ResponseAnimationStyle;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
index 876ef4ff425..cbc011bff30 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
@@ -12,8 +12,11 @@ import { operationSelectors } from '@/store/chat/slices/operation/selectors';
import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfig';
import { useToolStore } from '@/store/tool';
import { toolSelectors } from '@/store/tool/selectors';
+import { useUserStore } from '@/store/user';
+import { userGeneralSettingsSelectors } from '@/store/user/selectors';
import { dataSelectors, useConversationStore } from '../../../store';
+import { isImageReadTool } from '../toolRenderRules';
import Actions from './Actions';
import Detail from './Detail';
import Inspectors from './Inspector';
@@ -56,11 +59,16 @@ const Tool = memo<GroupToolProps>(({ assistantMessageId, disableEditing, id }) =
const isMcpApp = useServerConfigStore(
(s) => serverConfigSelectors.enableMcpApps(s) && !!getMcpAppFromState(result?.state),
);
+ // With `showImageReadPreview` off, a call that only read an image stays
+ // collapsed like any other call; the user can still click it open.
+ const showImageReads = useUserStore(userGeneralSettingsSelectors.showImageReadPreview);
+ const foldImageRead = !showImageReads && !!tool && isImageReadTool(tool);
const isPending = intervention?.status === 'pending';
const isReject = intervention?.status === 'rejected';
const isAbort = intervention?.status === 'aborted';
- const needExpand = renderDisplayControl !== 'collapsed' || isPending || isMcpApp;
- const isAlwaysExpand = renderDisplayControl === 'alwaysExpand';
+ const needExpand =
+ (renderDisplayControl !== 'collapsed' && !foldImageRead) || isPending || isMcpApp;
+ const isAlwaysExpand = renderDisplayControl === 'alwaysExpand' && !foldImageRead;
const { handleExpand, setShowDebug, showDebug, showToolRender } = useToolExpandState({
isAlwaysExpand,
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
index ec42a51e5da..c0caa20df6c 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
@@ -8,6 +8,8 @@ import { useChatStore } from '@/store/chat';
import { operationSelectors } from '@/store/chat/slices/operation/selectors';
import type { OperationStatus } from '@/store/chat/slices/operation/types';
import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfig';
+import { useUserStore } from '@/store/user';
+import { userGeneralSettingsSelectors } from '@/store/user/selectors';
import type { AssistantContentBlock } from '@/types/index';
import { messageStateSelectors, useConversationStore } from '../../../store';
@@ -137,6 +139,7 @@ const Group = memo<GroupChildrenProps>(
// Off: no view is lifted or broken out, and the turn renders as it did
// before MCP Apps.
const enableMcpApps = useServerConfigStore(serverConfigSelectors.enableMcpApps);
+ const showImageReads = useUserStore(userGeneralSettingsSelectors.showImageReadPreview);
const views = useMemo(
() =>
@@ -145,9 +148,10 @@ const Group = memo<GroupChildrenProps>(
enableMcpApps,
hasActiveOperation: !!activeFlags[index],
isGenerating: !!generatingFlags[index],
+ showImageReads,
}),
),
- [activeFlags, chainsWithFinishTypes, enableMcpApps, generatingFlags],
+ [activeFlags, chainsWithFinishTypes, enableMcpApps, generatingFlags, showImageReads],
);
const lastView = views.at(-1)!;
const isGenerating = lastView.isGenerating;
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/groupChain.test.ts b/src/features/Conversation/Messages/AssistantGroup/components/groupChain.test.ts
index 1906467e8b5..83e0d5f57a6 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/groupChain.test.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/components/groupChain.test.ts
@@ -168,3 +168,59 @@ describe('buildChainView answer keys', () => {
},
);
});
+
+describe('buildChainView image reads', () => {
+ const tool = (id: string, apiName: string, state?: unknown, identifier = 'claude-code') => ({
+ apiName,
+ arguments: '{}',
+ id,
+ identifier,
+ result: { content: 'ok', id: `r-${id}`, state },
+ type: 'default' as const,
+ });
+ const imageRead = tool('read', 'Read', { images: [{ url: 'https://x/a.png' }] });
+ const generated = tool(
+ 'gen',
+ 'generateImage',
+ { generations: [{ asset: { url: 'https://x/g.png' } }] },
+ 'lobe-image-generation',
+ );
+ const mcpApp = tool('app', 'show', { mcpApp: { resourceUri: 'ui://dash/view' } }, 'dash');
+ const workflowRows = (
+ tools: unknown[],
+ state: { enableMcpApps?: boolean; showImageReads?: boolean },
+ ) =>
+ buildChainView(
+ { blocks: [{ content: '', id: 'step', tools }] as AssistantContentBlock[], id: 'group' },
+ { hasActiveOperation: false, isGenerating: false, ...state },
+ ).segments.filter((segment) => segment.kind === 'workflow');
+
+ it('breaks an image read out of its step by default', () => {
+ const rows = workflowRows([tool('a', 'Grep'), imageRead, tool('b', 'Bash')], {});
+
+ expect(rows).toHaveLength(3);
+ });
+
+ it('folds an image read into the run when the setting is off', () => {
+ const rows = workflowRows([tool('a', 'Grep'), imageRead, tool('b', 'Bash')], {
+ showImageReads: false,
+ });
+
+ expect(rows).toHaveLength(1);
+ expect(
+ rows[0]!.kind === 'workflow' && rows[0]!.blocks.flatMap((b) => b.tools ?? []),
+ ).toHaveLength(3);
+ });
+
+ it('still breaks out produced images and MCP App views when the setting is off', () => {
+ expect(
+ workflowRows([tool('a', 'Grep'), generated, tool('b', 'Bash')], { showImageReads: false }),
+ ).toHaveLength(3);
+ expect(
+ workflowRows([tool('a', 'Grep'), mcpApp, tool('b', 'Bash')], {
+ enableMcpApps: true,
+ showImageReads: false,
+ }),
+ ).toHaveLength(3);
+ });
+});
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/groupChain.ts b/src/features/Conversation/Messages/AssistantGroup/components/groupChain.ts
index e20bc968972..76fa098add9 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/groupChain.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/components/groupChain.ts
@@ -12,7 +12,7 @@ import type {
} from '@/types/index';
import { areWorkflowToolsComplete } from '../toolDisplayNames';
-import { isBreakoutTool, isImageBearingTool } from '../toolRenderRules';
+import { getBreakoutPredicate } from '../toolRenderRules';
import type { GroupRenderSegment } from './segments';
import type { RenderableAssistantContentBlock } from './types';
@@ -301,10 +301,16 @@ export const buildChainView = (
enableMcpApps?: boolean;
hasActiveOperation: boolean;
isGenerating: boolean;
+ /**
+ * User setting `showImageReadPreview`: off folds tools that only read an
+ * image into the run instead of breaking them out on their own row.
+ * @default true
+ */
+ showImageReads?: boolean;
},
): GroupChainView => {
const { isGenerating } = state;
- const isBreakout = state.enableMcpApps ? isBreakoutTool : isImageBearingTool;
+ const isBreakout = getBreakoutPredicate(state);
const partitioned = partitionAssistantGroupBlocks(chain.blocks, {
isBreakoutTool: isBreakout,
isGenerating,
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
index ca296f4bcb1..e75e7dfa257 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
@@ -5,9 +5,11 @@ import {
import { describe, expect, it } from 'vitest';
import {
+ getBreakoutPredicate,
isBreakoutTool,
isImageBearingTool,
isImageOutputTool,
+ isImageReadTool,
isMcpAppTool,
shouldRenderToolCall,
} from './toolRenderRules';
@@ -150,3 +152,29 @@ describe('isMcpAppTool', () => {
expect(isBreakoutTool(mcp({ content: [] }))).toBe(false);
});
});
+
+describe('getBreakoutPredicate', () => {
+ const imageRead = {
+ apiName: 'Read',
+ id: 't',
+ identifier: 'claude-code',
+ result: { content: 'x', id: 'r', state: { images: [{ url: 'https://x/a.png' }] } },
+ } as any;
+ const mcpApp = {
+ apiName: 'get_weather',
+ id: 't',
+ identifier: 'weather-demo',
+ result: { content: 'x', id: 'r', state: { mcpApp: { resourceUri: 'ui://weather/view' } } },
+ } as any;
+
+ it('breaks out image reads unless the user turned them off', () => {
+ expect(isImageReadTool(imageRead)).toBe(true);
+ expect(getBreakoutPredicate({})(imageRead)).toBe(true);
+ expect(getBreakoutPredicate({ showImageReads: false })(imageRead)).toBe(false);
+ });
+
+ it('breaks out MCP App views only behind the runtime flag', () => {
+ expect(getBreakoutPredicate({ showImageReads: false })(mcpApp)).toBe(false);
+ expect(getBreakoutPredicate({ enableMcpApps: true, showImageReads: false })(mcpApp)).toBe(true);
+ });
+});
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
index 875bbe489f7..fc38a3e1a72 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
@@ -74,3 +74,33 @@ export const isMcpAppTool = (tool: ChatToolPayloadWithResult): boolean =>
/** Tools that surface on their own between collapsed workflow runs. */
export const isBreakoutTool = (tool: ChatToolPayloadWithResult): boolean =>
isImageBearingTool(tool) || isMcpAppTool(tool);
+
+/**
+ * A tool that only READ an image (Claude Code `Read`, `readFile`, a browser
+ * `screenshot`) without producing one. The user setting
+ * `showImageReadPreview` decides whether these break out of the workflow
+ * collapse and open their image by default, or fold in like any other call.
+ */
+export const isImageReadTool = (tool: ChatToolPayloadWithResult): boolean =>
+ !isImageOutputTool(tool) && hasUploadedImages(tool.result?.state);
+
+export interface BreakoutToolOptions {
+ /** Runtime flag `mcp_apps`: MCP App views break out of collapsed runs too. */
+ enableMcpApps?: boolean;
+ /**
+ * User setting `showImageReadPreview`. Off folds image reads into the run;
+ * produced images and MCP App views still break out.
+ * @default true
+ */
+ showImageReads?: boolean;
+}
+
+/** Picks the breakout predicate for the current flags and user setting. */
+export const getBreakoutPredicate = ({
+ enableMcpApps,
+ showImageReads = true,
+}: BreakoutToolOptions): ((tool: ChatToolPayloadWithResult) => boolean) => {
+ const isImageBreakout = showImageReads ? isImageBearingTool : isImageOutputTool;
+
+ return enableMcpApps ? (tool) => isImageBreakout(tool) || isMcpAppTool(tool) : isImageBreakout;
+};
diff --git a/src/features/Settings/chat-appearance/features/ChatAppearance/index.tsx b/src/features/Settings/chat-appearance/features/ChatAppearance/index.tsx
index 2a970a6fe57..fe19e4ed61b 100644
--- a/src/features/Settings/chat-appearance/features/ChatAppearance/index.tsx
+++ b/src/features/Settings/chat-appearance/features/ChatAppearance/index.tsx
@@ -107,6 +107,20 @@ const ChatAppearance = memo(() => {
label: t('settingChatAppearance.workflowStreamingExpand.title'),
minWidth: undefined,
},
+ {
+ children: (
+ <Flexbox horizontal align={'center'} gap={8}>
+ {renderSaveHint('showImageReadPreview')}
+ <Switch
+ checked={general.showImageReadPreview ?? true}
+ onChange={(checked) => handleChange('showImageReadPreview', checked)}
+ />
+ </Flexbox>
+ ),
+ desc: t('settingChatAppearance.showImageReadPreview.desc'),
+ label: t('settingChatAppearance.showImageReadPreview.title'),
+ minWidth: undefined,
+ },
{
children: (
<Flexbox horizontal align={'center'} gap={8}>
diff --git a/src/store/user/slices/settings/selectors/general.ts b/src/store/user/slices/settings/selectors/general.ts
index a17e68fb122..b20081f94a7 100644
--- a/src/store/user/slices/settings/selectors/general.ts
+++ b/src/store/user/slices/settings/selectors/general.ts
@@ -43,6 +43,7 @@ const enableMessageLinkIcon = (s: UserStore) => generalConfig(s).enableMessageLi
// Users who switched off the retired `enableInputMarkdown` lab did so to keep pasted text verbatim.
const enablePasteAutoConvert = (s: UserStore) =>
generalConfig(s).enablePasteAutoConvert ?? s.preference.lab?.enableInputMarkdown !== false;
+const showImageReadPreview = (s: UserStore) => generalConfig(s).showImageReadPreview ?? true;
const fontAntialiasing = (s: UserStore) => generalConfig(s).fontAntialiasing ?? true;
/** The setting is a boolean: either the live tool list is open or it is a
* summary row. "Open" means the full list — the height-capped middle level
@@ -66,6 +67,7 @@ export const userGeneralSettingsSelectors = {
currentResponseLanguage,
currentTimezone,
responseLanguage,
+ showImageReadPreview,
telemetry,
timezone,
transitionMode,