@lobehub/lobehub 2.0.0-next.376 → 2.0.0-next.378
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 +67 -0
- package/changelog/v1.json +21 -0
- package/docs/development/database-schema.dbml +51 -0
- package/docs/self-hosting/advanced/auth/providers/casdoor.mdx +1 -1
- package/docs/self-hosting/advanced/auth/providers/casdoor.zh-CN.mdx +1 -1
- package/docs/self-hosting/advanced/auth/providers/logto.mdx +1 -1
- package/docs/self-hosting/advanced/auth/providers/logto.zh-CN.mdx +1 -1
- package/package.json +1 -2
- package/packages/database/migrations/0075_add_user_memory_persona.sql +51 -0
- package/packages/database/migrations/meta/0075_snapshot.json +11957 -0
- package/packages/database/migrations/meta/_journal.json +8 -1
- package/packages/database/src/schemas/userMemories/persona.ts +81 -0
- package/scripts/_shared/checkDeprecatedAuth.js +46 -16
- package/scripts/_shared/checkDeprecatedAuth.test.ts +180 -0
- package/src/app/(backend)/api/webhooks/casdoor/route.ts +1 -2
- package/src/app/(backend)/api/webhooks/logto/route.ts +2 -3
- package/src/app/(backend)/trpc/async/[trpc]/route.ts +1 -2
- package/src/app/(backend)/trpc/mobile/[trpc]/route.ts +1 -2
- package/src/app/[variants]/(main)/agent/profile/features/ProfileEditor/index.tsx +1 -0
- package/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/AgentProfilePopup.tsx +9 -0
- package/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/GroupMember.tsx +27 -2
- package/src/app/[variants]/(main)/home/_layout/Body/Agent/Actions.tsx +1 -1
- package/src/app/[variants]/(main)/home/features/InputArea/SkillInstallBanner.tsx +40 -32
- package/src/app/[variants]/(main)/memory/(home)/index.tsx +1 -1
- package/src/app/[variants]/(main)/memory/contexts/index.tsx +2 -0
- package/src/app/[variants]/(main)/memory/experiences/index.tsx +2 -0
- package/src/app/[variants]/(main)/memory/features/MemoryAnalysis/Action.tsx +13 -2
- package/src/app/[variants]/(main)/memory/features/MemoryAnalysis/AnalysisTrigger.tsx +26 -13
- package/src/app/[variants]/(main)/memory/features/MemoryAnalysis/index.tsx +10 -1
- package/src/app/[variants]/(main)/memory/identities/index.tsx +2 -0
- package/src/app/[variants]/(main)/memory/preferences/index.tsx +2 -0
- package/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx +7 -3
- package/src/app/[variants]/(main)/settings/skill/features/KlavisSkillItem.tsx +30 -30
- package/src/app/[variants]/(main)/settings/skill/features/LobehubSkillItem.tsx +31 -31
- package/src/app/[variants]/(main)/settings/skill/index.tsx +2 -2
- package/src/components/FileParsingStatus/EmbeddingStatus.tsx +3 -16
- package/src/components/FileParsingStatus/index.tsx +2 -15
- package/src/features/ChatInput/ActionBar/Tools/PopoverContent.tsx +1 -3
- package/src/features/ChatInput/ActionBar/Tools/ToolsList.tsx +4 -0
- package/src/features/ChatInput/ActionBar/Tools/index.tsx +1 -10
- package/src/features/ChatInput/ActionBar/Tools/useControls.tsx +41 -16
- package/src/features/ChatInput/ActionBar/components/ActionDropdown.tsx +2 -1
- package/src/features/Conversation/ChatItem/components/Title.tsx +6 -2
- package/src/features/ModelSelect/index.tsx +10 -3
- package/src/features/ProfileEditor/AgentTool.tsx +52 -33
- package/src/features/ProfileEditor/PopoverContent.tsx +28 -61
- package/src/features/SharePopover/index.tsx +3 -3
- package/src/features/SkillStore/CommunityList/Item.tsx +2 -1
- package/src/features/SkillStore/CommunityList/index.tsx +16 -22
- package/src/features/SkillStore/CustomList/Item.tsx +2 -1
- package/src/features/SkillStore/CustomList/index.tsx +11 -31
- package/src/features/SkillStore/LobeHubList/Item.tsx +4 -3
- package/src/features/SkillStore/LobeHubList/index.tsx +2 -18
- package/src/features/SkillStore/Search/index.tsx +1 -1
- package/src/features/SkillStore/index.tsx +6 -3
- package/src/features/SkillStore/style.ts +34 -1
- package/src/libs/next/config/define-config.ts +0 -3
- package/src/server/routers/lambda/agent.ts +1 -2
- package/src/server/services/user/index.ts +1 -2
- package/src/server/services/webhookUser/index.test.ts +290 -0
- package/src/server/services/webhookUser/index.ts +29 -12
- package/src/libs/logger/index.ts +0 -5
|
@@ -3,8 +3,7 @@ import { and, eq } from 'drizzle-orm';
|
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
|
|
5
5
|
import { UserModel } from '@/database/models/user';
|
|
6
|
-
import { type UserItem, account, session } from '@/database/schemas';
|
|
7
|
-
import { pino } from '@/libs/logger';
|
|
6
|
+
import { type UserItem, account, nextauthAccounts, session, users } from '@/database/schemas';
|
|
8
7
|
|
|
9
8
|
export class WebhookUserService {
|
|
10
9
|
private db: LobeChatDatabase;
|
|
@@ -14,7 +13,9 @@ export class WebhookUserService {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* Find user by provider account info
|
|
16
|
+
* Find user by provider account info.
|
|
17
|
+
* First checks Better Auth accounts table, then falls back to NextAuth accounts table
|
|
18
|
+
* for users who performed simple migration (without migrating accounts data).
|
|
18
19
|
*/
|
|
19
20
|
private getUserByAccount = async ({
|
|
20
21
|
providerId,
|
|
@@ -23,15 +24,31 @@ export class WebhookUserService {
|
|
|
23
24
|
accountId: string;
|
|
24
25
|
providerId: string;
|
|
25
26
|
}) => {
|
|
26
|
-
|
|
27
|
+
// First, try Better Auth accounts table
|
|
28
|
+
const betterAuthAccount = await this.db.query.account.findFirst({
|
|
27
29
|
where: and(eq(account.providerId, providerId), eq(account.accountId, accountId)),
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
if (
|
|
32
|
+
if (betterAuthAccount) {
|
|
33
|
+
return this.db.query.users.findFirst({
|
|
34
|
+
where: eq(users.id, betterAuthAccount.userId),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
// Fallback to NextAuth accounts table for simple migration users
|
|
39
|
+
const nextAuthAccount = await this.db
|
|
40
|
+
.select({ users })
|
|
41
|
+
.from(nextauthAccounts)
|
|
42
|
+
.innerJoin(users, eq(nextauthAccounts.userId, users.id))
|
|
43
|
+
.where(
|
|
44
|
+
and(
|
|
45
|
+
eq(nextauthAccounts.provider, providerId),
|
|
46
|
+
eq(nextauthAccounts.providerAccountId, accountId),
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
.then((res) => res[0]);
|
|
50
|
+
|
|
51
|
+
return nextAuthAccount?.users ?? null;
|
|
35
52
|
};
|
|
36
53
|
|
|
37
54
|
/**
|
|
@@ -41,7 +58,7 @@ export class WebhookUserService {
|
|
|
41
58
|
{ accountId, providerId }: { accountId: string; providerId: string },
|
|
42
59
|
data: Partial<UserItem>,
|
|
43
60
|
) => {
|
|
44
|
-
|
|
61
|
+
console.log(`updating user "${JSON.stringify({ accountId, providerId })}" due to webhook`);
|
|
45
62
|
|
|
46
63
|
const user = await this.getUserByAccount({ accountId, providerId });
|
|
47
64
|
|
|
@@ -53,7 +70,7 @@ export class WebhookUserService {
|
|
|
53
70
|
fullName: data?.fullName,
|
|
54
71
|
});
|
|
55
72
|
} else {
|
|
56
|
-
|
|
73
|
+
console.warn(
|
|
57
74
|
`[${providerId}]: Webhook user "${JSON.stringify({ accountId, providerId })}" update for "${JSON.stringify(data)}", but no user was found.`,
|
|
58
75
|
);
|
|
59
76
|
}
|
|
@@ -71,14 +88,14 @@ export class WebhookUserService {
|
|
|
71
88
|
accountId: string;
|
|
72
89
|
providerId: string;
|
|
73
90
|
}) => {
|
|
74
|
-
|
|
91
|
+
console.log(`Signing out user "${JSON.stringify({ accountId, providerId })}"`);
|
|
75
92
|
|
|
76
93
|
const user = await this.getUserByAccount({ accountId, providerId });
|
|
77
94
|
|
|
78
95
|
if (user?.id) {
|
|
79
96
|
await this.db.delete(session).where(eq(session.userId, user.id));
|
|
80
97
|
} else {
|
|
81
|
-
|
|
98
|
+
console.warn(
|
|
82
99
|
`[${providerId}]: Webhook user "${JSON.stringify({ accountId, providerId })}" signout, but no user was found.`,
|
|
83
100
|
);
|
|
84
101
|
}
|