@lobehub/lobehub 2.0.0-next.21 → 2.0.0-next.22
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 +17 -0
- package/apps/desktop/package.json +1 -1
- package/apps/desktop/src/main/controllers/AuthCtr.ts +3 -3
- package/apps/desktop/src/main/controllers/MenuCtr.ts +5 -5
- package/apps/desktop/src/main/controllers/NotificationCtr.ts +29 -29
- package/apps/desktop/src/main/controllers/RemoteServerConfigCtr.ts +16 -16
- package/apps/desktop/src/main/controllers/ShortcutCtr.ts +2 -2
- package/apps/desktop/src/main/controllers/TrayMenuCtr.ts +18 -18
- package/apps/desktop/src/main/controllers/UpdaterCtr.ts +4 -4
- package/apps/desktop/src/main/controllers/__tests__/TrayMenuCtr.test.ts +5 -5
- package/apps/desktop/src/main/controllers/index.ts +4 -4
- package/changelog/v1.json +5 -0
- package/docs/development/database-schema.dbml +2 -1
- package/package.json +2 -2
- package/packages/database/migrations/0042_improve_agent_index.sql +1 -0
- package/packages/database/migrations/meta/0042_snapshot.json +7800 -0
- package/packages/database/migrations/meta/_journal.json +7 -0
- package/packages/database/src/core/migrations.json +8 -0
- package/packages/database/src/models/agent.ts +16 -13
- package/packages/database/src/models/session.ts +20 -9
- package/packages/database/src/models/user.ts +2 -1
- package/packages/database/src/schemas/agent.ts +4 -1
- package/packages/types/src/message/ui/params.ts +1 -1
- package/src/server/routers/lambda/message.ts +0 -2
- package/src/server/routers/lambda/user.ts +8 -6
|
@@ -294,6 +294,13 @@
|
|
|
294
294
|
"when": 1761878697451,
|
|
295
295
|
"tag": "0041_improve_index",
|
|
296
296
|
"breakpoints": true
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"idx": 42,
|
|
300
|
+
"version": "7",
|
|
301
|
+
"when": 1762232313711,
|
|
302
|
+
"tag": "0042_improve_agent_index",
|
|
303
|
+
"breakpoints": true
|
|
297
304
|
}
|
|
298
305
|
],
|
|
299
306
|
"version": "6"
|
|
@@ -746,5 +746,13 @@
|
|
|
746
746
|
"bps": true,
|
|
747
747
|
"folderMillis": 1761878697451,
|
|
748
748
|
"hash": "2f740719356c4ea28a4f71b6089595871f6e185e056b43288a7d16f7d0aae196"
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
"sql": [
|
|
752
|
+
"CREATE INDEX \"agents_knowledge_bases_agent_id_idx\" ON \"agents_knowledge_bases\" USING btree (\"agent_id\");"
|
|
753
|
+
],
|
|
754
|
+
"bps": true,
|
|
755
|
+
"folderMillis": 1762232313711,
|
|
756
|
+
"hash": "8988ec15592e000430d76566323f437b2ebde46122c5f7172067cd0a65f99614"
|
|
749
757
|
}
|
|
750
758
|
]
|
|
@@ -28,19 +28,21 @@ export class AgentModel {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
getAgentAssignedKnowledge = async (id: string) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
// Run both queries in parallel for better performance
|
|
32
|
+
const [knowledgeBaseResult, fileResult] = await Promise.all([
|
|
33
|
+
this.db
|
|
34
|
+
.select({ enabled: agentsKnowledgeBases.enabled, knowledgeBases })
|
|
35
|
+
.from(agentsKnowledgeBases)
|
|
36
|
+
.where(eq(agentsKnowledgeBases.agentId, id))
|
|
37
|
+
.orderBy(desc(agentsKnowledgeBases.createdAt))
|
|
38
|
+
.leftJoin(knowledgeBases, eq(knowledgeBases.id, agentsKnowledgeBases.knowledgeBaseId)),
|
|
39
|
+
this.db
|
|
40
|
+
.select({ enabled: agentsFiles.enabled, files })
|
|
41
|
+
.from(agentsFiles)
|
|
42
|
+
.where(eq(agentsFiles.agentId, id))
|
|
43
|
+
.orderBy(desc(agentsFiles.createdAt))
|
|
44
|
+
.leftJoin(files, eq(files.id, agentsFiles.fileId)),
|
|
45
|
+
]);
|
|
44
46
|
|
|
45
47
|
return {
|
|
46
48
|
files: fileResult.map((item) => ({
|
|
@@ -61,6 +63,7 @@ export class AgentModel {
|
|
|
61
63
|
const item = await this.db.query.agentsToSessions.findFirst({
|
|
62
64
|
where: eq(agentsToSessions.sessionId, sessionId),
|
|
63
65
|
});
|
|
66
|
+
|
|
64
67
|
if (!item) return;
|
|
65
68
|
|
|
66
69
|
const agentId = item.agentId;
|
|
@@ -123,17 +123,28 @@ export class SessionModel {
|
|
|
123
123
|
findByIdOrSlug = async (
|
|
124
124
|
idOrSlug: string,
|
|
125
125
|
): Promise<(SessionItem & { agent: AgentItem }) | undefined> => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
// Use leftJoin instead of nested 'with' for better performance
|
|
127
|
+
const result = await this.db
|
|
128
|
+
.select({
|
|
129
|
+
agent: agents,
|
|
130
|
+
group: sessionGroups,
|
|
131
|
+
session: sessions,
|
|
132
|
+
})
|
|
133
|
+
.from(sessions)
|
|
134
|
+
.where(
|
|
135
|
+
and(
|
|
136
|
+
or(eq(sessions.id, idOrSlug), eq(sessions.slug, idOrSlug)),
|
|
137
|
+
eq(sessions.userId, this.userId),
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
.leftJoin(agentsToSessions, eq(sessions.id, agentsToSessions.sessionId))
|
|
141
|
+
.leftJoin(agents, eq(agentsToSessions.agentId, agents.id))
|
|
142
|
+
.leftJoin(sessionGroups, eq(sessions.groupId, sessionGroups.id))
|
|
143
|
+
.limit(1);
|
|
133
144
|
|
|
134
|
-
if (!result) return;
|
|
145
|
+
if (!result || !result[0]) return;
|
|
135
146
|
|
|
136
|
-
return { ...result, agent:
|
|
147
|
+
return { ...result[0].session, agent: result[0].agent, group: result[0].group } as any;
|
|
137
148
|
};
|
|
138
149
|
|
|
139
150
|
count = async (params?: {
|
|
@@ -82,7 +82,8 @@ export class UserModel {
|
|
|
82
82
|
})
|
|
83
83
|
.from(users)
|
|
84
84
|
.where(eq(users.id, this.userId))
|
|
85
|
-
.leftJoin(userSettings, eq(users.id, userSettings.id))
|
|
85
|
+
.leftJoin(userSettings, eq(users.id, userSettings.id))
|
|
86
|
+
.limit(1);
|
|
86
87
|
|
|
87
88
|
if (!result || !result[0]) {
|
|
88
89
|
throw new UserNotFoundError();
|
|
@@ -90,7 +90,10 @@ export const agentsKnowledgeBases = pgTable(
|
|
|
90
90
|
|
|
91
91
|
...timestamps,
|
|
92
92
|
},
|
|
93
|
-
(t) => [
|
|
93
|
+
(t) => [
|
|
94
|
+
primaryKey({ columns: [t.agentId, t.knowledgeBaseId] }),
|
|
95
|
+
index('agents_knowledge_bases_agent_id_idx').on(t.agentId),
|
|
96
|
+
],
|
|
94
97
|
);
|
|
95
98
|
|
|
96
99
|
export const agentsFiles = pgTable(
|
|
@@ -180,7 +180,7 @@ export const CreateNewMessageParamsSchema = z
|
|
|
180
180
|
plugin: ChatPluginPayloadSchema.optional(),
|
|
181
181
|
// Grouping
|
|
182
182
|
parentId: z.string().optional(),
|
|
183
|
-
groupId: z.string().optional(),
|
|
183
|
+
groupId: z.string().nullable().optional(),
|
|
184
184
|
// Context
|
|
185
185
|
topicId: z.string().optional(),
|
|
186
186
|
threadId: z.string().nullable().optional(),
|
|
@@ -30,7 +30,9 @@ const userProcedure = authedProcedure.use(serverDatabase).use(async ({ ctx, next
|
|
|
30
30
|
ctx: {
|
|
31
31
|
clerkAuth: new ClerkAuth(),
|
|
32
32
|
fileService: new FileService(ctx.serverDB, ctx.userId),
|
|
33
|
+
messageModel: new MessageModel(ctx.serverDB, ctx.userId),
|
|
33
34
|
nextAuthUserService: new NextAuthUserService(ctx.serverDB),
|
|
35
|
+
sessionModel: new SessionModel(ctx.serverDB, ctx.userId),
|
|
34
36
|
userModel: new UserModel(ctx.serverDB, ctx.userId),
|
|
35
37
|
},
|
|
36
38
|
});
|
|
@@ -97,12 +99,12 @@ export const userRouter = router({
|
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
const hasMoreThan4Messages = await
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
// Run all count queries in parallel
|
|
103
|
+
const [hasMoreThan4Messages, hasAnyMessages, hasExtraSession] = await Promise.all([
|
|
104
|
+
ctx.messageModel.hasMoreThanN(4),
|
|
105
|
+
ctx.messageModel.hasMoreThanN(0),
|
|
106
|
+
ctx.sessionModel.hasMoreThanN(1),
|
|
107
|
+
]);
|
|
106
108
|
|
|
107
109
|
return {
|
|
108
110
|
avatar: state.avatar,
|