@lobehub/chat 1.39.3 → 1.40.1
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)/_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)/_layout/Desktop/HotKeys.tsx +7 -0
- package/src/app/(main)/chat/(workspace)/page.tsx +9 -2
- package/src/app/(main)/settings/about/features/Version.tsx +2 -2
- 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/components/mdx/Image.tsx +50 -0
- package/src/components/mdx/index.tsx +2 -0
- package/src/const/hotkeys.ts +1 -0
- package/src/const/url.ts +1 -0
- package/src/features/ChangelogModal/index.tsx +22 -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/libs/agent-runtime/openai/index.ts +2 -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
@@ -17,21 +17,21 @@ export class BrowserS3Storage {
|
|
17
17
|
* @param key 文件 hash
|
18
18
|
* @param file File 对象
|
19
19
|
*/
|
20
|
-
async
|
20
|
+
putObject = async (key: string, file: File): Promise<void> => {
|
21
21
|
try {
|
22
22
|
const data = await file.arrayBuffer();
|
23
23
|
await set(key, { data, name: file.name, type: file.type }, this.store);
|
24
24
|
} catch (e) {
|
25
25
|
throw new Error(`Failed to put file ${file.name}: ${(e as Error).message}`);
|
26
26
|
}
|
27
|
-
}
|
27
|
+
};
|
28
28
|
|
29
29
|
/**
|
30
30
|
* 获取文件
|
31
31
|
* @param key 文件 hash
|
32
32
|
* @returns File 对象
|
33
33
|
*/
|
34
|
-
async
|
34
|
+
getObject = async (key: string): Promise<File | undefined> => {
|
35
35
|
try {
|
36
36
|
const res = await get<{ data: ArrayBuffer; name: string; type: string }>(key, this.store);
|
37
37
|
if (!res) return;
|
@@ -40,19 +40,19 @@ export class BrowserS3Storage {
|
|
40
40
|
} catch (e) {
|
41
41
|
throw new Error(`Failed to get object (key=${key}): ${(e as Error).message}`);
|
42
42
|
}
|
43
|
-
}
|
43
|
+
};
|
44
44
|
|
45
45
|
/**
|
46
46
|
* 删除文件
|
47
47
|
* @param key 文件 hash
|
48
48
|
*/
|
49
|
-
async
|
49
|
+
deleteObject = async (key: string): Promise<void> => {
|
50
50
|
try {
|
51
51
|
await del(key, this.store);
|
52
52
|
} catch (e) {
|
53
53
|
throw new Error(`Failed to delete object (key=${key}): ${(e as Error).message}`);
|
54
54
|
}
|
55
|
-
}
|
55
|
+
};
|
56
56
|
}
|
57
57
|
|
58
58
|
export const clientS3Storage = new BrowserS3Storage();
|
@@ -2,7 +2,6 @@ import { clientDB } from '@/database/client/db';
|
|
2
2
|
import { FileModel } from '@/database/server/models/file';
|
3
3
|
import { BaseClientService } from '@/services/baseClientService';
|
4
4
|
import { clientS3Storage } from '@/services/file/ClientS3';
|
5
|
-
import { FileItem, UploadFileParams } from '@/types/files';
|
6
5
|
|
7
6
|
import { IFileService } from './type';
|
8
7
|
|
@@ -11,7 +10,7 @@ export class ClientService extends BaseClientService implements IFileService {
|
|
11
10
|
return new FileModel(clientDB as any, this.userId);
|
12
11
|
}
|
13
12
|
|
14
|
-
async
|
13
|
+
createFile: IFileService['createFile'] = async (file) => {
|
15
14
|
// save to local storage
|
16
15
|
// we may want to save to a remote server later
|
17
16
|
const res = await this.fileModel.create(
|
@@ -34,9 +33,9 @@ export class ClientService extends BaseClientService implements IFileService {
|
|
34
33
|
id: res.id,
|
35
34
|
url: `data:${file.fileType};base64,${base64}`,
|
36
35
|
};
|
37
|
-
}
|
36
|
+
};
|
38
37
|
|
39
|
-
async
|
38
|
+
getFile: IFileService['getFile'] = async (id) => {
|
40
39
|
const item = await this.fileModel.findById(id);
|
41
40
|
if (!item) {
|
42
41
|
throw new Error('file not found');
|
@@ -57,28 +56,28 @@ export class ClientService extends BaseClientService implements IFileService {
|
|
57
56
|
updatedAt: new Date(item.updatedAt),
|
58
57
|
url,
|
59
58
|
};
|
60
|
-
}
|
59
|
+
};
|
61
60
|
|
62
|
-
async
|
61
|
+
removeFile: IFileService['removeFile'] = async (id) => {
|
63
62
|
await this.fileModel.delete(id, false);
|
64
|
-
}
|
63
|
+
};
|
65
64
|
|
66
|
-
|
65
|
+
removeFiles: IFileService['removeFiles'] = async (ids) => {
|
67
66
|
await this.fileModel.deleteMany(ids, false);
|
68
|
-
}
|
67
|
+
};
|
69
68
|
|
70
|
-
async
|
69
|
+
removeAllFiles: IFileService['removeAllFiles'] = async () => {
|
71
70
|
return this.fileModel.clear();
|
72
|
-
}
|
71
|
+
};
|
73
72
|
|
74
|
-
async
|
73
|
+
checkFileHash: IFileService['checkFileHash'] = async (hash) => {
|
75
74
|
return this.fileModel.checkHash(hash);
|
76
|
-
}
|
75
|
+
};
|
77
76
|
|
78
|
-
private async
|
77
|
+
private getBase64ByFileHash = async (hash: string) => {
|
79
78
|
const fileItem = await clientS3Storage.getObject(hash);
|
80
79
|
if (!fileItem) throw new Error('file not found');
|
81
80
|
|
82
81
|
return Buffer.from(await fileItem.arrayBuffer()).toString('base64');
|
83
|
-
}
|
82
|
+
};
|
84
83
|
}
|
@@ -1,10 +1,5 @@
|
|
1
1
|
import { lambdaClient } from '@/libs/trpc/client';
|
2
|
-
import {
|
3
|
-
FileItem,
|
4
|
-
QueryFileListParams,
|
5
|
-
QueryFileListSchemaType,
|
6
|
-
UploadFileParams,
|
7
|
-
} from '@/types/files';
|
2
|
+
import { QueryFileListParams, QueryFileListSchemaType, UploadFileParams } from '@/types/files';
|
8
3
|
|
9
4
|
import { IFileService } from './type';
|
10
5
|
|
@@ -14,11 +9,11 @@ interface CreateFileParams extends Omit<UploadFileParams, 'url'> {
|
|
14
9
|
}
|
15
10
|
|
16
11
|
export class ServerService implements IFileService {
|
17
|
-
async
|
12
|
+
createFile: IFileService['createFile'] = async (params, knowledgeBaseId) => {
|
18
13
|
return lambdaClient.file.createFile.mutate({ ...params, knowledgeBaseId } as CreateFileParams);
|
19
|
-
}
|
14
|
+
};
|
20
15
|
|
21
|
-
async
|
16
|
+
getFile: IFileService['getFile'] = async (id) => {
|
22
17
|
const item = await lambdaClient.file.findById.query({ id });
|
23
18
|
|
24
19
|
if (!item) {
|
@@ -26,33 +21,33 @@ export class ServerService implements IFileService {
|
|
26
21
|
}
|
27
22
|
|
28
23
|
return { ...item, type: item.fileType };
|
29
|
-
}
|
24
|
+
};
|
30
25
|
|
31
|
-
async
|
26
|
+
removeFile: IFileService['removeFile'] = async (id) => {
|
32
27
|
await lambdaClient.file.removeFile.mutate({ id });
|
33
|
-
}
|
28
|
+
};
|
34
29
|
|
35
|
-
|
30
|
+
removeFiles: IFileService['removeFiles'] = async (ids) => {
|
36
31
|
await lambdaClient.file.removeFiles.mutate({ ids });
|
37
|
-
}
|
32
|
+
};
|
38
33
|
|
39
|
-
async
|
34
|
+
removeAllFiles: IFileService['removeAllFiles'] = async () => {
|
40
35
|
await lambdaClient.file.removeAllFiles.mutate();
|
41
|
-
}
|
36
|
+
};
|
42
37
|
|
43
|
-
async
|
38
|
+
getFiles = async (params: QueryFileListParams) => {
|
44
39
|
return lambdaClient.file.getFiles.query(params as QueryFileListSchemaType);
|
45
|
-
}
|
40
|
+
};
|
46
41
|
|
47
|
-
async
|
42
|
+
getFileItem = async (id: string) => {
|
48
43
|
return lambdaClient.file.getFileItemById.query({ id });
|
49
|
-
}
|
44
|
+
};
|
50
45
|
|
51
|
-
async
|
46
|
+
checkFileHash: IFileService['checkFileHash'] = async (hash) => {
|
52
47
|
return lambdaClient.file.checkFileHash.mutate({ hash });
|
53
|
-
}
|
48
|
+
};
|
54
49
|
|
55
|
-
async
|
56
|
-
return
|
57
|
-
}
|
50
|
+
removeFileAsyncTask = async (id: string, type: 'embedding' | 'chunk') => {
|
51
|
+
return lambdaClient.file.removeFileAsyncTask.mutate({ id, type });
|
52
|
+
};
|
58
53
|
}
|
package/src/services/global.ts
CHANGED
@@ -4,7 +4,7 @@ import { edgeClient } from '@/libs/trpc/client';
|
|
4
4
|
import { LobeAgentConfig } from '@/types/agent';
|
5
5
|
import { GlobalServerConfig } from '@/types/serverConfig';
|
6
6
|
|
7
|
-
const VERSION_URL = 'https://registry.npmmirror.com/@lobehub/chat';
|
7
|
+
const VERSION_URL = 'https://registry.npmmirror.com/@lobehub/chat/latest';
|
8
8
|
|
9
9
|
class GlobalService {
|
10
10
|
/**
|
@@ -14,7 +14,7 @@ class GlobalService {
|
|
14
14
|
const res = await fetch(VERSION_URL);
|
15
15
|
const data = await res.json();
|
16
16
|
|
17
|
-
return data['
|
17
|
+
return data['version'];
|
18
18
|
};
|
19
19
|
|
20
20
|
getGlobalConfig = async (): Promise<GlobalServerConfig> => {
|
@@ -2,19 +2,20 @@ import { clientDB } from '@/database/client/db';
|
|
2
2
|
import { DataImporterRepos } from '@/database/repositories/dataImporter';
|
3
3
|
import { BaseClientService } from '@/services/baseClientService';
|
4
4
|
import { useUserStore } from '@/store/user';
|
5
|
-
import { ImportStage
|
6
|
-
import { UserSettings } from '@/types/user/settings';
|
5
|
+
import { ImportStage } from '@/types/importer';
|
7
6
|
|
8
|
-
|
7
|
+
import { IImportService } from './type';
|
8
|
+
|
9
|
+
export class ClientService extends BaseClientService implements IImportService {
|
9
10
|
private get dataImporter(): DataImporterRepos {
|
10
11
|
return new DataImporterRepos(clientDB as any, this.userId);
|
11
12
|
}
|
12
13
|
|
13
|
-
importSettings = async (settings
|
14
|
+
importSettings: IImportService['importSettings'] = async (settings) => {
|
14
15
|
await useUserStore.getState().importAppSettings(settings);
|
15
16
|
};
|
16
17
|
|
17
|
-
importData = async (data
|
18
|
+
importData: IImportService['importData'] = async (data, callbacks) => {
|
18
19
|
callbacks?.onStageChange?.(ImportStage.Importing);
|
19
20
|
const time = Date.now();
|
20
21
|
try {
|
@@ -2,16 +2,17 @@ import { DefaultErrorShape } from '@trpc/server/unstable-core-do-not-import';
|
|
2
2
|
|
3
3
|
import { edgeClient, lambdaClient } from '@/libs/trpc/client';
|
4
4
|
import { useUserStore } from '@/store/user';
|
5
|
-
import { ImportStage,
|
6
|
-
import { UserSettings } from '@/types/user/settings';
|
5
|
+
import { ImportStage, OnImportCallbacks } from '@/types/importer';
|
7
6
|
import { uuid } from '@/utils/uuid';
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
import { IImportService } from './type';
|
9
|
+
|
10
|
+
export class ServerService implements IImportService {
|
11
|
+
importSettings: IImportService['importSettings'] = async (settings) => {
|
11
12
|
await useUserStore.getState().importAppSettings(settings);
|
12
13
|
};
|
13
14
|
|
14
|
-
importData = async (data
|
15
|
+
importData: IImportService['importData'] = async (data, callbacks) => {
|
15
16
|
const handleError = (e: unknown) => {
|
16
17
|
callbacks?.onStageChange?.(ImportStage.Error);
|
17
18
|
const error = e as DefaultErrorShape;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ImporterEntryData, OnImportCallbacks } from '@/types/importer';
|
2
|
+
import { UserSettings } from '@/types/user/settings';
|
3
|
+
|
4
|
+
export interface IImportService {
|
5
|
+
importData(data: ImporterEntryData, callbacks?: OnImportCallbacks): Promise<void>;
|
6
|
+
importSettings(settings: UserSettings): Promise<void>;
|
7
|
+
}
|
@@ -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
|
}
|