@lobehub/chat 0.161.14 → 0.161.16
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/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/docs/self-hosting/environment-variables/model-provider.mdx +7 -0
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +7 -0
- package/package.json +1 -1
- package/src/config/llm.ts +39 -63
- package/src/database/client/models/__tests__/sessionGroup.test.ts +7 -0
- package/src/hooks/useSyncData.ts +2 -2
- package/src/layout/AuthProvider/Clerk/UserUpdater.tsx +0 -1
- package/src/store/user/slices/auth/initialState.ts +0 -6
- package/src/store/user/slices/auth/selectors.ts +2 -2
- package/src/store/user/slices/common/action.test.ts +4 -3
- package/src/store/user/slices/common/action.ts +7 -2
- package/src/types/user/index.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.161.16](https://github.com/lobehub/lobe-chat/compare/v0.161.15...v0.161.16)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-05-25**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix bedrock show by default on vercel.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix bedrock show by default on vercel, closes [#2634](https://github.com/lobehub/lobe-chat/issues/2634) ([7ad3af2](https://github.com/lobehub/lobe-chat/commit/7ad3af2))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.161.15](https://github.com/lobehub/lobe-chat/compare/v0.161.14...v0.161.15)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-05-24**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: Fix avatar missing on client DB mode.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: Fix avatar missing on client DB mode, closes [#2645](https://github.com/lobehub/lobe-chat/issues/2645) ([12726c2](https://github.com/lobehub/lobe-chat/commit/12726c2))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.161.14](https://github.com/lobehub/lobe-chat/compare/v0.161.13...v0.161.14)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-05-24**</sup>
|
package/README.md
CHANGED
|
@@ -262,14 +262,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
262
262
|
|
|
263
263
|
<!-- AGENT LIST -->
|
|
264
264
|
|
|
265
|
-
| Recent Submits
|
|
266
|
-
|
|
|
267
|
-
| [
|
|
268
|
-
| [
|
|
269
|
-
| [
|
|
270
|
-
| [
|
|
271
|
-
|
|
272
|
-
> 📊 Total agents: [<kbd>**
|
|
265
|
+
| Recent Submits | Description |
|
|
266
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
267
|
+
| [Chinese Text Refinement Master](https://chat-preview.lobehub.com/market?agent=chinese-touch-ups)<br/><sup>By **[S45618](https://github.com/S45618)** on **2024-05-24**</sup> | Proficient in Chinese proofreading and rhetoric, aiming to enhance the fluency and elegance of the text.<br/>`proofreading` `text-refinement` `rhetorical-improvement` `classical-literature` `language-editing` |
|
|
268
|
+
| [IT Systems Architect](https://chat-preview.lobehub.com/market?agent=it-system-architect)<br/><sup>By **[a562314](https://github.com/a562314)** on **2024-05-24**</sup> | Senior IT architect specializing in requirements analysis, system design, technology selection, and cross-platform system optimization. With over 5 years of experience, holding a bachelor's degree in computer science, proficient in Windows, macOS, and Linux operating systems, skilled in teamwork, continuous learning, troubleshooting, and security protection.<br/>`it-architecture-design` `problem-solving` `agile-development` `system-optimization` `cross-platform-skills` `teamwork` |
|
|
269
|
+
| [Minecraft Command Instructor](https://chat-preview.lobehub.com/market?agent=mcse-helper)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-05-24**</sup> | Specializes in explaining and demonstrating Minecraft commands<br/>`minecraft` `commands` `explanation` `examples` |
|
|
270
|
+
| [Philosophical Analysis Assistant](https://chat-preview.lobehub.com/market?agent=philosophical-analysis)<br/><sup>By **[epochaudio](https://github.com/epochaudio)** on **2024-05-24**</sup> | Specializes in consulting on Kant and Hegel's philosophical analysis, cultivating critical thinking<br/>`philosophical-analysis` `critical-thinking` `systematic-thinking` |
|
|
271
|
+
|
|
272
|
+
> 📊 Total agents: [<kbd>**273**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
273
273
|
|
|
274
274
|
<!-- AGENT LIST -->
|
|
275
275
|
|
package/README.zh-CN.md
CHANGED
|
@@ -250,14 +250,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
250
250
|
|
|
251
251
|
<!-- AGENT LIST -->
|
|
252
252
|
|
|
253
|
-
| 最近新增
|
|
254
|
-
|
|
|
255
|
-
| [
|
|
256
|
-
| [
|
|
257
|
-
| [
|
|
258
|
-
| [
|
|
259
|
-
|
|
260
|
-
> 📊 Total agents: [<kbd>**
|
|
253
|
+
| 最近新增 | 助手说明 |
|
|
254
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
255
|
+
| [中文润色大师](https://chat-preview.lobehub.com/market?agent=chinese-touch-ups)<br/><sup>By **[S45618](https://github.com/S45618)** on **2024-05-24**</sup> | 精通中文校对与修辞,旨在提升文本之流畅与雅致<br/>`校对` `文字润色` `修辞改进` `古典文学` `语言编辑` |
|
|
256
|
+
| [IT 系统架构师](https://chat-preview.lobehub.com/market?agent=it-system-architect)<br/><sup>By **[a562314](https://github.com/a562314)** on **2024-05-24**</sup> | 资深 IT 架构师,擅长需求分析、系统设计、技术选型和跨平台系统优化。5 年以上经验,具备计算机科学本科学历,精通 Windows、macOS 和 Linux 三大操作系统,善于团队合作,持续学习,具备故障排除和安全防护能力。<br/>`it架构设计` `问题解决` `敏捷开发` `系统优化` `跨平台技能` `团队合作` |
|
|
257
|
+
| [我的世界指令导师](https://chat-preview.lobehub.com/market?agent=mcse-helper)<br/><sup>By **[CLOT-LIU](https://github.com/CLOT-LIU)** on **2024-05-24**</sup> | 擅长解释和示范 “我的世界” 指令<br/>`我的世界` `指令` `解释` `示例` |
|
|
258
|
+
| [哲学剖析助手](https://chat-preview.lobehub.com/market?agent=philosophical-analysis)<br/><sup>By **[epochaudio](https://github.com/epochaudio)** on **2024-05-24**</sup> | 擅长康德与黑格尔哲学分析咨询,培养批判性思维<br/>`哲学分析` `批判性思维` `系统思考` |
|
|
259
|
+
|
|
260
|
+
> 📊 Total agents: [<kbd>**273**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
261
261
|
|
|
262
262
|
<!-- AGENT LIST -->
|
|
263
263
|
|
|
@@ -132,6 +132,13 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
|
|
|
132
132
|
|
|
133
133
|
## AWS Bedrock
|
|
134
134
|
|
|
135
|
+
### `ENABLED_AWS_BEDROCK`
|
|
136
|
+
|
|
137
|
+
- Type:Optional
|
|
138
|
+
- Description:Enables AWS Bedrock as a model provider by default, turns on the AWS Bedrock service when set to `1`
|
|
139
|
+
- Default:`0`
|
|
140
|
+
- Example:`1`
|
|
141
|
+
|
|
135
142
|
### `AWS_ACCESS_KEY_ID`
|
|
136
143
|
|
|
137
144
|
- Type: Required
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.161.
|
|
3
|
+
"version": "0.161.16",
|
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
package/src/config/llm.ts
CHANGED
|
@@ -23,40 +23,6 @@ declare global {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const getLLMConfig = () => {
|
|
26
|
-
const AZURE_API_KEY = process.env.AZURE_API_KEY || '';
|
|
27
|
-
|
|
28
|
-
const ZHIPU_API_KEY = process.env.ZHIPU_API_KEY || '';
|
|
29
|
-
|
|
30
|
-
const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID || '';
|
|
31
|
-
|
|
32
|
-
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY || '';
|
|
33
|
-
|
|
34
|
-
const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY || '';
|
|
35
|
-
|
|
36
|
-
const MOONSHOT_API_KEY = process.env.MOONSHOT_API_KEY || '';
|
|
37
|
-
|
|
38
|
-
const PERPLEXITY_API_KEY = process.env.PERPLEXITY_API_KEY || '';
|
|
39
|
-
|
|
40
|
-
const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || '';
|
|
41
|
-
|
|
42
|
-
const MINIMAX_API_KEY = process.env.MINIMAX_API_KEY || '';
|
|
43
|
-
|
|
44
|
-
const MISTRAL_API_KEY = process.env.MISTRAL_API_KEY || '';
|
|
45
|
-
|
|
46
|
-
const GROQ_API_KEY = process.env.GROQ_API_KEY || '';
|
|
47
|
-
|
|
48
|
-
const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY || '';
|
|
49
|
-
|
|
50
|
-
const ZEROONE_API_KEY = process.env.ZEROONE_API_KEY || '';
|
|
51
|
-
|
|
52
|
-
const TOGETHERAI_API_KEY = process.env.TOGETHERAI_API_KEY || '';
|
|
53
|
-
|
|
54
|
-
// region format: iad1,sfo1
|
|
55
|
-
let regions: string[] = [];
|
|
56
|
-
if (process.env.OPENAI_FUNCTION_REGIONS) {
|
|
57
|
-
regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
26
|
if (process.env.CUSTOM_MODELS) {
|
|
61
27
|
console.warn(
|
|
62
28
|
'DEPRECATED: `CUSTOM_MODELS` is deprecated, please use `OPENAI_MODEL_LIST` instead, we will remove `CUSTOM_MODELS` in the LobeChat 1.0',
|
|
@@ -75,6 +41,16 @@ export const getLLMConfig = () => {
|
|
|
75
41
|
);
|
|
76
42
|
}
|
|
77
43
|
|
|
44
|
+
// region format: iad1,sfo1
|
|
45
|
+
let regions: string[] = [];
|
|
46
|
+
if (process.env.OPENAI_FUNCTION_REGIONS) {
|
|
47
|
+
regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log('AWS_REGION:', process.env.AWS_REGION);
|
|
51
|
+
console.log('AWS_ACCESS_KEY_ID:', process.env.AWS_ACCESS_KEY_ID);
|
|
52
|
+
console.log('AWS_SECRET_ACCESS_KEY:', process.env.AWS_SECRET_ACCESS_KEY);
|
|
53
|
+
|
|
78
54
|
return createEnv({
|
|
79
55
|
server: {
|
|
80
56
|
API_KEY_SELECT_MODE: z.string().optional(),
|
|
@@ -152,60 +128,60 @@ export const getLLMConfig = () => {
|
|
|
152
128
|
OPENAI_MODEL_LIST: process.env.OPENAI_MODEL_LIST || process.env.CUSTOM_MODELS,
|
|
153
129
|
OPENAI_FUNCTION_REGIONS: regions as any,
|
|
154
130
|
|
|
155
|
-
ENABLED_AZURE_OPENAI: !!AZURE_API_KEY,
|
|
156
|
-
AZURE_API_KEY,
|
|
131
|
+
ENABLED_AZURE_OPENAI: !!process.env.AZURE_API_KEY,
|
|
132
|
+
AZURE_API_KEY: process.env.AZURE_API_KEY,
|
|
157
133
|
AZURE_API_VERSION: process.env.AZURE_API_VERSION,
|
|
158
134
|
AZURE_ENDPOINT: process.env.AZURE_ENDPOINT,
|
|
159
135
|
AZURE_MODEL_LIST: process.env.AZURE_MODEL_LIST,
|
|
160
136
|
|
|
161
|
-
ENABLED_ZHIPU: !!ZHIPU_API_KEY,
|
|
162
|
-
ZHIPU_API_KEY,
|
|
137
|
+
ENABLED_ZHIPU: !!process.env.ZHIPU_API_KEY,
|
|
138
|
+
ZHIPU_API_KEY: process.env.ZHIPU_API_KEY,
|
|
163
139
|
|
|
164
|
-
ENABLED_DEEPSEEK: !!DEEPSEEK_API_KEY,
|
|
165
|
-
DEEPSEEK_API_KEY,
|
|
140
|
+
ENABLED_DEEPSEEK: !!process.env.DEEPSEEK_API_KEY,
|
|
141
|
+
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY,
|
|
166
142
|
|
|
167
|
-
ENABLED_GOOGLE: !!GOOGLE_API_KEY,
|
|
168
|
-
GOOGLE_API_KEY,
|
|
143
|
+
ENABLED_GOOGLE: !!process.env.GOOGLE_API_KEY,
|
|
144
|
+
GOOGLE_API_KEY: process.env.GOOGLE_API_KEY,
|
|
169
145
|
GOOGLE_PROXY_URL: process.env.GOOGLE_PROXY_URL,
|
|
170
146
|
|
|
171
|
-
ENABLED_PERPLEXITY: !!PERPLEXITY_API_KEY,
|
|
172
|
-
PERPLEXITY_API_KEY,
|
|
147
|
+
ENABLED_PERPLEXITY: !!process.env.PERPLEXITY_API_KEY,
|
|
148
|
+
PERPLEXITY_API_KEY: process.env.PERPLEXITY_API_KEY,
|
|
173
149
|
PERPLEXITY_PROXY_URL: process.env.PERPLEXITY_PROXY_URL,
|
|
174
150
|
|
|
175
|
-
ENABLED_ANTHROPIC: !!ANTHROPIC_API_KEY,
|
|
176
|
-
ANTHROPIC_API_KEY,
|
|
151
|
+
ENABLED_ANTHROPIC: !!process.env.ANTHROPIC_API_KEY,
|
|
152
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
177
153
|
ANTHROPIC_PROXY_URL: process.env.ANTHROPIC_PROXY_URL,
|
|
178
154
|
|
|
179
|
-
ENABLED_MINIMAX: !!MINIMAX_API_KEY,
|
|
180
|
-
MINIMAX_API_KEY,
|
|
155
|
+
ENABLED_MINIMAX: !!process.env.MINIMAX_API_KEY,
|
|
156
|
+
MINIMAX_API_KEY: process.env.MINIMAX_API_KEY,
|
|
181
157
|
|
|
182
|
-
ENABLED_MISTRAL: !!MISTRAL_API_KEY,
|
|
183
|
-
MISTRAL_API_KEY,
|
|
158
|
+
ENABLED_MISTRAL: !!process.env.MISTRAL_API_KEY,
|
|
159
|
+
MISTRAL_API_KEY: process.env.MISTRAL_API_KEY,
|
|
184
160
|
|
|
185
|
-
ENABLED_OPENROUTER: !!OPENROUTER_API_KEY,
|
|
186
|
-
OPENROUTER_API_KEY,
|
|
161
|
+
ENABLED_OPENROUTER: !!process.env.OPENROUTER_API_KEY,
|
|
162
|
+
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
|
|
187
163
|
OPENROUTER_MODEL_LIST:
|
|
188
164
|
process.env.OPENROUTER_MODEL_LIST || process.env.OPENROUTER_CUSTOM_MODELS,
|
|
189
165
|
|
|
190
|
-
ENABLED_TOGETHERAI: !!TOGETHERAI_API_KEY,
|
|
191
|
-
TOGETHERAI_API_KEY,
|
|
166
|
+
ENABLED_TOGETHERAI: !!process.env.TOGETHERAI_API_KEY,
|
|
167
|
+
TOGETHERAI_API_KEY: process.env.TOGETHERAI_API_KEY,
|
|
192
168
|
TOGETHERAI_MODEL_LIST: process.env.TOGETHERAI_MODEL_LIST,
|
|
193
169
|
|
|
194
|
-
ENABLED_MOONSHOT: !!MOONSHOT_API_KEY,
|
|
195
|
-
MOONSHOT_API_KEY,
|
|
170
|
+
ENABLED_MOONSHOT: !!process.env.MOONSHOT_API_KEY,
|
|
171
|
+
MOONSHOT_API_KEY: process.env.MOONSHOT_API_KEY,
|
|
196
172
|
MOONSHOT_PROXY_URL: process.env.MOONSHOT_PROXY_URL,
|
|
197
173
|
|
|
198
|
-
ENABLED_GROQ: !!GROQ_API_KEY,
|
|
174
|
+
ENABLED_GROQ: !!process.env.GROQ_API_KEY,
|
|
175
|
+
GROQ_API_KEY: process.env.GROQ_API_KEY,
|
|
199
176
|
GROQ_PROXY_URL: process.env.GROQ_PROXY_URL,
|
|
200
|
-
GROQ_API_KEY,
|
|
201
177
|
|
|
202
|
-
ENABLED_ZEROONE: !!ZEROONE_API_KEY,
|
|
203
|
-
ZEROONE_API_KEY,
|
|
178
|
+
ENABLED_ZEROONE: !!process.env.ZEROONE_API_KEY,
|
|
179
|
+
ZEROONE_API_KEY: process.env.ZEROONE_API_KEY,
|
|
204
180
|
|
|
205
|
-
ENABLED_AWS_BEDROCK:
|
|
181
|
+
ENABLED_AWS_BEDROCK: process.env.ENABLED_AWS_BEDROCK === '1',
|
|
206
182
|
AWS_REGION: process.env.AWS_REGION,
|
|
207
|
-
AWS_ACCESS_KEY_ID: AWS_ACCESS_KEY_ID,
|
|
208
|
-
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY
|
|
183
|
+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
|
|
184
|
+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
|
|
209
185
|
|
|
210
186
|
ENABLED_OLLAMA: process.env.ENABLED_OLLAMA !== '0',
|
|
211
187
|
OLLAMA_PROXY_URL: process.env.OLLAMA_PROXY_URL || '',
|
|
@@ -6,6 +6,8 @@ import { SessionGroups } from '@/types/session';
|
|
|
6
6
|
import { DB_SessionGroup } from '../../schemas/sessionGroup';
|
|
7
7
|
import { SessionGroupModel } from '../sessionGroup';
|
|
8
8
|
|
|
9
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
|
|
9
11
|
describe('SessionGroupModel', () => {
|
|
10
12
|
let sessionGroupData: DB_SessionGroup;
|
|
11
13
|
|
|
@@ -135,9 +137,14 @@ describe('SessionGroupModel', () => {
|
|
|
135
137
|
|
|
136
138
|
it('should return session groups sorted by sort field first and then by createdAt', async () => {
|
|
137
139
|
const group0 = await SessionGroupModel.create('group0');
|
|
140
|
+
await sleep(10);
|
|
138
141
|
const group1 = await SessionGroupModel.create('group1', 1);
|
|
142
|
+
await sleep(10);
|
|
139
143
|
const group2 = await SessionGroupModel.create('group2');
|
|
144
|
+
await sleep(10);
|
|
140
145
|
const group3 = await SessionGroupModel.create('group3', 2);
|
|
146
|
+
await sleep(10);
|
|
147
|
+
|
|
141
148
|
const fetchedGroups = await SessionGroupModel.query();
|
|
142
149
|
expect(fetchedGroups[0].id).toEqual(group1.id);
|
|
143
150
|
expect(fetchedGroups[1].id).toEqual(group3.id);
|
package/src/hooks/useSyncData.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { useChatStore } from '@/store/chat';
|
|
|
4
4
|
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
|
|
5
5
|
import { useSessionStore } from '@/store/session';
|
|
6
6
|
import { useUserStore } from '@/store/user';
|
|
7
|
-
import { syncSettingsSelectors } from '@/store/user/selectors';
|
|
7
|
+
import { syncSettingsSelectors, userProfileSelectors } from '@/store/user/selectors';
|
|
8
8
|
|
|
9
9
|
export const useSyncEvent = () => {
|
|
10
10
|
const [refreshMessages, refreshTopic] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]);
|
|
@@ -38,7 +38,7 @@ export const useSyncEvent = () => {
|
|
|
38
38
|
|
|
39
39
|
export const useEnabledDataSync = () => {
|
|
40
40
|
const [userId, userEnableSync, useEnabledSync] = useUserStore((s) => [
|
|
41
|
-
|
|
41
|
+
userProfileSelectors.userId(s),
|
|
42
42
|
syncSettingsSelectors.enableWebRTC(s),
|
|
43
43
|
s.useEnabledSync,
|
|
44
44
|
]);
|
|
@@ -27,7 +27,6 @@ const UserUpdater = memo(() => {
|
|
|
27
27
|
useStoreUpdater('isLoaded', isLoaded);
|
|
28
28
|
useStoreUpdater('user', lobeUser);
|
|
29
29
|
useStoreUpdater('isSignedIn', isSignedIn);
|
|
30
|
-
useStoreUpdater('userId', user?.id);
|
|
31
30
|
|
|
32
31
|
useStoreUpdater('clerkUser', user);
|
|
33
32
|
useStoreUpdater('clerkSession', session);
|
|
@@ -10,11 +10,6 @@ import {
|
|
|
10
10
|
import { LobeUser } from '@/types/user';
|
|
11
11
|
|
|
12
12
|
export interface UserAuthState {
|
|
13
|
-
/**
|
|
14
|
-
* 未来收到 user.avatar 中
|
|
15
|
-
* @deprecated
|
|
16
|
-
*/
|
|
17
|
-
avatar?: string;
|
|
18
13
|
clerkOpenUserProfile?: (props?: UserProfileProps) => void;
|
|
19
14
|
|
|
20
15
|
clerkSession?: ActiveSessionResource;
|
|
@@ -28,7 +23,6 @@ export interface UserAuthState {
|
|
|
28
23
|
nextSession?: Session;
|
|
29
24
|
nextUser?: User;
|
|
30
25
|
user?: LobeUser;
|
|
31
|
-
userId?: string;
|
|
32
26
|
}
|
|
33
27
|
|
|
34
28
|
export const initialAuthState: UserAuthState = {};
|
|
@@ -24,8 +24,8 @@ const username = (s: UserStore) => {
|
|
|
24
24
|
|
|
25
25
|
export const userProfileSelectors = {
|
|
26
26
|
nickName,
|
|
27
|
-
userAvatar: (s: UserStore): string => s.user?.avatar ||
|
|
28
|
-
userId: (s: UserStore) => s.
|
|
27
|
+
userAvatar: (s: UserStore): string => s.user?.avatar || '',
|
|
28
|
+
userId: (s: UserStore) => s.user?.id,
|
|
29
29
|
userProfile: (s: UserStore): LobeUser | null | undefined => s.user,
|
|
30
30
|
username,
|
|
31
31
|
};
|
|
@@ -105,7 +105,7 @@ describe('createCommonSlice', () => {
|
|
|
105
105
|
await waitFor(() => expect(result.current.data).toEqual(mockUserState));
|
|
106
106
|
|
|
107
107
|
// 验证状态是否正确更新
|
|
108
|
-
expect(useUserStore.getState().avatar).toBe(mockUserState.avatar);
|
|
108
|
+
expect(useUserStore.getState().user?.avatar).toBe(mockUserState.avatar);
|
|
109
109
|
expect(useUserStore.getState().settings).toEqual(mockUserState.settings);
|
|
110
110
|
expect(successCallback).toHaveBeenCalledWith(mockUserState);
|
|
111
111
|
|
|
@@ -183,13 +183,14 @@ describe('createCommonSlice', () => {
|
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
it('should handle the case when user
|
|
186
|
+
it('should handle the case when user state have avatar', async () => {
|
|
187
187
|
const { result } = renderHook(() => useUserStore());
|
|
188
188
|
const mockUserState: UserInitializationState = {
|
|
189
189
|
userId: 'user-id',
|
|
190
190
|
isOnboard: true,
|
|
191
191
|
preference: undefined as any,
|
|
192
192
|
settings: null as any,
|
|
193
|
+
avatar: 'abc',
|
|
193
194
|
};
|
|
194
195
|
|
|
195
196
|
vi.spyOn(userService, 'getUserState').mockResolvedValueOnce(mockUserState);
|
|
@@ -202,7 +203,7 @@ describe('createCommonSlice', () => {
|
|
|
202
203
|
await waitFor(() => {
|
|
203
204
|
expect(result.current.isUserStateInit).toBeTruthy();
|
|
204
205
|
// 验证状态未被错误更新
|
|
205
|
-
expect(result.current.avatar).
|
|
206
|
+
expect(result.current.user?.avatar).toEqual('abc');
|
|
206
207
|
expect(result.current.settings).toEqual({});
|
|
207
208
|
});
|
|
208
209
|
});
|
|
@@ -88,6 +88,12 @@ export const createCommonSlice: StateCreator<
|
|
|
88
88
|
const isEmpty = Object.keys(data.preference || {}).length === 0;
|
|
89
89
|
const preference = isEmpty ? DEFAULT_PREFERENCE : data.preference;
|
|
90
90
|
|
|
91
|
+
// if there is avatar or userId (from client DB), update it into user
|
|
92
|
+
const user =
|
|
93
|
+
data.avatar || data.userId
|
|
94
|
+
? merge(get().user, { avatar: data.avatar, id: data.userId })
|
|
95
|
+
: get().user;
|
|
96
|
+
|
|
91
97
|
set(
|
|
92
98
|
{
|
|
93
99
|
defaultSettings,
|
|
@@ -97,11 +103,10 @@ export const createCommonSlice: StateCreator<
|
|
|
97
103
|
isUserCanEnableTrace: data.canEnableTrace,
|
|
98
104
|
isUserHasConversation: data.hasConversation,
|
|
99
105
|
isUserStateInit: true,
|
|
100
|
-
|
|
101
106
|
preference,
|
|
102
107
|
serverLanguageModel: serverConfig.languageModel,
|
|
103
108
|
settings: data.settings || {},
|
|
104
|
-
|
|
109
|
+
user,
|
|
105
110
|
},
|
|
106
111
|
false,
|
|
107
112
|
n('initUserState'),
|
package/src/types/user/index.ts
CHANGED