@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,162 +0,0 @@
|
|
|
1
|
-
import { LobeTool } from '@lobechat/types';
|
|
2
|
-
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { PluginModel } from '@/database/_deprecated/models/plugin';
|
|
6
|
-
import { DB_Plugin } from '@/database/_deprecated/schemas/plugin';
|
|
7
|
-
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
8
|
-
|
|
9
|
-
import { ClientService } from './_deprecated';
|
|
10
|
-
import { InstallPluginParams } from './type';
|
|
11
|
-
|
|
12
|
-
const pluginService = new ClientService();
|
|
13
|
-
|
|
14
|
-
// Mocking modules and functions
|
|
15
|
-
|
|
16
|
-
vi.mock('@/database/_deprecated/models/plugin', () => ({
|
|
17
|
-
PluginModel: {
|
|
18
|
-
getList: vi.fn(),
|
|
19
|
-
create: vi.fn(),
|
|
20
|
-
delete: vi.fn(),
|
|
21
|
-
update: vi.fn(),
|
|
22
|
-
clear: vi.fn(),
|
|
23
|
-
},
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
vi.resetAllMocks();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('PluginService', () => {
|
|
31
|
-
describe('installPlugin', () => {
|
|
32
|
-
it('should install a plugin', async () => {
|
|
33
|
-
// Arrange
|
|
34
|
-
const fakePlugin = {
|
|
35
|
-
identifier: 'test-plugin',
|
|
36
|
-
manifest: { name: 'TestPlugin', version: '1.0.0' } as unknown as LobeChatPluginManifest,
|
|
37
|
-
type: 'plugin',
|
|
38
|
-
} as InstallPluginParams;
|
|
39
|
-
vi.mocked(PluginModel.create).mockResolvedValue(fakePlugin);
|
|
40
|
-
|
|
41
|
-
// Act
|
|
42
|
-
const installedPlugin = await pluginService.installPlugin(fakePlugin);
|
|
43
|
-
|
|
44
|
-
// Assert
|
|
45
|
-
expect(PluginModel.create).toHaveBeenCalledWith(fakePlugin);
|
|
46
|
-
expect(installedPlugin).toEqual(fakePlugin);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('getInstalledPlugins', () => {
|
|
51
|
-
it('should return a list of installed plugins', async () => {
|
|
52
|
-
// Arrange
|
|
53
|
-
const fakePlugins = [{ identifier: 'test-plugin', type: 'plugin' }] as LobeTool[];
|
|
54
|
-
vi.mocked(PluginModel.getList).mockResolvedValue(fakePlugins as DB_Plugin[]);
|
|
55
|
-
|
|
56
|
-
// Act
|
|
57
|
-
const installedPlugins = await pluginService.getInstalledPlugins();
|
|
58
|
-
|
|
59
|
-
// Assert
|
|
60
|
-
expect(PluginModel.getList).toHaveBeenCalled();
|
|
61
|
-
expect(installedPlugins).toEqual(fakePlugins);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('uninstallPlugin', () => {
|
|
66
|
-
it('should uninstall a plugin', async () => {
|
|
67
|
-
// Arrange
|
|
68
|
-
const identifier = 'test-plugin';
|
|
69
|
-
vi.mocked(PluginModel.delete).mockResolvedValue();
|
|
70
|
-
|
|
71
|
-
// Act
|
|
72
|
-
const result = await pluginService.uninstallPlugin(identifier);
|
|
73
|
-
|
|
74
|
-
// Assert
|
|
75
|
-
expect(PluginModel.delete).toHaveBeenCalledWith(identifier);
|
|
76
|
-
expect(result).toBe(undefined);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('createCustomPlugin', () => {
|
|
81
|
-
it('should create a custom plugin', async () => {
|
|
82
|
-
// Arrange
|
|
83
|
-
const customPlugin = {
|
|
84
|
-
identifier: 'custom-plugin',
|
|
85
|
-
manifest: {},
|
|
86
|
-
type: 'customPlugin',
|
|
87
|
-
} as LobeToolCustomPlugin;
|
|
88
|
-
vi.mocked(PluginModel.create).mockResolvedValue(customPlugin);
|
|
89
|
-
|
|
90
|
-
// Act
|
|
91
|
-
const result = await pluginService.createCustomPlugin(customPlugin);
|
|
92
|
-
|
|
93
|
-
// Assert
|
|
94
|
-
expect(PluginModel.create).toHaveBeenCalledWith({
|
|
95
|
-
...customPlugin,
|
|
96
|
-
type: 'customPlugin',
|
|
97
|
-
});
|
|
98
|
-
expect(result).toEqual(customPlugin);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('updatePlugin', () => {
|
|
103
|
-
it('should update a plugin', async () => {
|
|
104
|
-
// Arrange
|
|
105
|
-
const id = 'plugin-id';
|
|
106
|
-
const value = { settings: { ab: '1' } } as unknown as LobeToolCustomPlugin;
|
|
107
|
-
vi.mocked(PluginModel.update).mockResolvedValue(1);
|
|
108
|
-
|
|
109
|
-
// Act
|
|
110
|
-
const result = await pluginService.updatePlugin(id, value);
|
|
111
|
-
|
|
112
|
-
// Assert
|
|
113
|
-
expect(PluginModel.update).toHaveBeenCalledWith(id, value);
|
|
114
|
-
expect(result).toEqual(undefined);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('updatePluginManifest', () => {
|
|
119
|
-
it('should update a plugin manifest', async () => {
|
|
120
|
-
// Arrange
|
|
121
|
-
const id = 'plugin-id';
|
|
122
|
-
const manifest = { name: 'NewPluginManifest' } as unknown as LobeChatPluginManifest;
|
|
123
|
-
vi.mocked(PluginModel.update).mockResolvedValue(1);
|
|
124
|
-
|
|
125
|
-
// Act
|
|
126
|
-
const result = await pluginService.updatePluginManifest(id, manifest);
|
|
127
|
-
|
|
128
|
-
// Assert
|
|
129
|
-
expect(PluginModel.update).toHaveBeenCalledWith(id, { manifest });
|
|
130
|
-
expect(result).toEqual(undefined);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('removeAllPlugins', () => {
|
|
135
|
-
it('should remove all plugins', async () => {
|
|
136
|
-
// Arrange
|
|
137
|
-
vi.mocked(PluginModel.clear).mockResolvedValue(undefined);
|
|
138
|
-
|
|
139
|
-
// Act
|
|
140
|
-
const result = await pluginService.removeAllPlugins();
|
|
141
|
-
|
|
142
|
-
// Assert
|
|
143
|
-
expect(PluginModel.clear).toHaveBeenCalled();
|
|
144
|
-
expect(result).toBe(undefined);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('updatePluginSettings', () => {
|
|
149
|
-
it('should update plugin settings', async () => {
|
|
150
|
-
// Arrange
|
|
151
|
-
const id = 'plugin-id';
|
|
152
|
-
const settings = { color: 'blue' };
|
|
153
|
-
|
|
154
|
-
// Act
|
|
155
|
-
const result = await pluginService.updatePluginSettings(id, settings);
|
|
156
|
-
|
|
157
|
-
// Assert
|
|
158
|
-
expect(PluginModel.update).toHaveBeenCalledWith(id, { settings });
|
|
159
|
-
expect(result).toEqual(undefined);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { LobeTool } from '@lobechat/types';
|
|
2
|
-
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
3
|
-
|
|
4
|
-
import { PluginModel } from '@/database/_deprecated/models/plugin';
|
|
5
|
-
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
6
|
-
|
|
7
|
-
import { IPluginService, InstallPluginParams } from './type';
|
|
8
|
-
|
|
9
|
-
export class ClientService implements IPluginService {
|
|
10
|
-
installPlugin = async (plugin: InstallPluginParams) => {
|
|
11
|
-
return PluginModel.create(plugin);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
getInstalledPlugins = () => {
|
|
15
|
-
return PluginModel.getList() as Promise<LobeTool[]>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
uninstallPlugin(identifier: string) {
|
|
19
|
-
return PluginModel.delete(identifier);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async createCustomPlugin(customPlugin: LobeToolCustomPlugin) {
|
|
23
|
-
return PluginModel.create({ ...customPlugin, type: 'customPlugin' });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async updatePlugin(id: string, value: Partial<LobeToolCustomPlugin>) {
|
|
27
|
-
await PluginModel.update(id, value);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
async updatePluginManifest(id: string, manifest: LobeChatPluginManifest) {
|
|
31
|
-
await PluginModel.update(id, { manifest });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async removeAllPlugins() {
|
|
35
|
-
return PluginModel.clear();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
-
async updatePluginSettings(id: string, settings: any, _?: AbortSignal) {
|
|
40
|
-
await PluginModel.update(id, { settings });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { LobeTool } from '@lobechat/types';
|
|
2
|
-
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
3
|
-
import { eq } from 'drizzle-orm';
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
import { clientDB, initializeDB } from '@/database/client/db';
|
|
7
|
-
import { userInstalledPlugins, users } from '@/database/schemas';
|
|
8
|
-
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
9
|
-
|
|
10
|
-
import { ClientService } from './client';
|
|
11
|
-
import { InstallPluginParams } from './type';
|
|
12
|
-
|
|
13
|
-
// Mocking modules and functions
|
|
14
|
-
|
|
15
|
-
const userId = 'message-db';
|
|
16
|
-
const pluginService = new ClientService(userId);
|
|
17
|
-
|
|
18
|
-
// Mock data
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
await initializeDB();
|
|
21
|
-
|
|
22
|
-
// 在每个测试用例之前,重置表数据
|
|
23
|
-
await clientDB.transaction(async (trx) => {
|
|
24
|
-
await trx.delete(users);
|
|
25
|
-
await trx.insert(users).values([{ id: userId }, { id: '456' }]);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('PluginService', () => {
|
|
30
|
-
describe('installPlugin', () => {
|
|
31
|
-
it('should install a plugin', async () => {
|
|
32
|
-
// Arrange
|
|
33
|
-
const fakePlugin = {
|
|
34
|
-
identifier: 'test-plugin-d',
|
|
35
|
-
manifest: { name: 'TestPlugin', version: '1.0.0' } as unknown as LobeChatPluginManifest,
|
|
36
|
-
type: 'plugin',
|
|
37
|
-
} as InstallPluginParams;
|
|
38
|
-
|
|
39
|
-
// Act
|
|
40
|
-
await pluginService.installPlugin(fakePlugin);
|
|
41
|
-
|
|
42
|
-
// Assert
|
|
43
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
44
|
-
where: eq(userInstalledPlugins.identifier, fakePlugin.identifier),
|
|
45
|
-
});
|
|
46
|
-
expect(result).toMatchObject(fakePlugin);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('getInstalledPlugins', () => {
|
|
51
|
-
it('should return a list of installed plugins', async () => {
|
|
52
|
-
// Arrange
|
|
53
|
-
const fakePlugins = [{ identifier: 'test-plugin', type: 'plugin' }] as LobeTool[];
|
|
54
|
-
await clientDB
|
|
55
|
-
.insert(userInstalledPlugins)
|
|
56
|
-
.values([{ identifier: 'test-plugin', type: 'plugin', userId }]);
|
|
57
|
-
// Act
|
|
58
|
-
const data = await pluginService.getInstalledPlugins();
|
|
59
|
-
|
|
60
|
-
// Assert
|
|
61
|
-
expect(data).toMatchObject(fakePlugins);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('uninstallPlugin', () => {
|
|
66
|
-
it('should uninstall a plugin', async () => {
|
|
67
|
-
// Arrange
|
|
68
|
-
const identifier = 'test-plugin';
|
|
69
|
-
await clientDB.insert(userInstalledPlugins).values([{ identifier, type: 'plugin', userId }]);
|
|
70
|
-
|
|
71
|
-
// Act
|
|
72
|
-
await pluginService.uninstallPlugin(identifier);
|
|
73
|
-
|
|
74
|
-
// Assert
|
|
75
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
76
|
-
where: eq(userInstalledPlugins.identifier, identifier),
|
|
77
|
-
});
|
|
78
|
-
expect(result).toBe(undefined);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('createCustomPlugin', () => {
|
|
83
|
-
it('should create a custom plugin', async () => {
|
|
84
|
-
// Arrange
|
|
85
|
-
const customPlugin = {
|
|
86
|
-
identifier: 'custom-plugin-x',
|
|
87
|
-
manifest: {},
|
|
88
|
-
type: 'customPlugin',
|
|
89
|
-
} as LobeToolCustomPlugin;
|
|
90
|
-
|
|
91
|
-
// Act
|
|
92
|
-
await pluginService.createCustomPlugin(customPlugin);
|
|
93
|
-
|
|
94
|
-
// Assert
|
|
95
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
96
|
-
where: eq(userInstalledPlugins.identifier, customPlugin.identifier),
|
|
97
|
-
});
|
|
98
|
-
expect(result).toMatchObject(customPlugin);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('updatePlugin', () => {
|
|
103
|
-
it('should update a plugin', async () => {
|
|
104
|
-
// Arrange
|
|
105
|
-
const identifier = 'plugin-id';
|
|
106
|
-
const value = { customParams: { ab: '1' } } as unknown as LobeToolCustomPlugin;
|
|
107
|
-
await clientDB.insert(userInstalledPlugins).values([{ identifier, type: 'plugin', userId }]);
|
|
108
|
-
|
|
109
|
-
// Act
|
|
110
|
-
await pluginService.updatePlugin(identifier, value);
|
|
111
|
-
|
|
112
|
-
// Assert
|
|
113
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
114
|
-
where: eq(userInstalledPlugins.identifier, identifier),
|
|
115
|
-
});
|
|
116
|
-
expect(result).toMatchObject(value);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('updatePluginManifest', () => {
|
|
121
|
-
it('should update a plugin manifest', async () => {
|
|
122
|
-
// Arrange
|
|
123
|
-
const identifier = 'plugin-id';
|
|
124
|
-
const manifest = { name: 'NewPluginManifest' } as unknown as LobeChatPluginManifest;
|
|
125
|
-
await clientDB.insert(userInstalledPlugins).values([{ identifier, type: 'plugin', userId }]);
|
|
126
|
-
|
|
127
|
-
// Act
|
|
128
|
-
await pluginService.updatePluginManifest(identifier, manifest);
|
|
129
|
-
|
|
130
|
-
// Assert
|
|
131
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
132
|
-
where: eq(userInstalledPlugins.identifier, identifier),
|
|
133
|
-
});
|
|
134
|
-
expect(result).toMatchObject({ manifest });
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('removeAllPlugins', () => {
|
|
139
|
-
it('should remove all plugins', async () => {
|
|
140
|
-
// Arrange
|
|
141
|
-
await clientDB.insert(userInstalledPlugins).values([
|
|
142
|
-
{ identifier: '123', type: 'plugin', userId },
|
|
143
|
-
{ identifier: '234', type: 'plugin', userId },
|
|
144
|
-
]);
|
|
145
|
-
|
|
146
|
-
// Act
|
|
147
|
-
await pluginService.removeAllPlugins();
|
|
148
|
-
|
|
149
|
-
// Assert
|
|
150
|
-
const result = await clientDB.query.userInstalledPlugins.findMany({
|
|
151
|
-
where: eq(userInstalledPlugins.userId, userId),
|
|
152
|
-
});
|
|
153
|
-
expect(result.length).toEqual(0);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('updatePluginSettings', () => {
|
|
158
|
-
it('should update plugin settings', async () => {
|
|
159
|
-
// Arrange
|
|
160
|
-
const id = 'plugin-id';
|
|
161
|
-
const settings = { color: 'blue' };
|
|
162
|
-
await clientDB
|
|
163
|
-
.insert(userInstalledPlugins)
|
|
164
|
-
.values([{ identifier: id, type: 'plugin', userId }]);
|
|
165
|
-
|
|
166
|
-
// Act
|
|
167
|
-
await pluginService.updatePluginSettings(id, settings);
|
|
168
|
-
|
|
169
|
-
// Assert
|
|
170
|
-
const result = await clientDB.query.userInstalledPlugins.findFirst({
|
|
171
|
-
where: eq(userInstalledPlugins.identifier, id),
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect(result).toMatchObject({ settings });
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LobeTool } from '@lobechat/types';
|
|
2
|
-
|
|
3
|
-
import { clientDB } from '@/database/client/db';
|
|
4
|
-
import { PluginModel } from '@/database/models/plugin';
|
|
5
|
-
import { BaseClientService } from '@/services/baseClientService';
|
|
6
|
-
|
|
7
|
-
import { IPluginService } from './type';
|
|
8
|
-
|
|
9
|
-
export class ClientService extends BaseClientService implements IPluginService {
|
|
10
|
-
private get pluginModel(): PluginModel {
|
|
11
|
-
return new PluginModel(clientDB as any, this.userId);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
installPlugin: IPluginService['installPlugin'] = async (plugin) => {
|
|
15
|
-
await this.pluginModel.create(plugin);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
getInstalledPlugins: IPluginService['getInstalledPlugins'] = () => {
|
|
19
|
-
return this.pluginModel.query() as Promise<LobeTool[]>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
|
|
23
|
-
await this.pluginModel.delete(identifier);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
|
|
27
|
-
await this.pluginModel.create({ ...customPlugin, type: 'customPlugin' });
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
updatePlugin: IPluginService['updatePlugin'] = async (id, value) => {
|
|
31
|
-
await this.pluginModel.update(id, value);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
|
|
35
|
-
await this.pluginModel.update(id, { manifest });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
removeAllPlugins: IPluginService['removeAllPlugins'] = async () => {
|
|
39
|
-
await this.pluginModel.deleteAll();
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
-
updatePluginSettings: IPluginService['updatePluginSettings'] = async (id, settings, _?) => {
|
|
44
|
-
await this.pluginModel.update(id, { settings });
|
|
45
|
-
};
|
|
46
|
-
}
|