@lobehub/lobehub 2.0.0-next.26 → 2.0.0-next.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/package.json +1 -1
  4. package/packages/types/src/topic/topic.ts +14 -0
  5. package/src/server/routers/lambda/topic.ts +7 -1
  6. package/src/services/aiModel/index.test.ts +3 -3
  7. package/src/services/aiModel/index.ts +56 -2
  8. package/src/services/aiProvider/index.test.ts +2 -2
  9. package/src/services/aiProvider/index.ts +48 -2
  10. package/src/services/chatGroup/index.ts +66 -2
  11. package/src/services/export/index.ts +10 -2
  12. package/src/services/file/index.ts +61 -2
  13. package/src/services/import/index.ts +133 -2
  14. package/src/services/message/index.ts +176 -2
  15. package/src/services/message/{__tests__/server.test.ts → server.test.ts} +3 -3
  16. package/src/services/plugin/index.test.ts +8 -0
  17. package/src/services/plugin/index.ts +53 -2
  18. package/src/services/session/index.test.ts +8 -0
  19. package/src/services/session/index.ts +145 -2
  20. package/src/services/thread/index.test.ts +8 -0
  21. package/src/services/thread/index.ts +38 -2
  22. package/src/services/topic/index.test.ts +8 -0
  23. package/src/services/topic/index.ts +76 -2
  24. package/src/services/user/index.test.ts +8 -0
  25. package/src/services/user/index.ts +53 -2
  26. package/src/store/aiInfra/slices/aiModel/action.test.ts +17 -9
  27. package/src/store/chat/slices/aiChat/actions/__tests__/helpers.ts +4 -2
  28. package/src/store/chat/slices/topic/action.test.ts +1 -1
  29. package/src/store/chat/slices/topic/action.ts +1 -2
  30. package/src/store/chat/slices/topic/reducer.ts +1 -2
  31. package/src/store/file/slices/chat/action.ts +1 -4
  32. package/src/store/file/slices/fileManager/action.ts +2 -3
  33. package/src/store/session/slices/sessionGroup/action.test.ts +5 -5
  34. package/src/store/user/slices/common/action.test.ts +1 -1
  35. package/src/services/aiModel/server.test.ts +0 -122
  36. package/src/services/aiModel/server.ts +0 -51
  37. package/src/services/aiModel/type.ts +0 -32
  38. package/src/services/aiProvider/server.ts +0 -43
  39. package/src/services/aiProvider/type.ts +0 -27
  40. package/src/services/chatGroup/server.ts +0 -67
  41. package/src/services/chatGroup/type.ts +0 -22
  42. package/src/services/export/server.ts +0 -9
  43. package/src/services/export/type.ts +0 -5
  44. package/src/services/file/server.ts +0 -53
  45. package/src/services/file/type.ts +0 -13
  46. package/src/services/import/server.ts +0 -133
  47. package/src/services/import/type.ts +0 -17
  48. package/src/services/message/server.ts +0 -151
  49. package/src/services/message/type.ts +0 -55
  50. package/src/services/plugin/server.ts +0 -42
  51. package/src/services/plugin/type.ts +0 -23
  52. package/src/services/session/server.test.ts +0 -260
  53. package/src/services/session/server.ts +0 -125
  54. package/src/services/session/type.ts +0 -82
  55. package/src/services/thread/server.ts +0 -32
  56. package/src/services/thread/type.ts +0 -21
  57. package/src/services/topic/server.ts +0 -57
  58. package/src/services/topic/type.ts +0 -40
  59. package/src/services/user/server.test.ts +0 -149
  60. package/src/services/user/server.ts +0 -47
  61. package/src/services/user/type.ts +0 -21
@@ -1,151 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { ChatTranslate, UIChatMessage } from '@lobechat/types';
3
-
4
- import { INBOX_SESSION_ID } from '@/const/session';
5
- import { lambdaClient } from '@/libs/trpc/client';
6
- import { useUserStore } from '@/store/user';
7
- import { labPreferSelectors } from '@/store/user/selectors';
8
-
9
- import { IMessageService } from './type';
10
-
11
- export class ServerService implements IMessageService {
12
- createMessage: IMessageService['createMessage'] = async ({ sessionId, ...params }) => {
13
- return lambdaClient.message.createMessage.mutate({
14
- ...params,
15
- sessionId: sessionId ? this.toDbSessionId(sessionId) : undefined,
16
- });
17
- };
18
-
19
- createNewMessage: IMessageService['createNewMessage'] = async ({ sessionId, ...params }) => {
20
- return lambdaClient.message.createNewMessage.mutate({
21
- ...params,
22
- sessionId: sessionId ? this.toDbSessionId(sessionId) : undefined,
23
- });
24
- };
25
-
26
- getMessages: IMessageService['getMessages'] = async (sessionId, topicId, groupId) => {
27
- // Get user lab preference for message grouping
28
- const useGroup = labPreferSelectors.enableAssistantMessageGroup(useUserStore.getState());
29
-
30
- const data = await lambdaClient.message.getMessages.query({
31
- groupId,
32
- sessionId: this.toDbSessionId(sessionId),
33
- topicId,
34
- useGroup,
35
- });
36
-
37
- return data as unknown as UIChatMessage[];
38
- };
39
-
40
- getGroupMessages: IMessageService['getGroupMessages'] = async (groupId, topicId) => {
41
- // Get user lab preference for message grouping
42
- const useGroup = labPreferSelectors.enableAssistantMessageGroup(useUserStore.getState());
43
-
44
- const data = await lambdaClient.message.getMessages.query({
45
- groupId,
46
- topicId,
47
- useGroup,
48
- });
49
- return data as unknown as UIChatMessage[];
50
- };
51
-
52
- countMessages: IMessageService['countMessages'] = async (params) => {
53
- return lambdaClient.message.count.query(params);
54
- };
55
-
56
- countWords: IMessageService['countWords'] = async (params) => {
57
- return lambdaClient.message.countWords.query(params);
58
- };
59
-
60
- rankModels: IMessageService['rankModels'] = async () => {
61
- return lambdaClient.message.rankModels.query();
62
- };
63
-
64
- getHeatmaps: IMessageService['getHeatmaps'] = async () => {
65
- return lambdaClient.message.getHeatmaps.query();
66
- };
67
-
68
- updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
69
- return lambdaClient.message.update.mutate({ id, value: { error } });
70
- };
71
-
72
- updateMessagePluginArguments: IMessageService['updateMessagePluginArguments'] = async (
73
- id,
74
- value,
75
- ) => {
76
- const args = typeof value === 'string' ? value : JSON.stringify(value);
77
- return lambdaClient.message.updateMessagePlugin.mutate({ id, value: { arguments: args } });
78
- };
79
-
80
- updateMessage: IMessageService['updateMessage'] = async (id, value, options) => {
81
- return lambdaClient.message.update.mutate({
82
- id,
83
- sessionId: options?.sessionId,
84
- topicId: options?.topicId,
85
- value,
86
- });
87
- };
88
-
89
- updateMessageTranslate: IMessageService['updateMessageTranslate'] = async (id, translate) => {
90
- return lambdaClient.message.updateTranslate.mutate({ id, value: translate as ChatTranslate });
91
- };
92
-
93
- updateMessageTTS: IMessageService['updateMessageTTS'] = async (id, tts) => {
94
- return lambdaClient.message.updateTTS.mutate({ id, value: tts });
95
- };
96
-
97
- updateMessagePluginState: IMessageService['updateMessagePluginState'] = async (id, value) => {
98
- return lambdaClient.message.updatePluginState.mutate({ id, value });
99
- };
100
-
101
- updateMessagePluginError: IMessageService['updateMessagePluginError'] = async (id, error) => {
102
- return lambdaClient.message.updatePluginError.mutate({ id, value: error as any });
103
- };
104
-
105
- updateMessageRAG: IMessageService['updateMessageRAG'] = async (id, data) => {
106
- return lambdaClient.message.updateMessageRAG.mutate({ id, value: data });
107
- };
108
-
109
- removeMessage: IMessageService['removeMessage'] = async (id) => {
110
- return lambdaClient.message.removeMessage.mutate({ id });
111
- };
112
-
113
- removeMessages: IMessageService['removeMessages'] = async (ids) => {
114
- return lambdaClient.message.removeMessages.mutate({ ids });
115
- };
116
-
117
- removeMessagesByAssistant: IMessageService['removeMessagesByAssistant'] = async (
118
- sessionId,
119
- topicId,
120
- ) => {
121
- return lambdaClient.message.removeMessagesByAssistant.mutate({
122
- sessionId: this.toDbSessionId(sessionId),
123
- topicId,
124
- });
125
- };
126
-
127
- removeMessagesByGroup: IMessageService['removeMessagesByGroup'] = async (groupId, topicId) => {
128
- return lambdaClient.message.removeMessagesByGroup.mutate({
129
- groupId,
130
- topicId,
131
- });
132
- };
133
-
134
- removeAllMessages: IMessageService['removeAllMessages'] = async () => {
135
- return lambdaClient.message.removeAllMessages.mutate();
136
- };
137
-
138
- private toDbSessionId = (sessionId: string | undefined) => {
139
- return sessionId === INBOX_SESSION_ID ? null : sessionId;
140
- };
141
-
142
- hasMessages: IMessageService['hasMessages'] = async () => {
143
- const number = await this.countMessages();
144
- return number > 0;
145
- };
146
-
147
- messageCountToCheckTrace: IMessageService['messageCountToCheckTrace'] = async () => {
148
- const number = await this.countMessages();
149
- return number >= 4;
150
- };
151
- }
@@ -1,55 +0,0 @@
1
- import {
2
- ChatMessageError,
3
- ChatMessagePluginError,
4
- ChatTTS,
5
- ChatTranslate,
6
- CreateMessageParams,
7
- CreateMessageResult,
8
- ModelRankItem,
9
- UIChatMessage,
10
- UpdateMessageParams,
11
- UpdateMessageRAGParams,
12
- UpdateMessageResult,
13
- } from '@lobechat/types';
14
- import type { HeatmapsProps } from '@lobehub/charts';
15
-
16
- /* eslint-disable typescript-sort-keys/interface */
17
-
18
- export interface IMessageService {
19
- createMessage(data: CreateMessageParams): Promise<string>;
20
- createNewMessage(data: CreateMessageParams): Promise<CreateMessageResult>;
21
-
22
- getMessages(sessionId: string, topicId?: string, groupId?: string): Promise<UIChatMessage[]>;
23
- getGroupMessages(groupId: string, topicId?: string): Promise<UIChatMessage[]>;
24
- countMessages(params?: {
25
- endDate?: string;
26
- range?: [string, string];
27
- startDate?: string;
28
- }): Promise<number>;
29
- countWords(params?: {
30
- endDate?: string;
31
- range?: [string, string];
32
- startDate?: string;
33
- }): Promise<number>;
34
- rankModels(): Promise<ModelRankItem[]>;
35
- getHeatmaps(): Promise<HeatmapsProps['data']>;
36
- updateMessageError(id: string, error: ChatMessageError): Promise<any>;
37
- updateMessage(
38
- id: string,
39
- message: Partial<UpdateMessageParams>,
40
- options?: { sessionId?: string | null; topicId?: string | null },
41
- ): Promise<UpdateMessageResult>;
42
- updateMessageTTS(id: string, tts: Partial<ChatTTS> | false): Promise<any>;
43
- updateMessageTranslate(id: string, translate: Partial<ChatTranslate> | false): Promise<any>;
44
- updateMessagePluginState(id: string, value: Record<string, any>): Promise<any>;
45
- updateMessagePluginError(id: string, value: ChatMessagePluginError | null): Promise<any>;
46
- updateMessageRAG(id: string, value: UpdateMessageRAGParams): Promise<void>;
47
- updateMessagePluginArguments(id: string, value: string | Record<string, any>): Promise<any>;
48
- removeMessage(id: string): Promise<any>;
49
- removeMessages(ids: string[]): Promise<any>;
50
- removeMessagesByAssistant(assistantId: string, topicId?: string): Promise<any>;
51
- removeMessagesByGroup(groupId: string, topicId?: string): Promise<any>;
52
- removeAllMessages(): Promise<any>;
53
- messageCountToCheckTrace(): Promise<boolean>;
54
- hasMessages(): Promise<boolean>;
55
- }
@@ -1,42 +0,0 @@
1
- import { lambdaClient } from '@/libs/trpc/client';
2
-
3
- import { IPluginService } from './type';
4
-
5
- export class ServerService implements IPluginService {
6
- installPlugin: IPluginService['installPlugin'] = async (plugin) => {
7
- await lambdaClient.plugin.createOrInstallPlugin.mutate(plugin);
8
- };
9
-
10
- getInstalledPlugins: IPluginService['getInstalledPlugins'] = () => {
11
- return lambdaClient.plugin.getPlugins.query();
12
- };
13
-
14
- uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
15
- await lambdaClient.plugin.removePlugin.mutate({ id: identifier });
16
- };
17
-
18
- createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
19
- await lambdaClient.plugin.createPlugin.mutate({ ...customPlugin, type: 'customPlugin' });
20
- };
21
-
22
- updatePlugin: IPluginService['updatePlugin'] = async (id, value) => {
23
- await lambdaClient.plugin.updatePlugin.mutate({
24
- customParams: value.customParams,
25
- id,
26
- manifest: value.manifest,
27
- settings: value.settings,
28
- });
29
- };
30
-
31
- updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
32
- await lambdaClient.plugin.updatePlugin.mutate({ id, manifest });
33
- };
34
-
35
- removeAllPlugins: IPluginService['removeAllPlugins'] = async () => {
36
- await lambdaClient.plugin.removeAllPlugins.mutate();
37
- };
38
-
39
- updatePluginSettings: IPluginService['updatePluginSettings'] = async (id, settings, signal) => {
40
- await lambdaClient.plugin.updatePlugin.mutate({ id, settings }, { signal });
41
- };
42
- }
@@ -1,23 +0,0 @@
1
- import { LobeTool } from '@lobechat/types';
2
- import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
3
-
4
- import { LobeToolCustomPlugin } from '@/types/tool/plugin';
5
-
6
- export interface InstallPluginParams {
7
- customParams?: Record<string, any>;
8
- identifier: string;
9
- manifest: LobeChatPluginManifest;
10
- settings?: Record<string, any>;
11
- type: 'plugin' | 'customPlugin';
12
- }
13
-
14
- export interface IPluginService {
15
- createCustomPlugin: (customPlugin: LobeToolCustomPlugin) => Promise<void>;
16
- getInstalledPlugins: () => Promise<LobeTool[]>;
17
- installPlugin: (plugin: InstallPluginParams) => Promise<void>;
18
- removeAllPlugins: () => Promise<void>;
19
- uninstallPlugin: (identifier: string) => Promise<void>;
20
- updatePlugin: (id: string, value: Partial<LobeToolCustomPlugin>) => Promise<void>;
21
- updatePluginManifest: (id: string, manifest: LobeChatPluginManifest) => Promise<void>;
22
- updatePluginSettings: (id: string, settings: any, signal?: AbortSignal) => Promise<void>;
23
- }
@@ -1,260 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
-
3
- import { lambdaClient } from '@/libs/trpc/client';
4
- import { LobeSessionType } from '@/types/session';
5
-
6
- import { ServerService } from './server';
7
-
8
- vi.mock('@/libs/trpc/client', () => ({
9
- lambdaClient: {
10
- session: {
11
- createSession: { mutate: vi.fn() },
12
- batchCreateSessions: { mutate: vi.fn() },
13
- cloneSession: { mutate: vi.fn() },
14
- getGroupedSessions: { query: vi.fn() },
15
- countSessions: { query: vi.fn() },
16
- rankSessions: { query: vi.fn() },
17
- updateSession: { mutate: vi.fn() },
18
- updateSessionConfig: { mutate: vi.fn() },
19
- updateSessionChatConfig: { mutate: vi.fn() },
20
- getSessions: { query: vi.fn() },
21
- searchSessions: { query: vi.fn() },
22
- removeSession: { mutate: vi.fn() },
23
- removeAllSessions: { mutate: vi.fn() },
24
- },
25
- agent: {
26
- getAgentConfig: { query: vi.fn() },
27
- },
28
- sessionGroup: {
29
- createSessionGroup: { mutate: vi.fn() },
30
- getSessionGroup: { query: vi.fn() },
31
- removeSessionGroup: { mutate: vi.fn() },
32
- removeAllSessionGroups: { mutate: vi.fn() },
33
- updateSessionGroup: { mutate: vi.fn() },
34
- updateSessionGroupOrder: { mutate: vi.fn() },
35
- },
36
- },
37
- }));
38
-
39
- describe('ServerService', () => {
40
- let service: ServerService;
41
-
42
- beforeEach(() => {
43
- vi.clearAllMocks();
44
- service = new ServerService();
45
- });
46
-
47
- it('hasSessions should return true if count is 0', async () => {
48
- vi.mocked(lambdaClient.session.countSessions.query).mockResolvedValue(0);
49
- const result = await service.hasSessions();
50
- expect(result).toBe(true);
51
- });
52
-
53
- it('createSession should call lambdaClient with correct params', async () => {
54
- const mockData = {
55
- config: {
56
- model: 'gpt-3.5',
57
- params: {},
58
- systemRole: '',
59
- chatConfig: {
60
- autoCreateTopicThreshold: 2,
61
- compressThreshold: 10,
62
- enableAutoCreateTopic: true,
63
- enableCompressThreshold: true,
64
- maxTokens: 2000,
65
- model: 'gpt-3.5-turbo',
66
- params: {},
67
- temperature: 0.7,
68
- title: 'test',
69
- },
70
- tts: {
71
- showAllLocaleVoice: false,
72
- sttLocale: 'auto',
73
- ttsService: 'openai' as const,
74
- voice: {
75
- model: 'tts-1',
76
- name: 'alloy',
77
- type: 'tts',
78
- openai: 'voice-id',
79
- },
80
- },
81
- openingQuestions: ['Question 1', 'Question 2'],
82
- openingMessage: 'Hello, I am [LobeChat](https://github.com/lobehub/lobe-chat).',
83
- },
84
- group: 'testGroup',
85
- meta: { description: 'test' },
86
- title: 'Test Session',
87
- };
88
-
89
- await service.createSession(LobeSessionType.Agent, mockData);
90
-
91
- expect(lambdaClient.session.createSession.mutate).toBeCalledWith({
92
- config: { ...mockData.config, description: 'test' },
93
- session: { title: 'Test Session', groupId: 'testGroup' },
94
- type: LobeSessionType.Agent,
95
- });
96
- });
97
-
98
- it('batchCreateSessions should call lambdaClient', async () => {
99
- const mockSessions = [
100
- {
101
- id: '1',
102
- title: 'Test',
103
- config: {
104
- model: 'gpt-3.5',
105
- params: {},
106
- systemRole: '',
107
- chatConfig: {
108
- autoCreateTopicThreshold: 2,
109
- compressThreshold: 10,
110
- enableAutoCreateTopic: true,
111
- enableCompressThreshold: true,
112
- maxTokens: 2000,
113
- model: 'gpt-3.5-turbo',
114
- params: {},
115
- temperature: 0.7,
116
- title: 'test',
117
- },
118
- tts: {
119
- showAllLocaleVoice: false,
120
- sttLocale: 'auto',
121
- ttsService: 'openai' as const,
122
- voice: {
123
- model: 'tts-1',
124
- name: 'alloy',
125
- type: 'tts',
126
- openai: 'voice-id',
127
- },
128
- },
129
- },
130
- createdAt: new Date(),
131
- meta: { description: 'test' },
132
- model: 'gpt-3.5',
133
- type: LobeSessionType.Agent,
134
- updatedAt: new Date(),
135
- },
136
- ];
137
-
138
- await service.batchCreateSessions(mockSessions as any);
139
- expect(lambdaClient.session.batchCreateSessions.mutate).toBeCalledWith(mockSessions);
140
- });
141
-
142
- it('cloneSession should call lambdaClient', async () => {
143
- await service.cloneSession('123', 'New Title');
144
- expect(lambdaClient.session.cloneSession.mutate).toBeCalledWith({
145
- id: '123',
146
- newTitle: 'New Title',
147
- });
148
- });
149
-
150
- it('getGroupedSessions should call lambdaClient', async () => {
151
- await service.getGroupedSessions();
152
- expect(lambdaClient.session.getGroupedSessions.query).toBeCalled();
153
- });
154
-
155
- it('countSessions should call lambdaClient with params', async () => {
156
- const params = { startDate: '2023-01-01' };
157
- await service.countSessions(params);
158
- expect(lambdaClient.session.countSessions.query).toBeCalledWith(params);
159
- });
160
-
161
- it('rankSessions should call lambdaClient with limit', async () => {
162
- await service.rankSessions(10);
163
- expect(lambdaClient.session.rankSessions.query).toBeCalledWith(10);
164
- });
165
-
166
- it('updateSession should call lambdaClient with correct params', async () => {
167
- const mockData = {
168
- group: 'default',
169
- pinned: true,
170
- meta: { description: 'bar' },
171
- updatedAt: new Date(),
172
- };
173
-
174
- await service.updateSession('123', mockData);
175
-
176
- expect(lambdaClient.session.updateSession.mutate).toBeCalledWith({
177
- id: '123',
178
- value: {
179
- groupId: null,
180
- pinned: true,
181
- description: 'bar',
182
- updatedAt: mockData.updatedAt,
183
- },
184
- });
185
- });
186
-
187
- it('getSessionConfig should call lambdaClient', async () => {
188
- await service.getSessionConfig('123');
189
- expect(lambdaClient.agent.getAgentConfig.query).toBeCalledWith({ sessionId: '123' });
190
- });
191
-
192
- it('updateSessionConfig should call lambdaClient', async () => {
193
- const config = { model: 'gpt-4' };
194
- const signal = new AbortController().signal;
195
- await service.updateSessionConfig('123', config, signal);
196
- expect(lambdaClient.session.updateSessionConfig.mutate).toBeCalledWith(
197
- { id: '123', value: config },
198
- {
199
- signal,
200
- context: { showNotification: false },
201
- },
202
- );
203
- });
204
-
205
- it('getSessionsByType should call lambdaClient', async () => {
206
- await service.getSessionsByType('all');
207
- expect(lambdaClient.session.getSessions.query).toBeCalledWith({});
208
- });
209
-
210
- it('searchSessions should call lambdaClient with keywords', async () => {
211
- await service.searchSessions('test');
212
- expect(lambdaClient.session.searchSessions.query).toBeCalledWith({ keywords: 'test' });
213
- });
214
-
215
- it('removeSession should call lambdaClient', async () => {
216
- await service.removeSession('123');
217
- expect(lambdaClient.session.removeSession.mutate).toBeCalledWith({ id: '123' });
218
- });
219
-
220
- it('removeAllSessions should call lambdaClient', async () => {
221
- await service.removeAllSessions();
222
- expect(lambdaClient.session.removeAllSessions.mutate).toBeCalled();
223
- });
224
-
225
- it('createSessionGroup should call lambdaClient', async () => {
226
- await service.createSessionGroup('Test Group', 1);
227
- expect(lambdaClient.sessionGroup.createSessionGroup.mutate).toBeCalledWith({
228
- name: 'Test Group',
229
- sort: 1,
230
- });
231
- });
232
-
233
- it('getSessionGroups should call lambdaClient', async () => {
234
- await service.getSessionGroups();
235
- expect(lambdaClient.sessionGroup.getSessionGroup.query).toBeCalled();
236
- });
237
-
238
- it('removeSessionGroup should call lambdaClient', async () => {
239
- await service.removeSessionGroup('123', true);
240
- expect(lambdaClient.sessionGroup.removeSessionGroup.mutate).toBeCalledWith({
241
- id: '123',
242
- removeChildren: true,
243
- });
244
- });
245
-
246
- it('updateSessionGroup should call lambdaClient', async () => {
247
- const value = { name: 'Updated Group' };
248
- await service.updateSessionGroup('123', value);
249
- expect(lambdaClient.sessionGroup.updateSessionGroup.mutate).toBeCalledWith({
250
- id: '123',
251
- value,
252
- });
253
- });
254
-
255
- it('updateSessionGroupOrder should call lambdaClient', async () => {
256
- const sortMap = [{ id: '123', sort: 1 }];
257
- await service.updateSessionGroupOrder(sortMap);
258
- expect(lambdaClient.sessionGroup.updateSessionGroupOrder.mutate).toBeCalledWith({ sortMap });
259
- });
260
- });
@@ -1,125 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { lambdaClient } from '@/libs/trpc/client';
3
-
4
- import { ISessionService } from './type';
5
-
6
- export class ServerService implements ISessionService {
7
- hasSessions: ISessionService['hasSessions'] = async () => {
8
- const result = await this.countSessions();
9
- return result === 0;
10
- };
11
-
12
- createSession: ISessionService['createSession'] = async (type, data) => {
13
- const { config, group, meta, ...session } = data;
14
- return lambdaClient.session.createSession.mutate({
15
- config: { ...config, ...meta } as any,
16
- session: { ...session, groupId: group },
17
- type,
18
- });
19
- };
20
-
21
- batchCreateSessions: ISessionService['batchCreateSessions'] = async (importSessions) => {
22
- // TODO: remove any
23
- const data = await lambdaClient.session.batchCreateSessions.mutate(importSessions as any);
24
- console.log(data);
25
- return data;
26
- };
27
-
28
- cloneSession: ISessionService['cloneSession'] = (id, newTitle) => {
29
- return lambdaClient.session.cloneSession.mutate({ id, newTitle });
30
- };
31
-
32
- getGroupedSessions: ISessionService['getGroupedSessions'] = () => {
33
- return lambdaClient.session.getGroupedSessions.query();
34
- };
35
-
36
- countSessions: ISessionService['countSessions'] = async (params) => {
37
- return lambdaClient.session.countSessions.query(params);
38
- };
39
-
40
- rankSessions: ISessionService['rankSessions'] = async (limit) => {
41
- return lambdaClient.session.rankSessions.query(limit);
42
- };
43
-
44
- updateSession: ISessionService['updateSession'] = (id, data) => {
45
- const { group, pinned, meta, updatedAt } = data;
46
- return lambdaClient.session.updateSession.mutate({
47
- id,
48
- value: { groupId: group === 'default' ? null : group, pinned, ...meta, updatedAt },
49
- });
50
- };
51
-
52
- // TODO: Need to be fixed
53
- // @ts-ignore
54
- getSessionConfig: ISessionService['getSessionConfig'] = async (id) => {
55
- return lambdaClient.agent.getAgentConfig.query({ sessionId: id });
56
- };
57
-
58
- updateSessionConfig: ISessionService['updateSessionConfig'] = (id, config, signal) => {
59
- return lambdaClient.session.updateSessionConfig.mutate(
60
- { id, value: config },
61
- {
62
- context: { showNotification: false },
63
- signal,
64
- },
65
- );
66
- };
67
-
68
- updateSessionMeta: ISessionService['updateSessionMeta'] = (id, meta, signal) => {
69
- return lambdaClient.session.updateSessionConfig.mutate({ id, value: meta }, { signal });
70
- };
71
-
72
- updateSessionChatConfig: ISessionService['updateSessionChatConfig'] = (id, value, signal) => {
73
- return lambdaClient.session.updateSessionChatConfig.mutate({ id, value }, { signal });
74
- };
75
-
76
- // TODO: need be fixed
77
- // @ts-ignore
78
- getSessionsByType: ISessionService['getSessionsByType'] = (_type = 'all') => {
79
- return lambdaClient.session.getSessions.query({});
80
- };
81
-
82
- searchSessions: ISessionService['searchSessions'] = (keywords) => {
83
- return lambdaClient.session.searchSessions.query({ keywords });
84
- };
85
-
86
- removeSession: ISessionService['removeSession'] = (id) => {
87
- return lambdaClient.session.removeSession.mutate({ id });
88
- };
89
-
90
- removeAllSessions: ISessionService['removeAllSessions'] = () => {
91
- return lambdaClient.session.removeAllSessions.mutate();
92
- };
93
-
94
- // ************************************** //
95
- // *********** SessionGroup *********** //
96
- // ************************************** //
97
-
98
- createSessionGroup: ISessionService['createSessionGroup'] = (name, sort) => {
99
- return lambdaClient.sessionGroup.createSessionGroup.mutate({ name, sort });
100
- };
101
-
102
- getSessionGroups: ISessionService['getSessionGroups'] = () => {
103
- return lambdaClient.sessionGroup.getSessionGroup.query();
104
- };
105
-
106
- batchCreateSessionGroups: ISessionService['batchCreateSessionGroups'] = (_groups) => {
107
- return Promise.resolve({ added: 0, ids: [], skips: [], success: true });
108
- };
109
-
110
- removeSessionGroup: ISessionService['removeSessionGroup'] = (id, removeChildren) => {
111
- return lambdaClient.sessionGroup.removeSessionGroup.mutate({ id, removeChildren });
112
- };
113
-
114
- removeSessionGroups: ISessionService['removeSessionGroups'] = () => {
115
- return lambdaClient.sessionGroup.removeAllSessionGroups.mutate();
116
- };
117
-
118
- updateSessionGroup: ISessionService['updateSessionGroup'] = (id, value) => {
119
- return lambdaClient.sessionGroup.updateSessionGroup.mutate({ id, value });
120
- };
121
-
122
- updateSessionGroupOrder: ISessionService['updateSessionGroupOrder'] = (sortMap) => {
123
- return lambdaClient.sessionGroup.updateSessionGroupOrder.mutate({ sortMap });
124
- };
125
- }