@lobehub/lobehub 2.0.5 → 2.0.7

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 (38) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +50 -0
  3. package/changelog/v2.json +14 -0
  4. package/docs/self-hosting/advanced/auth/clerk-to-betterauth.mdx +2 -0
  5. package/docs/self-hosting/advanced/auth/clerk-to-betterauth.zh-CN.mdx +2 -0
  6. package/docs/self-hosting/advanced/auth/nextauth-to-betterauth.mdx +2 -0
  7. package/docs/self-hosting/advanced/auth/nextauth-to-betterauth.zh-CN.mdx +2 -0
  8. package/docs/self-hosting/platform/docker.mdx +6 -0
  9. package/docs/self-hosting/platform/docker.zh-CN.mdx +6 -0
  10. package/docs/self-hosting/platform/vercel.mdx +0 -49
  11. package/docs/self-hosting/platform/vercel.zh-CN.mdx +0 -47
  12. package/docs/self-hosting/start.mdx +0 -20
  13. package/docs/self-hosting/start.zh-CN.mdx +0 -18
  14. package/package.json +1 -1
  15. package/packages/database/src/repositories/aiInfra/index.test.ts +52 -0
  16. package/packages/database/src/repositories/aiInfra/index.ts +103 -0
  17. package/packages/model-runtime/src/core/streams/protocol.ts +3 -1
  18. package/src/app/(backend)/api/workflows/memory-user-memory/pipelines/persona/update-writing/route.ts +19 -19
  19. package/src/app/[variants]/(main)/agent/features/Conversation/AgentWelcome/ToolAuthAlert.tsx +3 -2
  20. package/src/app/[variants]/(main)/settings/skill/features/KlavisSkillItem.tsx +3 -3
  21. package/src/app/[variants]/onboarding/components/KlavisServerList/hooks/useKlavisOAuth.ts +12 -5
  22. package/src/components/DebugNode.tsx +21 -0
  23. package/src/features/ChatInput/ActionBar/Tools/KlavisServerItem.tsx +3 -3
  24. package/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx +16 -13
  25. package/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx +51 -40
  26. package/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx +7 -1
  27. package/src/features/ChatInput/ActionBar/components/ActionPopover.tsx +14 -11
  28. package/src/layout/GlobalProvider/useUserStateRedirect.ts +6 -2
  29. package/src/libs/observability/traceparent.test.ts +46 -7
  30. package/src/libs/observability/traceparent.ts +12 -10
  31. package/src/server/routers/lambda/klavis.ts +38 -10
  32. package/src/server/services/memory/userMemory/__tests__/extract.runtime.test.ts +181 -26
  33. package/src/server/services/memory/userMemory/extract.ts +120 -96
  34. package/src/server/services/memory/userMemory/persona/__tests__/service.test.ts +46 -0
  35. package/src/server/services/memory/userMemory/persona/service.ts +47 -6
  36. package/src/store/tool/slices/klavisStore/action.ts +20 -0
  37. package/docs/self-hosting/server-database.mdx +0 -157
  38. package/docs/self-hosting/server-database.zh-CN.mdx +0 -146
@@ -14,14 +14,33 @@ import { desc, eq } from 'drizzle-orm';
14
14
 
15
15
  import { UserMemoryModel } from '@/database/models/userMemory';
16
16
  import { UserPersonaModel } from '@/database/models/userMemory/persona';
17
+ import { AiInfraRepos } from '@/database/repositories/aiInfra';
17
18
  import { LobeChatDatabase } from '@/database/type';
18
19
  import {
19
20
  MemoryAgentConfig,
20
21
  parseMemoryExtractionConfig,
21
22
  } from '@/server/globalConfig/parseMemoryExtractionConfig';
23
+ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
22
24
  import { LayersEnum } from '@/types/userMemory';
23
25
  import { trimBasedOnBatchProbe } from '@/utils/chunkers';
24
26
 
27
+ const extractCredentialsFromVault = (
28
+ vault?: Record<string, unknown>,
29
+ ): { apiKey?: string; baseURL?: string } => {
30
+ if (!vault || typeof vault !== 'object') return {};
31
+
32
+ const apiKey =
33
+ 'apiKey' in vault && typeof (vault as any).apiKey === 'string'
34
+ ? (vault as any).apiKey
35
+ : undefined;
36
+ const baseURL =
37
+ 'baseURL' in vault && typeof (vault as any).baseURL === 'string'
38
+ ? (vault as any).baseURL
39
+ : undefined;
40
+
41
+ return { apiKey, baseURL };
42
+ };
43
+
25
44
  interface UserPersonaAgentPayload {
26
45
  existingPersona?: string | null;
27
46
  language?: string;
@@ -45,7 +64,6 @@ interface UserPersonaAgentResult {
45
64
  export class UserPersonaService {
46
65
  private readonly preferredLanguage?: string;
47
66
  private readonly db: LobeChatDatabase;
48
- private readonly runtime: ModelRuntime;
49
67
  private readonly agentConfig: MemoryAgentConfig;
50
68
 
51
69
  constructor(db: LobeChatDatabase) {
@@ -54,13 +72,36 @@ export class UserPersonaService {
54
72
  this.db = db;
55
73
  this.preferredLanguage = agentPersonaWriter.language;
56
74
  this.agentConfig = agentPersonaWriter;
57
- this.runtime = ModelRuntime.initializeWithProvider(agentPersonaWriter.provider || 'openai', {
58
- apiKey: agentPersonaWriter.apiKey,
59
- baseURL: agentPersonaWriter.baseURL,
60
- });
61
75
  }
62
76
 
63
77
  async composeWriting(payload: UserPersonaAgentPayload): Promise<UserPersonaAgentResult> {
78
+ const aiInfraRepos = new AiInfraRepos(this.db, payload.userId, {});
79
+ const runtimeState = await aiInfraRepos.getAiProviderRuntimeState(
80
+ KeyVaultsGateKeeper.getUserKeyVaults,
81
+ );
82
+
83
+ const providerId = await AiInfraRepos.tryMatchingProviderFrom(runtimeState, {
84
+ fallbackProvider: this.agentConfig.provider,
85
+ label: 'persona writer',
86
+ modelId: this.agentConfig.model,
87
+ });
88
+
89
+ const normalizedProvider = providerId.toLowerCase();
90
+ const { apiKey: vaultApiKey, baseURL: vaultBaseURL } = extractCredentialsFromVault(
91
+ runtimeState.runtimeConfig?.[normalizedProvider]?.keyVaults,
92
+ );
93
+
94
+ const useVaultCredential = !!vaultApiKey;
95
+ const apiKey = useVaultCredential ? vaultApiKey : this.agentConfig.apiKey;
96
+ const baseURL = useVaultCredential
97
+ ? vaultBaseURL || this.agentConfig.baseURL
98
+ : this.agentConfig.baseURL;
99
+
100
+ const runtime = await ModelRuntime.initializeWithProvider(normalizedProvider, {
101
+ apiKey,
102
+ baseURL,
103
+ });
104
+
64
105
  const personaModel = new UserPersonaModel(this.db, payload.userId);
65
106
  const lastDocument = await personaModel.getLatestPersonaDocument();
66
107
  const existingPersonaBaseline = payload.existingPersona ?? lastDocument?.persona;
@@ -68,7 +109,7 @@ export class UserPersonaService {
68
109
  const extractor = new UserPersonaExtractor({
69
110
  agent: 'user-persona',
70
111
  model: this.agentConfig.model,
71
- modelRuntime: this.runtime,
112
+ modelRuntime: runtime,
72
113
  });
73
114
 
74
115
  const agentResult = await extractor.toolCall({
@@ -210,10 +210,30 @@ export const createKlavisStoreSlice: StateCreator<
210
210
  instanceId: server.instanceId,
211
211
  });
212
212
 
213
+ // If server returned an auth error (during polling), silently return
214
+ // This happens when user is still in the process of authorizing
215
+ if (instanceStatus.error === 'AUTH_ERROR') {
216
+ set(
217
+ produce((draft: KlavisStoreState) => {
218
+ draft.loadingServerIds.delete(identifier);
219
+ }),
220
+ false,
221
+ n('refreshKlavisServerTools/pendingAuth'),
222
+ );
223
+ return;
224
+ }
225
+
213
226
  // If authentication failed, remove server and reset status
214
227
  if (!instanceStatus.isAuthenticated) {
215
228
  if (!instanceStatus.authNeeded) {
216
229
  // If no authentication needed, all is well
230
+ set(
231
+ produce((draft: KlavisStoreState) => {
232
+ draft.loadingServerIds.delete(identifier);
233
+ }),
234
+ false,
235
+ n('refreshKlavisServerTools/noAuthNeeded'),
236
+ );
217
237
  return;
218
238
  }
219
239
 
@@ -1,157 +0,0 @@
1
- ---
2
- title: Deploying Server-Side Database for LobeHub
3
- description: Learn how to deploy LobeHub's server-side database using Postgres.
4
- tags:
5
- - LobeHub
6
- - Server-Side Database
7
- - Postgres
8
- - Deployment Guide
9
- ---
10
-
11
- # Deploying Server-Side Database
12
-
13
- LobeHub defaults to using a client-side database (IndexedDB) but also supports deploying a server-side database. LobeHub uses Postgres as the backend storage database.
14
-
15
- <Callout>
16
- PostgreSQL is a powerful open-source relational database management system with high scalability
17
- and standard SQL support. It provides rich data types, concurrency control, data integrity,
18
- security, and programmability, making it suitable for complex applications and large-scale data
19
- management.
20
- </Callout>
21
-
22
- This guide will introduce the process and principles of deploying the server-side database version of LobeHub on any platform from a framework perspective, so you can understand both the what and the why, and then deploy according to your specific needs.
23
-
24
- If you are already familiar with the complete principles, you can quickly get started by checking the deployment guides for each platform:
25
-
26
- <PlatformCards urlPrefix={'platform'} />
27
-
28
- ---
29
-
30
- For the server-side database version of LobeHub, a normal deployment process typically involves configuring three modules:
31
-
32
- 1. Database configuration;
33
- 2. Authentication service configuration;
34
- 3. S3 storage service configuration.
35
-
36
- ## Configure the Database
37
-
38
- Before deployment, make sure you have a Postgres database instance ready. You can choose from the following instances:
39
-
40
- - `A.` Use Serverless Postgres instances like Vercel/Neon;
41
- - `B.` Use self-deployed Postgres instances like Docker/Railway/Zeabur, collectively referred to as Node Postgres instances;
42
-
43
- <Callout>
44
- There is a slight difference in the way they are configured in terms of environment variables.
45
- </Callout>
46
-
47
- Since we support file-based conversations/knowledge base conversations, we need to install the `pgvector` plugin for Postgres. This plugin provides vector search capabilities and is a key component for LobeHub to implement RAG.
48
-
49
- <Steps>
50
- ### `NEXT_PUBLIC_SERVICE_MODE`
51
-
52
- LobeHub supports both client-side and server-side databases, so we provide an environment variable for switching modes, which is `NEXT_PUBLIC_SERVICE_MODE`, with a default value of `client`.
53
-
54
- For server-side database deployment scenarios, you need to set `NEXT_PUBLIC_SERVICE_MODE` to `server`.
55
-
56
- <Callout type={'info'}>
57
- In the official `lobehub` Docker image, this environment variable is already set to
58
- `server` by default. Therefore, if you deploy using the Docker image, you do not need to configure
59
- this environment variable again.
60
- </Callout>
61
-
62
- <Callout type={'tip'}>
63
- Since environment variables starting with `NEXT_PUBLIC` take effect in the front-end code, they cannot be modified through container runtime injection. (Refer to the `next.js` documentation [Configuring: Environment Variables | Next.js (nextjs.org)](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables)). This is why we chose to create a separate DB version image.
64
-
65
- If you need to modify variables with the `NEXT_PUBLIC` prefix in a Docker deployment, you must build the image yourself and inject your own `NEXT_PUBLIC` prefixed environment variables during the build.
66
- </Callout>
67
-
68
- ### `DATABASE_URL`
69
-
70
- The core of configuring the database is to add the `DATABASE_URL` environment variable and fill in the Postgres database connection URL you have prepared. The typical format of the database connection URL is `postgres://username:password@host:port/database`.
71
-
72
- <Callout type={'info'}>
73
- If you want to enable SSL when connecting to the database, please refer to the
74
- [documentation](https://stackoverflow.com/questions/14021998/using-psql-to-connect-to-postgresql-in-ssl-mode)
75
- for setup instructions.
76
- </Callout>
77
-
78
- ### `DATABASE_DRIVER`
79
-
80
- The `DATABASE_DRIVER` environment variable is used to distinguish between the two types of Postgres database instances, with values of `node` or `neon`.
81
-
82
- To streamline deployment, we have set default values based on the characteristics of different platforms:
83
-
84
- - On the Vercel platform, `DATABASE_DRIVER` defaults to `neon`;
85
- - In our provided Docker image `lobehub`, `DATABASE_DRIVER` defaults to `node`.
86
-
87
- Therefore, if you follow the standard deployment methods below, you do not need to manually configure the `DATABASE_DRIVER` environment variable:
88
-
89
- - Vercel + Serverless Postgres
90
- - Docker image + Node Postgres
91
-
92
- ### `KEY_VAULTS_SECRET`
93
-
94
- Considering that users will store sensitive information such as their API Key and baseURL in the database, we need a key to encrypt this information to prevent leakage in case of a database breach. Hence, the `KEY_VAULTS_SECRET` environment variable is used to encrypt sensitive information like user-stored apikeys.
95
-
96
- <Callout type={'info'}>
97
- You can generate a random 32-character string as the value of `KEY_VAULTS_SECRET` using `openssl
98
- rand -base64 32`.
99
- </Callout>
100
- </Steps>
101
-
102
- ## Configuring Authentication Services
103
-
104
- In the server-side database mode, we need an authentication service to distinguish the identities of different users. There are many well-developed authentication solutions in the open-source community. We have integrated two different authentication services to meet the demands of different scenarios, one is Clerk, and the other is NextAuth.
105
-
106
- ### Clerk
107
-
108
- [Clerk](https://clerk.com?utm_source=lobehub\&utm_medium=docs) is an authentication SaaS service that provides out-of-the-box authentication capabilities with high productization, low integration costs, and a great user experience. For those who offer SaaS products, Clerk is a good choice. Our official [LobeHub Cloud](https://LobeHub.com) uses Clerk as the authentication service.
109
-
110
- The integration of Clerk is relatively simple, requiring only the configuration of these environment variables:
111
-
112
- - `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` and `CLERK_SECRET_KEY`, which can be obtained from the Clerk console
113
- - `CLERK_WEBHOOK_SECRET`, which is generated by following these instructions: [Configure Clerk Authentication Service](/docs/self-hosting/advanced/auth/clerk#create-and-configure-webhook-in-clerk).
114
-
115
- <Callout type={'tip'}>
116
- In Vercel deployment mode, we recommend using Clerk as the authentication service for a better
117
- user experience.
118
- </Callout>
119
-
120
- However, this type of authentication relies on Clerk's official service, so there may be some limitations in certain scenarios:
121
-
122
- - For example, when using Clerk in China, it may be affected by the network environment.
123
- - Clerk is not suitable for scenarios that require complete private deployment.
124
- - It relies on `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`, which may not be readily usable with public Docker images.
125
-
126
- Therefore, for the above scenarios, we also provide NextAuth as an alternative solution.
127
-
128
- ### NextAuth
129
-
130
- NextAuth is an open-source authentication library that supports multiple identity providers, including Auth0, Cognito, GitHub, Google, Facebook, Apple, Twitter, and more. NextAuth itself provides a complete authentication solution, including user registration, login, password recovery, integration with various identity providers, and more.
131
-
132
- For information on configuring NextAuth, you can refer to the [Authentication](/docs/self-hosting/advanced/authentication) documentation.
133
-
134
- <Callout type={'tip'}>
135
- In the official Docker image `lobehub`, we recommend using NextAuth as the
136
- authentication service.
137
- </Callout>
138
-
139
- ## Configuring S3 Storage Service
140
-
141
- LobeHub has supported multimodal AI conversations since [a long time ago](https://x.com/lobehub/status/1724289575672291782), involving the function of uploading images to large models. In the client-side database solution, image files are stored as binary data directly in the browser's IndexedDB database. However, this solution is not feasible in the server-side database. Storing file-like data directly in Postgres will greatly waste valuable database storage space and slow down computational performance.
142
-
143
- The best practice in this area is to use a file storage service (S3) to store image files, which is also the storage solution relied upon for subsequent file uploads/knowledge base functions.
144
-
145
- <Callout type={'info'}>
146
- In this documentation, S3 refers to a compatible S3 storage solution, which supports the Amazon S3
147
- API-compatible object storage system. Common examples include Cloudflare R2, Alibaba Cloud OSS,
148
- and self-deployable RustFS, ceph, all of which support the S3-compatible API.
149
- </Callout>
150
-
151
- For detailed configuration guidelines on S3, please refer to [S3 Object Storage](/docs/self-hosting/advanced/s3) for more information.
152
-
153
- ## Getting Started with Deployment
154
-
155
- The above is a detailed explanation of configuring LobeHub with a server-side database. You can configure it according to your actual situation and then choose a deployment platform that suits you to start deployment:
156
-
157
- <PlatformCards urlPrefix={'platform'} />
@@ -1,146 +0,0 @@
1
- ---
2
- title: 使用服务端数据库部署 - 配置数据库、身份验证服务和 S3 存储服务
3
- description: 本文将介绍服务端数据库版 LobeHub 的部署思路,解释如何配置数据库、身份验证服务和 S3 存储服务。
4
- tags:
5
- - 服务端数据库
6
- - Postgres
7
- - S3存储服务
8
- - 数据库配置
9
- - 身份验证服务
10
- - 环境变量配置
11
- ---
12
-
13
- # 使用服务端数据库部署
14
-
15
- LobeHub 默认使用客户端数据库(IndexedDB),同时也支持使用服务端数据库(下简称 DB 版)。LobeHub 采用了 Postgres 作为后端存储数据库。
16
-
17
- <Callout>
18
- PostgreSQL 是一种强大的开源关系型数据库管理系统,具备高度扩展性和标准 SQL
19
- 支持。它提供了丰富的数据类型、并发处理、数据完整性、安全性及可编程性,适用于复杂应用和大规模数据管理。
20
- </Callout>
21
-
22
- 本文将从框架角度介绍在任何一个平台中部署 DB 版 LobeHub 的流程和原理,让你知其然也知其所以然,最后可以根据自己的实际情况进行部署。
23
-
24
- 如你已经熟悉完整原理,可以查看各个平台的部署指南快速开始:
25
-
26
- <PlatformCards urlPrefix={'platform'} />
27
-
28
- ---
29
-
30
- 对于 LobeHub 的 DB 版,正常的部署流程都需要包含三个模块的配置:
31
-
32
- 1. 数据库配置;
33
- 2. 身份验证服务配置;
34
- 3. S3 存储服务配置。
35
-
36
- ## 配置数据库
37
-
38
- 在部署之前,请确保你已经准备好 Postgres 数据库实例,你可以选择以下任一实例:
39
-
40
- - `A.` 使用 Vercel / Neon 等 Serverless Postgres 实例;
41
- - `B.` 使用 Docker / Railway / Zeabur 等自部署 Postgres 实例,下统称 Node Postgres 实例;
42
-
43
- <Callout>两者的配置方式在环境变量的取值上会略有一点区别,其他方面是一样的。</Callout>
44
-
45
- 同时,由于我们支持了文件对话 / 知识库对话的能力,因此我们需要为 Postgres 安装 `pgvector` 插件,该插件提供了向量搜索的能力,是 LobeHub 实现 RAG 的重要构件之一。
46
-
47
- <Steps>
48
- ### `NEXT_PUBLIC_SERVICE_MODE`
49
-
50
- LobeHub 同时支持了客户端数据库和服务端数据库,因此我们提供了一个环境变量用于切换模式,这个变量为 `NEXT_PUBLIC_SERVICE_MODE`,该值默认为 `client`。
51
-
52
- 针对服务端数据库部署场景,你需要将 `NEXT_PUBLIC_SERVICE_MODE` 设置为 `server`。
53
-
54
- <Callout type={'info'}>
55
- 在官方的 `lobehub` Docker 镜像中,已经默认将该环境变量设为 `server`,因此如果你使用
56
- Docker 镜像部署,则无需再配置该环境变量。
57
- </Callout>
58
-
59
- <Callout type={'tip'}>
60
- 由于 `NEXT_PUBLIC` 开头的环境变量是在前端代码中生效的,而因此无法通过容器运行时注入进行修改。 (`next.js`的参考文档 [Configuring: Environment Variables | Next.js (nextjs.org)](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables) ) 这也是为什么我们选择再打一个 DB 版镜像的原因。
61
-
62
- 如果你需要在 Docker 部署中修改 `NEXT_PUBLIC` 前缀的变量,你必须自行构建镜像,在 build 时就把自己的 `NEXT_PUBLIC` 开头的环境变量打进去。
63
- </Callout>
64
-
65
- ### `DATABASE_URL`
66
-
67
- 配置数据库,核心是添加 `DATABASE_URL` 环境变量,将你准备好的 Postgres 数据库连接 URL 填入其中。数据库连接 URL 的通常格式为 `postgres://username:password@host:port/database`。
68
-
69
- <Callout type={'info'}>
70
- 如果希望连接数据库时启用 SSL
71
- ,请自行参考[文档](https://stackoverflow.com/questions/14021998/using-psql-to-connect-to-postgresql-in-ssl-mode)进行设置
72
- </Callout>
73
-
74
- ### `DATABASE_DRIVER`
75
-
76
- `DATABASE_DRIVER` 环境变量用于区分两种 Postgres 数据库实例,`DATABASE_DRIVER` 的取值为 `node` 或 `neon`。
77
-
78
- 为提升部署便捷性,我们根据不同的平台特点设置了默认值:
79
-
80
- - 在 Vercel 平台下,`DATABASE_DRIVER` 默认为 `neon`;
81
- - 在我们提供的 Docker 镜像 `lobehub` 中,`DATABASE_DRIVER` 默认为 `node`。
82
-
83
- 因此如果你采用了以下标准的部署方式,你无需手动配置 `DATABASE_DRIVER` 环境变量:
84
-
85
- - Vercel + Serverless Postgres
86
- - Docker 镜像 + Node Postgres
87
-
88
- ### `KEY_VAULTS_SECRET`
89
-
90
- 考虑到用户会存储自己的 API Key 和 baseURL 等敏感信息到数据库中,因此我们需要一个密钥来加密这些信息,避免数据库被爆破 / 脱库时这些关键信息被泄露。 因此有了 `KEY_VAULTS_SECRET` 环境变量,用于加密用户存储的 apikey 等敏感信息。
91
-
92
- <Callout type={'info'}>
93
- 你可以使用 `openssl rand -base64 32` 生成一个随机的 32 位字符串作为 `KEY_VAULTS_SECRET` 的值。
94
- </Callout>
95
- </Steps>
96
-
97
- ## 配置身份验证服务
98
-
99
- 在服务端数据库模式下,我们要为不同用户区分身份,因此需要一个身份验证服务。开源社区中已经存在较多完善的身份验证解决方案。我们在实现过程中集成了两种不同的身份验证服务,用于满足不同场景的诉求,一种是 Clerk ,另外一种是 NextAuth。
100
-
101
- ### Clerk
102
-
103
- [Clerk](https://clerk.com?utm_source=lobehub\&utm_medium=docs) 是一个身份验证 SaaS 服务,提供了开箱即用的身份验证能力,产品化程度很高,集成成本较低,体验很好。对于提供 SaaS 化产品的诉求来说,Clerk 是一个不错的选择。我们官方提供的 [LobeHub Cloud](https://LobeHub.com),就是使用了 Clerk 作为身份验证服务。
104
-
105
- Clerk 的集成也相对简单,只需要配置 `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` 、 `CLERK_SECRET_KEY` 和 `CLERK_WEBHOOK_SECRET` 环境变量即可,这三个环境变量可以在 Clerk 控制台中获取。
106
-
107
- <Callout type={'tip'}>
108
- 在 Vercel 部署模式下,我们推荐使用 Clerk 作为身份验证服务,可以获得更好的用户体验。
109
- </Callout>
110
-
111
- 但是这种身份验证依赖了 Clerk 官方的服务,因此在一些场景下可能会有一些限制:
112
-
113
- - 比如在国内使用 Clerk 时,可能会受到网络环境的影响;
114
- - 需要完全私有化部署的场景下,Clerk 并不适用;
115
- - 必须依赖 `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`,对于公共 Docker 镜像无法开箱即用;
116
-
117
- 因此针对上述场景,我们也提供了 NextAuth 作为备选方案。
118
-
119
- ### NextAuth
120
-
121
- NextAuth 是一个开源的身份验证库,支持多种身份验证提供商,包括 Auth0、Cognito、GitHub、Google、Facebook、Apple、Twitter 等。NextAuth 本身提供了一套完整的身份验证解决方案,包括用户注册、登录、密码找回、多种身份验证提供商的集成等。
122
-
123
- 关于 NextAuth 的配置,你可以参考 [身份验证](/zh/docs/self-hosting/advanced/authentication) 的文档获取更多信息。
124
-
125
- <Callout type={'tip'}>
126
- 在官方的 Docker 镜像 `lobehub` 中,我们推荐使用 NextAuth 作为身份验证服务。
127
- </Callout>
128
-
129
- ## 配置 S3 存储服务
130
-
131
- LobeHub 在 [很早以前](https://x.com/lobehub/status/1724289575672291782) 就支持了多模态的 AI 会话,其中涉及到图片上传给大模型的功能。在客户端数据库方案中,图片文件直接以二进制数据存储在浏览器 IndexedDB 数据库,但在服务端数据库中这个方案并不可行。因为在 Postgres 中直接存储文件类二进制数据会大大浪费宝贵的数据库存储空间,并拖慢计算性能。
132
-
133
- 这块最佳实践是使用文件存储服务(S3)来存储图片文件,同时 S3 也是文件上传 / 知识库功能所依赖的大容量静态文件存储方案。
134
-
135
- <Callout type={'info'}>
136
- 在本文档库中,S3 所指代的是指兼容 S3 存储方案,即支持 Amazon S3 API 的对象存储系统,常见例如
137
- Cloudflare R2 、阿里云 OSS,可以自部署的 RustFS、ceph 等均支持 S3 兼容 API。
138
- </Callout>
139
-
140
- 关于 S3 的详细配置指南,请参阅 [S3 对象存储](/zh/docs/self-hosting/advanced/s3) 了解详情。
141
-
142
- ## 开始部署
143
-
144
- 以上就是关于服务端数据库版 LobeHub 的配置详解,你可以根据自己的实际情况进行配置,然后选择适合自己的部署平台开始部署:
145
-
146
- <PlatformCards urlPrefix={'platform'} />