@lobehub/chat 0.120.3 → 0.120.4

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 (54) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +9 -9
  3. package/README.zh-CN.md +14 -14
  4. package/docs/Home.md +2 -2
  5. package/docs/_Sidebar.md +3 -3
  6. package/package.json +3 -2
  7. package/src/app/chat/(desktop)/features/ChatHeader.tsx +6 -6
  8. package/src/app/chat/{features → (desktop)/features/SideBar}/SystemRole/index.tsx +8 -5
  9. package/src/app/chat/(desktop)/features/{SideBar.tsx → SideBar/index.tsx} +2 -3
  10. package/src/app/chat/(mobile)/index.tsx +17 -4
  11. package/src/app/chat/(mobile)/mobile/page.tsx +30 -2
  12. package/src/app/chat/components/SessionHydration/index.tsx +44 -0
  13. package/src/app/chat/features/SessionListContent/DefaultMode.tsx +6 -1
  14. package/src/app/chat/features/SessionListContent/List/index.tsx +7 -3
  15. package/src/app/chat/features/TopicListContent/Header.tsx +1 -1
  16. package/src/app/chat/page.tsx +7 -3
  17. package/src/app/home/Redirect.tsx +2 -2
  18. package/src/app/metadata.ts +6 -0
  19. package/src/app/welcome/features/Banner/index.tsx +6 -7
  20. package/src/components/StoreHydration/ChatHydration/index.tsx +33 -0
  21. package/src/config/server.ts +4 -0
  22. package/src/const/url.ts +1 -1
  23. package/src/database/models/__tests__/message.test.ts +3 -2
  24. package/src/database/models/message.ts +13 -9
  25. package/src/database/schemas/message.ts +1 -1
  26. package/src/features/ChatInput/useChatInput.ts +2 -6
  27. package/src/features/Conversation/hooks/useInitConversation.ts +0 -2
  28. package/src/features/Conversation/index.tsx +7 -2
  29. package/src/features/SideBar/TopActions.tsx +5 -5
  30. package/src/layout/GlobalLayout/StoreHydration.tsx +12 -11
  31. package/src/store/chat/slices/message/action.ts +1 -1
  32. package/src/store/chat/store.ts +2 -34
  33. package/src/store/global/slices/common/action.ts +6 -0
  34. package/src/store/global/slices/common/initialState.ts +5 -0
  35. package/src/store/session/index.ts +0 -1
  36. package/src/store/session/initialState.ts +6 -2
  37. package/src/store/session/slices/agent/selectors.ts +3 -1
  38. package/src/store/session/slices/session/action.ts +13 -17
  39. package/src/store/session/slices/session/selectors/list.ts +7 -0
  40. package/src/store/session/store.ts +5 -46
  41. package/src/app/chat/(mobile)/layout.mobile.tsx +0 -17
  42. package/src/app/chat/(mobile)/mobile/index.tsx +0 -30
  43. package/src/app/chat/(mobile)/mobile/layout.mobile.tsx +0 -11
  44. package/src/store/session/hooks/index.ts +0 -4
  45. package/src/store/session/hooks/useEffectAfterHydrated.ts +0 -27
  46. package/src/store/session/hooks/useOnFinishHydrationSession.ts +0 -19
  47. package/src/store/session/hooks/useSessionChatInit.ts +0 -12
  48. package/src/store/session/hooks/useSessionHydrated.ts +0 -13
  49. /package/docs/Development/{index.md → Intro.md} +0 -0
  50. /package/docs/Development/{index.zh-CN.md → Intro.zh-CN.md} +0 -0
  51. /package/docs/Development/State-Management/{index.md → State-Management-Intro.md} +0 -0
  52. /package/docs/Development/State-Management/{index.zh-CN.md → State-Management-Intro.zh-CN.md} +0 -0
  53. /package/src/app/chat/{features → (desktop)/features/SideBar}/SystemRole/style.ts +0 -0
  54. /package/src/app/chat/{features → components}/SidebarHeader/index.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.120.4](https://github.com/lobehub/lobe-chat/compare/v0.120.3...v0.120.4)
6
+
7
+ <sup>Released on **2024-01-21**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Refactor url state management and fix some detail experience.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Refactor url state management and fix some detail experience, closes [#1117](https://github.com/lobehub/lobe-chat/issues/1117) ([a355d2c](https://github.com/lobehub/lobe-chat/commit/a355d2c))
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.120.3](https://github.com/lobehub/lobe-chat/compare/v0.120.2...v0.120.3)
6
31
 
7
32
  <sup>Released on **2024-01-19**</sup>
package/README.md CHANGED
@@ -184,14 +184,14 @@ e-commerce platform data access, and various third-party services.
184
184
 
185
185
  <!-- PLUGIN LIST -->
186
186
 
187
- | Recent Submits | Description |
188
- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
189
- | [Midjourney](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **2024-01-18**</sup> | Unleash creativity with Midjourney, effortlessly generating unique AI-driven images through simple prompts. Add visual flair to your conversations with Midjourney's artistic touch.<br/>`ai-image-generation` `midjourney` `visualization` |
190
- | [GIF Search](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **giphy** on **2024-01-17**</sup> | Search through a wide range of gifs - Powered by Giphy.<br/>`gif` `image` `search` |
191
- | [Asset Ovi](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **assetovi** on **2024-01-17**</sup> | Search and preview millions of 3D assets for games, AIGC, AR/VR and others.<br/>`3-d` `assets` `search` |
192
- | [Astrodaily](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **360macky** on **2024-01-17**</sup> | Search and discover NASA images.<br/>`nasa` `search` `image` |
187
+ | Recent Submits | Description |
188
+ | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
189
+ | [AskYourPDF](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **askyourpdf** on **2024-01-20**</sup> | Unlock the power of your PDFs!, dive into your documents, find answers, and bring information to your fingertips.<br/>`pdf` `document` `web` |
190
+ | [Savvy Trader AI](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **savvytrader** on **2024-01-20**</sup> | Realtime stock, crypto and other investment data.<br/>`stock` `analyze` |
191
+ | [Midjourney](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **2024-01-18**</sup> | Unleash creativity with Midjourney, effortlessly generating unique AI-driven images through simple prompts. Add visual flair to your conversations with Midjourney's artistic touch.<br/>`ai-image-generation` `midjourney` `visualization` |
192
+ | [GIF Search](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **efficiency** on **2024-01-17**</sup> | Search through a wide range of gifs - Powered by Giphy.<br/>`gif` `image` `search` |
193
193
 
194
- > 📊 Total plugins: [<kbd>**21**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
194
+ > 📊 Total plugins: [<kbd>**20**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
195
195
 
196
196
  <!-- PLUGIN LIST -->
197
197
 
@@ -225,12 +225,12 @@ Our marketplace is not just a showcase platform but also a collaborative space.
225
225
 
226
226
  | Recent Submits | Description |
227
227
  | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
228
+ | [PromptGPT](https://chat-preview.lobehub.com/market?agent=prompt-gpt)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-19**</sup> | A customized GPT model named PromptGPT. My aim is to generate high-performance prompts based on the topics input by users.<br/>`generation` `artificial-intelligence` `interaction` `customized-experience` `feedback-mechanism` `best-practices` `step-by-step-guidance` `language-flexibility` `boundaries` |
228
229
  | [Tech Explorer AI](https://chat-preview.lobehub.com/market?agent=tech-explorer-ai)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-19**</sup> | Technology exploration AI capability: - Conduct comprehensive technical research - Provide predictive insights based on statistical data and trend analysis - Optimize research methodology - Maintain data accuracy and completeness - Infer limitations in the absence of complete data: - Only answer questions related to technology - Do not provide general purchasing advice - Provide product technology discussion through step-by-step guidance User interaction: - Provide clear and concise dialogue - Provide multilingual options Support objective: To provide accurate information and analyze predictions to deepen the understanding of technology among users.<br/>`technical-research` `data-analysis` `research-methods` `data-accuracy` `inference` `user-interaction` |
229
230
  | [AE Script Development Expert](https://chat-preview.lobehub.com/market?agent=ae-script-development)<br/><sup>By **[Wutpeach](https://github.com/Wutpeach)** on **2024-01-18**</sup> | An expert in AE script development, proficient in JavaScript programming, understanding of AE software principles, capable of debugging and optimizing scripts.<br/>`script-development` `programmer` `adobe-after-effects` `java-script` `algorithm-design` `debugging` `optimization` `coding-standards` `user-communication` `script-usage-instructions` |
230
231
  | [Code Companion](https://chat-preview.lobehub.com/market?agent=code-companion)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-18**</sup> | The best companion for programmers<br/>`code` `dev` `program` |
231
- | [William](https://chat-preview.lobehub.com/market?agent=unreal-engine-development-engineer)<br/><sup>By **[Wutpeach](https://github.com/Wutpeach)** on **2024-01-16**</sup> | Unreal Engine expert, proficient in C++ programming, rendering, memory, thread and other pipeline architectures, UE application on Android platform, comprehensive artistic cognition, familiar with Shader writing, proficient in 3D art asset production process and tools.<br/>`unreal-engine` `c-programming` `rendering-pipeline` `memory-management` `thread-architecture` |
232
232
 
233
- > 📊 Total agents: [<kbd>**102**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
233
+ > 📊 Total agents: [<kbd>**103**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
234
234
 
235
235
  <!-- AGENT LIST -->
236
236
 
package/README.zh-CN.md CHANGED
@@ -168,14 +168,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
168
168
 
169
169
  <!-- PLUGIN LIST -->
170
170
 
171
- | 最近新增 | 插件描述 |
172
- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
173
- | [Midjourney](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **2024-01-18**</sup> | 通过简单的提示轻松释放创造力,利用 Midjourney 生成独特的 AI 驱动图像。通过 Midjourney 的艺术触感为您的对话增添视觉魅力。<br/>`ai-image-generation` `midjourney` `visualization` |
174
- | [GIF 搜索](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **giphy** on **2024-01-17**</sup> | 搜索各种各样的 GIF - 由 Giphy 提供动力。<br/>`gif` `图片` `搜索` |
175
- | [Asset Ovi](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **assetovi** on **2024-01-17**</sup> | 搜索和预览数百万款用于游戏、AIGC、AR/VR 等领域的 3D 资产。<br/>`3-d` `资产` `搜索` |
176
- | [Astrodaily](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **360macky** on **2024-01-17**</sup> | 搜索和发现 NASA 图像。<br/>`nasa` `搜索` `图像` |
171
+ | 最近新增 | 插件描述 |
172
+ | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
173
+ | [AskYourPDF](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **askyourpdf** on **2024-01-20**</sup> | 释放 PDF 的力量!深入文档,寻找答案,让信息触手可及。<br/>`pdf` `document` `web` |
174
+ | [Savvy Trader AI](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **savvytrader** on **2024-01-20**</sup> | 实时股票、加密货币和其他投资数据。<br/>`股票` `分析` |
175
+ | [Midjourney](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **2024-01-18**</sup> | 通过简单的提示轻松释放创造力,利用 Midjourney 生成独特的 AI 驱动图像。通过 Midjourney 的艺术触感为您的对话增添视觉魅力。<br/>`ai-image-generation` `midjourney` `visualization` |
176
+ | [GIF 搜索](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **efficiency** on **2024-01-17**</sup> | 搜索各种各样的 GIF - 由 Giphy 提供动力。<br/>`gif` `图片` `搜索` |
177
177
 
178
- > 📊 Total plugins: [<kbd>**21**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
178
+ > 📊 Total plugins: [<kbd>**20**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
179
179
 
180
180
  <!-- PLUGIN LIST -->
181
181
 
@@ -203,14 +203,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
203
203
 
204
204
  <!-- AGENT LIST -->
205
205
 
206
- | 最近新增 | 助手说明 |
207
- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
208
- | [Tech Explorer AI](https://chat-preview.lobehub.com/market?agent=tech-explorer-ai)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-19**</sup> | 技术探索人工智能能力:- 进行全面的技术研究 - 基于统计数据和趋势分析提供预测性见解 - 优化研究方法论 - 保持数据准确性和完整性 - 推断在没有完整数据的情况下的局限性:- 仅回答与技术相关的问题 - 不提供一般性的购买建议 - 通过逐步指导提供产品技术讨论用户交互:- 提供清晰简洁的对话 - 提供多语言选项支持目标:为用户提供准确的信息并分析预测,以加深他们对技术的理解。<br/>`技术研究` `数据分析` `研究方法` `数据准确性` `推断` `用户交互` |
209
- | [AE 脚本开发专家](https://chat-preview.lobehub.com/market?agent=ae-script-development)<br/><sup>By **[Wutpeach](https://github.com/Wutpeach)** on **2024-01-18**</sup> | AE 脚本开发专家,精通 JavaScript 编程,理解 AE 软件工作原理,能够调试和优化脚本。<br/>`脚本开发` `程序员` `adobe-after-effects` `java-script` `算法设计` `调试` `优化` `编程规范` `用户沟通` `脚本使用说明` |
210
- | [Code Companion](https://chat-preview.lobehub.com/market?agent=code-companion)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-18**</sup> | 程序员的最佳伴侣<br/>`code` `dev` `program` |
211
- | [William](https://chat-preview.lobehub.com/market?agent=unreal-engine-development-engineer)<br/><sup>By **[Wutpeach](https://github.com/Wutpeach)** on **2024-01-16**</sup> | 虚幻引擎专家,精通 C++ 编程,渲染、内存、线程等管线架构,UE 在安卓平台应用,全面的美术认知,熟悉 Shader 编写,熟练掌握 3D 美术资产制作流程与工具。<br/>`虚幻引擎` `c-编程` `渲染管线` `内存管理` `线程架构` |
206
+ | 最近新增 | 助手说明 |
207
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
208
+ | [PromptGPT](https://chat-preview.lobehub.com/market?agent=prompt-gpt)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-19**</sup> | 一个名为 PromptGPT 的定制 GPT 模型。我的目标是基于用户输入的主题生成高性能提示。<br/>`生成` `人工智能` `交互` `定制体验` `反馈机制` `最佳实践` `逐步指导` `语言灵活性` `边界` |
209
+ | [Tech Explorer AI](https://chat-preview.lobehub.com/market?agent=tech-explorer-ai)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-19**</sup> | 技术探索人工智能能力:- 进行全面的技术研究 - 基于统计数据和趋势分析提供预测性见解 - 优化研究方法论 - 保持数据准确性和完整性 - 推断在没有完整数据的情况下的局限性:- 仅回答与技术相关的问题 - 不提供一般性的购买建议 - 通过逐步指导提供产品技术讨论用户交互:- 提供清晰简洁的对话 - 提供多语言选项支持目标:为用户提供准确的信息并分析预测,以加深他们对技术的理解。<br/>`技术研究` `数据分析` `研究方法` `数据准确性` `推断` `用户交互` |
210
+ | [AE 脚本开发专家](https://chat-preview.lobehub.com/market?agent=ae-script-development)<br/><sup>By **[Wutpeach](https://github.com/Wutpeach)** on **2024-01-18**</sup> | AE 脚本开发专家,精通 JavaScript 编程,理解 AE 软件工作原理,能够调试和优化脚本。<br/>`脚本开发` `程序员` `adobe-after-effects` `java-script` `算法设计` `调试` `优化` `编程规范` `用户沟通` `脚本使用说明` |
211
+ | [Code Companion](https://chat-preview.lobehub.com/market?agent=code-companion)<br/><sup>By **[110rever](https://github.com/110rever)** on **2024-01-18**</sup> | 程序员的最佳伴侣<br/>`code` `dev` `program` |
212
212
 
213
- > 📊 Total agents: [<kbd>**102**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
213
+ > 📊 Total agents: [<kbd>**103**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
214
214
 
215
215
  <!-- AGENT LIST -->
216
216
 
package/docs/Home.md CHANGED
@@ -40,8 +40,8 @@ LobeChat is a open-source, extensible ([Function Calling][fc-url]), high-perform
40
40
  - [Environment Setup Guide](https://github.com/lobehub/lobe-chat/wiki/Setup-Development) | [环境设置指南](https://github.com/lobehub/lobe-chat/wiki/Setup-Development.zh-CN)
41
41
  - [Architecture Design](https://github.com/lobehub/lobe-chat/wiki/Architecture) | [架构设计](https://github.com/lobehub/lobe-chat/wiki/Architecture.zh-CN)
42
42
  - [Directory Structure](https://github.com/lobehub/lobe-chat/wiki/Folder-Structure) | [目录架构](https://github.com/lobehub/lobe-chat/wiki/Folder-Structure.zh-CN)
43
- - [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management)
44
- - [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management)
43
+ - [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro.zh-CN)
44
+ - [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selector) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selector.zh-CN)
45
45
  - [Conversation API Implementation Logic](https://github.com/lobehub/lobe-chat/wiki/Chat-API) | [会话 API 实现逻辑](https://github.com/lobehub/lobe-chat/wiki/Chat-API.zh-CN)
46
46
  - [How to Develop a New Feature](https://github.com/lobehub/lobe-chat/wiki/Feature-Development) | [如何开发一个新功能](https://github.com/lobehub/lobe-chat/wiki/Feature-Development.zh-CN)
47
47
  - [Internationalization Implementation Guide](https://github.com/lobehub/lobe-chat/wiki/Internationalization-Implementation) | [国际化实现指南](https://github.com/lobehub/lobe-chat/wiki/Internationalization-Implementation.zh-CN)
package/docs/_Sidebar.md CHANGED
@@ -23,13 +23,13 @@
23
23
 
24
24
  #### ⌨️ Development
25
25
 
26
- - [Technical Development Getting Started Guide](https://github.com/lobehub/lobe-chat/wiki/index) | [技术开发上手指南](https://github.com/lobehub/lobe-chat/wiki/index.zh-CN)
26
+ - [Technical Development Getting Started Guide](https://github.com/lobehub/lobe-chat/wiki/Intro) | [技术开发上手指南](https://github.com/lobehub/lobe-chat/wiki/Intro.zh-CN)
27
27
  - [Code Style and Contribution Guidelines](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines) | [代码风格与贡献指南](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines.zh-CN)
28
28
  - [Environment Setup Guide](https://github.com/lobehub/lobe-chat/wiki/Setup-Development) | [环境设置指南](https://github.com/lobehub/lobe-chat/wiki/Setup-Development.zh-CN)
29
29
  - [Architecture Design](https://github.com/lobehub/lobe-chat/wiki/Architecture) | [架构设计](https://github.com/lobehub/lobe-chat/wiki/Architecture.zh-CN)
30
30
  - [Directory Structure](https://github.com/lobehub/lobe-chat/wiki/Folder-Structure) | [目录架构](https://github.com/lobehub/lobe-chat/wiki/Folder-Structure.zh-CN)
31
- - [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management)
32
- - [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management)
31
+ - [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro.zh-CN)
32
+ - [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selector) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selector.zh-CN)
33
33
  - [Conversation API Implementation Logic](https://github.com/lobehub/lobe-chat/wiki/Chat-API) | [会话 API 实现逻辑](https://github.com/lobehub/lobe-chat/wiki/Chat-API.zh-CN)
34
34
  - [How to Develop a New Feature](https://github.com/lobehub/lobe-chat/wiki/Feature-Development) | [如何开发一个新功能](https://github.com/lobehub/lobe-chat/wiki/Feature-Development.zh-CN)
35
35
  - [Internationalization Implementation Guide](https://github.com/lobehub/lobe-chat/wiki/Internationalization-Implementation) | [国际化实现指南](https://github.com/lobehub/lobe-chat/wiki/Internationalization-Implementation.zh-CN)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.120.3",
3
+ "version": "0.120.4",
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",
@@ -105,6 +105,7 @@
105
105
  "modern-screenshot": "^4",
106
106
  "nanoid": "^5",
107
107
  "next": "^14.0.2",
108
+ "nuqs": "^1.15.4",
108
109
  "openai": "^4.17.3",
109
110
  "polished": "^4",
110
111
  "posthog-js": "^1",
@@ -135,7 +136,7 @@
135
136
  "yaml": "^2",
136
137
  "zod": "^3",
137
138
  "zustand": "^4.4",
138
- "zustand-utils": "^1"
139
+ "zustand-utils": "^1.3.2"
139
140
  },
140
141
  "devDependencies": {
141
142
  "@commitlint/cli": "^18",
@@ -9,7 +9,7 @@ import { Flexbox } from 'react-layout-kit';
9
9
 
10
10
  import { DESKTOP_HEADER_ICON_SIZE } from '@/const/layoutTokens';
11
11
  import { useGlobalStore } from '@/store/global';
12
- import { useSessionChatInit, useSessionStore } from '@/store/session';
12
+ import { useSessionStore } from '@/store/session';
13
13
  import { agentSelectors, sessionSelectors } from '@/store/session/selectors';
14
14
  import { pathString } from '@/utils/url';
15
15
 
@@ -19,11 +19,12 @@ import ShareButton from '../../features/ChatHeader/ShareButton';
19
19
 
20
20
  const Left = memo(() => {
21
21
  const { t } = useTranslation('chat');
22
- const init = useSessionChatInit();
22
+
23
23
  const router = useRouter();
24
24
 
25
- const [isInbox, title, description, avatar, backgroundColor, model, plugins] = useSessionStore(
26
- (s) => [
25
+ const [init, isInbox, title, description, avatar, backgroundColor, model, plugins] =
26
+ useSessionStore((s) => [
27
+ sessionSelectors.isSomeSessionActive(s),
27
28
  sessionSelectors.isInboxSession(s),
28
29
  agentSelectors.currentAgentTitle(s),
29
30
  agentSelectors.currentAgentDescription(s),
@@ -31,8 +32,7 @@ const Left = memo(() => {
31
32
  agentSelectors.currentAgentBackgroundColor(s),
32
33
  agentSelectors.currentAgentModel(s),
33
34
  agentSelectors.currentAgentPlugins(s),
34
- ],
35
- );
35
+ ]);
36
36
 
37
37
  const displayTitle = isInbox ? t('inbox.title') : title;
38
38
  const displayDesc = isInbox ? t('inbox.desc') : description;
@@ -9,33 +9,36 @@ import useMergeState from 'use-merge-value';
9
9
 
10
10
  import AgentInfo from '@/features/AgentInfo';
11
11
  import { useGlobalStore } from '@/store/global';
12
- import { useSessionChatInit, useSessionStore } from '@/store/session';
13
- import { agentSelectors } from '@/store/session/selectors';
12
+ import { useSessionStore } from '@/store/session';
13
+ import { agentSelectors, sessionSelectors } from '@/store/session/selectors';
14
14
  import { pathString } from '@/utils/url';
15
15
 
16
- import SidebarHeader from '../SidebarHeader';
16
+ import SidebarHeader from '../../../../components/SidebarHeader';
17
17
  import { useStyles } from './style';
18
18
 
19
19
  const SystemRole = memo(() => {
20
20
  const router = useRouter();
21
21
  const [editing, setEditing] = useState(false);
22
22
  const { styles } = useStyles();
23
- const [systemRole, meta, updateAgentConfig] = useSessionStore((s) => [
23
+
24
+ const [init, systemRole, meta, updateAgentConfig] = useSessionStore((s) => [
25
+ sessionSelectors.isSomeSessionActive(s),
24
26
  agentSelectors.currentAgentSystemRole(s),
25
27
  agentSelectors.currentAgentMeta(s),
26
28
  s.updateAgentConfig,
27
29
  ]);
30
+
28
31
  const [showSystemRole, toggleSystemRole] = useGlobalStore((s) => [
29
32
  s.preference.showSystemRole,
30
33
  s.toggleSystemRole,
31
34
  ]);
35
+
32
36
  const [open, setOpen] = useMergeState(false, {
33
37
  defaultValue: showSystemRole,
34
38
  onChange: toggleSystemRole,
35
39
  value: showSystemRole,
36
40
  });
37
41
 
38
- const init = useSessionChatInit();
39
42
  const { t } = useTranslation('common');
40
43
 
41
44
  const handleOpenWithEdit = () => {
@@ -3,15 +3,14 @@ import { createStyles } from 'antd-style';
3
3
  import dynamic from 'next/dynamic';
4
4
  import { memo } from 'react';
5
5
 
6
+ import TopicListContent from '@/app/chat/features/TopicListContent';
6
7
  import SafeSpacing from '@/components/SafeSpacing';
7
8
  import { CHAT_SIDEBAR_WIDTH } from '@/const/layoutTokens';
8
9
  import { useGlobalStore } from '@/store/global';
9
10
  import { useSessionStore } from '@/store/session';
10
11
  import { sessionSelectors } from '@/store/session/selectors';
11
12
 
12
- import TopicListContent from '../../features/TopicListContent';
13
-
14
- const SystemRole = dynamic(() => import('../../features/SystemRole'));
13
+ const SystemRole = dynamic(() => import('./SystemRole'));
15
14
 
16
15
  const useStyles = createStyles(({ css, token }) => ({
17
16
  content: css`
@@ -1,17 +1,30 @@
1
1
  'use client';
2
2
 
3
- import { memo } from 'react';
3
+ import { useRouter } from 'next/navigation';
4
+ import { memo, useEffect } from 'react';
5
+
6
+ import AppLayoutMobile from '@/layout/AppLayout.mobile';
7
+ import { useSwitchSideBarOnInit } from '@/store/global';
8
+ import { SidebarTabKey } from '@/store/global/slices/common/initialState';
4
9
 
5
10
  import PageTitle from '../features/PageTitle';
11
+ import SessionHeader from './features/SessionHeader';
6
12
  import SessionList from './features/SessionList';
7
- import Layout from './layout.mobile';
8
13
 
9
14
  const ChatMobilePage = memo(() => {
15
+ useSwitchSideBarOnInit(SidebarTabKey.Chat);
16
+
17
+ const router = useRouter();
18
+ useEffect(() => {
19
+ router.prefetch('/chat/mobile');
20
+ router.prefetch('/settings');
21
+ }, []);
22
+
10
23
  return (
11
- <Layout>
24
+ <AppLayoutMobile navBar={<SessionHeader />} showTabBar>
12
25
  <PageTitle />
13
26
  <SessionList />
14
- </Layout>
27
+ </AppLayoutMobile>
15
28
  );
16
29
  });
17
30
 
@@ -1,3 +1,31 @@
1
- import Index from './index';
1
+ 'use client';
2
2
 
3
- export default () => <Index />;
3
+ import dynamic from 'next/dynamic';
4
+ import { memo } from 'react';
5
+ import { Flexbox } from 'react-layout-kit';
6
+
7
+ import ChatHeader from '@/app/chat/(mobile)/features/ChatHeader';
8
+ import Conversation from '@/features/Conversation';
9
+ import AppLayoutMobile from '@/layout/AppLayout.mobile';
10
+ import { useSessionStore } from '@/store/session';
11
+
12
+ import ChatInput from '../features/ChatInput';
13
+
14
+ const TopicList = dynamic(() => import('../features/TopicList'));
15
+
16
+ const Chat = memo(() => {
17
+ // due to mobile side don't have sessionList, so we need to fetch sessions here
18
+ // refs: https://github.com/lobehub/lobe-chat/pull/541
19
+ const useFetchSessions = useSessionStore((s) => s.useFetchSessions);
20
+ useFetchSessions();
21
+
22
+ return (
23
+ <AppLayoutMobile navBar={<ChatHeader />}>
24
+ <Flexbox height={'calc(100% - 44px)'} horizontal>
25
+ <Conversation chatInput={<ChatInput />} mobile />
26
+ <TopicList />
27
+ </Flexbox>
28
+ </AppLayoutMobile>
29
+ );
30
+ });
31
+ export default Chat;
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+
3
+ import { useResponsive } from 'antd-style';
4
+ import { useRouter } from 'next/navigation';
5
+ import { useQueryState } from 'nuqs';
6
+ import { parseAsString } from 'nuqs/parsers';
7
+ import { memo, useEffect } from 'react';
8
+ import { createStoreUpdater } from 'zustand-utils';
9
+
10
+ import { useSessionStore } from '@/store/session';
11
+
12
+ // sync outside state to useSessionStore
13
+ const SessionHydration = memo(() => {
14
+ const useStoreUpdater = createStoreUpdater(useSessionStore);
15
+
16
+ const { mobile } = useResponsive();
17
+ useStoreUpdater('isMobile', mobile);
18
+
19
+ const router = useRouter();
20
+ // TODO: 后续可以把 router 从 useSessionStore 移除
21
+ useStoreUpdater('router', router);
22
+
23
+ // two-way bindings the url and session store
24
+ const [session, setSession] = useQueryState(
25
+ 'session',
26
+ parseAsString.withDefault('inbox').withOptions({ history: 'replace', throttleMs: 500 }),
27
+ );
28
+ useStoreUpdater('activeId', session);
29
+
30
+ useEffect(() => {
31
+ const unsubscribe = useSessionStore.subscribe(
32
+ (s) => s.activeId,
33
+ (state) => setSession(state),
34
+ );
35
+
36
+ return () => {
37
+ unsubscribe();
38
+ };
39
+ }, []);
40
+
41
+ return null;
42
+ });
43
+
44
+ export default SessionHydration;
@@ -16,13 +16,18 @@ const SessionListContent = memo(() => {
16
16
  const { t } = useTranslation('chat');
17
17
  const unpinnedSessionList = useSessionStore(sessionSelectors.unpinnedSessionList, isEqual);
18
18
  const pinnedList = useSessionStore(sessionSelectors.pinnedSessionList, isEqual);
19
- const hasPinnedSessionList = useSessionStore(sessionSelectors.hasPinnedSessionList);
19
+ const [hasPinnedSessionList, useFetchSessions] = useSessionStore((s) => [
20
+ sessionSelectors.hasPinnedSessionList(s),
21
+ s.useFetchSessions,
22
+ ]);
20
23
 
21
24
  const [sessionGroupKeys, updatePreference] = useGlobalStore((s) => [
22
25
  preferenceSelectors.sessionGroupKeys(s),
23
26
  s.updatePreference,
24
27
  ]);
25
28
 
29
+ useFetchSessions();
30
+
26
31
  const items = [
27
32
  hasPinnedSessionList && {
28
33
  children: <SessionList dataSource={pinnedList} />,
@@ -4,7 +4,8 @@ import { memo } from 'react';
4
4
  import LazyLoad from 'react-lazy-load';
5
5
 
6
6
  import { SESSION_CHAT_URL } from '@/const/url';
7
- import { useSessionHydrated, useSessionStore } from '@/store/session';
7
+ import { useSessionStore } from '@/store/session';
8
+ import { sessionSelectors } from '@/store/session/selectors';
8
9
  import { LobeAgentSession } from '@/types/session';
9
10
 
10
11
  import AddButton from './AddButton';
@@ -21,9 +22,12 @@ interface SessionListProps {
21
22
  dataSource: LobeAgentSession[];
22
23
  }
23
24
  const SessionList = memo<SessionListProps>(({ dataSource }) => {
24
- const [activeSession, switchSession] = useSessionStore((s) => [s.activeSession, s.switchSession]);
25
+ const [activeSession, switchSession, isInit] = useSessionStore((s) => [
26
+ s.activeSession,
27
+ s.switchSession,
28
+ sessionSelectors.isSessionListInit(s),
29
+ ]);
25
30
  const { styles } = useStyles();
26
- const isInit = useSessionHydrated();
27
31
 
28
32
  const { mobile } = useResponsive();
29
33
 
@@ -8,7 +8,7 @@ import { Flexbox } from 'react-layout-kit';
8
8
  import { useChatStore } from '@/store/chat';
9
9
  import { topicSelectors } from '@/store/chat/selectors';
10
10
 
11
- import SidebarHeader from '../SidebarHeader';
11
+ import SidebarHeader from '../../components/SidebarHeader';
12
12
  import TopicSearchBar from './TopicSearchBar';
13
13
 
14
14
  const Header = memo(() => {
@@ -2,6 +2,7 @@ import { isMobileDevice } from '@/utils/responsive';
2
2
 
3
3
  import DesktopPage from './(desktop)';
4
4
  import MobilePage from './(mobile)';
5
+ import SessionHydration from './components/SessionHydration';
5
6
  import Migration from './features/Migration';
6
7
 
7
8
  const Page = () => {
@@ -10,9 +11,12 @@ const Page = () => {
10
11
  const Page = mobile ? MobilePage : DesktopPage;
11
12
 
12
13
  return (
13
- <Migration>
14
- <Page />
15
- </Migration>
14
+ <>
15
+ <Migration>
16
+ <Page />
17
+ </Migration>
18
+ <SessionHydration />
19
+ </>
16
20
  );
17
21
  };
18
22
 
@@ -24,11 +24,11 @@ const Redirect = memo(() => {
24
24
  useGlobalStore.getState().switchSideBar(SidebarTabKey.Chat);
25
25
 
26
26
  if (hasData) {
27
- router.push('/chat');
27
+ router.replace('/chat');
28
28
 
29
29
  switchSession();
30
30
  } else {
31
- router.push('/welcome');
31
+ router.replace('/welcome');
32
32
  }
33
33
  });
34
34
  }, []);
@@ -1,9 +1,14 @@
1
1
  import { Metadata } from 'next';
2
2
 
3
+ import { getServerConfig } from '@/config/server';
4
+
3
5
  import pkg from '../../package.json';
4
6
 
5
7
  const title = 'LobeChat';
6
8
  const { description, homepage } = pkg;
9
+
10
+ const { METADATA_BASE_URL = 'https://chat-preview.lobehub.com/' } = getServerConfig();
11
+
7
12
  const metadata: Metadata = {
8
13
  appleWebApp: {
9
14
  statusBarStyle: 'black-translucent',
@@ -18,6 +23,7 @@ const metadata: Metadata = {
18
23
  'https://registry.npmmirror.com/@lobehub/assets-favicons/latest/files/assets/favicon.ico',
19
24
  },
20
25
  manifest: '/manifest.json',
26
+ metadataBase: new URL(METADATA_BASE_URL),
21
27
  openGraph: {
22
28
  description: description,
23
29
  images: [
@@ -3,11 +3,13 @@
3
3
  import { Icon } from '@lobehub/ui';
4
4
  import { Button } from 'antd';
5
5
  import { SendHorizonal } from 'lucide-react';
6
+ import { useRouter } from 'next/navigation';
6
7
  import { memo } from 'react';
7
8
  import { useTranslation } from 'react-i18next';
8
9
  import { Flexbox } from 'react-layout-kit';
9
10
 
10
11
  import DataImporter from '@/features/DataImporter';
12
+ import { useGlobalStore } from '@/store/global';
11
13
  import { useSessionStore } from '@/store/session';
12
14
 
13
15
  import Hero from './Hero';
@@ -15,13 +17,10 @@ import { useStyles } from './style';
15
17
 
16
18
  const Banner = memo<{ mobile?: boolean }>(({ mobile }) => {
17
19
  const { t } = useTranslation('welcome');
20
+ const router = useRouter();
18
21
  const { styles } = useStyles();
19
- const [switchSession, switchBackToChat, router, isMobile] = useSessionStore((s) => [
20
- s.switchSession,
21
- s.switchBackToChat,
22
- s.router,
23
- s.isMobile,
24
- ]);
22
+ const [switchSession] = useSessionStore((s) => [s.switchSession]);
23
+ const [switchBackToChat, isMobile] = useGlobalStore((s) => [s.switchBackToChat, s.isMobile]);
25
24
 
26
25
  return (
27
26
  <>
@@ -46,7 +45,7 @@ const Banner = memo<{ mobile?: boolean }>(({ mobile }) => {
46
45
  </DataImporter>
47
46
  <Button
48
47
  block={mobile}
49
- onClick={() => (isMobile ? router?.push('/chat') : switchBackToChat())}
48
+ onClick={() => (isMobile ? router.push('/chat') : switchBackToChat())}
50
49
  size={'large'}
51
50
  type={'primary'}
52
51
  >
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+
3
+ import { useQueryState } from 'nuqs';
4
+ import { memo, useEffect } from 'react';
5
+ import { createStoreUpdater } from 'zustand-utils';
6
+
7
+ import { useChatStore } from '@/store/chat';
8
+
9
+ // sync outside state to useChatStore
10
+ const ChatHydration = memo(() => {
11
+ const useStoreUpdater = createStoreUpdater(useChatStore);
12
+
13
+ // two-way bindings the topic params to chat store
14
+ const [topic, setTopic] = useQueryState('topic', { history: 'replace', throttleMs: 500 });
15
+ useStoreUpdater('activeTopicId', topic);
16
+
17
+ useEffect(() => {
18
+ const unsubscribe = useChatStore.subscribe(
19
+ (s) => s.activeTopicId,
20
+ (state) => {
21
+ setTopic(!state ? null : state);
22
+ },
23
+ );
24
+
25
+ return () => {
26
+ unsubscribe();
27
+ };
28
+ }, []);
29
+
30
+ return null;
31
+ });
32
+
33
+ export default ChatHydration;