@lobehub/chat 0.41.0 → 0.41.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/.eslintrc.js
CHANGED
|
@@ -8,5 +8,6 @@ config.rules['unicorn/prefer-logical-operator-over-ternary'] = 0;
|
|
|
8
8
|
config.rules['unicorn/no-null'] = 0;
|
|
9
9
|
config.rules['unicorn/no-typeof-undefined'] = 0;
|
|
10
10
|
config.rules['unicorn/explicit-length-check'] = 0;
|
|
11
|
+
config.rules['unicorn/prefer-code-point'] = 0;
|
|
11
12
|
|
|
12
13
|
module.exports = config;
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.41.1](https://github.com/lobehub/lobe-chat/compare/v0.41.0...v0.41.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-08-10**</sup>
|
|
8
|
+
|
|
9
|
+
#### ♻ Code Refactoring
|
|
10
|
+
|
|
11
|
+
- **misc**: 重构 settings store 代码写法.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Code refactoring
|
|
19
|
+
|
|
20
|
+
- **misc**: 重构 settings store 代码写法 ([4b6f917](https://github.com/lobehub/lobe-chat/commit/4b6f917))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 0.41.0](https://github.com/lobehub/lobe-chat/compare/v0.40.7...v0.41.0)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-08-10**</sup>
|
package/package.json
CHANGED
|
@@ -5,12 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
5
|
import { Flexbox } from 'react-layout-kit';
|
|
6
6
|
import { shallow } from 'zustand/shallow';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
agentSelectors,
|
|
10
|
-
chatSelectors,
|
|
11
|
-
useSessionHydrated,
|
|
12
|
-
useSessionStore,
|
|
13
|
-
} from '@/store/session';
|
|
8
|
+
import { agentSelectors, chatSelectors, useSessionStore } from '@/store/session';
|
|
14
9
|
import { ChatMessage } from '@/types/chatMessage';
|
|
15
10
|
import { ErrorType } from '@/types/fetch';
|
|
16
11
|
import { isFunctionMessage } from '@/utils/message';
|
|
@@ -34,9 +29,8 @@ const renderErrorMessage: RenderErrorMessage = (error, message) => {
|
|
|
34
29
|
|
|
35
30
|
const List = () => {
|
|
36
31
|
const { t } = useTranslation('common');
|
|
37
|
-
|
|
32
|
+
|
|
38
33
|
const data = useSessionStore(chatSelectors.currentChats, isEqual);
|
|
39
|
-
console.log(hydrated, data);
|
|
40
34
|
const [displayMode, chatLoadingId, deleteMessage, resendMessage, dispatchMessage] =
|
|
41
35
|
useSessionStore(
|
|
42
36
|
(s) => [
|
|
@@ -10,6 +10,8 @@ import { AgentAction, createAgentSlice } from './slices/agentConfig';
|
|
|
10
10
|
import { ChatAction, createChatSlice } from './slices/chat';
|
|
11
11
|
import { SessionAction, createSessionSlice } from './slices/session';
|
|
12
12
|
|
|
13
|
+
// =============== 聚合 createStoreFn ============ //
|
|
14
|
+
|
|
13
15
|
export type SessionStore = SessionAction & AgentAction & ChatAction & SessionStoreState;
|
|
14
16
|
|
|
15
17
|
const createStore: StateCreator<SessionStore, [['zustand/devtools', never]]> = (...parameters) => ({
|
|
@@ -19,6 +21,8 @@ const createStore: StateCreator<SessionStore, [['zustand/devtools', never]]> = (
|
|
|
19
21
|
...createChatSlice(...parameters),
|
|
20
22
|
});
|
|
21
23
|
|
|
24
|
+
// =============== persist 本地缓存中间件配置 ============ //
|
|
25
|
+
|
|
22
26
|
type SessionPersist = Pick<SessionStore, 'sessions'>;
|
|
23
27
|
|
|
24
28
|
const LOBE_CHAT = 'LOBE_CHAT';
|
|
@@ -36,6 +40,8 @@ const persistOptions: PersistOptions<SessionStore, SessionPersist> = {
|
|
|
36
40
|
// version: Migration.targetVersion,
|
|
37
41
|
};
|
|
38
42
|
|
|
43
|
+
// =============== 实装 useStore ============ //
|
|
44
|
+
|
|
39
45
|
export const useSessionStore = createWithEqualityFn<SessionStore>()(
|
|
40
46
|
persist(
|
|
41
47
|
devtools(createStore, {
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
import equal from 'fast-deep-equal';
|
|
2
|
-
import { type PersistOptions, devtools, persist } from 'zustand/middleware';
|
|
3
|
-
import { createWithEqualityFn } from 'zustand/traditional';
|
|
4
|
-
|
|
5
|
-
import { isDev } from '@/utils/env';
|
|
6
|
-
|
|
7
|
-
import { type SettingsStore, createStore } from './store';
|
|
8
|
-
|
|
9
|
-
export const LOBE_SETTINGS = 'LOBE_SETTINGS';
|
|
10
|
-
|
|
11
|
-
const persistOptions: PersistOptions<SettingsStore> = {
|
|
12
|
-
name: LOBE_SETTINGS,
|
|
13
|
-
skipHydration: true,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useSettings = createWithEqualityFn<SettingsStore>()(
|
|
17
|
-
persist(
|
|
18
|
-
devtools(createStore, {
|
|
19
|
-
name: LOBE_SETTINGS + (isDev ? '_DEV' : ''),
|
|
20
|
-
}),
|
|
21
|
-
persistOptions,
|
|
22
|
-
),
|
|
23
|
-
equal,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
1
|
export * from './selectors';
|
|
27
2
|
export type { SettingsStore } from './store';
|
|
3
|
+
export { useSettings } from './store';
|
|
@@ -1,15 +1,43 @@
|
|
|
1
|
+
import equal from 'fast-deep-equal';
|
|
2
|
+
import { PersistOptions, devtools, persist } from 'zustand/middleware';
|
|
3
|
+
import { createWithEqualityFn } from 'zustand/traditional';
|
|
1
4
|
import { StateCreator } from 'zustand/vanilla';
|
|
2
5
|
|
|
6
|
+
import { isDev } from '@/utils/env';
|
|
7
|
+
|
|
3
8
|
import { type AppSettingsState, initialState } from './initialState';
|
|
4
9
|
import { type AgentAction, createAgentSlice } from './slices/agent';
|
|
5
10
|
import { type CommonAction, createCommonSlice } from './slices/common';
|
|
6
11
|
|
|
12
|
+
// =============== 聚合 createStoreFn ============ //
|
|
13
|
+
|
|
7
14
|
export type SettingsStore = CommonAction & AppSettingsState & AgentAction;
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
const createStore: StateCreator<SettingsStore, [['zustand/devtools', never]]> = (
|
|
10
17
|
...parameters
|
|
11
18
|
) => ({
|
|
12
19
|
...initialState,
|
|
13
20
|
...createCommonSlice(...parameters),
|
|
14
21
|
...createAgentSlice(...parameters),
|
|
15
22
|
});
|
|
23
|
+
|
|
24
|
+
// =============== persist 本地缓存中间件配置 ============ //
|
|
25
|
+
|
|
26
|
+
const LOBE_SETTINGS = 'LOBE_SETTINGS';
|
|
27
|
+
|
|
28
|
+
const persistOptions: PersistOptions<SettingsStore> = {
|
|
29
|
+
name: LOBE_SETTINGS,
|
|
30
|
+
skipHydration: true,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// =============== 实装 useStore ============ //
|
|
34
|
+
|
|
35
|
+
export const useSettings = createWithEqualityFn<SettingsStore>()(
|
|
36
|
+
persist(
|
|
37
|
+
devtools(createStore, {
|
|
38
|
+
name: LOBE_SETTINGS + (isDev ? '_DEV' : ''),
|
|
39
|
+
}),
|
|
40
|
+
persistOptions,
|
|
41
|
+
),
|
|
42
|
+
equal,
|
|
43
|
+
);
|