@lobehub/chat 1.36.31 → 1.36.32

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 (42) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/docs/self-hosting/environment-variables/model-provider.mdx +7 -0
  4. package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +7 -0
  5. package/docs/self-hosting/server-database/dokploy.zh-CN.mdx +12 -12
  6. package/package.json +1 -1
  7. package/src/database/repositories/dataImporter/__tests__/index.test.ts +11 -18
  8. package/src/database/repositories/dataImporter/index.ts +31 -46
  9. package/src/database/server/models/__tests__/_test_template.ts +1 -1
  10. package/src/database/server/models/__tests__/agent.test.ts +1 -1
  11. package/src/database/server/models/__tests__/asyncTask.test.ts +1 -1
  12. package/src/database/server/models/__tests__/chunk.test.ts +1 -1
  13. package/src/database/server/models/__tests__/file.test.ts +1 -1
  14. package/src/database/server/models/__tests__/knowledgeBase.test.ts +1 -2
  15. package/src/database/server/models/__tests__/message.test.ts +35 -72
  16. package/src/database/server/models/__tests__/nextauth.test.ts +1 -1
  17. package/src/database/server/models/__tests__/session.test.ts +1 -1
  18. package/src/database/server/models/__tests__/sessionGroup.test.ts +1 -2
  19. package/src/database/server/models/__tests__/topic.test.ts +1 -1
  20. package/src/database/server/models/__tests__/user.test.ts +1 -1
  21. package/src/database/server/models/_template.ts +2 -2
  22. package/src/database/server/models/agent.ts +17 -25
  23. package/src/database/server/models/asyncTask.ts +2 -2
  24. package/src/database/server/models/chunk.ts +14 -14
  25. package/src/database/server/models/embedding.ts +1 -1
  26. package/src/database/server/models/file.ts +8 -10
  27. package/src/database/server/models/knowledgeBase.ts +4 -6
  28. package/src/database/server/models/message.ts +54 -65
  29. package/src/database/server/models/plugin.ts +2 -2
  30. package/src/database/server/models/ragEval/dataset.ts +2 -2
  31. package/src/database/server/models/ragEval/datasetRecord.ts +3 -8
  32. package/src/database/server/models/ragEval/evaluation.ts +3 -2
  33. package/src/database/server/models/ragEval/evaluationRecord.ts +2 -2
  34. package/src/database/server/models/session.ts +38 -35
  35. package/src/database/server/models/sessionGroup.ts +4 -4
  36. package/src/database/server/models/thread.ts +2 -2
  37. package/src/database/server/models/topic.ts +48 -53
  38. package/src/database/server/models/user.ts +12 -12
  39. package/src/libs/agent-runtime/utils/streams/azureOpenai.test.ts +0 -1
  40. package/src/libs/next-auth/adapter/index.ts +1 -1
  41. package/src/server/routers/lambda/chunk.ts +2 -2
  42. package/vercel.json +1 -1
@@ -1,4 +1,4 @@
1
- import { eq, inArray } from 'drizzle-orm';
1
+ import { eq, inArray } from 'drizzle-orm/expressions';
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import { getTestDBInstance } from '@/database/server/core/dbForTest';
@@ -1,4 +1,4 @@
1
- import { eq } from 'drizzle-orm';
1
+ import { eq } from 'drizzle-orm/expressions';
2
2
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import { INBOX_SESSION_ID } from '@/const/session';
@@ -45,10 +45,10 @@ export class TemplateModel {
45
45
  });
46
46
  };
47
47
 
48
- async update(id: string, value: Partial<SessionGroupItem>) {
48
+ update = async (id: string, value: Partial<SessionGroupItem>) => {
49
49
  return this.db
50
50
  .update(sessionGroups)
51
51
  .set({ ...value, updatedAt: new Date() })
52
52
  .where(and(eq(sessionGroups.id, id), eq(sessionGroups.userId, this.userId)));
53
- }
53
+ };
54
54
  }
@@ -19,15 +19,15 @@ export class AgentModel {
19
19
  this.db = db;
20
20
  }
21
21
 
22
- async getAgentConfigById(id: string) {
22
+ getAgentConfigById = async (id: string) => {
23
23
  const agent = await this.db.query.agents.findFirst({ where: eq(agents.id, id) });
24
24
 
25
25
  const knowledge = await this.getAgentAssignedKnowledge(id);
26
26
 
27
27
  return { ...agent, ...knowledge };
28
- }
28
+ };
29
29
 
30
- async getAgentAssignedKnowledge(id: string) {
30
+ getAgentAssignedKnowledge = async (id: string) => {
31
31
  const knowledgeBaseResult = await this.db
32
32
  .select({ enabled: agentsKnowledgeBases.enabled, knowledgeBases })
33
33
  .from(agentsKnowledgeBases)
@@ -52,12 +52,12 @@ export class AgentModel {
52
52
  enabled: item.enabled,
53
53
  })),
54
54
  };
55
- }
55
+ };
56
56
 
57
57
  /**
58
58
  * Find agent by session id
59
59
  */
60
- async findBySessionId(sessionId: string) {
60
+ findBySessionId = async (sessionId: string) => {
61
61
  const item = await this.db.query.agentsToSessions.findFirst({
62
62
  where: eq(agentsToSessions.sessionId, sessionId),
63
63
  });
@@ -66,22 +66,19 @@ export class AgentModel {
66
66
  const agentId = item.agentId;
67
67
 
68
68
  return this.getAgentConfigById(agentId);
69
- }
69
+ };
70
70
 
71
71
  createAgentKnowledgeBase = async (
72
72
  agentId: string,
73
73
  knowledgeBaseId: string,
74
74
  enabled: boolean = true,
75
75
  ) => {
76
- return this.db
77
- .insert(agentsKnowledgeBases)
78
- .values({
79
- agentId,
80
- enabled,
81
- knowledgeBaseId,
82
- userId: this.userId,
83
- })
84
- .execute();
76
+ return this.db.insert(agentsKnowledgeBases).values({
77
+ agentId,
78
+ enabled,
79
+ knowledgeBaseId,
80
+ userId: this.userId,
81
+ });
85
82
  };
86
83
 
87
84
  deleteAgentKnowledgeBase = async (agentId: string, knowledgeBaseId: string) => {
@@ -93,8 +90,7 @@ export class AgentModel {
93
90
  eq(agentsKnowledgeBases.knowledgeBaseId, knowledgeBaseId),
94
91
  eq(agentsKnowledgeBases.userId, this.userId),
95
92
  ),
96
- )
97
- .execute();
93
+ );
98
94
  };
99
95
 
100
96
  toggleKnowledgeBase = async (agentId: string, knowledgeBaseId: string, enabled?: boolean) => {
@@ -107,8 +103,7 @@ export class AgentModel {
107
103
  eq(agentsKnowledgeBases.knowledgeBaseId, knowledgeBaseId),
108
104
  eq(agentsKnowledgeBases.userId, this.userId),
109
105
  ),
110
- )
111
- .execute();
106
+ );
112
107
  };
113
108
 
114
109
  createAgentFiles = async (agentId: string, fileIds: string[], enabled: boolean = true) => {
@@ -134,8 +129,7 @@ export class AgentModel {
134
129
  .insert(agentsFiles)
135
130
  .values(
136
131
  needToInsertFileIds.map((fileId) => ({ agentId, enabled, fileId, userId: this.userId })),
137
- )
138
- .execute();
132
+ );
139
133
  };
140
134
 
141
135
  deleteAgentFile = async (agentId: string, fileId: string) => {
@@ -147,8 +141,7 @@ export class AgentModel {
147
141
  eq(agentsFiles.fileId, fileId),
148
142
  eq(agentsFiles.userId, this.userId),
149
143
  ),
150
- )
151
- .execute();
144
+ );
152
145
  };
153
146
 
154
147
  toggleFile = async (agentId: string, fileId: string, enabled?: boolean) => {
@@ -161,7 +154,6 @@ export class AgentModel {
161
154
  eq(agentsFiles.fileId, fileId),
162
155
  eq(agentsFiles.userId, this.userId),
163
156
  ),
164
- )
165
- .execute();
157
+ );
166
158
  };
167
159
  }
@@ -64,7 +64,7 @@ export class AsyncTaskModel {
64
64
  /**
65
65
  * make the task status to be `error` if the task is not finished in 20 seconds
66
66
  */
67
- async checkTimeoutTasks(ids: string[]) {
67
+ checkTimeoutTasks = async (ids: string[]) => {
68
68
  const tasks = await this.db
69
69
  .select({ id: asyncTasks.id })
70
70
  .from(asyncTasks)
@@ -93,5 +93,5 @@ export class AsyncTaskModel {
93
93
  ),
94
94
  );
95
95
  }
96
- }
96
+ };
97
97
  }
@@ -76,7 +76,7 @@ export class ChunkModel {
76
76
  });
77
77
  };
78
78
 
79
- async findByFileId(id: string, page = 0) {
79
+ findByFileId = async (id: string, page = 0) => {
80
80
  const data = await this.db
81
81
  .select({
82
82
  abstract: chunks.abstract,
@@ -100,9 +100,9 @@ export class ChunkModel {
100
100
 
101
101
  return { ...item, metadata, pageNumber: metadata?.pageNumber } as FileChunk;
102
102
  });
103
- }
103
+ };
104
104
 
105
- async getChunksTextByFileId(id: string): Promise<{ id: string; text: string }[]> {
105
+ getChunksTextByFileId = async (id: string): Promise<{ id: string; text: string }[]> => {
106
106
  const data = await this.db
107
107
  .select()
108
108
  .from(chunks)
@@ -113,9 +113,9 @@ export class ChunkModel {
113
113
  .map((item) => item.chunks)
114
114
  .map((chunk) => ({ id: chunk.id, text: this.mapChunkText(chunk) }))
115
115
  .filter((chunk) => chunk.text) as { id: string; text: string }[];
116
- }
116
+ };
117
117
 
118
- async countByFileIds(ids: string[]) {
118
+ countByFileIds = async (ids: string[]) => {
119
119
  if (ids.length === 0) return [];
120
120
 
121
121
  return this.db
@@ -126,9 +126,9 @@ export class ChunkModel {
126
126
  .from(fileChunks)
127
127
  .where(inArray(fileChunks.fileId, ids))
128
128
  .groupBy(fileChunks.fileId);
129
- }
129
+ };
130
130
 
131
- async countByFileId(ids: string) {
131
+ countByFileId = async (ids: string) => {
132
132
  const data = await this.db
133
133
  .select({
134
134
  count: count(fileChunks.chunkId),
@@ -139,16 +139,16 @@ export class ChunkModel {
139
139
  .groupBy(fileChunks.fileId);
140
140
 
141
141
  return data[0]?.count ?? 0;
142
- }
142
+ };
143
143
 
144
- async semanticSearch({
144
+ semanticSearch = async ({
145
145
  embedding,
146
146
  fileIds,
147
147
  }: {
148
148
  embedding: number[];
149
149
  fileIds: string[] | undefined;
150
150
  query: string;
151
- }) {
151
+ }) => {
152
152
  const similarity = sql<number>`1 - (${cosineDistance(embeddings.embeddings, embedding)})`;
153
153
 
154
154
  const data = await this.db
@@ -174,16 +174,16 @@ export class ChunkModel {
174
174
  ...item,
175
175
  metadata: item.metadata as ChunkMetadata,
176
176
  }));
177
- }
177
+ };
178
178
 
179
- async semanticSearchForChat({
179
+ semanticSearchForChat = async ({
180
180
  embedding,
181
181
  fileIds,
182
182
  }: {
183
183
  embedding: number[];
184
184
  fileIds: string[] | undefined;
185
185
  query: string;
186
- }) {
186
+ }) => {
187
187
  const similarity = sql<number>`1 - (${cosineDistance(embeddings.embeddings, embedding)})`;
188
188
 
189
189
  const hasFiles = fileIds && fileIds.length > 0;
@@ -219,7 +219,7 @@ export class ChunkModel {
219
219
  text: this.mapChunkText(item),
220
220
  };
221
221
  });
222
- }
222
+ };
223
223
 
224
224
  private mapChunkText = (chunk: { metadata: any; text: string | null; type: string | null }) => {
225
225
  let text = chunk.text;
@@ -50,7 +50,7 @@ export class EmbeddingModel {
50
50
  });
51
51
  };
52
52
 
53
- countUsage = async () => {
53
+ countUsage = async (): Promise<number> => {
54
54
  const result = await this.db
55
55
  .select({
56
56
  count: count(),
@@ -1,5 +1,5 @@
1
- import { asc, count, eq, ilike, inArray, notExists, or, sum } from 'drizzle-orm';
2
- import { and, desc, like } from 'drizzle-orm/expressions';
1
+ import { count, sum } from 'drizzle-orm';
2
+ import { and, asc, desc, eq, ilike, inArray, like, notExists, or } from 'drizzle-orm/expressions';
3
3
  import type { PgTransaction } from 'drizzle-orm/pg-core';
4
4
 
5
5
  import { LobeChatDatabase } from '@/database/type';
@@ -276,12 +276,11 @@ export class FileModel {
276
276
  return result[0].count;
277
277
  };
278
278
 
279
- async update(id: string, value: Partial<FileItem>) {
280
- return this.db
279
+ update = async (id: string, value: Partial<FileItem>) =>
280
+ this.db
281
281
  .update(files)
282
282
  .set({ ...value, updatedAt: new Date() })
283
283
  .where(and(eq(files.id, id), eq(files.userId, this.userId)));
284
- }
285
284
 
286
285
  /**
287
286
  * get the corresponding file type prefix according to FilesTabs
@@ -306,17 +305,16 @@ export class FileModel {
306
305
  }
307
306
  };
308
307
 
309
- async findByNames(fileNames: string[]) {
310
- return this.db.query.files.findMany({
308
+ findByNames = async (fileNames: string[]) =>
309
+ this.db.query.files.findMany({
311
310
  where: and(
312
311
  or(...fileNames.map((name) => like(files.name, `${name}%`))),
313
312
  eq(files.userId, this.userId),
314
313
  ),
315
314
  });
316
- }
317
315
 
318
316
  // 抽象出通用的删除 chunks 方法
319
- private async deleteFileChunks(trx: PgTransaction<any>, fileIds: string[]) {
317
+ private deleteFileChunks = async (trx: PgTransaction<any>, fileIds: string[]) => {
320
318
  const BATCH_SIZE = 1000; // 每批处理的数量
321
319
 
322
320
  // 1. 获取所有关联的 chunk IDs
@@ -339,5 +337,5 @@ export class FileModel {
339
337
  }
340
338
 
341
339
  return chunkIds;
342
- }
340
+ };
343
341
  }
@@ -80,16 +80,14 @@ export class KnowledgeBaseModel {
80
80
  };
81
81
 
82
82
  // update
83
- async update(id: string, value: Partial<KnowledgeBaseItem>) {
84
- return this.db
83
+ update = async (id: string, value: Partial<KnowledgeBaseItem>) =>
84
+ this.db
85
85
  .update(knowledgeBases)
86
86
  .set({ ...value, updatedAt: new Date() })
87
87
  .where(and(eq(knowledgeBases.id, id), eq(knowledgeBases.userId, this.userId)));
88
- }
89
88
 
90
- static async findById(db: LobeChatDatabase, id: string) {
91
- return db.query.knowledgeBases.findFirst({
89
+ static findById = async (db: LobeChatDatabase, id: string) =>
90
+ db.query.knowledgeBases.findFirst({
92
91
  where: eq(knowledgeBases.id, id),
93
92
  });
94
- }
95
93
  }
@@ -46,10 +46,10 @@ export class MessageModel {
46
46
  }
47
47
 
48
48
  // **************** Query *************** //
49
- async query(
49
+ query = async (
50
50
  { current = 0, pageSize = 1000, sessionId, topicId }: QueryMessageParams = {},
51
51
  options: { postProcessUrl?: (path: string | null) => Promise<string> } = {},
52
- ): Promise<MessageItem[]> {
52
+ ): Promise<MessageItem[]> => {
53
53
  const offset = current * pageSize;
54
54
 
55
55
  // 1. get basic messages
@@ -212,15 +212,15 @@ export class MessageModel {
212
212
  };
213
213
  },
214
214
  );
215
- }
215
+ };
216
216
 
217
- async findById(id: string) {
217
+ findById = async (id: string) => {
218
218
  return this.db.query.messages.findFirst({
219
219
  where: and(eq(messages.id, id), eq(messages.userId, this.userId)),
220
220
  });
221
- }
221
+ };
222
222
 
223
- async findMessageQueriesById(messageId: string) {
223
+ findMessageQueriesById = async (messageId: string) => {
224
224
  const result = await this.db
225
225
  .select({
226
226
  embeddings: embeddings.embeddings,
@@ -236,47 +236,43 @@ export class MessageModel {
236
236
  if (result.length === 0) return undefined;
237
237
 
238
238
  return result[0];
239
- }
239
+ };
240
240
 
241
- async queryAll(): Promise<MessageItem[]> {
241
+ queryAll = async (): Promise<MessageItem[]> => {
242
242
  return this.db
243
243
  .select()
244
244
  .from(messages)
245
245
  .orderBy(messages.createdAt)
246
- .where(eq(messages.userId, this.userId))
247
-
248
- .execute();
249
- }
246
+ .where(eq(messages.userId, this.userId));
247
+ };
250
248
 
251
- async queryBySessionId(sessionId?: string | null): Promise<MessageItem[]> {
249
+ queryBySessionId = async (sessionId?: string | null): Promise<MessageItem[]> => {
252
250
  return this.db.query.messages.findMany({
253
251
  orderBy: [asc(messages.createdAt)],
254
252
  where: and(eq(messages.userId, this.userId), this.matchSession(sessionId)),
255
253
  });
256
- }
254
+ };
257
255
 
258
- async queryByKeyword(keyword: string): Promise<MessageItem[]> {
256
+ queryByKeyword = async (keyword: string): Promise<MessageItem[]> => {
259
257
  if (!keyword) return [];
260
-
261
258
  return this.db.query.messages.findMany({
262
259
  orderBy: [desc(messages.createdAt)],
263
260
  where: and(eq(messages.userId, this.userId), like(messages.content, `%${keyword}%`)),
264
261
  });
265
- }
262
+ };
266
263
 
267
- async count() {
264
+ count = async (): Promise<number> => {
268
265
  const result = await this.db
269
266
  .select({
270
- count: count(),
267
+ count: count(messages.id),
271
268
  })
272
269
  .from(messages)
273
- .where(eq(messages.userId, this.userId))
274
- .execute();
270
+ .where(eq(messages.userId, this.userId));
275
271
 
276
272
  return result[0].count;
277
- }
273
+ };
278
274
 
279
- async countToday() {
275
+ countToday = async (): Promise<number> => {
280
276
  const today = new Date();
281
277
  today.setHours(0, 0, 0, 0);
282
278
  const tomorrow = new Date(today);
@@ -284,7 +280,7 @@ export class MessageModel {
284
280
 
285
281
  const result = await this.db
286
282
  .select({
287
- count: count(),
283
+ count: count(messages.id),
288
284
  })
289
285
  .from(messages)
290
286
  .where(
@@ -293,15 +289,14 @@ export class MessageModel {
293
289
  gte(messages.createdAt, today),
294
290
  lt(messages.createdAt, tomorrow),
295
291
  ),
296
- )
297
- .execute();
292
+ );
298
293
 
299
294
  return result[0].count;
300
- }
295
+ };
301
296
 
302
297
  // **************** Create *************** //
303
298
 
304
- async create(
299
+ create = async (
305
300
  {
306
301
  fromModel,
307
302
  fromProvider,
@@ -313,7 +308,7 @@ export class MessageModel {
313
308
  ...message
314
309
  }: CreateMessageParams,
315
310
  id: string = this.genId(),
316
- ): Promise<MessageItem> {
311
+ ): Promise<MessageItem> => {
317
312
  return this.db.transaction(async (trx) => {
318
313
  const [item] = (await trx
319
314
  .insert(messages)
@@ -358,31 +353,31 @@ export class MessageModel {
358
353
 
359
354
  return item;
360
355
  });
361
- }
356
+ };
362
357
 
363
- async batchCreate(newMessages: MessageItem[]) {
358
+ batchCreate = async (newMessages: MessageItem[]) => {
364
359
  const messagesToInsert = newMessages.map((m) => {
365
360
  return { ...m, userId: this.userId };
366
361
  });
367
362
 
368
363
  return this.db.insert(messages).values(messagesToInsert);
369
- }
364
+ };
370
365
 
371
- async createMessageQuery(params: NewMessageQuery) {
366
+ createMessageQuery = async (params: NewMessageQuery) => {
372
367
  const result = await this.db.insert(messageQueries).values(params).returning();
373
368
 
374
369
  return result[0];
375
- }
370
+ };
376
371
  // **************** Update *************** //
377
372
 
378
- async update(id: string, message: Partial<MessageItem>) {
373
+ update = async (id: string, message: Partial<MessageItem>) => {
379
374
  return this.db
380
375
  .update(messages)
381
376
  .set(message)
382
377
  .where(and(eq(messages.id, id), eq(messages.userId, this.userId)));
383
- }
378
+ };
384
379
 
385
- async updatePluginState(id: string, state: Record<string, any>) {
380
+ updatePluginState = async (id: string, state: Record<string, any>) => {
386
381
  const item = await this.db.query.messagePlugins.findFirst({
387
382
  where: eq(messagePlugins.id, id),
388
383
  });
@@ -392,18 +387,18 @@ export class MessageModel {
392
387
  .update(messagePlugins)
393
388
  .set({ state: merge(item.state || {}, state) })
394
389
  .where(eq(messagePlugins.id, id));
395
- }
390
+ };
396
391
 
397
- async updateMessagePlugin(id: string, value: Partial<MessagePluginItem>) {
392
+ updateMessagePlugin = async (id: string, value: Partial<MessagePluginItem>) => {
398
393
  const item = await this.db.query.messagePlugins.findFirst({
399
394
  where: eq(messagePlugins.id, id),
400
395
  });
401
396
  if (!item) throw new Error('Plugin not found');
402
397
 
403
398
  return this.db.update(messagePlugins).set(value).where(eq(messagePlugins.id, id));
404
- }
399
+ };
405
400
 
406
- async updateTranslate(id: string, translate: Partial<MessageItem>) {
401
+ updateTranslate = async (id: string, translate: Partial<MessageItem>) => {
407
402
  const result = await this.db.query.messageTranslates.findFirst({
408
403
  where: and(eq(messageTranslates.id, id)),
409
404
  });
@@ -415,9 +410,9 @@ export class MessageModel {
415
410
 
416
411
  // or just update the existing one
417
412
  return this.db.update(messageTranslates).set(translate).where(eq(messageTranslates.id, id));
418
- }
413
+ };
419
414
 
420
- async updateTTS(id: string, tts: Partial<ChatTTS>) {
415
+ updateTTS = async (id: string, tts: Partial<ChatTTS>) => {
421
416
  const result = await this.db.query.messageTTS.findFirst({
422
417
  where: and(eq(messageTTS.id, id)),
423
418
  });
@@ -434,11 +429,11 @@ export class MessageModel {
434
429
  .update(messageTTS)
435
430
  .set({ contentMd5: tts.contentMd5, fileId: tts.file, voice: tts.voice })
436
431
  .where(eq(messageTTS.id, id));
437
- }
432
+ };
438
433
 
439
434
  // **************** Delete *************** //
440
435
 
441
- async deleteMessage(id: string) {
436
+ deleteMessage = async (id: string) => {
442
437
  return this.db.transaction(async (tx) => {
443
438
  // 1. 查询要删除的 message 的完整信息
444
439
  const message = await tx
@@ -460,8 +455,7 @@ export class MessageModel {
460
455
  const res = await tx
461
456
  .select({ id: messagePlugins.id })
462
457
  .from(messagePlugins)
463
- .where(inArray(messagePlugins.toolCallId, toolCallIds))
464
- .execute();
458
+ .where(inArray(messagePlugins.toolCallId, toolCallIds));
465
459
 
466
460
  relatedMessageIds = res.map((row) => row.id);
467
461
  }
@@ -472,28 +466,24 @@ export class MessageModel {
472
466
  // 5. 删除所有相关的 message
473
467
  await tx.delete(messages).where(inArray(messages.id, messageIdsToDelete));
474
468
  });
475
- }
469
+ };
476
470
 
477
- async deleteMessages(ids: string[]) {
478
- return this.db
471
+ deleteMessages = async (ids: string[]) =>
472
+ this.db
479
473
  .delete(messages)
480
474
  .where(and(eq(messages.userId, this.userId), inArray(messages.id, ids)));
481
- }
482
475
 
483
- async deleteMessageTranslate(id: string) {
484
- return this.db.delete(messageTranslates).where(and(eq(messageTranslates.id, id)));
485
- }
476
+ deleteMessageTranslate = async (id: string) =>
477
+ this.db.delete(messageTranslates).where(and(eq(messageTranslates.id, id)));
486
478
 
487
- async deleteMessageTTS(id: string) {
488
- return this.db.delete(messageTTS).where(and(eq(messageTTS.id, id)));
489
- }
479
+ deleteMessageTTS = async (id: string) =>
480
+ this.db.delete(messageTTS).where(and(eq(messageTTS.id, id)));
490
481
 
491
- async deleteMessageQuery(id: string) {
492
- return this.db.delete(messageQueries).where(and(eq(messageQueries.id, id)));
493
- }
482
+ deleteMessageQuery = async (id: string) =>
483
+ this.db.delete(messageQueries).where(and(eq(messageQueries.id, id)));
494
484
 
495
- async deleteMessagesBySession(sessionId?: string | null, topicId?: string | null) {
496
- return this.db
485
+ deleteMessagesBySession = async (sessionId?: string | null, topicId?: string | null) =>
486
+ this.db
497
487
  .delete(messages)
498
488
  .where(
499
489
  and(
@@ -502,11 +492,10 @@ export class MessageModel {
502
492
  this.matchTopic(topicId),
503
493
  ),
504
494
  );
505
- }
506
495
 
507
- async deleteAllMessages() {
496
+ deleteAllMessages = async () => {
508
497
  return this.db.delete(messages).where(eq(messages.userId, this.userId));
509
- }
498
+ };
510
499
 
511
500
  // **************** Helper *************** //
512
501
 
@@ -60,10 +60,10 @@ export class PluginModel {
60
60
  });
61
61
  };
62
62
 
63
- async update(id: string, value: Partial<InstalledPluginItem>) {
63
+ update = async (id: string, value: Partial<InstalledPluginItem>) => {
64
64
  return this.db
65
65
  .update(installedPlugins)
66
66
  .set({ ...value, updatedAt: new Date() })
67
67
  .where(and(eq(installedPlugins.identifier, id), eq(installedPlugins.userId, this.userId)));
68
- }
68
+ };
69
69
  }
@@ -1,7 +1,7 @@
1
- import { and, desc, eq } from 'drizzle-orm';
1
+ import { and, desc, eq } from 'drizzle-orm/expressions';
2
2
 
3
- import { serverDB } from '@/database/server';
4
3
  import { NewEvalDatasetsItem, evalDatasets } from '@/database/schemas';
4
+ import { serverDB } from '@/database/server';
5
5
  import { RAGEvalDataSetItem } from '@/types/eval';
6
6
 
7
7
  export class EvalDatasetModel {
@@ -1,11 +1,7 @@
1
- import { and, eq, inArray } from 'drizzle-orm';
1
+ import { and, eq, inArray } from 'drizzle-orm/expressions';
2
2
 
3
+ import { NewEvalDatasetRecordsItem, evalDatasetRecords, files } from '@/database/schemas';
3
4
  import { serverDB } from '@/database/server';
4
- import {
5
- NewEvalDatasetRecordsItem,
6
- evalDatasetRecords,
7
- files,
8
- } from '@/database/schemas';
9
5
  import { EvalDatasetRecordRefFile } from '@/types/eval';
10
6
 
11
7
  export class EvalDatasetRecordModel {
@@ -50,8 +46,7 @@ export class EvalDatasetRecordModel {
50
46
  const fileItems = await serverDB
51
47
  .select({ fileType: files.fileType, id: files.id, name: files.name })
52
48
  .from(files)
53
- .where(and(inArray(files.id, fileList), eq(files.userId, this.userId)))
54
- .execute();
49
+ .where(and(inArray(files.id, fileList), eq(files.userId, this.userId)));
55
50
 
56
51
  return list.map((item) => {
57
52
  return {
@@ -1,12 +1,13 @@
1
- import { SQL, and, count, desc, eq, inArray } from 'drizzle-orm';
1
+ import { SQL, count } from 'drizzle-orm';
2
+ import { and, desc, eq, inArray } from 'drizzle-orm/expressions';
2
3
 
3
- import { serverDB } from '@/database/server';
4
4
  import {
5
5
  NewEvalEvaluationItem,
6
6
  evalDatasets,
7
7
  evalEvaluation,
8
8
  evaluationRecords,
9
9
  } from '@/database/schemas';
10
+ import { serverDB } from '@/database/server';
10
11
  import { EvalEvaluationStatus, RAGEvalEvaluationItem } from '@/types/eval';
11
12
 
12
13
  export class EvalEvaluationModel {