@lobehub/chat 0.162.24 → 0.163.0

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 (96) hide show
  1. package/.github/workflows/release.yml +21 -2
  2. package/.github/workflows/sync.yml +1 -1
  3. package/.github/workflows/test.yml +35 -4
  4. package/CHANGELOG.md +50 -0
  5. package/LICENSE +38 -21
  6. package/README.md +8 -8
  7. package/README.zh-CN.md +8 -8
  8. package/codecov.yml +11 -0
  9. package/docs/self-hosting/platform/zeabur.mdx +1 -1
  10. package/docs/self-hosting/platform/zeabur.zh-CN.mdx +1 -1
  11. package/drizzle.config.ts +29 -0
  12. package/next.config.mjs +3 -0
  13. package/package.json +25 -5
  14. package/scripts/migrateServerDB/index.ts +30 -0
  15. package/src/app/(main)/(mobile)/me/(home)/features/useCategory.tsx +2 -1
  16. package/src/app/(main)/chat/@session/features/SessionListContent/List/Item/Actions.tsx +95 -88
  17. package/src/app/(main)/chat/settings/features/HeaderContent.tsx +37 -31
  18. package/src/app/(main)/settings/llm/components/ProviderConfig/index.tsx +11 -1
  19. package/src/app/api/middleware/auth/index.ts +1 -1
  20. package/src/app/api/webhooks/clerk/__tests__/fixtures/createUser.json +73 -0
  21. package/src/app/api/webhooks/clerk/route.ts +159 -0
  22. package/src/app/api/webhooks/clerk/validateRequest.ts +22 -0
  23. package/src/app/trpc/edge/[trpc]/route.ts +1 -1
  24. package/src/app/trpc/lambda/[trpc]/route.ts +26 -0
  25. package/src/config/auth.ts +2 -0
  26. package/src/config/db.ts +13 -1
  27. package/src/database/server/core/db.ts +44 -0
  28. package/src/database/server/core/dbForTest.ts +45 -0
  29. package/src/database/server/index.ts +1 -0
  30. package/src/database/server/migrations/0000_init.sql +439 -0
  31. package/src/database/server/migrations/0001_add_client_id.sql +9 -0
  32. package/src/database/server/migrations/0002_amusing_puma.sql +9 -0
  33. package/src/database/server/migrations/meta/0000_snapshot.json +1583 -0
  34. package/src/database/server/migrations/meta/0001_snapshot.json +1636 -0
  35. package/src/database/server/migrations/meta/0002_snapshot.json +1630 -0
  36. package/src/database/server/migrations/meta/_journal.json +27 -0
  37. package/src/database/server/models/__tests__/file.test.ts +140 -0
  38. package/src/database/server/models/__tests__/message.test.ts +847 -0
  39. package/src/database/server/models/__tests__/plugin.test.ts +172 -0
  40. package/src/database/server/models/__tests__/session.test.ts +595 -0
  41. package/src/database/server/models/__tests__/topic.test.ts +623 -0
  42. package/src/database/server/models/__tests__/user.test.ts +173 -0
  43. package/src/database/server/models/_template.ts +44 -0
  44. package/src/database/server/models/file.ts +51 -0
  45. package/src/database/server/models/message.ts +378 -0
  46. package/src/database/server/models/plugin.ts +63 -0
  47. package/src/database/server/models/session.ts +290 -0
  48. package/src/database/server/models/sessionGroup.ts +69 -0
  49. package/src/database/server/models/topic.ts +265 -0
  50. package/src/database/server/models/user.ts +138 -0
  51. package/src/database/server/modules/DataImporter/__tests__/fixtures/messages.json +1101 -0
  52. package/src/database/server/modules/DataImporter/__tests__/index.test.ts +954 -0
  53. package/src/database/server/modules/DataImporter/index.ts +333 -0
  54. package/src/database/server/schemas/_id.ts +15 -0
  55. package/src/database/server/schemas/lobechat.ts +601 -0
  56. package/src/database/server/utils/idGenerator.test.ts +39 -0
  57. package/src/database/server/utils/idGenerator.ts +26 -0
  58. package/src/features/AgentSetting/AgentModal/index.tsx +6 -7
  59. package/src/features/User/UserPanel/useMenu.tsx +43 -37
  60. package/src/libs/trpc/client.ts +52 -3
  61. package/src/server/files/s3.ts +21 -1
  62. package/src/server/keyVaultsEncrypt/index.test.ts +62 -0
  63. package/src/server/keyVaultsEncrypt/index.ts +93 -0
  64. package/src/server/mock.ts +1 -1
  65. package/src/server/routers/{index.ts → edge/index.ts} +3 -3
  66. package/src/server/routers/lambda/file.ts +49 -0
  67. package/src/server/routers/lambda/importer.ts +54 -0
  68. package/src/server/routers/lambda/index.ts +28 -0
  69. package/src/server/routers/lambda/message.ts +165 -0
  70. package/src/server/routers/lambda/plugin.ts +100 -0
  71. package/src/server/routers/lambda/session.ts +194 -0
  72. package/src/server/routers/lambda/sessionGroup.ts +77 -0
  73. package/src/server/routers/lambda/topic.ts +134 -0
  74. package/src/server/routers/lambda/user.ts +57 -0
  75. package/src/services/file/index.ts +4 -7
  76. package/src/services/file/server.ts +45 -0
  77. package/src/services/import/index.ts +4 -1
  78. package/src/services/import/server.ts +115 -0
  79. package/src/services/message/index.ts +4 -8
  80. package/src/services/message/server.ts +93 -0
  81. package/src/services/plugin/index.ts +4 -9
  82. package/src/services/plugin/server.ts +46 -0
  83. package/src/services/session/index.ts +4 -8
  84. package/src/services/session/server.ts +148 -0
  85. package/src/services/topic/index.ts +4 -9
  86. package/src/services/topic/server.ts +68 -0
  87. package/src/services/user/index.ts +4 -9
  88. package/src/services/user/server.ts +28 -0
  89. package/src/store/user/slices/modelList/selectors/keyVaults.test.ts +201 -0
  90. package/src/store/user/slices/modelList/selectors/keyVaults.ts +15 -3
  91. package/src/store/user/slices/modelList/selectors/modelConfig.test.ts +29 -1
  92. package/src/store/user/slices/modelList/selectors/modelConfig.ts +21 -1
  93. package/src/types/user/settings/keyVaults.ts +1 -1
  94. package/tests/setup-db.ts +7 -0
  95. package/vitest.config.ts +2 -1
  96. package/vitest.server.config.ts +23 -0
@@ -8,6 +8,17 @@ jobs:
8
8
  release:
9
9
  name: Release
10
10
  runs-on: ubuntu-latest
11
+
12
+ services:
13
+ postgres:
14
+ image: postgres:16
15
+ env:
16
+ POSTGRES_PASSWORD: postgres
17
+ options: >-
18
+ --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
19
+ ports:
20
+ - 5432:5432
21
+
11
22
  steps:
12
23
  - uses: actions/checkout@v4
13
24
 
@@ -22,8 +33,16 @@ jobs:
22
33
  - name: Lint
23
34
  run: bun run lint
24
35
 
25
- - name: Test
26
- run: bun run test
36
+ - name: Test Server Coverage
37
+ run: bun run test-server:coverage
38
+ env:
39
+ DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
40
+ DATABASE_DRIVER: node
41
+ NEXT_PUBLIC_SERVICE_MODE: server
42
+ KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
43
+
44
+ - name: Test App Coverage
45
+ run: bun run test-app:coverage
27
46
 
28
47
  - name: Release
29
48
  run: bun run release
@@ -7,7 +7,7 @@ permissions:
7
7
 
8
8
  on:
9
9
  schedule:
10
- - cron: '0 * * * *' # every hour
10
+ - cron: '0 */6 * * *' # every 6 hours
11
11
  workflow_dispatch:
12
12
 
13
13
  jobs:
@@ -1,9 +1,23 @@
1
1
  name: Test CI
2
+
2
3
  on: [push, pull_request]
4
+
3
5
  jobs:
4
6
  test:
5
7
  runs-on: ubuntu-latest
6
8
 
9
+ services:
10
+ postgres:
11
+ image: postgres:16
12
+ env:
13
+ POSTGRES_PASSWORD: postgres
14
+ options: >-
15
+ --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
16
+
17
+
18
+ ports:
19
+ - 5432:5432
20
+
7
21
  steps:
8
22
  - uses: actions/checkout@v4
9
23
 
@@ -18,10 +32,27 @@ jobs:
18
32
  - name: Lint
19
33
  run: bun run lint
20
34
 
21
- - name: Test and coverage
22
- run: bun run test:coverage
35
+ - name: Test Server Coverage
36
+ run: bun run test-server:coverage
37
+ env:
38
+ DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
39
+ DATABASE_DRIVER: node
40
+ NEXT_PUBLIC_SERVICE_MODE: server
41
+ KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
42
+
43
+ - name: Upload Server coverage to Codecov
44
+ uses: codecov/codecov-action@v4
45
+ with:
46
+ token: ${{ secrets.CODECOV_TOKEN }}
47
+ files: ./coverage/server/lcov.info
48
+ flags: server
49
+
50
+ - name: Test App Coverage
51
+ run: bun run test-app:coverage
23
52
 
24
- - name: Upload coverage to Codecov
53
+ - name: Upload App Coverage to Codecov
25
54
  uses: codecov/codecov-action@v4
26
55
  with:
27
- token: ${{ secrets.CODECOV_TOKEN }} # required
56
+ token: ${{ secrets.CODECOV_TOKEN }}
57
+ files: ./coverage/app/lcov.info
58
+ flags: app
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.163.0](https://github.com/lobehub/lobe-chat/compare/v0.162.25...v0.163.0)
6
+
7
+ <sup>Released on **2024-06-17**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support server db mode with Postgres / Drizzle ORM / tRPC.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support server db mode with Postgres / Drizzle ORM / tRPC, closes [#2556](https://github.com/lobehub/lobe-chat/issues/2556) ([b26afbf](https://github.com/lobehub/lobe-chat/commit/b26afbf))
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
+
30
+ ### [Version 0.162.25](https://github.com/lobehub/lobe-chat/compare/v0.162.24...v0.162.25)
31
+
32
+ <sup>Released on **2024-06-16**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix issues for client fetch.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix issues for client fetch, closes [#2753](https://github.com/lobehub/lobe-chat/issues/2753) ([6f5be5d](https://github.com/lobehub/lobe-chat/commit/6f5be5d))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 0.162.24](https://github.com/lobehub/lobe-chat/compare/v0.162.23...v0.162.24)
6
56
 
7
57
  <sup>Released on **2024-06-14**</sup>
package/LICENSE CHANGED
@@ -1,21 +1,38 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 - current LobeHub
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License Version 2.0
2
+
3
+ Copyright (c) 2024/03/29 - current LobeHub LLC. All rights reserved.
4
+
5
+ ----------
6
+
7
+ From 1.0, LobeChat is licensed under the Apache License 2.0, with the following additional conditions:
8
+
9
+ 1. The commercial usage of LobeChat:
10
+
11
+ a. LobeChat may be utilized commercially, including as a frontend and backend service without modifying the source code.
12
+
13
+ b. a commercial license must be obtained from the producer if you want to develop and distribute a derivative work based on LobeChat.
14
+
15
+ Please contact hello@lobehub.com by email to inquire about licensing matters.
16
+
17
+
18
+ 2. As a contributor, you should agree that:
19
+
20
+ a. The producer can adjust the open-source agreement to be more strict or relaxed as deemed necessary.
21
+
22
+ b. Your contributed code may be used for commercial purposes, including but not limited to its cloud edition.
23
+
24
+ Apart from the specific conditions mentioned above, all other rights and restrictions follow the Apache License 2.0. Detailed information about the Apache License 2.0 can be found at http://www.apache.org/licenses/LICENSE-2.0.
25
+
26
+ ----------
27
+
28
+ Licensed under the Apache License, Version 2.0 (the "License");
29
+ you may not use this file except in compliance with the License.
30
+ You may obtain a copy of the License at
31
+
32
+ http://www.apache.org/licenses/LICENSE-2.0
33
+
34
+ Unless required by applicable law or agreed to in writing, software
35
+ distributed under the License is distributed on an "AS IS" BASIS,
36
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ See the License for the specific language governing permissions and
38
+ limitations under the License.
package/README.md CHANGED
@@ -263,14 +263,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
263
263
 
264
264
  <!-- AGENT LIST -->
265
265
 
266
- | Recent Submits | Description |
267
- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
268
- | [Mr. MySQL](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | Mr. MySQL is a great teacher to help everyone learn MySQL<br/>`mysql` `programming` `learning` |
269
- | [Popular Science Writing Assistant](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | The popular science writing assistant uses everyday language to explain scientific concepts, tells stories, uses examples and metaphors to spark interest, and emphasizes importance.<br/>`science-writing` `science-popularization` `creative-expression` |
270
- | [Expert Response to Reviewer](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | Specializing in natural academic editing, assisting authors in responding to reviewer comments in a scientific, courteous, and point-by-point manner.<br/>`academic-editing` `response-to-reviewer-comments` `scientific-writing` |
271
- | [Translation of Novels: English to Chinese](https://chat-preview.lobehub.com/market?agent=noveltranslation)<br/><sup>By **[xbtachlb](https://github.com/xbtachlb)** on **2024-06-03**</sup> | Secondary translation of novels<br/>`translation` |
272
-
273
- > 📊 Total agents: [<kbd>**287**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
266
+ | Recent Submits | Description |
267
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
268
+ | [Pseudo Code Prompt Word Generator Expert](https://chat-preview.lobehub.com/market?agent=pseudocode-prompt-master)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-16**</sup> | Pseudo Code Prompt Word Generator Expert allows users to directly input prompt word design requirements and returns designed pseudo code prompt words directly.<br/>`prompt` `prompt-word` `pseudo-code` |
269
+ | [Mr. MySQL](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | Mr. MySQL is a great teacher to help everyone learn MySQL<br/>`mysql` `programming` `learning` |
270
+ | [Popular Science Writing Assistant](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | The popular science writing assistant uses everyday language to explain scientific concepts, tells stories, uses examples and metaphors to spark interest, and emphasizes importance.<br/>`science-writing` `science-popularization` `creative-expression` |
271
+ | [Expert Response to Reviewer](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | Specializing in natural academic editing, assisting authors in responding to reviewer comments in a scientific, courteous, and point-by-point manner.<br/>`academic-editing` `response-to-reviewer-comments` `scientific-writing` |
272
+
273
+ > 📊 Total agents: [<kbd>**288**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
274
274
 
275
275
  <!-- AGENT LIST -->
276
276
 
package/README.zh-CN.md CHANGED
@@ -251,14 +251,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
251
251
 
252
252
  <!-- AGENT LIST -->
253
253
 
254
- | 最近新增 | 助手说明 |
255
- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
256
- | [Mysql 好先生](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | mysql 好先生是帮助所有人学习 mysql 的好老师<br/>`mysql` `编程` `学习` |
257
- | [通俗科普创作助手](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | 通俗科普创作助手,用生活化语言讲科学概念,讲故事、使用例子和比喻,激发兴趣,强调重要性。<br/>`科普写作` `科学普及` `创意表达` |
258
- | [审稿回复专家](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | 擅长自然学术编辑,协助作者回复审稿人意见,科学、礼貌、逐点回应。<br/>`学术编辑` `审稿意见回复` `科学写作` |
259
- | [小说翻译 英译中](https://chat-preview.lobehub.com/market?agent=noveltranslation)<br/><sup>By **[xbtachlb](https://github.com/xbtachlb)** on **2024-06-03**</sup> | 小说二次翻译<br/>`翻译` |
260
-
261
- > 📊 Total agents: [<kbd>**287**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
254
+ | 最近新增 | 助手说明 |
255
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
256
+ | [伪代码提示词生成专家](https://chat-preview.lobehub.com/market?agent=pseudocode-prompt-master)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-16**</sup> | 伪代码提示词生成专家,用户直接输入提示词设计需求,直接返还设计的伪代码提示词<br/>`prompt` `提示词` `伪代码` |
257
+ | [Mysql 好先生](https://chat-preview.lobehub.com/market?agent=mysql-haoteacher)<br/><sup>By **[yayoinoyume](https://github.com/yayoinoyume)** on **2024-06-09**</sup> | mysql 好先生是帮助所有人学习 mysql 的好老师<br/>`mysql` `编程` `学习` |
258
+ | [通俗科普创作助手](https://chat-preview.lobehub.com/market?agent=popular-science-writer)<br/><sup>By **[ShinChven](https://github.com/ShinChven)** on **2024-06-08**</sup> | 通俗科普创作助手,用生活化语言讲科学概念,讲故事、使用例子和比喻,激发兴趣,强调重要性。<br/>`科普写作` `科学普及` `创意表达` |
259
+ | [审稿回复专家](https://chat-preview.lobehub.com/market?agent=academic-editor-en)<br/><sup>By **[Starlitnightly](https://github.com/Starlitnightly)** on **2024-06-03**</sup> | 擅长自然学术编辑,协助作者回复审稿人意见,科学、礼貌、逐点回应。<br/>`学术编辑` `审稿意见回复` `科学写作` |
260
+
261
+ > 📊 Total agents: [<kbd>**288**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
262
262
 
263
263
  <!-- AGENT LIST -->
264
264
 
package/codecov.yml ADDED
@@ -0,0 +1,11 @@
1
+ coverage:
2
+ status:
3
+ project:
4
+ default: off
5
+ server:
6
+ flags:
7
+ - server
8
+ app:
9
+ flags:
10
+ - app
11
+ patch: off
@@ -82,4 +82,4 @@ You can create a subdomain provided by Zeabur, or choose to bind a custom domain
82
82
 
83
83
  ### Zeabur shall start auto build and you should be able to access it by the domain of your choice after a while.
84
84
 
85
- </Steps>
85
+ </Steps>
@@ -81,4 +81,4 @@ tags:
81
81
 
82
82
  ### Zeabur 将开始自动构建,您应该可以在一段时间后通过您选择的域名访问它。
83
83
 
84
- </Steps>
84
+ </Steps>
@@ -0,0 +1,29 @@
1
+ import * as dotenv from 'dotenv';
2
+ import type { Config } from 'drizzle-kit';
3
+
4
+ // Read the .env file if it exists, or a file specified by the
5
+
6
+ // dotenv_config_path parameter that's passed to Node.js
7
+
8
+ dotenv.config();
9
+
10
+ let connectionString = process.env.DATABASE_URL;
11
+
12
+ if (process.env.NODE_ENV === 'test') {
13
+ console.log('current ENV:', process.env.NODE_ENV);
14
+ connectionString = process.env.DATABASE_TEST_URL;
15
+ }
16
+
17
+ if (!connectionString)
18
+ throw new Error('`DATABASE_URL` or `DATABASE_TEST_URL` not found in environment');
19
+
20
+ export default {
21
+ dbCredentials: {
22
+ url: connectionString,
23
+ },
24
+ dialect: 'postgresql',
25
+ out: './src/database/server/migrations',
26
+
27
+ schema: './src/database/server/schemas/lobechat.ts',
28
+ strict: true,
29
+ } satisfies Config;
package/next.config.mjs CHANGED
@@ -60,6 +60,9 @@ const nextConfig = {
60
60
  },
61
61
  });
62
62
 
63
+ // https://github.com/pinojs/pino/issues/688#issuecomment-637763276
64
+ config.externals.push('pino-pretty');
65
+
63
66
  return config;
64
67
  },
65
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.162.24",
3
+ "version": "0.163.0",
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",
@@ -27,10 +27,17 @@
27
27
  "sideEffects": false,
28
28
  "scripts": {
29
29
  "build": "next build",
30
- "postbuild": "npm run build-sitemap",
30
+ "postbuild": "npm run build-sitemap && npm run build-migrate-db",
31
+ "build-migrate-db": "bun run db:migrate",
31
32
  "build-sitemap": "next-sitemap --config next-sitemap.config.mjs",
32
33
  "build:analyze": "ANALYZE=true next build",
33
34
  "build:docker": "DOCKER=true next build && npm run build-sitemap",
35
+ "db:generate": "drizzle-kit generate -- dotenv_config_path='.env'",
36
+ "db:migrate": "MIGRATION_DB=1 tsx scripts/migrateServerDB/index.ts",
37
+ "db:push": "drizzle-kit push -- dotenv_config_path='.env'",
38
+ "db:push-test": "NODE_ENV=test drizzle-kit push -- dotenv_config_path='.env'",
39
+ "db:studio": "drizzle-kit studio",
40
+ "db:z-pull": "drizzle-kit introspect -- dotenv_config_path='.env'",
34
41
  "dev": "next dev -p 3010",
35
42
  "dev:clerk-proxy": "ngrok http http://localhost:3011",
36
43
  "docs:i18n": "lobe-i18n md && npm run workflow:docs && npm run lint:mdx",
@@ -48,8 +55,11 @@
48
55
  "release": "semantic-release",
49
56
  "start": "next start",
50
57
  "stylelint": "stylelint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
51
- "test": "vitest",
52
- "test:coverage": "vitest run --coverage",
58
+ "test": "npm run test-app && npm run test-server",
59
+ "test-app": "vitest run --config vitest.config.ts",
60
+ "test-app:coverage": "vitest run --config vitest.config.ts --coverage",
61
+ "test-server": "vitest run --config vitest.server.config.ts",
62
+ "test-server:coverage": "vitest run --config vitest.server.config.ts --coverage",
53
63
  "test:update": "vitest -u",
54
64
  "type-check": "tsc --noEmit",
55
65
  "workflow:docs": "tsx scripts/docsWorkflow/index.ts",
@@ -101,6 +111,7 @@
101
111
  "@lobehub/tts": "^1.24.1",
102
112
  "@lobehub/ui": "^1.141.2",
103
113
  "@microsoft/fetch-event-source": "^2.0.1",
114
+ "@neondatabase/serverless": "^0.9.3",
104
115
  "@next/third-parties": "^14.2.3",
105
116
  "@sentry/nextjs": "^7.116.0",
106
117
  "@t3-oss/env-nextjs": "^0.10.1",
@@ -119,6 +130,8 @@
119
130
  "debug": "^4.3.4",
120
131
  "dexie": "^3.2.7",
121
132
  "diff": "^5.2.0",
133
+ "drizzle-orm": "^0.30.10",
134
+ "drizzle-zod": "^0.5.1",
122
135
  "fast-deep-equal": "^3.1.3",
123
136
  "gpt-tokenizer": "^2.1.2",
124
137
  "i18next": "^23.11.5",
@@ -141,6 +154,7 @@
141
154
  "nuqs": "^1.17.4",
142
155
  "ollama": "^0.5.1",
143
156
  "openai": "^4.47.1",
157
+ "pg": "^8.11.5",
144
158
  "pino": "^9.1.0",
145
159
  "polished": "^4.3.1",
146
160
  "posthog-js": "^1.135.2",
@@ -163,6 +177,7 @@
163
177
  "semver": "^7.6.2",
164
178
  "sharp": "^0.33.4",
165
179
  "superjson": "^2.2.1",
180
+ "svix": "^1.24.0",
166
181
  "swr": "^2.2.5",
167
182
  "systemjs": "^6.15.1",
168
183
  "ts-md5": "^1.3.1",
@@ -170,7 +185,8 @@
170
185
  "url-join": "^5.0.0",
171
186
  "use-merge-value": "^1.2.0",
172
187
  "utility-types": "^3.11.0",
173
- "uuid": "^9.0.1",
188
+ "uuid": "^10.0.0",
189
+ "ws": "^8.17.0",
174
190
  "y-protocols": "^1.0.6",
175
191
  "y-webrtc": "^10.3.0",
176
192
  "yaml": "^2.4.2",
@@ -200,6 +216,7 @@
200
216
  "@types/lodash-es": "^4.17.12",
201
217
  "@types/node": "^20.12.12",
202
218
  "@types/numeral": "^2.0.5",
219
+ "@types/pg": "^8.11.6",
203
220
  "@types/react": "^18.3.3",
204
221
  "@types/react-dom": "^18.3.0",
205
222
  "@types/rtl-detect": "^1.0.3",
@@ -207,12 +224,15 @@
207
224
  "@types/systemjs": "^6.13.5",
208
225
  "@types/ua-parser-js": "^0.7.39",
209
226
  "@types/uuid": "^9.0.8",
227
+ "@types/ws": "^8.5.10",
210
228
  "@umijs/lint": "^4.2.5",
211
229
  "@vitest/coverage-v8": "~1.2.2",
212
230
  "ajv-keywords": "^5.1.0",
213
231
  "commitlint": "^19.3.0",
214
232
  "consola": "^3.2.3",
233
+ "dotenv": "^16.4.5",
215
234
  "dpdm": "^3.14.0",
235
+ "drizzle-kit": "^0.21.1",
216
236
  "eslint": "^8.57.0",
217
237
  "eslint-plugin-mdx": "^2.3.4",
218
238
  "fake-indexeddb": "^6.0.0",
@@ -0,0 +1,30 @@
1
+ import * as dotenv from 'dotenv';
2
+ import * as migrator from 'drizzle-orm/neon-serverless/migrator';
3
+ import { join } from 'node:path';
4
+
5
+ import { serverDB } from '../../src/database/server/core/db';
6
+
7
+ // Read the `.env` file if it exists, or a file specified by the
8
+ // dotenv_config_path parameter that's passed to Node.js
9
+ dotenv.config();
10
+
11
+ const runMigrations = async () => {
12
+ await migrator.migrate(serverDB, {
13
+ migrationsFolder: join(__dirname, '../../src/database/server/migrations'),
14
+ });
15
+ console.log('✅ database migration pass.');
16
+ // eslint-disable-next-line unicorn/no-process-exit
17
+ process.exit(0);
18
+ };
19
+
20
+ let connectionString = process.env.DATABASE_URL;
21
+
22
+ // only migrate database if the connection string is available
23
+ if (connectionString) {
24
+ // eslint-disable-next-line unicorn/prefer-top-level-await
25
+ runMigrations().catch((err) => {
26
+ console.error('❌ Database migrate failed:', err);
27
+ // eslint-disable-next-line unicorn/no-process-exit
28
+ process.exit(1);
29
+ });
30
+ }
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
  import { CellProps } from '@/components/Cell';
7
7
  import { enableAuth } from '@/const/auth';
8
8
  import { DISCORD, DOCUMENTS, FEEDBACK } from '@/const/url';
9
+ import { isServerMode } from '@/const/version';
9
10
  import { usePWAInstall } from '@/hooks/usePWAInstall';
10
11
  import { useUserStore } from '@/store/user';
11
12
  import { authSelectors } from '@/store/user/slices/auth/selectors';
@@ -109,7 +110,7 @@ export const useCategory = () => {
109
110
 
110
111
  /* ↑ cloud slot ↑ */
111
112
  ...(canInstall ? pwa : []),
112
- ...(isLogin ? data : []),
113
+ ...(isLogin && !isServerMode ? data : []),
113
114
  ...helps,
114
115
  ].filter(Boolean) as CellProps[];
115
116