@lobehub/chat 0.150.9 → 0.150.10

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 (131) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.json +1 -1
  3. package/src/app/chat/(desktop)/features/ChatHeader/Tags.tsx +3 -3
  4. package/src/app/chat/(desktop)/features/ChatInput/Footer/DragUpload.tsx +3 -3
  5. package/src/app/chat/(desktop)/features/ChatInput/Footer/SendMore.tsx +3 -3
  6. package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +3 -3
  7. package/src/app/chat/(desktop)/features/ChatInput/TextArea.test.tsx +5 -5
  8. package/src/app/chat/(desktop)/features/ChatInput/TextArea.tsx +3 -3
  9. package/src/app/chat/(mobile)/features/SessionHeader.tsx +3 -3
  10. package/src/app/chat/features/ShareButton/ShareModal.tsx +3 -3
  11. package/src/app/chat/features/TelemetryNotification/index.tsx +2 -2
  12. package/src/app/chat/features/TopicListContent/Topic/index.tsx +2 -2
  13. package/src/app/chat/settings/features/SubmitAgentButton/SubmitAgentModal.tsx +3 -3
  14. package/src/app/settings/(mobile)/index.tsx +3 -3
  15. package/src/app/settings/about/Analytics.tsx +4 -4
  16. package/src/app/settings/agent/Agent.tsx +4 -4
  17. package/src/app/settings/common/Common.tsx +4 -4
  18. package/src/app/settings/common/Theme.tsx +4 -4
  19. package/src/app/settings/features/ThemeSwatches/ThemeSwatchesNeutral.tsx +3 -3
  20. package/src/app/settings/features/ThemeSwatches/ThemeSwatchesPrimary.tsx +3 -3
  21. package/src/app/settings/hooks/useSyncSettings.ts +3 -3
  22. package/src/app/settings/llm/Azure/index.tsx +3 -3
  23. package/src/app/settings/llm/components/ProviderConfig/index.tsx +3 -3
  24. package/src/app/settings/llm/components/ProviderModelList/CustomModelOption.tsx +4 -4
  25. package/src/app/settings/llm/components/ProviderModelList/ModelConfigModal.tsx +4 -4
  26. package/src/app/settings/llm/components/ProviderModelList/ModelFetcher.tsx +6 -6
  27. package/src/app/settings/llm/components/ProviderModelList/Option.tsx +3 -3
  28. package/src/app/settings/llm/components/ProviderModelList/index.tsx +6 -6
  29. package/src/app/settings/sync/Alert.tsx +3 -3
  30. package/src/app/settings/sync/DeviceInfo/DeviceName.tsx +3 -3
  31. package/src/app/settings/sync/WebRTC/index.tsx +2 -2
  32. package/src/app/settings/tts/TTS/index.tsx +4 -4
  33. package/src/chains/__tests__/summaryAgentName.test.ts +2 -2
  34. package/src/chains/__tests__/summaryDescription.test.ts +2 -2
  35. package/src/chains/__tests__/summaryTags.test.ts +2 -2
  36. package/src/chains/__tests__/summaryTitle.test.ts +2 -2
  37. package/src/chains/summaryAgentName.ts +1 -1
  38. package/src/chains/summaryDescription.ts +1 -1
  39. package/src/chains/summaryTags.ts +1 -1
  40. package/src/chains/summaryTitle.ts +1 -1
  41. package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +3 -6
  42. package/src/features/AgentSetting/AgentMeta/index.tsx +3 -3
  43. package/src/features/AgentSetting/AgentPrompt/TokenTag.tsx +4 -4
  44. package/src/features/AgentSetting/AgentTTS/index.tsx +3 -3
  45. package/src/features/AvatarWithUpload/index.tsx +3 -3
  46. package/src/features/ChatInput/ActionBar/FileUpload.tsx +3 -3
  47. package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +4 -4
  48. package/src/features/ChatInput/ActionBar/Token/index.tsx +3 -3
  49. package/src/features/ChatInput/ActionBar/Tools/index.tsx +3 -3
  50. package/src/features/ChatInput/STT/browser.tsx +4 -4
  51. package/src/features/ChatInput/STT/index.tsx +3 -3
  52. package/src/features/ChatInput/STT/openai.tsx +4 -4
  53. package/src/features/ChatInput/useChatInput.ts +3 -3
  54. package/src/features/Conversation/Error/APIKeyForm/Bedrock.tsx +3 -3
  55. package/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx +3 -3
  56. package/src/features/Conversation/Error/AccessCodeForm.tsx +3 -3
  57. package/src/features/Conversation/Extras/TTS/index.tsx +3 -3
  58. package/src/features/Conversation/Plugins/Render/MarkdownType/index.tsx +3 -3
  59. package/src/features/Conversation/components/ChatItem/index.tsx +3 -3
  60. package/src/features/ModelSwitchPanel/index.tsx +3 -6
  61. package/src/features/PluginDevModal/LocalForm.tsx +3 -3
  62. package/src/features/SyncStatusInspector/DisableSync.tsx +3 -3
  63. package/src/features/SyncStatusInspector/EnableSync.tsx +4 -4
  64. package/src/features/SyncStatusInspector/index.tsx +2 -2
  65. package/src/hooks/_header.ts +4 -4
  66. package/src/hooks/useSyncData.ts +3 -3
  67. package/src/hooks/useTTS.ts +4 -4
  68. package/src/layout/DefaultLayout/Desktop/SideBar/BottomActions.tsx +2 -2
  69. package/src/layout/DefaultLayout/Desktop/SideBar/TopActions.tsx +2 -2
  70. package/src/layout/DefaultLayout/Mobile/index.tsx +1 -1
  71. package/src/layout/GlobalProvider/AppTheme.tsx +4 -4
  72. package/src/layout/GlobalProvider/StoreInitialization.tsx +6 -1
  73. package/src/services/__tests__/chat.test.ts +17 -20
  74. package/src/services/__tests__/tool.test.ts +2 -2
  75. package/src/services/_auth.test.ts +2 -2
  76. package/src/services/_auth.ts +7 -7
  77. package/src/services/_header.ts +4 -4
  78. package/src/services/chat.ts +13 -13
  79. package/src/services/config.ts +4 -4
  80. package/src/services/models.ts +3 -3
  81. package/src/services/ollama.ts +3 -3
  82. package/src/services/session/client.ts +2 -2
  83. package/src/services/tool.ts +1 -1
  84. package/src/services/trace.ts +3 -3
  85. package/src/store/agent/slices/chat/selectors.test.ts +2 -2
  86. package/src/store/chat/slices/message/selectors.test.ts +1 -1
  87. package/src/store/chat/slices/message/selectors.ts +3 -3
  88. package/src/store/global/{slices/preference/action.test.ts → action.test.ts} +65 -13
  89. package/src/store/global/{slices/preference/action.ts → action.ts} +30 -16
  90. package/src/store/global/initialState.ts +58 -8
  91. package/src/store/global/selectors.ts +9 -8
  92. package/src/store/global/store.ts +3 -7
  93. package/src/store/market/action.ts +1 -1
  94. package/src/store/session/slices/session/action.ts +3 -3
  95. package/src/store/{global → user}/helpers.ts +2 -2
  96. package/src/store/user/index.ts +1 -0
  97. package/src/store/user/initialState.ts +11 -0
  98. package/src/store/user/selectors.ts +8 -0
  99. package/src/store/{global → user}/slices/common/action.test.ts +29 -81
  100. package/src/store/{global → user}/slices/common/action.ts +2 -20
  101. package/src/store/user/slices/common/initialState.ts +18 -0
  102. package/src/store/user/slices/common/selectors.ts +6 -0
  103. package/src/store/user/slices/preference/action.test.ts +41 -0
  104. package/src/store/user/slices/preference/action.ts +50 -0
  105. package/src/store/user/slices/preference/initialState.ts +33 -0
  106. package/src/store/user/slices/preference/selectors.ts +13 -0
  107. package/src/store/{global → user}/slices/settings/actions/general.test.ts +6 -6
  108. package/src/store/{global → user}/slices/settings/actions/general.ts +2 -2
  109. package/src/store/{global → user}/slices/settings/actions/index.ts +2 -2
  110. package/src/store/{global → user}/slices/settings/actions/llm.test.ts +11 -14
  111. package/src/store/{global → user}/slices/settings/actions/llm.ts +2 -2
  112. package/src/store/{global → user}/slices/settings/initialState.ts +2 -2
  113. package/src/store/{global → user}/slices/settings/selectors/modelConfig.test.ts +8 -8
  114. package/src/store/{global → user}/slices/settings/selectors/modelConfig.ts +12 -12
  115. package/src/store/{global → user}/slices/settings/selectors/modelProvider.test.ts +17 -17
  116. package/src/store/{global → user}/slices/settings/selectors/modelProvider.ts +19 -20
  117. package/src/store/{global → user}/slices/settings/selectors/selectors.test.ts +8 -8
  118. package/src/store/{global → user}/slices/settings/selectors/settings.ts +12 -12
  119. package/src/store/user/slices/settings/selectors/sync.ts +14 -0
  120. package/src/store/user/store.ts +33 -0
  121. package/src/tools/dalle/Render/ToolBar.tsx +3 -3
  122. package/src/utils/localStorage.ts +3 -1
  123. package/src/store/global/slices/common/initialState.ts +0 -42
  124. package/src/store/global/slices/common/selectors.ts +0 -6
  125. package/src/store/global/slices/preference/initialState.ts +0 -51
  126. package/src/store/global/slices/preference/selectors.ts +0 -18
  127. package/src/store/global/slices/settings/selectors/sync.ts +0 -14
  128. /package/src/store/{global → user}/slices/settings/reducers/customModelCard.test.ts +0 -0
  129. /package/src/store/{global → user}/slices/settings/reducers/customModelCard.ts +0 -0
  130. /package/src/store/{global → user}/slices/settings/selectors/__snapshots__/selectors.test.ts.snap +0 -0
  131. /package/src/store/{global → user}/slices/settings/selectors/index.ts +0 -0
@@ -11,8 +11,8 @@ import { Flexbox } from 'react-layout-kit';
11
11
  import { ModelItemRender, ProviderItemRender } from '@/components/ModelSelect';
12
12
  import { useAgentStore } from '@/store/agent';
13
13
  import { agentSelectors } from '@/store/agent/slices/chat';
14
- import { useGlobalStore } from '@/store/global';
15
- import { modelProviderSelectors } from '@/store/global/selectors';
14
+ import { useUserStore } from '@/store/user';
15
+ import { modelProviderSelectors } from '@/store/user/selectors';
16
16
  import { ModelProviderCard } from '@/types/llm';
17
17
  import { withBasePath } from '@/utils/basePath';
18
18
 
@@ -46,10 +46,7 @@ const ModelSwitchPanel = memo<PropsWithChildren>(({ children }) => {
46
46
  ]);
47
47
 
48
48
  const router = useRouter();
49
- const enabledList = useGlobalStore(
50
- modelProviderSelectors.modelProviderListForModelSelect,
51
- isEqual,
52
- );
49
+ const enabledList = useUserStore(modelProviderSelectors.modelProviderListForModelSelect, isEqual);
53
50
 
54
51
  const items = useMemo(() => {
55
52
  const getModelItems = (provider: ModelProviderCard) => {
@@ -4,16 +4,16 @@ import dynamic from 'next/dynamic';
4
4
  import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
 
7
- import { useGlobalStore } from '@/store/global';
8
- import { settingsSelectors } from '@/store/global/selectors';
9
7
  import { useToolStore } from '@/store/tool';
10
8
  import { pluginSelectors } from '@/store/tool/selectors';
9
+ import { useUserStore } from '@/store/user';
10
+ import { settingsSelectors } from '@/store/user/selectors';
11
11
 
12
12
  const EmojiPicker = dynamic(() => import('@lobehub/ui/es/EmojiPicker'), { ssr: false });
13
13
 
14
14
  const LocalForm = memo<{ form: FormInstance; mode?: 'edit' | 'create' }>(({ form, mode }) => {
15
15
  const isEditMode = mode === 'edit';
16
- const locale = useGlobalStore(settingsSelectors.currentLanguage);
16
+ const locale = useUserStore(settingsSelectors.currentLanguage);
17
17
  const { t } = useTranslation('plugin');
18
18
 
19
19
  const pluginIds = useToolStore(pluginSelectors.storeAndInstallPluginsIdList);
@@ -7,8 +7,8 @@ import { memo } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { Flexbox } from 'react-layout-kit';
9
9
 
10
- import { useGlobalStore } from '@/store/global';
11
- import { syncSettingsSelectors } from '@/store/global/selectors';
10
+ import { useUserStore } from '@/store/user';
11
+ import { syncSettingsSelectors } from '@/store/user/selectors';
12
12
 
13
13
  interface DisableSyncProps {
14
14
  noPopover?: boolean;
@@ -17,7 +17,7 @@ interface DisableSyncProps {
17
17
 
18
18
  const DisableSync = memo<DisableSyncProps>(({ noPopover, placement = 'bottomLeft' }) => {
19
19
  const { t } = useTranslation('common');
20
- const [haveConfig, setSettings] = useGlobalStore((s) => [
20
+ const [haveConfig, setSettings] = useUserStore((s) => [
21
21
  !!syncSettingsSelectors.webrtcConfig(s).channelName,
22
22
  s.setSettings,
23
23
  ]);
@@ -9,8 +9,8 @@ import { memo } from 'react';
9
9
  import { useTranslation } from 'react-i18next';
10
10
  import { Flexbox } from 'react-layout-kit';
11
11
 
12
- import { useGlobalStore } from '@/store/global';
13
- import { syncSettingsSelectors } from '@/store/global/selectors';
12
+ import { useUserStore } from '@/store/user';
13
+ import { syncSettingsSelectors } from '@/store/user/selectors';
14
14
  import { pathString } from '@/utils/url';
15
15
 
16
16
  import EnableTag from './EnableTag';
@@ -39,7 +39,7 @@ const EnableSync = memo<EnableSyncProps>(({ hiddenActions, placement = 'bottomLe
39
39
  const { t } = useTranslation('common');
40
40
 
41
41
  const { styles, theme } = useStyles();
42
- const [syncStatus, isSyncing, channelName, enableWebRTC, setSettings] = useGlobalStore((s) => [
42
+ const [syncStatus, isSyncing, channelName, enableWebRTC, setSettings] = useUserStore((s) => [
43
43
  s.syncStatus,
44
44
  s.syncStatus === 'syncing',
45
45
  syncSettingsSelectors.webrtcChannelName(s),
@@ -47,7 +47,7 @@ const EnableSync = memo<EnableSyncProps>(({ hiddenActions, placement = 'bottomLe
47
47
  s.setSettings,
48
48
  ]);
49
49
 
50
- const users = useGlobalStore((s) => s.syncAwareness, isEqual);
50
+ const users = useUserStore((s) => s.syncAwareness, isEqual);
51
51
 
52
52
  const switchSync = (enabled: boolean) => {
53
53
  setSettings({ sync: { webrtc: { enabled } } });
@@ -1,7 +1,7 @@
1
1
  import { TooltipPlacement } from 'antd/es/tooltip';
2
2
  import { memo } from 'react';
3
3
 
4
- import { useGlobalStore } from '@/store/global';
4
+ import { useUserStore } from '@/store/user';
5
5
 
6
6
  import DisableSync from './DisableSync';
7
7
  import EnableSync from './EnableSync';
@@ -14,7 +14,7 @@ interface SyncStatusTagProps {
14
14
 
15
15
  const SyncStatusTag = memo<SyncStatusTagProps>(
16
16
  ({ hiddenActions, placement, hiddenEnableGuide }) => {
17
- const [enableSync] = useGlobalStore((s) => [s.syncEnabled]);
17
+ const [enableSync] = useUserStore((s) => [s.syncEnabled]);
18
18
 
19
19
  return enableSync ? (
20
20
  <EnableSync hiddenActions={hiddenActions} placement={placement} />
@@ -1,11 +1,11 @@
1
1
  import { LOBE_CHAT_ACCESS_CODE, OPENAI_API_KEY_HEADER_KEY, OPENAI_END_POINT } from '@/const/fetch';
2
- import { useGlobalStore } from '@/store/global';
3
- import { modelConfigSelectors, settingsSelectors } from '@/store/global/selectors';
2
+ import { useUserStore } from '@/store/user';
3
+ import { modelConfigSelectors, settingsSelectors } from '@/store/user/selectors';
4
4
 
5
5
  // TODO: Need to be removed after tts refactor
6
6
  // eslint-disable-next-line no-undef
7
7
  export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
8
- const openai = modelConfigSelectors.openAIConfig(useGlobalStore.getState());
8
+ const openai = modelConfigSelectors.openAIConfig(useUserStore.getState());
9
9
 
10
10
  const apiKey = openai.apiKey || '';
11
11
  const endpoint = openai.endpoint || '';
@@ -13,7 +13,7 @@ export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
13
13
  // eslint-disable-next-line no-undef
14
14
  return {
15
15
  ...header,
16
- [LOBE_CHAT_ACCESS_CODE]: settingsSelectors.password(useGlobalStore.getState()),
16
+ [LOBE_CHAT_ACCESS_CODE]: settingsSelectors.password(useUserStore.getState()),
17
17
  [OPENAI_API_KEY_HEADER_KEY]: apiKey,
18
18
  [OPENAI_END_POINT]: endpoint,
19
19
  };
@@ -1,9 +1,9 @@
1
1
  import { useCallback } from 'react';
2
2
 
3
3
  import { useChatStore } from '@/store/chat';
4
- import { useGlobalStore } from '@/store/global';
5
- import { syncSettingsSelectors } from '@/store/global/selectors';
6
4
  import { useSessionStore } from '@/store/session';
5
+ import { useUserStore } from '@/store/user';
6
+ import { syncSettingsSelectors } from '@/store/user/selectors';
7
7
 
8
8
  export const useSyncEvent = () => {
9
9
  const [refreshMessages, refreshTopic] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]);
@@ -36,7 +36,7 @@ export const useSyncEvent = () => {
36
36
  };
37
37
 
38
38
  export const useEnabledDataSync = () => {
39
- const [userId, userEnableSync, useEnabledSync] = useGlobalStore((s) => [
39
+ const [userId, userEnableSync, useEnabledSync] = useUserStore((s) => [
40
40
  s.userId,
41
41
  syncSettingsSelectors.enableWebRTC(s),
42
42
  s.useEnabledSync,
@@ -13,8 +13,8 @@ import { createHeaderWithOpenAI } from '@/services/_header';
13
13
  import { API_ENDPOINTS } from '@/services/_url';
14
14
  import { useAgentStore } from '@/store/agent';
15
15
  import { agentSelectors } from '@/store/agent/slices/chat';
16
- import { useGlobalStore } from '@/store/global';
17
- import { settingsSelectors } from '@/store/global/selectors';
16
+ import { useUserStore } from '@/store/user';
17
+ import { settingsSelectors } from '@/store/user/selectors';
18
18
  import { TTSServer } from '@/types/agent';
19
19
 
20
20
  interface TTSConfig extends TTSOptions {
@@ -24,9 +24,9 @@ interface TTSConfig extends TTSOptions {
24
24
  }
25
25
 
26
26
  export const useTTS = (content: string, config?: TTSConfig) => {
27
- const ttsSettings = useGlobalStore(settingsSelectors.currentTTS, isEqual);
27
+ const ttsSettings = useUserStore(settingsSelectors.currentTTS, isEqual);
28
28
  const ttsAgentSettings = useAgentStore(agentSelectors.currentAgentTTS, isEqual);
29
- const lang = useGlobalStore(settingsSelectors.currentLanguage);
29
+ const lang = useUserStore(settingsSelectors.currentLanguage);
30
30
  const voice = useAgentStore(agentSelectors.currentAgentTTSVoice(lang));
31
31
  let useSelectedTTS;
32
32
  let options: any = {};
@@ -20,11 +20,11 @@ import { Flexbox } from 'react-layout-kit';
20
20
  import { ABOUT, CHANGELOG, DISCORD, DOCUMENTS, FEEDBACK, GITHUB } from '@/const/url';
21
21
  import DataImporter from '@/features/DataImporter';
22
22
  import { configService } from '@/services/config';
23
- import { GlobalStore, useGlobalStore } from '@/store/global';
23
+ import { useGlobalStore } from '@/store/global';
24
24
  import { SidebarTabKey } from '@/store/global/initialState';
25
25
 
26
26
  export interface BottomActionProps {
27
- tab?: GlobalStore['sidebarKey'];
27
+ tab?: SidebarTabKey;
28
28
  }
29
29
 
30
30
  const BottomActions = memo<BottomActionProps>(({ tab }) => {
@@ -4,12 +4,12 @@ import Link from 'next/link';
4
4
  import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
 
7
- import { GlobalStore, useGlobalStore } from '@/store/global';
7
+ import { useGlobalStore } from '@/store/global';
8
8
  import { SidebarTabKey } from '@/store/global/initialState';
9
9
  import { useSessionStore } from '@/store/session';
10
10
 
11
11
  export interface TopActionProps {
12
- tab?: GlobalStore['sidebarKey'];
12
+ tab?: SidebarTabKey;
13
13
  }
14
14
 
15
15
  const TopActions = memo<TopActionProps>(({ tab }) => {
@@ -7,7 +7,7 @@ import { CSSProperties, PropsWithChildren, memo } from 'react';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import SafeSpacing from '@/components/SafeSpacing';
10
- import { SidebarTabKey } from '@/store/global/slices/common/initialState';
10
+ import { SidebarTabKey } from '@/store/global/initialState';
11
11
 
12
12
  const MobileTabBar = dynamic(() => import('@/features/MobileTabBar'));
13
13
 
@@ -13,8 +13,8 @@ import {
13
13
  LOBE_THEME_NEUTRAL_COLOR,
14
14
  LOBE_THEME_PRIMARY_COLOR,
15
15
  } from '@/const/theme';
16
- import { useGlobalStore } from '@/store/global';
17
- import { settingsSelectors } from '@/store/global/selectors';
16
+ import { useUserStore } from '@/store/user';
17
+ import { settingsSelectors } from '@/store/user/selectors';
18
18
  import { GlobalStyle } from '@/styles';
19
19
  import { setCookie } from '@/utils/cookie';
20
20
 
@@ -83,9 +83,9 @@ const AppTheme = memo<AppThemeProps>(
83
83
  // console.debug('server:appearance', defaultAppearance);
84
84
  // console.debug('server:primaryColor', defaultPrimaryColor);
85
85
  // console.debug('server:neutralColor', defaultNeutralColor);
86
- const themeMode = useGlobalStore((s) => settingsSelectors.currentSettings(s).themeMode);
86
+ const themeMode = useUserStore((s) => settingsSelectors.currentSettings(s).themeMode);
87
87
 
88
- const [primaryColor, neutralColor] = useGlobalStore((s) => [
88
+ const [primaryColor, neutralColor] = useUserStore((s) => [
89
89
  settingsSelectors.currentSettings(s).primaryColor,
90
90
  settingsSelectors.currentSettings(s).neutralColor,
91
91
  ]);
@@ -8,16 +8,21 @@ import { useIsMobile } from '@/hooks/useIsMobile';
8
8
  import { useEnabledDataSync } from '@/hooks/useSyncData';
9
9
  import { useAgentStore } from '@/store/agent';
10
10
  import { useGlobalStore } from '@/store/global';
11
+ import { useUserStore } from '@/store/user';
11
12
 
12
13
  const StoreInitialization = memo(() => {
13
- const [useFetchServerConfig, useFetchUserConfig, useInitPreference] = useGlobalStore((s) => [
14
+ const [useFetchServerConfig, useFetchUserConfig, useInitPreference] = useUserStore((s) => [
14
15
  s.useFetchServerConfig,
15
16
  s.useFetchUserConfig,
16
17
  s.useInitPreference,
17
18
  ]);
19
+ const useInitGlobalPreference = useGlobalStore((s) => s.useInitGlobalPreference);
20
+
18
21
  const useFetchDefaultAgentConfig = useAgentStore((s) => s.useFetchDefaultAgentConfig);
19
22
  // init the system preference
20
23
  useInitPreference();
24
+ useInitGlobalPreference();
25
+
21
26
  useFetchDefaultAgentConfig();
22
27
 
23
28
  const { isLoading } = useFetchServerConfig();
@@ -23,12 +23,9 @@ import {
23
23
  } from '@/libs/agent-runtime';
24
24
  import { AgentRuntime } from '@/libs/agent-runtime';
25
25
  import { useFileStore } from '@/store/file';
26
- import { GlobalStore } from '@/store/global';
27
- import {
28
- GlobalSettingsState,
29
- initialSettingsState,
30
- } from '@/store/global/slices/settings/initialState';
31
26
  import { useToolStore } from '@/store/tool';
27
+ import { UserStore } from '@/store/user';
28
+ import { UserSettingsState, initialSettingsState } from '@/store/user/slices/settings/initialState';
32
29
  import { DalleManifest } from '@/tools/dalle';
33
30
  import { ChatMessage } from '@/types/message';
34
31
  import { ChatStreamPayload } from '@/types/openai/chat';
@@ -695,7 +692,7 @@ describe('AgentRuntimeOnClient', () => {
695
692
  },
696
693
  },
697
694
  },
698
- } as GlobalSettingsState) as unknown as GlobalStore;
695
+ } as UserSettingsState) as unknown as UserStore;
699
696
  const runtime = await initializeWithClientStore(ModelProvider.OpenAI, {});
700
697
  expect(runtime).toBeInstanceOf(AgentRuntime);
701
698
  expect(runtime['_runtime']).toBeInstanceOf(LobeOpenAI);
@@ -713,7 +710,7 @@ describe('AgentRuntimeOnClient', () => {
713
710
  },
714
711
  },
715
712
  },
716
- } as GlobalSettingsState) as unknown as GlobalStore;
713
+ } as UserSettingsState) as unknown as UserStore;
717
714
  const runtime = await initializeWithClientStore(ModelProvider.Azure, {});
718
715
  expect(runtime).toBeInstanceOf(AgentRuntime);
719
716
  expect(runtime['_runtime']).toBeInstanceOf(LobeAzureOpenAI);
@@ -728,7 +725,7 @@ describe('AgentRuntimeOnClient', () => {
728
725
  },
729
726
  },
730
727
  },
731
- } as GlobalSettingsState) as unknown as GlobalStore;
728
+ } as UserSettingsState) as unknown as UserStore;
732
729
  const runtime = await initializeWithClientStore(ModelProvider.Google, {});
733
730
  expect(runtime).toBeInstanceOf(AgentRuntime);
734
731
  expect(runtime['_runtime']).toBeInstanceOf(LobeGoogleAI);
@@ -743,7 +740,7 @@ describe('AgentRuntimeOnClient', () => {
743
740
  },
744
741
  },
745
742
  },
746
- } as GlobalSettingsState) as unknown as GlobalStore;
743
+ } as UserSettingsState) as unknown as UserStore;
747
744
  const runtime = await initializeWithClientStore(ModelProvider.Moonshot, {});
748
745
  expect(runtime).toBeInstanceOf(AgentRuntime);
749
746
  expect(runtime['_runtime']).toBeInstanceOf(LobeMoonshotAI);
@@ -760,7 +757,7 @@ describe('AgentRuntimeOnClient', () => {
760
757
  },
761
758
  },
762
759
  },
763
- } as GlobalSettingsState) as unknown as GlobalStore;
760
+ } as UserSettingsState) as unknown as UserStore;
764
761
  const runtime = await initializeWithClientStore(ModelProvider.Bedrock, {});
765
762
  expect(runtime).toBeInstanceOf(AgentRuntime);
766
763
  expect(runtime['_runtime']).toBeInstanceOf(LobeBedrockAI);
@@ -775,7 +772,7 @@ describe('AgentRuntimeOnClient', () => {
775
772
  },
776
773
  },
777
774
  },
778
- } as GlobalSettingsState) as unknown as GlobalStore;
775
+ } as UserSettingsState) as unknown as UserStore;
779
776
  const runtime = await initializeWithClientStore(ModelProvider.Ollama, {});
780
777
  expect(runtime).toBeInstanceOf(AgentRuntime);
781
778
  expect(runtime['_runtime']).toBeInstanceOf(LobeOllamaAI);
@@ -790,7 +787,7 @@ describe('AgentRuntimeOnClient', () => {
790
787
  },
791
788
  },
792
789
  },
793
- } as GlobalSettingsState) as unknown as GlobalStore;
790
+ } as UserSettingsState) as unknown as UserStore;
794
791
  const runtime = await initializeWithClientStore(ModelProvider.Perplexity, {});
795
792
  expect(runtime).toBeInstanceOf(AgentRuntime);
796
793
  expect(runtime['_runtime']).toBeInstanceOf(LobePerplexityAI);
@@ -805,7 +802,7 @@ describe('AgentRuntimeOnClient', () => {
805
802
  },
806
803
  },
807
804
  },
808
- } as GlobalSettingsState) as unknown as GlobalStore;
805
+ } as UserSettingsState) as unknown as UserStore;
809
806
  const runtime = await initializeWithClientStore(ModelProvider.Anthropic, {});
810
807
  expect(runtime).toBeInstanceOf(AgentRuntime);
811
808
  expect(runtime['_runtime']).toBeInstanceOf(LobeAnthropicAI);
@@ -820,7 +817,7 @@ describe('AgentRuntimeOnClient', () => {
820
817
  },
821
818
  },
822
819
  },
823
- } as GlobalSettingsState) as unknown as GlobalStore;
820
+ } as UserSettingsState) as unknown as UserStore;
824
821
  const runtime = await initializeWithClientStore(ModelProvider.Mistral, {});
825
822
  expect(runtime).toBeInstanceOf(AgentRuntime);
826
823
  expect(runtime['_runtime']).toBeInstanceOf(LobeMistralAI);
@@ -835,7 +832,7 @@ describe('AgentRuntimeOnClient', () => {
835
832
  },
836
833
  },
837
834
  },
838
- } as GlobalSettingsState) as unknown as GlobalStore;
835
+ } as UserSettingsState) as unknown as UserStore;
839
836
  const runtime = await initializeWithClientStore(ModelProvider.OpenRouter, {});
840
837
  expect(runtime).toBeInstanceOf(AgentRuntime);
841
838
  expect(runtime['_runtime']).toBeInstanceOf(LobeOpenRouterAI);
@@ -850,7 +847,7 @@ describe('AgentRuntimeOnClient', () => {
850
847
  },
851
848
  },
852
849
  },
853
- } as GlobalSettingsState) as unknown as GlobalStore;
850
+ } as UserSettingsState) as unknown as UserStore;
854
851
  const runtime = await initializeWithClientStore(ModelProvider.TogetherAI, {});
855
852
  expect(runtime).toBeInstanceOf(AgentRuntime);
856
853
  expect(runtime['_runtime']).toBeInstanceOf(LobeTogetherAI);
@@ -865,7 +862,7 @@ describe('AgentRuntimeOnClient', () => {
865
862
  },
866
863
  },
867
864
  },
868
- } as GlobalSettingsState) as unknown as GlobalStore;
865
+ } as UserSettingsState) as unknown as UserStore;
869
866
  const runtime = await initializeWithClientStore(ModelProvider.ZeroOne, {});
870
867
  expect(runtime).toBeInstanceOf(AgentRuntime);
871
868
  expect(runtime['_runtime']).toBeInstanceOf(LobeZeroOneAI);
@@ -880,7 +877,7 @@ describe('AgentRuntimeOnClient', () => {
880
877
  },
881
878
  },
882
879
  },
883
- } as GlobalSettingsState) as unknown as GlobalStore;
880
+ } as UserSettingsState) as unknown as UserStore;
884
881
  const runtime = await initializeWithClientStore(ModelProvider.Groq, {});
885
882
  expect(runtime).toBeInstanceOf(AgentRuntime);
886
883
  expect(runtime['_runtime']).toBeInstanceOf(LobeGroq);
@@ -900,7 +897,7 @@ describe('AgentRuntimeOnClient', () => {
900
897
  },
901
898
  },
902
899
  },
903
- } as any as GlobalSettingsState) as unknown as GlobalStore;
900
+ } as any as UserSettingsState) as unknown as UserStore;
904
901
  const runtime = await initializeWithClientStore('unknown' as ModelProvider, {});
905
902
  expect(runtime).toBeInstanceOf(AgentRuntime);
906
903
  expect(runtime['_runtime']).toBeInstanceOf(LobeOpenAI);
@@ -927,7 +924,7 @@ describe('AgentRuntimeOnClient', () => {
927
924
  },
928
925
  },
929
926
  },
930
- } as GlobalSettingsState) as unknown as GlobalStore;
927
+ } as UserSettingsState) as unknown as UserStore;
931
928
  const runtime = await initializeWithClientStore(ModelProvider.ZhiPu, {});
932
929
  expect(runtime).toBeInstanceOf(AgentRuntime);
933
930
  expect(runtime['_runtime']).toBeInstanceOf(LobeZhipuAI);
@@ -1,6 +1,6 @@
1
1
  import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { globalHelpers } from '@/store/global/helpers';
3
+ import { globalHelpers } from '@/store/user/helpers';
4
4
 
5
5
  import { toolService } from '../tool';
6
6
  import openAPIV3 from './openai/OpenAPI_V3.json';
@@ -8,7 +8,7 @@ import OpenAIPlugin from './openai/plugin.json';
8
8
 
9
9
  // Mocking modules and functions
10
10
 
11
- vi.mock('@/store/global/helpers', () => ({
11
+ vi.mock('@/store/user/helpers', () => ({
12
12
  globalHelpers: {
13
13
  getCurrentLanguage: vi.fn(),
14
14
  },
@@ -2,7 +2,7 @@ import { act } from '@testing-library/react';
2
2
  import { describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import { ModelProvider } from '@/libs/agent-runtime';
5
- import { useGlobalStore } from '@/store/global';
5
+ import { useUserStore } from '@/store/user';
6
6
  import { GlobalLLMConfig, GlobalLLMProviderKey } from '@/types/settings';
7
7
 
8
8
  import { getProviderAuthPayload } from './_auth';
@@ -23,7 +23,7 @@ const setModelProviderConfig = <T extends GlobalLLMProviderKey>(
23
23
  provider: T,
24
24
  config: Partial<GlobalLLMConfig[T]>,
25
25
  ) => {
26
- useGlobalStore.setState({
26
+ useUserStore.setState({
27
27
  settings: { languageModel: { [provider]: config } },
28
28
  });
29
29
  };
@@ -1,14 +1,14 @@
1
1
  import { JWTPayload, LOBE_CHAT_AUTH_HEADER } from '@/const/auth';
2
2
  import { ModelProvider } from '@/libs/agent-runtime';
3
- import { useGlobalStore } from '@/store/global';
4
- import { modelConfigSelectors, settingsSelectors } from '@/store/global/selectors';
3
+ import { useUserStore } from '@/store/user';
4
+ import { modelConfigSelectors, settingsSelectors } from '@/store/user/selectors';
5
5
  import { createJWT } from '@/utils/jwt';
6
6
 
7
7
  export const getProviderAuthPayload = (provider: string) => {
8
8
  switch (provider) {
9
9
  case ModelProvider.Bedrock: {
10
10
  const { accessKeyId, region, secretAccessKey } = modelConfigSelectors.bedrockConfig(
11
- useGlobalStore.getState(),
11
+ useUserStore.getState(),
12
12
  );
13
13
  const awsSecretAccessKey = secretAccessKey;
14
14
  const awsAccessKeyId = accessKeyId;
@@ -19,7 +19,7 @@ export const getProviderAuthPayload = (provider: string) => {
19
19
  }
20
20
 
21
21
  case ModelProvider.Azure: {
22
- const azure = modelConfigSelectors.azureConfig(useGlobalStore.getState());
22
+ const azure = modelConfigSelectors.azureConfig(useUserStore.getState());
23
23
 
24
24
  return {
25
25
  apiKey: azure.apiKey,
@@ -29,13 +29,13 @@ export const getProviderAuthPayload = (provider: string) => {
29
29
  }
30
30
 
31
31
  case ModelProvider.Ollama: {
32
- const config = modelConfigSelectors.ollamaConfig(useGlobalStore.getState());
32
+ const config = modelConfigSelectors.ollamaConfig(useUserStore.getState());
33
33
 
34
34
  return { endpoint: config?.endpoint };
35
35
  }
36
36
 
37
37
  default: {
38
- const config = settingsSelectors.providerConfig(provider)(useGlobalStore.getState());
38
+ const config = settingsSelectors.providerConfig(provider)(useUserStore.getState());
39
39
 
40
40
  return { apiKey: config?.apiKey, endpoint: config?.endpoint };
41
41
  }
@@ -43,7 +43,7 @@ export const getProviderAuthPayload = (provider: string) => {
43
43
  };
44
44
 
45
45
  const createAuthTokenWithPayload = async (payload = {}) => {
46
- const accessCode = settingsSelectors.password(useGlobalStore.getState());
46
+ const accessCode = settingsSelectors.password(useUserStore.getState());
47
47
 
48
48
  return await createJWT<JWTPayload>({ accessCode, ...payload });
49
49
  };
@@ -1,6 +1,6 @@
1
1
  import { LOBE_CHAT_ACCESS_CODE, OPENAI_API_KEY_HEADER_KEY, OPENAI_END_POINT } from '@/const/fetch';
2
- import { useGlobalStore } from '@/store/global';
3
- import { modelConfigSelectors, settingsSelectors } from '@/store/global/selectors';
2
+ import { useUserStore } from '@/store/user';
3
+ import { modelConfigSelectors, settingsSelectors } from '@/store/user/selectors';
4
4
 
5
5
  /**
6
6
  * TODO: Need to be removed after tts refactor
@@ -8,12 +8,12 @@ import { modelConfigSelectors, settingsSelectors } from '@/store/global/selector
8
8
  */
9
9
  // eslint-disable-next-line no-undef
10
10
  export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
11
- const openAIConfig = modelConfigSelectors.openAIConfig(useGlobalStore.getState());
11
+ const openAIConfig = modelConfigSelectors.openAIConfig(useUserStore.getState());
12
12
 
13
13
  // eslint-disable-next-line no-undef
14
14
  return {
15
15
  ...header,
16
- [LOBE_CHAT_ACCESS_CODE]: settingsSelectors.password(useGlobalStore.getState()),
16
+ [LOBE_CHAT_ACCESS_CODE]: settingsSelectors.password(useUserStore.getState()),
17
17
  [OPENAI_API_KEY_HEADER_KEY]: openAIConfig.apiKey || '',
18
18
  [OPENAI_END_POINT]: openAIConfig.endpoint || '',
19
19
  };
@@ -7,17 +7,17 @@ import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
7
7
  import { TracePayload, TraceTagMap } from '@/const/trace';
8
8
  import { AgentRuntime, ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
9
9
  import { filesSelectors, useFileStore } from '@/store/file';
10
- import { useGlobalStore } from '@/store/global';
10
+ import { useSessionStore } from '@/store/session';
11
+ import { sessionMetaSelectors } from '@/store/session/selectors';
12
+ import { useToolStore } from '@/store/tool';
13
+ import { pluginSelectors, toolSelectors } from '@/store/tool/selectors';
14
+ import { useUserStore } from '@/store/user';
11
15
  import {
12
16
  commonSelectors,
13
17
  modelConfigSelectors,
14
18
  modelProviderSelectors,
15
19
  preferenceSelectors,
16
- } from '@/store/global/selectors';
17
- import { useSessionStore } from '@/store/session';
18
- import { sessionMetaSelectors } from '@/store/session/selectors';
19
- import { useToolStore } from '@/store/tool';
20
- import { pluginSelectors, toolSelectors } from '@/store/tool/selectors';
20
+ } from '@/store/user/selectors';
21
21
  import { ChatErrorType } from '@/types/fetch';
22
22
  import { ChatMessage } from '@/types/message';
23
23
  import type { ChatStreamPayload, OpenAIChatMessage } from '@/types/openai/chat';
@@ -195,7 +195,7 @@ class ChatService {
195
195
 
196
196
  // check this model can use function call
197
197
  const canUseFC = modelProviderSelectors.isModelEnabledFunctionCall(payload.model)(
198
- useGlobalStore.getState(),
198
+ useUserStore.getState(),
199
199
  );
200
200
  // the rule that model can use tools:
201
201
  // 1. tools is not empty
@@ -241,7 +241,7 @@ class ChatService {
241
241
  // if the provider is Azure, get the deployment name as the request model
242
242
  if (provider === ModelProvider.Azure) {
243
243
  const chatModelCards = modelProviderSelectors.getModelCardsById(provider)(
244
- useGlobalStore.getState(),
244
+ useUserStore.getState(),
245
245
  );
246
246
 
247
247
  const deploymentName = chatModelCards.find((i) => i.id === model)?.deploymentName;
@@ -257,7 +257,7 @@ class ChatService {
257
257
  * Use browser agent runtime
258
258
  */
259
259
  const enableFetchOnClient = modelConfigSelectors.isProviderFetchOnClient(provider)(
260
- useGlobalStore.getState(),
260
+ useUserStore.getState(),
261
261
  );
262
262
  /**
263
263
  * Notes:
@@ -391,7 +391,7 @@ class ChatService {
391
391
  if (imageList.length === 0) return m.content;
392
392
 
393
393
  const canUploadFile = modelProviderSelectors.isModelEnabledUpload(model)(
394
- useGlobalStore.getState(),
394
+ useUserStore.getState(),
395
395
  );
396
396
 
397
397
  if (!canUploadFile) {
@@ -426,7 +426,7 @@ class ChatService {
426
426
  return produce(postMessages, (draft) => {
427
427
  if (!tools || tools.length === 0) return;
428
428
  const hasFC = modelProviderSelectors.isModelEnabledFunctionCall(model)(
429
- useGlobalStore.getState(),
429
+ useUserStore.getState(),
430
430
  );
431
431
  if (!hasFC) return;
432
432
 
@@ -449,7 +449,7 @@ class ChatService {
449
449
  private mapTrace(trace?: TracePayload, tag?: TraceTagMap): TracePayload {
450
450
  const tags = sessionMetaSelectors.currentAgentMeta(useSessionStore.getState()).tags || [];
451
451
 
452
- const enabled = preferenceSelectors.userAllowTrace(useGlobalStore.getState());
452
+ const enabled = preferenceSelectors.userAllowTrace(useUserStore.getState());
453
453
 
454
454
  if (!enabled) return { enabled: false };
455
455
 
@@ -457,7 +457,7 @@ class ChatService {
457
457
  ...trace,
458
458
  enabled: true,
459
459
  tags: [tag, ...(trace?.tags || []), ...tags].filter(Boolean) as string[],
460
- userId: commonSelectors.userId(useGlobalStore.getState()),
460
+ userId: commonSelectors.userId(useUserStore.getState()),
461
461
  };
462
462
  }
463
463
 
@@ -1,10 +1,10 @@
1
1
  import { messageService } from '@/services/message';
2
2
  import { sessionService } from '@/services/session';
3
3
  import { topicService } from '@/services/topic';
4
- import { useGlobalStore } from '@/store/global';
5
- import { settingsSelectors } from '@/store/global/selectors';
6
4
  import { useSessionStore } from '@/store/session';
7
5
  import { sessionSelectors } from '@/store/session/selectors';
6
+ import { useUserStore } from '@/store/user';
7
+ import { settingsSelectors } from '@/store/user/selectors';
8
8
  import { ConfigFile } from '@/types/exportConfig';
9
9
  import { ChatMessage } from '@/types/message';
10
10
  import { LobeSessions, SessionGroupItem } from '@/types/session';
@@ -36,7 +36,7 @@ class ConfigService {
36
36
  return messageService.batchCreateMessages(messages);
37
37
  };
38
38
  importSettings = async (settings: GlobalSettings) => {
39
- useGlobalStore.getState().importAppSettings(settings);
39
+ useUserStore.getState().importAppSettings(settings);
40
40
  };
41
41
  importTopics = async (topics: ChatTopic[]) => {
42
42
  return topicService.batchCreateTopics(topics);
@@ -183,7 +183,7 @@ class ConfigService {
183
183
  exportConfigFile(config, 'config');
184
184
  };
185
185
 
186
- private getSettings = () => settingsSelectors.exportSettings(useGlobalStore.getState());
186
+ private getSettings = () => settingsSelectors.exportSettings(useUserStore.getState());
187
187
 
188
188
  private getSession = (id: string) =>
189
189
  sessionSelectors.getSessionById(id)(useSessionStore.getState());