@lobehub/chat 0.120.3 → 0.120.4

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 (54) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +9 -9
  3. package/README.zh-CN.md +14 -14
  4. package/docs/Home.md +2 -2
  5. package/docs/_Sidebar.md +3 -3
  6. package/package.json +3 -2
  7. package/src/app/chat/(desktop)/features/ChatHeader.tsx +6 -6
  8. package/src/app/chat/{features → (desktop)/features/SideBar}/SystemRole/index.tsx +8 -5
  9. package/src/app/chat/(desktop)/features/{SideBar.tsx → SideBar/index.tsx} +2 -3
  10. package/src/app/chat/(mobile)/index.tsx +17 -4
  11. package/src/app/chat/(mobile)/mobile/page.tsx +30 -2
  12. package/src/app/chat/components/SessionHydration/index.tsx +44 -0
  13. package/src/app/chat/features/SessionListContent/DefaultMode.tsx +6 -1
  14. package/src/app/chat/features/SessionListContent/List/index.tsx +7 -3
  15. package/src/app/chat/features/TopicListContent/Header.tsx +1 -1
  16. package/src/app/chat/page.tsx +7 -3
  17. package/src/app/home/Redirect.tsx +2 -2
  18. package/src/app/metadata.ts +6 -0
  19. package/src/app/welcome/features/Banner/index.tsx +6 -7
  20. package/src/components/StoreHydration/ChatHydration/index.tsx +33 -0
  21. package/src/config/server.ts +4 -0
  22. package/src/const/url.ts +1 -1
  23. package/src/database/models/__tests__/message.test.ts +3 -2
  24. package/src/database/models/message.ts +13 -9
  25. package/src/database/schemas/message.ts +1 -1
  26. package/src/features/ChatInput/useChatInput.ts +2 -6
  27. package/src/features/Conversation/hooks/useInitConversation.ts +0 -2
  28. package/src/features/Conversation/index.tsx +7 -2
  29. package/src/features/SideBar/TopActions.tsx +5 -5
  30. package/src/layout/GlobalLayout/StoreHydration.tsx +12 -11
  31. package/src/store/chat/slices/message/action.ts +1 -1
  32. package/src/store/chat/store.ts +2 -34
  33. package/src/store/global/slices/common/action.ts +6 -0
  34. package/src/store/global/slices/common/initialState.ts +5 -0
  35. package/src/store/session/index.ts +0 -1
  36. package/src/store/session/initialState.ts +6 -2
  37. package/src/store/session/slices/agent/selectors.ts +3 -1
  38. package/src/store/session/slices/session/action.ts +13 -17
  39. package/src/store/session/slices/session/selectors/list.ts +7 -0
  40. package/src/store/session/store.ts +5 -46
  41. package/src/app/chat/(mobile)/layout.mobile.tsx +0 -17
  42. package/src/app/chat/(mobile)/mobile/index.tsx +0 -30
  43. package/src/app/chat/(mobile)/mobile/layout.mobile.tsx +0 -11
  44. package/src/store/session/hooks/index.ts +0 -4
  45. package/src/store/session/hooks/useEffectAfterHydrated.ts +0 -27
  46. package/src/store/session/hooks/useOnFinishHydrationSession.ts +0 -19
  47. package/src/store/session/hooks/useSessionChatInit.ts +0 -12
  48. package/src/store/session/hooks/useSessionHydrated.ts +0 -13
  49. /package/docs/Development/{index.md → Intro.md} +0 -0
  50. /package/docs/Development/{index.zh-CN.md → Intro.zh-CN.md} +0 -0
  51. /package/docs/Development/State-Management/{index.md → State-Management-Intro.md} +0 -0
  52. /package/docs/Development/State-Management/{index.zh-CN.md → State-Management-Intro.zh-CN.md} +0 -0
  53. /package/src/app/chat/{features → (desktop)/features/SideBar}/SystemRole/style.ts +0 -0
  54. /package/src/app/chat/{features → components}/SidebarHeader/index.tsx +0 -0
@@ -1,27 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- import { SessionStore, useSessionStore } from '../store';
4
-
5
- export const useEffectAfterSessionHydrated = (
6
- fn: (session: typeof useSessionStore, store: SessionStore) => void,
7
- deps: any[] = [],
8
- ) => {
9
- // const hasTrigger = useRef(false);
10
- useEffect(() => {
11
- const hasRehydrated = useSessionStore.persist.hasHydrated();
12
-
13
- if (hasRehydrated) {
14
- // equal useEffect triggered multi-time
15
- fn(useSessionStore, useSessionStore.getState());
16
- } else {
17
- // keep onFinishHydration just are triggered only once
18
- // if (hasTrigger.current) return;
19
- //
20
- // hasTrigger.current = true;
21
- // equal useEffect first trigger
22
- useSessionStore.persist.onFinishHydration(() => {
23
- fn(useSessionStore, useSessionStore.getState());
24
- });
25
- }
26
- }, deps);
27
- };
@@ -1,19 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { StoreApi, UseBoundStore } from 'zustand';
3
-
4
- import { SessionStore, useSessionStore } from '../store';
5
-
6
- /**
7
- * 当 Session 水合完毕后才会执行的 useEffect
8
- * @param fn
9
- */
10
- export const useOnFinishHydrationSession = (
11
- fn: (state: SessionStore, store: UseBoundStore<StoreApi<SessionStore>>) => void,
12
- ) => {
13
- useEffect(() => {
14
- // 只有当水合完毕后再开始做操作
15
- useSessionStore.persist.onFinishHydration(() => {
16
- fn(useSessionStore.getState(), useSessionStore);
17
- });
18
- }, []);
19
- };
@@ -1,12 +0,0 @@
1
- import { useSessionStore } from '../store';
2
- import { useSessionHydrated } from './useSessionHydrated';
3
-
4
- /**
5
- * 用于判断某个会话是否完全被激活
6
- */
7
- export const useSessionChatInit = () => {
8
- const sessionHydrated = useSessionHydrated();
9
- const [hasActive] = useSessionStore((s) => [!!s.activeId]);
10
-
11
- return sessionHydrated && hasActive;
12
- };
@@ -1,13 +0,0 @@
1
- import { useSessionStore } from '../store';
2
-
3
- export const useSessionHydrated = () => {
4
- const [fetchSessionsLoading, useFetchSessions] = useSessionStore((s) => [
5
- s.fetchSessionsLoading,
6
-
7
- s.useFetchSessions,
8
- ]);
9
-
10
- const { isLoading } = useFetchSessions();
11
-
12
- return !(isLoading || fetchSessionsLoading);
13
- };
File without changes