@lobehub/chat 0.70.0 → 0.70.1

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 CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.70.1](https://github.com/lobehub/lobe-chat/compare/v0.70.0...v0.70.1)
6
+
7
+ <sup>Released on **2023-09-08**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor settingsSelectors to globalSelectors.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor settingsSelectors to globalSelectors ([38917e8](https://github.com/lobehub/lobe-chat/commit/38917e8))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ## [Version 0.70.0](https://github.com/lobehub/lobe-chat/compare/v0.69.1...v0.70.0)
6
31
 
7
32
  <sup>Released on **2023-09-08**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.70.0",
3
+ "version": "0.70.1",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -1,4 +1,4 @@
1
- import { settingsSelectors, useGlobalStore } from '@/store/global';
1
+ import { globalSelectors, useGlobalStore } from '@/store/global';
2
2
  import { useSessionStore } from '@/store/session';
3
3
  import { sessionSelectors } from '@/store/session/selectors';
4
4
  import { createConfigFile, exportConfigFile } from '@/utils/config';
@@ -6,7 +6,7 @@ import { createConfigFile, exportConfigFile } from '@/utils/config';
6
6
  const getSessions = () => sessionSelectors.exportSessions(useSessionStore.getState());
7
7
  const getSession = (id: string) => sessionSelectors.getSessionById(id)(useSessionStore.getState());
8
8
 
9
- const getSettings = () => settingsSelectors.exportSettings(useGlobalStore.getState());
9
+ const getSettings = () => globalSelectors.exportSettings(useGlobalStore.getState());
10
10
 
11
11
  // ============= 导出所有角色 ============= //
12
12
 
@@ -6,7 +6,7 @@ import { memo, useMemo, useRef, useState } from 'react';
6
6
  import { Flexbox } from 'react-layout-kit';
7
7
  import { shallow } from 'zustand/shallow';
8
8
 
9
- import { settingsSelectors, useGlobalStore } from '@/store/global';
9
+ import { globalSelectors, useGlobalStore } from '@/store/global';
10
10
  import { useSessionStore } from '@/store/session';
11
11
  import { agentSelectors, sessionSelectors } from '@/store/session/selectors';
12
12
 
@@ -36,7 +36,7 @@ const SessionItem = memo<SessionItemProps>(({ id }) => {
36
36
  const isHovering = useHover(ref);
37
37
 
38
38
  const { styles } = useStyles();
39
- const [defaultModel] = useGlobalStore((s) => [settingsSelectors.currentAgentConfig(s).model]);
39
+ const [defaultModel] = useGlobalStore((s) => [globalSelectors.defaultAgentConfig(s).model]);
40
40
 
41
41
  const [
42
42
  active,
@@ -2,11 +2,11 @@ import isEqual from 'fast-deep-equal';
2
2
  import { memo } from 'react';
3
3
 
4
4
  import AgentSetting from '@/features/AgentSetting';
5
- import { settingsSelectors, useGlobalStore } from '@/store/global';
5
+ import { globalSelectors, useGlobalStore } from '@/store/global';
6
6
 
7
7
  const Agent = memo(() => {
8
- const config = useGlobalStore(settingsSelectors.currentAgentConfig, isEqual);
9
- const meta = useGlobalStore(settingsSelectors.currentAgentMeta, isEqual);
8
+ const config = useGlobalStore(globalSelectors.defaultAgentConfig, isEqual);
9
+ const meta = useGlobalStore(globalSelectors.defaultAgentMeta, isEqual);
10
10
  const [updateAgent] = useGlobalStore((s) => [s.updateDefaultAgent]);
11
11
 
12
12
  return (
@@ -12,7 +12,7 @@ import { FORM_STYLE } from '@/const/layoutTokens';
12
12
  import { DEFAULT_SETTINGS } from '@/const/settings';
13
13
  import AvatarWithUpload from '@/features/AvatarWithUpload';
14
14
  import { options } from '@/locales/options';
15
- import { settingsSelectors, useGlobalStore } from '@/store/global';
15
+ import { globalSelectors, useGlobalStore } from '@/store/global';
16
16
  import { useSessionStore } from '@/store/session';
17
17
  import { ConfigKeys } from '@/types/settings';
18
18
 
@@ -29,7 +29,7 @@ const Common = memo(() => {
29
29
  const [form] = AntForm.useForm();
30
30
  const clearSessions = useSessionStore((s) => s.clearSessions);
31
31
 
32
- const settings = useGlobalStore(settingsSelectors.currentSettings, isEqual);
32
+ const settings = useGlobalStore(globalSelectors.currentSettings, isEqual);
33
33
  const [setThemeMode, setSettings, resetSettings] = useGlobalStore((s) => [
34
34
  s.switchThemeMode,
35
35
  s.setSettings,
@@ -1,20 +1,18 @@
1
- import { merge } from 'lodash-es';
2
-
3
1
  import { DEFAULT_AGENT_META } from '@/const/meta';
4
2
  import { DEFAULT_AGENT, DEFAULT_AGENT_CONFIG, DEFAULT_SETTINGS } from '@/const/settings';
5
3
  import { GlobalSettings } from '@/types/settings';
4
+ import { merge } from '@/utils/merge';
6
5
 
7
6
  import { GlobalStore } from './store';
8
7
 
9
8
  const currentSettings = (s: GlobalStore) => merge({}, DEFAULT_SETTINGS, s.settings);
10
9
 
11
- const currentDefaultAgent = (s: GlobalStore) => merge({}, DEFAULT_AGENT, s.settings.defaultAgent);
10
+ const defaultAgent = (s: GlobalStore) => merge({}, DEFAULT_AGENT, s.settings.defaultAgent);
12
11
 
13
- const currentAgentConfig = (s: GlobalStore) =>
14
- merge({}, DEFAULT_AGENT_CONFIG, currentDefaultAgent(s).config);
12
+ const defaultAgentConfig = (s: GlobalStore) =>
13
+ merge({}, DEFAULT_AGENT_CONFIG, defaultAgent(s).config);
15
14
 
16
- const currentAgentMeta = (s: GlobalStore) =>
17
- merge({}, DEFAULT_AGENT_META, currentDefaultAgent(s).meta);
15
+ const defaultAgentMeta = (s: GlobalStore) => merge({}, DEFAULT_AGENT_META, defaultAgent(s).meta);
18
16
 
19
17
  export const exportSettings = (s: GlobalStore) => {
20
18
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -23,10 +21,10 @@ export const exportSettings = (s: GlobalStore) => {
23
21
  return settings as GlobalSettings;
24
22
  };
25
23
 
26
- export const settingsSelectors = {
27
- currentAgentConfig,
28
- currentAgentMeta,
29
- currentDefaultAgent,
24
+ export const globalSelectors = {
30
25
  currentSettings,
26
+ defaultAgent,
27
+ defaultAgentConfig,
28
+ defaultAgentMeta,
31
29
  exportSettings,
32
30
  };
@@ -5,25 +5,24 @@ import { agentSelectors } from '@/store/session/slices/agentConfig';
5
5
  import type { SessionStore } from '../../../store';
6
6
  import { currentChatsWithHistoryConfig } from './chat';
7
7
 
8
+ // TODO: We should find a smaller package to do this. gpt-tokenizer has 2M Size
9
+ const count = (text: string) => encode(text).length;
10
+
8
11
  export const systemRoleSel = (s: SessionStore): string => {
9
12
  const config = agentSelectors.currentAgentConfig(s);
10
13
 
11
14
  return config.systemRole;
12
15
  };
13
16
 
14
- const systemRoleTokens = (s: SessionStore): number[] => {
17
+ export const systemRoleTokenCount = (s: SessionStore): number => {
15
18
  const systemRole = systemRoleSel(s);
16
19
 
17
- return encode(systemRole || '');
20
+ return count(systemRole || '');
18
21
  };
19
22
 
20
- const chatsTokens = (s: SessionStore): number[] => {
23
+ export const chatsTokenCount = (s: SessionStore): number => {
21
24
  const chats = currentChatsWithHistoryConfig(s);
22
- return encode(chats.map((m) => m.content).join(''));
25
+ return count(chats.map((m) => m.content).join(''));
23
26
  };
24
27
 
25
- export const chatsTokenCount = (s: SessionStore) => chatsTokens(s).length;
26
-
27
- export const systemRoleTokenCount = (s: SessionStore) => systemRoleTokens(s).length;
28
-
29
- export const totalTokenCount = (s: SessionStore) => chatsTokens(s).length + systemRoleTokenCount(s);
28
+ export const totalTokenCount = (s: SessionStore) => chatsTokenCount(s) + systemRoleTokenCount(s);