🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor: refactor chat selectors (#10274)
Arvin Xu0a056f3f0bbb
diff --git a/src/components/Analytics/MainInterfaceTracker.tsx b/src/components/Analytics/MainInterfaceTracker.tsxindex 1c80eefe8f5..d53e775f9bd 100644--- a/src/components/Analytics/MainInterfaceTracker.tsx+++ b/src/components/Analytics/MainInterfaceTracker.tsx@@ -4,7 +4,7 @@ import { useAnalytics } from '@lobehub/analytics/react';import { memo, useCallback, useEffect } from 'react';import { getChatStoreState } from '@/store/chat';-import { chatSelectors } from '@/store/chat/slices/message/selectors';+import { displayMessageSelectors } from '@/store/chat/selectors';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';import { getSessionStoreState } from '@/store/session';@@ -18,7 +18,7 @@ const MainInterfaceTracker = memo(() => {const activeSessionId = currentSession?.id;const defaultSessions = sessionSelectors.defaultSessions(getSessionStoreState());const showChatSideBar = systemStatusSelectors.showChatSideBar(useGlobalStore.getState());- const messages = chatSelectors.activeBaseChats(getChatStoreState());+ const messages = displayMessageSelectors.activeDisplayMessages(getChatStoreState());return {active_assistant: activeSessionId === 'inbox' ? null : currentSession?.meta?.title || null,has_chat_history: messages.length > 0,diff --git a/src/features/Conversation/MarkdownElements/LobeThinking/Render.tsx b/src/features/Conversation/MarkdownElements/LobeThinking/Render.tsxindex d1a720adf62..c21802ce5a1 100644--- a/src/features/Conversation/MarkdownElements/LobeThinking/Render.tsx+++ b/src/features/Conversation/MarkdownElements/LobeThinking/Render.tsx@@ -1,9 +1,9 @@+import { ARTIFACT_THINKING_TAG } from '@lobechat/const';import { memo } from 'react';import Thinking from '@/components/Thinking';-import { ARTIFACT_THINKING_TAG } from '@/const/plugin';import { useChatStore } from '@/store/chat';-import { chatSelectors } from '@/store/chat/selectors';+import { dbMessageSelectors } from '@/store/chat/selectors';import { useUserStore } from '@/store/user';import { userGeneralSettingsSelectors } from '@/store/user/selectors';@@ -12,7 +12,7 @@ import { isTagClosed } from '../utils';const Render = memo<MarkdownElementProps>(({ children, id }) => {const [isGenerating] = useChatStore((s) => {- const message = chatSelectors.getMessageById(id)(s);+ const message = dbMessageSelectors.getDbMessageById(id)(s);return [!isTagClosed(ARTIFACT_THINKING_TAG, message?.content)];});const transitionMode = useUserStore(userGeneralSettingsSelectors.transitionMode);diff --git a/src/features/Conversation/MarkdownElements/Thinking/Render.tsx b/src/features/Conversation/MarkdownElements/Thinking/Render.tsxindex 2b3847bbbc8..4de2c644985 100644--- a/src/features/Conversation/MarkdownElements/Thinking/Render.tsx+++ b/src/features/Conversation/MarkdownElements/Thinking/Render.tsx@@ -2,7 +2,7 @@ import { memo } from 'react';import Thinking from '@/components/Thinking';import { useChatStore } from '@/store/chat';-import { chatSelectors } from '@/store/chat/selectors';+import { dbMessageSelectors } from '@/store/chat/selectors';import { useUserStore } from '@/store/user';import { userGeneralSettingsSelectors } from '@/store/user/selectors';@@ -17,11 +17,11 @@ const isThinkingClosed = (input: string = '') => {const Render = memo<MarkdownElementProps>(({ children, id }) => {const [isGenerating] = useChatStore((s) => {- const message = chatSelectors.getMessageById(id)(s);+ const message = dbMessageSelectors.getDbMessageById(id)(s);return [!isThinkingClosed(message?.content)];});const citations = useChatStore((s) => {- const message = chatSelectors.getMessageById(id)(s);+ const message = dbMessageSelectors.getDbMessageById(id)(s);return message?.search?.citations;});diff --git a/src/features/PluginsUI/Render/StandaloneType/Iframe.tsx b/src/features/PluginsUI/Render/StandaloneType/Iframe.tsxindex 047ee5029d5..b8b3da97cfa 100644--- a/src/features/PluginsUI/Render/StandaloneType/Iframe.tsx+++ b/src/features/PluginsUI/Render/StandaloneType/Iframe.tsx@@ -3,7 +3,7 @@ import { Skeleton } from 'antd';import { memo, useRef, useState } from 'react';import { useChatStore } from '@/store/chat';-import { chatSelectors } from '@/store/chat/selectors';+import { dbMessageSelectors } from '@/store/chat/selectors';import { useToolStore } from '@/store/tool';import { pluginSelectors } from '@/store/tool/selectors';@@ -28,7 +28,7 @@ import {// just to simplify code a little, don't use this pattern everywhereconst getSettings = (identifier: string) =>pluginSelectors.getPluginSettingsById(identifier)(useToolStore.getState());-const getMessage = (id: string) => chatSelectors.getMessageById(id)(useChatStore.getState());+const getMessage = (id: string) => dbMessageSelectors.getDbMessageById(id)(useChatStore.getState());interface IFrameRenderProps {height?: number;@@ -61,7 +61,7 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, id, payload, width = 600, hconst iframeWin = iframeRef.current?.contentWindow;if (iframeWin) {- const message = chatSelectors.getMessageById(id)(useChatStore.getState());+ const message = dbMessageSelectors.getDbMessageById(id)(useChatStore.getState());if (!message) return;const props = { content: '' };diff --git a/src/features/Portal/Home/Body/Plugins/ArtifactList/index.tsx b/src/features/Portal/Home/Body/Plugins/ArtifactList/index.tsxindex 30a30e1c88b..c7f4157d30c 100644--- a/src/features/Portal/Home/Body/Plugins/ArtifactList/index.tsx+++ b/src/features/Portal/Home/Body/Plugins/ArtifactList/index.tsx@@ -8,14 +8,14 @@ import { Center, Flexbox } from 'react-layout-kit';import Balancer from 'react-wrap-balancer';import { useChatStore } from '@/store/chat';-import { chatSelectors } from '@/store/chat/selectors';+import { dbMessageSelectors, displayMessageSelectors } from '@/store/chat/selectors';import ArtifactItem from './Item';const ArtifactList = () => {const { t } = useTranslation('portal');- const messages = useChatStore(chatSelectors.currentToolMessages, isEqual);- const isCurrentChatLoaded = useChatStore(chatSelectors.isCurrentChatLoaded);+ const messages = useChatStore(dbMessageSelectors.dbToolMessages, isEqual);+ const isCurrentChatLoaded = useChatStore(displayMessageSelectors.isCurrentDisplayChatLoaded);const theme = useTheme();return !isCurrentChatLoaded ? (diff --git a/src/features/ShareModal/ShareText/index.tsx b/src/features/ShareModal/ShareText/index.tsxindex 53ad0909868..508696ebb1f 100644--- a/src/features/ShareModal/ShareText/index.tsx+++ b/src/features/ShareModal/ShareText/index.tsx@@ -1,3 +1,4 @@+import { FORM_STYLE } from '@lobechat/const';import { exportFile } from '@lobechat/utils/client';import { Button, Form, type FormItemProps, copyToClipboard } from '@lobehub/ui';import { App, Switch } from 'antd';@@ -7,12 +8,11 @@ import { memo, useState } from 'react';import { useTranslation } from 'react-i18next';import { Flexbox } from 'react-layout-kit';-import { FORM_STYLE } from '@/const/layoutTokens';import { useIsMobile } from '@/hooks/useIsMobile';import { useAgentStore } from '@/store/agent';import { agentSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';-import { chatSelectors, topicSelectors } from '@/store/chat/selectors';+import { displayMessageSelectors, topicSelectors } from '@/store/chat/selectors';import { useStyles } from '../style';import Preview from './Preview';@@ -67,7 +67,7 @@ const ShareText = memo(() => {];const [systemRole] = useAgentStore((s) => [agentSelectors.currentAgentSystemRole(s)]);- const messages = useChatStore(chatSelectors.activeBaseChats, isEqual);+ const messages = useChatStore(displayMessageSelectors.activeDisplayMessages, isEqual);const topic = useChatStore(topicSelectors.currentActiveTopic, isEqual);const title = topic?.title || t('shareModal.exportTitle');diff --git a/src/store/chat/slices/topic/action.ts b/src/store/chat/slices/topic/action.tsindex c882dbf917f..f00c5f8285a 100644--- a/src/store/chat/slices/topic/action.ts+++ b/src/store/chat/slices/topic/action.ts@@ -27,7 +27,7 @@ import { ChatTopic, CreateTopicParams } from '@/types/topic';import { merge } from '@/utils/merge';import { setNamespace } from '@/utils/storeDebug';-import { chatSelectors } from '../message/selectors';+import { displayMessageSelectors } from '../message/selectors';import { ChatTopicDispatch, topicReducer } from './reducer';import { topicSelectors } from './selectors';@@ -92,7 +92,7 @@ export const chatTopic: StateCreator<createTopic: async (sessionId, groupId) => {const { activeId, activeSessionType, internal_createTopic } = get();- const messages = chatSelectors.activeBaseChats(get());+ const messages = displayMessageSelectors.activeDisplayMessages(get());set({ creatingTopic: true }, false, n('creatingTopic/start'));const topicId = await internal_createTopic({@@ -109,7 +109,7 @@ export const chatTopic: StateCreator<saveToTopic: async (sessionId, groupId) => {// if there is no message, stop- const messages = chatSelectors.activeBaseChats(get());+ const messages = displayMessageSelectors.activeDisplayMessages(get());if (messages.length === 0) return;const { activeId, activeSessionType, summaryTopicTitle, internal_createTopic } = get();