@lobehub/chat 1.0.6 → 1.0.8

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 (69) hide show
  1. package/.env.example +52 -0
  2. package/CHANGELOG.md +58 -0
  3. package/README.md +48 -7
  4. package/README.zh-CN.md +48 -7
  5. package/docs/self-hosting/advanced/feature-flags.mdx +13 -11
  6. package/docs/self-hosting/advanced/feature-flags.zh-CN.mdx +1 -1
  7. package/docs/self-hosting/advanced/server-database.mdx +387 -0
  8. package/docs/self-hosting/advanced/server-database.zh-CN.mdx +376 -0
  9. package/docs/self-hosting/advanced/upstream-sync.zh-CN.mdx +15 -15
  10. package/docs/usage/features/auth.mdx +44 -0
  11. package/docs/usage/features/auth.zh-CN.mdx +58 -0
  12. package/docs/usage/features/database.mdx +54 -0
  13. package/docs/usage/features/database.zh-CN.mdx +54 -0
  14. package/locales/ar/chat.json +0 -1
  15. package/locales/ar/common.json +1 -2
  16. package/locales/bg-BG/chat.json +0 -1
  17. package/locales/bg-BG/common.json +1 -2
  18. package/locales/de-DE/chat.json +0 -1
  19. package/locales/de-DE/common.json +1 -2
  20. package/locales/en-US/chat.json +14 -15
  21. package/locales/en-US/common.json +12 -13
  22. package/locales/en-US/market.json +6 -6
  23. package/locales/en-US/metadata.json +2 -2
  24. package/locales/en-US/setting.json +16 -16
  25. package/locales/en-US/welcome.json +2 -2
  26. package/locales/es-ES/chat.json +0 -1
  27. package/locales/es-ES/common.json +1 -2
  28. package/locales/fr-FR/chat.json +0 -1
  29. package/locales/fr-FR/common.json +1 -2
  30. package/locales/it-IT/chat.json +0 -1
  31. package/locales/it-IT/common.json +1 -2
  32. package/locales/ja-JP/chat.json +0 -1
  33. package/locales/ja-JP/common.json +1 -2
  34. package/locales/ko-KR/chat.json +0 -1
  35. package/locales/ko-KR/common.json +1 -2
  36. package/locales/nl-NL/chat.json +0 -1
  37. package/locales/nl-NL/common.json +1 -2
  38. package/locales/pl-PL/chat.json +0 -1
  39. package/locales/pl-PL/common.json +1 -2
  40. package/locales/pt-BR/chat.json +0 -1
  41. package/locales/pt-BR/common.json +1 -2
  42. package/locales/ru-RU/chat.json +0 -1
  43. package/locales/ru-RU/common.json +1 -2
  44. package/locales/tr-TR/chat.json +0 -1
  45. package/locales/tr-TR/common.json +1 -2
  46. package/locales/vi-VN/chat.json +0 -1
  47. package/locales/vi-VN/common.json +1 -2
  48. package/locales/zh-CN/chat.json +0 -1
  49. package/locales/zh-CN/common.json +1 -2
  50. package/locales/zh-TW/chat.json +0 -1
  51. package/locales/zh-TW/common.json +1 -2
  52. package/package.json +2 -2
  53. package/scripts/i18nWorkflow/utils.ts +1 -4
  54. package/scripts/migrateServerDB/index.ts +2 -0
  55. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/SendMore.tsx +3 -5
  56. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/index.tsx +15 -6
  57. package/src/app/(main)/chat/(workspace)/features/ShareButton/Preview.tsx +3 -2
  58. package/src/app/(main)/chat/@session/_layout/Desktop/SessionHeader.tsx +3 -2
  59. package/src/app/(main)/chat/@session/_layout/Mobile/SessionHeader.tsx +3 -2
  60. package/src/app/(main)/market/_layout/Desktop/Header.tsx +3 -2
  61. package/src/app/(main)/market/_layout/Desktop/Hero.tsx +1 -1
  62. package/src/app/(main)/welcome/_layout/Desktop.tsx +3 -2
  63. package/src/app/layout.tsx +2 -1
  64. package/src/components/BrandWatermark/index.tsx +2 -2
  65. package/src/components/FullscreenLoading/index.tsx +3 -2
  66. package/src/config/featureFlags/schema.ts +1 -1
  67. package/src/locales/default/chat.ts +0 -1
  68. package/src/locales/default/common.ts +1 -2
  69. package/src/store/serverConfig/selectors.test.ts +1 -1
@@ -0,0 +1,387 @@
1
+ # Deploying Server-Side Database
2
+
3
+ LobeChat defaults to using a client-side database (IndexedDB) but also supports using a server-side database. LobeChat uses Postgres as the backend storage database. PostgreSQL is a powerful open-source relational database management system with high scalability and standard SQL support. It provides rich data types, concurrency control, data integrity, security, and programmability, making it suitable for complex applications and large-scale data management.
4
+
5
+ This article will detail how to deploy the server-side database version of LobeChat on Vercel, including: 1) database configuration; 2) identity authentication service configuration; 3) steps for setting up the S3 storage service.
6
+
7
+ <Callout type={'info'}>
8
+ Due to workload constraints, currently only deployment on Vercel using the server-side database
9
+ version is supported, with Docker version support planned for future iterations.
10
+ </Callout>
11
+
12
+ ## 1. Configure the Database
13
+
14
+ <Steps>
15
+
16
+ ### Prepare a Server-Side Database Instance and Obtain the Connection URL
17
+
18
+ Before deployment, make sure you have prepared a Postgres database instance. You can choose either of the following methods:
19
+
20
+ - `A.` Use Serverless Postgres instances like Vercel/Neon;
21
+ - `B.` Use self-deployed Postgres instances like Docker.
22
+
23
+ The configuration for both methods is slightly different, which will be distinguished in the next step.
24
+
25
+ ### Add Environment Variables in Vercel
26
+
27
+ In Vercel's deployment environment variables, add the `DATABASE_URL` and other environment variables. Fill in the prepared Postgres database connection URL. The typical format for the database connection URL is `postgres://username:password@host:port/database`.
28
+
29
+ <Tabs items={['Serverless Postgres', 'Node Postgres']}>
30
+
31
+ <Tab>
32
+
33
+ Variables required for Serverless Postgres are as follows:
34
+
35
+ ```shell
36
+ # Serverless Postgres DB Url
37
+ DATABASE_URL=
38
+
39
+ # Specify the service mode as server, otherwise it won't enter the server-side database
40
+ NEXT_PUBLIC_SERVICE_MODE=server
41
+ ```
42
+
43
+ An example of how to fill in Vercel is shown below:
44
+
45
+ <Image
46
+ alt={'Add Serverless Postgres DATABASE_URL'}
47
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/d4a710cd-6404-4196-90d0-cd08ca385074'}
48
+ ></Image>
49
+
50
+ </Tab>
51
+
52
+ <Tab>
53
+ Variables required for Node Postgres are as follows:
54
+
55
+ ```shell
56
+ # Node Postgres DB Url
57
+ DATABASE_URL=
58
+
59
+ # Specify the Postgres database driver as node
60
+ DATABASE_DRIVER=node
61
+
62
+ # Specify the service mode as server, otherwise it won't enter the server-side database
63
+ NEXT_PUBLIC_SERVICE_MODE=server
64
+ ```
65
+
66
+ An example of how to fill in Vercel is shown below:
67
+
68
+ <Image
69
+ alt={'Add Node Postgres DATABASE_URL'}
70
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/1c689738-809b-4199-b305-ba5770d39da7'}
71
+ ></Image>
72
+
73
+ </Tab>
74
+
75
+ </Tabs>
76
+
77
+ ### Add the `KEY_VAULTS_SECRET` Environment Variable
78
+
79
+ After adding the `DATABASE_URL` environment variable, you need to add a `KEY_VAULTS_SECRET` environment variable. This variable is used to encrypt sensitive information like user-stored API keys. You can generate a random 32-character string as the key using `openssl rand -base64 32`.
80
+
81
+ ```shell
82
+ KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
83
+ ```
84
+
85
+ Add this to the Vercel environment variables as well.
86
+
87
+ </Steps>
88
+
89
+ ## 2. Configure the Identity Authentication Service
90
+
91
+ A server-side database needs to be paired with an identity authentication service to function properly. Therefore, the corresponding identity authentication service needs to be configured.
92
+
93
+ <Callout type={'warning'}>
94
+ Due to workload constraints, currently only Clerk is supported as an identity authentication
95
+ service solution. Integration with Next-Auth for server-side database is under development.
96
+ </Callout>
97
+
98
+ <Steps>
99
+
100
+ ### Prepare the Clerk Identity Authentication Service
101
+
102
+ Go to [Clerk](https://clerk.com?utm_source=lobehub&utm_medium=docs) to register and create an application to obtain the corresponding Public Key and Secret Key.
103
+
104
+ <Callout type={'info'}>
105
+ If you are unfamiliar with Clerk, you can refer to [Authentication
106
+ Service-Clerk](/en/docs/self-hosting/advanced/authentication#clerk) for details on using Clerk.
107
+ </Callout>
108
+
109
+ ### Add Public and Private Key Environment Variables in Vercel
110
+
111
+ In Vercel's deployment environment variables, add the `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` and `CLERK_SECRET_KEY` environment variables. You can click on "API Keys" in the menu, then copy the corresponding values and paste them into Vercel's environment variables.
112
+
113
+ <Image
114
+ alt={'Find the corresponding public and private key environment variables in Clerk'}
115
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/89883703-7a1a-4a11-b944-5d804544e57c'}
116
+ ></Image>
117
+
118
+ The environment variables required for this step are as follows:
119
+
120
+ ```shell
121
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx
122
+ CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx
123
+ ```
124
+
125
+ Add these variables to Vercel:
126
+
127
+ <Image
128
+ alt={'Add Clerk public and private key environment variables in Vercel'}
129
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/2bfa13df-6e20-4768-97c0-4dad06c85a2f'}
130
+ ></Image>
131
+
132
+ ### Create and Configure a Webhook in Clerk
133
+
134
+ Since we let Clerk handle user authentication and management entirely, we need Clerk to notify our application and store data in the database when there are changes in the user lifecycle (create, update, delete). We achieve this using the Webhook provided by Clerk.
135
+
136
+ We need to add an endpoint in Clerk's Webhooks to inform Clerk to send notifications to this endpoint when a user's status changes.
137
+
138
+ <Image
139
+ alt={'Add an endpoint in Clerk Webhooks'}
140
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/f50f47fb-5e8e-4930-bf4e-8cf6f5b8afb9'}
141
+ >
142
+
143
+ </Image>
144
+
145
+ Fill in your Vercel project's URL in the endpoint, such as `https://your-project.vercel.app/api/webhooks/clerk`. Then, in the Subscribe to events section, check the three user events (`user.created`, `user.deleted`, `user.updated`), and click create.
146
+
147
+ <Image
148
+ alt={'Configure URL and user events when adding Clerk Webhooks'}
149
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/0249ea56-ab17-4aa9-a56c-9ebd556c2645'}
150
+ ></Image>
151
+
152
+ ### Add the Webhook Secret to Vercel Environment Variables
153
+
154
+ After creation, you can find the secret of this Webhook in the bottom right corner:
155
+
156
+ <Image
157
+ alt={'View Clerk Webhook secret'}
158
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/fab4abb2-584b-49de-9340-813382951635'}
159
+ ></Image>
160
+
161
+ The corresponding environment variable name for this secret is `CLERK_WEBHOOK_SECRET`:
162
+
163
+ ```shell
164
+ CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
165
+ ```
166
+
167
+ Add this to Vercel's environment variables:
168
+
169
+ <Image
170
+ alt={'Add Clerk Webhook secret in Vercel'}
171
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/5fdc9479-007f-46ab-9d6e-a9603e949116'}>
172
+
173
+ </Image>
174
+
175
+ </Steps>
176
+
177
+ You have now successfully configured the Clerk identity authentication service. Next, we will configure the S3 storage service.
178
+
179
+ ## 3. Configure S3 Storage Service
180
+
181
+ LobeChat has long supported multimodal AI conversations, involving the function of uploading images to AI. In the client-side database solution, image files are stored as binary data in the browser's indexedDB database. However, this solution is not feasible in the server-side database. We need to configure the S3 storage service to store a large number of image files, and S3 can also serve as a storage solution for file uploads.
182
+
183
+ <Callout type={'info'}>
184
+ In this article, S3 refers to a compatible S3 storage solution, which supports object storage systems
185
+ that comply with the Amazon S3 API. Common examples include Cloudflare R2 etc., all of which support
186
+ S3-compatible APIs.
187
+ </Callout>
188
+
189
+ <Steps>
190
+
191
+ ### Configure and Obtain S3 Bucket
192
+
193
+ You need to go to your S3 service provider (such as AWS S3, Cloudflare R2, etc.) and create a new storage bucket. Below is an example of the creation process using Cloudflare R2.
194
+
195
+ The interface of Cloudflare R2 is shown below:
196
+
197
+ <Image
198
+ alt={'Cloudflare R2 Storage Interface'}
199
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/41f7f677-0153-4a96-b849-5ac9b7ebefee'}
200
+ ></Image>
201
+
202
+ When creating the bucket, specify its name and then click create.
203
+
204
+ <Image
205
+ alt={'Create Bucket in R2'}
206
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/9c0d184c-3169-40fa-9115-011cfffb9ca7'}
207
+ ></Image>
208
+
209
+ ### Obtain Environment Variables for the Bucket
210
+
211
+ In the settings of the R2 storage bucket, you can view the bucket configuration information:
212
+
213
+ <Image
214
+ alt={'View Bucket Information'}
215
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/2ceb210c-eca0-4439-ba27-8734d4ebb3ee'}
216
+ ></Image>
217
+
218
+ The corresponding environment variables are:
219
+
220
+ ```shell
221
+ # Bucket name
222
+ S3_BUCKET=lobechat
223
+ # Bucket request endpoint
224
+ S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
225
+ # Public domain for accessing the bucket
226
+ NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
227
+ ```
228
+
229
+ ### Obtain S3 Key Environment Variables
230
+
231
+ You need to obtain the access key for S3 so that the LobeChat server has permission to access the S3 storage service. In R2, you can configure the access key in the account details:
232
+
233
+ <Image
234
+ alt={'View Access Key for Bucket'}
235
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/be0c95c0-6693-44ee-a490-7e8dfaa8b34d'}
236
+ ></Image>
237
+
238
+ Click the button in the upper right corner to create an API token, then enter the API Token creation page.
239
+
240
+ <Image
241
+ alt={'Create Corresponding API Token'}
242
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/7b0ea46c-5157-40a8-888f-f47664a4884f'}
243
+ ></Image>
244
+
245
+ Since our server-side database needs to read and write to the S3 storage service, the permissions need to be set to read and write, and only select the bucket we created, then click create.
246
+
247
+ <Image
248
+ alt={'Configure API Token Permissions'}
249
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/d6f5a918-7b50-4d6e-83a6-3894ab930ddf'}
250
+ ></Image>
251
+
252
+ After creation, you can see the corresponding S3 API token.
253
+
254
+ <Image
255
+ alt={'Copy API Token'}
256
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/763b18f9-2b5f-44bb-a479-9b56d46f7397'}
257
+ ></Image>
258
+
259
+ The corresponding environment variables are:
260
+
261
+ ```shell
262
+ S3_ACCESS_KEY_ID=9998d6757e276cf9f1edbd325b7083a6
263
+ S3_SECRET_ACCESS_KEY=55af75d8eb6b99f189f6a35f855336ea62cd9c4751a5cf4337c53c1d3f497ac2
264
+ ```
265
+
266
+ ### Add the Corresponding Environment Variables in Vercel
267
+
268
+ The steps to obtain the required environment variables may vary for different S3 service providers, but the obtained environment variables should be consistent in the end:
269
+
270
+ ```shell
271
+ # S3 Key
272
+ S3_ACCESS_KEY_ID=9998d6757e276cf9f1edbd325b7083a6
273
+ S3_SECRET_ACCESS_KEY=55af75d8eb6b99f189f6a35f855336ea62cd9c4751a5cf4337c53c1d3f497ac2
274
+
275
+ # Bucket name
276
+ S3_BUCKET=lobechat
277
+ # Bucket request endpoint
278
+ S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
279
+ # Public domain for accessing the bucket
280
+ NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
281
+
282
+ # Bucket region, such as us-west-1, generally not required to add, but some service providers may need to configure
283
+ # S3_REGION=us-west-1
284
+ ```
285
+
286
+ Then enter the above environment variables into Vercel's environment variables:
287
+
288
+ <Image
289
+ alt={'Add S3 Environment Variables in Vercel'}
290
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/cd74152d-0ae8-44fd-b815-3307c56a3c18'}
291
+ ></Image>
292
+
293
+ ### Configure Cross-Origin Resource Sharing (CORS)
294
+
295
+ Since S3 storage services are often on a separate domain, cross-origin access needs to be configured.
296
+
297
+ In R2, you can find the CORS configuration in the settings of the storage bucket:
298
+
299
+ <Image
300
+ alt={'Cloudflare R2 CORS Settings'}
301
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/ab008be7-26b2-4b78-8bd9-24301bf34d23'}
302
+ ></Image>
303
+
304
+ Add a CORS rule to allow requests from your domain (in this case, `https://your-project.vercel.app`):
305
+
306
+ <Image
307
+ alt={'Configure Allowed Site Domain'}
308
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/dfcc2cb3-2958-4498-a8a4-51bec584fe7d'}
309
+ ></Image>
310
+
311
+ Example configuration:
312
+
313
+ ```json
314
+ [
315
+ {
316
+ "AllowedOrigins": ["https://your-project.vercel.app"],
317
+ "AllowedMethods": ["GET", "PUT", "HEAD", "POST", "DELETE"],
318
+ "AllowedHeaders": ["*"]
319
+ }
320
+ ]
321
+ ```
322
+
323
+ After configuration, click save.
324
+
325
+ </Steps>
326
+
327
+ ## 4. Deployment and Verification
328
+
329
+ After completing the above steps, the configuration of the server database should be done. Next, we can deploy LobeChat to Vercel and then visit your Vercel link to verify if the server database is working correctly.
330
+
331
+ <Steps>
332
+ ### Redeploy the latest commit
333
+
334
+ After configuring the environment variables, you need to redeploy the latest commit and wait for the deployment to complete.
335
+
336
+ <Image
337
+ alt={'Redeploy the latest commit'}
338
+ src={'https://github.com/lobehub/lobe-chat/assets/28616219/b3a78112-adc8-4837-b4e3-48f67058f16e'}
339
+ ></Image>
340
+
341
+ ### Check if the features are working properly
342
+
343
+ If you click on the login button in the top left corner and the login popup appears normally, then you have configured it successfully. Enjoy using it\~
344
+
345
+ <Image alt={'User login popup'} src={'https://github.com/lobehub/lobe-chat/assets/28616219/da84edc3-46f7-4e2b-a0cd-dc33a98bf5cb'}>
346
+
347
+ </Image>
348
+
349
+ <Image alt={'Login success status'} src={'https://github.com/lobehub/lobe-chat/assets/28616219/9cb5150d-6e1e-4c59-9a18-4e418dce1a5d'}>
350
+
351
+ </Image>
352
+
353
+ </Steps>
354
+
355
+ ## Appendix
356
+
357
+ ### Overview of Server Database Environment Variables
358
+
359
+ For easy copying, here is a summary of the environment variables required to configure the server data:
360
+
361
+ ```shell
362
+ # Specify the service mode as server
363
+ NEXT_PUBLIC_SERVICE_MODE=server
364
+
365
+ # Postgres database URL
366
+ DATABASE_URL=
367
+ KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
368
+
369
+ # Clerk related configurations
370
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_xxxxxxxxxxx
371
+ CLERK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxx
372
+ CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
373
+
374
+ # S3 related configurations
375
+ # S3 keys
376
+ S3_ACCESS_KEY_ID=9998d6757e276cf9f1edbd325b7083a6
377
+ S3_SECRET_ACCESS_KEY=55af75d8eb6b99f189f6a35f855336ea62cd9c4751a5cf4337c53c1d3f497ac2
378
+
379
+ # Bucket name
380
+ S3_BUCKET=lobechat
381
+ # Bucket request endpoint
382
+ S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
383
+ # Public access domain for the bucket
384
+ NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
385
+ # Bucket region, such as us-west-1, generally not needed to add, but some service providers may require configuration
386
+ # S3_REGION=us-west-1
387
+ ```