@lobehub/lobehub 2.0.0-next.13 → 2.0.0-next.15
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/.github/workflows/desktop-pr-build.yml +6 -6
- package/.github/workflows/release-desktop-beta.yml +4 -4
- package/.github/workflows/release.yml +1 -2
- package/.github/workflows/test.yml +4 -5
- package/.nvmrc +1 -1
- package/CHANGELOG.md +42 -0
- package/apps/desktop/tsconfig.json +0 -1
- package/changelog/v1.json +14 -0
- package/e2e/tsconfig.json +0 -1
- package/package.json +58 -58
- package/packages/const/src/version.ts +3 -3
- package/packages/database/src/repositories/dataImporter/deprecated/__tests__/index.test.ts +2 -1
- package/packages/database/src/repositories/dataImporter/deprecated/index.ts +7 -1
- package/packages/web-crawler/tsconfig.json +0 -1
- package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +9 -0
- package/src/app/[variants]/(main)/(mobile)/me/(home)/layout.tsx +0 -2
- package/src/app/[variants]/(main)/chat/@session/features/SessionListContent/List/Item/Actions.tsx +3 -28
- package/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx +0 -2
- package/src/app/[variants]/(main)/chat/_layout/Mobile.tsx +1 -5
- package/src/app/[variants]/(main)/chat/settings/features/HeaderContent.tsx +2 -62
- package/src/app/[variants]/(main)/image/page.tsx +0 -2
- package/src/app/[variants]/(main)/profile/_layout/Desktop/index.tsx +23 -24
- package/src/app/[variants]/(main)/profile/_layout/Mobile/index.tsx +5 -9
- package/src/app/[variants]/(main)/settings/_layout/Desktop/index.tsx +0 -2
- package/src/app/[variants]/(main)/settings/_layout/Mobile/index.tsx +0 -2
- package/src/app/[variants]/(main)/settings/provider/(list)/ProviderGrid/Card.tsx +1 -1
- package/src/app/[variants]/loading/index.tsx +1 -10
- package/src/components/Link.tsx +12 -0
- package/src/envs/app.ts +5 -8
- package/src/features/DataImporter/index.tsx +15 -60
- package/src/features/DevPanel/PostgresViewer/usePgTable.ts +3 -2
- package/src/hooks/useInterceptingRoutes.test.ts +21 -3
- package/src/libs/trpc/client/index.ts +0 -1
- package/src/libs/trpc/client/lambda.ts +8 -5
- package/src/server/routers/desktop/mcp.ts +1 -3
- package/src/server/routers/lambda/config/index.test.ts +2 -2
- package/src/server/routers/tools/mcp.ts +2 -3
- package/src/server/routers/tools/search.test.ts +1 -7
- package/src/server/routers/tools/search.ts +1 -4
- package/src/services/__tests__/tool.test.ts +0 -3
- package/src/services/aiModel/index.test.ts +0 -3
- package/src/services/aiModel/index.ts +1 -7
- package/src/services/aiProvider/index.test.ts +0 -3
- package/src/services/aiProvider/index.ts +1 -7
- package/src/services/chatGroup/index.ts +1 -10
- package/src/services/config.ts +1 -65
- package/src/services/export/index.ts +1 -4
- package/src/services/file/index.ts +1 -11
- package/src/services/import/index.ts +1 -7
- package/src/services/message/index.ts +1 -11
- package/src/services/plugin/index.ts +1 -11
- package/src/services/session/index.ts +1 -11
- package/src/services/tableViewer/client.ts +12 -15
- package/src/services/thread/index.ts +1 -7
- package/src/services/topic/index.ts +1 -11
- package/src/services/user/index.ts +1 -13
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChat.test.ts +0 -241
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +26 -1
- package/src/store/chat/slices/aiChat/actions/__tests__/helpers.ts +3 -1
- package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +1 -138
- package/src/store/user/slices/common/action.test.ts +1 -4
- package/tsconfig.json +0 -1
- package/src/app/(backend)/trpc/edge/[trpc]/route.ts +0 -26
- package/src/app/[variants]/(main)/(mobile)/me/data/features/Category.tsx +0 -48
- package/src/app/[variants]/(main)/(mobile)/me/data/features/Header.tsx +0 -33
- package/src/app/[variants]/(main)/(mobile)/me/data/layout.tsx +0 -13
- package/src/app/[variants]/(main)/(mobile)/me/data/loading.tsx +0 -5
- package/src/app/[variants]/(main)/(mobile)/me/data/page.tsx +0 -29
- package/src/app/[variants]/(main)/chat/features/Migration/DBReader.ts +0 -290
- package/src/app/[variants]/(main)/chat/features/Migration/ExportConfigButton.tsx +0 -35
- package/src/app/[variants]/(main)/chat/features/Migration/Failed.tsx +0 -120
- package/src/app/[variants]/(main)/chat/features/Migration/Modal.tsx +0 -81
- package/src/app/[variants]/(main)/chat/features/Migration/Start.tsx +0 -108
- package/src/app/[variants]/(main)/chat/features/Migration/UpgradeButton.tsx +0 -71
- package/src/app/[variants]/(main)/chat/features/Migration/const.ts +0 -15
- package/src/app/[variants]/(main)/chat/features/Migration/index.tsx +0 -50
- package/src/app/[variants]/loading/Client/Content.tsx +0 -48
- package/src/app/[variants]/loading/Client/Error.tsx +0 -27
- package/src/app/[variants]/loading/Client/Redirect.tsx +0 -47
- package/src/app/[variants]/loading/Client/index.tsx +0 -22
- package/src/components/InnerLink.tsx +0 -20
- package/src/database/_deprecated/core/__tests__/db-upgrade.test.ts +0 -42
- package/src/database/_deprecated/core/__tests__/db.test.ts +0 -79
- package/src/database/_deprecated/core/__tests__/model.test.ts +0 -55
- package/src/database/_deprecated/core/db.ts +0 -246
- package/src/database/_deprecated/core/index.ts +0 -2
- package/src/database/_deprecated/core/migrations/migrateSettingsToUser/fixtures/input.json +0 -55
- package/src/database/_deprecated/core/migrations/migrateSettingsToUser/fixtures/output.json +0 -60
- package/src/database/_deprecated/core/migrations/migrateSettingsToUser/index.test.ts +0 -14
- package/src/database/_deprecated/core/migrations/migrateSettingsToUser/index.ts +0 -22
- package/src/database/_deprecated/core/migrations/migrateSettingsToUser/type.ts +0 -105
- package/src/database/_deprecated/core/model.ts +0 -218
- package/src/database/_deprecated/core/schemas.ts +0 -88
- package/src/database/_deprecated/core/types/db.ts +0 -15
- package/src/database/_deprecated/models/__DEBUG.ts +0 -124
- package/src/database/_deprecated/models/__tests__/file.test.ts +0 -83
- package/src/database/_deprecated/models/__tests__/message.test.ts +0 -426
- package/src/database/_deprecated/models/__tests__/plugin.test.ts +0 -81
- package/src/database/_deprecated/models/__tests__/session.test.ts +0 -253
- package/src/database/_deprecated/models/__tests__/sessionGroup.test.ts +0 -220
- package/src/database/_deprecated/models/__tests__/topic.test.ts +0 -523
- package/src/database/_deprecated/models/__tests__/user.test.ts +0 -82
- package/src/database/_deprecated/models/file.ts +0 -51
- package/src/database/_deprecated/models/message.ts +0 -277
- package/src/database/_deprecated/models/plugin.ts +0 -62
- package/src/database/_deprecated/models/session.ts +0 -271
- package/src/database/_deprecated/models/sessionGroup.ts +0 -93
- package/src/database/_deprecated/models/topic.ts +0 -250
- package/src/database/_deprecated/models/user.ts +0 -69
- package/src/database/_deprecated/schemas/files.ts +0 -39
- package/src/database/_deprecated/schemas/message.ts +0 -50
- package/src/database/_deprecated/schemas/plugin.ts +0 -12
- package/src/database/_deprecated/schemas/session.ts +0 -54
- package/src/database/_deprecated/schemas/sessionGroup.ts +0 -8
- package/src/database/_deprecated/schemas/topic.ts +0 -12
- package/src/database/_deprecated/schemas/user.ts +0 -40
- package/src/features/DataImporter/_deprecated.ts +0 -43
- package/src/features/InitClientDB/EnableModal.tsx +0 -118
- package/src/features/InitClientDB/ErrorResult.tsx +0 -143
- package/src/features/InitClientDB/InitIndicator.tsx +0 -124
- package/src/features/InitClientDB/PGliteIcon.tsx +0 -28
- package/src/features/InitClientDB/features/DatabaseRepair/Backup.tsx +0 -75
- package/src/features/InitClientDB/features/DatabaseRepair/Diagnosis.tsx +0 -98
- package/src/features/InitClientDB/features/DatabaseRepair/Repair.tsx +0 -218
- package/src/features/InitClientDB/features/DatabaseRepair/index.tsx +0 -91
- package/src/features/InitClientDB/index.tsx +0 -37
- package/src/libs/trpc/client/edge.ts +0 -26
- package/src/libs/trpc/edge/context.ts +0 -71
- package/src/libs/trpc/edge/index.ts +0 -45
- package/src/libs/trpc/edge/init.ts +0 -26
- package/src/libs/trpc/edge/middleware/jwtPayload.test.ts +0 -75
- package/src/libs/trpc/edge/middleware/jwtPayload.ts +0 -14
- package/src/migrations/FromV0ToV1.ts +0 -10
- package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +0 -191
- package/src/migrations/FromV1ToV2/fixtures/output-v2.json +0 -202
- package/src/migrations/FromV1ToV2/index.ts +0 -82
- package/src/migrations/FromV1ToV2/migrations.test.ts +0 -224
- package/src/migrations/FromV1ToV2/types/v1.ts +0 -78
- package/src/migrations/FromV1ToV2/types/v2.ts +0 -52
- package/src/migrations/FromV2ToV3/fixtures/input-v2-session.json +0 -72
- package/src/migrations/FromV2ToV3/fixtures/output-v3-from-v1.json +0 -203
- package/src/migrations/FromV2ToV3/fixtures/output-v3.json +0 -74
- package/src/migrations/FromV2ToV3/index.ts +0 -30
- package/src/migrations/FromV2ToV3/migrations.test.ts +0 -42
- package/src/migrations/FromV2ToV3/types/v3.ts +0 -27
- package/src/migrations/FromV3ToV4/fixtures/azure-input-v3.json +0 -79
- package/src/migrations/FromV3ToV4/fixtures/azure-output-v4.json +0 -75
- package/src/migrations/FromV3ToV4/fixtures/ollama-input-v3.json +0 -85
- package/src/migrations/FromV3ToV4/fixtures/ollama-output-v4.json +0 -86
- package/src/migrations/FromV3ToV4/fixtures/openai-input-v3.json +0 -77
- package/src/migrations/FromV3ToV4/fixtures/openai-output-v4.json +0 -77
- package/src/migrations/FromV3ToV4/fixtures/openrouter-input-v3.json +0 -82
- package/src/migrations/FromV3ToV4/fixtures/openrouter-output-v4.json +0 -85
- package/src/migrations/FromV3ToV4/fixtures/output-v4-from-v1.json +0 -203
- package/src/migrations/FromV3ToV4/index.ts +0 -102
- package/src/migrations/FromV3ToV4/migrations.test.ts +0 -195
- package/src/migrations/FromV3ToV4/types/v3.ts +0 -52
- package/src/migrations/FromV3ToV4/types/v4.ts +0 -37
- package/src/migrations/FromV4ToV5/fixtures/from-v1-to-v5-output.json +0 -245
- package/src/migrations/FromV4ToV5/fixtures/function-input-v4.json +0 -96
- package/src/migrations/FromV4ToV5/fixtures/function-output-v5.json +0 -120
- package/src/migrations/FromV4ToV5/index.ts +0 -58
- package/src/migrations/FromV4ToV5/migrations.test.ts +0 -49
- package/src/migrations/FromV4ToV5/types/v4.ts +0 -21
- package/src/migrations/FromV4ToV5/types/v5.ts +0 -27
- package/src/migrations/FromV5ToV6/fixtures/from-v1-to-v6-output.json +0 -247
- package/src/migrations/FromV5ToV6/fixtures/session-input-v5.json +0 -81
- package/src/migrations/FromV5ToV6/fixtures/session-output-v6.json +0 -85
- package/src/migrations/FromV5ToV6/index.ts +0 -61
- package/src/migrations/FromV5ToV6/migrations.test.ts +0 -50
- package/src/migrations/FromV5ToV6/types/v5.ts +0 -48
- package/src/migrations/FromV5ToV6/types/v6.ts +0 -63
- package/src/migrations/FromV6ToV7/fixtures/output-v7-from-v1.json +0 -203
- package/src/migrations/FromV6ToV7/fixtures/provider-input-v6.json +0 -103
- package/src/migrations/FromV6ToV7/fixtures/provider-output-v7.json +0 -118
- package/src/migrations/FromV6ToV7/index.ts +0 -101
- package/src/migrations/FromV6ToV7/migrations.test.ts +0 -64
- package/src/migrations/FromV6ToV7/types/v6.ts +0 -61
- package/src/migrations/FromV6ToV7/types/v7.ts +0 -69
- package/src/migrations/VersionController.test.ts +0 -88
- package/src/migrations/VersionController.ts +0 -67
- package/src/migrations/index.ts +0 -61
- package/src/server/routers/edge/appStatus.ts +0 -3
- package/src/server/routers/edge/index.ts +0 -14
- package/src/server/routers/edge/upload.ts +0 -16
- package/src/services/aiModel/client.ts +0 -70
- package/src/services/aiProvider/client.ts +0 -58
- package/src/services/baseClientService/index.ts +0 -9
- package/src/services/chatGroup/client.ts +0 -63
- package/src/services/export/_deprecated.ts +0 -155
- package/src/services/export/client.ts +0 -15
- package/src/services/file/_deprecated.test.ts +0 -119
- package/src/services/file/_deprecated.ts +0 -80
- package/src/services/file/client.test.ts +0 -199
- package/src/services/file/client.ts +0 -85
- package/src/services/import/_deprecated.ts +0 -115
- package/src/services/import/client.test.ts +0 -1015
- package/src/services/import/client.ts +0 -64
- package/src/services/message/_deprecated.test.ts +0 -398
- package/src/services/message/_deprecated.ts +0 -168
- package/src/services/message/client.test.ts +0 -410
- package/src/services/message/client.ts +0 -192
- package/src/services/plugin/_deprecated.test.ts +0 -162
- package/src/services/plugin/_deprecated.ts +0 -42
- package/src/services/plugin/client.test.ts +0 -177
- package/src/services/plugin/client.ts +0 -46
- package/src/services/session/_deprecated.test.ts +0 -440
- package/src/services/session/_deprecated.ts +0 -190
- package/src/services/session/client.test.ts +0 -413
- package/src/services/session/client.ts +0 -193
- package/src/services/thread/client.ts +0 -51
- package/src/services/topic/_deprecated.test.ts +0 -245
- package/src/services/topic/_deprecated.ts +0 -75
- package/src/services/topic/client.ts +0 -89
- package/src/services/topic/pglite.test.ts +0 -212
- package/src/services/user/_deprecated.test.ts +0 -101
- package/src/services/user/_deprecated.ts +0 -70
- package/src/services/user/client.test.ts +0 -111
- package/src/services/user/client.ts +0 -104
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { isServerMode } from '@lobechat/const';
|
|
2
1
|
import { z } from 'zod';
|
|
3
2
|
|
|
4
|
-
import { passwordProcedure } from '@/libs/trpc/edge';
|
|
5
3
|
import { authedProcedure, router } from '@/libs/trpc/lambda';
|
|
6
4
|
import { searchService } from '@/server/services/search';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
const searchProcedure = isServerMode ? authedProcedure : passwordProcedure;
|
|
6
|
+
const searchProcedure = authedProcedure;
|
|
10
7
|
|
|
11
8
|
export const searchRouter = router({
|
|
12
9
|
crawlPages: searchProcedure
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { edgeClient } from '@/libs/trpc/client';
|
|
4
|
-
import { globalHelpers } from '@/store/global/helpers';
|
|
5
|
-
|
|
6
3
|
import { toolService } from '../tool';
|
|
7
4
|
import openAPIV3 from './openai/OpenAPI_V3.json';
|
|
8
5
|
import OpenAIPlugin from './openai/plugin.json';
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService } from './client';
|
|
4
1
|
import { ServerService } from './server';
|
|
5
2
|
|
|
6
|
-
export const aiModelService =
|
|
7
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
8
|
-
? new ServerService()
|
|
9
|
-
: new ClientService();
|
|
3
|
+
export const aiModelService = new ServerService();
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService } from './client';
|
|
4
1
|
import { ServerService } from './server';
|
|
5
2
|
|
|
6
|
-
export const aiProviderService =
|
|
7
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
8
|
-
? new ServerService()
|
|
9
|
-
: new ClientService();
|
|
3
|
+
export const aiProviderService = new ServerService();
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService } from './client';
|
|
4
1
|
import { ServerService } from './server';
|
|
5
2
|
|
|
6
|
-
const
|
|
7
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new ServerService();
|
|
8
|
-
|
|
9
|
-
export const chatGroupService =
|
|
10
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
11
|
-
? new ServerService()
|
|
12
|
-
: clientService;
|
|
3
|
+
export const chatGroupService = new ServerService();
|
package/src/services/config.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import { BRANDING_NAME,
|
|
1
|
+
import { BRANDING_NAME, isServerMode } from '@lobechat/const';
|
|
2
2
|
import { downloadFile, exportJSONFile } from '@lobechat/utils/client';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
|
|
5
|
-
import { CURRENT_CONFIG_VERSION } from '@/migrations';
|
|
6
5
|
import { ImportPgDataStructure } from '@/types/export';
|
|
7
6
|
|
|
8
7
|
import { exportService } from './export';
|
|
9
|
-
import { configService as deprecatedExportService } from './export/_deprecated';
|
|
10
8
|
|
|
11
9
|
class ConfigService {
|
|
12
10
|
exportAll = async () => {
|
|
13
|
-
// TODO: remove this in V2
|
|
14
|
-
if (isDeprecatedEdition) {
|
|
15
|
-
const config = await deprecatedExportService.exportAll();
|
|
16
|
-
const filename = `${BRANDING_NAME}-config-v${CURRENT_CONFIG_VERSION}.json`;
|
|
17
|
-
exportJSONFile(config, filename);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
11
|
const { data, url } = await exportService.exportData();
|
|
22
12
|
const filename = `${dayjs().format('YYYY-MM-DD-hh-mm')}_${BRANDING_NAME}-data.json`;
|
|
23
13
|
|
|
@@ -34,60 +24,6 @@ class ConfigService {
|
|
|
34
24
|
exportJSONFile(result, filename);
|
|
35
25
|
};
|
|
36
26
|
|
|
37
|
-
exportAgents = async () => {
|
|
38
|
-
// TODO: remove this in V2
|
|
39
|
-
if (isDeprecatedEdition) {
|
|
40
|
-
const config = await deprecatedExportService.exportAgents();
|
|
41
|
-
const filename = `${BRANDING_NAME}-agents-v${CURRENT_CONFIG_VERSION}.json`;
|
|
42
|
-
exportJSONFile(config, filename);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exportSingleAgent = async (agentId: string) => {
|
|
48
|
-
// TODO: remove this in V2
|
|
49
|
-
if (isDeprecatedEdition) {
|
|
50
|
-
const result = await deprecatedExportService.exportSingleAgent(agentId);
|
|
51
|
-
if (!result) return;
|
|
52
|
-
|
|
53
|
-
const filename = `${BRANDING_NAME}-${result.title}-v${CURRENT_CONFIG_VERSION}.json`;
|
|
54
|
-
exportJSONFile(result.config, filename);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
exportSessions = async () => {
|
|
60
|
-
// TODO: remove this in V2
|
|
61
|
-
if (isDeprecatedEdition) {
|
|
62
|
-
const config = await deprecatedExportService.exportSessions();
|
|
63
|
-
const filename = `${BRANDING_NAME}-sessions-v${CURRENT_CONFIG_VERSION}.json`;
|
|
64
|
-
exportJSONFile(config, filename);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
exportSettings = async () => {
|
|
70
|
-
// TODO: remove this in V2
|
|
71
|
-
if (isDeprecatedEdition) {
|
|
72
|
-
const config = await deprecatedExportService.exportSessions();
|
|
73
|
-
const filename = `${BRANDING_NAME}-settings-v${CURRENT_CONFIG_VERSION}.json`;
|
|
74
|
-
exportJSONFile(config, filename);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
exportSingleSession = async (sessionId: string) => {
|
|
80
|
-
// TODO: remove this in V2
|
|
81
|
-
if (isDeprecatedEdition) {
|
|
82
|
-
const data = await deprecatedExportService.exportSingleSession(sessionId);
|
|
83
|
-
if (!data) return;
|
|
84
|
-
|
|
85
|
-
const filename = `${BRANDING_NAME}-${data.title}-v${CURRENT_CONFIG_VERSION}.json`;
|
|
86
|
-
exportJSONFile(data.config, filename);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
27
|
private createDataStructure = async (
|
|
92
28
|
data: any,
|
|
93
29
|
mode: 'pglite' | 'postgres',
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { isServerMode } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService } from './client';
|
|
4
1
|
import { ServerService } from './server';
|
|
5
2
|
|
|
6
|
-
export const exportService =
|
|
3
|
+
export const exportService = new ServerService();
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const fileService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
3
|
+
export const fileService = new ServerService();
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
2
|
-
import { ClientService } from './client';
|
|
3
1
|
import { ServerService } from './server';
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
7
|
-
|
|
8
|
-
export const importService =
|
|
9
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : clientService;
|
|
3
|
+
export const importService = new ServerService();
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const messageService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
3
|
+
export const messageService = new ServerService();
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const pluginService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
3
|
+
export const pluginService = new ServerService();
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const sessionService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
3
|
+
export const sessionService = new ServerService();
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getTableData = async (tableName: string) =>
|
|
15
|
-
this.tableViewerRepo.getTableData(tableName, { page: 1, pageSize: 300 });
|
|
1
|
+
export class ClientService {
|
|
2
|
+
getAllTables = async () => [];
|
|
3
|
+
|
|
4
|
+
getTableDetails = async (tableName: string) => {
|
|
5
|
+
console.log('getTableDetails:', tableName);
|
|
6
|
+
return [];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
getTableData = async (tableName: string) => {
|
|
10
|
+
console.log('getTableData:', tableName);
|
|
11
|
+
return [];
|
|
12
|
+
};
|
|
16
13
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService } from './client';
|
|
4
1
|
import { ServerService } from './server';
|
|
5
2
|
|
|
6
|
-
export const threadService =
|
|
7
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
8
|
-
? new ServerService()
|
|
9
|
-
: new ClientService();
|
|
3
|
+
export const threadService = new ServerService();
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const topicService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
3
|
+
export const topicService = new ServerService();
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import { isDesktop } from '@/const/version';
|
|
2
|
-
|
|
3
|
-
import { ClientService as DeprecatedService } from './_deprecated';
|
|
4
|
-
import { ClientService } from './client';
|
|
5
1
|
import { ServerService } from './server';
|
|
6
2
|
|
|
7
|
-
const
|
|
8
|
-
process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite' ? new ClientService() : new DeprecatedService();
|
|
9
|
-
|
|
10
|
-
export const userService =
|
|
11
|
-
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' || isDesktop
|
|
12
|
-
? new ServerService()
|
|
13
|
-
: clientService;
|
|
14
|
-
|
|
15
|
-
export const userClientService = clientService;
|
|
3
|
+
export const userService = new ServerService();
|
|
@@ -87,57 +87,6 @@ describe('chatMessage actions', () => {
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
describe('message creation', () => {
|
|
90
|
-
it('should create user message and trigger AI processing', async () => {
|
|
91
|
-
const { result } = renderHook(() => useChatStore());
|
|
92
|
-
|
|
93
|
-
await act(async () => {
|
|
94
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(messageService.createMessage).toHaveBeenCalledWith({
|
|
98
|
-
content: TEST_CONTENT.USER_MESSAGE,
|
|
99
|
-
files: undefined,
|
|
100
|
-
role: 'user',
|
|
101
|
-
sessionId: TEST_IDS.SESSION_ID,
|
|
102
|
-
topicId: TEST_IDS.TOPIC_ID,
|
|
103
|
-
});
|
|
104
|
-
expect(result.current.internal_coreProcessMessage).toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should send message with files attached', async () => {
|
|
108
|
-
const { result } = renderHook(() => useChatStore());
|
|
109
|
-
const files = [{ id: TEST_IDS.FILE_ID } as UploadFileItem];
|
|
110
|
-
|
|
111
|
-
await act(async () => {
|
|
112
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE, files });
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(messageService.createMessage).toHaveBeenCalledWith({
|
|
116
|
-
content: TEST_CONTENT.USER_MESSAGE,
|
|
117
|
-
files: [TEST_IDS.FILE_ID],
|
|
118
|
-
role: 'user',
|
|
119
|
-
sessionId: TEST_IDS.SESSION_ID,
|
|
120
|
-
topicId: TEST_IDS.TOPIC_ID,
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should send files without message content', async () => {
|
|
125
|
-
const { result } = renderHook(() => useChatStore());
|
|
126
|
-
const files = [{ id: TEST_IDS.FILE_ID } as UploadFileItem];
|
|
127
|
-
|
|
128
|
-
await act(async () => {
|
|
129
|
-
await result.current.sendMessage({ message: TEST_CONTENT.EMPTY, files });
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
expect(messageService.createMessage).toHaveBeenCalledWith({
|
|
133
|
-
content: TEST_CONTENT.EMPTY,
|
|
134
|
-
files: [TEST_IDS.FILE_ID],
|
|
135
|
-
role: 'user',
|
|
136
|
-
sessionId: TEST_IDS.SESSION_ID,
|
|
137
|
-
topicId: TEST_IDS.TOPIC_ID,
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
90
|
it('should not process AI when onlyAddUserMessage is true', async () => {
|
|
142
91
|
const { result } = renderHook(() => useChatStore());
|
|
143
92
|
|
|
@@ -169,196 +118,6 @@ describe('chatMessage actions', () => {
|
|
|
169
118
|
expect(result.current.internal_coreProcessMessage).not.toHaveBeenCalled();
|
|
170
119
|
});
|
|
171
120
|
});
|
|
172
|
-
|
|
173
|
-
describe('auto-create topic', () => {
|
|
174
|
-
const TOPIC_THRESHOLD = 5;
|
|
175
|
-
|
|
176
|
-
it('should create topic when threshold is reached and feature is enabled', async () => {
|
|
177
|
-
const { result } = renderHook(() => useChatStore());
|
|
178
|
-
|
|
179
|
-
const createTopicMock = vi.fn(() => Promise.resolve(TEST_IDS.NEW_TOPIC_ID));
|
|
180
|
-
const switchTopicMock = vi.fn();
|
|
181
|
-
|
|
182
|
-
act(() => {
|
|
183
|
-
setupMockSelectors({
|
|
184
|
-
agentConfig: {
|
|
185
|
-
enableAutoCreateTopic: true,
|
|
186
|
-
autoCreateTopicThreshold: TOPIC_THRESHOLD,
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
useChatStore.setState({
|
|
191
|
-
activeTopicId: undefined,
|
|
192
|
-
messagesMap: {
|
|
193
|
-
[messageMapKey(TEST_IDS.SESSION_ID)]: createMockMessages(TOPIC_THRESHOLD),
|
|
194
|
-
},
|
|
195
|
-
createTopic: createTopicMock,
|
|
196
|
-
switchTopic: switchTopicMock,
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
await act(async () => {
|
|
201
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
expect(createTopicMock).toHaveBeenCalled();
|
|
205
|
-
expect(switchTopicMock).toHaveBeenCalledWith(TEST_IDS.NEW_TOPIC_ID, true);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe('RAG integration', () => {
|
|
210
|
-
it('should include RAG query when RAG is enabled', async () => {
|
|
211
|
-
const { result } = renderHook(() => useChatStore());
|
|
212
|
-
vi.spyOn(result.current, 'internal_shouldUseRAG').mockReturnValue(true);
|
|
213
|
-
|
|
214
|
-
await act(async () => {
|
|
215
|
-
await result.current.sendMessage({ message: TEST_CONTENT.RAG_QUERY });
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(result.current.internal_coreProcessMessage).toHaveBeenCalledWith(
|
|
219
|
-
expect.any(Array),
|
|
220
|
-
expect.any(String),
|
|
221
|
-
expect.objectContaining({
|
|
222
|
-
ragQuery: TEST_CONTENT.RAG_QUERY,
|
|
223
|
-
}),
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should not use RAG when feature is disabled', async () => {
|
|
228
|
-
const { result } = renderHook(() => useChatStore());
|
|
229
|
-
vi.spyOn(result.current, 'internal_shouldUseRAG').mockReturnValue(false);
|
|
230
|
-
const retrieveChunksSpy = vi.spyOn(result.current, 'internal_retrieveChunks');
|
|
231
|
-
|
|
232
|
-
await act(async () => {
|
|
233
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
expect(retrieveChunksSpy).not.toHaveBeenCalled();
|
|
237
|
-
expect(result.current.internal_coreProcessMessage).toHaveBeenCalledWith(
|
|
238
|
-
expect.any(Array),
|
|
239
|
-
expect.any(String),
|
|
240
|
-
expect.not.objectContaining({
|
|
241
|
-
ragQuery: expect.anything(),
|
|
242
|
-
}),
|
|
243
|
-
);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe('special flags', () => {
|
|
248
|
-
it('should pass isWelcomeQuestion flag to processing', async () => {
|
|
249
|
-
const { result } = renderHook(() => useChatStore());
|
|
250
|
-
|
|
251
|
-
await act(async () => {
|
|
252
|
-
await result.current.sendMessage({
|
|
253
|
-
message: TEST_CONTENT.USER_MESSAGE,
|
|
254
|
-
isWelcomeQuestion: true,
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
expect(result.current.internal_coreProcessMessage).toHaveBeenCalledWith(
|
|
259
|
-
expect.anything(),
|
|
260
|
-
expect.anything(),
|
|
261
|
-
{ isWelcomeQuestion: true },
|
|
262
|
-
);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('should return early when onlyAddUserMessage is true', async () => {
|
|
266
|
-
const { result } = renderHook(() => useChatStore());
|
|
267
|
-
|
|
268
|
-
await act(async () => {
|
|
269
|
-
await result.current.sendMessage({
|
|
270
|
-
message: TEST_CONTENT.USER_MESSAGE,
|
|
271
|
-
onlyAddUserMessage: true,
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
expect(result.current.internal_coreProcessMessage).not.toHaveBeenCalled();
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
describe('topic creation flow', () => {
|
|
280
|
-
it('should handle tempMessage during topic creation', async () => {
|
|
281
|
-
setupMockSelectors({
|
|
282
|
-
chatConfig: { enableAutoCreateTopic: true, autoCreateTopicThreshold: 2 },
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
act(() => {
|
|
286
|
-
useChatStore.setState({ activeTopicId: undefined });
|
|
287
|
-
setupStoreWithMessages(createMockMessages(5));
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const { result } = renderHook(() => useChatStore());
|
|
291
|
-
const createTopicMock = vi
|
|
292
|
-
.spyOn(result.current, 'createTopic')
|
|
293
|
-
.mockResolvedValue(TEST_IDS.NEW_TOPIC_ID);
|
|
294
|
-
const toggleMessageLoadingSpy = vi.spyOn(result.current, 'internal_toggleMessageLoading');
|
|
295
|
-
const createTmpMessageSpy = vi
|
|
296
|
-
.spyOn(result.current, 'internal_createTmpMessage')
|
|
297
|
-
.mockReturnValue('temp-id');
|
|
298
|
-
vi.spyOn(result.current, 'internal_fetchMessages').mockResolvedValue();
|
|
299
|
-
vi.spyOn(result.current, 'switchTopic').mockResolvedValue();
|
|
300
|
-
|
|
301
|
-
await act(async () => {
|
|
302
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
expect(createTmpMessageSpy).toHaveBeenCalled();
|
|
306
|
-
expect(toggleMessageLoadingSpy).toHaveBeenCalledWith(true, 'temp-id');
|
|
307
|
-
expect(createTopicMock).toHaveBeenCalled();
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('should call summaryTopicTitle after processing when new topic created', async () => {
|
|
311
|
-
setupMockSelectors({
|
|
312
|
-
chatConfig: { enableAutoCreateTopic: true, autoCreateTopicThreshold: 2 },
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
act(() => {
|
|
316
|
-
useChatStore.setState({ activeTopicId: undefined });
|
|
317
|
-
setupStoreWithMessages(createMockMessages(5));
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const { result } = renderHook(() => useChatStore());
|
|
321
|
-
vi.spyOn(result.current, 'createTopic').mockResolvedValue(TEST_IDS.NEW_TOPIC_ID);
|
|
322
|
-
vi.spyOn(result.current, 'internal_createTmpMessage').mockReturnValue('temp-id');
|
|
323
|
-
vi.spyOn(result.current, 'internal_fetchMessages').mockResolvedValue();
|
|
324
|
-
vi.spyOn(result.current, 'switchTopic').mockResolvedValue();
|
|
325
|
-
|
|
326
|
-
const summaryTopicTitleSpy = vi
|
|
327
|
-
.spyOn(result.current, 'summaryTopicTitle')
|
|
328
|
-
.mockResolvedValue();
|
|
329
|
-
|
|
330
|
-
await act(async () => {
|
|
331
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
expect(summaryTopicTitleSpy).toHaveBeenCalledWith(TEST_IDS.NEW_TOPIC_ID, expect.any(Array));
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('should handle topic creation failure gracefully', async () => {
|
|
338
|
-
setupMockSelectors({
|
|
339
|
-
chatConfig: { enableAutoCreateTopic: true, autoCreateTopicThreshold: 2 },
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
act(() => {
|
|
343
|
-
useChatStore.setState({ activeTopicId: undefined });
|
|
344
|
-
setupStoreWithMessages(createMockMessages(5));
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
const { result } = renderHook(() => useChatStore());
|
|
348
|
-
vi.spyOn(result.current, 'createTopic').mockResolvedValue(undefined);
|
|
349
|
-
vi.spyOn(result.current, 'internal_createTmpMessage').mockReturnValue('temp-id');
|
|
350
|
-
const toggleLoadingSpy = vi.spyOn(result.current, 'internal_toggleMessageLoading');
|
|
351
|
-
const updateTopicLoadingSpy = vi.spyOn(result.current, 'internal_updateTopicLoading');
|
|
352
|
-
|
|
353
|
-
await act(async () => {
|
|
354
|
-
await result.current.sendMessage({ message: TEST_CONTENT.USER_MESSAGE });
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// Should still call the AI processing even if topic creation fails
|
|
358
|
-
expect(result.current.internal_coreProcessMessage).toHaveBeenCalled();
|
|
359
|
-
expect(updateTopicLoadingSpy).not.toHaveBeenCalled();
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
121
|
});
|
|
363
122
|
|
|
364
123
|
describe('regenerateMessage', () => {
|
|
@@ -19,8 +19,33 @@ import { resetTestEnvironment, setupMockSelectors, spyOnMessageService } from '.
|
|
|
19
19
|
// Keep zustand mock as it's needed globally
|
|
20
20
|
vi.mock('zustand/traditional');
|
|
21
21
|
|
|
22
|
+
// Mock AntdStaticMethods
|
|
23
|
+
vi.mock('@/components/AntdStaticMethods', () => ({
|
|
24
|
+
notification: {
|
|
25
|
+
error: vi.fn(),
|
|
26
|
+
success: vi.fn(),
|
|
27
|
+
info: vi.fn(),
|
|
28
|
+
warning: vi.fn(),
|
|
29
|
+
},
|
|
30
|
+
message: {
|
|
31
|
+
error: vi.fn(),
|
|
32
|
+
success: vi.fn(),
|
|
33
|
+
info: vi.fn(),
|
|
34
|
+
warning: vi.fn(),
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
// Mock sessionService to prevent TRPC requests
|
|
39
|
+
vi.mock('@/services/session', () => ({
|
|
40
|
+
sessionService: {
|
|
41
|
+
updateSession: vi.fn(),
|
|
42
|
+
updateSessionConfig: vi.fn(),
|
|
43
|
+
updateSessionChatConfig: vi.fn(),
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
|
|
22
47
|
// Mock server mode for V2 tests
|
|
23
|
-
vi.mock('
|
|
48
|
+
vi.mock('@lobechat/const', async (importOriginal) => {
|
|
24
49
|
const module = await importOriginal();
|
|
25
50
|
return {
|
|
26
51
|
...(module as any),
|
|
@@ -60,7 +60,9 @@ export const spyOnMessageService = () => {
|
|
|
60
60
|
const createMessageSpy = vi
|
|
61
61
|
.spyOn(messageService, 'createMessage')
|
|
62
62
|
.mockResolvedValue(TEST_IDS.NEW_MESSAGE_ID);
|
|
63
|
-
const updateMessageSpy = vi
|
|
63
|
+
const updateMessageSpy = vi
|
|
64
|
+
.spyOn(messageService, 'updateMessage')
|
|
65
|
+
.mockResolvedValue({ messages: [], success: true });
|
|
64
66
|
const removeMessageSpy = vi.spyOn(messageService, 'removeMessage').mockResolvedValue(undefined);
|
|
65
67
|
const updateMessageErrorSpy = vi
|
|
66
68
|
.spyOn(messageService, 'updateMessageError')
|