@lobehub/chat 1.16.10 → 1.16.11
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.
Potentially problematic release.
This version of @lobehub/chat might be problematic. Click here for more details.
- package/CHANGELOG.md +33 -0
- package/docs/self-hosting/server-database/docker-compose.mdx +1 -0
- package/docs/self-hosting/server-database/docker-compose.zh-CN.mdx +1 -0
- package/package.json +1 -1
- package/src/app/api/webhooks/logto/__tests__/route.test.ts +92 -0
- package/src/app/api/webhooks/logto/route.ts +40 -0
- package/src/app/api/webhooks/logto/validateRequest.ts +50 -0
- package/src/config/auth.ts +2 -0
- package/src/config/modelProviders/bedrock.ts +14 -14
- package/src/config/modelProviders/mistral.ts +0 -3
- package/src/server/services/nextAuthUser/index.ts +42 -0
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,39 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.16.11](https://github.com/lobehub/lobe-chat/compare/v1.16.10...v1.16.11)
|
6
|
+
|
7
|
+
<sup>Released on **2024-09-12**</sup>
|
8
|
+
|
9
|
+
#### 🐛 Bug Fixes
|
10
|
+
|
11
|
+
- **misc**: Support webhooks for logto.
|
12
|
+
|
13
|
+
#### 💄 Styles
|
14
|
+
|
15
|
+
- **misc**: Default disable mistral provider useless models.
|
16
|
+
|
17
|
+
<br/>
|
18
|
+
|
19
|
+
<details>
|
20
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
21
|
+
|
22
|
+
#### What's fixed
|
23
|
+
|
24
|
+
- **misc**: Support webhooks for logto, closes [#3774](https://github.com/lobehub/lobe-chat/issues/3774) ([0cfee6b](https://github.com/lobehub/lobe-chat/commit/0cfee6b))
|
25
|
+
|
26
|
+
#### Styles
|
27
|
+
|
28
|
+
- **misc**: Default disable mistral provider useless models, closes [#3922](https://github.com/lobehub/lobe-chat/issues/3922) ([bdbc647](https://github.com/lobehub/lobe-chat/commit/bdbc647))
|
29
|
+
|
30
|
+
</details>
|
31
|
+
|
32
|
+
<div align="right">
|
33
|
+
|
34
|
+
[](#readme-top)
|
35
|
+
|
36
|
+
</div>
|
37
|
+
|
5
38
|
### [Version 1.16.10](https://github.com/lobehub/lobe-chat/compare/v1.16.9...v1.16.10)
|
6
39
|
|
7
40
|
<sup>Released on **2024-09-12**</sup>
|
@@ -186,6 +186,7 @@ And the service port without reverse proxy:
|
|
186
186
|
|
187
187
|
<Callout type="warning">
|
188
188
|
Please note that CORS cross-origin is configured internally in MinIO / Logto service, do not configure CORS additionally in your reverse proxy, as this will cause errors.
|
189
|
+
For minio ports other than 443, Host must be $http_host (with port number), otherwise a 403 error will occur: proxy_set_header Host $http_host.
|
189
190
|
|
190
191
|
If you need to configure SSL certificates, please configure them uniformly in the outer Nginx reverse proxy, rather than in MinIO.
|
191
192
|
|
@@ -185,6 +185,7 @@ docker compose up -d
|
|
185
185
|
|
186
186
|
<Callout type="warning">
|
187
187
|
请务必注意,CORS 跨域是在 MinIO / Logto 服务端内部配置的,请勿在你的反向代理中额外配置 CORS,这会导致错误。
|
188
|
+
对于minio非443端口时,Host必须是$http_host(带端口号),否则会403错误:proxy_set_header Host $http_host。
|
188
189
|
|
189
190
|
如果你需要配置 SSL 证书,请统一在外层的 Nginx 反向代理中配置,而不是在 MinIO 中配置。
|
190
191
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.16.
|
3
|
+
"version": "1.16.11",
|
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",
|
@@ -0,0 +1,92 @@
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
2
|
+
import { describe, expect, it } from 'vitest';
|
3
|
+
|
4
|
+
interface UserDataUpdatedEvent {
|
5
|
+
event: string;
|
6
|
+
createdAt: string;
|
7
|
+
userAgent: string;
|
8
|
+
ip: string;
|
9
|
+
path: string;
|
10
|
+
method: string;
|
11
|
+
status: number;
|
12
|
+
params: {
|
13
|
+
userId: string;
|
14
|
+
};
|
15
|
+
matchedRoute: string;
|
16
|
+
data: {
|
17
|
+
id: string;
|
18
|
+
username: string;
|
19
|
+
primaryEmail: string;
|
20
|
+
primaryPhone: string | null;
|
21
|
+
name: string;
|
22
|
+
avatar: string | null;
|
23
|
+
customData: Record<string, unknown>;
|
24
|
+
identities: Record<string, unknown>;
|
25
|
+
lastSignInAt: number;
|
26
|
+
createdAt: number;
|
27
|
+
updatedAt: number;
|
28
|
+
profile: Record<string, unknown>;
|
29
|
+
applicationId: string;
|
30
|
+
isSuspended: boolean;
|
31
|
+
};
|
32
|
+
hookId: string;
|
33
|
+
}
|
34
|
+
|
35
|
+
const userDataUpdatedEvent: UserDataUpdatedEvent = {
|
36
|
+
event: 'User.Data.Updated',
|
37
|
+
createdAt: '2024-09-07T08:29:09.381Z',
|
38
|
+
userAgent:
|
39
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
|
40
|
+
ip: '223.104.76.217',
|
41
|
+
path: '/users/rra41h9vmpnd',
|
42
|
+
method: 'PATCH',
|
43
|
+
status: 200,
|
44
|
+
params: {
|
45
|
+
userId: 'rra41h9vmpnd',
|
46
|
+
},
|
47
|
+
matchedRoute: '/users/:userId',
|
48
|
+
data: {
|
49
|
+
id: 'uid',
|
50
|
+
username: 'test',
|
51
|
+
primaryEmail: 'user@example.com',
|
52
|
+
primaryPhone: null,
|
53
|
+
name: 'test',
|
54
|
+
avatar: null,
|
55
|
+
customData: {},
|
56
|
+
identities: {},
|
57
|
+
lastSignInAt: 1725446291545,
|
58
|
+
createdAt: 1725440405556,
|
59
|
+
updatedAt: 1725697749337,
|
60
|
+
profile: {},
|
61
|
+
applicationId: 'appid',
|
62
|
+
isSuspended: false,
|
63
|
+
},
|
64
|
+
hookId: 'hookId',
|
65
|
+
};
|
66
|
+
|
67
|
+
const LOGTO_WEBHOOK_SIGNING_KEY = 'logto-signing-key';
|
68
|
+
|
69
|
+
// Test Logto Webhooks in Local dev, here is some tips:
|
70
|
+
// - Replace the var `LOGTO_WEBHOOK_SIGNING_KEY` with the actual value in your `.env` file
|
71
|
+
// - Start web request: If you want to run the test, replace `describe.skip` with `describe` below
|
72
|
+
|
73
|
+
describe.skip('Test Logto Webhooks in Local dev', () => {
|
74
|
+
// describe('Test Logto Webhooks in Local dev', () => {
|
75
|
+
it('should send a POST request with logto headers', async () => {
|
76
|
+
const url = 'http://localhost:3010/api/webhooks/logto'; // 替换为目标URL
|
77
|
+
const data = userDataUpdatedEvent;
|
78
|
+
// Generate data signature
|
79
|
+
const hmac = createHmac('sha256', LOGTO_WEBHOOK_SIGNING_KEY!);
|
80
|
+
hmac.update(JSON.stringify(data));
|
81
|
+
const signature = hmac.digest('hex');
|
82
|
+
const response = await fetch(url, {
|
83
|
+
method: 'POST',
|
84
|
+
headers: {
|
85
|
+
'Content-Type': 'application/json',
|
86
|
+
'logto-signature-sha-256': signature,
|
87
|
+
},
|
88
|
+
body: JSON.stringify(data),
|
89
|
+
});
|
90
|
+
expect(response.status).toBe(200); // 检查响应状态
|
91
|
+
});
|
92
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { NextResponse } from 'next/server';
|
2
|
+
|
3
|
+
import { authEnv } from '@/config/auth';
|
4
|
+
import { pino } from '@/libs/logger';
|
5
|
+
import { NextAuthUserService } from '@/server/services/nextAuthUser';
|
6
|
+
|
7
|
+
import { validateRequest } from './validateRequest';
|
8
|
+
|
9
|
+
export const POST = async (req: Request): Promise<NextResponse> => {
|
10
|
+
const payload = await validateRequest(req, authEnv.LOGTO_WEBHOOK_SIGNING_KEY!);
|
11
|
+
|
12
|
+
if (!payload) {
|
13
|
+
return NextResponse.json(
|
14
|
+
{ error: 'webhook verification failed or payload was malformed' },
|
15
|
+
{ status: 400 },
|
16
|
+
);
|
17
|
+
}
|
18
|
+
|
19
|
+
const { event, data } = payload;
|
20
|
+
|
21
|
+
pino.trace(`logto webhook payload: ${{ data, event }}`);
|
22
|
+
|
23
|
+
const nextAuthUserService = new NextAuthUserService();
|
24
|
+
switch (event) {
|
25
|
+
case 'User.Data.Updated': {
|
26
|
+
return nextAuthUserService.safeUpdateUser(data.id, {
|
27
|
+
avatar: data?.avatar,
|
28
|
+
email: data?.primaryEmail,
|
29
|
+
fullName: data?.name,
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
default: {
|
34
|
+
pino.warn(
|
35
|
+
`${req.url} received event type "${event}", but no handler is defined for this type`,
|
36
|
+
);
|
37
|
+
return NextResponse.json({ error: `unrecognised payload type: ${event}` }, { status: 400 });
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import { headers } from 'next/headers';
|
2
|
+
import { createHmac } from 'node:crypto';
|
3
|
+
|
4
|
+
import { authEnv } from '@/config/auth';
|
5
|
+
|
6
|
+
export type LogtToUserEntity = {
|
7
|
+
applicationId?: string;
|
8
|
+
avatar?: string;
|
9
|
+
createdAt?: string;
|
10
|
+
customData?: object;
|
11
|
+
id: string;
|
12
|
+
identities?: object;
|
13
|
+
isSuspended?: boolean;
|
14
|
+
lastSignInAt?: string;
|
15
|
+
name?: string;
|
16
|
+
primaryEmail?: string;
|
17
|
+
primaryPhone?: string;
|
18
|
+
username?: string;
|
19
|
+
};
|
20
|
+
|
21
|
+
interface LogtoWebhookPayload {
|
22
|
+
// Only support user event currently
|
23
|
+
data: LogtToUserEntity;
|
24
|
+
event: string;
|
25
|
+
}
|
26
|
+
|
27
|
+
export const validateRequest = async (request: Request, signingKey: string) => {
|
28
|
+
const payloadString = await request.text();
|
29
|
+
const headerPayload = headers();
|
30
|
+
const logtoHeaderSignature = headerPayload.get('logto-signature-sha-256')!;
|
31
|
+
try {
|
32
|
+
const hmac = createHmac('sha256', signingKey);
|
33
|
+
hmac.update(payloadString);
|
34
|
+
const signature = hmac.digest('hex');
|
35
|
+
if (signature === logtoHeaderSignature) {
|
36
|
+
return JSON.parse(payloadString) as LogtoWebhookPayload;
|
37
|
+
} else {
|
38
|
+
console.warn(
|
39
|
+
'[logto]: signature verify failed, please check your logto signature in `LOGTO_WEBHOOK_SIGNING_KEY`',
|
40
|
+
);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
} catch (e) {
|
44
|
+
if (!authEnv.LOGTO_WEBHOOK_SIGNING_KEY) {
|
45
|
+
throw new Error('`LOGTO_WEBHOOK_SIGNING_KEY` environment variable is missing.');
|
46
|
+
}
|
47
|
+
console.error('[logto]: incoming webhook failed in verification.\n', e);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
};
|
package/src/config/auth.ts
CHANGED
@@ -200,6 +200,7 @@ export const getAuthConfig = () => {
|
|
200
200
|
LOGTO_CLIENT_ID: z.string().optional(),
|
201
201
|
LOGTO_CLIENT_SECRET: z.string().optional(),
|
202
202
|
LOGTO_ISSUER: z.string().optional(),
|
203
|
+
LOGTO_WEBHOOK_SIGNING_KEY: z.string().optional(),
|
203
204
|
},
|
204
205
|
|
205
206
|
runtimeEnv: {
|
@@ -257,6 +258,7 @@ export const getAuthConfig = () => {
|
|
257
258
|
LOGTO_CLIENT_ID: process.env.LOGTO_CLIENT_ID,
|
258
259
|
LOGTO_CLIENT_SECRET: process.env.LOGTO_CLIENT_SECRET,
|
259
260
|
LOGTO_ISSUER: process.env.LOGTO_ISSUER,
|
261
|
+
LOGTO_WEBHOOK_SIGNING_KEY: process.env.LOGTO_WEBHOOK_SIGNING_KEY,
|
260
262
|
},
|
261
263
|
});
|
262
264
|
};
|
@@ -40,6 +40,20 @@ const Bedrock: ModelProviderCard = {
|
|
40
40
|
tokens: 200_000,
|
41
41
|
vision: true,
|
42
42
|
},
|
43
|
+
{
|
44
|
+
description:
|
45
|
+
'Claude 3 Haiku 是 Anthropic 最快、最紧凑的模型,提供近乎即时的响应速度。它可以快速回答简单的查询和请求。客户将能够构建模仿人类互动的无缝 AI 体验。Claude 3 Haiku 可以处理图像并返回文本输出,具有 200K 的上下文窗口。',
|
46
|
+
displayName: 'Claude 3 Haiku',
|
47
|
+
enabled: true,
|
48
|
+
functionCall: true,
|
49
|
+
id: 'anthropic.claude-3-haiku-20240307-v1:0',
|
50
|
+
pricing: {
|
51
|
+
input: 0.25,
|
52
|
+
output: 1.25,
|
53
|
+
},
|
54
|
+
tokens: 200_000,
|
55
|
+
vision: true,
|
56
|
+
},
|
43
57
|
{
|
44
58
|
description:
|
45
59
|
'Anthropic 的 Claude 3 Sonnet 在智能和速度之间达到了理想的平衡——特别适合企业工作负载。它以低于竞争对手的价格提供最大的效用,并被设计成为可靠的、高耐用的主力机,适用于规模化的 AI 部署。Claude 3 Sonnet 可以处理图像并返回文本输出,具有 200K 的上下文窗口。',
|
@@ -68,20 +82,6 @@ const Bedrock: ModelProviderCard = {
|
|
68
82
|
tokens: 200_000,
|
69
83
|
vision: true,
|
70
84
|
},
|
71
|
-
{
|
72
|
-
description:
|
73
|
-
'Claude 3 Haiku 是 Anthropic 最快、最紧凑的模型,提供近乎即时的响应速度。它可以快速回答简单的查询和请求。客户将能够构建模仿人类互动的无缝 AI 体验。Claude 3 Haiku 可以处理图像并返回文本输出,具有 200K 的上下文窗口。',
|
74
|
-
displayName: 'Claude 3 Haiku',
|
75
|
-
enabled: true,
|
76
|
-
functionCall: true,
|
77
|
-
id: 'anthropic.claude-3-haiku-20240307-v1:0',
|
78
|
-
pricing: {
|
79
|
-
input: 0.25,
|
80
|
-
output: 1.25,
|
81
|
-
},
|
82
|
-
tokens: 200_000,
|
83
|
-
vision: true,
|
84
|
-
},
|
85
85
|
{
|
86
86
|
description:
|
87
87
|
'Claude 2 的更新版,具有双倍的上下文窗口,以及在长文档和 RAG 上下文中的可靠性、幻觉率和基于证据的准确性的改进。',
|
@@ -8,7 +8,6 @@ const Mistral: ModelProviderCard = {
|
|
8
8
|
description:
|
9
9
|
'Mistral 7B是一款紧凑但高性能的模型,擅长批量处理和简单任务,如分类和文本生成,具有良好的推理能力。',
|
10
10
|
displayName: 'Mistral 7B',
|
11
|
-
enabled: true,
|
12
11
|
id: 'open-mistral-7b',
|
13
12
|
tokens: 32_768,
|
14
13
|
},
|
@@ -16,7 +15,6 @@ const Mistral: ModelProviderCard = {
|
|
16
15
|
description:
|
17
16
|
'Mixtral 8x7B是一个稀疏专家模型,利用多个参数提高推理速度,适合处理多语言和代码生成任务。',
|
18
17
|
displayName: 'Mixtral 8x7B',
|
19
|
-
enabled: true,
|
20
18
|
id: 'open-mixtral-8x7b',
|
21
19
|
tokens: 32_768,
|
22
20
|
},
|
@@ -57,7 +55,6 @@ const Mistral: ModelProviderCard = {
|
|
57
55
|
description:
|
58
56
|
'Codestral Mamba是专注于代码生成的Mamba 2语言模型,为先进的代码和推理任务提供强力支持。',
|
59
57
|
displayName: 'Codestral Mamba',
|
60
|
-
enabled: true,
|
61
58
|
id: 'open-codestral-mamba',
|
62
59
|
tokens: 256_000,
|
63
60
|
},
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { NextResponse } from 'next/server';
|
2
|
+
|
3
|
+
import { serverDB } from '@/database/server';
|
4
|
+
import { UserModel } from '@/database/server/models/user';
|
5
|
+
import { UserItem } from '@/database/server/schemas/lobechat';
|
6
|
+
import { pino } from '@/libs/logger';
|
7
|
+
import { LobeNextAuthDbAdapter } from '@/libs/next-auth/adapter';
|
8
|
+
|
9
|
+
export class NextAuthUserService {
|
10
|
+
userModel;
|
11
|
+
adapter;
|
12
|
+
|
13
|
+
constructor() {
|
14
|
+
this.userModel = new UserModel();
|
15
|
+
this.adapter = LobeNextAuthDbAdapter(serverDB);
|
16
|
+
}
|
17
|
+
|
18
|
+
safeUpdateUser = async (providerAccountId: string, data: Partial<UserItem>) => {
|
19
|
+
pino.info('updating user due to webhook');
|
20
|
+
// 1. Find User by account
|
21
|
+
// @ts-expect-error: Already impl in `LobeNextauthDbAdapter`
|
22
|
+
const user = await this.adapter.getUserByAccount({
|
23
|
+
provider: 'logto',
|
24
|
+
providerAccountId,
|
25
|
+
});
|
26
|
+
|
27
|
+
// 2. If found, Update user data from provider
|
28
|
+
if (user?.id) {
|
29
|
+
// Perform update
|
30
|
+
await this.userModel.updateUser(user.id, {
|
31
|
+
avatar: data?.avatar,
|
32
|
+
email: data?.email,
|
33
|
+
fullName: data?.fullName,
|
34
|
+
});
|
35
|
+
} else {
|
36
|
+
pino.warn(
|
37
|
+
`[logto]: Webhooks handler user update for "${JSON.stringify(data)}", but no user was found by the providerAccountId.`,
|
38
|
+
);
|
39
|
+
}
|
40
|
+
return NextResponse.json({ message: 'user updated', success: true }, { status: 200 });
|
41
|
+
};
|
42
|
+
}
|