@lobehub/chat 1.1.5 → 1.1.6
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.
- package/CHANGELOG.md +33 -0
- package/package.json +1 -1
- package/src/app/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +1 -1
- package/src/app/(main)/(mobile)/me/(home)/features/UserBanner.tsx +1 -1
- package/src/app/(main)/settings/llm/components/ProviderConfig/index.tsx +1 -1
- package/src/app/api/webhooks/clerk/route.ts +6 -86
- package/src/app/trpc/tools/[trpc]/route.ts +28 -0
- package/src/database/server/migrations/0003_naive_echo.sql +46 -0
- package/src/database/server/migrations/meta/0003_snapshot.json +1823 -0
- package/src/database/server/migrations/meta/_journal.json +7 -0
- package/src/database/server/models/__tests__/user.test.ts +3 -3
- package/src/database/server/models/user.ts +4 -4
- package/src/database/server/schemas/lobechat.ts +56 -5
- package/src/features/User/{UserLoginOrSignup.tsx → UserLoginOrSignup/Community.tsx} +1 -1
- package/src/features/User/UserLoginOrSignup/index.tsx +1 -0
- package/src/features/User/UserPanel/LangButton.tsx +3 -3
- package/src/features/User/UserPanel/ThemeButton.tsx +3 -3
- package/src/server/routers/lambda/importer.ts +1 -3
- package/src/server/routers/lambda/user.ts +21 -14
- package/src/server/routers/tools/index.ts +7 -0
- package/src/server/services/user/index.ts +96 -0
- package/src/services/__tests__/chat.test.ts +9 -2
- package/src/services/chat.ts +4 -0
- package/src/types/user/settings/keyVaults.ts +1 -0
- package/vitest.config.ts +7 -1
- /package/src/{database/server → server}/modules/DataImporter/__tests__/fixtures/messages.json +0 -0
- /package/src/{database/server → server}/modules/DataImporter/__tests__/index.test.ts +0 -0
- /package/src/{database/server → server}/modules/DataImporter/index.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 1.1.6](https://github.com/lobehub/lobe-chat/compare/v1.1.5...v1.1.6)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-06-23**</sup>
|
|
8
|
+
|
|
9
|
+
#### ♻ Code Refactoring
|
|
10
|
+
|
|
11
|
+
- **misc**: Refactor the server db implement.
|
|
12
|
+
|
|
13
|
+
#### 🐛 Bug Fixes
|
|
14
|
+
|
|
15
|
+
- **misc**: Fix incorrect baseURL for Groq in client mode.
|
|
16
|
+
|
|
17
|
+
<br/>
|
|
18
|
+
|
|
19
|
+
<details>
|
|
20
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
21
|
+
|
|
22
|
+
#### Code refactoring
|
|
23
|
+
|
|
24
|
+
- **misc**: Refactor the server db implement, closes [#2991](https://github.com/lobehub/lobe-chat/issues/2991) ([fa78599](https://github.com/lobehub/lobe-chat/commit/fa78599))
|
|
25
|
+
|
|
26
|
+
#### What's fixed
|
|
27
|
+
|
|
28
|
+
- **misc**: Fix incorrect baseURL for Groq in client mode, closes [#2747](https://github.com/lobehub/lobe-chat/issues/2747) ([af14225](https://github.com/lobehub/lobe-chat/commit/af14225))
|
|
29
|
+
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
<div align="right">
|
|
33
|
+
|
|
34
|
+
[](#readme-top)
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
|
+
|
|
5
38
|
### [Version 1.1.5](https://github.com/lobehub/lobe-chat/compare/v1.1.4...v1.1.5)
|
|
6
39
|
|
|
7
40
|
<sup>Released on **2024-06-23**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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",
|
|
@@ -20,7 +20,7 @@ vi.mock('@/features/User/DataStatistics', () => ({
|
|
|
20
20
|
default: vi.fn(() => <div>Mocked DataStatistics</div>),
|
|
21
21
|
}));
|
|
22
22
|
|
|
23
|
-
vi.mock('@/features/User/UserLoginOrSignup', () => ({
|
|
23
|
+
vi.mock('@/features/User/UserLoginOrSignup/Community', () => ({
|
|
24
24
|
default: vi.fn(() => <div>Mocked UserLoginOrSignup</div>),
|
|
25
25
|
}));
|
|
26
26
|
|
|
@@ -7,7 +7,7 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
7
7
|
import { enableAuth } from '@/const/auth';
|
|
8
8
|
import DataStatistics from '@/features/User/DataStatistics';
|
|
9
9
|
import UserInfo from '@/features/User/UserInfo';
|
|
10
|
-
import UserLoginOrSignup from '@/features/User/UserLoginOrSignup';
|
|
10
|
+
import UserLoginOrSignup from '@/features/User/UserLoginOrSignup/Community';
|
|
11
11
|
import { useUserStore } from '@/store/user';
|
|
12
12
|
import { authSelectors } from '@/store/user/selectors';
|
|
13
13
|
|
|
@@ -61,7 +61,7 @@ const useStyles = createStyles(({ css, prefixCls, responsive, token }) => ({
|
|
|
61
61
|
`,
|
|
62
62
|
}));
|
|
63
63
|
|
|
64
|
-
export interface ProviderConfigProps extends Omit<ModelProviderCard, 'id'> {
|
|
64
|
+
export interface ProviderConfigProps extends Omit<ModelProviderCard, 'id' | 'chatModels'> {
|
|
65
65
|
apiKeyItems?: FormItemProps[];
|
|
66
66
|
canDeactivate?: boolean;
|
|
67
67
|
checkerItem?: FormItemProps;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { UserJSON } from '@clerk/backend';
|
|
2
1
|
import { NextResponse } from 'next/server';
|
|
3
2
|
|
|
4
3
|
import { authEnv } from '@/config/auth';
|
|
5
4
|
import { isServerMode } from '@/const/version';
|
|
6
|
-
import { UserModel } from '@/database/server/models/user';
|
|
7
5
|
import { pino } from '@/libs/logger';
|
|
6
|
+
import { UserService } from '@/server/services/user';
|
|
8
7
|
|
|
9
8
|
import { validateRequest } from './validateRequest';
|
|
10
9
|
|
|
@@ -12,86 +11,6 @@ if (authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH && isServerMode && !authEnv.CLERK_WEBH
|
|
|
12
11
|
throw new Error('`CLERK_WEBHOOK_SECRET` environment variable is missing');
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
const createUser = async (id: string, params: UserJSON) => {
|
|
16
|
-
pino.info('creating user due to clerk webhook');
|
|
17
|
-
|
|
18
|
-
const userModel = new UserModel();
|
|
19
|
-
|
|
20
|
-
// Check if user already exists
|
|
21
|
-
const res = await userModel.findById(id);
|
|
22
|
-
|
|
23
|
-
// If user already exists, skip creating a new user
|
|
24
|
-
if (res)
|
|
25
|
-
return NextResponse.json(
|
|
26
|
-
{ message: 'user not created due to user already existing in the database', success: false },
|
|
27
|
-
{ status: 200 },
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const email = params.email_addresses.find((e) => e.id === params.primary_email_address_id);
|
|
31
|
-
const phone = params.phone_numbers.find((e) => e.id === params.primary_phone_number_id);
|
|
32
|
-
|
|
33
|
-
await userModel.createUser({
|
|
34
|
-
avatar: params.image_url,
|
|
35
|
-
clerkCreatedAt: new Date(params.created_at),
|
|
36
|
-
email: email?.email_address,
|
|
37
|
-
firstName: params.first_name,
|
|
38
|
-
id,
|
|
39
|
-
lastName: params.last_name,
|
|
40
|
-
phone: phone?.phone_number,
|
|
41
|
-
username: params.username,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return NextResponse.json({ message: 'user created', success: true }, { status: 200 });
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const deleteUser = async (id?: string) => {
|
|
48
|
-
if (id) {
|
|
49
|
-
pino.info('delete user due to clerk webhook');
|
|
50
|
-
const userModel = new UserModel();
|
|
51
|
-
|
|
52
|
-
await userModel.deleteUser(id);
|
|
53
|
-
|
|
54
|
-
return NextResponse.json({ message: 'user deleted' }, { status: 200 });
|
|
55
|
-
} else {
|
|
56
|
-
pino.warn('clerk sent a delete user request, but no user ID was included in the payload');
|
|
57
|
-
return NextResponse.json({ message: 'ok' }, { status: 200 });
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const updateUser = async (id: string, params: UserJSON) => {
|
|
62
|
-
pino.info('updating user due to clerk webhook');
|
|
63
|
-
|
|
64
|
-
const userModel = new UserModel();
|
|
65
|
-
|
|
66
|
-
// Check if user already exists
|
|
67
|
-
const res = await userModel.findById(id);
|
|
68
|
-
|
|
69
|
-
// If user not exists, skip update the user
|
|
70
|
-
if (!res)
|
|
71
|
-
return NextResponse.json(
|
|
72
|
-
{
|
|
73
|
-
message: "user not updated due to the user don't existing in the database",
|
|
74
|
-
success: false,
|
|
75
|
-
},
|
|
76
|
-
{ status: 200 },
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const email = params.email_addresses.find((e) => e.id === params.primary_email_address_id);
|
|
80
|
-
const phone = params.phone_numbers.find((e) => e.id === params.primary_phone_number_id);
|
|
81
|
-
|
|
82
|
-
await userModel.updateUser(id, {
|
|
83
|
-
avatar: params.image_url,
|
|
84
|
-
email: email?.email_address,
|
|
85
|
-
firstName: params.first_name,
|
|
86
|
-
id,
|
|
87
|
-
lastName: params.last_name,
|
|
88
|
-
phone: phone?.phone_number,
|
|
89
|
-
username: params.username,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return NextResponse.json({ message: 'user updated', success: true }, { status: 200 });
|
|
93
|
-
};
|
|
94
|
-
|
|
95
14
|
export const POST = async (req: Request): Promise<NextResponse> => {
|
|
96
15
|
const payload = await validateRequest(req, authEnv.CLERK_WEBHOOK_SECRET!);
|
|
97
16
|
|
|
@@ -106,22 +25,23 @@ export const POST = async (req: Request): Promise<NextResponse> => {
|
|
|
106
25
|
|
|
107
26
|
pino.trace(`clerk webhook payload: ${{ data, type }}`);
|
|
108
27
|
|
|
28
|
+
const userService = new UserService();
|
|
109
29
|
switch (type) {
|
|
110
30
|
case 'user.created': {
|
|
111
|
-
return createUser(data.id, data);
|
|
31
|
+
return userService.createUser(data.id, data);
|
|
112
32
|
}
|
|
113
33
|
case 'user.deleted': {
|
|
114
|
-
return deleteUser(data.id);
|
|
34
|
+
return userService.deleteUser(data.id);
|
|
115
35
|
}
|
|
116
36
|
case 'user.updated': {
|
|
117
|
-
return updateUser(data.id, data);
|
|
37
|
+
return userService.updateUser(data.id, data);
|
|
118
38
|
}
|
|
119
39
|
|
|
120
40
|
default: {
|
|
121
41
|
pino.warn(
|
|
122
42
|
`${req.url} received event type "${type}", but no handler is defined for this type`,
|
|
123
43
|
);
|
|
124
|
-
return NextResponse.json({ error: `
|
|
44
|
+
return NextResponse.json({ error: `unrecognised payload type: ${type}` }, { status: 400 });
|
|
125
45
|
}
|
|
126
46
|
// case 'user.updated':
|
|
127
47
|
// break;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
|
|
2
|
+
import type { NextRequest } from 'next/server';
|
|
3
|
+
|
|
4
|
+
import { pino } from '@/libs/logger';
|
|
5
|
+
import { createContext } from '@/server/context';
|
|
6
|
+
import { toolsRouter } from '@/server/routers/tools';
|
|
7
|
+
|
|
8
|
+
export const maxDuration = 120;
|
|
9
|
+
|
|
10
|
+
const handler = (req: NextRequest) =>
|
|
11
|
+
fetchRequestHandler({
|
|
12
|
+
/**
|
|
13
|
+
* @link https://trpc.io/docs/v11/context
|
|
14
|
+
*/
|
|
15
|
+
createContext: () => createContext(req),
|
|
16
|
+
|
|
17
|
+
endpoint: '/trpc/tools',
|
|
18
|
+
|
|
19
|
+
onError: ({ error, path, type }) => {
|
|
20
|
+
pino.info(`Error in tRPC handler (tools) on path: ${path}, type: ${type}`);
|
|
21
|
+
console.error(error);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
req,
|
|
25
|
+
router: toolsRouter,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { handler as GET, handler as POST };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "user_budgets" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"free_budget_id" text,
|
|
4
|
+
"free_budget_key" text,
|
|
5
|
+
"subscription_budget_id" text,
|
|
6
|
+
"subscription_budget_key" text,
|
|
7
|
+
"package_budget_id" text,
|
|
8
|
+
"package_budget_key" text,
|
|
9
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
10
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE TABLE IF NOT EXISTS "user_subscriptions" (
|
|
14
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
15
|
+
"user_id" text NOT NULL,
|
|
16
|
+
"stripe_id" text,
|
|
17
|
+
"currency" text,
|
|
18
|
+
"pricing" integer,
|
|
19
|
+
"billing_paid_at" integer,
|
|
20
|
+
"billing_cycle_start" integer,
|
|
21
|
+
"billing_cycle_end" integer,
|
|
22
|
+
"cancel_at_period_end" boolean,
|
|
23
|
+
"cancel_at" integer,
|
|
24
|
+
"next_billing" jsonb,
|
|
25
|
+
"plan" text,
|
|
26
|
+
"recurring" text,
|
|
27
|
+
"storage_limit" integer,
|
|
28
|
+
"status" integer,
|
|
29
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
30
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
31
|
+
);
|
|
32
|
+
--> statement-breakpoint
|
|
33
|
+
ALTER TABLE "users" ALTER COLUMN "preference" DROP DEFAULT;--> statement-breakpoint
|
|
34
|
+
DO $$ BEGIN
|
|
35
|
+
ALTER TABLE "user_budgets" ADD CONSTRAINT "user_budgets_id_users_id_fk" FOREIGN KEY ("id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
|
36
|
+
EXCEPTION
|
|
37
|
+
WHEN duplicate_object THEN null;
|
|
38
|
+
END $$;
|
|
39
|
+
--> statement-breakpoint
|
|
40
|
+
DO $$ BEGIN
|
|
41
|
+
ALTER TABLE "user_subscriptions" ADD CONSTRAINT "user_subscriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
|
42
|
+
EXCEPTION
|
|
43
|
+
WHEN duplicate_object THEN null;
|
|
44
|
+
END $$;
|
|
45
|
+
--> statement-breakpoint
|
|
46
|
+
ALTER TABLE "users" DROP COLUMN IF EXISTS "key";
|