@lobehub/chat 1.32.4 → 1.32.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.json +2 -2
  3. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/ChatItem/index.tsx +39 -0
  4. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/Content.tsx +20 -14
  5. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/WelcomeMessage.tsx +44 -0
  6. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/index.tsx +17 -0
  7. package/src/app/(main)/chat/(workspace)/@portal/features/Header.tsx +1 -13
  8. package/src/components/BrandWatermark/index.tsx +1 -0
  9. package/src/const/message.ts +1 -1
  10. package/src/features/Conversation/components/ChatItem/ActionsBar.tsx +9 -13
  11. package/src/features/Conversation/components/ChatItem/index.tsx +183 -209
  12. package/src/features/Conversation/components/VirtualizedList/index.tsx +75 -84
  13. package/src/features/Conversation/index.ts +0 -1
  14. package/src/features/Portal/Artifacts/index.ts +1 -1
  15. package/src/features/Portal/FilePreview/index.ts +1 -1
  16. package/src/features/Portal/Home/{Header.tsx → Title.tsx} +2 -2
  17. package/src/features/Portal/Home/index.ts +1 -1
  18. package/src/features/Portal/MessageDetail/index.ts +1 -1
  19. package/src/features/Portal/Plugins/index.ts +1 -1
  20. package/src/features/Portal/components/Header.tsx +29 -0
  21. package/src/features/Portal/router.tsx +22 -3
  22. package/src/features/Portal/type.ts +3 -1
  23. package/src/features/{Conversation/components → ShareModal/ShareImage}/ChatList/index.tsx +3 -4
  24. package/src/features/ShareModal/ShareImage/Preview.tsx +1 -1
  25. package/src/features/ShareModal/ShareJSON/index.tsx +1 -1
  26. package/src/features/ShareModal/ShareText/index.tsx +1 -1
  27. package/src/layout/GlobalProvider/Debug.tsx +15 -0
  28. package/src/layout/GlobalProvider/index.tsx +2 -0
  29. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +5 -5
  30. package/src/store/chat/slices/message/action.ts +2 -2
  31. package/src/store/chat/slices/message/selectors.test.ts +0 -86
  32. package/src/store/chat/slices/message/selectors.ts +55 -73
  33. package/src/store/chat/slices/plugin/action.test.ts +2 -2
  34. package/src/store/chat/slices/plugin/action.ts +1 -1
  35. package/src/store/chat/slices/topic/action.ts +2 -2
  36. /package/src/{features/Conversation/components → app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem}/InboxWelcome/AgentsSuggest.tsx +0 -0
  37. /package/src/{features/Conversation/components → app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem}/InboxWelcome/QuestionSuggest.tsx +0 -0
  38. /package/src/{features/Conversation/components → app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem}/InboxWelcome/index.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.32.5](https://github.com/lobehub/lobe-chat/compare/v1.32.4...v1.32.5)
6
+
7
+ <sup>Released on **2024-11-24**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor the main chat.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor the main chat, closes [#4773](https://github.com/lobehub/lobe-chat/issues/4773) ([6973f4e](https://github.com/lobehub/lobe-chat/commit/6973f4e))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.32.4](https://github.com/lobehub/lobe-chat/compare/v1.32.3...v1.32.4)
6
31
 
7
32
  <sup>Released on **2024-11-20**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.32.4",
3
+ "version": "1.32.5",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -302,7 +302,7 @@
302
302
  "vitest": "~1.2.2",
303
303
  "vitest-canvas-mock": "^0.3.3"
304
304
  },
305
- "packageManager": "pnpm@9.13.2",
305
+ "packageManager": "pnpm@9.14.2",
306
306
  "publishConfig": {
307
307
  "access": "public",
308
308
  "registry": "https://registry.npmjs.org"
@@ -0,0 +1,39 @@
1
+ import React, { memo, useMemo } from 'react';
2
+
3
+ import { ChatItem } from '@/features/Conversation';
4
+ import ActionsBar from '@/features/Conversation/components/ChatItem/ActionsBar';
5
+ import { useAgentStore } from '@/store/agent';
6
+ import { agentSelectors } from '@/store/agent/selectors';
7
+ import { useChatStore } from '@/store/chat';
8
+ import { chatSelectors } from '@/store/chat/selectors';
9
+
10
+ export interface ThreadChatItemProps {
11
+ id: string;
12
+ index: number;
13
+ }
14
+
15
+ const MainChatItem = memo<ThreadChatItemProps>(({ id, index }) => {
16
+ const [historyLength] = useChatStore((s) => [chatSelectors.mainDisplayChatIDs(s).length]);
17
+
18
+ const enableHistoryDivider = useAgentStore((s) => {
19
+ const config = agentSelectors.currentAgentChatConfig(s);
20
+ return (
21
+ config.enableHistoryCount &&
22
+ historyLength > (config.historyCount ?? 0) &&
23
+ config.historyCount === historyLength - index
24
+ );
25
+ });
26
+
27
+ const actionBar = useMemo(() => <ActionsBar id={id} />, [id]);
28
+
29
+ return (
30
+ <ChatItem
31
+ actionBar={actionBar}
32
+ enableHistoryDivider={enableHistoryDivider}
33
+ id={id}
34
+ index={index}
35
+ />
36
+ );
37
+ });
38
+
39
+ export default MainChatItem;
@@ -1,35 +1,41 @@
1
1
  'use client';
2
2
 
3
- import isEqual from 'fast-deep-equal';
4
- import React, { memo } from 'react';
3
+ import React, { memo, useCallback } from 'react';
5
4
 
6
- import { InboxWelcome, VirtualizedList } from '@/features/Conversation';
5
+ import { SkeletonList, VirtualizedList } from '@/features/Conversation';
7
6
  import { useChatStore } from '@/store/chat';
8
7
  import { chatSelectors } from '@/store/chat/selectors';
9
8
  import { useSessionStore } from '@/store/session';
10
9
 
10
+ import MainChatItem from './ChatItem';
11
+ import Welcome from './WelcomeChatItem';
12
+
11
13
  interface ListProps {
12
14
  mobile?: boolean;
13
15
  }
14
16
 
15
17
  const Content = memo<ListProps>(({ mobile }) => {
16
- const [activeTopicId, useFetchMessages, showInboxWelcome, isCurrentChatLoaded] = useChatStore(
17
- (s) => [
18
- s.activeTopicId,
19
- s.useFetchMessages,
20
- chatSelectors.showInboxWelcome(s),
21
- chatSelectors.isCurrentChatLoaded(s),
22
- ],
23
- );
18
+ const [activeTopicId, useFetchMessages, isCurrentChatLoaded] = useChatStore((s) => [
19
+ s.activeTopicId,
20
+ s.useFetchMessages,
21
+ chatSelectors.isCurrentChatLoaded(s),
22
+ ]);
24
23
 
25
24
  const [sessionId] = useSessionStore((s) => [s.activeId]);
26
25
  useFetchMessages(sessionId, activeTopicId);
27
26
 
28
- const data = useChatStore(chatSelectors.currentChatIDsWithGuideMessage, isEqual);
27
+ const data = useChatStore(chatSelectors.mainDisplayChatIDs);
28
+
29
+ const itemContent = useCallback(
30
+ (index: number, id: string) => <MainChatItem id={id} index={index} />,
31
+ [mobile],
32
+ );
33
+
34
+ if (!isCurrentChatLoaded) return <SkeletonList mobile={mobile} />;
29
35
 
30
- if (showInboxWelcome && isCurrentChatLoaded) return <InboxWelcome />;
36
+ if (data.length === 0) return <Welcome />;
31
37
 
32
- return <VirtualizedList dataSource={data} mobile={mobile} />;
38
+ return <VirtualizedList dataSource={data} itemContent={itemContent} mobile={mobile} />;
33
39
  });
34
40
 
35
41
  Content.displayName = 'ChatListRender';
@@ -0,0 +1,44 @@
1
+ import { ChatItem } from '@lobehub/ui';
2
+ import isEqual from 'fast-deep-equal';
3
+ import React from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+
6
+ import { useAgentStore } from '@/store/agent';
7
+ import { agentSelectors } from '@/store/agent/selectors';
8
+ import { useChatStore } from '@/store/chat';
9
+ import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
10
+ import { useSessionStore } from '@/store/session';
11
+ import { sessionMetaSelectors } from '@/store/session/selectors';
12
+
13
+ const WelcomeMessage = () => {
14
+ const { t } = useTranslation('chat');
15
+ const [type = 'chat'] = useAgentStore((s) => {
16
+ const config = agentSelectors.currentAgentChatConfig(s);
17
+ return [config.displayMode];
18
+ });
19
+
20
+ const meta = useSessionStore(sessionMetaSelectors.currentAgentMeta, isEqual);
21
+ const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors);
22
+ const activeId = useChatStore((s) => s.activeId);
23
+
24
+ const agentSystemRoleMsg = t('agentDefaultMessageWithSystemRole', {
25
+ name: meta.title || t('defaultAgent'),
26
+ systemRole: meta.description,
27
+ });
28
+
29
+ const agentMsg = t(isAgentEditable ? 'agentDefaultMessage' : 'agentDefaultMessageWithoutEdit', {
30
+ name: meta.title || t('defaultAgent'),
31
+ url: `/chat/settings?session=${activeId}`,
32
+ });
33
+
34
+ return (
35
+ <ChatItem
36
+ avatar={meta}
37
+ editing={false}
38
+ message={!!meta.description ? agentSystemRoleMsg : agentMsg}
39
+ placement={'left'}
40
+ type={type === 'chat' ? 'block' : 'pure'}
41
+ />
42
+ );
43
+ };
44
+ export default WelcomeMessage;
@@ -0,0 +1,17 @@
1
+ import React, { memo } from 'react';
2
+
3
+ import { useChatStore } from '@/store/chat';
4
+ import { chatSelectors } from '@/store/chat/selectors';
5
+
6
+ import InboxWelcome from './InboxWelcome';
7
+ import WelcomeMessage from './WelcomeMessage';
8
+
9
+ const WelcomeChatItem = memo(() => {
10
+ const showInboxWelcome = useChatStore(chatSelectors.showInboxWelcome);
11
+
12
+ if (showInboxWelcome) return <InboxWelcome />;
13
+
14
+ return <WelcomeMessage />;
15
+ });
16
+
17
+ export default WelcomeChatItem;
@@ -1,23 +1,11 @@
1
1
  'use client';
2
2
 
3
- import { ActionIcon } from '@lobehub/ui';
4
- import { XIcon } from 'lucide-react';
5
3
  import { memo } from 'react';
6
4
 
7
- import SidebarHeader from '@/components/SidebarHeader';
8
5
  import { PortalHeader } from '@/features/Portal/router';
9
- import { useChatStore } from '@/store/chat';
10
6
 
11
7
  const Header = memo(() => {
12
- const [toggleInspector] = useChatStore((s) => [s.togglePortal]);
13
-
14
- return (
15
- <SidebarHeader
16
- actions={<ActionIcon icon={XIcon} onClick={() => toggleInspector(false)} />}
17
- style={{ paddingBlock: 8, paddingInline: 8 }}
18
- title={<PortalHeader />}
19
- />
20
- );
8
+ return <PortalHeader />;
21
9
  });
22
10
 
23
11
  export default Header;
@@ -26,6 +26,7 @@ const BrandWatermark = memo<Omit<FlexboxProps, 'children'>>(({ style, ...rest })
26
26
  return (
27
27
  <Flexbox
28
28
  align={'center'}
29
+ dir={'ltr'}
29
30
  flex={'none'}
30
31
  gap={4}
31
32
  horizontal
@@ -2,6 +2,6 @@ export const LOADING_FLAT = '...';
2
2
 
3
3
  export const MESSAGE_CANCEL_FLAT = 'canceled';
4
4
 
5
- export const MESSAGE_THREAD_DIVIDER_ID = 'thread-divider';
5
+ export const MESSAGE_THREAD_DIVIDER_ID = '__THREAD_DIVIDER__';
6
6
 
7
7
  export const MESSAGE_WELCOME_GUIDE_ID = 'welcome';
@@ -4,8 +4,7 @@ import { memo, useCallback } from 'react';
4
4
 
5
5
  import { useChatStore } from '@/store/chat';
6
6
  import { chatSelectors } from '@/store/chat/selectors';
7
- import { useSessionStore } from '@/store/session';
8
- import { sessionMetaSelectors } from '@/store/session/selectors';
7
+ import { MessageRoleType } from '@/types/message';
9
8
 
10
9
  import { renderActions, useActionsClick } from '../../Actions';
11
10
  import { useChatListActionsBar } from '../../hooks/useChatListActionsBar';
@@ -25,34 +24,31 @@ const ActionsBar = memo<ActionsBarProps>((props) => {
25
24
  });
26
25
 
27
26
  interface ActionsProps {
28
- index: number;
29
- setEditing: (edit: boolean) => void;
27
+ id: string;
30
28
  }
31
- const Actions = memo<ActionsProps>(({ index, setEditing }) => {
32
- const meta = useSessionStore(sessionMetaSelectors.currentAgentMeta, isEqual);
33
29
 
34
- const item = useChatStore(
35
- (s) => chatSelectors.currentChatsWithGuideMessage(meta)(s)[index],
36
- isEqual,
37
- );
30
+ const Actions = memo<ActionsProps>(({ id }) => {
31
+ const item = useChatStore(chatSelectors.getMessageById(id), isEqual);
32
+ const [toggleMessageEditing] = useChatStore((s) => [s.toggleMessageEditing]);
38
33
  const onActionsClick = useActionsClick();
39
34
 
40
35
  const handleActionClick = useCallback(
41
36
  async (action: ActionEvent) => {
42
37
  switch (action.key) {
43
38
  case 'edit': {
44
- setEditing(true);
39
+ toggleMessageEditing(id, true);
45
40
  }
46
41
  }
42
+ if (!item) return;
47
43
 
48
44
  onActionsClick(action, item);
49
45
  },
50
46
  [item],
51
47
  );
52
48
 
53
- const RenderFunction = renderActions[item?.role] ?? ActionsBar;
49
+ const RenderFunction = renderActions[(item?.role || '') as MessageRoleType] ?? ActionsBar;
54
50
 
55
- return <RenderFunction {...item} onActionClick={handleActionClick} />;
51
+ return <RenderFunction {...item!} onActionClick={handleActionClick} />;
56
52
  });
57
53
 
58
54
  export default Actions;