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.

πŸ› fix(conversation): stop image reads from unfolding the whole turn (#20716)

Arvin Xuce2f04bd06ff
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts b/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts
index 6fb1ad71b92..90e53651758 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/components/segments.test.ts
@@ -84,6 +84,32 @@ describe('shouldFoldProcess', () => {
);
const proc = [w('t1')];
+ it('folds a finished turn whose process only READ an image', () => {
+ const readImage = {
+ apiName: 'Read',
+ id: 'read-image',
+ identifier: 'claude-code',
+ result: { content: 'ok', id: 'r', state: { images: [{ url: 'https://x/a.png' }] } },
+ };
+ expect(
+ shouldFoldProcess({
+ enabled: true,
+ hasFinalAnswer: true,
+ isGenerating: false,
+ isLatestItem: true,
+ operationEnded: true,
+ processSegments: [
+ w('commands', 2),
+ {
+ kind: 'workflow',
+ blocks: [{ id: 'read-image', tools: [readImage] } as any],
+ standalone: true,
+ },
+ ],
+ }),
+ ).toBe(true);
+ });
+
it('folds a finished, non-latest turn that has a workflow when enabled', () => {
expect(
shouldFoldProcess({
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/segments.ts b/src/features/Conversation/Messages/AssistantGroup/components/segments.ts
index f402289304b..bd7c5c68e14 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/segments.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/components/segments.ts
@@ -2,7 +2,7 @@ import type { AssistantGroupSegment } from '@lobechat/conversation-flow';
import { LOADING_FLAT } from '@/const/message';
-import { isImageBearingTool } from '../toolRenderRules';
+import { isImageOutputTool } from '../toolRenderRules';
import type { RenderableAssistantContentBlock } from './types';
import type { WorkflowExpandLevel, WorkflowExpandLevelDefault } from './WorkflowCollapse';
@@ -46,6 +46,11 @@ export const hasRenderableFinalAnswer = (segments: GroupRenderSegment[]): boolea
* the message is not generating. The latest turn is eligible only once its final
* answer is visible, so a tool-only latest turn does not collapse into a lone
* header.
+ *
+ * A turn whose process carries a PRODUCED image never folds β€” that image is the
+ * deliverable. A tool that merely READ an image no longer blocks folding: the
+ * read is one ordinary step, and it surfaces (with its preview) once the fold is
+ * expanded instead of holding the whole process open.
*/
export const shouldFoldProcess = ({
enabled,
@@ -69,7 +74,7 @@ export const shouldFoldProcess = ({
processSegments.some((segment) => segment.kind === 'workflow') &&
!processSegments.some((segment) =>
(segment.kind === 'answer' ? [segment.block] : segment.blocks).some((block) =>
- block.tools?.some(isImageBearingTool),
+ block.tools?.some(isImageOutputTool),
),
);
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
index 2e6de10325c..1999834d6d4 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.test.ts
@@ -4,7 +4,7 @@ import {
} from '@lobechat/builtin-tool-web-onboarding';
import { describe, expect, it } from 'vitest';
-import { isImageBearingTool, shouldRenderToolCall } from './toolRenderRules';
+import { isImageBearingTool, isImageOutputTool, shouldRenderToolCall } from './toolRenderRules';
describe('shouldRenderToolCall', () => {
it('hides the onboarding completion tool call', () => {
@@ -72,3 +72,48 @@ describe('isImageBearingTool', () => {
).toBe(false);
});
});
+
+describe('isImageOutputTool', () => {
+ it('is false for a tool that merely READ an image', () => {
+ expect(
+ isImageOutputTool({
+ apiName: 'Read',
+ id: 't',
+ identifier: 'claude-code',
+ result: { content: 'x', id: 'r', state: { images: [{ url: 'https://x/a.png' }] } },
+ } as any),
+ ).toBe(false);
+ });
+
+ it('is true for a Codex image output, including upload failures', () => {
+ for (const state of [undefined, { images: [{ url: 'https://x/a.png' }] }]) {
+ expect(
+ isImageOutputTool({
+ apiName: 'image_output',
+ id: 't',
+ identifier: 'codex',
+ result: { content: 'x', id: 'r', state },
+ } as any),
+ ).toBe(true);
+ }
+ });
+
+ it('is true for a generateImage result only once it carries a finished asset', () => {
+ expect(
+ isImageOutputTool({
+ apiName: 'generateImage',
+ id: 't',
+ identifier: 'lobe-image-generation',
+ result: { content: 'x', id: 'r', state: { generations: [{ asset: { url: 'u' } }] } },
+ } as any),
+ ).toBe(true);
+ expect(
+ isImageOutputTool({
+ apiName: 'generateImage',
+ id: 't',
+ identifier: 'lobe-image-generation',
+ result: { content: 'x', id: 'r', state: { generations: [{ asset: null }] } },
+ } as any),
+ ).toBe(false);
+ });
+});
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
index 65cdc20828a..b1c3656a7ce 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolRenderRules.ts
@@ -30,18 +30,33 @@ const hasGeneratedImage = (state: unknown): boolean =>
(generation) => !!generation.asset,
);
-export const isImageBearingTool = (tool: ChatToolPayloadWithResult): boolean => {
+/**
+ * Tools whose result IS an image the turn produced β€” a generated image, or a
+ * Codex image output. These are the turn's deliverable, so a finished turn
+ * carrying one must not fold it away.
+ *
+ * Deliberately excludes tools that merely READ an image (`readFile`, Claude
+ * Code `Read`, the in-app browser's `screenshot`): a read is one ordinary step
+ * among many, and letting it block the fold unfolded the whole process.
+ */
+export const isImageOutputTool = (tool: ChatToolPayloadWithResult): boolean => {
// Image delivery failures must stay visible alongside successful outputs.
if (tool.identifier === 'codex' && tool.apiName === 'image_output') return true;
const state = tool.result?.state;
if (!state) return false;
- if (
+ return (
tool.identifier === ImageGenerationIdentifier &&
- tool.apiName === ImageGenerationApiName.generateImage
- )
- return hasGeneratedImage(state);
-
- return hasUploadedImages(state);
+ tool.apiName === ImageGenerationApiName.generateImage &&
+ hasGeneratedImage(state)
+ );
};
+
+/**
+ * Any tool whose result carries an image, output or read. Drives the workflow
+ * breakout only: a read image still surfaces as its own row once the process is
+ * unfolded, but no longer keeps that process from folding in the first place.
+ */
+export const isImageBearingTool = (tool: ChatToolPayloadWithResult): boolean =>
+ isImageOutputTool(tool) || hasUploadedImages(tool.result?.state);