@lobehub/chat 0.115.2 → 0.115.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.
- package/CHANGELOG.md +50 -0
- package/package.json +1 -1
- package/src/app/chat/features/SessionListContent/DefaultMode.tsx +2 -1
- package/src/app/chat/features/SessionListContent/List/Item/index.tsx +2 -1
- package/src/app/settings/agent/Agent.tsx +2 -1
- package/src/app/settings/common/Common.tsx +2 -1
- package/src/app/settings/llm/LLM/Checker.tsx +1 -1
- package/src/app/settings/llm/LLM/index.tsx +2 -1
- package/src/app/settings/tts/TTS/index.tsx +2 -1
- package/src/database/models/__tests__/message.test.ts +1 -1
- package/src/database/models/message.ts +1 -1
- package/src/features/AgentSetting/AgentConfig/index.tsx +2 -1
- package/src/features/AgentSetting/AgentMeta/index.tsx +2 -1
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/AgentTTS/index.tsx +3 -2
- package/src/features/ChatInput/ActionBar/ModelSwitch.tsx +2 -1
- package/src/features/ChatInput/STT/index.tsx +1 -1
- package/src/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -1
- package/src/features/Conversation/ChatList/Extras/Assistant.test.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/Assistant.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/TTS/InitPlayer.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/TTS/Player.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/TTS/index.tsx +3 -2
- package/src/features/Conversation/ChatList/Extras/Translate.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/User.tsx +1 -1
- package/src/features/Conversation/ChatList/Extras/type.ts +1 -1
- package/src/features/Conversation/ChatList/Messages/Assistant.tsx +1 -1
- package/src/features/Conversation/ChatList/Messages/Default.tsx +1 -1
- package/src/features/Conversation/ChatList/Messages/Function.tsx +1 -1
- package/src/features/Conversation/ChatList/Messages/User.tsx +1 -1
- package/src/features/Conversation/index.tsx +2 -1
- package/src/features/PluginDevModal/LocalForm.tsx +3 -2
- package/src/hooks/useSTT.ts +2 -1
- package/src/hooks/useTTS.ts +2 -1
- package/src/services/__tests__/chat.test.ts +1 -1
- package/src/services/__tests__/message.test.ts +1 -1
- package/src/services/_header.ts +2 -2
- package/src/services/chat.ts +1 -1
- package/src/services/config.ts +3 -2
- package/src/services/message.ts +2 -2
- package/src/store/chat/helpers.test.ts +1 -1
- package/src/store/chat/helpers.ts +1 -1
- package/src/store/chat/initialState.ts +9 -47
- package/src/store/chat/selectors.ts +3 -0
- package/src/store/chat/{actions/enhance.test.ts → slices/enchance/action.test.ts} +2 -2
- package/src/store/chat/{actions/message.test.ts → slices/message/action.test.ts} +2 -2
- package/src/store/chat/{actions/message.ts → slices/message/action.ts} +3 -3
- package/src/store/chat/slices/message/initialState.ts +29 -0
- package/src/store/chat/{reducers/message.test.ts → slices/message/reducer.test.ts} +2 -2
- package/src/store/chat/{reducers/message.ts → slices/message/reducer.ts} +1 -1
- package/src/store/chat/{selectors/__tests__/chat.test.ts → slices/message/selectors.test.ts} +2 -2
- package/src/store/chat/{selectors/chat.ts → slices/message/selectors.ts} +3 -3
- package/src/store/chat/{actions/share.ts → slices/share/action.ts} +2 -2
- package/src/store/chat/slices/share/initialState.ts +7 -0
- package/src/store/chat/{actions/plugin.ts → slices/tool/action.ts} +2 -4
- package/src/store/chat/slices/tool/initialState.ts +7 -0
- package/src/store/chat/{actions/topic.test.ts → slices/topic/action.test.ts} +2 -2
- package/src/store/chat/{actions/topic.ts → slices/topic/action.ts} +3 -2
- package/src/store/chat/slices/topic/initialState.ts +23 -0
- package/src/store/chat/{selectors/__tests__/topic.test.ts → slices/topic/selectors.test.ts} +1 -1
- package/src/store/chat/{selectors/topic.ts → slices/topic/selectors.ts} +1 -1
- package/src/store/chat/store.ts +5 -5
- package/src/store/global/helpers.ts +1 -1
- package/src/store/global/index.ts +0 -1
- package/src/store/global/initialState.ts +6 -61
- package/src/store/global/selectors.ts +2 -2
- package/src/store/global/slices/{common.ts → common/action.ts} +3 -3
- package/src/store/global/slices/common/initialState.ts +55 -0
- package/src/store/global/{selectors/preference.ts → slices/common/selectors.ts} +1 -1
- package/src/store/global/slices/{settings.ts → settings/action.ts} +12 -4
- package/src/store/global/slices/settings/initialState.ts +15 -0
- package/src/store/global/{selectors/settings.test.ts → slices/settings/selectors.test.ts} +2 -2
- package/src/store/global/{selectors/settings.ts → slices/settings/selectors.ts} +3 -4
- package/src/store/global/store.ts +4 -18
- package/src/store/session/slices/agent/selectors.ts +2 -1
- package/src/store/session/slices/session/action.ts +2 -1
- package/src/tools/dalle/Render/ToolBar.tsx +2 -1
- package/src/types/exportConfig.ts +1 -1
- package/src/types/{chatMessage.ts → message/index.ts} +2 -2
- package/src/types/settings.ts +0 -29
- package/src/utils/fetch.ts +1 -1
- package/src/store/chat/selectors/index.ts +0 -3
- package/src/store/global/slices/agent.ts +0 -34
- /package/src/store/chat/{actions/enhance.ts → slices/enchance/action.ts} +0 -0
- /package/src/store/chat/{selectors/enchance.ts → slices/enchance/selectors.ts} +0 -0
- /package/src/store/chat/{actions/plugin.test.ts → slices/tool/action.test.ts} +0 -0
- /package/src/store/global/{selectors/__snapshots__/settings.test.ts.snap → slices/settings/__snapshots__/selectors.test.ts.snap} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChatMessage } from '@/types/message';
|
|
2
|
+
|
|
3
|
+
export interface ChatMessageState {
|
|
4
|
+
abortController?: AbortController;
|
|
5
|
+
/**
|
|
6
|
+
* @title 当前活动的会话
|
|
7
|
+
* @description 当前正在编辑或查看的会话
|
|
8
|
+
*/
|
|
9
|
+
activeId: string;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
chatLoadingId?: string;
|
|
14
|
+
inputMessage: string;
|
|
15
|
+
messageLoadingIds: [];
|
|
16
|
+
messages: ChatMessage[];
|
|
17
|
+
/**
|
|
18
|
+
* whether messages have fetched
|
|
19
|
+
*/
|
|
20
|
+
messagesInit: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const initialMessageState: ChatMessageState = {
|
|
24
|
+
activeId: 'inbox',
|
|
25
|
+
inputMessage: '',
|
|
26
|
+
messageLoadingIds: [],
|
|
27
|
+
messages: [],
|
|
28
|
+
messagesInit: false,
|
|
29
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChatMessage
|
|
1
|
+
import { ChatMessage } from '@/types/message';
|
|
2
2
|
|
|
3
|
-
import { MessageDispatch, messagesReducer } from './
|
|
3
|
+
import { MessageDispatch, messagesReducer } from './reducer';
|
|
4
4
|
|
|
5
5
|
describe('messagesReducer', () => {
|
|
6
6
|
let initialState: ChatMessage[];
|
package/src/store/chat/{selectors/__tests__/chat.test.ts → slices/message/selectors.test.ts}
RENAMED
|
@@ -5,11 +5,11 @@ import { INBOX_SESSION_ID } from '@/const/session';
|
|
|
5
5
|
import { ChatStore } from '@/store/chat';
|
|
6
6
|
import { initialState } from '@/store/chat/initialState';
|
|
7
7
|
import { useSessionStore } from '@/store/session';
|
|
8
|
-
import { ChatMessage } from '@/types/
|
|
8
|
+
import { ChatMessage } from '@/types/message';
|
|
9
9
|
import { MetaData } from '@/types/meta';
|
|
10
10
|
import { merge } from '@/utils/merge';
|
|
11
11
|
|
|
12
|
-
import { chatSelectors } from '
|
|
12
|
+
import { chatSelectors } from './selectors';
|
|
13
13
|
|
|
14
14
|
vi.mock('i18next', () => ({
|
|
15
15
|
t: vi.fn((key) => key), // Simplified mock return value
|
|
@@ -6,12 +6,12 @@ import { INBOX_SESSION_ID } from '@/const/session';
|
|
|
6
6
|
import { useGlobalStore } from '@/store/global';
|
|
7
7
|
import { useSessionStore } from '@/store/session';
|
|
8
8
|
import { agentSelectors } from '@/store/session/selectors';
|
|
9
|
-
import { ChatMessage } from '@/types/
|
|
9
|
+
import { ChatMessage } from '@/types/message';
|
|
10
10
|
import { MetaData } from '@/types/meta';
|
|
11
11
|
import { merge } from '@/utils/merge';
|
|
12
12
|
|
|
13
|
-
import { chatHelpers } from '
|
|
14
|
-
import type { ChatStore } from '
|
|
13
|
+
import { chatHelpers } from '../../helpers';
|
|
14
|
+
import type { ChatStore } from '../../store';
|
|
15
15
|
|
|
16
16
|
const getMeta = (message: ChatMessage) => {
|
|
17
17
|
switch (message.role) {
|
|
@@ -8,8 +8,8 @@ import { useSessionStore } from '@/store/session';
|
|
|
8
8
|
import { agentSelectors } from '@/store/session/selectors';
|
|
9
9
|
import { ShareGPTConversation } from '@/types/share';
|
|
10
10
|
|
|
11
|
-
import { chatSelectors } from '
|
|
12
|
-
import { ChatStore } from '
|
|
11
|
+
import { chatSelectors } from '../../selectors';
|
|
12
|
+
import { ChatStore } from '../../store';
|
|
13
13
|
|
|
14
14
|
interface ShareMessage {
|
|
15
15
|
from: 'human' | 'gpt';
|
|
@@ -7,11 +7,11 @@ import { messageService } from '@/services/message';
|
|
|
7
7
|
import { ChatStore } from '@/store/chat/store';
|
|
8
8
|
import { useToolStore } from '@/store/tool';
|
|
9
9
|
import { pluginSelectors } from '@/store/tool/selectors';
|
|
10
|
-
import { ChatPluginPayload } from '@/types/
|
|
10
|
+
import { ChatPluginPayload } from '@/types/message';
|
|
11
11
|
import { OpenAIFunctionCall } from '@/types/openai/functionCall';
|
|
12
12
|
import { setNamespace } from '@/utils/storeDebug';
|
|
13
13
|
|
|
14
|
-
import { chatSelectors } from '
|
|
14
|
+
import { chatSelectors } from '../../selectors';
|
|
15
15
|
|
|
16
16
|
const n = setNamespace('plugin');
|
|
17
17
|
|
|
@@ -85,7 +85,6 @@ export const chatPlugin: StateCreator<
|
|
|
85
85
|
const chats = chatSelectors.currentChats(get());
|
|
86
86
|
await coreProcessMessage(chats, id);
|
|
87
87
|
},
|
|
88
|
-
|
|
89
88
|
triggerFunctionCall: async (id) => {
|
|
90
89
|
const { invokeDefaultTypePlugin, invokeBuiltinTool, refreshMessages } = get();
|
|
91
90
|
|
|
@@ -146,7 +145,6 @@ export const chatPlugin: StateCreator<
|
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
},
|
|
149
|
-
|
|
150
148
|
updatePluginState: async (id, key, value) => {
|
|
151
149
|
const { refreshMessages } = get();
|
|
152
150
|
|
|
@@ -6,10 +6,10 @@ import { LOADING_FLAT } from '@/const/message';
|
|
|
6
6
|
import { chatService } from '@/services/chat';
|
|
7
7
|
import { messageService } from '@/services/message';
|
|
8
8
|
import { topicService } from '@/services/topic';
|
|
9
|
-
import { ChatMessage } from '@/types/
|
|
9
|
+
import { ChatMessage } from '@/types/message';
|
|
10
10
|
import { ChatTopic } from '@/types/topic';
|
|
11
11
|
|
|
12
|
-
import { useChatStore } from '
|
|
12
|
+
import { useChatStore } from '../../store';
|
|
13
13
|
|
|
14
14
|
// Mock topicService 和 messageService
|
|
15
15
|
vi.mock('@/services/topic', () => ({
|
|
@@ -12,11 +12,12 @@ import { chatService } from '@/services/chat';
|
|
|
12
12
|
import { messageService } from '@/services/message';
|
|
13
13
|
import { topicService } from '@/services/topic';
|
|
14
14
|
import { ChatStore } from '@/store/chat';
|
|
15
|
-
import { ChatMessage } from '@/types/
|
|
15
|
+
import { ChatMessage } from '@/types/message';
|
|
16
16
|
import { ChatTopic } from '@/types/topic';
|
|
17
17
|
import { setNamespace } from '@/utils/storeDebug';
|
|
18
18
|
|
|
19
|
-
import { chatSelectors
|
|
19
|
+
import { chatSelectors } from '../message/selectors';
|
|
20
|
+
import { topicSelectors } from './selectors';
|
|
20
21
|
|
|
21
22
|
const n = setNamespace('topic');
|
|
22
23
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChatTopic } from '@/types/topic';
|
|
2
|
+
|
|
3
|
+
export interface ChatTopicState {
|
|
4
|
+
activeTopicId?: string;
|
|
5
|
+
isSearchingTopic: boolean;
|
|
6
|
+
searchTopics: ChatTopic[];
|
|
7
|
+
topicLoadingId?: string;
|
|
8
|
+
topicRenamingId?: string;
|
|
9
|
+
topicSearchKeywords: string;
|
|
10
|
+
topics: ChatTopic[];
|
|
11
|
+
/**
|
|
12
|
+
* whether topics have fetched
|
|
13
|
+
*/
|
|
14
|
+
topicsInit: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const initialTopicState: ChatTopicState = {
|
|
18
|
+
isSearchingTopic: false,
|
|
19
|
+
searchTopics: [],
|
|
20
|
+
topicSearchKeywords: '',
|
|
21
|
+
topics: [],
|
|
22
|
+
topicsInit: false,
|
|
23
|
+
};
|
|
@@ -4,7 +4,7 @@ import { ChatStore } from '@/store/chat';
|
|
|
4
4
|
import { initialState } from '@/store/chat/initialState';
|
|
5
5
|
import { merge } from '@/utils/merge';
|
|
6
6
|
|
|
7
|
-
import { topicSelectors } from '
|
|
7
|
+
import { topicSelectors } from '../../selectors';
|
|
8
8
|
|
|
9
9
|
const initialStore = initialState as ChatStore;
|
|
10
10
|
|
package/src/store/chat/store.ts
CHANGED
|
@@ -6,12 +6,12 @@ import { StateCreator } from 'zustand/vanilla';
|
|
|
6
6
|
import { createHyperStorage } from '@/store/middleware/createHyperStorage';
|
|
7
7
|
import { isDev } from '@/utils/env';
|
|
8
8
|
|
|
9
|
-
import { ChatEnhanceAction, chatEnhance } from './actions/enhance';
|
|
10
|
-
import { ChatMessageAction, chatMessage } from './actions/message';
|
|
11
|
-
import { ChatPluginAction, chatPlugin } from './actions/plugin';
|
|
12
|
-
import { ShareAction, chatShare } from './actions/share';
|
|
13
|
-
import { ChatTopicAction, chatTopic } from './actions/topic';
|
|
14
9
|
import { ChatStoreState, initialState } from './initialState';
|
|
10
|
+
import { ChatEnhanceAction, chatEnhance } from './slices/enchance/action';
|
|
11
|
+
import { ChatMessageAction, chatMessage } from './slices/message/action';
|
|
12
|
+
import { ShareAction, chatShare } from './slices/share/action';
|
|
13
|
+
import { ChatPluginAction, chatPlugin } from './slices/tool/action';
|
|
14
|
+
import { ChatTopicAction, chatTopic } from './slices/topic/action';
|
|
15
15
|
|
|
16
16
|
export interface ChatStoreAction
|
|
17
17
|
extends ChatMessageAction,
|
|
@@ -1,66 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { GlobalCommonState, initialCommonState } from './slices/common/initialState';
|
|
2
|
+
import { GlobalSettingsState, initialSettingsState } from './slices/settings/initialState';
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
Chat = 'chat',
|
|
6
|
-
Market = 'market',
|
|
7
|
-
Setting = 'settings',
|
|
8
|
-
}
|
|
4
|
+
export { SettingsTabs, SidebarTabKey } from './slices/common/initialState';
|
|
9
5
|
|
|
10
|
-
export
|
|
11
|
-
Agent = 'agent',
|
|
12
|
-
Common = 'common',
|
|
13
|
-
LLM = 'llm',
|
|
14
|
-
TTS = 'tts',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Guide {
|
|
18
|
-
// Topic 引导
|
|
19
|
-
topic?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface GlobalPreference {
|
|
23
|
-
guide?: Guide;
|
|
24
|
-
inputHeight: number;
|
|
25
|
-
mobileShowTopic?: boolean;
|
|
26
|
-
sessionGroupKeys: string[];
|
|
27
|
-
sessionsWidth: number;
|
|
28
|
-
showChatSideBar?: boolean;
|
|
29
|
-
showSessionPanel?: boolean;
|
|
30
|
-
showSystemRole?: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface GlobalState {
|
|
34
|
-
hasNewVersion?: boolean;
|
|
35
|
-
latestVersion?: string;
|
|
36
|
-
/**
|
|
37
|
-
* 用户偏好的 UI 状态
|
|
38
|
-
* @localStorage
|
|
39
|
-
*/
|
|
40
|
-
preference: GlobalPreference;
|
|
41
|
-
serverConfig: GlobalServerConfig;
|
|
42
|
-
/**
|
|
43
|
-
* @localStorage
|
|
44
|
-
* 用户设置
|
|
45
|
-
*/
|
|
46
|
-
settings: GlobalSettings;
|
|
47
|
-
settingsTab: SettingsTabs;
|
|
48
|
-
sidebarKey: SidebarTabKey;
|
|
49
|
-
}
|
|
6
|
+
export type GlobalState = GlobalCommonState & GlobalSettingsState;
|
|
50
7
|
|
|
51
8
|
export const initialState: GlobalState = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
inputHeight: 200,
|
|
55
|
-
mobileShowTopic: false,
|
|
56
|
-
sessionGroupKeys: ['pinned', 'sessionList'],
|
|
57
|
-
sessionsWidth: 320,
|
|
58
|
-
showChatSideBar: true,
|
|
59
|
-
showSessionPanel: true,
|
|
60
|
-
showSystemRole: false,
|
|
61
|
-
},
|
|
62
|
-
serverConfig: {},
|
|
63
|
-
settings: DEFAULT_SETTINGS,
|
|
64
|
-
settingsTab: SettingsTabs.Common,
|
|
65
|
-
sidebarKey: SidebarTabKey.Chat,
|
|
9
|
+
...initialCommonState,
|
|
10
|
+
...initialSettingsState,
|
|
66
11
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './selectors
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './slices/common/selectors';
|
|
2
|
+
export * from './slices/settings/selectors';
|
|
@@ -5,12 +5,12 @@ import type { StateCreator } from 'zustand/vanilla';
|
|
|
5
5
|
|
|
6
6
|
import { CURRENT_VERSION } from '@/const/version';
|
|
7
7
|
import { globalService } from '@/services/global';
|
|
8
|
+
import type { GlobalStore } from '@/store/global';
|
|
8
9
|
import type { GlobalServerConfig } from '@/types/settings';
|
|
9
10
|
import { merge } from '@/utils/merge';
|
|
10
11
|
import { setNamespace } from '@/utils/storeDebug';
|
|
11
12
|
|
|
12
|
-
import type {
|
|
13
|
-
import type { GlobalStore } from '../store';
|
|
13
|
+
import type { GlobalCommonState, GlobalPreference, Guide, SidebarTabKey } from './initialState';
|
|
14
14
|
|
|
15
15
|
const n = setNamespace('settings');
|
|
16
16
|
|
|
@@ -66,7 +66,7 @@ export const createCommonSlice: StateCreator<
|
|
|
66
66
|
},
|
|
67
67
|
updatePreference: (preference, action) => {
|
|
68
68
|
set(
|
|
69
|
-
produce((draft:
|
|
69
|
+
produce((draft: GlobalCommonState) => {
|
|
70
70
|
draft.preference = merge(draft.preference, preference);
|
|
71
71
|
}),
|
|
72
72
|
false,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export enum SidebarTabKey {
|
|
2
|
+
Chat = 'chat',
|
|
3
|
+
Market = 'market',
|
|
4
|
+
Setting = 'settings',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum SettingsTabs {
|
|
8
|
+
Agent = 'agent',
|
|
9
|
+
Common = 'common',
|
|
10
|
+
LLM = 'llm',
|
|
11
|
+
TTS = 'tts',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Guide {
|
|
15
|
+
// Topic 引导
|
|
16
|
+
topic?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GlobalPreference {
|
|
20
|
+
guide?: Guide;
|
|
21
|
+
inputHeight: number;
|
|
22
|
+
mobileShowTopic?: boolean;
|
|
23
|
+
sessionGroupKeys: string[];
|
|
24
|
+
sessionsWidth: number;
|
|
25
|
+
showChatSideBar?: boolean;
|
|
26
|
+
showSessionPanel?: boolean;
|
|
27
|
+
showSystemRole?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface GlobalCommonState {
|
|
31
|
+
hasNewVersion?: boolean;
|
|
32
|
+
latestVersion?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 用户偏好的 UI 状态
|
|
35
|
+
* @localStorage
|
|
36
|
+
*/
|
|
37
|
+
preference: GlobalPreference;
|
|
38
|
+
settingsTab: SettingsTabs;
|
|
39
|
+
sidebarKey: SidebarTabKey;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const initialCommonState: GlobalCommonState = {
|
|
43
|
+
preference: {
|
|
44
|
+
guide: {},
|
|
45
|
+
inputHeight: 200,
|
|
46
|
+
mobileShowTopic: false,
|
|
47
|
+
sessionGroupKeys: ['pinned', 'sessionList'],
|
|
48
|
+
sessionsWidth: 320,
|
|
49
|
+
showChatSideBar: true,
|
|
50
|
+
showSessionPanel: true,
|
|
51
|
+
showSystemRole: false,
|
|
52
|
+
},
|
|
53
|
+
settingsTab: SettingsTabs.Common,
|
|
54
|
+
sidebarKey: SidebarTabKey.Chat,
|
|
55
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GlobalStore } from '@/store/global';
|
|
2
2
|
|
|
3
|
-
import { initialState } from '
|
|
3
|
+
import { initialState } from '../../initialState';
|
|
4
4
|
|
|
5
5
|
const sessionGroupKeys = (s: GlobalStore): string[] =>
|
|
6
6
|
s.preference.sessionGroupKeys || initialState.preference.sessionGroupKeys;
|
|
@@ -5,13 +5,13 @@ import { DeepPartial } from 'utility-types';
|
|
|
5
5
|
import type { StateCreator } from 'zustand/vanilla';
|
|
6
6
|
|
|
7
7
|
import { DEFAULT_AGENT, DEFAULT_SETTINGS } from '@/const/settings';
|
|
8
|
+
import type { GlobalStore } from '@/store/global';
|
|
8
9
|
import { SettingsTabs } from '@/store/global/initialState';
|
|
10
|
+
import { LobeAgentSettings } from '@/types/session';
|
|
9
11
|
import type { GlobalSettings, OpenAIConfig } from '@/types/settings';
|
|
10
12
|
import { merge } from '@/utils/merge';
|
|
11
13
|
import { setNamespace } from '@/utils/storeDebug';
|
|
12
14
|
|
|
13
|
-
import type { GlobalStore } from '../store';
|
|
14
|
-
|
|
15
15
|
const n = setNamespace('settings');
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -24,6 +24,7 @@ export interface SettingsAction {
|
|
|
24
24
|
*/
|
|
25
25
|
resetSettings: () => void;
|
|
26
26
|
setOpenAIConfig: (config: Partial<OpenAIConfig>) => void;
|
|
27
|
+
|
|
27
28
|
/**
|
|
28
29
|
* 设置部分配置设置
|
|
29
30
|
* @param settings - 部分配置设置
|
|
@@ -35,6 +36,7 @@ export interface SettingsAction {
|
|
|
35
36
|
* @param themeMode - 主题模式
|
|
36
37
|
*/
|
|
37
38
|
switchThemeMode: (themeMode: ThemeMode) => void;
|
|
39
|
+
updateDefaultAgent: (agent: DeepPartial<LobeAgentSettings>) => void;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export const createSettingsSlice: StateCreator<
|
|
@@ -46,7 +48,7 @@ export const createSettingsSlice: StateCreator<
|
|
|
46
48
|
importAppSettings: (importAppSettings) => {
|
|
47
49
|
const { setSettings } = get();
|
|
48
50
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
-
const {
|
|
51
|
+
const { password: _, ...settings } = importAppSettings;
|
|
50
52
|
|
|
51
53
|
setSettings({
|
|
52
54
|
...settings,
|
|
@@ -78,8 +80,14 @@ export const createSettingsSlice: StateCreator<
|
|
|
78
80
|
switchSettingTabs: (tab) => {
|
|
79
81
|
set({ settingsTab: tab });
|
|
80
82
|
},
|
|
81
|
-
|
|
82
83
|
switchThemeMode: (themeMode) => {
|
|
83
84
|
get().setSettings({ themeMode });
|
|
84
85
|
},
|
|
86
|
+
updateDefaultAgent: (agent) => {
|
|
87
|
+
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
88
|
+
draft.defaultAgent = merge(draft.defaultAgent, agent);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
set({ settings }, false, n('updateDefaultAgent', agent));
|
|
92
|
+
},
|
|
85
93
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DEFAULT_SETTINGS } from '@/const/settings';
|
|
2
|
+
import type { GlobalServerConfig, GlobalSettings } from '@/types/settings';
|
|
3
|
+
|
|
4
|
+
export interface GlobalSettingsState {
|
|
5
|
+
serverConfig: GlobalServerConfig;
|
|
6
|
+
/**
|
|
7
|
+
* @localStorage
|
|
8
|
+
*/
|
|
9
|
+
settings: GlobalSettings;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const initialSettingsState: GlobalSettingsState = {
|
|
13
|
+
serverConfig: {},
|
|
14
|
+
settings: DEFAULT_SETTINGS,
|
|
15
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LanguageModel } from '@/types/llm';
|
|
2
2
|
|
|
3
|
-
import { GlobalStore } from '
|
|
4
|
-
import { settingsSelectors } from './
|
|
3
|
+
import { GlobalStore } from '../../store';
|
|
4
|
+
import { settingsSelectors } from './selectors';
|
|
5
5
|
|
|
6
6
|
describe('settingsSelectors', () => {
|
|
7
7
|
describe('currentSettings', () => {
|
|
@@ -12,7 +12,7 @@ import { CustomModels, GlobalSettings } from '@/types/settings';
|
|
|
12
12
|
import { isOnServerSide } from '@/utils/env';
|
|
13
13
|
import { merge } from '@/utils/merge';
|
|
14
14
|
|
|
15
|
-
import { GlobalStore } from '
|
|
15
|
+
import { GlobalStore } from '../../store';
|
|
16
16
|
|
|
17
17
|
const currentSettings = (s: GlobalStore) => merge(DEFAULT_SETTINGS, s.settings);
|
|
18
18
|
|
|
@@ -24,8 +24,7 @@ const defaultAgentConfig = (s: GlobalStore) => merge(DEFAULT_AGENT_CONFIG, defau
|
|
|
24
24
|
|
|
25
25
|
const defaultAgentMeta = (s: GlobalStore) => merge(DEFAULT_AGENT_META, defaultAgent(s).meta);
|
|
26
26
|
|
|
27
|
-
const openAIAPIKeySelectors = (s: GlobalStore) =>
|
|
28
|
-
s.settings.languageModel.openAI.OPENAI_API_KEY || s.settings.OPENAI_API_KEY;
|
|
27
|
+
const openAIAPIKeySelectors = (s: GlobalStore) => s.settings.languageModel.openAI.OPENAI_API_KEY;
|
|
29
28
|
|
|
30
29
|
const openAIProxyUrlSelectors = (s: GlobalStore) => s.settings.languageModel.openAI.endpoint;
|
|
31
30
|
|
|
@@ -68,7 +67,7 @@ const modelListSelectors = (s: GlobalStore) => {
|
|
|
68
67
|
|
|
69
68
|
export const exportSettings = (s: GlobalStore) => {
|
|
70
69
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
71
|
-
const {
|
|
70
|
+
const { password: _, ...settings } = s.settings;
|
|
72
71
|
|
|
73
72
|
return settings as GlobalSettings;
|
|
74
73
|
};
|
|
@@ -9,18 +9,16 @@ import { isDev } from '@/utils/env';
|
|
|
9
9
|
|
|
10
10
|
import { createHyperStorage } from '../middleware/createHyperStorage';
|
|
11
11
|
import { type GlobalState, initialState } from './initialState';
|
|
12
|
-
import { type
|
|
13
|
-
import { type
|
|
14
|
-
import { type SettingsAction, createSettingsSlice } from './slices/settings';
|
|
12
|
+
import { type CommonAction, createCommonSlice } from './slices/common/action';
|
|
13
|
+
import { type SettingsAction, createSettingsSlice } from './slices/settings/action';
|
|
15
14
|
|
|
16
15
|
// =============== 聚合 createStoreFn ============ //
|
|
17
16
|
|
|
18
|
-
export type GlobalStore = CommonAction & GlobalState &
|
|
17
|
+
export type GlobalStore = CommonAction & GlobalState & SettingsAction;
|
|
19
18
|
|
|
20
19
|
const createStore: StateCreator<GlobalStore, [['zustand/devtools', never]]> = (...parameters) => ({
|
|
21
20
|
...initialState,
|
|
22
21
|
...createCommonSlice(...parameters),
|
|
23
|
-
...createAgentSlice(...parameters),
|
|
24
22
|
...createSettingsSlice(...parameters),
|
|
25
23
|
});
|
|
26
24
|
|
|
@@ -38,24 +36,12 @@ const persistOptions: PersistOptions<GlobalStore, GlobalPersist> = {
|
|
|
38
36
|
if (!draft.defaultAgent) {
|
|
39
37
|
draft.defaultAgent = DEFAULT_AGENT;
|
|
40
38
|
}
|
|
41
|
-
delete draft.enableMaxTokens;
|
|
42
|
-
delete draft.enableHistoryCount;
|
|
43
|
-
delete draft.historyCount;
|
|
44
|
-
delete draft.enableCompressThreshold;
|
|
45
|
-
delete draft.compressThreshold;
|
|
46
39
|
|
|
47
40
|
// migration to new data model
|
|
48
41
|
if (!draft.languageModel) {
|
|
49
42
|
draft.languageModel = {
|
|
50
|
-
openAI:
|
|
51
|
-
...DEFAULT_LLM_CONFIG.openAI,
|
|
52
|
-
OPENAI_API_KEY: draft.OPENAI_API_KEY || DEFAULT_LLM_CONFIG.openAI.OPENAI_API_KEY,
|
|
53
|
-
endpoint: draft.endpoint || DEFAULT_LLM_CONFIG.openAI.OPENAI_API_KEY,
|
|
54
|
-
},
|
|
43
|
+
openAI: DEFAULT_LLM_CONFIG.openAI,
|
|
55
44
|
};
|
|
56
|
-
|
|
57
|
-
delete draft.OPENAI_API_KEY;
|
|
58
|
-
delete draft.endpoint;
|
|
59
45
|
}
|
|
60
46
|
}),
|
|
61
47
|
};
|
|
@@ -4,7 +4,8 @@ import { t } from 'i18next';
|
|
|
4
4
|
import { DEFAULT_OPENAI_MODEL_LIST, VISION_MODEL_WHITE_LIST } from '@/const/llm';
|
|
5
5
|
import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR, DEFAULT_INBOX_AVATAR } from '@/const/meta';
|
|
6
6
|
import { DEFAULT_AGENT_CONFIG, DEFAUTT_AGENT_TTS_CONFIG } from '@/const/settings';
|
|
7
|
-
import {
|
|
7
|
+
import { useGlobalStore } from '@/store/global';
|
|
8
|
+
import { settingsSelectors } from '@/store/global/selectors';
|
|
8
9
|
import { SessionStore } from '@/store/session';
|
|
9
10
|
import { LobeAgentTTSConfig } from '@/types/agent';
|
|
10
11
|
import { LanguageModel } from '@/types/llm';
|
|
@@ -5,7 +5,8 @@ import { StateCreator } from 'zustand/vanilla';
|
|
|
5
5
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
6
6
|
import { SESSION_CHAT_URL } from '@/const/url';
|
|
7
7
|
import { sessionService } from '@/services/session';
|
|
8
|
-
import {
|
|
8
|
+
import { useGlobalStore } from '@/store/global';
|
|
9
|
+
import { settingsSelectors } from '@/store/global/selectors';
|
|
9
10
|
import { SessionStore } from '@/store/session';
|
|
10
11
|
import {
|
|
11
12
|
LobeAgentSession,
|
|
@@ -5,7 +5,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
5
5
|
|
|
6
6
|
import { useChatStore } from '@/store/chat';
|
|
7
7
|
import { chatEnhanceSelectors } from '@/store/chat/selectors';
|
|
8
|
-
import {
|
|
8
|
+
import { useGlobalStore } from '@/store/global';
|
|
9
|
+
import { settingsSelectors } from '@/store/global/selectors';
|
|
9
10
|
import { DallEImageItem } from '@/types/tool/dalle';
|
|
10
11
|
|
|
11
12
|
interface ToolBarProps {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ErrorType } from '@/types/fetch';
|
|
2
2
|
import { Translate } from '@/types/translate';
|
|
3
3
|
|
|
4
|
-
import { LLMRoleType } from '
|
|
5
|
-
import { BaseDataModel } from '
|
|
4
|
+
import { LLMRoleType } from '../llm';
|
|
5
|
+
import { BaseDataModel } from '../meta';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 聊天消息错误对象
|