@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.
Files changed (203) hide show
  1. package/.env.example +19 -8
  2. package/.eslintignore +1 -1
  3. package/CHANGELOG.md +58 -0
  4. package/changelog/v1.json +21 -0
  5. package/docs/.cdn.cache.json +25 -0
  6. package/docs/changelog/2023-09-09-plugin-system.mdx +1 -1
  7. package/docs/changelog/2023-09-09-plugin-system.zh-CN.mdx +1 -1
  8. package/docs/changelog/2024-09-20-artifacts.mdx +1 -1
  9. package/docs/changelog/2024-09-20-artifacts.zh-CN.mdx +1 -1
  10. package/docs/changelog/2024-10-27-pin-assistant.mdx +2 -2
  11. package/docs/changelog/2024-10-27-pin-assistant.zh-CN.mdx +2 -2
  12. package/docs/changelog/2024-11-06-share-text-json.mdx +2 -2
  13. package/docs/changelog/2024-11-06-share-text-json.zh-CN.mdx +2 -2
  14. package/docs/changelog/index.json +16 -16
  15. package/locales/ar/changelog.json +18 -0
  16. package/locales/ar/common.json +1 -0
  17. package/locales/ar/metadata.json +4 -0
  18. package/locales/bg-BG/changelog.json +18 -0
  19. package/locales/bg-BG/common.json +1 -0
  20. package/locales/bg-BG/metadata.json +4 -0
  21. package/locales/de-DE/changelog.json +18 -0
  22. package/locales/de-DE/common.json +1 -0
  23. package/locales/de-DE/metadata.json +4 -0
  24. package/locales/en-US/changelog.json +18 -0
  25. package/locales/en-US/common.json +1 -0
  26. package/locales/en-US/metadata.json +4 -0
  27. package/locales/es-ES/changelog.json +18 -0
  28. package/locales/es-ES/common.json +1 -0
  29. package/locales/es-ES/metadata.json +4 -0
  30. package/locales/fa-IR/changelog.json +18 -0
  31. package/locales/fa-IR/common.json +1 -0
  32. package/locales/fa-IR/metadata.json +4 -0
  33. package/locales/fr-FR/changelog.json +18 -0
  34. package/locales/fr-FR/common.json +1 -0
  35. package/locales/fr-FR/metadata.json +4 -0
  36. package/locales/it-IT/changelog.json +18 -0
  37. package/locales/it-IT/common.json +1 -0
  38. package/locales/it-IT/metadata.json +4 -0
  39. package/locales/ja-JP/changelog.json +18 -0
  40. package/locales/ja-JP/common.json +1 -0
  41. package/locales/ja-JP/metadata.json +4 -0
  42. package/locales/ko-KR/changelog.json +18 -0
  43. package/locales/ko-KR/common.json +1 -0
  44. package/locales/ko-KR/metadata.json +4 -0
  45. package/locales/nl-NL/changelog.json +18 -0
  46. package/locales/nl-NL/common.json +1 -0
  47. package/locales/nl-NL/metadata.json +4 -0
  48. package/locales/pl-PL/changelog.json +18 -0
  49. package/locales/pl-PL/common.json +1 -0
  50. package/locales/pl-PL/metadata.json +4 -0
  51. package/locales/pt-BR/changelog.json +18 -0
  52. package/locales/pt-BR/common.json +1 -0
  53. package/locales/pt-BR/metadata.json +4 -0
  54. package/locales/ru-RU/changelog.json +18 -0
  55. package/locales/ru-RU/common.json +1 -0
  56. package/locales/ru-RU/metadata.json +4 -0
  57. package/locales/tr-TR/changelog.json +18 -0
  58. package/locales/tr-TR/common.json +1 -0
  59. package/locales/tr-TR/metadata.json +4 -0
  60. package/locales/vi-VN/changelog.json +18 -0
  61. package/locales/vi-VN/common.json +1 -0
  62. package/locales/vi-VN/metadata.json +4 -0
  63. package/locales/zh-CN/changelog.json +18 -0
  64. package/locales/zh-CN/common.json +1 -0
  65. package/locales/zh-CN/metadata.json +4 -0
  66. package/locales/zh-TW/changelog.json +18 -0
  67. package/locales/zh-TW/common.json +1 -0
  68. package/locales/zh-TW/metadata.json +4 -0
  69. package/package.json +6 -1
  70. package/scripts/cdnWorkflow/index.ts +217 -0
  71. package/scripts/cdnWorkflow/optimized.ts +21 -0
  72. package/scripts/cdnWorkflow/s3/index.ts +120 -0
  73. package/scripts/cdnWorkflow/s3/types.ts +25 -0
  74. package/scripts/cdnWorkflow/s3/utils.ts +106 -0
  75. package/scripts/cdnWorkflow/uploader.ts +73 -0
  76. package/scripts/cdnWorkflow/utils.ts +93 -0
  77. package/src/app/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +25 -12
  78. package/src/app/(main)/(mobile)/me/(home)/features/useCategory.tsx +19 -9
  79. package/src/app/(main)/(mobile)/me/(home)/loading.tsx +1 -1
  80. package/src/app/(main)/(mobile)/me/data/loading.tsx +1 -1
  81. package/src/app/(main)/(mobile)/me/profile/loading.tsx +1 -1
  82. package/src/app/(main)/(mobile)/me/settings/loading.tsx +1 -1
  83. package/src/app/(main)/_layout/Desktop.tsx +4 -1
  84. package/src/app/(main)/_layout/Mobile.tsx +2 -1
  85. package/src/app/(main)/changelog/_layout/Desktop.tsx +25 -0
  86. package/src/app/(main)/changelog/_layout/Mobile/Header.tsx +33 -0
  87. package/src/app/(main)/changelog/_layout/Mobile/index.tsx +21 -0
  88. package/src/app/(main)/changelog/error.tsx +5 -0
  89. package/src/app/(main)/changelog/features/GridLayout.tsx +22 -0
  90. package/src/app/(main)/changelog/features/Hero.tsx +40 -0
  91. package/src/app/(main)/changelog/features/Post.tsx +56 -0
  92. package/src/app/(main)/changelog/features/PublishedTime.tsx +50 -0
  93. package/src/app/(main)/changelog/features/VersionTag.tsx +27 -0
  94. package/src/app/(main)/changelog/layout.tsx +10 -0
  95. package/src/app/(main)/changelog/loading.tsx +3 -0
  96. package/src/app/(main)/changelog/modal/page.tsx +23 -0
  97. package/src/app/(main)/changelog/not-found.tsx +3 -0
  98. package/src/app/(main)/changelog/page.tsx +73 -0
  99. package/src/app/(main)/chat/(workspace)/@portal/default.tsx +1 -1
  100. package/src/app/(main)/chat/(workspace)/@portal/loading.tsx +1 -1
  101. package/src/app/(main)/chat/(workspace)/page.tsx +9 -2
  102. package/src/app/(main)/chat/@session/default.tsx +3 -2
  103. package/src/app/(main)/chat/loading.tsx +1 -1
  104. package/src/app/(main)/chat/settings/loading.tsx +1 -1
  105. package/src/app/(main)/discover/loading.tsx +1 -1
  106. package/src/app/(main)/files/loading.tsx +2 -22
  107. package/src/app/(main)/profile/loading.tsx +1 -1
  108. package/src/app/(main)/repos/[id]/evals/dataset/page.tsx +1 -1
  109. package/src/app/(main)/repos/[id]/evals/evaluation/page.tsx +1 -1
  110. package/src/app/(main)/settings/@category/default.tsx +6 -2
  111. package/src/app/(main)/settings/_layout/Desktop/SideBar.tsx +1 -1
  112. package/src/app/(main)/settings/about/features/Version.tsx +2 -2
  113. package/src/app/(main)/settings/loading.tsx +2 -8
  114. package/src/app/@modal/(.)changelog/modal/features/Cover.tsx +48 -0
  115. package/src/app/@modal/(.)changelog/modal/features/Hero.tsx +29 -0
  116. package/src/app/@modal/(.)changelog/modal/features/Pagination.tsx +54 -0
  117. package/src/app/@modal/(.)changelog/modal/features/Post.tsx +57 -0
  118. package/src/app/@modal/(.)changelog/modal/features/PublishedTime.tsx +50 -0
  119. package/src/app/@modal/(.)changelog/modal/features/ReadDetail.tsx +94 -0
  120. package/src/app/@modal/(.)changelog/modal/features/UpdateChangelogStatus.tsx +21 -0
  121. package/src/app/@modal/(.)changelog/modal/features/VersionTag.tsx +27 -0
  122. package/src/app/@modal/(.)changelog/modal/layout.tsx +39 -0
  123. package/src/app/@modal/(.)changelog/modal/loading.tsx +10 -0
  124. package/src/app/@modal/(.)changelog/modal/page.tsx +37 -0
  125. package/src/app/@modal/(.)settings/modal/layout.tsx +19 -16
  126. package/src/app/@modal/_layout/ModalLayout.tsx +63 -0
  127. package/src/app/@modal/chat/(.)settings/modal/layout.tsx +20 -17
  128. package/src/app/@modal/layout.tsx +5 -69
  129. package/src/app/loading/Client/Content.tsx +1 -1
  130. package/src/app/loading/Server/Content.tsx +1 -1
  131. package/src/components/Loading/BrandTextLoading/LobeChatText/SVG.tsx +44 -0
  132. package/src/components/Loading/BrandTextLoading/LobeChatText/index.tsx +6 -0
  133. package/src/components/Loading/BrandTextLoading/LobeChatText/style.css +32 -0
  134. package/src/components/Loading/BrandTextLoading/index.tsx +11 -0
  135. package/src/components/{SkeletonLoading → Loading/SkeletonLoading}/index.tsx +1 -1
  136. package/src/components/mdx/Image.tsx +50 -0
  137. package/src/components/mdx/index.tsx +2 -0
  138. package/src/const/url.ts +1 -0
  139. package/src/features/ChangelogModal/index.tsx +22 -0
  140. package/src/features/FileViewer/Renderer/TXT/index.tsx +1 -1
  141. package/src/features/Portal/FilePreview/Body/index.tsx +1 -1
  142. package/src/features/Portal/Home/Body/Files/FileList/index.tsx +1 -1
  143. package/src/features/Setting/Footer.tsx +3 -1
  144. package/src/features/Setting/SettingContainer.tsx +1 -0
  145. package/src/features/User/UserPanel/useMenu.tsx +50 -46
  146. package/src/features/User/__tests__/useMenu.test.tsx +7 -6
  147. package/src/hooks/useInterceptingRoutes.ts +1 -6
  148. package/src/hooks/useShare.tsx +1 -0
  149. package/src/locales/default/changelog.ts +18 -0
  150. package/src/locales/default/common.ts +1 -0
  151. package/src/locales/default/index.ts +2 -0
  152. package/src/locales/default/metadata.ts +4 -0
  153. package/src/server/metadata.ts +5 -3
  154. package/src/server/routers/edge/appStatus.ts +3 -0
  155. package/src/server/routers/edge/index.ts +2 -0
  156. package/src/server/routers/lambda/agent.ts +1 -1
  157. package/src/server/services/changelog/index.test.ts +310 -0
  158. package/src/server/services/changelog/index.ts +196 -0
  159. package/src/server/services/discover/index.test.ts +0 -1
  160. package/src/server/sitemap.ts +4 -1
  161. package/src/services/__tests__/chat.test.ts +1 -1
  162. package/src/services/__tests__/global.test.ts +5 -2
  163. package/src/services/_auth.ts +1 -1
  164. package/src/services/agent.ts +25 -21
  165. package/src/services/chat.ts +2 -2
  166. package/src/services/file/ClientS3/index.ts +6 -6
  167. package/src/services/file/client.ts +14 -15
  168. package/src/services/file/server.ts +20 -25
  169. package/src/services/global.ts +2 -2
  170. package/src/services/import/client.ts +6 -5
  171. package/src/services/import/server.ts +6 -5
  172. package/src/services/import/type.ts +7 -0
  173. package/src/services/knowledgeBase.ts +19 -19
  174. package/src/services/message/_deprecated.ts +5 -0
  175. package/src/services/message/client.ts +52 -48
  176. package/src/services/message/server.ts +50 -53
  177. package/src/services/message/type.ts +2 -2
  178. package/src/services/plugin/client.ts +16 -22
  179. package/src/services/plugin/server.ts +15 -19
  180. package/src/services/rag.ts +18 -18
  181. package/src/services/ragEval.ts +29 -26
  182. package/src/services/session/_deprecated.ts +2 -2
  183. package/src/services/session/client.ts +55 -81
  184. package/src/services/session/server.ts +50 -74
  185. package/src/services/session/type.ts +4 -6
  186. package/src/services/share.ts +4 -4
  187. package/src/services/textToImage.ts +5 -2
  188. package/src/services/thread/client.ts +9 -15
  189. package/src/services/thread/server.ts +10 -15
  190. package/src/services/topic/client.ts +25 -25
  191. package/src/services/topic/server.ts +25 -42
  192. package/src/services/trace.ts +4 -4
  193. package/src/services/user/client.ts +13 -17
  194. package/src/services/user/server.ts +9 -13
  195. package/src/services/user/type.ts +1 -1
  196. package/src/store/chat/slices/message/reducer.ts +3 -2
  197. package/src/store/global/action.ts +27 -22
  198. package/src/store/global/initialState.ts +1 -0
  199. package/src/types/changelog.ts +6 -0
  200. package/src/types/message/index.ts +10 -8
  201. package/src/app/@modal/features/InterceptingContext.tsx +0 -9
  202. /package/src/components/{CircleLoading → Loading/CircleLoading}/index.tsx +0 -0
  203. /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 createKnowledgeBase(params: CreateKnowledgeBaseParams) {
6
- return await lambdaClient.knowledgeBase.createKnowledgeBase.mutate(params);
7
- }
5
+ createKnowledgeBase = async (params: CreateKnowledgeBaseParams) => {
6
+ return lambdaClient.knowledgeBase.createKnowledgeBase.mutate(params);
7
+ };
8
8
 
9
- async getKnowledgeBaseList() {
10
- return await lambdaClient.knowledgeBase.getKnowledgeBases.query();
11
- }
9
+ getKnowledgeBaseList = async () => {
10
+ return lambdaClient.knowledgeBase.getKnowledgeBases.query();
11
+ };
12
12
 
13
- async getKnowledgeBaseById(id: string) {
14
- return await lambdaClient.knowledgeBase.getKnowledgeBaseById.query({ id });
15
- }
13
+ getKnowledgeBaseById = async (id: string) => {
14
+ return lambdaClient.knowledgeBase.getKnowledgeBaseById.query({ id });
15
+ };
16
16
 
17
- async updateKnowledgeBaseList(id: string, value: any) {
18
- return await lambdaClient.knowledgeBase.updateKnowledgeBase.mutate({ id, value });
19
- }
17
+ updateKnowledgeBaseList = async (id: string, value: any) => {
18
+ return lambdaClient.knowledgeBase.updateKnowledgeBase.mutate({ id, value });
19
+ };
20
20
 
21
- async deleteKnowledgeBase(id: string) {
22
- return await lambdaClient.knowledgeBase.removeKnowledgeBase.mutate({ id });
23
- }
21
+ deleteKnowledgeBase = async (id: string) => {
22
+ return lambdaClient.knowledgeBase.removeKnowledgeBase.mutate({ id });
23
+ };
24
24
 
25
- async addFilesToKnowledgeBase(knowledgeBaseId: string, ids: string[]) {
25
+ addFilesToKnowledgeBase = async (knowledgeBaseId: string, ids: string[]) => {
26
26
  return lambdaClient.knowledgeBase.addFilesToKnowledgeBase.mutate({ ids, knowledgeBaseId });
27
- }
27
+ };
28
28
 
29
- async removeFilesFromKnowledgeBase(knowledgeBaseId: string, ids: string[]) {
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 createMessage({ sessionId, ...params }: CreateMessageParams) {
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
- async batchCreateMessages(messages: MessageItem[]) {
26
+ batchCreateMessages: IMessageService['batchCreateMessages'] = async (messages) => {
34
27
  return this.messageModel.batchCreate(messages);
35
- }
28
+ };
36
29
 
37
- async getMessages(sessionId: string, topicId?: string) {
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 getAllMessages() {
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 countMessages() {
55
+ countMessages: IMessageService['countMessages'] = async () => {
63
56
  return this.messageModel.count();
64
- }
57
+ };
65
58
 
66
- async countTodayMessages() {
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 getAllMessagesInSession(sessionId: string) {
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 updateMessageError(id: string, error: ChatMessageError) {
72
+ updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
80
73
  return this.messageModel.update(id, { error });
81
- }
74
+ };
82
75
 
83
- async updateMessage(id: string, message: Partial<MessageItem>) {
76
+ updateMessage: IMessageService['updateMessage'] = async (id, message) => {
84
77
  return this.messageModel.update(id, message);
85
- }
78
+ };
86
79
 
87
- async updateMessageTTS(id: string, tts: Partial<ChatTTS> | false) {
80
+ updateMessageTTS: IMessageService['updateMessageTTS'] = async (id, tts) => {
88
81
  return this.messageModel.updateTTS(id, tts as any);
89
- }
82
+ };
90
83
 
91
- async updateMessageTranslate(id: string, translate: Partial<ChatTranslate> | false) {
84
+ updateMessageTranslate: IMessageService['updateMessageTranslate'] = async (id, translate) => {
92
85
  return this.messageModel.updateTranslate(id, translate as any);
93
- }
86
+ };
94
87
 
95
- async updateMessagePluginState(id: string, value: Record<string, any>) {
88
+ updateMessagePluginState: IMessageService['updateMessagePluginState'] = async (id, value) => {
96
89
  return this.messageModel.updatePluginState(id, value);
97
- }
90
+ };
98
91
 
99
- async updateMessagePluginArguments(id: string, value: string | Record<string, any>) {
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 removeMessage(id: string) {
101
+ removeMessage: IMessageService['removeMessage'] = async (id) => {
106
102
  return this.messageModel.deleteMessage(id);
107
- }
103
+ };
108
104
 
109
- async removeMessages(ids: string[]) {
105
+ removeMessages: IMessageService['removeMessages'] = async (ids) => {
110
106
  return this.messageModel.deleteMessages(ids);
111
- }
107
+ };
112
108
 
113
- async removeMessagesByAssistant(sessionId: string, topicId?: string) {
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 removeAllMessages() {
116
+ removeAllMessages: IMessageService['removeAllMessages'] = async () => {
118
117
  return this.messageModel.deleteAllMessages();
119
- }
118
+ };
120
119
 
121
- async hasMessages() {
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 getBase64ByFileHash(hash: string) {
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 }: CreateMessageParams): Promise<string> {
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(messages: MessageItem[]): Promise<any> {
16
+ batchCreateMessages: IMessageService['batchCreateMessages'] = async (messages) => {
24
17
  return lambdaClient.message.batchCreateMessages.mutate(messages);
25
- }
18
+ };
26
19
 
27
- getMessages = async (sessionId?: string, topicId?: string | undefined) => {
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(): Promise<ChatMessage[]> {
29
+ getAllMessages: IMessageService['getAllMessages'] = async () => {
37
30
  return lambdaClient.message.getAllMessages.query();
38
- }
31
+ };
39
32
 
40
- getAllMessagesInSession(sessionId: string): Promise<ChatMessage[]> {
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(): Promise<number> {
39
+ countMessages: IMessageService['countMessages'] = async () => {
47
40
  return lambdaClient.message.count.query();
48
- }
49
- countTodayMessages(): Promise<number> {
41
+ };
42
+
43
+ countTodayMessages: IMessageService['countTodayMessages'] = async () => {
50
44
  return lambdaClient.message.countToday.query();
51
- }
45
+ };
52
46
 
53
- updateMessageError(id: string, error: ChatMessageError): Promise<any> {
47
+ updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
54
48
  return lambdaClient.message.update.mutate({ id, value: { error } });
55
- }
49
+ };
56
50
 
57
- async updateMessagePluginError(id: string, error: ChatMessageError): Promise<any> {
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 updateMessagePluginArguments(
62
- id: string,
63
- value: string | Record<string, any>,
64
- ): Promise<any> {
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: string, message: Partial<MessageItem>): Promise<any> {
63
+ updateMessage: IMessageService['updateMessage'] = async (id, message) => {
71
64
  return lambdaClient.message.update.mutate({ id, value: message });
72
- }
65
+ };
73
66
 
74
- updateMessageTranslate(id: string, translate: Partial<ChatTranslate> | false): Promise<any> {
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(id: string, tts: Partial<ChatTTS> | false): Promise<any> {
71
+ updateMessageTTS: IMessageService['updateMessageTTS'] = async (id, tts) => {
79
72
  return lambdaClient.message.updateTTS.mutate({ id, value: tts });
80
- }
73
+ };
81
74
 
82
- updateMessagePluginState(id: string, value: any): Promise<any> {
75
+ updateMessagePluginState: IMessageService['updateMessagePluginState'] = async (id, value) => {
83
76
  return lambdaClient.message.updatePluginState.mutate({ id, value });
84
- }
77
+ };
85
78
 
86
- removeMessage(id: string): Promise<any> {
79
+ removeMessage: IMessageService['removeMessage'] = async (id) => {
87
80
  return lambdaClient.message.removeMessage.mutate({ id });
88
- }
81
+ };
89
82
 
90
- removeMessages(ids: string[]): Promise<any> {
83
+ removeMessages: IMessageService['removeMessages'] = async (ids) => {
91
84
  return lambdaClient.message.removeMessages.mutate({ ids });
92
- }
85
+ };
93
86
 
94
- removeMessagesByAssistant(sessionId: string, topicId?: string | undefined): Promise<any> {
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
- removeAllMessages(): Promise<any> {
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 hasMessages() {
105
+ hasMessages: IMessageService['hasMessages'] = async () => {
109
106
  const number = await this.countMessages();
110
107
  return number > 0;
111
- }
108
+ };
112
109
 
113
- async messageCountToCheckTrace() {
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, InstallPluginParams } from './type';
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: InstallPluginParams) => {
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 uninstallPlugin(identifier: string) {
21
+ uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
26
22
  await this.pluginModel.delete(identifier);
27
- return;
28
- }
23
+ };
29
24
 
30
- async createCustomPlugin(customPlugin: LobeToolCustomPlugin) {
25
+ createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
31
26
  await this.pluginModel.create({ ...customPlugin, type: 'customPlugin' });
32
- return;
33
- }
27
+ };
34
28
 
35
- async updatePlugin(id: string, value: LobeToolCustomPlugin) {
29
+ updatePlugin: IPluginService['updatePlugin'] = async (id, value) => {
36
30
  await this.pluginModel.update(id, value);
37
- return;
38
- }
39
- async updatePluginManifest(id: string, manifest: LobeChatPluginManifest) {
31
+ };
32
+
33
+ updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
40
34
  await this.pluginModel.update(id, { manifest });
41
- }
35
+ };
42
36
 
43
- async removeAllPlugins() {
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 updatePluginSettings(id: string, settings: any, _?: AbortSignal) {
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, InstallPluginParams } from './type';
3
+ import { IPluginService } from './type';
8
4
 
9
5
  export class ServerService implements IPluginService {
10
- installPlugin = async (plugin: InstallPluginParams) => {
6
+ installPlugin: IPluginService['installPlugin'] = async (plugin) => {
11
7
  await lambdaClient.plugin.createOrInstallPlugin.mutate(plugin);
12
8
  };
13
9
 
14
- getInstalledPlugins = (): Promise<LobeTool[]> => {
10
+ getInstalledPlugins: IPluginService['getInstalledPlugins'] = () => {
15
11
  return lambdaClient.plugin.getPlugins.query();
16
12
  };
17
13
 
18
- async uninstallPlugin(identifier: string) {
14
+ uninstallPlugin: IPluginService['uninstallPlugin'] = async (identifier) => {
19
15
  await lambdaClient.plugin.removePlugin.mutate({ id: identifier });
20
- }
16
+ };
21
17
 
22
- async createCustomPlugin(customPlugin: LobeToolCustomPlugin) {
18
+ createCustomPlugin: IPluginService['createCustomPlugin'] = async (customPlugin) => {
23
19
  await lambdaClient.plugin.createPlugin.mutate({ ...customPlugin, type: 'customPlugin' });
24
- }
20
+ };
25
21
 
26
- async updatePlugin(id: string, value: LobeToolCustomPlugin) {
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 updatePluginManifest(id: string, manifest: LobeChatPluginManifest) {
31
+ updatePluginManifest: IPluginService['updatePluginManifest'] = async (id, manifest) => {
36
32
  await lambdaClient.plugin.updatePlugin.mutate({ id, manifest });
37
- }
33
+ };
38
34
 
39
- async removeAllPlugins() {
35
+ removeAllPlugins: IPluginService['removeAllPlugins'] = async () => {
40
36
  await lambdaClient.plugin.removeAllPlugins.mutate();
41
- }
37
+ };
42
38
 
43
- async updatePluginSettings(id: string, settings: any, signal?: AbortSignal) {
39
+ updatePluginSettings: IPluginService['updatePluginSettings'] = async (id, settings, signal) => {
44
40
  await lambdaClient.plugin.updatePlugin.mutate({ id, settings }, { signal });
45
- }
41
+ };
46
42
  }
@@ -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 createParseFileTask(id: string, skipExist?: boolean) {
6
- return await lambdaClient.chunk.createParseFileTask.mutate({ id, skipExist });
7
- }
5
+ createParseFileTask = async (id: string, skipExist?: boolean) => {
6
+ return lambdaClient.chunk.createParseFileTask.mutate({ id, skipExist });
7
+ };
8
8
 
9
- async retryParseFile(id: string) {
10
- return await lambdaClient.chunk.retryParseFileTask.mutate({ id });
11
- }
9
+ retryParseFile = async (id: string) => {
10
+ return lambdaClient.chunk.retryParseFileTask.mutate({ id });
11
+ };
12
12
 
13
- async createEmbeddingChunksTask(id: string) {
14
- return await lambdaClient.chunk.createEmbeddingChunksTask.mutate({ id });
15
- }
13
+ createEmbeddingChunksTask = async (id: string) => {
14
+ return lambdaClient.chunk.createEmbeddingChunksTask.mutate({ id });
15
+ };
16
16
 
17
- async semanticSearch(query: string, fileIds?: string[]) {
18
- return await lambdaClient.chunk.semanticSearch.mutate({ fileIds, query });
19
- }
17
+ semanticSearch = async (query: string, fileIds?: string[]) => {
18
+ return lambdaClient.chunk.semanticSearch.mutate({ fileIds, query });
19
+ };
20
20
 
21
- async semanticSearchForChat(params: SemanticSearchSchemaType) {
22
- return await lambdaClient.chunk.semanticSearchForChat.mutate(params);
23
- }
21
+ semanticSearchForChat = async (params: SemanticSearchSchemaType) => {
22
+ return lambdaClient.chunk.semanticSearchForChat.mutate(params);
23
+ };
24
24
 
25
- async deleteMessageRagQuery(id: string) {
26
- return await lambdaClient.message.removeMessageQuery.mutate({ id });
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();