@lobehub/chat 1.39.2 → 1.40.0
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/.env.example +19 -8
- package/.eslintignore +1 -1
- package/CHANGELOG.md +58 -0
- package/changelog/v1.json +21 -0
- package/docs/.cdn.cache.json +25 -0
- package/docs/changelog/2023-09-09-plugin-system.mdx +1 -1
- package/docs/changelog/2023-09-09-plugin-system.zh-CN.mdx +1 -1
- package/docs/changelog/2024-09-20-artifacts.mdx +1 -1
- package/docs/changelog/2024-09-20-artifacts.zh-CN.mdx +1 -1
- package/docs/changelog/2024-10-27-pin-assistant.mdx +2 -2
- package/docs/changelog/2024-10-27-pin-assistant.zh-CN.mdx +2 -2
- package/docs/changelog/2024-11-06-share-text-json.mdx +2 -2
- package/docs/changelog/2024-11-06-share-text-json.zh-CN.mdx +2 -2
- package/docs/changelog/index.json +16 -16
- package/locales/ar/changelog.json +18 -0
- package/locales/ar/common.json +1 -0
- package/locales/ar/metadata.json +4 -0
- package/locales/bg-BG/changelog.json +18 -0
- package/locales/bg-BG/common.json +1 -0
- package/locales/bg-BG/metadata.json +4 -0
- package/locales/de-DE/changelog.json +18 -0
- package/locales/de-DE/common.json +1 -0
- package/locales/de-DE/metadata.json +4 -0
- package/locales/en-US/changelog.json +18 -0
- package/locales/en-US/common.json +1 -0
- package/locales/en-US/metadata.json +4 -0
- package/locales/es-ES/changelog.json +18 -0
- package/locales/es-ES/common.json +1 -0
- package/locales/es-ES/metadata.json +4 -0
- package/locales/fa-IR/changelog.json +18 -0
- package/locales/fa-IR/common.json +1 -0
- package/locales/fa-IR/metadata.json +4 -0
- package/locales/fr-FR/changelog.json +18 -0
- package/locales/fr-FR/common.json +1 -0
- package/locales/fr-FR/metadata.json +4 -0
- package/locales/it-IT/changelog.json +18 -0
- package/locales/it-IT/common.json +1 -0
- package/locales/it-IT/metadata.json +4 -0
- package/locales/ja-JP/changelog.json +18 -0
- package/locales/ja-JP/common.json +1 -0
- package/locales/ja-JP/metadata.json +4 -0
- package/locales/ko-KR/changelog.json +18 -0
- package/locales/ko-KR/common.json +1 -0
- package/locales/ko-KR/metadata.json +4 -0
- package/locales/nl-NL/changelog.json +18 -0
- package/locales/nl-NL/common.json +1 -0
- package/locales/nl-NL/metadata.json +4 -0
- package/locales/pl-PL/changelog.json +18 -0
- package/locales/pl-PL/common.json +1 -0
- package/locales/pl-PL/metadata.json +4 -0
- package/locales/pt-BR/changelog.json +18 -0
- package/locales/pt-BR/common.json +1 -0
- package/locales/pt-BR/metadata.json +4 -0
- package/locales/ru-RU/changelog.json +18 -0
- package/locales/ru-RU/common.json +1 -0
- package/locales/ru-RU/metadata.json +4 -0
- package/locales/tr-TR/changelog.json +18 -0
- package/locales/tr-TR/common.json +1 -0
- package/locales/tr-TR/metadata.json +4 -0
- package/locales/vi-VN/changelog.json +18 -0
- package/locales/vi-VN/common.json +1 -0
- package/locales/vi-VN/metadata.json +4 -0
- package/locales/zh-CN/changelog.json +18 -0
- package/locales/zh-CN/common.json +1 -0
- package/locales/zh-CN/metadata.json +4 -0
- package/locales/zh-TW/changelog.json +18 -0
- package/locales/zh-TW/common.json +1 -0
- package/locales/zh-TW/metadata.json +4 -0
- package/package.json +6 -1
- package/scripts/cdnWorkflow/index.ts +217 -0
- package/scripts/cdnWorkflow/optimized.ts +21 -0
- package/scripts/cdnWorkflow/s3/index.ts +120 -0
- package/scripts/cdnWorkflow/s3/types.ts +25 -0
- package/scripts/cdnWorkflow/s3/utils.ts +106 -0
- package/scripts/cdnWorkflow/uploader.ts +73 -0
- package/scripts/cdnWorkflow/utils.ts +93 -0
- package/src/app/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +25 -12
- package/src/app/(main)/(mobile)/me/(home)/features/useCategory.tsx +19 -9
- package/src/app/(main)/(mobile)/me/(home)/loading.tsx +1 -1
- package/src/app/(main)/(mobile)/me/data/loading.tsx +1 -1
- package/src/app/(main)/(mobile)/me/profile/loading.tsx +1 -1
- package/src/app/(main)/(mobile)/me/settings/loading.tsx +1 -1
- package/src/app/(main)/_layout/Desktop.tsx +4 -1
- package/src/app/(main)/_layout/Mobile.tsx +2 -1
- package/src/app/(main)/changelog/_layout/Desktop.tsx +25 -0
- package/src/app/(main)/changelog/_layout/Mobile/Header.tsx +33 -0
- package/src/app/(main)/changelog/_layout/Mobile/index.tsx +21 -0
- package/src/app/(main)/changelog/error.tsx +5 -0
- package/src/app/(main)/changelog/features/GridLayout.tsx +22 -0
- package/src/app/(main)/changelog/features/Hero.tsx +40 -0
- package/src/app/(main)/changelog/features/Post.tsx +56 -0
- package/src/app/(main)/changelog/features/PublishedTime.tsx +50 -0
- package/src/app/(main)/changelog/features/VersionTag.tsx +27 -0
- package/src/app/(main)/changelog/layout.tsx +10 -0
- package/src/app/(main)/changelog/loading.tsx +3 -0
- package/src/app/(main)/changelog/modal/page.tsx +23 -0
- package/src/app/(main)/changelog/not-found.tsx +3 -0
- package/src/app/(main)/changelog/page.tsx +73 -0
- package/src/app/(main)/chat/(workspace)/@portal/default.tsx +1 -1
- package/src/app/(main)/chat/(workspace)/@portal/loading.tsx +1 -1
- package/src/app/(main)/chat/(workspace)/page.tsx +9 -2
- package/src/app/(main)/chat/@session/default.tsx +3 -2
- package/src/app/(main)/chat/loading.tsx +1 -1
- package/src/app/(main)/chat/settings/loading.tsx +1 -1
- package/src/app/(main)/discover/loading.tsx +1 -1
- package/src/app/(main)/files/loading.tsx +2 -22
- package/src/app/(main)/profile/loading.tsx +1 -1
- package/src/app/(main)/repos/[id]/evals/dataset/page.tsx +1 -1
- package/src/app/(main)/repos/[id]/evals/evaluation/page.tsx +1 -1
- package/src/app/(main)/settings/@category/default.tsx +6 -2
- package/src/app/(main)/settings/_layout/Desktop/SideBar.tsx +1 -1
- package/src/app/(main)/settings/about/features/Version.tsx +2 -2
- package/src/app/(main)/settings/loading.tsx +2 -8
- package/src/app/@modal/(.)changelog/modal/features/Cover.tsx +48 -0
- package/src/app/@modal/(.)changelog/modal/features/Hero.tsx +29 -0
- package/src/app/@modal/(.)changelog/modal/features/Pagination.tsx +54 -0
- package/src/app/@modal/(.)changelog/modal/features/Post.tsx +57 -0
- package/src/app/@modal/(.)changelog/modal/features/PublishedTime.tsx +50 -0
- package/src/app/@modal/(.)changelog/modal/features/ReadDetail.tsx +94 -0
- package/src/app/@modal/(.)changelog/modal/features/UpdateChangelogStatus.tsx +21 -0
- package/src/app/@modal/(.)changelog/modal/features/VersionTag.tsx +27 -0
- package/src/app/@modal/(.)changelog/modal/layout.tsx +39 -0
- package/src/app/@modal/(.)changelog/modal/loading.tsx +10 -0
- package/src/app/@modal/(.)changelog/modal/page.tsx +37 -0
- package/src/app/@modal/(.)settings/modal/layout.tsx +19 -16
- package/src/app/@modal/_layout/ModalLayout.tsx +63 -0
- package/src/app/@modal/chat/(.)settings/modal/layout.tsx +20 -17
- package/src/app/@modal/layout.tsx +5 -69
- package/src/app/loading/Client/Content.tsx +1 -1
- package/src/app/loading/Server/Content.tsx +1 -1
- package/src/components/Loading/BrandTextLoading/LobeChatText/SVG.tsx +44 -0
- package/src/components/Loading/BrandTextLoading/LobeChatText/index.tsx +6 -0
- package/src/components/Loading/BrandTextLoading/LobeChatText/style.css +32 -0
- package/src/components/Loading/BrandTextLoading/index.tsx +11 -0
- package/src/components/{SkeletonLoading → Loading/SkeletonLoading}/index.tsx +1 -1
- package/src/components/mdx/Image.tsx +50 -0
- package/src/components/mdx/index.tsx +2 -0
- package/src/const/url.ts +1 -0
- package/src/features/ChangelogModal/index.tsx +22 -0
- package/src/features/FileViewer/Renderer/TXT/index.tsx +1 -1
- package/src/features/Portal/FilePreview/Body/index.tsx +1 -1
- package/src/features/Portal/Home/Body/Files/FileList/index.tsx +1 -1
- package/src/features/Setting/Footer.tsx +3 -1
- package/src/features/Setting/SettingContainer.tsx +1 -0
- package/src/features/User/UserPanel/useMenu.tsx +50 -46
- package/src/features/User/__tests__/useMenu.test.tsx +7 -6
- package/src/hooks/useInterceptingRoutes.ts +1 -6
- package/src/hooks/useShare.tsx +1 -0
- package/src/locales/default/changelog.ts +18 -0
- package/src/locales/default/common.ts +1 -0
- package/src/locales/default/index.ts +2 -0
- package/src/locales/default/metadata.ts +4 -0
- package/src/server/metadata.ts +5 -3
- package/src/server/routers/edge/appStatus.ts +3 -0
- package/src/server/routers/edge/index.ts +2 -0
- package/src/server/routers/lambda/agent.ts +1 -1
- package/src/server/services/changelog/index.test.ts +310 -0
- package/src/server/services/changelog/index.ts +196 -0
- package/src/server/services/discover/index.test.ts +0 -1
- package/src/server/sitemap.ts +4 -1
- package/src/services/__tests__/chat.test.ts +1 -1
- package/src/services/__tests__/global.test.ts +5 -2
- package/src/services/_auth.ts +1 -1
- package/src/services/agent.ts +25 -21
- package/src/services/chat.ts +2 -2
- package/src/services/file/ClientS3/index.ts +6 -6
- package/src/services/file/client.ts +14 -15
- package/src/services/file/server.ts +20 -25
- package/src/services/global.ts +2 -2
- package/src/services/import/client.ts +6 -5
- package/src/services/import/server.ts +6 -5
- package/src/services/import/type.ts +7 -0
- package/src/services/knowledgeBase.ts +19 -19
- package/src/services/message/_deprecated.ts +5 -0
- package/src/services/message/client.ts +52 -48
- package/src/services/message/server.ts +50 -53
- package/src/services/message/type.ts +2 -2
- package/src/services/plugin/client.ts +16 -22
- package/src/services/plugin/server.ts +15 -19
- package/src/services/rag.ts +18 -18
- package/src/services/ragEval.ts +29 -26
- package/src/services/session/_deprecated.ts +2 -2
- package/src/services/session/client.ts +55 -81
- package/src/services/session/server.ts +50 -74
- package/src/services/session/type.ts +4 -6
- package/src/services/share.ts +4 -4
- package/src/services/textToImage.ts +5 -2
- package/src/services/thread/client.ts +9 -15
- package/src/services/thread/server.ts +10 -15
- package/src/services/topic/client.ts +25 -25
- package/src/services/topic/server.ts +25 -42
- package/src/services/trace.ts +4 -4
- package/src/services/user/client.ts +13 -17
- package/src/services/user/server.ts +9 -13
- package/src/services/user/type.ts +1 -1
- package/src/store/chat/slices/message/reducer.ts +3 -2
- package/src/store/global/action.ts +27 -22
- package/src/store/global/initialState.ts +1 -0
- package/src/types/changelog.ts +6 -0
- package/src/types/message/index.ts +10 -8
- package/src/app/@modal/features/InterceptingContext.tsx +0 -9
- /package/src/components/{CircleLoading → Loading/CircleLoading}/index.tsx +0 -0
- /package/src/components/{FullscreenLoading → Loading/FullscreenLoading}/index.tsx +0 -0
|
@@ -2,33 +2,33 @@ import { lambdaClient } from '@/libs/trpc/client';
|
|
|
2
2
|
import { CreateKnowledgeBaseParams } from '@/types/knowledgeBase';
|
|
3
3
|
|
|
4
4
|
class KnowledgeBaseService {
|
|
5
|
-
async
|
|
6
|
-
return
|
|
7
|
-
}
|
|
5
|
+
createKnowledgeBase = async (params: CreateKnowledgeBaseParams) => {
|
|
6
|
+
return lambdaClient.knowledgeBase.createKnowledgeBase.mutate(params);
|
|
7
|
+
};
|
|
8
8
|
|
|
9
|
-
async
|
|
10
|
-
return
|
|
11
|
-
}
|
|
9
|
+
getKnowledgeBaseList = async () => {
|
|
10
|
+
return lambdaClient.knowledgeBase.getKnowledgeBases.query();
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
async
|
|
14
|
-
return
|
|
15
|
-
}
|
|
13
|
+
getKnowledgeBaseById = async (id: string) => {
|
|
14
|
+
return lambdaClient.knowledgeBase.getKnowledgeBaseById.query({ id });
|
|
15
|
+
};
|
|
16
16
|
|
|
17
|
-
async
|
|
18
|
-
return
|
|
19
|
-
}
|
|
17
|
+
updateKnowledgeBaseList = async (id: string, value: any) => {
|
|
18
|
+
return lambdaClient.knowledgeBase.updateKnowledgeBase.mutate({ id, value });
|
|
19
|
+
};
|
|
20
20
|
|
|
21
|
-
async
|
|
22
|
-
return
|
|
23
|
-
}
|
|
21
|
+
deleteKnowledgeBase = async (id: string) => {
|
|
22
|
+
return lambdaClient.knowledgeBase.removeKnowledgeBase.mutate({ id });
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
async
|
|
25
|
+
addFilesToKnowledgeBase = async (knowledgeBaseId: string, ids: string[]) => {
|
|
26
26
|
return lambdaClient.knowledgeBase.addFilesToKnowledgeBase.mutate({ ids, knowledgeBaseId });
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
|
|
29
|
-
async
|
|
29
|
+
removeFilesFromKnowledgeBase = async (knowledgeBaseId: string, ids: string[]) => {
|
|
30
30
|
return lambdaClient.knowledgeBase.removeFilesFromKnowledgeBase.mutate({ ids, knowledgeBaseId });
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export const knowledgeBaseService = new KnowledgeBaseService();
|
|
@@ -118,4 +118,9 @@ export class ClientService implements IMessageService {
|
|
|
118
118
|
const number = await this.countMessages();
|
|
119
119
|
return number > 0;
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
async messageCountToCheckTrace() {
|
|
123
|
+
const number = await this.countMessages();
|
|
124
|
+
return number >= 4;
|
|
125
|
+
}
|
|
121
126
|
}
|
|
@@ -2,17 +2,10 @@ import dayjs from 'dayjs';
|
|
|
2
2
|
|
|
3
3
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
4
4
|
import { clientDB } from '@/database/client/db';
|
|
5
|
-
import { MessageItem } from '@/database/schemas';
|
|
6
5
|
import { MessageModel } from '@/database/server/models/message';
|
|
7
6
|
import { BaseClientService } from '@/services/baseClientService';
|
|
8
7
|
import { clientS3Storage } from '@/services/file/ClientS3';
|
|
9
|
-
import {
|
|
10
|
-
ChatMessage,
|
|
11
|
-
ChatMessageError,
|
|
12
|
-
ChatTTS,
|
|
13
|
-
ChatTranslate,
|
|
14
|
-
CreateMessageParams,
|
|
15
|
-
} from '@/types/message';
|
|
8
|
+
import { ChatMessage } from '@/types/message';
|
|
16
9
|
|
|
17
10
|
import { IMessageService } from './type';
|
|
18
11
|
|
|
@@ -21,20 +14,20 @@ export class ClientService extends BaseClientService implements IMessageService
|
|
|
21
14
|
return new MessageModel(clientDB as any, this.userId);
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
async
|
|
17
|
+
createMessage: IMessageService['createMessage'] = async ({ sessionId, ...params }) => {
|
|
25
18
|
const { id } = await this.messageModel.create({
|
|
26
19
|
...params,
|
|
27
20
|
sessionId: this.toDbSessionId(sessionId) as string,
|
|
28
21
|
});
|
|
29
22
|
|
|
30
23
|
return id;
|
|
31
|
-
}
|
|
24
|
+
};
|
|
32
25
|
|
|
33
|
-
|
|
26
|
+
batchCreateMessages: IMessageService['batchCreateMessages'] = async (messages) => {
|
|
34
27
|
return this.messageModel.batchCreate(messages);
|
|
35
|
-
}
|
|
28
|
+
};
|
|
36
29
|
|
|
37
|
-
async
|
|
30
|
+
getMessages: IMessageService['getMessages'] = async (sessionId, topicId) => {
|
|
38
31
|
const data = await this.messageModel.query(
|
|
39
32
|
{
|
|
40
33
|
sessionId: this.toDbSessionId(sessionId),
|
|
@@ -51,86 +44,97 @@ export class ClientService extends BaseClientService implements IMessageService
|
|
|
51
44
|
);
|
|
52
45
|
|
|
53
46
|
return data as unknown as ChatMessage[];
|
|
54
|
-
}
|
|
47
|
+
};
|
|
55
48
|
|
|
56
|
-
async
|
|
49
|
+
getAllMessages: IMessageService['getAllMessages'] = async () => {
|
|
57
50
|
const data = await this.messageModel.queryAll();
|
|
58
51
|
|
|
59
52
|
return data as unknown as ChatMessage[];
|
|
60
|
-
}
|
|
53
|
+
};
|
|
61
54
|
|
|
62
|
-
async
|
|
55
|
+
countMessages: IMessageService['countMessages'] = async () => {
|
|
63
56
|
return this.messageModel.count();
|
|
64
|
-
}
|
|
57
|
+
};
|
|
65
58
|
|
|
66
|
-
async
|
|
59
|
+
countTodayMessages: IMessageService['countTodayMessages'] = async () => {
|
|
67
60
|
const topics = await this.messageModel.queryAll();
|
|
68
61
|
return topics.filter(
|
|
69
62
|
(item) => dayjs(item.createdAt).format('YYYY-MM-DD') === dayjs().format('YYYY-MM-DD'),
|
|
70
63
|
).length;
|
|
71
|
-
}
|
|
64
|
+
};
|
|
72
65
|
|
|
73
|
-
async
|
|
66
|
+
getAllMessagesInSession: IMessageService['getAllMessagesInSession'] = async (sessionId) => {
|
|
74
67
|
const data = this.messageModel.queryBySessionId(this.toDbSessionId(sessionId));
|
|
75
68
|
|
|
76
69
|
return data as unknown as ChatMessage[];
|
|
77
|
-
}
|
|
70
|
+
};
|
|
78
71
|
|
|
79
|
-
async
|
|
72
|
+
updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
|
|
80
73
|
return this.messageModel.update(id, { error });
|
|
81
|
-
}
|
|
74
|
+
};
|
|
82
75
|
|
|
83
|
-
async
|
|
76
|
+
updateMessage: IMessageService['updateMessage'] = async (id, message) => {
|
|
84
77
|
return this.messageModel.update(id, message);
|
|
85
|
-
}
|
|
78
|
+
};
|
|
86
79
|
|
|
87
|
-
async
|
|
80
|
+
updateMessageTTS: IMessageService['updateMessageTTS'] = async (id, tts) => {
|
|
88
81
|
return this.messageModel.updateTTS(id, tts as any);
|
|
89
|
-
}
|
|
82
|
+
};
|
|
90
83
|
|
|
91
|
-
async
|
|
84
|
+
updateMessageTranslate: IMessageService['updateMessageTranslate'] = async (id, translate) => {
|
|
92
85
|
return this.messageModel.updateTranslate(id, translate as any);
|
|
93
|
-
}
|
|
86
|
+
};
|
|
94
87
|
|
|
95
|
-
async
|
|
88
|
+
updateMessagePluginState: IMessageService['updateMessagePluginState'] = async (id, value) => {
|
|
96
89
|
return this.messageModel.updatePluginState(id, value);
|
|
97
|
-
}
|
|
90
|
+
};
|
|
98
91
|
|
|
99
|
-
|
|
92
|
+
updateMessagePluginArguments: IMessageService['updateMessagePluginArguments'] = async (
|
|
93
|
+
id,
|
|
94
|
+
value,
|
|
95
|
+
) => {
|
|
100
96
|
const args = typeof value === 'string' ? value : JSON.stringify(value);
|
|
101
97
|
|
|
102
98
|
return this.messageModel.updateMessagePlugin(id, { arguments: args });
|
|
103
|
-
}
|
|
99
|
+
};
|
|
104
100
|
|
|
105
|
-
async
|
|
101
|
+
removeMessage: IMessageService['removeMessage'] = async (id) => {
|
|
106
102
|
return this.messageModel.deleteMessage(id);
|
|
107
|
-
}
|
|
103
|
+
};
|
|
108
104
|
|
|
109
|
-
|
|
105
|
+
removeMessages: IMessageService['removeMessages'] = async (ids) => {
|
|
110
106
|
return this.messageModel.deleteMessages(ids);
|
|
111
|
-
}
|
|
107
|
+
};
|
|
112
108
|
|
|
113
|
-
|
|
109
|
+
removeMessagesByAssistant: IMessageService['removeMessagesByAssistant'] = async (
|
|
110
|
+
sessionId,
|
|
111
|
+
topicId,
|
|
112
|
+
) => {
|
|
114
113
|
return this.messageModel.deleteMessagesBySession(this.toDbSessionId(sessionId), topicId);
|
|
115
|
-
}
|
|
114
|
+
};
|
|
116
115
|
|
|
117
|
-
async
|
|
116
|
+
removeAllMessages: IMessageService['removeAllMessages'] = async () => {
|
|
118
117
|
return this.messageModel.deleteAllMessages();
|
|
119
|
-
}
|
|
118
|
+
};
|
|
120
119
|
|
|
121
|
-
async
|
|
120
|
+
hasMessages: IMessageService['hasMessages'] = async () => {
|
|
122
121
|
const number = await this.countMessages();
|
|
123
122
|
return number > 0;
|
|
124
|
-
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
messageCountToCheckTrace: IMessageService['messageCountToCheckTrace'] = async () => {
|
|
126
|
+
const number = await this.countMessages();
|
|
127
|
+
return number >= 4;
|
|
128
|
+
};
|
|
125
129
|
|
|
126
|
-
private toDbSessionId(sessionId: string | undefined) {
|
|
130
|
+
private toDbSessionId = (sessionId: string | undefined) => {
|
|
127
131
|
return sessionId === INBOX_SESSION_ID ? undefined : sessionId;
|
|
128
|
-
}
|
|
132
|
+
};
|
|
129
133
|
|
|
130
|
-
private async
|
|
134
|
+
private getBase64ByFileHash = async (hash: string) => {
|
|
131
135
|
const fileItem = await clientS3Storage.getObject(hash);
|
|
132
136
|
if (!fileItem) throw new Error('file not found');
|
|
133
137
|
|
|
134
138
|
return Buffer.from(await fileItem.arrayBuffer()).toString('base64');
|
|
135
|
-
}
|
|
139
|
+
};
|
|
136
140
|
}
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
3
|
-
import { MessageItem } from '@/database/schemas';
|
|
4
3
|
import { lambdaClient } from '@/libs/trpc/client';
|
|
5
|
-
import {
|
|
6
|
-
ChatMessage,
|
|
7
|
-
ChatMessageError,
|
|
8
|
-
ChatTTS,
|
|
9
|
-
ChatTranslate,
|
|
10
|
-
CreateMessageParams,
|
|
11
|
-
} from '@/types/message';
|
|
4
|
+
import { ChatMessage, ChatMessageError, ChatTranslate } from '@/types/message';
|
|
12
5
|
|
|
13
6
|
import { IMessageService } from './type';
|
|
14
7
|
|
|
15
8
|
export class ServerService implements IMessageService {
|
|
16
|
-
createMessage({ sessionId, ...params }
|
|
9
|
+
createMessage: IMessageService['createMessage'] = async ({ sessionId, ...params }) => {
|
|
17
10
|
return lambdaClient.message.createMessage.mutate({
|
|
18
11
|
...params,
|
|
19
12
|
sessionId: this.toDbSessionId(sessionId),
|
|
20
13
|
});
|
|
21
|
-
}
|
|
14
|
+
};
|
|
22
15
|
|
|
23
|
-
batchCreateMessages
|
|
16
|
+
batchCreateMessages: IMessageService['batchCreateMessages'] = async (messages) => {
|
|
24
17
|
return lambdaClient.message.batchCreateMessages.mutate(messages);
|
|
25
|
-
}
|
|
18
|
+
};
|
|
26
19
|
|
|
27
|
-
getMessages = async (sessionId
|
|
20
|
+
getMessages: IMessageService['getMessages'] = async (sessionId, topicId) => {
|
|
28
21
|
const data = await lambdaClient.message.getMessages.query({
|
|
29
22
|
sessionId: this.toDbSessionId(sessionId),
|
|
30
23
|
topicId,
|
|
@@ -33,85 +26,89 @@ export class ServerService implements IMessageService {
|
|
|
33
26
|
return data as unknown as ChatMessage[];
|
|
34
27
|
};
|
|
35
28
|
|
|
36
|
-
getAllMessages
|
|
29
|
+
getAllMessages: IMessageService['getAllMessages'] = async () => {
|
|
37
30
|
return lambdaClient.message.getAllMessages.query();
|
|
38
|
-
}
|
|
31
|
+
};
|
|
39
32
|
|
|
40
|
-
getAllMessagesInSession
|
|
33
|
+
getAllMessagesInSession: IMessageService['getAllMessagesInSession'] = async (sessionId) => {
|
|
41
34
|
return lambdaClient.message.getAllMessagesInSession.query({
|
|
42
35
|
sessionId: this.toDbSessionId(sessionId),
|
|
43
36
|
});
|
|
44
|
-
}
|
|
37
|
+
};
|
|
45
38
|
|
|
46
|
-
countMessages()
|
|
39
|
+
countMessages: IMessageService['countMessages'] = async () => {
|
|
47
40
|
return lambdaClient.message.count.query();
|
|
48
|
-
}
|
|
49
|
-
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
countTodayMessages: IMessageService['countTodayMessages'] = async () => {
|
|
50
44
|
return lambdaClient.message.countToday.query();
|
|
51
|
-
}
|
|
45
|
+
};
|
|
52
46
|
|
|
53
|
-
updateMessageError(id
|
|
47
|
+
updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
|
|
54
48
|
return lambdaClient.message.update.mutate({ id, value: { error } });
|
|
55
|
-
}
|
|
49
|
+
};
|
|
56
50
|
|
|
57
|
-
async
|
|
51
|
+
updateMessagePluginError = async (id: string, error: ChatMessageError): Promise<any> => {
|
|
58
52
|
return lambdaClient.message.update.mutate({ id, value: { pluginError: error } });
|
|
59
|
-
}
|
|
53
|
+
};
|
|
60
54
|
|
|
61
|
-
async
|
|
62
|
-
id
|
|
63
|
-
value
|
|
64
|
-
)
|
|
55
|
+
updateMessagePluginArguments: IMessageService['updateMessagePluginArguments'] = async (
|
|
56
|
+
id,
|
|
57
|
+
value,
|
|
58
|
+
) => {
|
|
65
59
|
const args = typeof value === 'string' ? value : JSON.stringify(value);
|
|
66
|
-
|
|
67
60
|
return lambdaClient.message.updateMessagePlugin.mutate({ id, value: { arguments: args } });
|
|
68
|
-
}
|
|
61
|
+
};
|
|
69
62
|
|
|
70
|
-
updateMessage(id
|
|
63
|
+
updateMessage: IMessageService['updateMessage'] = async (id, message) => {
|
|
71
64
|
return lambdaClient.message.update.mutate({ id, value: message });
|
|
72
|
-
}
|
|
65
|
+
};
|
|
73
66
|
|
|
74
|
-
updateMessageTranslate
|
|
67
|
+
updateMessageTranslate: IMessageService['updateMessageTranslate'] = async (id, translate) => {
|
|
75
68
|
return lambdaClient.message.updateTranslate.mutate({ id, value: translate as ChatTranslate });
|
|
76
|
-
}
|
|
69
|
+
};
|
|
77
70
|
|
|
78
|
-
updateMessageTTS
|
|
71
|
+
updateMessageTTS: IMessageService['updateMessageTTS'] = async (id, tts) => {
|
|
79
72
|
return lambdaClient.message.updateTTS.mutate({ id, value: tts });
|
|
80
|
-
}
|
|
73
|
+
};
|
|
81
74
|
|
|
82
|
-
updateMessagePluginState(id
|
|
75
|
+
updateMessagePluginState: IMessageService['updateMessagePluginState'] = async (id, value) => {
|
|
83
76
|
return lambdaClient.message.updatePluginState.mutate({ id, value });
|
|
84
|
-
}
|
|
77
|
+
};
|
|
85
78
|
|
|
86
|
-
removeMessage(id
|
|
79
|
+
removeMessage: IMessageService['removeMessage'] = async (id) => {
|
|
87
80
|
return lambdaClient.message.removeMessage.mutate({ id });
|
|
88
|
-
}
|
|
81
|
+
};
|
|
89
82
|
|
|
90
|
-
removeMessages
|
|
83
|
+
removeMessages: IMessageService['removeMessages'] = async (ids) => {
|
|
91
84
|
return lambdaClient.message.removeMessages.mutate({ ids });
|
|
92
|
-
}
|
|
85
|
+
};
|
|
93
86
|
|
|
94
|
-
removeMessagesByAssistant
|
|
87
|
+
removeMessagesByAssistant: IMessageService['removeMessagesByAssistant'] = async (
|
|
88
|
+
sessionId,
|
|
89
|
+
topicId,
|
|
90
|
+
) => {
|
|
95
91
|
return lambdaClient.message.removeMessagesByAssistant.mutate({
|
|
96
92
|
sessionId: this.toDbSessionId(sessionId),
|
|
97
93
|
topicId,
|
|
98
94
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
removeAllMessages: IMessageService['removeAllMessages'] = async () => {
|
|
101
98
|
return lambdaClient.message.removeAllMessages.mutate();
|
|
102
|
-
}
|
|
99
|
+
};
|
|
103
100
|
|
|
104
|
-
private toDbSessionId(sessionId: string | undefined) {
|
|
101
|
+
private toDbSessionId = (sessionId: string | undefined) => {
|
|
105
102
|
return sessionId === INBOX_SESSION_ID ? null : sessionId;
|
|
106
|
-
}
|
|
103
|
+
};
|
|
107
104
|
|
|
108
|
-
async
|
|
105
|
+
hasMessages: IMessageService['hasMessages'] = async () => {
|
|
109
106
|
const number = await this.countMessages();
|
|
110
107
|
return number > 0;
|
|
111
|
-
}
|
|
108
|
+
};
|
|
112
109
|
|
|
113
|
-
async
|
|
110
|
+
messageCountToCheckTrace: IMessageService['messageCountToCheckTrace'] = async () => {
|
|
114
111
|
const number = await this.countMessages();
|
|
115
112
|
return number >= 4;
|
|
116
|
-
}
|
|
113
|
+
};
|
|
117
114
|
}
|
|
@@ -24,11 +24,11 @@ export interface IMessageService {
|
|
|
24
24
|
updateMessageTTS(id: string, tts: Partial<ChatTTS> | false): Promise<any>;
|
|
25
25
|
updateMessageTranslate(id: string, translate: Partial<ChatTranslate> | false): Promise<any>;
|
|
26
26
|
updateMessagePluginState(id: string, value: Record<string, any>): Promise<any>;
|
|
27
|
-
|
|
27
|
+
updateMessagePluginArguments(id: string, value: string | Record<string, any>): Promise<any>;
|
|
28
28
|
removeMessage(id: string): Promise<any>;
|
|
29
29
|
removeMessages(ids: string[]): Promise<any>;
|
|
30
30
|
removeMessagesByAssistant(assistantId: string, topicId?: string): Promise<any>;
|
|
31
31
|
removeAllMessages(): Promise<any>;
|
|
32
|
-
|
|
32
|
+
messageCountToCheckTrace(): Promise<boolean>;
|
|
33
33
|
hasMessages(): Promise<boolean>;
|
|
34
34
|
}
|
|
@@ -1,51 +1,45 @@
|
|
|
1
|
-
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
2
|
-
|
|
3
1
|
import { clientDB } from '@/database/client/db';
|
|
4
2
|
import { PluginModel } from '@/database/server/models/plugin';
|
|
5
3
|
import { BaseClientService } from '@/services/baseClientService';
|
|
6
4
|
import { LobeTool } from '@/types/tool';
|
|
7
|
-
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
8
5
|
|
|
9
|
-
import { IPluginService
|
|
6
|
+
import { IPluginService } from './type';
|
|
10
7
|
|
|
11
8
|
export class ClientService extends BaseClientService implements IPluginService {
|
|
12
9
|
private get pluginModel(): PluginModel {
|
|
13
10
|
return new PluginModel(clientDB as any, this.userId);
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
installPlugin = async (plugin
|
|
13
|
+
installPlugin: IPluginService['installPlugin'] = async (plugin) => {
|
|
17
14
|
await this.pluginModel.create(plugin);
|
|
18
|
-
return;
|
|
19
15
|
};
|
|
20
16
|
|
|
21
|
-
getInstalledPlugins = () => {
|
|
17
|
+
getInstalledPlugins: IPluginService['getInstalledPlugins'] = () => {
|
|
22
18
|
return this.pluginModel.query() as Promise<LobeTool[]>;
|
|
23
19
|
};
|
|
24
20
|
|
|
25
|
-
async
|
|
21
|
+
uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
|
|
26
22
|
await this.pluginModel.delete(identifier);
|
|
27
|
-
|
|
28
|
-
}
|
|
23
|
+
};
|
|
29
24
|
|
|
30
|
-
async
|
|
25
|
+
createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
|
|
31
26
|
await this.pluginModel.create({ ...customPlugin, type: 'customPlugin' });
|
|
32
|
-
|
|
33
|
-
}
|
|
27
|
+
};
|
|
34
28
|
|
|
35
|
-
async
|
|
29
|
+
updatePlugin: IPluginService['updatePlugin'] = async (id, value) => {
|
|
36
30
|
await this.pluginModel.update(id, value);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
async
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
|
|
40
34
|
await this.pluginModel.update(id, { manifest });
|
|
41
|
-
}
|
|
35
|
+
};
|
|
42
36
|
|
|
43
|
-
async
|
|
37
|
+
removeAllPlugins: IPluginService['removeAllPlugins'] = async () => {
|
|
44
38
|
await this.pluginModel.deleteAll();
|
|
45
|
-
}
|
|
39
|
+
};
|
|
46
40
|
|
|
47
41
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
-
async
|
|
42
|
+
updatePluginSettings: IPluginService['updatePluginSettings'] = async (id, settings, _?) => {
|
|
49
43
|
await this.pluginModel.update(id, { settings });
|
|
50
|
-
}
|
|
44
|
+
};
|
|
51
45
|
}
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
2
|
-
|
|
3
1
|
import { lambdaClient } from '@/libs/trpc/client';
|
|
4
|
-
import { LobeTool } from '@/types/tool';
|
|
5
|
-
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
6
2
|
|
|
7
|
-
import { IPluginService
|
|
3
|
+
import { IPluginService } from './type';
|
|
8
4
|
|
|
9
5
|
export class ServerService implements IPluginService {
|
|
10
|
-
installPlugin = async (plugin
|
|
6
|
+
installPlugin: IPluginService['installPlugin'] = async (plugin) => {
|
|
11
7
|
await lambdaClient.plugin.createOrInstallPlugin.mutate(plugin);
|
|
12
8
|
};
|
|
13
9
|
|
|
14
|
-
getInstalledPlugins = ()
|
|
10
|
+
getInstalledPlugins: IPluginService['getInstalledPlugins'] = () => {
|
|
15
11
|
return lambdaClient.plugin.getPlugins.query();
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
async
|
|
14
|
+
uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
|
|
19
15
|
await lambdaClient.plugin.removePlugin.mutate({ id: identifier });
|
|
20
|
-
}
|
|
16
|
+
};
|
|
21
17
|
|
|
22
|
-
async
|
|
18
|
+
createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
|
|
23
19
|
await lambdaClient.plugin.createPlugin.mutate({ ...customPlugin, type: 'customPlugin' });
|
|
24
|
-
}
|
|
20
|
+
};
|
|
25
21
|
|
|
26
|
-
async
|
|
22
|
+
updatePlugin: IPluginService['updatePlugin'] = async (id, value) => {
|
|
27
23
|
await lambdaClient.plugin.updatePlugin.mutate({
|
|
28
24
|
customParams: value.customParams,
|
|
29
25
|
id,
|
|
30
26
|
manifest: value.manifest,
|
|
31
27
|
settings: value.settings,
|
|
32
28
|
});
|
|
33
|
-
}
|
|
29
|
+
};
|
|
34
30
|
|
|
35
|
-
async
|
|
31
|
+
updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
|
|
36
32
|
await lambdaClient.plugin.updatePlugin.mutate({ id, manifest });
|
|
37
|
-
}
|
|
33
|
+
};
|
|
38
34
|
|
|
39
|
-
async
|
|
35
|
+
removeAllPlugins: IPluginService['removeAllPlugins'] = async () => {
|
|
40
36
|
await lambdaClient.plugin.removeAllPlugins.mutate();
|
|
41
|
-
}
|
|
37
|
+
};
|
|
42
38
|
|
|
43
|
-
async
|
|
39
|
+
updatePluginSettings: IPluginService['updatePluginSettings'] = async (id, settings, signal) => {
|
|
44
40
|
await lambdaClient.plugin.updatePlugin.mutate({ id, settings }, { signal });
|
|
45
|
-
}
|
|
41
|
+
};
|
|
46
42
|
}
|
package/src/services/rag.ts
CHANGED
|
@@ -2,29 +2,29 @@ import { lambdaClient } from '@/libs/trpc/client';
|
|
|
2
2
|
import { SemanticSearchSchemaType } from '@/types/rag';
|
|
3
3
|
|
|
4
4
|
class RAGService {
|
|
5
|
-
async
|
|
6
|
-
return
|
|
7
|
-
}
|
|
5
|
+
createParseFileTask = async (id: string, skipExist?: boolean) => {
|
|
6
|
+
return lambdaClient.chunk.createParseFileTask.mutate({ id, skipExist });
|
|
7
|
+
};
|
|
8
8
|
|
|
9
|
-
async
|
|
10
|
-
return
|
|
11
|
-
}
|
|
9
|
+
retryParseFile = async (id: string) => {
|
|
10
|
+
return lambdaClient.chunk.retryParseFileTask.mutate({ id });
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
async
|
|
14
|
-
return
|
|
15
|
-
}
|
|
13
|
+
createEmbeddingChunksTask = async (id: string) => {
|
|
14
|
+
return lambdaClient.chunk.createEmbeddingChunksTask.mutate({ id });
|
|
15
|
+
};
|
|
16
16
|
|
|
17
|
-
async
|
|
18
|
-
return
|
|
19
|
-
}
|
|
17
|
+
semanticSearch = async (query: string, fileIds?: string[]) => {
|
|
18
|
+
return lambdaClient.chunk.semanticSearch.mutate({ fileIds, query });
|
|
19
|
+
};
|
|
20
20
|
|
|
21
|
-
async
|
|
22
|
-
return
|
|
23
|
-
}
|
|
21
|
+
semanticSearchForChat = async (params: SemanticSearchSchemaType) => {
|
|
22
|
+
return lambdaClient.chunk.semanticSearchForChat.mutate(params);
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
async
|
|
26
|
-
return
|
|
27
|
-
}
|
|
25
|
+
deleteMessageRagQuery = async (id: string) => {
|
|
26
|
+
return lambdaClient.message.removeMessageQuery.mutate({ id });
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export const ragService = new RAGService();
|