@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
@@ -4,14 +4,14 @@ import { TopicModel } from '@/database/server/models/topic';
|
|
4
4
|
import { BaseClientService } from '@/services/baseClientService';
|
5
5
|
import { ChatTopic } from '@/types/topic';
|
6
6
|
|
7
|
-
import {
|
7
|
+
import { ITopicService } from './type';
|
8
8
|
|
9
9
|
export class ClientService extends BaseClientService implements ITopicService {
|
10
10
|
private get topicModel(): TopicModel {
|
11
11
|
return new TopicModel(clientDB as any, this.userId);
|
12
12
|
}
|
13
13
|
|
14
|
-
async
|
14
|
+
createTopic: ITopicService['createTopic'] = async (params) => {
|
15
15
|
const item = await this.topicModel.create({
|
16
16
|
...params,
|
17
17
|
sessionId: this.toDbSessionId(params.sessionId),
|
@@ -22,62 +22,62 @@ export class ClientService extends BaseClientService implements ITopicService {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
return item.id;
|
25
|
-
}
|
25
|
+
};
|
26
26
|
|
27
|
-
|
27
|
+
batchCreateTopics: ITopicService['batchCreateTopics'] = async (importTopics) => {
|
28
28
|
const data = await this.topicModel.batchCreate(importTopics as any);
|
29
29
|
|
30
30
|
return { added: data.length, ids: [], skips: [], success: true };
|
31
|
-
}
|
31
|
+
};
|
32
32
|
|
33
|
-
async
|
33
|
+
cloneTopic: ITopicService['cloneTopic'] = async (id, newTitle) => {
|
34
34
|
const data = await this.topicModel.duplicate(id, newTitle);
|
35
35
|
return data.topic.id;
|
36
|
-
}
|
36
|
+
};
|
37
37
|
|
38
|
-
async
|
38
|
+
getTopics: ITopicService['getTopics'] = async (params) => {
|
39
39
|
const data = await this.topicModel.query({
|
40
40
|
...params,
|
41
41
|
sessionId: this.toDbSessionId(params.sessionId),
|
42
42
|
});
|
43
43
|
return data as unknown as Promise<ChatTopic[]>;
|
44
|
-
}
|
44
|
+
};
|
45
45
|
|
46
|
-
async
|
46
|
+
searchTopics: ITopicService['searchTopics'] = async (keyword, sessionId) => {
|
47
47
|
const data = await this.topicModel.queryByKeyword(keyword, this.toDbSessionId(sessionId));
|
48
48
|
|
49
49
|
return data as unknown as Promise<ChatTopic[]>;
|
50
|
-
}
|
50
|
+
};
|
51
51
|
|
52
|
-
async
|
52
|
+
getAllTopics: ITopicService['getAllTopics'] = async () => {
|
53
53
|
const data = await this.topicModel.queryAll();
|
54
54
|
|
55
55
|
return data as unknown as Promise<ChatTopic[]>;
|
56
|
-
}
|
56
|
+
};
|
57
57
|
|
58
|
-
async
|
58
|
+
countTopics: ITopicService['countTopics'] = async () => {
|
59
59
|
return this.topicModel.count();
|
60
|
-
}
|
60
|
+
};
|
61
61
|
|
62
|
-
async
|
62
|
+
updateTopic: ITopicService['updateTopic'] = async (id, data) => {
|
63
63
|
return this.topicModel.update(id, data as any);
|
64
|
-
}
|
64
|
+
};
|
65
65
|
|
66
|
-
async
|
66
|
+
removeTopic: ITopicService['removeTopic'] = async (id) => {
|
67
67
|
return this.topicModel.delete(id);
|
68
|
-
}
|
68
|
+
};
|
69
69
|
|
70
|
-
async
|
70
|
+
removeTopics: ITopicService['removeTopics'] = async (sessionId) => {
|
71
71
|
return this.topicModel.batchDeleteBySessionId(this.toDbSessionId(sessionId));
|
72
|
-
}
|
72
|
+
};
|
73
73
|
|
74
|
-
|
74
|
+
batchRemoveTopics: ITopicService['batchRemoveTopics'] = async (topics) => {
|
75
75
|
return this.topicModel.batchDelete(topics);
|
76
|
-
}
|
76
|
+
};
|
77
77
|
|
78
|
-
async
|
78
|
+
removeAllTopic: ITopicService['removeAllTopic'] = async () => {
|
79
79
|
return this.topicModel.deleteAll();
|
80
|
-
}
|
80
|
+
};
|
81
81
|
|
82
82
|
private toDbSessionId(sessionId?: string | null) {
|
83
83
|
return sessionId === INBOX_SESSION_ID ? null : sessionId;
|
@@ -1,68 +1,51 @@
|
|
1
1
|
import { INBOX_SESSION_ID } from '@/const/session';
|
2
2
|
import { lambdaClient } from '@/libs/trpc/client';
|
3
|
-
import {
|
4
|
-
import { BatchTaskResult } from '@/types/service';
|
5
|
-
import { ChatTopic } from '@/types/topic';
|
3
|
+
import { ITopicService } from '@/services/topic/type';
|
6
4
|
|
7
5
|
export class ServerService implements ITopicService {
|
8
|
-
createTopic(params
|
9
|
-
|
6
|
+
createTopic: ITopicService['createTopic'] = (params) =>
|
7
|
+
lambdaClient.topic.createTopic.mutate({
|
10
8
|
...params,
|
11
9
|
sessionId: this.toDbSessionId(params.sessionId),
|
12
10
|
});
|
13
|
-
}
|
14
11
|
|
15
|
-
batchCreateTopics
|
16
|
-
|
17
|
-
}
|
12
|
+
batchCreateTopics: ITopicService['batchCreateTopics'] = (importTopics) =>
|
13
|
+
lambdaClient.topic.batchCreateTopics.mutate(importTopics);
|
18
14
|
|
19
|
-
cloneTopic(id
|
20
|
-
|
21
|
-
}
|
15
|
+
cloneTopic: ITopicService['cloneTopic'] = (id, newTitle) =>
|
16
|
+
lambdaClient.topic.cloneTopic.mutate({ id, newTitle });
|
22
17
|
|
23
|
-
getTopics
|
24
|
-
|
18
|
+
getTopics: ITopicService['getTopics'] = (params) =>
|
19
|
+
lambdaClient.topic.getTopics.query({
|
25
20
|
...params,
|
26
21
|
sessionId: this.toDbSessionId(params.sessionId),
|
27
22
|
}) as any;
|
28
|
-
}
|
29
23
|
|
30
|
-
getAllTopics
|
31
|
-
|
32
|
-
}
|
24
|
+
getAllTopics: ITopicService['getAllTopics'] = () =>
|
25
|
+
lambdaClient.topic.getAllTopics.query() as any;
|
33
26
|
|
34
|
-
async countTopics()
|
35
|
-
return lambdaClient.topic.countTopics.query();
|
36
|
-
}
|
27
|
+
countTopics: ITopicService['countTopics'] = async () => lambdaClient.topic.countTopics.query();
|
37
28
|
|
38
|
-
searchTopics(keywords
|
39
|
-
|
29
|
+
searchTopics: ITopicService['searchTopics'] = (keywords, sessionId) =>
|
30
|
+
lambdaClient.topic.searchTopics.query({
|
40
31
|
keywords,
|
41
32
|
sessionId: this.toDbSessionId(sessionId),
|
42
33
|
}) as any;
|
43
|
-
}
|
44
34
|
|
45
|
-
updateTopic(id
|
46
|
-
|
47
|
-
}
|
35
|
+
updateTopic: ITopicService['updateTopic'] = (id, data) =>
|
36
|
+
lambdaClient.topic.updateTopic.mutate({ id, value: data });
|
48
37
|
|
49
|
-
removeTopic(id
|
50
|
-
return lambdaClient.topic.removeTopic.mutate({ id });
|
51
|
-
}
|
38
|
+
removeTopic: ITopicService['removeTopic'] = (id) => lambdaClient.topic.removeTopic.mutate({ id });
|
52
39
|
|
53
|
-
removeTopics(sessionId
|
54
|
-
|
55
|
-
}
|
40
|
+
removeTopics: ITopicService['removeTopics'] = (sessionId) =>
|
41
|
+
lambdaClient.topic.batchDeleteBySessionId.mutate({ id: this.toDbSessionId(sessionId) });
|
56
42
|
|
57
|
-
batchRemoveTopics
|
58
|
-
|
59
|
-
}
|
43
|
+
batchRemoveTopics: ITopicService['batchRemoveTopics'] = (topics) =>
|
44
|
+
lambdaClient.topic.batchDelete.mutate({ ids: topics });
|
60
45
|
|
61
|
-
removeAllTopic()
|
62
|
-
|
63
|
-
}
|
46
|
+
removeAllTopic: ITopicService['removeAllTopic'] = () =>
|
47
|
+
lambdaClient.topic.removeAllTopics.mutate();
|
64
48
|
|
65
|
-
private toDbSessionId(sessionId?: string | null)
|
66
|
-
|
67
|
-
}
|
49
|
+
private toDbSessionId = (sessionId?: string | null) =>
|
50
|
+
sessionId === INBOX_SESSION_ID ? null : sessionId;
|
68
51
|
}
|
package/src/services/trace.ts
CHANGED
@@ -4,7 +4,7 @@ import { preferenceSelectors } from '@/store/user/selectors';
|
|
4
4
|
import { TraceEventBasePayload, TraceEventPayloads } from '@/types/trace';
|
5
5
|
|
6
6
|
class TraceService {
|
7
|
-
private async
|
7
|
+
private request = async <T>(data: T) => {
|
8
8
|
try {
|
9
9
|
return fetch(API_ENDPOINTS.trace, {
|
10
10
|
body: JSON.stringify(data),
|
@@ -14,15 +14,15 @@ class TraceService {
|
|
14
14
|
} catch (e) {
|
15
15
|
console.error(e);
|
16
16
|
}
|
17
|
-
}
|
17
|
+
};
|
18
18
|
|
19
|
-
async
|
19
|
+
traceEvent = async (data: TraceEventPayloads & TraceEventBasePayload) => {
|
20
20
|
const enabled = preferenceSelectors.userAllowTrace(useUserStore.getState());
|
21
21
|
|
22
22
|
if (!enabled) return;
|
23
23
|
|
24
24
|
return this.request(data);
|
25
|
-
}
|
25
|
+
};
|
26
26
|
}
|
27
27
|
|
28
28
|
export const traceService = new TraceService();
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import { DeepPartial } from 'utility-types';
|
2
|
-
|
3
1
|
import { clientDB } from '@/database/client/db';
|
4
2
|
import { users } from '@/database/schemas';
|
5
3
|
import { MessageModel } from '@/database/server/models/message';
|
6
4
|
import { SessionModel } from '@/database/server/models/session';
|
7
5
|
import { UserModel } from '@/database/server/models/user';
|
8
6
|
import { BaseClientService } from '@/services/baseClientService';
|
9
|
-
import {
|
10
|
-
import { UserSettings } from '@/types/user/settings';
|
7
|
+
import { UserPreference } from '@/types/user';
|
11
8
|
import { AsyncLocalStorage } from '@/utils/localStorage';
|
12
9
|
|
13
10
|
import { IUserService } from './type';
|
@@ -30,7 +27,7 @@ export class ClientService extends BaseClientService implements IUserService {
|
|
30
27
|
this.preferenceStorage = new AsyncLocalStorage('LOBE_PREFERENCE');
|
31
28
|
}
|
32
29
|
|
33
|
-
async
|
30
|
+
getUserState: IUserService['getUserState'] = async () => {
|
34
31
|
// if user not exist in the db, create one to make sure the user exist
|
35
32
|
await this.makeSureUserExist();
|
36
33
|
|
@@ -51,32 +48,31 @@ export class ClientService extends BaseClientService implements IUserService {
|
|
51
48
|
isOnboard: true,
|
52
49
|
preference: await this.preferenceStorage.getFromLocalStorage(),
|
53
50
|
};
|
54
|
-
}
|
51
|
+
};
|
55
52
|
|
56
|
-
updateUserSettings = async (value
|
53
|
+
updateUserSettings: IUserService['updateUserSettings'] = async (value) => {
|
57
54
|
const { keyVaults, ...res } = value;
|
58
55
|
|
59
56
|
return this.userModel.updateSetting({ ...res, keyVaults: JSON.stringify(keyVaults) });
|
60
57
|
};
|
61
58
|
|
62
|
-
resetUserSettings = async () => {
|
59
|
+
resetUserSettings: IUserService['resetUserSettings'] = async () => {
|
63
60
|
return this.userModel.deleteSetting();
|
64
61
|
};
|
65
62
|
|
66
|
-
async
|
63
|
+
updateAvatar = async (avatar: string) => {
|
67
64
|
await this.userModel.updateUser({ avatar });
|
68
|
-
}
|
65
|
+
};
|
69
66
|
|
70
|
-
async
|
67
|
+
updatePreference: IUserService['updatePreference'] = async (preference) => {
|
71
68
|
await this.preferenceStorage.saveToLocalStorage(preference);
|
72
|
-
}
|
69
|
+
};
|
73
70
|
|
74
|
-
|
75
|
-
async updateGuide(guide: Partial<UserGuide>) {
|
71
|
+
updateGuide: IUserService['updateGuide'] = async () => {
|
76
72
|
throw new Error('Method not implemented.');
|
77
|
-
}
|
73
|
+
};
|
78
74
|
|
79
|
-
async
|
75
|
+
makeSureUserExist = async () => {
|
80
76
|
const existUsers = await clientDB.query.users.findMany();
|
81
77
|
|
82
78
|
let user: { id: string };
|
@@ -88,5 +84,5 @@ export class ClientService extends BaseClientService implements IUserService {
|
|
88
84
|
}
|
89
85
|
|
90
86
|
return user;
|
91
|
-
}
|
87
|
+
};
|
92
88
|
}
|
@@ -1,32 +1,28 @@
|
|
1
|
-
import { DeepPartial } from 'utility-types';
|
2
|
-
|
3
1
|
import { lambdaClient } from '@/libs/trpc/client';
|
4
2
|
import { IUserService } from '@/services/user/type';
|
5
|
-
import { UserGuide, UserInitializationState, UserPreference } from '@/types/user';
|
6
|
-
import { UserSettings } from '@/types/user/settings';
|
7
3
|
|
8
4
|
export class ServerService implements IUserService {
|
9
|
-
getUserState = async ()
|
5
|
+
getUserState: IUserService['getUserState'] = async () => {
|
10
6
|
return lambdaClient.user.getUserState.query();
|
11
7
|
};
|
12
8
|
|
13
|
-
async
|
9
|
+
makeUserOnboarded = async () => {
|
14
10
|
return lambdaClient.user.makeUserOnboarded.mutate();
|
15
|
-
}
|
11
|
+
};
|
16
12
|
|
17
|
-
async
|
13
|
+
updatePreference: IUserService['updatePreference'] = async (preference) => {
|
18
14
|
return lambdaClient.user.updatePreference.mutate(preference);
|
19
|
-
}
|
15
|
+
};
|
20
16
|
|
21
|
-
async
|
17
|
+
updateGuide: IUserService['updateGuide'] = async (guide) => {
|
22
18
|
return lambdaClient.user.updateGuide.mutate(guide);
|
23
|
-
}
|
19
|
+
};
|
24
20
|
|
25
|
-
updateUserSettings = async (value
|
21
|
+
updateUserSettings: IUserService['updateUserSettings'] = async (value, signal) => {
|
26
22
|
return lambdaClient.user.updateSettings.mutate(value, { signal });
|
27
23
|
};
|
28
24
|
|
29
|
-
resetUserSettings = async () => {
|
25
|
+
resetUserSettings: IUserService['resetUserSettings'] = async () => {
|
30
26
|
return lambdaClient.user.resetSettings.mutate();
|
31
27
|
};
|
32
28
|
}
|
@@ -8,5 +8,5 @@ export interface IUserService {
|
|
8
8
|
resetUserSettings: () => Promise<any>;
|
9
9
|
updateGuide: (guide: Partial<UserGuide>) => Promise<any>;
|
10
10
|
updatePreference: (preference: Partial<UserPreference>) => Promise<any>;
|
11
|
-
updateUserSettings: (
|
11
|
+
updateUserSettings: (value: DeepPartial<UserSettings>, signal?: AbortSignal) => Promise<any>;
|
12
12
|
}
|
@@ -3,6 +3,7 @@ import { produce } from 'immer';
|
|
3
3
|
|
4
4
|
import {
|
5
5
|
ChatMessage,
|
6
|
+
ChatMessageExtra,
|
6
7
|
ChatPluginPayload,
|
7
8
|
ChatToolPayload,
|
8
9
|
CreateMessageParams,
|
@@ -100,9 +101,9 @@ export const messagesReducer = (state: ChatMessage[], payload: MessageDispatch):
|
|
100
101
|
if (!message) return;
|
101
102
|
|
102
103
|
if (!message.extra) {
|
103
|
-
message.extra = { [key]: value } as
|
104
|
+
message.extra = { [key]: value } as ChatMessageExtra;
|
104
105
|
} else {
|
105
|
-
message.extra[key] = value;
|
106
|
+
message.extra[key as keyof ChatMessageExtra] = value;
|
106
107
|
}
|
107
108
|
|
108
109
|
message.updatedAt = Date.now();
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import isEqual from 'fast-deep-equal';
|
2
2
|
import { produce } from 'immer';
|
3
3
|
import { gt, parse, valid } from 'semver';
|
4
|
-
import
|
4
|
+
import { SWRResponse } from 'swr';
|
5
5
|
import type { StateCreator } from 'zustand/vanilla';
|
6
6
|
|
7
7
|
import { INBOX_SESSION_ID } from '@/const/session';
|
@@ -42,6 +42,7 @@ export const globalActionSlice: StateCreator<
|
|
42
42
|
switchBackToChat: (sessionId) => {
|
43
43
|
get().router?.push(SESSION_CHAT_URL(sessionId || INBOX_SESSION_ID, get().isMobile));
|
44
44
|
},
|
45
|
+
|
45
46
|
toggleChatSideBar: (newValue) => {
|
46
47
|
const showChatSideBar =
|
47
48
|
typeof newValue === 'boolean' ? newValue : !get().status.showChatSideBar;
|
@@ -97,28 +98,32 @@ export const globalActionSlice: StateCreator<
|
|
97
98
|
},
|
98
99
|
|
99
100
|
useCheckLatestVersion: (enabledCheck = true) =>
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
101
|
+
useOnlyFetchOnceSWR(
|
102
|
+
enabledCheck ? 'checkLatestVersion' : null,
|
103
|
+
async () => globalService.getLatestVersion(),
|
104
|
+
{
|
105
|
+
// check latest version every 30 minutes
|
106
|
+
focusThrottleInterval: 1000 * 60 * 30,
|
107
|
+
onSuccess: (data: string) => {
|
108
|
+
if (!valid(CURRENT_VERSION) || !valid(data)) return;
|
109
|
+
|
110
|
+
// Parse versions to ensure we're working with valid SemVer objects
|
111
|
+
const currentVersion = parse(CURRENT_VERSION);
|
112
|
+
const latestVersion = parse(data);
|
113
|
+
|
114
|
+
if (!currentVersion || !latestVersion) return;
|
115
|
+
|
116
|
+
// only compare major and minor versions
|
117
|
+
// solve the problem of frequent patch updates
|
118
|
+
const currentMajorMinor = `${currentVersion.major}.${currentVersion.minor}.0`;
|
119
|
+
const latestMajorMinor = `${latestVersion.major}.${latestVersion.minor}.0`;
|
120
|
+
|
121
|
+
if (gt(latestMajorMinor, currentMajorMinor)) {
|
122
|
+
set({ hasNewVersion: true, latestVersion: data }, false, n('checkLatestVersion'));
|
123
|
+
}
|
124
|
+
},
|
120
125
|
},
|
121
|
-
|
126
|
+
),
|
122
127
|
|
123
128
|
useInitSystemStatus: () =>
|
124
129
|
useOnlyFetchOnceSWR<SystemStatus>(
|
@@ -56,20 +56,22 @@ export interface ChatFileChunk {
|
|
56
56
|
text: string;
|
57
57
|
}
|
58
58
|
|
59
|
+
export interface ChatMessageExtra {
|
60
|
+
fromModel?: string;
|
61
|
+
fromProvider?: string;
|
62
|
+
// 翻译
|
63
|
+
translate?: ChatTranslate | false | null;
|
64
|
+
// TTS
|
65
|
+
tts?: ChatTTS;
|
66
|
+
}
|
67
|
+
|
59
68
|
export interface ChatMessage extends BaseDataModel {
|
60
69
|
chunksList?: ChatFileChunk[];
|
61
70
|
content: string;
|
62
71
|
error?: ChatMessageError | null;
|
63
72
|
|
64
73
|
// 扩展字段
|
65
|
-
extra?:
|
66
|
-
fromModel?: string;
|
67
|
-
fromProvider?: string;
|
68
|
-
// 翻译
|
69
|
-
translate?: ChatTranslate | false | null;
|
70
|
-
// TTS
|
71
|
-
tts?: ChatTTS;
|
72
|
-
} & Record<string, any>;
|
74
|
+
extra?: ChatMessageExtra;
|
73
75
|
fileList?: ChatFileItem[];
|
74
76
|
/**
|
75
77
|
* this is a deprecated field, only use in client db
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { PropsWithChildren, createContext, memo } from 'react';
|
2
|
-
|
3
|
-
export const InterceptContext = createContext(false);
|
4
|
-
|
5
|
-
const InterceptingLayout = memo<PropsWithChildren>(({ children }) => {
|
6
|
-
return <InterceptContext.Provider value={true}>{children}</InterceptContext.Provider>;
|
7
|
-
});
|
8
|
-
|
9
|
-
export default InterceptingLayout;
|