@lobehub/chat 0.70.0 → 0.70.2
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/const/url.ts +2 -1
- package/src/helpers/export.ts +2 -2
- package/src/layout/AppMobileLayout.tsx +5 -0
- package/src/pages/chat/features/Conversation/index.tsx +5 -0
- package/src/pages/chat/features/SessionList/Inbox.tsx +7 -2
- package/src/pages/chat/features/SessionList/List/Item/index.tsx +2 -2
- package/src/pages/chat/features/SessionList/List/index.tsx +8 -3
- package/src/pages/chat/layout.tsx +0 -4
- package/src/pages/chat/mobile/index.page.tsx +4 -7
- package/src/pages/settings/Settings/Agent.tsx +3 -3
- package/src/pages/settings/Settings/Common.tsx +2 -2
- package/src/store/global/selectors.ts +9 -11
- package/src/store/session/slices/chat/selectors/token.ts +8 -9
- package/src/store/session/slices/session/action.ts +2 -2
- package/src/store/session/slices/session/initialState.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.70.2](https://github.com/lobehub/lobe-chat/compare/v0.70.1...v0.70.2)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-09-08**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: 修正移动端路由问题.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: 修正移动端路由问题 ([ae3d2f4](https://github.com/lobehub/lobe-chat/commit/ae3d2f4))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.70.1](https://github.com/lobehub/lobe-chat/compare/v0.70.0...v0.70.1)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-09-08**</sup>
|
|
33
|
+
|
|
34
|
+
#### ♻ Code Refactoring
|
|
35
|
+
|
|
36
|
+
- **misc**: Refactor settingsSelectors to globalSelectors.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### Code refactoring
|
|
44
|
+
|
|
45
|
+
- **misc**: Refactor settingsSelectors to globalSelectors ([38917e8](https://github.com/lobehub/lobe-chat/commit/38917e8))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
## [Version 0.70.0](https://github.com/lobehub/lobe-chat/compare/v0.69.1...v0.70.0)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-09-08**</sup>
|
package/package.json
CHANGED
package/src/const/url.ts
CHANGED
|
@@ -10,4 +10,5 @@ export const DISCORD = 'https://discord.gg/AYFPHvv2jT';
|
|
|
10
10
|
export const PLUGINS_INDEX_URL =
|
|
11
11
|
process.env.PLUGINS_INDEX_URL ?? 'https://chat-plugins.lobehub.com';
|
|
12
12
|
|
|
13
|
-
export const SESSION_CHAT_URL = (id: string = INBOX_SESSION_ID) =>
|
|
13
|
+
export const SESSION_CHAT_URL = (id: string = INBOX_SESSION_ID, mobile?: boolean) =>
|
|
14
|
+
mobile ? `/chat/mobile#session=${id}` : `/chat#session=${id}`;
|
package/src/helpers/export.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 = () =>
|
|
9
|
+
const getSettings = () => globalSelectors.exportSettings(useGlobalStore.getState());
|
|
10
10
|
|
|
11
11
|
// ============= 导出所有角色 ============= //
|
|
12
12
|
|
|
@@ -6,6 +6,7 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
6
6
|
|
|
7
7
|
import SafeSpacing from '@/components/SafeSpacing';
|
|
8
8
|
import MobileTabBar from '@/features/MobileTabBar';
|
|
9
|
+
import { useOnFinishHydrationSession, useSessionStore } from '@/store/session';
|
|
9
10
|
|
|
10
11
|
const useStyles = createStyles(({ css }) => ({
|
|
11
12
|
container: css`
|
|
@@ -45,6 +46,10 @@ const AppMobileLayout = memo<AppMobileLayoutProps>(
|
|
|
45
46
|
({ children, showTabBar, navBar, style, className }) => {
|
|
46
47
|
const { styles, cx } = useStyles();
|
|
47
48
|
|
|
49
|
+
useOnFinishHydrationSession(() => {
|
|
50
|
+
useSessionStore.setState({ isMobile: true });
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
48
53
|
return (
|
|
49
54
|
<>
|
|
50
55
|
<Head>
|
|
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
6
|
import SafeSpacing from '@/components/SafeSpacing';
|
|
7
|
+
import { usePluginStore } from '@/store/plugin';
|
|
7
8
|
|
|
8
9
|
import ChatList from './ChatList';
|
|
9
10
|
import ChatInput from './Input';
|
|
@@ -12,6 +13,10 @@ import ChatScrollAnchor from './ScrollAnchor';
|
|
|
12
13
|
const Conversation = memo<{ mobile?: boolean }>(({ mobile }) => {
|
|
13
14
|
const ref = useRef(null);
|
|
14
15
|
const { t } = useTranslation('common');
|
|
16
|
+
|
|
17
|
+
const useFetchPluginList = usePluginStore((s) => s.useFetchPluginList);
|
|
18
|
+
useFetchPluginList();
|
|
19
|
+
|
|
15
20
|
return (
|
|
16
21
|
<Flexbox flex={1} style={{ position: 'relative' }}>
|
|
17
22
|
<div style={{ flex: 1, overflow: 'hidden', position: 'relative' }}>
|
|
@@ -15,7 +15,12 @@ const Inbox = memo(() => {
|
|
|
15
15
|
const ref = useRef(null);
|
|
16
16
|
const isHovering = useHover(ref);
|
|
17
17
|
const { t } = useTranslation('common');
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
const [mobile, activeId, switchSession] = useSessionStore((s) => [
|
|
20
|
+
s.isMobile,
|
|
21
|
+
s.activeId,
|
|
22
|
+
s.switchSession,
|
|
23
|
+
]);
|
|
19
24
|
|
|
20
25
|
const avatarRender = useMemo(
|
|
21
26
|
() => (
|
|
@@ -31,7 +36,7 @@ const Inbox = memo(() => {
|
|
|
31
36
|
|
|
32
37
|
return (
|
|
33
38
|
<Link
|
|
34
|
-
href={SESSION_CHAT_URL()}
|
|
39
|
+
href={SESSION_CHAT_URL(INBOX_SESSION_ID, mobile)}
|
|
35
40
|
onClick={(e) => {
|
|
36
41
|
e.preventDefault();
|
|
37
42
|
switchSession(INBOX_SESSION_ID);
|
|
@@ -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 {
|
|
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) => [
|
|
39
|
+
const [defaultModel] = useGlobalStore((s) => [globalSelectors.defaultAgentConfig(s).model]);
|
|
40
40
|
|
|
41
41
|
const [
|
|
42
42
|
active,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useResponsive } from 'antd-style';
|
|
1
2
|
import isEqual from 'fast-deep-equal';
|
|
2
3
|
import Link from 'next/link';
|
|
3
4
|
import { memo } from 'react';
|
|
@@ -12,20 +13,24 @@ import SkeletonList from './SkeletonList';
|
|
|
12
13
|
|
|
13
14
|
const SessionList = memo(() => {
|
|
14
15
|
const list = useSessionStore(sessionSelectors.sessionList, isEqual);
|
|
15
|
-
const activeSession = useSessionStore((s) => s.activeSession);
|
|
16
|
+
const [activeSession, switchSession] = useSessionStore((s) => [s.activeSession, s.switchSession]);
|
|
16
17
|
|
|
17
18
|
const isInit = useSessionHydrated();
|
|
18
19
|
|
|
20
|
+
const { mobile } = useResponsive();
|
|
21
|
+
|
|
19
22
|
return !isInit ? (
|
|
20
23
|
<SkeletonList />
|
|
21
24
|
) : list.length > 0 ? (
|
|
22
25
|
list.map(({ id }) => (
|
|
23
26
|
<Link
|
|
24
|
-
href={SESSION_CHAT_URL(id)}
|
|
27
|
+
href={SESSION_CHAT_URL(id, mobile)}
|
|
25
28
|
key={id}
|
|
26
29
|
onClick={(e) => {
|
|
27
30
|
e.preventDefault();
|
|
28
|
-
|
|
31
|
+
|
|
32
|
+
if (mobile) switchSession(id);
|
|
33
|
+
else activeSession(id);
|
|
29
34
|
}}
|
|
30
35
|
>
|
|
31
36
|
<SessionItem id={id} />
|
|
@@ -4,7 +4,6 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
4
4
|
|
|
5
5
|
import AppLayout from '@/layout/AppLayout';
|
|
6
6
|
import { useSwitchSideBarOnInit } from '@/store/global';
|
|
7
|
-
import { usePluginStore } from '@/store/plugin';
|
|
8
7
|
|
|
9
8
|
import { Sessions } from './features/SessionList';
|
|
10
9
|
|
|
@@ -13,9 +12,6 @@ const ChatLayout = memo<PropsWithChildren>(({ children }) => {
|
|
|
13
12
|
|
|
14
13
|
useSwitchSideBarOnInit('chat');
|
|
15
14
|
|
|
16
|
-
const useFetchPluginList = usePluginStore((s) => s.useFetchPluginList);
|
|
17
|
-
useFetchPluginList();
|
|
18
|
-
|
|
19
15
|
return (
|
|
20
16
|
<AppLayout>
|
|
21
17
|
<Sessions />
|
|
@@ -10,7 +10,6 @@ import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
|
10
10
|
|
|
11
11
|
import Conversation from '../features/Conversation';
|
|
12
12
|
import SideBar from '../features/Sidebar';
|
|
13
|
-
import ChatLayout from '../layout';
|
|
14
13
|
|
|
15
14
|
const Chat = memo(() => {
|
|
16
15
|
const [avatar, title] = useSessionStore((s) => [
|
|
@@ -26,12 +25,10 @@ const Chat = memo(() => {
|
|
|
26
25
|
<title>{pageTitle}</title>
|
|
27
26
|
</Head>
|
|
28
27
|
<AppMobileLayout navBar={<Header />}>
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</Flexbox>
|
|
34
|
-
</ChatLayout>
|
|
28
|
+
<Flexbox height={'calc(100vh - 44px)'} horizontal>
|
|
29
|
+
<Conversation mobile />
|
|
30
|
+
<SideBar mobile />
|
|
31
|
+
</Flexbox>
|
|
35
32
|
</AppMobileLayout>
|
|
36
33
|
</>
|
|
37
34
|
);
|
|
@@ -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 {
|
|
5
|
+
import { globalSelectors, useGlobalStore } from '@/store/global';
|
|
6
6
|
|
|
7
7
|
const Agent = memo(() => {
|
|
8
|
-
const config = useGlobalStore(
|
|
9
|
-
const meta = useGlobalStore(
|
|
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 {
|
|
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(
|
|
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
|
|
10
|
+
const defaultAgent = (s: GlobalStore) => merge({}, DEFAULT_AGENT, s.settings.defaultAgent);
|
|
12
11
|
|
|
13
|
-
const
|
|
14
|
-
merge({}, DEFAULT_AGENT_CONFIG,
|
|
12
|
+
const defaultAgentConfig = (s: GlobalStore) =>
|
|
13
|
+
merge({}, DEFAULT_AGENT_CONFIG, defaultAgent(s).config);
|
|
15
14
|
|
|
16
|
-
const
|
|
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
|
|
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
|
|
17
|
+
export const systemRoleTokenCount = (s: SessionStore): number => {
|
|
15
18
|
const systemRole = systemRoleSel(s);
|
|
16
19
|
|
|
17
|
-
return
|
|
20
|
+
return count(systemRole || '');
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
const
|
|
23
|
+
export const chatsTokenCount = (s: SessionStore): number => {
|
|
21
24
|
const chats = currentChatsWithHistoryConfig(s);
|
|
22
|
-
return
|
|
25
|
+
return count(chats.map((m) => m.content).join(''));
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
export const
|
|
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);
|
|
@@ -158,13 +158,13 @@ export const createSessionSlice: StateCreator<
|
|
|
158
158
|
|
|
159
159
|
get().activeSession(id);
|
|
160
160
|
|
|
161
|
-
Router.push(SESSION_CHAT_URL(id));
|
|
161
|
+
Router.push(SESSION_CHAT_URL(id, get().isMobile));
|
|
162
162
|
},
|
|
163
163
|
switchSession: (sessionId = INBOX_SESSION_ID) => {
|
|
164
164
|
if (get().activeId === sessionId) return;
|
|
165
165
|
|
|
166
166
|
get().activeSession(sessionId);
|
|
167
167
|
|
|
168
|
-
Router.push(SESSION_CHAT_URL(sessionId));
|
|
168
|
+
Router.push(SESSION_CHAT_URL(sessionId, get().isMobile));
|
|
169
169
|
},
|
|
170
170
|
});
|
|
@@ -13,6 +13,7 @@ export interface SessionState {
|
|
|
13
13
|
activeId: string | undefined;
|
|
14
14
|
// 默认会话
|
|
15
15
|
inbox: LobeAgentSession;
|
|
16
|
+
isMobile?: boolean;
|
|
16
17
|
searchKeywords: string;
|
|
17
18
|
sessions: Record<string, LobeAgentSession>;
|
|
18
19
|
}
|
|
@@ -40,6 +41,7 @@ export const initInbox = merge({}, initLobeSession, {
|
|
|
40
41
|
export const initialSessionState: SessionState = {
|
|
41
42
|
activeId: undefined,
|
|
42
43
|
inbox: initInbox,
|
|
44
|
+
isMobile: false,
|
|
43
45
|
searchKeywords: '',
|
|
44
46
|
sessions: {},
|
|
45
47
|
};
|