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: improve agent loading state (#11511)

Arvin Xu3bb7f331f26e
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index eff353923ce..cec87739831 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -203,6 +203,8 @@
"noMembersYet": "This group doesn't have any members yet. Click the + button to invite agents.",
"noSelectedAgents": "No members selected yet",
"openInNewWindow": "Open in New Window",
+ "operation.execAgentRuntime": "Preparing response",
+ "operation.sendMessage": "Sending message",
"owner": "Group owner",
"pageCopilot.title": "Page Agent",
"pageCopilot.welcome": "**Clearer, sharper writing**\n\nDraft, rewrite, or polish—tell me your intent and I’ll refine the rest.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 84ec23d4df0..523bfd2d2ca 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -203,6 +203,8 @@
"noMembersYet": "这个群组还没有成员。点击「+」邀请助理加入",
"noSelectedAgents": "还未选择成员",
"openInNewWindow": "在新窗口打开",
+ "operation.execAgentRuntime": "准备响应中",
+ "operation.sendMessage": "消息发送中",
"owner": "群主",
"pageCopilot.title": "文稿助理",
"pageCopilot.welcome": "**让文字更清晰、更到位**\n\n起草、改写、润色都可以。你把意图说清楚,其余交给我打磨",
diff --git a/src/features/ChatInput/ChatInputProvider.tsx b/src/features/ChatInput/ChatInputProvider.tsx
index 5c014220896..ff6029d34e5 100644
--- a/src/features/ChatInput/ChatInputProvider.tsx
+++ b/src/features/ChatInput/ChatInputProvider.tsx
@@ -21,7 +21,7 @@ export const ChatInputProvider = memo<ChatInputProviderProps>(
chatInputEditorRef,
onMarkdownContentChange,
mentionItems,
- allowExpand,
+ allowExpand = true,
}) => {
const editor = useEditor();
const slashMenuRef = useRef<HTMLDivElement>(null);
diff --git a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
index 9e058f47695..ffae7b4d983 100644
--- a/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
+++ b/src/features/Conversation/Messages/Assistant/components/MessageContent.tsx
@@ -8,7 +8,6 @@ import { CollapsedMessage } from '../../AssistantGroup/components/CollapsedMessa
import DisplayContent from '../../components/DisplayContent';
import FileChunks from '../../components/FileChunks';
import ImageFileListViewer from '../../components/ImageFileListViewer';
-import IntentUnderstanding from '../../components/IntentUnderstanding';
import Reasoning from '../../components/Reasoning';
import SearchGrounding from '../../components/SearchGrounding';
import { useMarkdown } from '../useMarkdown';
@@ -23,9 +22,6 @@ const MessageContent = memo<UIChatMessage>(
const isToolCallGenerating = generating && (content === LOADING_FLAT || !content) && !!tools;
- // TODO: Need to implement isIntentUnderstanding selector in ConversationStore if needed
- const isIntentUnderstanding = false;
-
const showSearch = !!search && !!search.citations?.length;
const showImageItems = !!imageList && imageList.length > 0;
@@ -46,18 +42,15 @@ const MessageContent = memo<UIChatMessage>(
)}
{showFileChunks && <FileChunks data={chunksList} />}
{showReasoning && <Reasoning {...props.reasoning} id={id} />}
- {isIntentUnderstanding ? (
- <IntentUnderstanding />
- ) : (
- <DisplayContent
- content={content}
- hasImages={showImageItems}
- isMultimodal={metadata?.isMultimodal}
- isToolCallGenerating={isToolCallGenerating}
- markdownProps={markdownProps}
- tempDisplayContent={metadata?.tempDisplayContent}
- />
- )}
+ <DisplayContent
+ content={content}
+ hasImages={showImageItems}
+ id={id}
+ isMultimodal={metadata?.isMultimodal}
+ isToolCallGenerating={isToolCallGenerating}
+ markdownProps={markdownProps}
+ tempDisplayContent={metadata?.tempDisplayContent}
+ />
{showImageItems && <ImageFileListViewer items={imageList} />}
</Flexbox>
);
diff --git a/src/features/Conversation/Messages/Task/components/MessageContent.tsx b/src/features/Conversation/Messages/Task/components/MessageContent.tsx
index c14cb69c800..797b8df38b7 100644
--- a/src/features/Conversation/Messages/Task/components/MessageContent.tsx
+++ b/src/features/Conversation/Messages/Task/components/MessageContent.tsx
@@ -52,6 +52,7 @@ const MessageContent = memo<UIChatMessage>(
<DisplayContent
content={content}
hasImages={showImageItems}
+ id={id}
isMultimodal={metadata?.isMultimodal}
isToolCallGenerating={isToolCallGenerating}
markdownProps={markdownProps}
diff --git a/src/features/Conversation/Messages/components/ContentLoading.tsx b/src/features/Conversation/Messages/components/ContentLoading.tsx
new file mode 100644
index 00000000000..63bbe33f578
--- /dev/null
+++ b/src/features/Conversation/Messages/components/ContentLoading.tsx
@@ -0,0 +1,64 @@
+import { Flexbox, Text } from '@lobehub/ui';
+import { memo, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import BubblesLoading from '@/components/BubblesLoading';
+import { useChatStore } from '@/store/chat';
+import { operationSelectors } from '@/store/chat/selectors';
+import type { OperationType } from '@/store/chat/slices/operation/types';
+
+const ELAPSED_TIME_THRESHOLD = 2100; // Show elapsed time after 2 seconds
+
+interface ContentLoadingProps {
+ id: string;
+}
+
+const ContentLoading = memo<ContentLoadingProps>(({ id }) => {
+ const { t } = useTranslation('chat');
+ const operations = useChatStore(operationSelectors.getOperationsByMessage(id));
+ const [elapsedSeconds, setElapsedSeconds] = useState(0);
+
+ // Get the running operation
+ const runningOp = operations.find((op) => op.status === 'running');
+ const operationType = runningOp?.type as OperationType | undefined;
+ const startTime = runningOp?.metadata?.startTime;
+
+ // Track elapsed time, reset when operation type changes
+ useEffect(() => {
+ if (!startTime) {
+ setElapsedSeconds(0);
+ return;
+ }
+
+ const updateElapsed = () => {
+ const elapsed = Math.floor((Date.now() - startTime) / 1000);
+ setElapsedSeconds(elapsed);
+ };
+
+ updateElapsed();
+ const interval = setInterval(updateElapsed, 1000);
+
+ return () => clearInterval(interval);
+ }, [startTime, operationType]);
+
+ // Get localized label based on operation type
+ const operationLabel = operationType
+ ? (t(`operation.${operationType}` as any) as string)
+ : undefined;
+
+ const showElapsedTime = elapsedSeconds >= ELAPSED_TIME_THRESHOLD / 1000;
+
+ return (
+ <Flexbox align={'center'} horizontal>
+ <BubblesLoading />
+ {operationLabel && (
+ <Text type={'secondary'}>
+ {operationLabel}...
+ {showElapsedTime && ` (${elapsedSeconds}s)`}
+ </Text>
+ )}
+ </Flexbox>
+ );
+});
+
+export default ContentLoading;
diff --git a/src/features/Conversation/Messages/components/DisplayContent.tsx b/src/features/Conversation/Messages/components/DisplayContent.tsx
index 68d21f0403d..88410f8fc83 100644
--- a/src/features/Conversation/Messages/components/DisplayContent.tsx
+++ b/src/features/Conversation/Messages/components/DisplayContent.tsx
@@ -2,17 +2,18 @@ import { deserializeParts } from '@lobechat/utils';
import { type MarkdownProps } from '@lobehub/ui';
import { memo } from 'react';
-import BubblesLoading from '@/components/BubblesLoading';
import { LOADING_FLAT } from '@/const/message';
import MarkdownMessage from '@/features/Conversation/Markdown';
import { normalizeThinkTags, processWithArtifact } from '../../utils/markdown';
+import ContentLoading from './ContentLoading';
import { RichContentRenderer } from './RichContentRenderer';
const DisplayContent = memo<{
addIdOnDOM?: boolean;
content: string;
hasImages?: boolean;
+ id: string;
isMultimodal?: boolean;
isToolCallGenerating?: boolean;
markdownProps?: Omit<MarkdownProps, 'className' | 'style' | 'children'>;
@@ -25,11 +26,12 @@ const DisplayContent = memo<{
hasImages,
isMultimodal,
tempDisplayContent,
+ id,
}) => {
const message = normalizeThinkTags(processWithArtifact(content));
if (isToolCallGenerating) return;
- if ((!content && !hasImages) || content === LOADING_FLAT) return <BubblesLoading />;
+ if ((!content && !hasImages) || content === LOADING_FLAT) return <ContentLoading id={id} />;
const contentParts = isMultimodal ? deserializeParts(tempDisplayContent || content) : null;
diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.ts
index 405e0ba5676..73eabcbde2a 100644
--- a/src/locales/default/chat.ts
+++ b/src/locales/default/chat.ts
@@ -229,6 +229,8 @@ export default {
'noMembersYet': "This group doesn't have any members yet. Click the + button to invite agents.",
'noSelectedAgents': 'No members selected yet',
'openInNewWindow': 'Open in New Window',
+ 'operation.execAgentRuntime': 'Preparing response',
+ 'operation.sendMessage': 'Sending message',
'owner': 'Group owner',
'pageCopilot.title': 'Page Agent',
'pageCopilot.welcome':
diff --git a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts b/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts
index 42f4cf876b7..7ab341addd6 100644
--- a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts
+++ b/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts
@@ -204,8 +204,9 @@ export const conversationLifecycle: StateCreator<
);
get().internal_toggleMessageLoading(true, tempId);
- // Associate temp message with operation
+ // Associate temp messages with operation
get().associateMessageWithOperation(tempId, operationId);
+ get().associateMessageWithOperation(tempAssistantId, operationId);
// Store editor state in operation metadata for cancel restoration
const jsonState = mainInputEditor?.getJSONState();