@lobehub/chat 0.122.2 → 0.122.3

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +8 -8
  3. package/README.zh-CN.md +8 -8
  4. package/docs/Deployment/Docker-Deployment.md +118 -0
  5. package/docs/Deployment/Docker-Deployment.zh-CN.md +118 -0
  6. package/package.json +1 -4
  7. package/src/app/api/config/route.ts +3 -1
  8. package/src/app/chat/(mobile)/features/SessionHeader.tsx +2 -1
  9. package/src/app/chat/features/ChatHeader/ShareButton/ShareModal.tsx +2 -1
  10. package/src/app/chat/settings/features/SubmitAgentButton/SubmitAgentModal.tsx +2 -1
  11. package/src/app/settings/(mobile)/mobile/index.tsx +2 -1
  12. package/src/app/settings/common/Common.tsx +14 -3
  13. package/src/app/settings/features/ThemeSwatches/ThemeSwatchesNeutral.tsx +2 -1
  14. package/src/app/settings/features/ThemeSwatches/ThemeSwatchesPrimary.tsx +2 -1
  15. package/src/app/settings/llm/LLM/index.tsx +17 -10
  16. package/src/const/settings.ts +0 -1
  17. package/src/database/core/db.ts +41 -2
  18. package/src/database/core/migrations/migrateSettingsToUser/fixtures/input.json +55 -0
  19. package/src/database/core/migrations/migrateSettingsToUser/fixtures/output.json +60 -0
  20. package/src/database/core/migrations/migrateSettingsToUser/index.test.ts +13 -0
  21. package/src/database/core/migrations/migrateSettingsToUser/index.ts +39 -0
  22. package/src/database/core/schemas.ts +10 -0
  23. package/src/database/models/user.ts +54 -0
  24. package/src/database/schemas/user.ts +57 -0
  25. package/src/features/AgentSetting/AgentConfig/index.tsx +2 -2
  26. package/src/features/AvatarWithUpload/index.tsx +6 -2
  27. package/src/features/ChatInput/ActionBar/ModelSwitch.tsx +2 -2
  28. package/src/features/Conversation/Error/ApiKeyForm.tsx +3 -3
  29. package/src/features/Conversation/Error/InvalidAccess.tsx +5 -1
  30. package/src/features/Conversation/Extras/Translate.tsx +3 -4
  31. package/src/layout/GlobalLayout/AppTheme.tsx +4 -3
  32. package/src/layout/GlobalLayout/Locale.tsx +2 -1
  33. package/src/layout/GlobalLayout/StoreHydration.tsx +7 -2
  34. package/src/services/_header.ts +3 -2
  35. package/src/services/user.ts +31 -0
  36. package/src/store/chat/slices/message/selectors.test.ts +7 -2
  37. package/src/store/chat/slices/message/selectors.ts +2 -1
  38. package/src/store/global/hooks/index.ts +0 -1
  39. package/src/store/global/initialState.ts +3 -1
  40. package/src/store/global/selectors.ts +1 -0
  41. package/src/store/global/slices/common/action.test.ts +2 -79
  42. package/src/store/global/slices/common/action.ts +37 -61
  43. package/src/store/global/slices/common/initialState.ts +0 -34
  44. package/src/store/global/slices/common/selectors.ts +2 -7
  45. package/src/store/global/slices/preference/action.test.ts +92 -0
  46. package/src/store/global/slices/preference/action.ts +75 -0
  47. package/src/store/global/slices/preference/initialState.ts +45 -0
  48. package/src/store/global/slices/preference/selectors.ts +10 -0
  49. package/src/store/global/slices/settings/action.test.ts +68 -39
  50. package/src/store/global/slices/settings/action.ts +26 -50
  51. package/src/store/global/slices/settings/initialState.ts +8 -6
  52. package/src/store/global/slices/settings/selectors/__snapshots__/modelProvider.test.ts.snap +100 -0
  53. package/src/store/global/slices/settings/selectors/__snapshots__/selectors.test.ts.snap +132 -0
  54. package/src/store/global/slices/settings/selectors/index.ts +2 -0
  55. package/src/store/global/slices/settings/selectors/modelProvider.test.ts +100 -0
  56. package/src/store/global/slices/settings/selectors/modelProvider.ts +64 -0
  57. package/src/store/global/slices/settings/{selectors.test.ts → selectors/selectors.test.ts} +2 -97
  58. package/src/store/global/slices/settings/selectors/settings.ts +58 -0
  59. package/src/store/global/store.ts +11 -36
  60. package/src/store/session/slices/agent/action.ts +1 -1
  61. package/src/types/settings/base.ts +13 -0
  62. package/src/types/settings/index.ts +34 -0
  63. package/src/types/settings/modelProvider.ts +17 -0
  64. package/src/types/settings/tts.ts +10 -0
  65. package/src/utils/difference.ts +12 -0
  66. package/tests/utils.tsx +8 -0
  67. package/tsconfig.json +9 -8
  68. package/vitest.config.ts +1 -0
  69. package/src/store/global/hooks/useHydrated.ts +0 -18
  70. package/src/store/global/slices/settings/selectors.ts +0 -105
  71. package/src/types/settings.ts +0 -68
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.122.3](https://github.com/lobehub/lobe-chat/compare/v0.122.2...v0.122.3)
6
+
7
+ <sup>Released on **2024-01-30**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor the setting storage from localStorage to indexedDB.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor the setting storage from localStorage to indexedDB, closes [#1180](https://github.com/lobehub/lobe-chat/issues/1180) ([615e796](https://github.com/lobehub/lobe-chat/commit/615e796))
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.122.2](https://github.com/lobehub/lobe-chat/compare/v0.122.1...v0.122.2)
6
31
 
7
32
  <sup>Released on **2024-01-30**</sup>
package/README.md CHANGED
@@ -225,14 +225,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
225
225
 
226
226
  <!-- AGENT LIST -->
227
227
 
228
- | Recent Submits | Description |
229
- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
230
- | [Territory Promotion Strategist](https://chat-preview.lobehub.com/market?agent=biskaya)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | Territorial Competitiveness and Promotion Expert<br/>`territorial-competitiveness` `promotion` `consulting` `marketing` `event-coordination` |
231
- | [Bizkaia Entrepreneurship Expert](https://chat-preview.lobehub.com/market?agent=bizkaia-entrepreneurship-expert)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | Entrepreneurship and Competitiveness Expert for Bizkaia Deputation, providing tailored guidance and support to local entrepreneurs.<br/>`bizkaia` `entrepreneurship` `consulting` `mentorship` `local-business-ecosystem` `market-dynamics` `business-plans` `financial-models` `funding-strategies` `marketing` `branding` `sales-strategies` `networking` `entrepreneurship-programs` `guidance` `local-resources` `funding-opportunities` `collaboration` `sustainable-business-practices` `economic-development` |
232
- | [English Language C1 Mastery Coach](https://chat-preview.lobehub.com/market?agent=english-language-c-1-mastery-coach)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | English Conversation Partner for C1 Level<br/>`english-conversation` `language-proficiency` `advanced-level` `language-coaching` `fluency` |
233
- | [Software Architecture Strategist](https://chat-preview.lobehub.com/market?agent=software-architecture-strategist)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | Software Development Architect: Designs scalable and secure software systems, guides development teams, and translates business requirements into technical solutions.<br/>`software-development` `architecture` `design` `leadership` `communication` |
234
-
235
- > 📊 Total agents: [<kbd>**139**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
228
+ | Recent Submits | Description |
229
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
230
+ | [English Proficiency Coach](https://chat-preview.lobehub.com/market?agent=english-c-2-level)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | C2 Level English Conversation Partner<br/>`english-proficiency` `conversation-partner` `language-coaching` |
231
+ | [Entrepreneurship and Competitiveness Expert](https://chat-preview.lobehub.com/market?agent=entrepreneurship-and-competitiveness-expert)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | Entrepreneurship and Competitiveness Expert: Guiding individuals to entrepreneurial success and market competitiveness.<br/>`entrepreneurship` `competitiveness` `consulting` `mentoring` `advising` |
232
+ | [Mathematical Research Advisor](https://chat-preview.lobehub.com/market?agent=mathematical-research-advisor)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | Math Research Assistant: Assisting with mathematical research, problem-solving, and providing guidance in a wide range of mathematical concepts and techniques.<br/>`mathematics` `research` `assistance` `problem-solving` `communication` |
233
+ | [Territory Promotion Strategist](https://chat-preview.lobehub.com/market?agent=biskaya)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | Territorial Competitiveness and Promotion Expert<br/>`territorial-competitiveness` `promotion` `consulting` `marketing` `event-coordination` |
234
+
235
+ > 📊 Total agents: [<kbd>**142**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
236
236
 
237
237
  <!-- AGENT LIST -->
238
238
 
package/README.zh-CN.md CHANGED
@@ -205,14 +205,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
205
205
 
206
206
  <!-- AGENT LIST -->
207
207
 
208
- | 最近新增 | 助手说明 |
209
- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
210
- | [领土推广策略师](https://chat-preview.lobehub.com/market?agent=biskaya)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | 领土竞争力和推广专家<br/>`territorial-competitiveness` `promotion` `consulting` `marketing` `event-coordination` |
211
- | [毕尔巴鄂创业专家](https://chat-preview.lobehub.com/market?agent=bizkaia-entrepreneurship-expert)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | 毕尔巴鄂代表处的创业和竞争力专家,为当地企业家提供定制指导和支持。<br/>`毕尔巴鄂` `创业` `咨询` `指导` `本地商业生态系统` `市场动态` `商业计划` `财务模型` `融资策略` `营销` `品牌塑造` `销售策略` `社交网络` `创业项目` `指导` `本地资源` `融资机会` `合作` `可持续商业实践` `经济发展` |
212
- | [英语 C1 级精通教练](https://chat-preview.lobehub.com/market?agent=english-language-c-1-mastery-coach)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | C1 级别的英语会话伙伴<br/>`英语会话` `语言熟练度` `高级水平` `语言辅导` `流利度` |
213
- | [软件架构策略师](https://chat-preview.lobehub.com/market?agent=software-architecture-strategist)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | 软件开发架构师:设计可扩展和安全的软件系统,指导开发团队,并将业务需求转化为技术解决方案。<br/>`软件开发` `架构` `设计` `领导力` `沟通` |
214
-
215
- > 📊 Total agents: [<kbd>**139**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
208
+ | 最近新增 | 助手说明 |
209
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
210
+ | [英语熟练度教练](https://chat-preview.lobehub.com/market?agent=english-c-2-level)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | C2 级别英语会话伙伴<br/>`英语熟练度` `会话伙伴` `语言辅导` |
211
+ | [创业和竞争力专家](https://chat-preview.lobehub.com/market?agent=entrepreneurship-and-competitiveness-expert)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | 创业和竞争力专家:指导个人实现创业成功和市场竞争力。<br/>`创业` `竞争力` `咨询` `指导` `建议` |
212
+ | [数学研究顾问](https://chat-preview.lobehub.com/market?agent=mathematical-research-advisor)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-30**</sup> | 数学研究助理:协助进行数学研究、解决问题,并在各种数学概念和技术方面提供指导。<br/>`数学` `研究` `协助` `问题解决` `沟通` |
213
+ | [领土推广策略师](https://chat-preview.lobehub.com/market?agent=biskaya)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-01-29**</sup> | 领土竞争力和推广专家<br/>`territorial-competitiveness` `promotion` `consulting` `marketing` `event-coordination` |
214
+
215
+ > 📊 Total agents: [<kbd>**142**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
216
216
 
217
217
  <!-- AGENT LIST -->
218
218
 
@@ -71,6 +71,69 @@ $ docker run -d -p 3210:3210 \
71
71
  >
72
72
  > As the official Docker image build takes about half an hour, if there is a "update available" prompt after updating deployment, wait for the image to finish building before deploying again.
73
73
 
74
+ #### Crontab Auto-Update Script
75
+
76
+ If you want to automatically get the latest images, you can do the following.
77
+
78
+ First, create a `lobe.env` configuration file with various environment variables, for example:
79
+
80
+ ```env
81
+ OPENAI_API_KEY=sk-xxxx
82
+ OPENAI_PROXY_URL=https://api-proxy.com/v1
83
+ ACCESS_CODE=arthals2333
84
+ CUSTOM_MODELS=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-1106-preview=gpt-4-turbo,gpt-4-vision-preview=gpt-4-vision
85
+ ```
86
+
87
+ Then, you can use the following script to automatically update:
88
+
89
+ ```bash
90
+ #!/bin/bash
91
+ # auto-update-lobe-chat.sh
92
+
93
+ # Set proxy (optional)
94
+ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
95
+
96
+ # Pull the latest image and store the output in a variable
97
+ output=$(docker pull lobehub/lobe-chat:latest 2>&1)
98
+
99
+ # Check if the pull command executed successfully
100
+ if [ $? -ne 0 ]; then
101
+ exit 1
102
+ fi
103
+
104
+ # Check if the output contains a specific string
105
+ echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"
106
+
107
+ # If the image is already up to date, then do nothing
108
+ if [ $? -eq 0 ]; then
109
+ exit 0
110
+ fi
111
+
112
+ echo "Detected Lobe-Chat update"
113
+
114
+ # Remove old container
115
+ echo "Removed: $(docker rm -f Lobe-Chat)"
116
+
117
+ # Run new container
118
+ echo "Started: $(docker run -d --network=host --env-file /path/to/lobe.env --name=Lobe-Chat --restart=always lobehub/lobe-chat)"
119
+
120
+ # Print the update time and version
121
+ echo "Update time: $(date)"
122
+ echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"
123
+
124
+ # Clean up unused images
125
+ docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
126
+ echo "Removed old images."
127
+ ```
128
+
129
+ This script can be used in Crontab, but make sure your Crontab can find the correct Docker command. It's recommended to use absolute paths.
130
+
131
+ Configure Crontab to execute the script every 5 minutes:
132
+
133
+ ```bash
134
+ */5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
135
+ ```
136
+
74
137
  ### `B` Docker Compose
75
138
 
76
139
  The configuration file for using `docker-compose` is as follows:
@@ -91,6 +154,61 @@ services:
91
154
  ACCESS_CODE: lobe66
92
155
  ```
93
156
 
157
+ #### Crontab Auto-Update Script
158
+
159
+ Similarly, you can use the following script to update Lobe Chat automatically. When using `Docker Compose`, environment variables do not need additional configuration.
160
+
161
+ ```bash
162
+ #!/bin/bash
163
+ # auto-update-lobe-chat.sh
164
+
165
+ # Set proxy (optional)
166
+ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
167
+
168
+ # Pull the latest image and store the output in a variable
169
+ output=$(docker pull lobehub/lobe-chat:latest 2>&1)
170
+
171
+ # Check if the pull command executed successfully
172
+ if [ $? -ne 0 ]; then
173
+ exit 1
174
+ fi
175
+
176
+ # Check if the output contains a specific string
177
+ echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"
178
+
179
+ # If the image is already up to date, then do nothing
180
+ if [ $? -eq 0 ]; then
181
+ exit 0
182
+ fi
183
+
184
+ echo "Detected Lobe-Chat update"
185
+
186
+ # Remove old container
187
+ echo "Removed: $(docker rm -f Lobe-Chat)"
188
+
189
+ # Maybe you need to enter the directory where `docker-compose.yml` is located first
190
+ # cd /path/to/docker-compose-folder
191
+
192
+ # Run new container
193
+ echo "Started: $(docker-compose up)"
194
+
195
+ # Print the update time and version
196
+ echo "Update time: $(date)"
197
+ echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"
198
+
199
+ # Clean up unused images
200
+ docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
201
+ echo "Removed old images."
202
+ ```
203
+
204
+ This script can also be used in Crontab, but make sure your Crontab can find the correct Docker command. It's recommended to use absolute paths.
205
+
206
+ Configure Crontab to execute the script every 5 minutes:
207
+
208
+ ```bash
209
+ */5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
210
+ ```
211
+
94
212
  <!-- LINK GROUP -->
95
213
 
96
214
  [docker-pulls-link]: https://hub.docker.com/r/lobehub/lobe-chat
@@ -71,6 +71,69 @@ $ docker run -d -p 3210:3210 \
71
71
  >
72
72
  > 由于官方的 Docker 镜像构建大约需要半小时左右,如果在更新部署后会出现「存在更新」的提示,可以等待镜像构建完成后再次部署。
73
73
 
74
+ #### Crontab 自动更新脚本
75
+
76
+ 如果你想自动获得最新的镜像,你可以如下操作。
77
+
78
+ 首先,新建一个 `lobe.env` 配置文件,内容为各种环境变量,例如:
79
+
80
+ ```env
81
+ OPENAI_API_KEY=sk-xxxx
82
+ OPENAI_PROXY_URL=https://api-proxy.com/v1
83
+ ACCESS_CODE=arthals2333
84
+ CUSTOM_MODELS=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-1106-preview=gpt-4-turbo,gpt-4-vision-preview=gpt-4-vision
85
+ ```
86
+
87
+ 然后,你可以使用以下脚本来自动更新:
88
+
89
+ ```bash
90
+ #!/bin/bash
91
+ # auto-update-lobe-chat.sh
92
+
93
+ # 设置代理(可选)
94
+ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
95
+
96
+ # 拉取最新的镜像并将输出存储在变量中
97
+ output=$(docker pull lobehub/lobe-chat:latest 2>&1)
98
+
99
+ # 检查拉取命令是否成功执行
100
+ if [ $? -ne 0 ]; then
101
+ exit 1
102
+ fi
103
+
104
+ # 检查输出中是否包含特定的字符串
105
+ echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"
106
+
107
+ # 如果镜像已经是最新的,则不执行任何操作
108
+ if [ $? -eq 0 ]; then
109
+ exit 0
110
+ fi
111
+
112
+ echo "Detected Lobe-Chat update"
113
+
114
+ # 删除旧的容器
115
+ echo "Removed: $(docker rm -f Lobe-Chat)"
116
+
117
+ # 运行新的容器
118
+ echo "Started: $(docker run -d --network=host --env-file /path/to/lobe.env --name=Lobe-Chat --restart=always lobehub/lobe-chat)"
119
+
120
+ # 打印更新的时间和版本
121
+ echo "Update time: $(date)"
122
+ echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"
123
+
124
+ # 清理不再使用的镜像
125
+ docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
126
+ echo "Removed old images."
127
+ ```
128
+
129
+ 此脚本可以在 Crontab 中使用,但请确认你的 Crontab 可以找到正确的 Docker 命令。建议使用绝对路径。
130
+
131
+ 配置 Crontab,每 5 分钟执行一次脚本:
132
+
133
+ ```bash
134
+ */5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
135
+ ```
136
+
74
137
  ### `B` Docker Compose
75
138
 
76
139
  使用 `docker-compose` 时配置文件如下:
@@ -91,6 +154,61 @@ services:
91
154
  ACCESS_CODE: lobe66
92
155
  ```
93
156
 
157
+ #### Crontab 自动更新脚本
158
+
159
+ 类似地,你可以使用以下脚本来自动更新 Lobe Chat,使用 `Docker Compose` 时,环境变量无需额外配置。
160
+
161
+ ```bash
162
+ #!/bin/bash
163
+ # auto-update-lobe-chat.sh
164
+
165
+ # 设置代理(可选)
166
+ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
167
+
168
+ # 拉取最新的镜像并将输出存储在变量中
169
+ output=$(docker pull lobehub/lobe-chat:latest 2>&1)
170
+
171
+ # 检查拉取命令是否成功执行
172
+ if [ $? -ne 0 ]; then
173
+ exit 1
174
+ fi
175
+
176
+ # 检查输出中是否包含特定的字符串
177
+ echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"
178
+
179
+ # 如果镜像已经是最新的,则不执行任何操作
180
+ if [ $? -eq 0 ]; then
181
+ exit 0
182
+ fi
183
+
184
+ echo "Detected Lobe-Chat update"
185
+
186
+ # 删除旧的容器
187
+ echo "Removed: $(docker rm -f Lobe-Chat)"
188
+
189
+ # 也许需要先进入 `docker-compose.yml` 所在的目录
190
+ # cd /path/to/docker-compose-folder
191
+
192
+ # 运行新的容器
193
+ echo "Started: $(docker-compose up)"
194
+
195
+ # 打印更新的时间和版本
196
+ echo "Update time: $(date)"
197
+ echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"
198
+
199
+ # 清理不再使用的镜像
200
+ docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
201
+ echo "Removed old images."
202
+ ```
203
+
204
+ 此脚本亦可以在 Crontab 中使用,但请确认你的 Crontab 可以找到正确的 Docker 命令。建议使用绝对路径。
205
+
206
+ 配置 Crontab,每 5 分钟执行一次脚本:
207
+
208
+ ```bash
209
+ */5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
210
+ ```
211
+
94
212
  [docker-pulls-link]: https://hub.docker.com/r/lobehub/lobe-chat
95
213
  [docker-pulls-shield]: https://img.shields.io/docker/pulls/lobehub/lobe-chat?color=45cc11&labelColor=black&style=flat-square
96
214
  [docker-release-link]: https://hub.docker.com/r/lobehub/lobe-chat
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.122.2",
3
+ "version": "0.122.3",
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",
@@ -86,14 +86,12 @@
86
86
  "antd-style": "^3",
87
87
  "brotli-wasm": "^2",
88
88
  "chroma-js": "^2",
89
- "copy-to-clipboard": "^3",
90
89
  "dayjs": "^1",
91
90
  "dexie": "^3",
92
91
  "fast-deep-equal": "^3",
93
92
  "gpt-tokenizer": "^2",
94
93
  "i18next": "^23",
95
94
  "i18next-browser-languagedetector": "^7",
96
- "i18next-resources-for-ts": "^1",
97
95
  "i18next-resources-to-backend": "^1",
98
96
  "idb-keyval": "^6",
99
97
  "immer": "^10",
@@ -111,7 +109,6 @@
111
109
  "react-dom": "^18",
112
110
  "react-hotkeys-hook": "^4",
113
111
  "react-i18next": "^14",
114
- "react-intersection-observer": "^9",
115
112
  "react-layout-kit": "^1",
116
113
  "react-lazy-load": "^4",
117
114
  "react-virtuoso": "^4.6.2",
@@ -9,7 +9,9 @@ export const runtime = 'edge';
9
9
  export const GET = async () => {
10
10
  const { CUSTOM_MODELS } = getServerConfig();
11
11
 
12
- const config: GlobalServerConfig = { customModelName: CUSTOM_MODELS };
12
+ const config: GlobalServerConfig = {
13
+ customModelName: CUSTOM_MODELS,
14
+ };
13
15
 
14
16
  return new Response(JSON.stringify(config));
15
17
  };
@@ -6,6 +6,7 @@ import { memo } from 'react';
6
6
 
7
7
  import { MOBILE_HEADER_ICON_SIZE } from '@/const/layoutTokens';
8
8
  import { useGlobalStore } from '@/store/global';
9
+ import { commonSelectors } from '@/store/global/selectors';
9
10
  import { useSessionStore } from '@/store/session';
10
11
 
11
12
  export const useStyles = createStyles(({ css, token }) => ({
@@ -21,7 +22,7 @@ export const useStyles = createStyles(({ css, token }) => ({
21
22
  const Header = memo(() => {
22
23
  const [createSession] = useSessionStore((s) => [s.createSession]);
23
24
  const router = useRouter();
24
- const avatar = useGlobalStore((st) => st.settings.avatar);
25
+ const avatar = useGlobalStore(commonSelectors.userAvatar);
25
26
  return (
26
27
  <MobileNavBar
27
28
  center={<Logo type={'text'} />}
@@ -7,6 +7,7 @@ import { Flexbox } from 'react-layout-kit';
7
7
  import { FORM_STYLE } from '@/const/layoutTokens';
8
8
  import { useChatStore } from '@/store/chat';
9
9
  import { useGlobalStore } from '@/store/global';
10
+ import { commonSelectors } from '@/store/global/selectors';
10
11
 
11
12
  import Preview from './Preview';
12
13
  import { FieldType, ImageType } from './type';
@@ -48,7 +49,7 @@ const ShareModal = memo<ModalProps>(({ onCancel, open }) => {
48
49
  const [fieldValue, setFieldValue] = useState<FieldType>(DEFAULT_FIELD_VALUE);
49
50
  const [tab, setTab] = useState<Tab>(Tab.Screenshot);
50
51
  const { t } = useTranslation('chat');
51
- const avatar = useGlobalStore((s) => s.settings.avatar);
52
+ const avatar = useGlobalStore(commonSelectors.userAvatar);
52
53
  const [shareLoading, shareToShareGPT] = useChatStore((s) => [s.shareLoading, s.shareToShareGPT]);
53
54
  const { loading, onDownload, title } = useScreenshot(fieldValue.imageType);
54
55
 
@@ -11,6 +11,7 @@ import { Flexbox } from 'react-layout-kit';
11
11
  import { AGENTS_INDEX_GITHUB_ISSUE } from '@/const/url';
12
12
  import AgentInfo from '@/features/AgentInfo';
13
13
  import { useGlobalStore } from '@/store/global';
14
+ import { settingsSelectors } from '@/store/global/selectors';
14
15
  import { useSessionStore } from '@/store/session';
15
16
  import { agentSelectors } from '@/store/session/selectors';
16
17
 
@@ -20,7 +21,7 @@ const SubmitAgentModal = memo<ModalProps>(({ open, onCancel }) => {
20
21
  const systemRole = useSessionStore(agentSelectors.currentAgentSystemRole);
21
22
  const theme = useTheme();
22
23
  const meta = useSessionStore(agentSelectors.currentAgentMeta, isEqual);
23
- const language = useGlobalStore((s) => s.settings.language);
24
+ const language = useGlobalStore((s) => settingsSelectors.currentSettings(s).language);
24
25
 
25
26
  const isMetaPass = Boolean(
26
27
  meta && meta.title && meta.description && (meta.tags as string[])?.length > 0 && meta.avatar,
@@ -9,6 +9,7 @@ import { CURRENT_VERSION } from '@/const/version';
9
9
  import AvatarWithUpload from '@/features/AvatarWithUpload';
10
10
  import { useGlobalStore, useSwitchSideBarOnInit } from '@/store/global';
11
11
  import { SidebarTabKey } from '@/store/global/initialState';
12
+ import { commonSelectors } from '@/store/global/selectors';
12
13
 
13
14
  import List from '../../features/SideBar/List';
14
15
  import AvatarBanner from '../features/AvatarBanner';
@@ -28,7 +29,7 @@ const useStyles = createStyles(({ css, token }) => ({
28
29
 
29
30
  const Setting = memo(() => {
30
31
  useSwitchSideBarOnInit(SidebarTabKey.Setting);
31
- const avatar = useGlobalStore((s) => s.settings.avatar);
32
+ const avatar = useGlobalStore(commonSelectors.userAvatar);
32
33
  const { styles } = useStyles();
33
34
 
34
35
  return (
@@ -1,9 +1,8 @@
1
1
  import { Form, type ItemGroup, SelectWithImg, SliderWithInput } from '@lobehub/ui';
2
2
  import { Form as AntForm, App, Button, Input, Select } from 'antd';
3
3
  import isEqual from 'fast-deep-equal';
4
- import { debounce } from 'lodash-es';
5
4
  import { AppWindow, Monitor, Moon, Palette, Sun } from 'lucide-react';
6
- import { memo, useCallback } from 'react';
5
+ import { memo, useCallback, useEffect } from 'react';
7
6
  import { useTranslation } from 'react-i18next';
8
7
 
9
8
  import { FORM_STYLE } from '@/const/layoutTokens';
@@ -222,12 +221,24 @@ const Common = memo<SettingsCommonProps>(({ showAccessCodeConfig }) => {
222
221
  title: t('settingSystem.title'),
223
222
  };
224
223
 
224
+ useEffect(() => {
225
+ const unsubscribe = useGlobalStore.subscribe(
226
+ (s) => s.settings,
227
+ (settings) => {
228
+ form.setFieldsValue(settings);
229
+ },
230
+ );
231
+ return () => {
232
+ unsubscribe();
233
+ };
234
+ }, []);
235
+
225
236
  return (
226
237
  <Form
227
238
  form={form}
228
239
  initialValues={settings}
229
240
  items={[theme, system]}
230
- onValuesChange={debounce(setSettings, 100)}
241
+ onValuesChange={setSettings}
231
242
  {...FORM_STYLE}
232
243
  />
233
244
  );
@@ -8,10 +8,11 @@ import {
8
8
  import { memo } from 'react';
9
9
 
10
10
  import { useGlobalStore } from '@/store/global';
11
+ import { settingsSelectors } from '@/store/global/selectors';
11
12
 
12
13
  const ThemeSwatchesNeutral = memo(() => {
13
14
  const [neutralColor, setSettings] = useGlobalStore((s) => [
14
- s.settings.neutralColor,
15
+ settingsSelectors.currentSettings(s).neutralColor,
15
16
  s.setSettings,
16
17
  ]);
17
18
 
@@ -8,10 +8,11 @@ import {
8
8
  import { memo } from 'react';
9
9
 
10
10
  import { useGlobalStore } from '@/store/global';
11
+ import { settingsSelectors } from '@/store/global/selectors';
11
12
 
12
13
  const ThemeSwatchesPrimary = memo(() => {
13
14
  const [primaryColor, setSettings] = useGlobalStore((s) => [
14
- s.settings.primaryColor,
15
+ settingsSelectors.currentSettings(s).primaryColor,
15
16
  s.setSettings,
16
17
  ]);
17
18
 
@@ -3,12 +3,12 @@ import { Form as AntForm, AutoComplete, Input, Switch } from 'antd';
3
3
  import { createStyles } from 'antd-style';
4
4
  import { debounce } from 'lodash-es';
5
5
  import { Webhook } from 'lucide-react';
6
- import { memo } from 'react';
6
+ import { memo, useEffect } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
 
9
9
  import { FORM_STYLE } from '@/const/layoutTokens';
10
- import { useEffectAfterGlobalHydrated, useGlobalStore } from '@/store/global';
11
- import { settingsSelectors } from '@/store/global/selectors';
10
+ import { useGlobalStore } from '@/store/global';
11
+ import { modelProviderSelectors } from '@/store/global/selectors';
12
12
 
13
13
  import Checker from './Checker';
14
14
 
@@ -35,16 +35,23 @@ const LLM = memo(() => {
35
35
  const { t } = useTranslation('setting');
36
36
  const [form] = AntForm.useForm();
37
37
  const { styles } = useStyles();
38
- const [setSettings] = useGlobalStore((s) => [s.setSettings]);
38
+ const [useAzure, setSettings] = useGlobalStore((s) => [
39
+ modelProviderSelectors.enableAzure(s),
40
+ s.setSettings,
41
+ ]);
39
42
 
40
- useEffectAfterGlobalHydrated((store) => {
41
- const settings = settingsSelectors.currentSettings(store.getState());
42
-
43
- form.setFieldsValue(settings);
43
+ useEffect(() => {
44
+ const unsubscribe = useGlobalStore.subscribe(
45
+ (s) => s.settings,
46
+ (settings) => {
47
+ form.setFieldsValue(settings);
48
+ },
49
+ );
50
+ return () => {
51
+ unsubscribe();
52
+ };
44
53
  }, []);
45
54
 
46
- const useAzure = useGlobalStore((s) => s.settings.languageModel.openAI.useAzure);
47
-
48
55
  const openAI: ItemGroup = {
49
56
  children: [
50
57
  {
@@ -11,7 +11,6 @@ import {
11
11
  } from '@/types/settings';
12
12
 
13
13
  export const DEFAULT_BASE_SETTINGS: GlobalBaseSettings = {
14
- avatar: '',
15
14
  fontSize: 14,
16
15
  language: 'auto',
17
16
  password: '',