@lobehub/chat 1.77.2 → 1.77.4
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 +58 -0
- package/changelog/v1.json +18 -0
- package/docs/self-hosting/environment-variables/model-provider.mdx +1 -1
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +1 -1
- package/package.json +3 -3
- package/packages/electron-server-ipc/README.md +54 -0
- package/packages/electron-server-ipc/package.json +7 -0
- package/packages/electron-server-ipc/src/const.ts +5 -0
- package/packages/electron-server-ipc/src/index.ts +3 -0
- package/packages/electron-server-ipc/src/ipcClient.test.ts +211 -0
- package/packages/electron-server-ipc/src/ipcClient.ts +179 -0
- package/packages/electron-server-ipc/src/ipcServer.ts +126 -0
- package/packages/electron-server-ipc/src/types/event.ts +18 -0
- package/packages/electron-server-ipc/src/types/index.ts +1 -0
- package/scripts/migrateServerDB/index.ts +1 -1
- package/src/app/[variants]/(main)/repos/[id]/@menu/default.tsx +1 -1
- package/src/app/[variants]/(main)/repos/[id]/page.tsx +1 -1
- package/src/components/Branding/ProductLogo/index.tsx +3 -3
- package/src/database/core/db-adaptor.ts +6 -0
- package/src/database/{server/core → core}/dbForTest.ts +2 -2
- package/src/database/{server/core/db.ts → core/web-server.ts} +4 -5
- package/src/database/models/__tests__/_test_template.ts +4 -3
- package/src/database/models/__tests__/_util.ts +2 -2
- package/src/database/models/__tests__/agent.test.ts +1 -1
- package/src/database/models/__tests__/aiModel.test.ts +1 -1
- package/src/database/models/__tests__/aiProvider.test.ts +1 -1
- package/src/database/models/__tests__/asyncTask.test.ts +1 -1
- package/src/database/models/__tests__/chunk.test.ts +1 -1
- package/src/database/models/__tests__/file.test.ts +1 -1
- package/src/database/models/__tests__/knowledgeBase.test.ts +1 -1
- package/src/database/models/__tests__/message.test.ts +1 -1
- package/src/database/models/__tests__/plugin.test.ts +1 -1
- package/src/database/models/__tests__/session.test.ts +1 -2
- package/src/database/models/__tests__/sessionGroup.test.ts +1 -1
- package/src/database/models/__tests__/topic.test.ts +1 -1
- package/src/database/{server/models → models}/_template.ts +1 -1
- package/src/database/{server/models → models}/aiModel.ts +1 -1
- package/src/database/{server/models → models}/aiProvider.ts +1 -1
- package/src/database/{server/models → models}/asyncTask.ts +1 -1
- package/src/database/{server/models → models}/chunk.ts +1 -1
- package/src/database/{server/models → models}/embedding.ts +1 -1
- package/src/database/{server/models → models}/file.ts +1 -1
- package/src/database/{server/models → models}/knowledgeBase.ts +1 -1
- package/src/database/{server/models → models}/message.ts +1 -1
- package/src/database/{server/models → models}/plugin.ts +11 -4
- package/src/database/{server/models → models}/session.ts +1 -1
- package/src/database/{server/models → models}/sessionGroup.ts +1 -1
- package/src/database/{server/models → models}/thread.ts +1 -1
- package/src/database/{server/models → models}/topic.ts +1 -1
- package/src/database/{server/models → models}/user.ts +1 -1
- package/src/database/repositories/aiInfra/index.ts +2 -2
- package/src/database/repositories/dataImporter/deprecated/__tests__/index.test.ts +1 -1
- package/src/database/server/index.ts +1 -1
- package/src/database/server/models/__tests__/nextauth.test.ts +1 -1
- package/src/database/server/models/__tests__/user.test.ts +3 -3
- package/src/libs/next-auth/adapter/index.ts +1 -1
- package/src/libs/trpc/async/asyncAuth.ts +1 -1
- package/src/server/routers/async/file.ts +4 -4
- package/src/server/routers/async/ragEval.ts +3 -3
- package/src/server/routers/lambda/_template.ts +1 -1
- package/src/server/routers/lambda/agent.test.ts +10 -10
- package/src/server/routers/lambda/agent.ts +5 -5
- package/src/server/routers/lambda/aiModel.test.ts +4 -4
- package/src/server/routers/lambda/aiModel.ts +2 -2
- package/src/server/routers/lambda/aiProvider.test.ts +4 -4
- package/src/server/routers/lambda/aiProvider.ts +2 -2
- package/src/server/routers/lambda/chunk.ts +5 -5
- package/src/server/routers/lambda/file.ts +3 -3
- package/src/server/routers/lambda/knowledgeBase.ts +1 -1
- package/src/server/routers/lambda/message.ts +1 -1
- package/src/server/routers/lambda/plugin.ts +1 -1
- package/src/server/routers/lambda/ragEval.ts +1 -1
- package/src/server/routers/lambda/session.ts +2 -2
- package/src/server/routers/lambda/sessionGroup.ts +1 -1
- package/src/server/routers/lambda/thread.ts +2 -2
- package/src/server/routers/lambda/topic.ts +1 -1
- package/src/server/routers/lambda/user.test.ts +6 -6
- package/src/server/routers/lambda/user.ts +3 -3
- package/src/server/services/agent/index.test.ts +2 -2
- package/src/server/services/agent/index.ts +1 -1
- package/src/server/services/chunk/index.ts +2 -2
- package/src/server/services/nextAuthUser/index.test.ts +2 -2
- package/src/server/services/nextAuthUser/index.ts +1 -1
- package/src/server/services/user/index.test.ts +2 -2
- package/src/server/services/user/index.ts +1 -1
- package/src/services/aiModel/client.ts +1 -1
- package/src/services/aiProvider/client.ts +1 -1
- package/src/services/file/client.ts +1 -1
- package/src/services/message/client.ts +1 -1
- package/src/services/plugin/client.ts +1 -1
- package/src/services/session/client.ts +2 -2
- package/src/services/thread/client.ts +2 -2
- package/src/services/topic/client.ts +1 -1
- package/src/services/user/client.ts +3 -3
- /package/src/database/{server/models → models}/agent.ts +0 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
import fs from 'node:fs';
|
2
|
+
import net from 'node:net';
|
3
|
+
import os from 'node:os';
|
4
|
+
import path from 'node:path';
|
5
|
+
|
6
|
+
import { SOCK_FILE, SOCK_INFO_FILE, WINDOW_PIPE_FILE } from './const';
|
7
|
+
import { IElectronIPCMethods } from './types';
|
8
|
+
|
9
|
+
export type IPCEventMethod = (
|
10
|
+
params: any,
|
11
|
+
context: { id: string; method: string; socket: net.Socket },
|
12
|
+
) => Promise<any>;
|
13
|
+
|
14
|
+
export type ElectronIPCEventHandler = {
|
15
|
+
[key in IElectronIPCMethods]: IPCEventMethod;
|
16
|
+
};
|
17
|
+
|
18
|
+
export class ElectronIPCServer {
|
19
|
+
private server: net.Server;
|
20
|
+
private socketPath: string;
|
21
|
+
private eventHandler: ElectronIPCEventHandler;
|
22
|
+
|
23
|
+
constructor(eventHandler: ElectronIPCEventHandler) {
|
24
|
+
const isWindows = process.platform === 'win32';
|
25
|
+
// 创建唯一的套接字路径,避免冲突
|
26
|
+
this.socketPath = isWindows ? WINDOW_PIPE_FILE : path.join(os.tmpdir(), SOCK_FILE);
|
27
|
+
|
28
|
+
// 如果是 Unix 套接字,确保文件不存在
|
29
|
+
if (!isWindows && fs.existsSync(this.socketPath)) {
|
30
|
+
fs.unlinkSync(this.socketPath);
|
31
|
+
}
|
32
|
+
|
33
|
+
// 创建服务器
|
34
|
+
this.server = net.createServer(this.handleConnection.bind(this));
|
35
|
+
|
36
|
+
this.eventHandler = eventHandler;
|
37
|
+
}
|
38
|
+
|
39
|
+
// 启动服务器
|
40
|
+
public start(): Promise<void> {
|
41
|
+
return new Promise((resolve, reject) => {
|
42
|
+
this.server.on('error', (err) => {
|
43
|
+
console.error('IPC Server error:', err);
|
44
|
+
reject(err);
|
45
|
+
});
|
46
|
+
|
47
|
+
this.server.listen(this.socketPath, () => {
|
48
|
+
console.log(`Electron IPC server listening on ${this.socketPath}`);
|
49
|
+
|
50
|
+
// 将套接字路径写入临时文件,供 Next.js 服务端读取
|
51
|
+
const tempDir = os.tmpdir();
|
52
|
+
const socketInfoPath = path.join(tempDir, SOCK_INFO_FILE);
|
53
|
+
fs.writeFileSync(socketInfoPath, JSON.stringify({ socketPath: this.socketPath }), 'utf8');
|
54
|
+
|
55
|
+
resolve();
|
56
|
+
});
|
57
|
+
});
|
58
|
+
}
|
59
|
+
|
60
|
+
// 处理客户端连接
|
61
|
+
private handleConnection(socket: net.Socket): void {
|
62
|
+
let dataBuffer = '';
|
63
|
+
|
64
|
+
socket.on('data', (data) => {
|
65
|
+
dataBuffer += data.toString();
|
66
|
+
|
67
|
+
try {
|
68
|
+
// 尝试解析 JSON 消息
|
69
|
+
const message = JSON.parse(dataBuffer);
|
70
|
+
dataBuffer = ''; // 重置缓冲区
|
71
|
+
|
72
|
+
// 处理请求
|
73
|
+
this.handleRequest(socket, message);
|
74
|
+
} catch {
|
75
|
+
// 如果不是有效的 JSON,可能是消息不完整,继续等待
|
76
|
+
}
|
77
|
+
});
|
78
|
+
|
79
|
+
socket.on('error', (err) => {
|
80
|
+
console.error('Socket error:', err);
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
// 处理客户端请求
|
85
|
+
private handleRequest = async (socket: net.Socket, request: any) => {
|
86
|
+
const { id, method, params } = request;
|
87
|
+
|
88
|
+
// 根据请求方法执行相应的操作
|
89
|
+
const eventHandler = this.eventHandler[method as IElectronIPCMethods];
|
90
|
+
if (!eventHandler) return;
|
91
|
+
|
92
|
+
try {
|
93
|
+
const data = await eventHandler(params, { id, method, socket });
|
94
|
+
|
95
|
+
this.sendResult(socket, id, data);
|
96
|
+
} catch (err) {
|
97
|
+
this.sendError(socket, id, `Failed to handle method(${method}): ${(err as Error).message}`);
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
// 发送结果
|
102
|
+
private sendResult(socket: net.Socket, id: string, result: any): void {
|
103
|
+
socket.write(JSON.stringify({ id, result }));
|
104
|
+
}
|
105
|
+
|
106
|
+
// 发送错误
|
107
|
+
private sendError(socket: net.Socket, id: string, error: string): void {
|
108
|
+
socket.write(JSON.stringify({ error, id }));
|
109
|
+
}
|
110
|
+
|
111
|
+
// 关闭服务器
|
112
|
+
public close(): Promise<void> {
|
113
|
+
return new Promise((resolve) => {
|
114
|
+
this.server.close(() => {
|
115
|
+
console.log('Electron IPC server closed');
|
116
|
+
|
117
|
+
// 删除套接字文件(Unix 平台)
|
118
|
+
if (process.platform !== 'win32' && fs.existsSync(this.socketPath)) {
|
119
|
+
fs.unlinkSync(this.socketPath);
|
120
|
+
}
|
121
|
+
|
122
|
+
resolve();
|
123
|
+
});
|
124
|
+
});
|
125
|
+
}
|
126
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* eslint-disable typescript-sort-keys/interface, sort-keys-fix/sort-keys-fix */
|
2
|
+
export const ElectronIPCMethods = {
|
3
|
+
getDatabasePath: 'getDatabasePath',
|
4
|
+
getUserDataPath: 'getUserDataPath',
|
5
|
+
|
6
|
+
getDatabaseSchemaHash: 'getDatabaseSchemaHash',
|
7
|
+
setDatabaseSchemaHash: 'setDatabaseSchemaHash',
|
8
|
+
} as const;
|
9
|
+
|
10
|
+
export type IElectronIPCMethods = keyof typeof ElectronIPCMethods;
|
11
|
+
|
12
|
+
export interface IpcDispatchEvent {
|
13
|
+
getDatabasePath: () => Promise<string>;
|
14
|
+
getUserDataPath: () => Promise<string>;
|
15
|
+
|
16
|
+
getDatabaseSchemaHash: () => Promise<string | undefined>;
|
17
|
+
setDatabaseSchemaHash: (hash: string) => Promise<void>;
|
18
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './event';
|
@@ -3,7 +3,7 @@ import { migrate as neonMigrate } from 'drizzle-orm/neon-serverless/migrator';
|
|
3
3
|
import { migrate as nodeMigrate } from 'drizzle-orm/node-postgres/migrator';
|
4
4
|
import { join } from 'node:path';
|
5
5
|
|
6
|
-
import { serverDB } from '../../src/database/server
|
6
|
+
import { serverDB } from '../../src/database/server';
|
7
7
|
import { DB_FAIL_INIT_HINT, PGVECTOR_HINT } from './errorHint';
|
8
8
|
|
9
9
|
// Read the `.env` file if it exists, or a file specified by the
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { notFound } from 'next/navigation';
|
2
2
|
import { Flexbox } from 'react-layout-kit';
|
3
3
|
|
4
|
+
import { KnowledgeBaseModel } from '@/database/models/knowledgeBase';
|
4
5
|
import { serverDB } from '@/database/server';
|
5
|
-
import { KnowledgeBaseModel } from '@/database/server/models/knowledgeBase';
|
6
6
|
|
7
7
|
import Head from './Head';
|
8
8
|
import Menu from './Menu';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { redirect } from 'next/navigation';
|
2
2
|
|
3
|
+
import { KnowledgeBaseModel } from '@/database/models/knowledgeBase';
|
3
4
|
import { serverDB } from '@/database/server';
|
4
|
-
import { KnowledgeBaseModel } from '@/database/server/models/knowledgeBase';
|
5
5
|
import FileManager from '@/features/FileManager';
|
6
6
|
import { PagePropsWithId } from '@/types/next';
|
7
7
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { LobeHub, LobeHubProps } from '@lobehub/ui/brand';
|
2
2
|
import { memo } from 'react';
|
3
3
|
|
4
4
|
import { isCustomBranding } from '@/const/version';
|
5
5
|
|
6
6
|
import CustomLogo from './Custom';
|
7
7
|
|
8
|
-
export const ProductLogo = memo<
|
8
|
+
export const ProductLogo = memo<LobeHubProps>((props) => {
|
9
9
|
if (isCustomBranding) {
|
10
10
|
return <CustomLogo {...props} />;
|
11
11
|
}
|
12
12
|
|
13
|
-
return <
|
13
|
+
return <LobeHub {...props} />;
|
14
14
|
});
|
@@ -9,9 +9,9 @@ import ws from 'ws';
|
|
9
9
|
|
10
10
|
import { serverDBEnv } from '@/config/db';
|
11
11
|
|
12
|
-
import * as schema from '
|
12
|
+
import * as schema from '../schemas';
|
13
13
|
|
14
|
-
const migrationsFolder = join(__dirname, '
|
14
|
+
const migrationsFolder = join(__dirname, '../migrations');
|
15
15
|
|
16
16
|
export const getTestDBInstance = async () => {
|
17
17
|
let connectionString = serverDBEnv.DATABASE_TEST_URL;
|
@@ -1,15 +1,16 @@
|
|
1
1
|
import { Pool as NeonPool, neonConfig } from '@neondatabase/serverless';
|
2
|
-
import {
|
2
|
+
import { drizzle as neonDrizzle } from 'drizzle-orm/neon-serverless';
|
3
3
|
import { drizzle as nodeDrizzle } from 'drizzle-orm/node-postgres';
|
4
4
|
import { Pool as NodePool } from 'pg';
|
5
5
|
import ws from 'ws';
|
6
6
|
|
7
7
|
import { serverDBEnv } from '@/config/db';
|
8
8
|
import { isServerMode } from '@/const/version';
|
9
|
+
import * as schema from '@/database/schemas';
|
9
10
|
|
10
|
-
import
|
11
|
+
import { LobeChatDatabase } from '../type';
|
11
12
|
|
12
|
-
export const getDBInstance = ():
|
13
|
+
export const getDBInstance = (): LobeChatDatabase => {
|
13
14
|
if (!isServerMode) return {} as any;
|
14
15
|
|
15
16
|
if (!serverDBEnv.KEY_VAULTS_SECRET) {
|
@@ -40,5 +41,3 @@ If you don't have it, please run \`openssl rand -base64 32\` to create one.
|
|
40
41
|
const client = new NeonPool({ connectionString });
|
41
42
|
return neonDrizzle(client, { schema });
|
42
43
|
};
|
43
|
-
|
44
|
-
export const serverDB = getDBInstance();
|
@@ -2,12 +2,13 @@
|
|
2
2
|
import { eq } from 'drizzle-orm/expressions';
|
3
3
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { LobeChatDatabase } from '@/database/type';
|
6
6
|
|
7
7
|
import { sessionGroups, users } from '../../schemas';
|
8
|
-
import { SessionGroupModel } from '
|
8
|
+
import { SessionGroupModel } from '../sessionGroup';
|
9
|
+
import { getTestDB } from './_util';
|
9
10
|
|
10
|
-
|
11
|
+
const serverDB: LobeChatDatabase = await getTestDB();
|
11
12
|
|
12
13
|
const userId = 'session-group-model-test-user-id';
|
13
14
|
const sessionGroupModel = new SessionGroupModel(serverDB, userId);
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { clientDB, initializeDB } from '@/database/client/db';
|
2
|
-
import { getTestDBInstance } from '@/database/
|
2
|
+
import { getTestDBInstance } from '@/database/core/dbForTest';
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
|
5
|
-
|
5
|
+
const isServerDBMode = process.env.TEST_SERVER_DB === '1';
|
6
6
|
|
7
7
|
export const getTestDB = async () => {
|
8
8
|
if (isServerDBMode) return await getTestDBInstance();
|
@@ -6,7 +6,7 @@ import { LobeChatDatabase } from '@/database/type';
|
|
6
6
|
import { AiProviderModelListItem } from '@/types/aiModel';
|
7
7
|
|
8
8
|
import { AiModelSelectItem, NewAiModelItem, aiModels, users } from '../../schemas';
|
9
|
-
import { AiModelModel } from '
|
9
|
+
import { AiModelModel } from '../aiModel';
|
10
10
|
import { getTestDB } from './_util';
|
11
11
|
|
12
12
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -6,7 +6,7 @@ import { LobeChatDatabase } from '@/database/type';
|
|
6
6
|
import { ModelProvider } from '@/libs/agent-runtime';
|
7
7
|
|
8
8
|
import { aiProviders, users } from '../../schemas';
|
9
|
-
import { AiProviderModel } from '
|
9
|
+
import { AiProviderModel } from '../aiProvider';
|
10
10
|
import { getTestDB } from './_util';
|
11
11
|
|
12
12
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -6,7 +6,7 @@ import { LobeChatDatabase } from '@/database/type';
|
|
6
6
|
import { AsyncTaskStatus, AsyncTaskType } from '@/types/asyncTask';
|
7
7
|
|
8
8
|
import { asyncTasks, users } from '../../schemas';
|
9
|
-
import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '
|
9
|
+
import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '../asyncTask';
|
10
10
|
import { getTestDB } from './_util';
|
11
11
|
|
12
12
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -6,7 +6,7 @@ import { LobeChatDatabase } from '@/database/type';
|
|
6
6
|
import { uuid } from '@/utils/uuid';
|
7
7
|
|
8
8
|
import { chunks, embeddings, fileChunks, files, unstructuredChunks, users } from '../../schemas';
|
9
|
-
import { ChunkModel } from '
|
9
|
+
import { ChunkModel } from '../chunk';
|
10
10
|
import { getTestDB } from './_util';
|
11
11
|
import { codeEmbedding, designThinkingQuery, designThinkingQuery2 } from './fixtures/embedding';
|
12
12
|
|
@@ -6,7 +6,7 @@ import { LobeChatDatabase } from '@/database/type';
|
|
6
6
|
import { FilesTabs, SortType } from '@/types/files';
|
7
7
|
|
8
8
|
import { files, globalFiles, knowledgeBaseFiles, knowledgeBases, users } from '../../schemas';
|
9
|
-
import { FileModel } from '
|
9
|
+
import { FileModel } from '../file';
|
10
10
|
import { getTestDB } from './_util';
|
11
11
|
|
12
12
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
knowledgeBases,
|
14
14
|
users,
|
15
15
|
} from '../../schemas';
|
16
|
-
import { KnowledgeBaseModel } from '
|
16
|
+
import { KnowledgeBaseModel } from '../knowledgeBase';
|
17
17
|
import { getTestDB } from './_util';
|
18
18
|
|
19
19
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -23,7 +23,7 @@ import {
|
|
23
23
|
topics,
|
24
24
|
users,
|
25
25
|
} from '../../schemas';
|
26
|
-
import { MessageModel } from '
|
26
|
+
import { MessageModel } from '../message';
|
27
27
|
import { codeEmbedding } from './fixtures/embedding';
|
28
28
|
|
29
29
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
import { LobeChatDatabase } from '@/database/type';
|
5
5
|
|
6
6
|
import { NewInstalledPlugin, userInstalledPlugins, users } from '../../schemas';
|
7
|
-
import { PluginModel } from '
|
7
|
+
import { PluginModel } from '../plugin';
|
8
8
|
import { getTestDB } from './_util';
|
9
9
|
|
10
10
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -2,7 +2,6 @@ import { and, eq, inArray } from 'drizzle-orm/expressions';
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
3
3
|
|
4
4
|
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
5
|
-
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
6
5
|
import { LobeChatDatabase } from '@/database/type';
|
7
6
|
import { idGenerator } from '@/database/utils/idGenerator';
|
8
7
|
|
@@ -17,7 +16,7 @@ import {
|
|
17
16
|
topics,
|
18
17
|
users,
|
19
18
|
} from '../../schemas';
|
20
|
-
import { SessionModel } from '
|
19
|
+
import { SessionModel } from '../session';
|
21
20
|
import { getTestDB } from './_util';
|
22
21
|
|
23
22
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { LobeChatDatabase } from '@/database/type';
|
6
6
|
|
7
7
|
import { sessionGroups, users } from '../../schemas';
|
8
|
-
import { SessionGroupModel } from '
|
8
|
+
import { SessionGroupModel } from '../sessionGroup';
|
9
9
|
import { getTestDB } from './_util';
|
10
10
|
|
11
11
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
import { LobeChatDatabase } from '@/database/type';
|
5
5
|
|
6
6
|
import { messages, sessions, topics, users } from '../../schemas';
|
7
|
-
import { CreateTopicParams, TopicModel } from '
|
7
|
+
import { CreateTopicParams, TopicModel } from '../topic';
|
8
8
|
import { getTestDB } from './_util';
|
9
9
|
|
10
10
|
const serverDB: LobeChatDatabase = await getTestDB();
|
@@ -2,7 +2,7 @@ import { and, desc, eq } from 'drizzle-orm/expressions';
|
|
2
2
|
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
|
5
|
-
import { NewSessionGroup, SessionGroupItem, sessionGroups } from '
|
5
|
+
import { NewSessionGroup, SessionGroupItem, sessionGroups } from '../schemas';
|
6
6
|
|
7
7
|
export class TemplateModel {
|
8
8
|
private userId: string;
|
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
ToggleAiModelEnableParams,
|
10
10
|
} from '@/types/aiModel';
|
11
11
|
|
12
|
-
import { AiModelSelectItem, NewAiModelItem, aiModels } from '
|
12
|
+
import { AiModelSelectItem, NewAiModelItem, aiModels } from '../schemas';
|
13
13
|
|
14
14
|
export class AiModelModel {
|
15
15
|
private userId: string;
|
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
} from '@/types/aiProvider';
|
14
14
|
import { merge } from '@/utils/merge';
|
15
15
|
|
16
|
-
import { AiProviderSelectItem, aiModels, aiProviders } from '
|
16
|
+
import { AiProviderSelectItem, aiModels, aiProviders } from '../schemas';
|
17
17
|
|
18
18
|
type DecryptUserKeyVaults = (encryptKeyVaultsStr: string | null) => Promise<any>;
|
19
19
|
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
AsyncTaskType,
|
9
9
|
} from '@/types/asyncTask';
|
10
10
|
|
11
|
-
import { AsyncTaskSelectItem, NewAsyncTaskItem, asyncTasks } from '
|
11
|
+
import { AsyncTaskSelectItem, NewAsyncTaskItem, asyncTasks } from '../schemas';
|
12
12
|
|
13
13
|
// set timeout to about 5 minutes, and give 2s padding time
|
14
14
|
export const ASYNC_TASK_TIMEOUT = 298 * 1000;
|
@@ -3,7 +3,7 @@ import { and, eq } from 'drizzle-orm/expressions';
|
|
3
3
|
|
4
4
|
import { LobeChatDatabase } from '@/database/type';
|
5
5
|
|
6
|
-
import { NewEmbeddingsItem, embeddings } from '
|
6
|
+
import { NewEmbeddingsItem, embeddings } from '../schemas';
|
7
7
|
|
8
8
|
export class EmbeddingModel {
|
9
9
|
private userId: string;
|
@@ -3,7 +3,7 @@ import { and, desc, eq, inArray } from 'drizzle-orm/expressions';
|
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
import { KnowledgeBaseItem } from '@/types/knowledgeBase';
|
5
5
|
|
6
|
-
import { NewKnowledgeBase, knowledgeBaseFiles, knowledgeBases } from '
|
6
|
+
import { NewKnowledgeBase, knowledgeBaseFiles, knowledgeBases } from '../schemas';
|
7
7
|
|
8
8
|
export class KnowledgeBaseModel {
|
9
9
|
private userId: string;
|
@@ -2,7 +2,7 @@ import { and, desc, eq } from 'drizzle-orm/expressions';
|
|
2
2
|
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
|
5
|
-
import { InstalledPluginItem, NewInstalledPlugin, userInstalledPlugins } from '
|
5
|
+
import { InstalledPluginItem, NewInstalledPlugin, userInstalledPlugins } from '../schemas';
|
6
6
|
|
7
7
|
export class PluginModel {
|
8
8
|
private userId: string;
|
@@ -31,7 +31,9 @@ export class PluginModel {
|
|
31
31
|
delete = async (id: string) => {
|
32
32
|
return this.db
|
33
33
|
.delete(userInstalledPlugins)
|
34
|
-
.where(
|
34
|
+
.where(
|
35
|
+
and(eq(userInstalledPlugins.identifier, id), eq(userInstalledPlugins.userId, this.userId)),
|
36
|
+
);
|
35
37
|
};
|
36
38
|
|
37
39
|
deleteAll = async () => {
|
@@ -56,7 +58,10 @@ export class PluginModel {
|
|
56
58
|
|
57
59
|
findById = async (id: string) => {
|
58
60
|
return this.db.query.userInstalledPlugins.findFirst({
|
59
|
-
where: and(
|
61
|
+
where: and(
|
62
|
+
eq(userInstalledPlugins.identifier, id),
|
63
|
+
eq(userInstalledPlugins.userId, this.userId),
|
64
|
+
),
|
60
65
|
});
|
61
66
|
};
|
62
67
|
|
@@ -64,6 +69,8 @@ export class PluginModel {
|
|
64
69
|
return this.db
|
65
70
|
.update(userInstalledPlugins)
|
66
71
|
.set({ ...value, updatedAt: new Date() })
|
67
|
-
.where(
|
72
|
+
.where(
|
73
|
+
and(eq(userInstalledPlugins.identifier, id), eq(userInstalledPlugins.userId, this.userId)),
|
74
|
+
);
|
68
75
|
};
|
69
76
|
}
|
@@ -3,7 +3,7 @@ import { and, asc, desc, eq } from 'drizzle-orm/expressions';
|
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
import { idGenerator } from '@/database/utils/idGenerator';
|
5
5
|
|
6
|
-
import { SessionGroupItem, sessionGroups } from '
|
6
|
+
import { SessionGroupItem, sessionGroups } from '../schemas';
|
7
7
|
|
8
8
|
export class SessionGroupModel {
|
9
9
|
private userId: string;
|
@@ -3,7 +3,7 @@ import { and, desc, eq } from 'drizzle-orm/expressions';
|
|
3
3
|
import { LobeChatDatabase } from '@/database/type';
|
4
4
|
import { CreateThreadParams, ThreadStatus } from '@/types/topic';
|
5
5
|
|
6
|
-
import { ThreadItem, threads } from '
|
6
|
+
import { ThreadItem, threads } from '../schemas';
|
7
7
|
|
8
8
|
const queryColumns = {
|
9
9
|
createdAt: threads.createdAt,
|
@@ -12,7 +12,7 @@ import { idGenerator } from '@/database/utils/idGenerator';
|
|
12
12
|
import { MessageItem } from '@/types/message';
|
13
13
|
import { TopicRankItem } from '@/types/topic';
|
14
14
|
|
15
|
-
import { TopicItem, messages, topics } from '
|
15
|
+
import { TopicItem, messages, topics } from '../schemas';
|
16
16
|
|
17
17
|
export interface CreateTopicParams {
|
18
18
|
favorite?: boolean;
|
@@ -2,8 +2,8 @@ import { isEmpty } from 'lodash-es';
|
|
2
2
|
import pMap from 'p-map';
|
3
3
|
|
4
4
|
import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
|
5
|
-
import { AiModelModel } from '@/database/
|
6
|
-
import { AiProviderModel } from '@/database/
|
5
|
+
import { AiModelModel } from '@/database/models/aiModel';
|
6
|
+
import { AiProviderModel } from '@/database/models/aiProvider';
|
7
7
|
import { LobeChatDatabase } from '@/database/type';
|
8
8
|
import {
|
9
9
|
AIChatModelCard,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import { eq, inArray } from 'drizzle-orm/expressions';
|
3
3
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
4
4
|
|
5
|
+
import { getTestDBInstance } from '@/database/core/dbForTest';
|
5
6
|
import {
|
6
7
|
agents,
|
7
8
|
agentsToSessions,
|
@@ -11,7 +12,6 @@ import {
|
|
11
12
|
topics,
|
12
13
|
users,
|
13
14
|
} from '@/database/schemas';
|
14
|
-
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
15
15
|
import { CURRENT_CONFIG_VERSION } from '@/migrations';
|
16
16
|
import { ImporterEntryData } from '@/types/importer';
|
17
17
|
|
@@ -1 +1 @@
|
|
1
|
-
export { serverDB } from '
|
1
|
+
export { serverDB } from '../core/db-adaptor';
|
@@ -8,6 +8,7 @@ import type {
|
|
8
8
|
import { eq } from 'drizzle-orm/expressions';
|
9
9
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
10
10
|
|
11
|
+
import { getTestDBInstance } from '@/database/core/dbForTest';
|
11
12
|
import {
|
12
13
|
nextauthAccounts,
|
13
14
|
nextauthAuthenticators,
|
@@ -15,7 +16,6 @@ import {
|
|
15
16
|
nextauthVerificationTokens,
|
16
17
|
users,
|
17
18
|
} from '@/database/schemas';
|
18
|
-
import { getTestDBInstance } from '@/database/server/core/dbForTest';
|
19
19
|
import { LobeChatDatabase } from '@/database/type';
|
20
20
|
import { LobeNextAuthDbAdapter } from '@/libs/next-auth/adapter';
|
21
21
|
|