@lobehub/chat 0.106.0 → 0.107.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 +25 -0
- package/locales/en_US/common.json +19 -0
- package/locales/en_US/migration.json +45 -0
- package/locales/en_US/setting.json +7 -7
- package/locales/ja_JP/common.json +19 -0
- package/locales/ja_JP/migration.json +45 -0
- package/locales/ja_JP/setting.json +2 -2
- package/locales/ko_KR/common.json +19 -0
- package/locales/ko_KR/migration.json +45 -0
- package/locales/ko_KR/setting.json +2 -2
- package/locales/ru_RU/common.json +19 -0
- package/locales/ru_RU/migration.json +45 -0
- package/locales/ru_RU/setting.json +2 -2
- package/locales/zh_CN/common.json +19 -0
- package/locales/zh_CN/migration.json +45 -0
- package/locales/zh_CN/setting.json +1 -1
- package/locales/zh_TW/common.json +19 -0
- package/locales/zh_TW/migration.json +45 -0
- package/locales/zh_TW/setting.json +2 -2
- package/package.json +2 -1
- package/src/app/api/openai/chat/createChatCompletion.test.ts +4 -4
- package/src/app/api/openai/chat/createChatCompletion.ts +4 -10
- package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
- package/src/app/api/openai/errorResponse.test.ts +1 -1
- package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +2 -1
- package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +2 -2
- package/src/app/chat/features/ChatHeader/ShareButton/Inner.tsx +2 -5
- package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/Clear.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +8 -2
- package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/STT/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/Topic/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/useSend.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/InvalidAccess.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.test.tsx +4 -4
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +30 -31
- package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Translate.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +8 -5
- package/src/app/chat/features/Conversation/ChatList/Extras/index.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Extras/type.ts +5 -0
- package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +10 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/Default.tsx +7 -3
- package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +7 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/index.ts +7 -7
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +6 -6
- package/src/app/chat/features/Conversation/ChatList/index.tsx +16 -24
- package/src/app/chat/features/Conversation/ScrollAnchor/index.tsx +2 -2
- package/src/app/chat/features/Conversation/index.tsx +3 -3
- package/src/app/chat/features/Conversation/useInitConversation.ts +43 -0
- package/src/app/chat/features/Migration/ExportConfigButton.tsx +33 -0
- package/src/app/chat/features/Migration/Failed.tsx +115 -0
- package/src/app/chat/features/Migration/Modal.tsx +80 -0
- package/src/app/chat/features/Migration/Start.tsx +106 -0
- package/src/app/chat/features/Migration/UpgradeButton.tsx +74 -0
- package/src/app/chat/features/Migration/const.ts +15 -0
- package/src/app/chat/features/Migration/index.tsx +44 -0
- package/src/app/chat/features/SessionListContent/DefaultMode.tsx +54 -0
- package/src/app/chat/features/SessionListContent/List/Item/Actions.tsx +5 -4
- package/src/app/chat/features/SessionListContent/List/Item/index.tsx +22 -28
- package/src/app/chat/features/SessionListContent/SearchMode.tsx +15 -0
- package/src/app/chat/features/SessionListContent/index.tsx +4 -44
- package/src/app/chat/features/SessionSearchBar/index.tsx +11 -3
- package/src/app/chat/features/TopicListContent/Header.tsx +4 -4
- package/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +11 -9
- package/src/app/chat/features/TopicListContent/Topic/TopicItem.tsx +15 -13
- package/src/app/chat/features/TopicListContent/Topic/index.tsx +9 -16
- package/src/app/chat/features/TopicListContent/TopicSearchBar/index.tsx +13 -4
- package/src/app/chat/features/TopicListContent/index.tsx +1 -2
- package/src/app/chat/page.tsx +6 -1
- package/src/app/chat/settings/features/HeaderContent.tsx +3 -3
- package/src/app/home/Redirect.tsx +13 -7
- package/src/app/settings/(mobile)/features/ExtraList.tsx +12 -4
- package/src/app/settings/common/Common.tsx +16 -4
- package/src/app/welcome/features/Banner/index.tsx +9 -10
- package/src/chains/summaryTitle.ts +5 -2
- package/src/components/DataStyleModal/index.tsx +64 -0
- package/src/config/client.ts +5 -0
- package/src/const/session.ts +21 -0
- package/src/const/settings.ts +1 -1
- package/src/database/core/__tests__/db.test.ts +8 -5
- package/src/database/core/__tests__/model.test.ts +3 -3
- package/src/database/core/db.ts +38 -10
- package/src/database/core/index.ts +1 -0
- package/src/database/core/model.ts +121 -10
- package/src/database/core/schemas.ts +22 -0
- package/src/database/core/types/db.ts +13 -0
- package/src/database/models/__DEBUG.ts +119 -0
- package/src/database/models/{file.test.ts → __tests__/file.test.ts} +19 -6
- package/src/database/models/__tests__/message.test.ts +314 -0
- package/src/database/models/__tests__/session.test.ts +117 -0
- package/src/database/models/__tests__/topic.test.ts +250 -0
- package/src/database/models/file.ts +9 -5
- package/src/database/models/message.ts +186 -0
- package/src/database/models/session.ts +160 -0
- package/src/database/models/topic.ts +196 -0
- package/src/{types/database → database/schemas}/files.ts +2 -2
- package/src/database/schemas/message.ts +37 -0
- package/src/database/schemas/session.ts +56 -0
- package/src/database/schemas/topic.ts +12 -0
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/store/action.ts +1 -1
- package/src/features/AgentSetting/store/initialState.ts +1 -1
- package/src/features/AgentSetting/store/reducers/config.ts +1 -1
- package/src/features/DataImporter/index.tsx +240 -0
- package/src/features/DebugUI/index.tsx +34 -0
- package/src/features/SideBar/BottomActions.tsx +8 -14
- package/src/hooks/useImportConfig.ts +13 -30
- package/src/hooks/useTTS.ts +1 -1
- package/src/layout/GlobalLayout/index.tsx +16 -1
- package/src/locales/default/common.ts +19 -0
- package/src/locales/default/migration.ts +47 -0
- package/src/locales/default/setting.ts +1 -1
- package/src/locales/resources/en_US.ts +2 -0
- package/src/locales/resources/ja_JP.ts +2 -0
- package/src/locales/resources/ko_KR.ts +2 -0
- package/src/locales/resources/ru_RU.ts +2 -0
- package/src/locales/resources/zh_CN.ts +2 -0
- package/src/locales/resources/zh_TW.ts +2 -0
- package/src/migrations/FromV0ToV1.ts +2 -4
- package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +191 -0
- package/src/migrations/FromV1ToV2/fixtures/output-v2.json +202 -0
- package/src/migrations/FromV1ToV2/index.ts +82 -0
- package/src/migrations/FromV1ToV2/migrations.test.ts +224 -0
- package/src/migrations/FromV1ToV2/types/v1.ts +78 -0
- package/src/migrations/FromV1ToV2/types/v2.ts +52 -0
- package/src/{utils → migrations}/VersionController.test.ts +1 -3
- package/src/{utils → migrations}/VersionController.ts +5 -2
- package/src/migrations/index.ts +17 -3
- package/src/services/__tests__/file.test.ts +3 -3
- package/src/services/chat.ts +66 -5
- package/src/services/config.ts +184 -0
- package/src/services/debug.ts +13 -0
- package/src/services/file.ts +6 -2
- package/src/services/github.ts +25 -0
- package/src/services/message.ts +79 -0
- package/src/services/session.ts +63 -0
- package/src/services/topic.ts +56 -0
- package/src/store/chat/actions/enhance.ts +95 -0
- package/src/store/{session/slices/chat → chat}/actions/message.ts +225 -247
- package/src/store/{session/slices/chat → chat}/actions/plugin.ts +29 -34
- package/src/store/{session/slices/chat → chat}/actions/share.ts +9 -13
- package/src/store/chat/actions/topic.ts +197 -0
- package/src/store/chat/helpers.ts +23 -0
- package/src/store/chat/index.ts +3 -0
- package/src/store/chat/initialState.ts +48 -0
- package/src/store/chat/reducers/message.test.ts +83 -0
- package/src/store/chat/reducers/message.ts +83 -0
- package/src/store/chat/selectors/__tests__/topic.test.ts +43 -0
- package/src/store/chat/selectors/chat.ts +119 -0
- package/src/store/chat/selectors/index.ts +2 -0
- package/src/store/chat/selectors/topic.ts +28 -0
- package/src/store/chat/store.ts +63 -0
- package/src/store/files/slices/images/action.ts +6 -4
- package/src/store/global/store.ts +1 -1
- package/src/store/middleware/createHyperStorage/index.ts +40 -24
- package/src/store/middleware/createHyperStorage/keyMapper.ts +8 -2
- package/src/store/middleware/createHyperStorage/type.ts +10 -8
- package/src/store/plugin/slices/plugin/action.ts +1 -1
- package/src/store/plugin/store.ts +2 -4
- package/src/store/session/helpers.ts +1 -1
- package/src/store/session/hooks/useSessionHydrated.ts +6 -10
- package/src/store/session/initialState.ts +26 -7
- package/src/store/session/selectors.ts +1 -2
- package/src/store/session/slices/agent/action.ts +26 -35
- package/src/store/session/slices/agent/selectors.ts +32 -37
- package/src/store/session/slices/session/action.ts +81 -88
- package/src/store/session/slices/session/helpers.ts +19 -0
- package/src/store/session/slices/session/initialState.ts +7 -10
- package/src/store/session/slices/session/selectors/export.ts +12 -9
- package/src/store/session/slices/session/selectors/index.ts +2 -35
- package/src/store/session/slices/session/selectors/list.test.ts +25 -203
- package/src/store/session/slices/session/selectors/list.ts +40 -78
- package/src/store/session/store.ts +11 -17
- package/src/types/agent/index.ts +61 -0
- package/src/types/chatMessage.ts +11 -20
- package/src/types/exportConfig.ts +7 -2
- package/src/types/files.ts +2 -2
- package/src/types/llm.ts +1 -1
- package/src/types/meta.ts +24 -12
- package/src/types/openai/chat.ts +9 -1
- package/src/types/openai/functionCall.ts +4 -0
- package/src/types/session.ts +10 -94
- package/src/types/translate.ts +2 -1
- package/src/utils/config.ts +5 -11
- package/src/utils/fetch.ts +8 -2
- package/src/app/chat/features/Conversation/usePluginsInit.ts +0 -14
- package/src/database/core/schema.ts +0 -9
- package/src/helpers/export.ts +0 -69
- package/src/hooks/useExportConfig.ts +0 -6
- package/src/store/session/slices/chat/actions/index.ts +0 -32
- package/src/store/session/slices/chat/actions/topic.ts +0 -171
- package/src/store/session/slices/chat/actions/translate.ts +0 -113
- package/src/store/session/slices/chat/helpers.ts +0 -9
- package/src/store/session/slices/chat/initialState.ts +0 -13
- package/src/store/session/slices/chat/reducers/message.test.ts +0 -319
- package/src/store/session/slices/chat/reducers/message.ts +0 -156
- package/src/store/session/slices/chat/reducers/topic.test.ts +0 -179
- package/src/store/session/slices/chat/reducers/topic.ts +0 -81
- package/src/store/session/slices/chat/selectors/chat.ts +0 -111
- package/src/store/session/slices/chat/selectors/index.ts +0 -26
- package/src/store/session/slices/chat/selectors/topic.ts +0 -30
- package/src/store/session/slices/chat/selectors/utils.test.ts +0 -385
- package/src/store/session/slices/chat/selectors/utils.ts +0 -91
- package/src/store/session/slices/chat/utils.ts +0 -13
- package/src/store/session/slices/session/reducers/session.test.ts +0 -577
- package/src/store/session/slices/session/reducers/session.ts +0 -182
- package/src/types/database/db.ts +0 -4
- /package/src/store/{session/slices/chat → chat}/reducers/files.test.ts +0 -0
- /package/src/store/{session/slices/chat → chat}/reducers/files.ts +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { OpenAIStream, StreamingTextResponse } from 'ai';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
|
|
4
|
-
import { createErrorResponse } from '@/app/api/openai/errorResponse';
|
|
5
4
|
import { ChatErrorType } from '@/types/fetch';
|
|
6
5
|
import { OpenAIChatStreamPayload } from '@/types/openai/chat';
|
|
7
6
|
|
|
7
|
+
import { createErrorResponse } from '../errorResponse';
|
|
8
|
+
|
|
8
9
|
interface CreateChatCompletionOptions {
|
|
9
10
|
openai: OpenAI;
|
|
10
11
|
payload: OpenAIChatStreamPayload;
|
|
@@ -14,22 +15,15 @@ export const createChatCompletion = async ({ payload, openai }: CreateChatComple
|
|
|
14
15
|
// ============ 1. preprocess messages ============ //
|
|
15
16
|
const { messages, ...params } = payload;
|
|
16
17
|
|
|
17
|
-
// remove unnecessary fields like `plugins` or `files` by lobe-chat
|
|
18
|
-
const formatMessages = messages.map((m) => ({
|
|
19
|
-
content: m.content,
|
|
20
|
-
name: m.name,
|
|
21
|
-
role: m.role,
|
|
22
|
-
})) as OpenAI.ChatCompletionMessageParam[];
|
|
23
|
-
|
|
24
18
|
// ============ 2. send api ============ //
|
|
25
19
|
|
|
26
20
|
try {
|
|
27
21
|
const response = await openai.chat.completions.create(
|
|
28
22
|
{
|
|
29
|
-
messages
|
|
23
|
+
messages,
|
|
30
24
|
...params,
|
|
31
25
|
stream: true,
|
|
32
|
-
},
|
|
26
|
+
} as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
|
|
33
27
|
{ headers: { Accept: '*/*' } },
|
|
34
28
|
);
|
|
35
29
|
const stream = OpenAIStream(response);
|
|
@@ -8,6 +8,7 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
8
8
|
|
|
9
9
|
import SaveTopic from '@/app/chat/features/ChatInput/Topic';
|
|
10
10
|
import { useSendMessage } from '@/app/chat/features/ChatInput/useSend';
|
|
11
|
+
import { useChatStore } from '@/store/chat';
|
|
11
12
|
import { useSessionStore } from '@/store/session';
|
|
12
13
|
import { agentSelectors } from '@/store/session/selectors';
|
|
13
14
|
|
|
@@ -16,7 +17,7 @@ import { LocalFiles } from './LocalFiles';
|
|
|
16
17
|
const Footer = memo(() => {
|
|
17
18
|
const { t } = useTranslation('chat');
|
|
18
19
|
const theme = useTheme();
|
|
19
|
-
const [loading, onStop] =
|
|
20
|
+
const [loading, onStop] = useChatStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
|
|
20
21
|
|
|
21
22
|
const onSend = useSendMessage();
|
|
22
23
|
const canUpload = useSessionStore(agentSelectors.modelHasVisionAbility);
|
|
@@ -4,10 +4,10 @@ import { Loader2, SendHorizonal } from 'lucide-react';
|
|
|
4
4
|
import { memo } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useSendMessage } from '@/app/chat/features/ChatInput/useSend';
|
|
7
|
-
import {
|
|
7
|
+
import { useChatStore } from '@/store/chat';
|
|
8
8
|
|
|
9
9
|
const SendButton = memo(() => {
|
|
10
|
-
const [loading, onStop] =
|
|
10
|
+
const [loading, onStop] = useChatStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
|
|
11
11
|
|
|
12
12
|
const handleSend = useSendMessage();
|
|
13
13
|
|
|
@@ -7,8 +7,8 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
7
7
|
|
|
8
8
|
import MobilePadding from '@/components/MobilePadding';
|
|
9
9
|
import { FORM_STYLE } from '@/const/layoutTokens';
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
10
11
|
import { useGlobalStore } from '@/store/global';
|
|
11
|
-
import { useSessionStore } from '@/store/session';
|
|
12
12
|
|
|
13
13
|
import Preview, { ImageType, imageTypeOptions } from './Preview';
|
|
14
14
|
|
|
@@ -27,10 +27,7 @@ const Inner = memo(() => {
|
|
|
27
27
|
const { t } = useTranslation('chat');
|
|
28
28
|
|
|
29
29
|
const avatar = useGlobalStore((s) => s.settings.avatar);
|
|
30
|
-
const [shareLoading, shareToShareGPT] =
|
|
31
|
-
s.shareLoading,
|
|
32
|
-
s.shareToShareGPT,
|
|
33
|
-
]);
|
|
30
|
+
const [shareLoading, shareToShareGPT] = useChatStore((s) => [s.shareLoading, s.shareToShareGPT]);
|
|
34
31
|
|
|
35
32
|
const options: SegmentedProps['options'] = useMemo(
|
|
36
33
|
() => [
|
|
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
6
6
|
import useMergeState from 'use-merge-value';
|
|
7
7
|
|
|
8
8
|
import { DESKTOP_HEADER_ICON_SIZE } from '@/const/layoutTokens';
|
|
9
|
-
import {
|
|
9
|
+
import { useChatStore } from '@/store/chat';
|
|
10
10
|
|
|
11
11
|
const Inner = dynamic(() => import('./Inner'));
|
|
12
12
|
interface ShareButtonProps {
|
|
@@ -22,7 +22,7 @@ const ShareButton = memo<ShareButtonProps>(({ mobile, setOpen, open }) => {
|
|
|
22
22
|
value: open,
|
|
23
23
|
});
|
|
24
24
|
const { t } = useTranslation('common');
|
|
25
|
-
const [shareLoading] =
|
|
25
|
+
const [shareLoading] = useChatStore((s) => [s.shareLoading]);
|
|
26
26
|
|
|
27
27
|
return (
|
|
28
28
|
<>
|
|
@@ -7,12 +7,12 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
|
|
8
8
|
import HotKeys from '@/components/HotKeys';
|
|
9
9
|
import { CLEAN_MESSAGE_KEY, PREFIX_KEY } from '@/const/hotkeys';
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
10
11
|
import { useFileStore } from '@/store/files';
|
|
11
|
-
import { useSessionStore } from '@/store/session';
|
|
12
12
|
|
|
13
13
|
const Clear = memo(() => {
|
|
14
14
|
const { t } = useTranslation('setting');
|
|
15
|
-
const [clearMessage] =
|
|
15
|
+
const [clearMessage] = useChatStore((s) => [s.clearMessage]);
|
|
16
16
|
const [clearImageList] = useFileStore((s) => [s.clearImageList]);
|
|
17
17
|
const hotkeys = [PREFIX_KEY, CLEAN_MESSAGE_KEY].join('+');
|
|
18
18
|
|
|
@@ -4,19 +4,25 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
|
|
5
5
|
import { ModelTokens } from '@/const/modelTokens';
|
|
6
6
|
import { useTokenCount } from '@/hooks/useTokenCount';
|
|
7
|
+
import { useChatStore } from '@/store/chat';
|
|
8
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
7
9
|
import { useSessionStore } from '@/store/session';
|
|
8
|
-
import { agentSelectors
|
|
10
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
9
11
|
import { LanguageModel } from '@/types/llm';
|
|
10
12
|
|
|
11
13
|
const Token = memo(() => {
|
|
12
14
|
const { t } = useTranslation('chat');
|
|
13
15
|
|
|
14
|
-
const [input, messageString
|
|
16
|
+
const [input, messageString] = useChatStore((s) => [
|
|
15
17
|
s.inputMessage,
|
|
16
18
|
chatSelectors.chatsMessageString(s),
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const [systemRole, model] = useSessionStore((s) => [
|
|
17
22
|
agentSelectors.currentAgentSystemRole(s),
|
|
18
23
|
agentSelectors.currentAgentModel(s) as LanguageModel,
|
|
19
24
|
]);
|
|
25
|
+
|
|
20
26
|
const inputTokenCount = useTokenCount(input);
|
|
21
27
|
|
|
22
28
|
const systemRoleToken = useTokenCount(systemRole);
|
|
@@ -2,7 +2,7 @@ import { Input, TextArea } from '@lobehub/ui';
|
|
|
2
2
|
import { memo, useRef } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useChatStore } from '@/store/chat';
|
|
6
6
|
|
|
7
7
|
import { useSendMessage } from '../useSend';
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ const InputAreaInner = memo<InputAreaInnerProps>(({ className, mobile }) => {
|
|
|
15
15
|
const { t } = useTranslation('chat');
|
|
16
16
|
const isChineseInput = useRef(false);
|
|
17
17
|
|
|
18
|
-
const [loading, message, updateInputMessage] =
|
|
18
|
+
const [loading, message, updateInputMessage] = useChatStore((s) => [
|
|
19
19
|
!!s.chatLoadingId,
|
|
20
20
|
s.inputMessage,
|
|
21
21
|
s.updateInputMessage,
|
|
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { Flexbox } from 'react-layout-kit';
|
|
8
8
|
|
|
9
9
|
import { useSTT } from '@/hooks/useSTT';
|
|
10
|
-
import {
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
11
11
|
import { ChatMessageError } from '@/types/chatMessage';
|
|
12
12
|
import { getMessageError } from '@/utils/fetch';
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ const STT = memo<{ mobile?: boolean }>(({ mobile }) => {
|
|
|
25
25
|
const { t } = useTranslation('chat');
|
|
26
26
|
const { styles } = useStyles();
|
|
27
27
|
|
|
28
|
-
const [loading, updateInputMessage] =
|
|
28
|
+
const [loading, updateInputMessage] = useChatStore((s) => [
|
|
29
29
|
!!s.chatLoadingId,
|
|
30
30
|
s.updateInputMessage,
|
|
31
31
|
]);
|
|
@@ -7,11 +7,11 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
|
|
8
8
|
import HotKeys from '@/components/HotKeys';
|
|
9
9
|
import { PREFIX_KEY, SAVE_TOPIC_KEY } from '@/const/hotkeys';
|
|
10
|
-
import {
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
11
11
|
|
|
12
12
|
const SaveTopic = memo<{ mobile?: boolean }>(({ mobile }) => {
|
|
13
13
|
const { t } = useTranslation('chat');
|
|
14
|
-
const [hasTopic, openNewTopicOrSaveTopic] =
|
|
14
|
+
const [hasTopic, openNewTopicOrSaveTopic] = useChatStore((s) => [
|
|
15
15
|
!!s.activeTopicId,
|
|
16
16
|
s.openNewTopicOrSaveTopic,
|
|
17
17
|
]);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
import { filesSelectors, useFileStore } from '@/store/files';
|
|
4
|
-
import {
|
|
4
|
+
import { useChatStore } from 'src/store/chat';
|
|
5
5
|
|
|
6
6
|
export const useSendMessage = () => {
|
|
7
|
-
const [sendMessage, updateInputMessage] =
|
|
7
|
+
const [sendMessage, updateInputMessage] = useChatStore((s) => [
|
|
8
8
|
s.sendMessage,
|
|
9
9
|
s.updateInputMessage,
|
|
10
10
|
]);
|
|
11
11
|
|
|
12
12
|
return useCallback(() => {
|
|
13
|
-
const store =
|
|
13
|
+
const store = useChatStore.getState();
|
|
14
14
|
if (!!store.chatLoadingId) return;
|
|
15
15
|
const imageList = filesSelectors.imageUrlOrBase64List(useFileStore.getState());
|
|
16
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChatListProps } from '@lobehub/ui';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useChatStore } from '@/store/chat';
|
|
4
4
|
|
|
5
5
|
import { AssistantActionsBar } from './Assistant';
|
|
6
6
|
import { DefaultActionsBar } from './Fallback';
|
|
@@ -20,7 +20,7 @@ interface ActionsClick {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const useActionsClick = (): ChatListProps['onActionsClick'] => {
|
|
23
|
-
const [deleteMessage, resendMessage, translateMessage, ttsMessage] =
|
|
23
|
+
const [deleteMessage, resendMessage, translateMessage, ttsMessage] = useChatStore((s) => [
|
|
24
24
|
s.deleteMessage,
|
|
25
25
|
s.resendMessage,
|
|
26
26
|
s.translateMessage,
|
|
@@ -5,8 +5,8 @@ import { memo, useState } from 'react';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { Center, Flexbox } from 'react-layout-kit';
|
|
7
7
|
|
|
8
|
+
import { useChatStore } from '@/store/chat';
|
|
8
9
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
9
|
-
import { useSessionStore } from '@/store/session';
|
|
10
10
|
|
|
11
11
|
import { FormAction } from './style';
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ const APIKeyForm = memo<{ id: string }>(({ id }) => {
|
|
|
20
20
|
s.setOpenAIConfig,
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
-
const [resend, deleteMessage] =
|
|
23
|
+
const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<Center gap={16} style={{ maxWidth: 300 }}>
|
|
@@ -5,8 +5,8 @@ import { memo, useState } from 'react';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { Flexbox } from 'react-layout-kit';
|
|
7
7
|
|
|
8
|
+
import { useChatStore } from '@/store/chat';
|
|
8
9
|
import { useGlobalStore } from '@/store/global';
|
|
9
|
-
import { useSessionStore } from '@/store/session';
|
|
10
10
|
|
|
11
11
|
import APIKeyForm from './ApiKeyForm';
|
|
12
12
|
import { ErrorActionContainer, FormAction } from './style';
|
|
@@ -20,7 +20,7 @@ const InvalidAccess: RenderErrorMessage['Render'] = memo(({ id }) => {
|
|
|
20
20
|
const { t } = useTranslation('error');
|
|
21
21
|
const [mode, setMode] = useState<Tab>(Tab.Password);
|
|
22
22
|
const [password, setSettings] = useGlobalStore((s) => [s.settings.password, s.setSettings]);
|
|
23
|
-
const [resend, deleteMessage] =
|
|
23
|
+
const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<ErrorActionContainer>
|
|
@@ -7,9 +7,9 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { Center, Flexbox } from 'react-layout-kit';
|
|
8
8
|
|
|
9
9
|
import PluginSettingsConfig from '@/features/PluginSettings';
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
10
11
|
import { pluginHelpers, usePluginStore } from '@/store/plugin';
|
|
11
12
|
import { pluginSelectors } from '@/store/plugin/selectors';
|
|
12
|
-
import { useSessionStore } from '@/store/session';
|
|
13
13
|
|
|
14
14
|
import { ErrorActionContainer, useStyles } from '../style';
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ const PluginSettings: RenderErrorMessage['Render'] = memo(({ id, plugin }) => {
|
|
|
17
17
|
const { styles } = useStyles();
|
|
18
18
|
const { t } = useTranslation('error');
|
|
19
19
|
const theme = useTheme();
|
|
20
|
-
const [resend, deleteMessage] =
|
|
20
|
+
const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
|
|
21
21
|
const pluginIdentifier = plugin?.identifier as string;
|
|
22
22
|
const pluginMeta = usePluginStore(pluginSelectors.getPluginMetaById(pluginIdentifier), isEqual);
|
|
23
23
|
const manifest = usePluginStore(pluginSelectors.getPluginManifestById(pluginIdentifier), isEqual);
|
|
@@ -27,11 +27,11 @@ vi.mock('@/store/session/selectors', () => ({
|
|
|
27
27
|
|
|
28
28
|
const mockData: ChatMessage = {
|
|
29
29
|
content: 'test-content',
|
|
30
|
-
|
|
30
|
+
createdAt: 0,
|
|
31
31
|
id: 'abc',
|
|
32
32
|
meta: { avatar: '', backgroundColor: '', description: '', tags: [], title: '' },
|
|
33
33
|
role: 'assistant',
|
|
34
|
-
|
|
34
|
+
updatedAt: 0,
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
describe('AssistantMessageExtra', () => {
|
|
@@ -71,7 +71,7 @@ describe('AssistantMessageExtra', () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('should render Translate component if extra.translate exists', async () => {
|
|
74
|
-
render(<AssistantMessageExtra {...mockData} extra={{ translate: {} }} />);
|
|
74
|
+
render(<AssistantMessageExtra {...mockData} extra={{ translate: { to: 'abc' } }} />);
|
|
75
75
|
expect(screen.getByText('Translate Component')).toBeInTheDocument();
|
|
76
76
|
});
|
|
77
77
|
|
|
@@ -79,7 +79,7 @@ describe('AssistantMessageExtra', () => {
|
|
|
79
79
|
(useSessionStore as unknown as Mock).mockImplementation(() => ({
|
|
80
80
|
chatLoadingId: 'test-id',
|
|
81
81
|
}));
|
|
82
|
-
render(<AssistantMessageExtra {...mockData} extra={{ translate: {}, tts: {} }} />);
|
|
82
|
+
render(<AssistantMessageExtra {...mockData} extra={{ translate: { to: 'abc' }, tts: {} }} />);
|
|
83
83
|
expect(screen.getByText('TTS Component')).toBeInTheDocument();
|
|
84
84
|
expect(screen.getByText('Translate Component')).toBeInTheDocument();
|
|
85
85
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SiOpenai } from '@icons-pack/react-simple-icons';
|
|
2
|
-
import {
|
|
2
|
+
import { Tag } from '@lobehub/ui';
|
|
3
3
|
import { memo } from 'react';
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
|
+
import { useChatStore } from '@/store/chat';
|
|
6
7
|
import { useSessionStore } from '@/store/session';
|
|
7
8
|
import { agentSelectors } from '@/store/session/selectors';
|
|
8
9
|
import { ChatMessage } from '@/types/chatMessage';
|
|
@@ -11,39 +12,37 @@ import ExtraContainer from './ExtraContainer';
|
|
|
11
12
|
import TTS from './TTS';
|
|
12
13
|
import Translate from './Translate';
|
|
13
14
|
|
|
14
|
-
export const AssistantMessageExtra
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const loading = useSessionStore((s) => s.chatLoadingId === id);
|
|
15
|
+
export const AssistantMessageExtra = memo<ChatMessage>(({ extra, id, content }) => {
|
|
16
|
+
const model = useSessionStore(agentSelectors.currentAgentModel);
|
|
17
|
+
const loading = useChatStore((s) => s.chatLoadingId === id);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const showModelTag = extra?.fromModel && model !== extra?.fromModel;
|
|
20
|
+
const showTranslate = !!extra?.translate;
|
|
21
|
+
const showTTS = !!extra?.tts;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const showExtra = showModelTag || showTranslate || showTTS;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
if (!showExtra) return;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<div>
|
|
31
|
-
<Tag icon={<SiOpenai size={'1em'} />}>{extra?.fromModel as string}</Tag>
|
|
32
|
-
</div>
|
|
33
|
-
)}
|
|
27
|
+
return (
|
|
28
|
+
<Flexbox gap={8} style={{ marginTop: 8 }}>
|
|
29
|
+
{showModelTag && (
|
|
34
30
|
<div>
|
|
35
|
-
{extra?.
|
|
36
|
-
<ExtraContainer>
|
|
37
|
-
<TTS content={content} id={id} loading={loading} {...extra?.tts} />
|
|
38
|
-
</ExtraContainer>
|
|
39
|
-
)}
|
|
40
|
-
{extra?.translate && (
|
|
41
|
-
<ExtraContainer>
|
|
42
|
-
<Translate id={id} loading={loading} {...extra?.translate} />
|
|
43
|
-
</ExtraContainer>
|
|
44
|
-
)}
|
|
31
|
+
<Tag icon={<SiOpenai size={'1em'} />}>{extra?.fromModel as string}</Tag>
|
|
45
32
|
</div>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
)}
|
|
34
|
+
<div>
|
|
35
|
+
{extra?.tts && (
|
|
36
|
+
<ExtraContainer>
|
|
37
|
+
<TTS content={content} id={id} loading={loading} {...extra?.tts} />
|
|
38
|
+
</ExtraContainer>
|
|
39
|
+
)}
|
|
40
|
+
{extra?.translate && (
|
|
41
|
+
<ExtraContainer>
|
|
42
|
+
<Translate id={id} loading={loading} {...extra?.translate} />
|
|
43
|
+
</ExtraContainer>
|
|
44
|
+
)}
|
|
45
|
+
</div>
|
|
46
|
+
</Flexbox>
|
|
47
|
+
);
|
|
48
|
+
});
|
|
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
7
7
|
import { Flexbox } from 'react-layout-kit';
|
|
8
8
|
|
|
9
9
|
import { useTTS } from '@/hooks/useTTS';
|
|
10
|
-
import {
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
11
11
|
import { ChatMessageError, ChatTTS } from '@/types/chatMessage';
|
|
12
12
|
import { getMessageError } from '@/utils/fetch';
|
|
13
13
|
|
|
@@ -22,7 +22,7 @@ const TTS = memo<TTSProps>(({ id, init, content }) => {
|
|
|
22
22
|
const [error, setError] = useState<ChatMessageError>();
|
|
23
23
|
const { t } = useTranslation('chat');
|
|
24
24
|
|
|
25
|
-
const [ttsMessage, clearTTS] =
|
|
25
|
+
const [ttsMessage, clearTTS] = useChatStore((s) => [s.ttsMessage, s.clearTTS]);
|
|
26
26
|
|
|
27
27
|
const setDefaultError = useCallback(
|
|
28
28
|
(err?: any) => {
|
|
@@ -7,7 +7,7 @@ import { memo, useState } from 'react';
|
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { Flexbox } from 'react-layout-kit';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { useChatStore } from '@/store/chat';
|
|
11
11
|
import { ChatTranslate } from '@/types/chatMessage';
|
|
12
12
|
|
|
13
13
|
import BubblesLoading from '../Loading';
|
|
@@ -25,7 +25,7 @@ const Translate = memo<TranslateProps>(({ content = '', from, to, id, loading })
|
|
|
25
25
|
const { theme, styles } = useStyles();
|
|
26
26
|
const { t } = useTranslation('common');
|
|
27
27
|
const [show, setShow] = useState(true);
|
|
28
|
-
const clearTranslate =
|
|
28
|
+
const clearTranslate = useChatStore((s) => s.clearTranslate);
|
|
29
29
|
|
|
30
30
|
const { message } = App.useApp();
|
|
31
31
|
return (
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { RenderMessageExtra } from '@lobehub/ui';
|
|
2
1
|
import { memo } from 'react';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { useChatStore } from '@/store/chat';
|
|
5
4
|
import { ChatMessage } from '@/types/chatMessage';
|
|
6
5
|
|
|
7
6
|
import ExtraContainer from './ExtraContainer';
|
|
8
7
|
import TTS from './TTS';
|
|
9
8
|
import Translate from './Translate';
|
|
10
9
|
|
|
11
|
-
export const UserMessageExtra
|
|
12
|
-
const loading =
|
|
10
|
+
export const UserMessageExtra = memo<ChatMessage>(({ extra, id, content }) => {
|
|
11
|
+
const loading = useChatStore((s) => s.chatLoadingId === id);
|
|
12
|
+
|
|
13
|
+
const showTranslate = !!extra?.translate;
|
|
14
|
+
const showTTS = !!extra?.tts;
|
|
15
|
+
|
|
16
|
+
const showExtra = showTranslate || showTTS;
|
|
13
17
|
|
|
14
|
-
const showExtra = extra?.translate || extra?.tts;
|
|
15
18
|
if (!showExtra) return;
|
|
16
19
|
|
|
17
20
|
return (
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ChatListProps } from '@lobehub/ui';
|
|
1
|
+
import { ChatListProps, RenderMessageExtra } from '@lobehub/ui';
|
|
2
2
|
|
|
3
3
|
import { AssistantMessageExtra } from './Assistant';
|
|
4
4
|
import { UserMessageExtra } from './User';
|
|
5
5
|
|
|
6
6
|
export const renderMessagesExtra: ChatListProps['renderMessagesExtra'] = {
|
|
7
|
-
assistant: AssistantMessageExtra,
|
|
8
|
-
user: UserMessageExtra,
|
|
7
|
+
assistant: AssistantMessageExtra as unknown as RenderMessageExtra,
|
|
8
|
+
user: UserMessageExtra as unknown as RenderMessageExtra,
|
|
9
9
|
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { memo } from 'react';
|
|
1
|
+
import { ReactNode, memo } from 'react';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import { chatSelectors } from '@/store/
|
|
3
|
+
import { useChatStore } from '@/store/chat';
|
|
4
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
5
|
+
import { ChatMessage } from '@/types/chatMessage';
|
|
6
6
|
import { isFunctionMessageAtStart } from '@/utils/message';
|
|
7
7
|
|
|
8
8
|
import Inspector from '../Plugins/Inspector';
|
|
9
9
|
import { DefaultMessage } from './Default';
|
|
10
10
|
|
|
11
|
-
export const AssistantMessage
|
|
12
|
-
|
|
11
|
+
export const AssistantMessage = memo<
|
|
12
|
+
ChatMessage & {
|
|
13
|
+
editableContent: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
>(({ id, plugin, content, ...props }) => {
|
|
16
|
+
const fcProps = useChatStore(chatSelectors.getFunctionMessageProps({ content, id, plugin }));
|
|
13
17
|
|
|
14
18
|
if (!isFunctionMessageAtStart(content))
|
|
15
19
|
return <DefaultMessage content={content} id={id} {...props} />;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { memo } from 'react';
|
|
1
|
+
import { ReactNode, memo } from 'react';
|
|
3
2
|
|
|
4
3
|
import { LOADING_FLAT } from '@/const/message';
|
|
4
|
+
import { ChatMessage } from '@/types/chatMessage';
|
|
5
5
|
|
|
6
6
|
import BubblesLoading from '../Loading';
|
|
7
7
|
|
|
8
|
-
export const DefaultMessage
|
|
8
|
+
export const DefaultMessage = memo<
|
|
9
|
+
ChatMessage & {
|
|
10
|
+
editableContent: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
>(({ id, editableContent, content }) => {
|
|
9
13
|
if (content === LOADING_FLAT) return <BubblesLoading />;
|
|
10
14
|
|
|
11
15
|
return <div id={id}>{editableContent}</div>;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { RenderMessage } from '@lobehub/ui';
|
|
2
1
|
import isEqual from 'fast-deep-equal';
|
|
3
2
|
import { memo, useState } from 'react';
|
|
4
3
|
import { Flexbox } from 'react-layout-kit';
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
import { chatSelectors } from '@/store/
|
|
5
|
+
import { useChatStore } from '@/store/chat';
|
|
6
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
7
|
+
import { ChatMessage } from '@/types/chatMessage';
|
|
8
8
|
|
|
9
9
|
import Inspector from '../Plugins/Inspector';
|
|
10
10
|
import PluginRender from '../Plugins/Render';
|
|
11
11
|
|
|
12
|
-
export const FunctionMessage
|
|
13
|
-
const fcProps =
|
|
12
|
+
export const FunctionMessage = memo<ChatMessage>(({ id, content, plugin }) => {
|
|
13
|
+
const fcProps = useChatStore(
|
|
14
14
|
chatSelectors.getFunctionMessageProps({ content, id, plugin }),
|
|
15
15
|
isEqual,
|
|
16
16
|
);
|
|
17
|
+
|
|
17
18
|
const [showRender, setShow] = useState(true);
|
|
18
19
|
|
|
19
20
|
return (
|
|
@@ -24,7 +25,7 @@ export const FunctionMessage: RenderMessage = memo(({ id, content, plugin, name
|
|
|
24
25
|
content={content}
|
|
25
26
|
id={id}
|
|
26
27
|
loading={fcProps.loading}
|
|
27
|
-
name={
|
|
28
|
+
name={plugin?.identifier}
|
|
28
29
|
payload={fcProps.command}
|
|
29
30
|
type={fcProps.type}
|
|
30
31
|
/>
|
|
@@ -4,7 +4,7 @@ import { useRouter } from 'next/navigation';
|
|
|
4
4
|
|
|
5
5
|
import { useGlobalStore } from '@/store/global';
|
|
6
6
|
import { useSessionStore } from '@/store/session';
|
|
7
|
-
import { sessionSelectors } from '@/store/session/
|
|
7
|
+
import { sessionSelectors } from '@/store/session/selectors';
|
|
8
8
|
import { pathString } from '@/utils/url';
|
|
9
9
|
|
|
10
10
|
import { AssistantMessage } from './Assistant';
|
|
@@ -13,10 +13,10 @@ import { FunctionMessage } from './Function';
|
|
|
13
13
|
import { UserMessage } from './User';
|
|
14
14
|
|
|
15
15
|
export const renderMessages: ChatListProps['renderMessages'] = {
|
|
16
|
-
assistant: AssistantMessage,
|
|
17
|
-
default: DefaultMessage,
|
|
18
|
-
function: FunctionMessage,
|
|
19
|
-
user: UserMessage,
|
|
16
|
+
assistant: AssistantMessage as any,
|
|
17
|
+
default: DefaultMessage as any,
|
|
18
|
+
function: FunctionMessage as any,
|
|
19
|
+
user: UserMessage as any,
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export const useAvatarsClick = (): ChatListProps['onAvatarsClick'] => {
|
|
@@ -32,8 +32,8 @@ export const useAvatarsClick = (): ChatListProps['onAvatarsClick'] => {
|
|
|
32
32
|
isInbox
|
|
33
33
|
? router.push('/settings/agent')
|
|
34
34
|
: mobile
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
? router.push(pathString('/chat/settings', { hash: location.hash }))
|
|
36
|
+
: toggleSystemRole(true);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|