@lobehub/chat 1.76.0 → 1.77.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/CHANGELOG.md +50 -0
- package/Dockerfile +3 -2
- package/Dockerfile.database +3 -1
- package/Dockerfile.pglite +3 -1
- package/changelog/v1.json +18 -0
- package/locales/ar/common.json +12 -1
- package/locales/ar/error.json +10 -0
- package/locales/ar/models.json +12 -6
- package/locales/ar/setting.json +28 -0
- package/locales/bg-BG/common.json +12 -1
- package/locales/bg-BG/error.json +10 -0
- package/locales/bg-BG/models.json +12 -6
- package/locales/bg-BG/setting.json +28 -0
- package/locales/de-DE/common.json +12 -1
- package/locales/de-DE/error.json +10 -0
- package/locales/de-DE/models.json +12 -6
- package/locales/de-DE/setting.json +28 -0
- package/locales/en-US/common.json +12 -1
- package/locales/en-US/error.json +10 -0
- package/locales/en-US/models.json +12 -6
- package/locales/en-US/setting.json +28 -0
- package/locales/es-ES/common.json +12 -1
- package/locales/es-ES/error.json +10 -0
- package/locales/es-ES/models.json +12 -6
- package/locales/es-ES/setting.json +28 -0
- package/locales/fa-IR/common.json +12 -1
- package/locales/fa-IR/error.json +10 -0
- package/locales/fa-IR/models.json +12 -6
- package/locales/fa-IR/setting.json +28 -0
- package/locales/fr-FR/common.json +12 -1
- package/locales/fr-FR/error.json +10 -0
- package/locales/fr-FR/models.json +12 -6
- package/locales/fr-FR/setting.json +28 -0
- package/locales/it-IT/common.json +12 -1
- package/locales/it-IT/error.json +10 -0
- package/locales/it-IT/models.json +12 -6
- package/locales/it-IT/setting.json +28 -0
- package/locales/ja-JP/common.json +12 -1
- package/locales/ja-JP/error.json +10 -0
- package/locales/ja-JP/models.json +12 -6
- package/locales/ja-JP/setting.json +28 -0
- package/locales/ko-KR/common.json +12 -1
- package/locales/ko-KR/error.json +10 -0
- package/locales/ko-KR/models.json +12 -6
- package/locales/ko-KR/setting.json +28 -0
- package/locales/nl-NL/common.json +12 -1
- package/locales/nl-NL/error.json +10 -0
- package/locales/nl-NL/models.json +12 -6
- package/locales/nl-NL/setting.json +28 -0
- package/locales/pl-PL/common.json +12 -1
- package/locales/pl-PL/error.json +10 -0
- package/locales/pl-PL/models.json +12 -6
- package/locales/pl-PL/setting.json +28 -0
- package/locales/pt-BR/common.json +12 -1
- package/locales/pt-BR/error.json +10 -0
- package/locales/pt-BR/models.json +12 -6
- package/locales/pt-BR/setting.json +28 -0
- package/locales/ru-RU/common.json +12 -1
- package/locales/ru-RU/error.json +10 -0
- package/locales/ru-RU/models.json +12 -6
- package/locales/ru-RU/setting.json +28 -0
- package/locales/tr-TR/common.json +12 -1
- package/locales/tr-TR/error.json +10 -0
- package/locales/tr-TR/models.json +12 -6
- package/locales/tr-TR/setting.json +28 -0
- package/locales/vi-VN/common.json +12 -1
- package/locales/vi-VN/error.json +10 -0
- package/locales/vi-VN/models.json +12 -6
- package/locales/vi-VN/setting.json +28 -0
- package/locales/zh-CN/common.json +12 -1
- package/locales/zh-CN/error.json +10 -0
- package/locales/zh-CN/models.json +12 -6
- package/locales/zh-CN/setting.json +28 -0
- package/locales/zh-TW/common.json +12 -1
- package/locales/zh-TW/error.json +10 -0
- package/locales/zh-TW/models.json +12 -6
- package/locales/zh-TW/setting.json +28 -0
- package/package.json +1 -1
- package/src/app/[variants]/(main)/(mobile)/me/data/features/Category.tsx +1 -1
- package/src/app/[variants]/(main)/chat/features/Migration/UpgradeButton.tsx +2 -1
- package/src/app/[variants]/(main)/settings/common/features/Common.tsx +0 -44
- package/src/app/[variants]/(main)/settings/hooks/useCategory.tsx +40 -14
- package/src/app/[variants]/(main)/settings/storage/Advanced.tsx +133 -0
- package/src/app/[variants]/(main)/settings/storage/IndexedDBStorage.tsx +55 -0
- package/src/app/[variants]/(main)/settings/storage/page.tsx +17 -0
- package/src/app/[variants]/(main)/settings/tts/features/const.tsx +4 -0
- package/src/components/GroupIcon/index.tsx +25 -0
- package/src/components/IndexCard/index.tsx +143 -0
- package/src/components/ProgressItem/index.tsx +75 -0
- package/src/config/aiModels/openai.ts +10 -0
- package/src/database/repositories/dataExporter/index.test.ts +330 -0
- package/src/database/repositories/dataExporter/index.ts +216 -0
- package/src/database/repositories/dataImporter/__tests__/fixtures/agents.json +65 -0
- package/src/database/repositories/dataImporter/__tests__/fixtures/agentsToSessions.json +541 -0
- package/src/database/repositories/dataImporter/__tests__/fixtures/topic.json +269 -0
- package/src/database/repositories/dataImporter/__tests__/fixtures/userSettings.json +18 -0
- package/src/database/repositories/dataImporter/__tests__/fixtures/with-client-id.json +778 -0
- package/src/database/repositories/dataImporter/__tests__/index.test.ts +120 -880
- package/src/database/repositories/dataImporter/deprecated/__tests__/index.test.ts +940 -0
- package/src/database/repositories/dataImporter/deprecated/index.ts +326 -0
- package/src/database/repositories/dataImporter/index.ts +684 -289
- package/src/features/DataImporter/ImportDetail.tsx +203 -0
- package/src/features/DataImporter/SuccessResult.tsx +22 -6
- package/src/features/DataImporter/_deprecated.ts +43 -0
- package/src/features/DataImporter/config.ts +21 -0
- package/src/features/DataImporter/index.tsx +112 -31
- package/src/features/DevPanel/PostgresViewer/DataTable/index.tsx +6 -0
- package/src/features/User/UserPanel/useMenu.tsx +0 -35
- package/src/features/User/__tests__/useMenu.test.tsx +0 -2
- package/src/locales/default/common.ts +11 -0
- package/src/locales/default/error.ts +10 -0
- package/src/locales/default/setting.ts +28 -0
- package/src/server/routers/lambda/exporter.ts +25 -0
- package/src/server/routers/lambda/importer.ts +19 -3
- package/src/server/routers/lambda/index.ts +2 -0
- package/src/services/config.ts +80 -135
- package/src/services/export/_deprecated.ts +155 -0
- package/src/services/export/client.ts +15 -0
- package/src/services/export/index.ts +6 -0
- package/src/services/export/server.ts +9 -0
- package/src/services/export/type.ts +5 -0
- package/src/services/import/_deprecated.ts +42 -1
- package/src/services/import/client.test.ts +1 -1
- package/src/services/import/client.ts +30 -1
- package/src/services/import/server.ts +70 -2
- package/src/services/import/type.ts +10 -0
- package/src/store/global/initialState.ts +1 -0
- package/src/types/export.ts +11 -0
- package/src/types/exportConfig.ts +2 -0
- package/src/types/importer.ts +15 -0
- package/src/types/user/settings/tts.ts +1 -1
- package/src/utils/client/exportFile.ts +21 -0
- package/vitest.config.ts +1 -1
- package/src/utils/config.ts +0 -109
- /package/src/database/repositories/dataImporter/{__tests__ → deprecated/__tests__}/fixtures/messages.json +0 -0
|
@@ -23,7 +23,36 @@ export class ClientService extends BaseClientService implements IImportService {
|
|
|
23
23
|
const duration = Date.now() - time;
|
|
24
24
|
|
|
25
25
|
callbacks?.onStageChange?.(ImportStage.Success);
|
|
26
|
-
callbacks?.onSuccess?.(result, duration);
|
|
26
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
callbacks?.onStageChange?.(ImportStage.Error);
|
|
30
|
+
const error = e as Error;
|
|
31
|
+
|
|
32
|
+
callbacks?.onError?.({ code: 'ImportError', httpStatus: 0, message: error.message });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
importPgData: IImportService['importPgData'] = async (
|
|
37
|
+
data,
|
|
38
|
+
{ callbacks, overwriteExisting } = {},
|
|
39
|
+
) => {
|
|
40
|
+
callbacks?.onStageChange?.(ImportStage.Importing);
|
|
41
|
+
const time = Date.now();
|
|
42
|
+
try {
|
|
43
|
+
const result = await this.dataImporter.importPgData(
|
|
44
|
+
data,
|
|
45
|
+
overwriteExisting ? 'override' : 'skip',
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const duration = Date.now() - time;
|
|
49
|
+
|
|
50
|
+
callbacks?.onStageChange?.(ImportStage.Success);
|
|
51
|
+
if (result.success) {
|
|
52
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
53
|
+
} else {
|
|
54
|
+
callbacks?.onError?.({ code: 'ImportError', httpStatus: 0, message: result.error.message });
|
|
55
|
+
}
|
|
27
56
|
} catch (e) {
|
|
28
57
|
console.error(e);
|
|
29
58
|
callbacks?.onStageChange?.(ImportStage.Error);
|
|
@@ -2,6 +2,7 @@ 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 { ImportPgDataStructure } from '@/types/export';
|
|
5
6
|
import { ImportStage, OnImportCallbacks } from '@/types/importer';
|
|
6
7
|
import { uuid } from '@/utils/uuid';
|
|
7
8
|
|
|
@@ -39,7 +40,7 @@ export class ServerService implements IImportService {
|
|
|
39
40
|
const duration = Date.now() - time;
|
|
40
41
|
|
|
41
42
|
callbacks?.onStageChange?.(ImportStage.Success);
|
|
42
|
-
callbacks?.onSuccess?.(result, duration);
|
|
43
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
43
44
|
} catch (e) {
|
|
44
45
|
handleError(e);
|
|
45
46
|
}
|
|
@@ -67,7 +68,74 @@ export class ServerService implements IImportService {
|
|
|
67
68
|
const result = await lambdaClient.importer.importByFile.mutate({ pathname });
|
|
68
69
|
const duration = Date.now() - time;
|
|
69
70
|
callbacks?.onStageChange?.(ImportStage.Success);
|
|
70
|
-
callbacks?.onSuccess?.(result, duration);
|
|
71
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
handleError(e);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
importPgData: IImportService['importPgData'] = async (
|
|
78
|
+
data: ImportPgDataStructure,
|
|
79
|
+
{
|
|
80
|
+
callbacks,
|
|
81
|
+
}: {
|
|
82
|
+
callbacks?: OnImportCallbacks;
|
|
83
|
+
overwriteExisting?: boolean;
|
|
84
|
+
} = {},
|
|
85
|
+
): Promise<void> => {
|
|
86
|
+
const handleError = (e: unknown) => {
|
|
87
|
+
callbacks?.onStageChange?.(ImportStage.Error);
|
|
88
|
+
const error = e as DefaultErrorShape;
|
|
89
|
+
|
|
90
|
+
callbacks?.onError?.({
|
|
91
|
+
code: error.data.code,
|
|
92
|
+
httpStatus: error.data.httpStatus,
|
|
93
|
+
message: error.message,
|
|
94
|
+
path: error.data.path,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const totalLength = Object.values(data.data)
|
|
99
|
+
.map((d) => d.length)
|
|
100
|
+
.reduce((a, b) => a + b, 0);
|
|
101
|
+
|
|
102
|
+
if (totalLength < 500) {
|
|
103
|
+
callbacks?.onStageChange?.(ImportStage.Importing);
|
|
104
|
+
const time = Date.now();
|
|
105
|
+
try {
|
|
106
|
+
const result = await lambdaClient.importer.importPgByPost.mutate(data);
|
|
107
|
+
const duration = Date.now() - time;
|
|
108
|
+
|
|
109
|
+
callbacks?.onStageChange?.(ImportStage.Success);
|
|
110
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
handleError(e);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// if the data is too large, upload it to S3 and upload by file
|
|
119
|
+
const filename = `${uuid()}.json`;
|
|
120
|
+
|
|
121
|
+
const pathname = `import_config/${filename}`;
|
|
122
|
+
|
|
123
|
+
const url = await edgeClient.upload.createS3PreSignedUrl.mutate({ pathname });
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
callbacks?.onStageChange?.(ImportStage.Uploading);
|
|
127
|
+
await this.uploadWithProgress(url, data, callbacks?.onFileUploading);
|
|
128
|
+
} catch {
|
|
129
|
+
throw new Error('Upload Error');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
callbacks?.onStageChange?.(ImportStage.Importing);
|
|
133
|
+
const time = Date.now();
|
|
134
|
+
try {
|
|
135
|
+
const result = await lambdaClient.importer.importByFile.mutate({ pathname });
|
|
136
|
+
const duration = Date.now() - time;
|
|
137
|
+
callbacks?.onStageChange?.(ImportStage.Success);
|
|
138
|
+
callbacks?.onSuccess?.(result.results, duration);
|
|
71
139
|
} catch (e) {
|
|
72
140
|
handleError(e);
|
|
73
141
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { ImportPgDataStructure } from '@/types/export';
|
|
1
2
|
import { ImporterEntryData, OnImportCallbacks } from '@/types/importer';
|
|
2
3
|
import { UserSettings } from '@/types/user/settings';
|
|
3
4
|
|
|
4
5
|
export interface IImportService {
|
|
5
6
|
importData(data: ImporterEntryData, callbacks?: OnImportCallbacks): Promise<void>;
|
|
7
|
+
|
|
8
|
+
importPgData(
|
|
9
|
+
data: ImportPgDataStructure,
|
|
10
|
+
options?: {
|
|
11
|
+
callbacks?: OnImportCallbacks;
|
|
12
|
+
overwriteExisting?: boolean;
|
|
13
|
+
},
|
|
14
|
+
): Promise<void>;
|
|
15
|
+
|
|
6
16
|
importSettings(settings: UserSettings): Promise<void>;
|
|
7
17
|
}
|
|
@@ -3,6 +3,8 @@ import { LobeSessions, SessionGroupItem } from '@/types/session';
|
|
|
3
3
|
import { ChatTopic } from '@/types/topic';
|
|
4
4
|
import { UserSettings } from '@/types/user/settings';
|
|
5
5
|
|
|
6
|
+
// ---------- TODO: this file need to be deleted in V2 ---------- //
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* 导出方式
|
|
8
10
|
* @enum ['agents', 'sessions', 'singleSession', 'settings', 'all']
|
package/src/types/importer.ts
CHANGED
|
@@ -146,3 +146,18 @@ export interface OnImportCallbacks {
|
|
|
146
146
|
*/
|
|
147
147
|
onSuccess?: (results: ImportResults, duration: number) => void;
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
// ------
|
|
151
|
+
|
|
152
|
+
export type ImportResultData = ImportSuccessResult | ImportErrorResult;
|
|
153
|
+
|
|
154
|
+
export interface ImportSuccessResult {
|
|
155
|
+
results: Record<string, any>;
|
|
156
|
+
success: true;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ImportErrorResult {
|
|
160
|
+
error: { details?: string; message: string };
|
|
161
|
+
results: Record<string, any>;
|
|
162
|
+
success: false;
|
|
163
|
+
}
|
|
@@ -18,3 +18,24 @@ export const exportFile = (content: string, filename?: string) => {
|
|
|
18
18
|
URL.revokeObjectURL(url);
|
|
19
19
|
a.remove();
|
|
20
20
|
};
|
|
21
|
+
|
|
22
|
+
export const exportJSONFile = (data: object, fileName: string) => {
|
|
23
|
+
// 创建一个 Blob 对象
|
|
24
|
+
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
|
|
25
|
+
|
|
26
|
+
// 创建一个 URL 对象,用于下载
|
|
27
|
+
const url = URL.createObjectURL(blob);
|
|
28
|
+
|
|
29
|
+
// 创建一个 <a> 元素,设置下载链接和文件名
|
|
30
|
+
const a = document.createElement('a');
|
|
31
|
+
a.href = url;
|
|
32
|
+
a.download = fileName;
|
|
33
|
+
|
|
34
|
+
// 触发 <a> 元素的点击事件,开始下载
|
|
35
|
+
document.body.append(a);
|
|
36
|
+
a.click();
|
|
37
|
+
|
|
38
|
+
// 下载完成后,清除 URL 对象
|
|
39
|
+
URL.revokeObjectURL(url);
|
|
40
|
+
a.remove();
|
|
41
|
+
};
|
package/vitest.config.ts
CHANGED
package/src/utils/config.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { notification } from '@/components/AntdStaticMethods';
|
|
2
|
-
import { BRANDING_NAME } from '@/const/branding';
|
|
3
|
-
import { CURRENT_CONFIG_VERSION, Migration } from '@/migrations';
|
|
4
|
-
import {
|
|
5
|
-
ConfigFile,
|
|
6
|
-
ConfigFileAgents,
|
|
7
|
-
ConfigFileAll,
|
|
8
|
-
ConfigFileSessions,
|
|
9
|
-
ConfigFileSettings,
|
|
10
|
-
ConfigFileSingleSession,
|
|
11
|
-
ConfigModelMap,
|
|
12
|
-
ExportType,
|
|
13
|
-
} from '@/types/exportConfig';
|
|
14
|
-
|
|
15
|
-
export const exportConfigFile = (config: object, fileName?: string) => {
|
|
16
|
-
const file = `${BRANDING_NAME}-${fileName || '-config'}-v${CURRENT_CONFIG_VERSION}.json`;
|
|
17
|
-
|
|
18
|
-
// 创建一个 Blob 对象
|
|
19
|
-
const blob = new Blob([JSON.stringify(config)], { type: 'application/json' });
|
|
20
|
-
|
|
21
|
-
// 创建一个 URL 对象,用于下载
|
|
22
|
-
const url = URL.createObjectURL(blob);
|
|
23
|
-
|
|
24
|
-
// 创建一个 <a> 元素,设置下载链接和文件名
|
|
25
|
-
const a = document.createElement('a');
|
|
26
|
-
a.href = url;
|
|
27
|
-
a.download = file;
|
|
28
|
-
|
|
29
|
-
// 触发 <a> 元素的点击事件,开始下载
|
|
30
|
-
document.body.append(a);
|
|
31
|
-
a.click();
|
|
32
|
-
|
|
33
|
-
// 下载完成后,清除 URL 对象
|
|
34
|
-
URL.revokeObjectURL(url);
|
|
35
|
-
a.remove();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const importConfigFile = async (
|
|
39
|
-
file: File,
|
|
40
|
-
onConfigImport: (config: ConfigFile) => Promise<void>,
|
|
41
|
-
) => {
|
|
42
|
-
const text = await file.text();
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const config = JSON.parse(text);
|
|
46
|
-
const { state, version } = Migration.migrate(config);
|
|
47
|
-
|
|
48
|
-
await onConfigImport({ ...config, state, version });
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error(error);
|
|
51
|
-
notification.error({
|
|
52
|
-
description: `出错原因: ${(error as Error).message}`,
|
|
53
|
-
message: '导入失败',
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
type CreateConfigFileState<T extends ExportType> = ConfigModelMap[T]['state'];
|
|
59
|
-
|
|
60
|
-
type CreateConfigFile<T extends ExportType> = ConfigModelMap[T]['file'];
|
|
61
|
-
|
|
62
|
-
export const createConfigFile = <T extends ExportType>(
|
|
63
|
-
type: T,
|
|
64
|
-
state: CreateConfigFileState<T>,
|
|
65
|
-
): CreateConfigFile<T> => {
|
|
66
|
-
switch (type) {
|
|
67
|
-
case 'agents': {
|
|
68
|
-
return {
|
|
69
|
-
exportType: 'agents',
|
|
70
|
-
state,
|
|
71
|
-
version: Migration.targetVersion,
|
|
72
|
-
} as ConfigFileAgents;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
case 'sessions': {
|
|
76
|
-
return {
|
|
77
|
-
exportType: 'sessions',
|
|
78
|
-
state,
|
|
79
|
-
version: Migration.targetVersion,
|
|
80
|
-
} as ConfigFileSessions;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
case 'settings': {
|
|
84
|
-
return {
|
|
85
|
-
exportType: 'settings',
|
|
86
|
-
state,
|
|
87
|
-
version: Migration.targetVersion,
|
|
88
|
-
} as ConfigFileSettings;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
case 'singleSession': {
|
|
92
|
-
return {
|
|
93
|
-
exportType: 'sessions',
|
|
94
|
-
state,
|
|
95
|
-
version: Migration.targetVersion,
|
|
96
|
-
} as ConfigFileSingleSession;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
case 'all': {
|
|
100
|
-
return {
|
|
101
|
-
exportType: 'all',
|
|
102
|
-
state,
|
|
103
|
-
version: Migration.targetVersion,
|
|
104
|
-
} as ConfigFileAll;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
throw new Error('缺少正确的导出类型,请检查实现...');
|
|
109
|
-
};
|
|
File without changes
|