@lobehub/chat 0.115.1 → 0.115.3

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 (91) hide show
  1. package/.env.example +1 -1
  2. package/CHANGELOG.md +50 -0
  3. package/Dockerfile +1 -1
  4. package/README.md +6 -6
  5. package/README.zh-CN.md +6 -6
  6. package/docs/Deployment/Environment-Variable.md +2 -2
  7. package/docs/Deployment/Environment-Variable.zh-CN.md +2 -2
  8. package/next.config.mjs +0 -4
  9. package/package.json +1 -1
  10. package/src/app/api/config/route.ts +15 -0
  11. package/src/app/api/market/AgentMarket.ts +25 -0
  12. package/src/app/api/market/[id]/route.ts +6 -3
  13. package/src/app/api/market/route.ts +6 -3
  14. package/src/app/chat/features/SessionListContent/DefaultMode.tsx +2 -1
  15. package/src/app/chat/features/SessionListContent/List/Item/index.tsx +2 -1
  16. package/src/app/settings/agent/Agent.tsx +2 -1
  17. package/src/app/settings/common/Common.tsx +2 -1
  18. package/src/app/settings/llm/LLM/index.tsx +2 -1
  19. package/src/app/settings/tts/TTS/index.tsx +2 -1
  20. package/src/components/FileList/EditableFileList.tsx +1 -1
  21. package/src/components/FileList/index.tsx +3 -45
  22. package/src/components/FileList/style.ts +0 -23
  23. package/src/config/__tests__/client.test.ts +0 -23
  24. package/src/config/__tests__/server.test.ts +26 -1
  25. package/src/config/client.ts +4 -15
  26. package/src/config/server.ts +14 -1
  27. package/src/const/settings.ts +0 -3
  28. package/src/const/url.ts +1 -18
  29. package/src/features/AgentSetting/AgentConfig/index.tsx +2 -1
  30. package/src/features/AgentSetting/AgentMeta/index.tsx +2 -1
  31. package/src/features/AgentSetting/AgentTTS/index.tsx +3 -2
  32. package/src/features/ChatInput/ActionBar/ModelSwitch.tsx +2 -1
  33. package/src/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -1
  34. package/src/features/Conversation/ChatList/Extras/TTS/index.tsx +3 -2
  35. package/src/features/Conversation/index.tsx +2 -1
  36. package/src/features/PluginDevModal/LocalForm.tsx +3 -2
  37. package/src/hooks/useSTT.ts +2 -1
  38. package/src/hooks/useTTS.ts +2 -1
  39. package/src/layout/GlobalLayout/StoreHydration.tsx +5 -0
  40. package/src/services/__tests__/chat.test.ts +1 -1
  41. package/src/services/__tests__/global.test.ts +49 -32
  42. package/src/services/_header.ts +2 -2
  43. package/src/services/_url.ts +1 -0
  44. package/src/services/config.ts +2 -1
  45. package/src/services/global.ts +9 -0
  46. package/src/services/market.ts +21 -0
  47. package/src/store/chat/initialState.ts +9 -47
  48. package/src/store/chat/selectors.ts +3 -0
  49. package/src/store/chat/{actions/enhance.test.ts → slices/enchance/action.test.ts} +2 -2
  50. package/src/store/chat/{actions/message.test.ts → slices/message/action.test.ts} +1 -1
  51. package/src/store/chat/{actions/message.ts → slices/message/action.ts} +2 -2
  52. package/src/store/chat/slices/message/initialState.ts +29 -0
  53. package/src/store/chat/{reducers/message.test.ts → slices/message/reducer.test.ts} +2 -2
  54. package/src/store/chat/{selectors/__tests__/chat.test.ts → slices/message/selectors.test.ts} +1 -1
  55. package/src/store/chat/{selectors/chat.ts → slices/message/selectors.ts} +2 -2
  56. package/src/store/chat/{actions/share.ts → slices/share/action.ts} +2 -2
  57. package/src/store/chat/slices/share/initialState.ts +7 -0
  58. package/src/store/chat/{actions/plugin.ts → slices/tool/action.ts} +1 -3
  59. package/src/store/chat/slices/tool/initialState.ts +7 -0
  60. package/src/store/chat/{actions/topic.test.ts → slices/topic/action.test.ts} +1 -1
  61. package/src/store/chat/{actions/topic.ts → slices/topic/action.ts} +2 -1
  62. package/src/store/chat/slices/topic/initialState.ts +23 -0
  63. package/src/store/chat/{selectors/__tests__/topic.test.ts → slices/topic/selectors.test.ts} +1 -1
  64. package/src/store/chat/{selectors/topic.ts → slices/topic/selectors.ts} +1 -1
  65. package/src/store/chat/store.ts +5 -5
  66. package/src/store/global/helpers.ts +1 -1
  67. package/src/store/global/index.ts +0 -1
  68. package/src/store/global/initialState.ts +6 -59
  69. package/src/store/global/selectors.ts +2 -2
  70. package/src/store/global/slices/{common.ts → common/action.ts} +12 -3
  71. package/src/store/global/slices/common/initialState.ts +55 -0
  72. package/src/store/global/{selectors/preference.ts → slices/common/selectors.ts} +1 -1
  73. package/src/store/global/{selectors/__snapshots__/settings.test.ts.snap → slices/settings/__snapshots__/selectors.test.ts.snap} +0 -1
  74. package/src/store/global/slices/{settings.ts → settings/action.ts} +12 -4
  75. package/src/store/global/slices/settings/initialState.ts +15 -0
  76. package/src/store/global/{selectors/settings.test.ts → slices/settings/selectors.test.ts} +9 -6
  77. package/src/store/global/{selectors/settings.ts → slices/settings/selectors.ts} +4 -4
  78. package/src/store/global/store.ts +4 -18
  79. package/src/store/market/action.ts +14 -10
  80. package/src/store/session/slices/agent/selectors.ts +2 -1
  81. package/src/store/session/slices/session/action.ts +2 -1
  82. package/src/tools/dalle/Render/ToolBar.tsx +2 -1
  83. package/src/types/settings.ts +4 -29
  84. package/src/components/FileList/FileGrid.tsx +0 -36
  85. package/src/services/agentMarket.ts +0 -21
  86. package/src/store/chat/selectors/index.ts +0 -3
  87. package/src/store/global/slices/agent.ts +0 -34
  88. /package/src/store/chat/{actions/enhance.ts → slices/enchance/action.ts} +0 -0
  89. /package/src/store/chat/{selectors/enchance.ts → slices/enchance/selectors.ts} +0 -0
  90. /package/src/store/chat/{reducers/message.ts → slices/message/reducer.ts} +0 -0
  91. /package/src/store/chat/{actions/plugin.test.ts → slices/tool/action.test.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { ChatTopic } from '@/types/topic';
2
2
 
3
- import { ChatStore } from '../store';
3
+ import { ChatStore } from '../../store';
4
4
 
5
5
  const currentTopics = (s: ChatStore): ChatTopic[] => s.topics;
6
6
 
@@ -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,4 +1,4 @@
1
- import { settingsSelectors } from './selectors';
1
+ import { settingsSelectors } from './slices/settings/selectors';
2
2
  import { useGlobalStore } from './store';
3
3
 
4
4
  const getCurrentLanguage = () => settingsSelectors.currentLanguage(useGlobalStore.getState());
@@ -1,3 +1,2 @@
1
1
  export * from './hooks';
2
- export * from './selectors';
3
2
  export * from './store';
@@ -1,64 +1,11 @@
1
- import { DEFAULT_SETTINGS } from '@/const/settings';
2
- import type { GlobalSettings } from '@/types/settings';
1
+ import { GlobalCommonState, initialCommonState } from './slices/common/initialState';
2
+ import { GlobalSettingsState, initialSettingsState } from './slices/settings/initialState';
3
3
 
4
- export enum SidebarTabKey {
5
- Chat = 'chat',
6
- Market = 'market',
7
- Setting = 'settings',
8
- }
4
+ export { SettingsTabs, SidebarTabKey } from './slices/common/initialState';
9
5
 
10
- export enum SettingsTabs {
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
- /**
42
- * @localStorage
43
- * 用户设置
44
- */
45
- settings: GlobalSettings;
46
- settingsTab: SettingsTabs;
47
- sidebarKey: SidebarTabKey;
48
- }
6
+ export type GlobalState = GlobalCommonState & GlobalSettingsState;
49
7
 
50
8
  export const initialState: GlobalState = {
51
- preference: {
52
- guide: {},
53
- inputHeight: 200,
54
- mobileShowTopic: false,
55
- sessionGroupKeys: ['pinned', 'sessionList'],
56
- sessionsWidth: 320,
57
- showChatSideBar: true,
58
- showSessionPanel: true,
59
- showSystemRole: false,
60
- },
61
- settings: DEFAULT_SETTINGS,
62
- settingsTab: SettingsTabs.Common,
63
- sidebarKey: SidebarTabKey.Chat,
9
+ ...initialCommonState,
10
+ ...initialSettingsState,
64
11
  };
@@ -1,2 +1,2 @@
1
- export * from './selectors/preference';
2
- export * from './selectors/settings';
1
+ export * from './slices/common/selectors';
2
+ export * from './slices/settings/selectors';
@@ -5,11 +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';
9
+ import type { GlobalServerConfig } from '@/types/settings';
8
10
  import { merge } from '@/utils/merge';
9
11
  import { setNamespace } from '@/utils/storeDebug';
10
12
 
11
- import type { GlobalPreference, GlobalState, Guide, SidebarTabKey } from '../initialState';
12
- import type { GlobalStore } from '../store';
13
+ import type { GlobalCommonState, GlobalPreference, Guide, SidebarTabKey } from './initialState';
13
14
 
14
15
  const n = setNamespace('settings');
15
16
 
@@ -28,6 +29,7 @@ export interface CommonAction {
28
29
  updateGuideState: (guide: Partial<Guide>) => void;
29
30
  updatePreference: (preference: Partial<GlobalPreference>, action?: string) => void;
30
31
  useCheckLatestVersion: () => SWRResponse<string>;
32
+ useFetchGlobalConfig: () => SWRResponse;
31
33
  }
32
34
 
33
35
  export const createCommonSlice: StateCreator<
@@ -64,7 +66,7 @@ export const createCommonSlice: StateCreator<
64
66
  },
65
67
  updatePreference: (preference, action) => {
66
68
  set(
67
- produce((draft: GlobalState) => {
69
+ produce((draft: GlobalCommonState) => {
68
70
  draft.preference = merge(draft.preference, preference);
69
71
  }),
70
72
  false,
@@ -78,4 +80,11 @@ export const createCommonSlice: StateCreator<
78
80
  set({ hasNewVersion: true, latestVersion: data }, false, n('checkLatestVersion'));
79
81
  },
80
82
  }),
83
+ useFetchGlobalConfig: () =>
84
+ useSWR<GlobalServerConfig>('fetchGlobalConfig', globalService.getGlobalConfig, {
85
+ onSuccess: (data) => {
86
+ if (data) set({ serverConfig: data });
87
+ },
88
+ revalidateOnFocus: false,
89
+ }),
81
90
  });
@@ -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 '../initialState';
3
+ import { initialState } from '../../initialState';
4
4
 
5
5
  const sessionGroupKeys = (s: GlobalStore): string[] =>
6
6
  s.preference.sessionGroupKeys || initialState.preference.sessionGroupKeys;
@@ -136,7 +136,6 @@ exports[`settingsSelectors > currentSettings > should merge DEFAULT_SETTINGS and
136
136
  "languageModel": {
137
137
  "openAI": {
138
138
  "OPENAI_API_KEY": "openai-api-key",
139
- "customModelName": undefined,
140
139
  "endpoint": "https://openai-endpoint.com",
141
140
  "models": [
142
141
  "gpt-3.5-turbo",
@@ -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 { OPENAI_API_KEY: _, password: __, ...settings } = importAppSettings;
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 '../store';
4
- import { settingsSelectors } from './settings';
3
+ import { GlobalStore } from '../../store';
4
+ import { settingsSelectors } from './selectors';
5
5
 
6
6
  describe('settingsSelectors', () => {
7
7
  describe('currentSettings', () => {
@@ -61,12 +61,13 @@ describe('settingsSelectors', () => {
61
61
  describe('CUSTOM_MODELS', () => {
62
62
  it('custom deletion, addition, and renaming of models', () => {
63
63
  const s = {
64
+ serverConfig: {
65
+ customModelName:
66
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo,gpt-4-1106-preview=gpt-4-32k',
67
+ },
64
68
  settings: {
65
69
  languageModel: {
66
- openAI: {
67
- customModelName:
68
- '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo,gpt-4-1106-preview=gpt-4-32k',
69
- },
70
+ openAI: {},
70
71
  },
71
72
  },
72
73
  } as unknown as GlobalStore;
@@ -78,6 +79,7 @@ describe('settingsSelectors', () => {
78
79
 
79
80
  it('duplicate naming model', () => {
80
81
  const s = {
82
+ serverConfig: {},
81
83
  settings: {
82
84
  languageModel: {
83
85
  openAI: {
@@ -94,6 +96,7 @@ describe('settingsSelectors', () => {
94
96
 
95
97
  it('only add the model', () => {
96
98
  const s = {
99
+ serverConfig: {},
97
100
  settings: {
98
101
  languageModel: {
99
102
  openAI: {
@@ -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 '../store';
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
 
@@ -34,6 +33,7 @@ const modelListSelectors = (s: GlobalStore) => {
34
33
 
35
34
  const modelNames = [
36
35
  ...DEFAULT_OPENAI_MODEL_LIST,
36
+ ...(s.serverConfig.customModelName || '').split(/[,,]/).filter(Boolean),
37
37
  ...(s.settings.languageModel.openAI.customModelName || '').split(/[,,]/).filter(Boolean),
38
38
  ];
39
39
 
@@ -67,7 +67,7 @@ const modelListSelectors = (s: GlobalStore) => {
67
67
 
68
68
  export const exportSettings = (s: GlobalStore) => {
69
69
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
- const { OPENAI_API_KEY: _, password: __, ...settings } = s.settings;
70
+ const { password: _, ...settings } = s.settings;
71
71
 
72
72
  return settings as GlobalSettings;
73
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 AgentAction, createAgentSlice } from './slices/agent';
13
- import { type CommonAction, createCommonSlice } from './slices/common';
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 & AgentAction & SettingsAction;
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
  };
@@ -3,7 +3,7 @@ import { produce } from 'immer';
3
3
  import useSWR, { SWRResponse } from 'swr';
4
4
  import type { StateCreator } from 'zustand/vanilla';
5
5
 
6
- import { getAgentList, getAgentManifest } from '@/services/agentMarket';
6
+ import { marketService } from '@/services/market';
7
7
  import { globalHelpers } from '@/store/global/helpers';
8
8
  import { AgentsMarketItem, LobeChatAgentsMarketIndex } from '@/types/market';
9
9
 
@@ -47,7 +47,7 @@ export const createMarketAction: StateCreator<
47
47
  useFetchAgent: (identifier) =>
48
48
  useSWR<AgentsMarketItem>(
49
49
  [identifier, globalHelpers.getCurrentLanguage()],
50
- ([id, locale]) => getAgentManifest(id, locale as string),
50
+ ([id, locale]) => marketService.getAgentManifest(id, locale as string),
51
51
  {
52
52
  onError: () => {
53
53
  get().deactivateAgent();
@@ -58,13 +58,17 @@ export const createMarketAction: StateCreator<
58
58
  },
59
59
  ),
60
60
  useFetchAgentList: () =>
61
- useSWR<LobeChatAgentsMarketIndex>(globalHelpers.getCurrentLanguage(), getAgentList, {
62
- onSuccess: (agentMarketIndex) => {
63
- set(
64
- { agentList: agentMarketIndex.agents, tagList: agentMarketIndex.tags },
65
- false,
66
- 'useFetchAgentList',
67
- );
61
+ useSWR<LobeChatAgentsMarketIndex>(
62
+ globalHelpers.getCurrentLanguage(),
63
+ marketService.getAgentList,
64
+ {
65
+ onSuccess: (agentMarketIndex) => {
66
+ set(
67
+ { agentList: agentMarketIndex.agents, tagList: agentMarketIndex.tags },
68
+ false,
69
+ 'useFetchAgentList',
70
+ );
71
+ },
68
72
  },
69
- }),
73
+ ),
70
74
  });
@@ -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 { settingsSelectors, useGlobalStore } from '@/store/global';
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 { settingsSelectors, useGlobalStore } from '@/store/global';
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 { settingsSelectors, useGlobalStore } from '@/store/global';
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 {
@@ -5,37 +5,8 @@ import { LocaleMode } from '@/types/locale';
5
5
  import type { LobeAgentSession } from '@/types/session';
6
6
 
7
7
  export interface GlobalBaseSettings {
8
- /**
9
- * @deprecated
10
- */
11
- OPENAI_API_KEY?: string;
12
-
13
8
  avatar: string;
14
- /**
15
- * @deprecated
16
- */
17
- compressThreshold?: number;
18
- /**
19
- * @deprecated
20
- */
21
- enableCompressThreshold?: boolean;
22
- /**
23
- * @deprecated
24
- */
25
- enableHistoryCount?: boolean;
26
- /**
27
- * @deprecated
28
- */
29
- enableMaxTokens?: boolean;
30
- /**
31
- * @deprecated
32
- */
33
- endpoint?: string;
34
9
  fontSize: number;
35
- /**
36
- * @deprecated
37
- */
38
- historyCount?: number;
39
10
  language: LocaleMode;
40
11
  neutralColor?: NeutralColors;
41
12
  password: string;
@@ -91,3 +62,7 @@ export interface GlobalSettings extends GlobalBaseSettings {
91
62
  }
92
63
 
93
64
  export type ConfigKeys = keyof GlobalSettings;
65
+
66
+ export interface GlobalServerConfig {
67
+ customModelName?: string;
68
+ }
@@ -1,36 +0,0 @@
1
- import { CSSProperties, ReactNode, memo } from 'react';
2
- import { Flexbox } from 'react-layout-kit';
3
-
4
- import { MAX_SIZE_DESKTOP, MIN_IMAGE_SIZE, useStyles } from '@/components/FileList/style';
5
-
6
- interface FileGridProps {
7
- children: ReactNode;
8
- className?: string;
9
- col?: number;
10
- gap?: number;
11
- max?: number;
12
- min?: number;
13
- style?: CSSProperties;
14
- }
15
-
16
- const FileGrid = memo<FileGridProps>(
17
- ({
18
- gap = 4,
19
- col = 3,
20
- max = MAX_SIZE_DESKTOP,
21
- min = MIN_IMAGE_SIZE,
22
- children,
23
- className,
24
- style,
25
- }) => {
26
- const { styles, cx } = useStyles({ col, gap, max, min });
27
-
28
- return (
29
- <Flexbox className={cx(styles.container, className)} gap={gap} horizontal style={style}>
30
- {children}
31
- </Flexbox>
32
- );
33
- },
34
- );
35
-
36
- export default FileGrid;
@@ -1,21 +0,0 @@
1
- import { URLS } from '@/services/_url';
2
- import { LobeChatAgentsMarketIndex } from '@/types/market';
3
-
4
- /**
5
- * 请求助手列表
6
- */
7
- export const getAgentList = async (locale: string): Promise<LobeChatAgentsMarketIndex> => {
8
- const res = await fetch(`${URLS.market}?locale=${locale}`);
9
-
10
- return res.json();
11
- };
12
-
13
- /**
14
- * 请求助手 manifest
15
- */
16
- export const getAgentManifest = async (identifier: string, locale: string) => {
17
- if (!identifier) return;
18
- const res = await fetch(`${URLS.market}/${identifier}?locale=${locale}`);
19
-
20
- return res.json();
21
- };
@@ -1,3 +0,0 @@
1
- export { chatSelectors } from './chat';
2
- export { chatEnhanceSelectors } from './enchance';
3
- export { topicSelectors } from './topic';
@@ -1,34 +0,0 @@
1
- import { produce } from 'immer';
2
- import { DeepPartial } from 'utility-types';
3
- import type { StateCreator } from 'zustand/vanilla';
4
-
5
- import { LobeAgentSettings } from '@/types/session';
6
- import type { GlobalSettings } from '@/types/settings';
7
- import { merge } from '@/utils/merge';
8
- import { setNamespace } from '@/utils/storeDebug';
9
-
10
- import type { GlobalStore } from '../store';
11
-
12
- const n = setNamespace('settings');
13
-
14
- /**
15
- * 设置操作
16
- */
17
- export interface AgentAction {
18
- updateDefaultAgent: (agent: DeepPartial<LobeAgentSettings>) => void;
19
- }
20
-
21
- export const createAgentSlice: StateCreator<
22
- GlobalStore,
23
- [['zustand/devtools', never]],
24
- [],
25
- AgentAction
26
- > = (set, get) => ({
27
- updateDefaultAgent: (agent) => {
28
- const settings = produce(get().settings, (draft: GlobalSettings) => {
29
- draft.defaultAgent = merge(draft.defaultAgent, agent);
30
- });
31
-
32
- set({ settings }, false, n('updateDefaultAgent', agent));
33
- },
34
- });