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.

💄 style(conversation): fold a compressed turn's process like the live conversation (#20630)

Arvin Xu4e5c2349b921
diff --git a/src/features/Conversation/Messages/CompressedGroup/CompressedMessageItem.tsx b/src/features/Conversation/Messages/CompressedGroup/CompressedMessageItem.tsx
index caa41e750bb..2ef61a413bd 100644
--- a/src/features/Conversation/Messages/CompressedGroup/CompressedMessageItem.tsx
+++ b/src/features/Conversation/Messages/CompressedGroup/CompressedMessageItem.tsx
@@ -12,8 +12,10 @@ import { userProfileSelectors } from '@/store/user/selectors';
import { useAgentMeta } from '../../hooks';
import ContentBlock from '../AssistantGroup/components/ContentBlock';
+import Group from '../AssistantGroup/components/Group';
import UserMessageContent from '../User/components/MessageContent';
import { getBotSender, resolveSenderIdentity } from '../User/resolveSenderIdentity';
+import { resolveCompressedMessageView } from './resolveCompressedMessageView';
interface CompressedMessageItemProps {
message: UIChatMessage;
@@ -28,10 +30,11 @@ const CompressedMessageItem = memo<CompressedMessageItemProps>(({ message }) =>
const userAvatar = useUserAvatar();
const currentUserId = useUserStore(userProfileSelectors.userId);
const agentAvatar = useAgentMeta(message.agentId);
- const { role, children, sender } = message;
+ const { children, sender } = message;
+ const view = resolveCompressedMessageView(message);
// Render user message
- if (role === 'user') {
+ if (view === 'user') {
// A shared (workspace) topic's compressed history may hold messages from
// other members — render the sender's identity, not the viewer's.
const { avatar, title } = resolveSenderIdentity({
@@ -52,7 +55,7 @@ const CompressedMessageItem = memo<CompressedMessageItemProps>(({ message }) =>
}
// Render assistant message (standalone without tools)
- if (role === 'assistant') {
+ if (view === 'assistant-content') {
return (
<Flexbox horizontal gap={8} paddingBlock={4}>
<Avatar {...agentAvatar} name={agentDisplayName(agentAvatar)} size={28} />
@@ -68,15 +71,26 @@ const CompressedMessageItem = memo<CompressedMessageItemProps>(({ message }) =>
);
}
- // Render assistantGroup (assistant message with tool calls)
- if (role === 'assistantGroup' && children) {
+ // Render a turn that used tools through the same chain renderer as the live
+ // conversation, so its process (reasoning + tool calls + intermediate prose)
+ // folds under the same turn-process header ("共运行 {n} 步") instead of
+ // expanding every step.
+ if (view === 'assistant-turn-chain') {
return (
<Flexbox horizontal gap={8} paddingBlock={4}>
<Avatar {...agentAvatar} name={agentDisplayName(agentAvatar)} size={28} />
- <Flexbox flex={1} gap={8} style={{ overflow: 'hidden' }}>
- {children.map((block) => (
- <ContentBlock {...block} disableEditing assistantId={message.id} key={block.id} />
- ))}
+ <Flexbox flex={1} style={{ overflow: 'hidden' }}>
+ <Group
+ disableEditing
+ enableProcessFold
+ blocks={children ?? []}
+ id={message.id}
+ // Compressed history is never the conversation's live tail, so it
+ // must not wait for the latest turn's "final answer exists" guard.
+ isLatestItem={false}
+ // Only feeds the (disabled) edit affordance.
+ messageIndex={0}
+ />
</Flexbox>
</Flexbox>
);
diff --git a/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.test.ts b/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.test.ts
new file mode 100644
index 00000000000..798278b6063
--- /dev/null
+++ b/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.test.ts
@@ -0,0 +1,43 @@
+import type { UIChatMessage } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { resolveCompressedMessageView } from './resolveCompressedMessageView';
+
+const message = (input: Partial<UIChatMessage> & { role: string }) =>
+ input as Pick<UIChatMessage, 'children' | 'role'>;
+
+describe('resolveCompressedMessageView', () => {
+ it('sends an assistant group with tool steps through the folded turn renderer', () => {
+ // Regression: the history view rendered these blocks one by one, expanding
+ // every reasoning and tool step of the compressed turn at once. It must use
+ // the same chain renderer as the conversation, which folds the process.
+ const turn = message({
+ children: [
+ { content: 'Running the checks.', id: 'block-1', tools: [{ id: 'tool-1' } as any] } as any,
+ { content: 'Here is the final answer.', id: 'block-2' } as any,
+ ],
+ role: 'assistantGroup',
+ });
+
+ expect(resolveCompressedMessageView(turn)).toBe('assistant-turn-chain');
+ });
+
+ it('keeps a tool-less assistant message on the plain content renderer', () => {
+ expect(resolveCompressedMessageView(message({ content: 'Answer', role: 'assistant' }))).toBe(
+ 'assistant-content',
+ );
+ });
+
+ it('renders user messages with the shared user renderer', () => {
+ expect(resolveCompressedMessageView(message({ content: 'Question', role: 'user' }))).toBe(
+ 'user',
+ );
+ });
+
+ it('renders nothing for roles the history view does not carry', () => {
+ expect(resolveCompressedMessageView(message({ role: 'tool' }))).toBe('none');
+ expect(resolveCompressedMessageView(message({ role: 'system' }))).toBe('none');
+ // An assistant group without projected blocks has nothing to show.
+ expect(resolveCompressedMessageView(message({ role: 'assistantGroup' }))).toBe('none');
+ });
+});
diff --git a/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.ts b/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.ts
new file mode 100644
index 00000000000..b4ce3fe5adf
--- /dev/null
+++ b/src/features/Conversation/Messages/CompressedGroup/resolveCompressedMessageView.ts
@@ -0,0 +1,37 @@
+import type { UIChatMessage } from '@lobechat/types';
+
+/**
+ * How one message inside a compressed group is rendered — the history view
+ * reuses the live conversation's components rather than re-implementing them.
+ */
+export type CompressedMessageView =
+ | 'assistant-content'
+ /** The assistant-group chain renderer, which folds the turn's process. */
+ | 'assistant-turn-chain'
+ | 'none'
+ | 'user';
+
+/**
+ * A turn that used tools must go through the assistant-group chain renderer
+ * (`AssistantGroup/components/Group`, with process folding on): that renderer
+ * folds the turn's process — reasoning, tool calls and intermediate prose —
+ * under one turn-process header ("共运行 {n} 步") and keeps only the final
+ * answer visible.
+ *
+ * Rendering such a turn's blocks one by one instead expands every step of the
+ * historical turn into the history view at once, which is not how the same turn
+ * reads in the conversation above it.
+ */
+export const resolveCompressedMessageView = (
+ message: Pick<UIChatMessage, 'children' | 'role'>,
+): CompressedMessageView => {
+ if (message.role === 'user') return 'user';
+
+ // A tool-less assistant message is a single answer block: nothing to fold.
+ if (message.role === 'assistant') return 'assistant-content';
+
+ if (message.role === 'assistantGroup' && message.children) return 'assistant-turn-chain';
+
+ // Other roles (tool, system, …) are not rendered in the history view.
+ return 'none';
+};