@lobehub/chat 0.16.0 → 0.16.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,39 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.16.1](https://github.com/lobehub/lobe-chat/compare/v0.16.0...v0.16.1)
6
+
7
+ <sup>Released on **2023-07-24**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: 重构优化 selectors 实现.
12
+
13
+ #### 💄 Styles
14
+
15
+ - **misc**: 优化 document title.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### Code refactoring
23
+
24
+ - **misc**: 重构优化 selectors 实现 ([97fe1cd](https://github.com/lobehub/lobe-chat/commit/97fe1cd))
25
+
26
+ #### Styles
27
+
28
+ - **misc**: 优化 document title ([c3cda00](https://github.com/lobehub/lobe-chat/commit/c3cda00))
29
+
30
+ </details>
31
+
32
+ <div align="right">
33
+
34
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
35
+
36
+ </div>
37
+
5
38
  ## [Version 0.16.0](https://github.com/lobehub/lobe-chat/compare/v0.15.1...v0.16.0)
6
39
 
7
40
  <sup>Released on **2023-07-24**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -17,6 +17,7 @@ export default {
17
17
  header: {
18
18
  global: '全局设置',
19
19
  session: '会话设置',
20
+ sessionWithName: '会话设置 · {{name}}',
20
21
  },
21
22
  settingAgent: {
22
23
  avatar: {
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
  import { Flexbox } from 'react-layout-kit';
7
7
  import { shallow } from 'zustand/shallow';
8
8
 
9
- import { chatSelectors, sessionSelectors, useSessionStore } from '@/store/session';
9
+ import { agentSelectors, chatSelectors, sessionSelectors, useSessionStore } from '@/store/session';
10
10
  import { useSettings } from '@/store/settings';
11
11
 
12
12
  import { useStyles } from './style';
@@ -39,10 +39,10 @@ const SessionItem: FC<SessionItemProps> = memo(({ id, active = true, loading })
39
39
  const meta = session.meta;
40
40
  const systemRole = session.config.systemRole;
41
41
  return [
42
- meta.title,
42
+ agentSelectors.getTitle(meta),
43
43
  meta.description,
44
44
  systemRole,
45
- sessionSelectors.getAgentAvatar(meta),
45
+ agentSelectors.getAvatar(meta),
46
46
  meta.backgroundColor,
47
47
  session?.updateAt,
48
48
  session.config.model,
@@ -95,7 +95,7 @@ const SessionItem: FC<SessionItemProps> = memo(({ id, active = true, loading })
95
95
  }
96
96
  loading={loading}
97
97
  style={{ color: theme.colorText }}
98
- title={title || t('defaultSession')}
98
+ title={title}
99
99
  />
100
100
  <Popconfirm
101
101
  arrow={false}
@@ -8,7 +8,7 @@ import { sessionSelectors, useSessionStore } from '@/store/session';
8
8
  import SessionItem from './SessionItem';
9
9
 
10
10
  const SessionList = memo(() => {
11
- const list = useSessionStore((s) => sessionSelectors.chatList(s), isEqual);
11
+ const list = useSessionStore((s) => sessionSelectors.sessionList(s), isEqual);
12
12
  const [activeId, loading] = useSessionStore(
13
13
  (s) => [s.activeId, s.autocompleteLoading.title],
14
14
  shallow,
@@ -2,9 +2,11 @@ import Head from 'next/head';
2
2
  import { memo } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Flexbox } from 'react-layout-kit';
5
+ import { shallow } from 'zustand/shallow';
5
6
 
6
7
  import HeaderSpacing from '@/components/HeaderSpacing';
7
8
  import { HEADER_HEIGHT } from '@/const/layoutTokens';
9
+ import { agentSelectors, useSessionStore } from '@/store/session';
8
10
  import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
9
11
 
10
12
  import ChatLayout from '../../layout';
@@ -17,7 +19,8 @@ import Header from './Header';
17
19
  const EditPage = memo(() => {
18
20
  const { t } = useTranslation('setting');
19
21
 
20
- const pageTitle = genSiteHeadTitle(t('header.session'));
22
+ const title = useSessionStore(agentSelectors.currentAgentTitle, shallow);
23
+ const pageTitle = genSiteHeadTitle(t('header.sessionWithName', { name: title }));
21
24
 
22
25
  return (
23
26
  <>
@@ -6,14 +6,14 @@ import { sessionSelectors, useSessionStore } from '@/store/session';
6
6
  import Chat from './[id]/index.page';
7
7
 
8
8
  export default () => {
9
- // 支持用户在进到首页时,自动激活第一个列表中的角色
9
+ // 支持用户在进到首页时,自动激活列表中的第一个角色
10
10
  useEffect(() => {
11
11
  const hasRehydrated = useSessionStore.persist.hasHydrated();
12
12
  // 只有当水合完毕后,才往下走
13
13
  if (!hasRehydrated) return;
14
14
 
15
15
  // 如果当前有会话,那么就激活第一个会话
16
- const list = sessionSelectors.chatList(useSessionStore.getState());
16
+ const list = sessionSelectors.sessionList(useSessionStore.getState());
17
17
  if (list.length > 0) {
18
18
  const sessionId = list[0].id;
19
19
  Router.push(`/chat/${sessionId}`);
@@ -1,3 +1,5 @@
1
+ import { t } from 'i18next';
2
+
1
3
  import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
2
4
  import { SessionStore } from '@/store/session';
3
5
  import { LanguageModel } from '@/types/llm';
@@ -13,7 +15,7 @@ const currentAgentMeta = (s: SessionStore): MetaData => {
13
15
  return { avatar: DEFAULT_AVATAR, backgroundColor: DEFAULT_BACKGROUND_COLOR, ...session?.meta };
14
16
  };
15
17
 
16
- const currentAgentTitle = (s: SessionStore) => currentAgentMeta(s)?.title;
18
+ const currentAgentTitle = (s: SessionStore) => currentAgentMeta(s)?.title || t('defaultSession');
17
19
 
18
20
  const currentAgentBackgroundColor = (s: SessionStore) => {
19
21
  const session = sessionSelectors.currentSession(s);
@@ -51,6 +53,10 @@ const hasSystemRole = (s: SessionStore) => {
51
53
 
52
54
  return !!config.systemRole;
53
55
  };
56
+
57
+ export const getAvatar = (s: MetaData) => s.avatar || DEFAULT_AVATAR;
58
+ export const getTitle = (s: MetaData) => s.title || t('defaultSession');
59
+
54
60
  export const agentSelectors = {
55
61
  currentAgentAvatar,
56
62
  currentAgentBackgroundColor,
@@ -60,5 +66,7 @@ export const agentSelectors = {
60
66
  currentAgentModel,
61
67
  currentAgentSystemRole,
62
68
  currentAgentTitle,
69
+ getAvatar,
70
+ getTitle,
63
71
  hasSystemRole,
64
72
  };
@@ -1,20 +1,15 @@
1
- import { getAgentAvatar } from './chat';
2
1
  import {
3
- chatListSel,
4
2
  currentSessionSafe,
5
3
  currentSessionSel,
6
4
  getSessionById,
7
5
  getSessionMetaById,
6
+ sessionList,
8
7
  } from './list';
9
8
 
10
9
  export const sessionSelectors = {
11
- chatList: chatListSel,
12
10
  currentSession: currentSessionSel,
13
11
  currentSessionSafe,
14
-
15
- getAgentAvatar,
16
-
17
12
  getSessionById,
18
- // sessionTree: sessionTreeSel,
19
13
  getSessionMetaById,
14
+ sessionList,
20
15
  };
@@ -14,7 +14,7 @@ export const currentSessionSafe = (s: SessionStore): LobeAgentSession => {
14
14
  return currentSessionSel(s) || initLobeSession;
15
15
  };
16
16
 
17
- export const chatListSel = (s: SessionStore) => {
17
+ export const sessionList = (s: SessionStore) => {
18
18
  const filterChats = filterWithKeywords(s.sessions, s.searchKeywords, (item) => [
19
19
  Object.values(item.chats)
20
20
  .map((c) => c.content)
@@ -1 +1 @@
1
- export const genSiteHeadTitle = (title?: string) => (title ? `${title} - LobeChat` : 'LobeChat');
1
+ export const genSiteHeadTitle = (title?: string) => (title ? `${title} · LobeChat` : 'LobeChat');
@@ -1,4 +0,0 @@
1
- import { DEFAULT_AVATAR } from '@/const/meta';
2
- import { MetaData } from '@/types/meta';
3
-
4
- export const getAgentAvatar = (s: MetaData) => s.avatar || DEFAULT_AVATAR;