@lobehub/chat 0.162.12 → 0.162.13

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 (37) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +8 -8
  3. package/README.zh-CN.md +8 -8
  4. package/locales/ar/common.json +11 -1
  5. package/locales/bg-BG/common.json +11 -1
  6. package/locales/de-DE/common.json +11 -1
  7. package/locales/en-US/common.json +11 -1
  8. package/locales/es-ES/common.json +11 -1
  9. package/locales/fr-FR/common.json +11 -1
  10. package/locales/it-IT/common.json +11 -1
  11. package/locales/ja-JP/common.json +11 -1
  12. package/locales/ko-KR/common.json +11 -1
  13. package/locales/nl-NL/common.json +11 -1
  14. package/locales/pl-PL/common.json +11 -1
  15. package/locales/pt-BR/common.json +11 -1
  16. package/locales/ru-RU/common.json +11 -1
  17. package/locales/tr-TR/common.json +11 -1
  18. package/locales/vi-VN/common.json +11 -1
  19. package/locales/zh-CN/common.json +11 -1
  20. package/locales/zh-TW/common.json +11 -1
  21. package/package.json +1 -1
  22. package/src/features/Conversation/Error/OllamaBizError/InvalidOllamaModel/useDownloadMonitor.ts +2 -10
  23. package/src/features/DataImporter/Error.tsx +65 -0
  24. package/src/features/DataImporter/FileUploading.tsx +50 -0
  25. package/src/features/DataImporter/Loading.tsx +125 -0
  26. package/src/features/DataImporter/SuccessResult.tsx +61 -0
  27. package/src/features/DataImporter/index.tsx +127 -208
  28. package/src/features/DataImporter/style.ts +17 -0
  29. package/src/hooks/useDownloadSpeed.ts +50 -0
  30. package/src/locales/default/common.ts +10 -0
  31. package/src/services/config.ts +15 -11
  32. package/src/services/github.ts +17 -0
  33. package/src/services/import/client.ts +18 -6
  34. package/src/types/importer.ts +128 -0
  35. package/src/utils/config.ts +18 -15
  36. package/src/utils/speed.ts +32 -0
  37. package/src/features/DataImporter/useImportConfig.ts +0 -27
@@ -0,0 +1,128 @@
1
+ import { LobeAgentConfig } from '@/types/agent';
2
+ import {
3
+ ChatMessageError,
4
+ ChatPluginPayload,
5
+ ChatTTS,
6
+ ChatToolPayload,
7
+ ChatTranslate,
8
+ MessageRoleType,
9
+ } from '@/types/message';
10
+ import { MetaData } from '@/types/meta';
11
+ import { SessionGroupId, SessionGroupItem } from '@/types/session';
12
+ import { ChatTopic } from '@/types/topic';
13
+
14
+ interface ImportSession {
15
+ config: LobeAgentConfig;
16
+ createdAt: string;
17
+ group?: SessionGroupId;
18
+ id: string;
19
+ meta: MetaData;
20
+ pinned?: boolean;
21
+ type: 'agent' | 'group';
22
+ updatedAt: string;
23
+ }
24
+
25
+ interface ImportMessage {
26
+ content: string;
27
+ createdAt: number;
28
+ error?: ChatMessageError;
29
+
30
+ // 扩展字段
31
+ extra?: {
32
+ fromModel?: string;
33
+ fromProvider?: string;
34
+ // 翻译
35
+ translate?: ChatTranslate | false | null;
36
+ // TTS
37
+ tts?: ChatTTS;
38
+ } & Record<string, any>;
39
+ files?: string[];
40
+ id: string;
41
+
42
+ /**
43
+ * observation id
44
+ */
45
+ observationId?: string;
46
+
47
+ /**
48
+ * parent message id
49
+ */
50
+ parentId?: string;
51
+ plugin?: ChatPluginPayload;
52
+ pluginState?: any;
53
+
54
+ quotaId?: string;
55
+ role: MessageRoleType;
56
+
57
+ sessionId?: string;
58
+ tool_call_id?: string;
59
+ tools?: ChatToolPayload[];
60
+
61
+ topicId?: string;
62
+ traceId?: string;
63
+
64
+ updatedAt: number;
65
+ }
66
+
67
+ export interface ImporterEntryData {
68
+ messages?: ImportMessage[];
69
+ sessionGroups?: SessionGroupItem[];
70
+ sessions?: ImportSession[];
71
+ topics?: ChatTopic[];
72
+ version: number;
73
+ }
74
+
75
+ export interface ImportResult {
76
+ added: number;
77
+ errors: number;
78
+ skips: number;
79
+ }
80
+
81
+ export interface ImportResults {
82
+ messages?: ImportResult;
83
+ sessionGroups?: ImportResult;
84
+ sessions?: ImportResult;
85
+ topics?: ImportResult;
86
+ type?: string;
87
+ }
88
+
89
+ export enum ImportStage {
90
+ Start,
91
+ Preparing,
92
+ Uploading,
93
+ Importing,
94
+ Success,
95
+ Error,
96
+ Finished,
97
+ }
98
+
99
+ export interface FileUploadState {
100
+ progress: number;
101
+ /**
102
+ * rest time in ms
103
+ */
104
+ restTime: number;
105
+ /**
106
+ * upload speed in KB/s
107
+ */
108
+ speed: number;
109
+ }
110
+
111
+ export interface ErrorShape {
112
+ code: string;
113
+ httpStatus: number;
114
+ message: string;
115
+ path?: string;
116
+ }
117
+
118
+ export interface OnImportCallbacks {
119
+ onError?: (error: ErrorShape) => void;
120
+ onFileUploading?: (state: FileUploadState) => void;
121
+ onStageChange?: (stage: ImportStage) => void;
122
+ /**
123
+ *
124
+ * @param results
125
+ * @param duration in ms
126
+ */
127
+ onSuccess?: (results: ImportResults, duration: number) => void;
128
+ }
@@ -34,21 +34,24 @@ export const exportConfigFile = (config: object, fileName?: string) => {
34
34
  a.remove();
35
35
  };
36
36
 
37
- export const importConfigFile = (file: File, onConfigImport: (config: ConfigFile) => void) => {
38
- file.text().then((text) => {
39
- try {
40
- const config = JSON.parse(text);
41
- const { state } = Migration.migrate(config);
42
-
43
- onConfigImport({ ...config, state });
44
- } catch (error) {
45
- console.error(error);
46
- notification.error({
47
- description: `出错原因: ${(error as Error).message}`,
48
- message: '导入失败',
49
- });
50
- }
51
- });
37
+ export const importConfigFile = async (
38
+ file: File,
39
+ onConfigImport: (config: ConfigFile) => Promise<void>,
40
+ ) => {
41
+ const text = await file.text();
42
+
43
+ try {
44
+ const config = JSON.parse(text);
45
+ const { state, version } = Migration.migrate(config);
46
+
47
+ await onConfigImport({ ...config, state, version });
48
+ } catch (error) {
49
+ console.error(error);
50
+ notification.error({
51
+ description: `出错原因: ${(error as Error).message}`,
52
+ message: '导入失败',
53
+ });
54
+ }
52
55
  };
53
56
 
54
57
  type CreateConfigFileState<T extends ExportType> = ConfigModelMap[T]['state'];
@@ -0,0 +1,32 @@
1
+ /**
2
+ * format speed from KB number to string like KB/s, MB/s or GB/s
3
+ * @param speed
4
+ */
5
+ export const formatSpeed = (speed: number) => {
6
+ let word = '';
7
+
8
+ // KB
9
+ if (speed <= 1000) {
10
+ word = speed.toFixed(2) + 'KB/s';
11
+ }
12
+ // MB
13
+ else if (speed / 1024 <= 1000) {
14
+ word = (speed / 1024).toFixed(2) + 'MB/s';
15
+ }
16
+ // GB
17
+ else {
18
+ word = (speed / 1024 / 1024).toFixed(2) + 'GB/s';
19
+ }
20
+
21
+ return word;
22
+ };
23
+
24
+ export const formatTime = (timeInSeconds: number): string => {
25
+ if (timeInSeconds < 60) {
26
+ return `${timeInSeconds.toFixed(1)} s`;
27
+ } else if (timeInSeconds < 3600) {
28
+ return `${(timeInSeconds / 60).toFixed(1)} min`;
29
+ } else {
30
+ return `${(timeInSeconds / 3600).toFixed(2)} h`;
31
+ }
32
+ };
@@ -1,27 +0,0 @@
1
- import { useCallback } from 'react';
2
-
3
- import { ImportResults, configService } from '@/services/config';
4
- import { useChatStore } from '@/store/chat';
5
- import { useSessionStore } from '@/store/session';
6
- import { importConfigFile } from '@/utils/config';
7
-
8
- export const useImportConfig = () => {
9
- const refreshSessions = useSessionStore((s) => s.refreshSessions);
10
- const [refreshMessages, refreshTopics] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]);
11
-
12
- return useCallback(
13
- async (file: File) =>
14
- new Promise<ImportResults | undefined>((resolve) => {
15
- importConfigFile(file, async (config) => {
16
- const data = await configService.importConfigState(config);
17
-
18
- await refreshSessions();
19
- await refreshMessages();
20
- await refreshTopics();
21
-
22
- resolve(data);
23
- });
24
- }),
25
- [],
26
- );
27
- };