fix: auto send prompt runtime (#3295)

This commit is contained in:
Archer
2024-12-03 00:02:56 +08:00
committed by GitHub
parent c506442993
commit f28b7e41a8
8 changed files with 79 additions and 76 deletions

View File

@@ -41,7 +41,6 @@ type useChatStoreType = ChatProviderProps & {
ttsConfig: AppTTSConfigType; ttsConfig: AppTTSConfigType;
whisperConfig: AppWhisperConfigType; whisperConfig: AppWhisperConfigType;
autoTTSResponse: boolean; autoTTSResponse: boolean;
autoExecute: AppAutoExecuteConfigType;
startSegmentedAudio: () => Promise<any>; startSegmentedAudio: () => Promise<any>;
splitText2Audio: (text: string, done?: boolean | undefined) => void; splitText2Audio: (text: string, done?: boolean | undefined) => void;
finishSegmentedAudio: () => void; finishSegmentedAudio: () => void;
@@ -136,24 +135,38 @@ const Provider = ({
}: ChatProviderProps & { }: ChatProviderProps & {
children: React.ReactNode; children: React.ReactNode;
}) => { }) => {
const chatConfig = useContextSelector( const welcomeText = useContextSelector(
ChatItemContext, ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig || {} (v) => v.chatBoxData?.app?.chatConfig?.welcomeText ?? ''
); );
const variables = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.variables ?? []
);
const questionGuide = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.questionGuide ?? false
);
const ttsConfig = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.ttsConfig ?? defaultTTSConfig
);
const whisperConfig = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.whisperConfig ?? defaultWhisperConfig
);
const chatInputGuide = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.chatInputGuide ?? defaultChatInputGuideConfig
);
const fileSelectConfig = useContextSelector(
ChatItemContext,
(v) => v.chatBoxData?.app?.chatConfig?.fileSelectConfig ?? defaultAppSelectFileConfig
);
const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords); const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
const setChatRecords = useContextSelector(ChatRecordContext, (v) => v.setChatRecords); const setChatRecords = useContextSelector(ChatRecordContext, (v) => v.setChatRecords);
const {
welcomeText = '',
variables = [],
questionGuide = false,
ttsConfig = defaultTTSConfig,
whisperConfig = defaultWhisperConfig,
chatInputGuide = defaultChatInputGuideConfig,
fileSelectConfig = defaultAppSelectFileConfig,
autoExecute = defaultAutoExecuteConfig
} = useMemo(() => chatConfig, [chatConfig]);
// segment audio // segment audio
const [audioPlayingChatId, setAudioPlayingChatId] = useState<string>(); const [audioPlayingChatId, setAudioPlayingChatId] = useState<string>();
const { const {
@@ -202,7 +215,6 @@ const Provider = ({
const value: useChatStoreType = { const value: useChatStoreType = {
...props, ...props,
welcomeText, welcomeText,
autoExecute,
variableList: variables.filter((item) => item.type !== VariableInputEnum.custom), variableList: variables.filter((item) => item.type !== VariableInputEnum.custom),
allVariableList: variables, allVariableList: variables,
questionGuide, questionGuide,

View File

@@ -83,7 +83,6 @@ enum FeedbackTypeEnum {
type Props = OutLinkChatAuthProps & type Props = OutLinkChatAuthProps &
ChatProviderProps & { ChatProviderProps & {
isReady?: boolean;
feedbackType?: `${FeedbackTypeEnum}`; feedbackType?: `${FeedbackTypeEnum}`;
showMarkIcon?: boolean; // admin mark dataset showMarkIcon?: boolean; // admin mark dataset
showVoiceIcon?: boolean; showVoiceIcon?: boolean;
@@ -98,7 +97,6 @@ type Props = OutLinkChatAuthProps &
}; };
const ChatBox = ({ const ChatBox = ({
isReady = true,
feedbackType = FeedbackTypeEnum.hidden, feedbackType = FeedbackTypeEnum.hidden,
showMarkIcon = false, showMarkIcon = false,
showVoiceIcon = true, showVoiceIcon = true,
@@ -132,6 +130,7 @@ const ChatBox = ({
const appAvatar = useContextSelector(ChatItemContext, (v) => v.chatBoxData?.app?.avatar); const appAvatar = useContextSelector(ChatItemContext, (v) => v.chatBoxData?.app?.avatar);
const userAvatar = useContextSelector(ChatItemContext, (v) => v.chatBoxData?.userAvatar); const userAvatar = useContextSelector(ChatItemContext, (v) => v.chatBoxData?.userAvatar);
const chatBoxData = useContextSelector(ChatItemContext, (v) => v.chatBoxData);
const ChatBoxRef = useContextSelector(ChatItemContext, (v) => v.ChatBoxRef); const ChatBoxRef = useContextSelector(ChatItemContext, (v) => v.ChatBoxRef);
const variablesForm = useContextSelector(ChatItemContext, (v) => v.variablesForm); const variablesForm = useContextSelector(ChatItemContext, (v) => v.variablesForm);
const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords); const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
@@ -146,7 +145,6 @@ const ChatBox = ({
const variableList = useContextSelector(ChatBoxContext, (v) => v.variableList); const variableList = useContextSelector(ChatBoxContext, (v) => v.variableList);
const allVariableList = useContextSelector(ChatBoxContext, (v) => v.allVariableList); const allVariableList = useContextSelector(ChatBoxContext, (v) => v.allVariableList);
const questionGuide = useContextSelector(ChatBoxContext, (v) => v.questionGuide); const questionGuide = useContextSelector(ChatBoxContext, (v) => v.questionGuide);
const autoExecute = useContextSelector(ChatBoxContext, (v) => v.autoExecute);
const startSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.startSegmentedAudio); const startSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.startSegmentedAudio);
const finishSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.finishSegmentedAudio); const finishSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.finishSegmentedAudio);
const setAudioPlayingChatId = useContextSelector(ChatBoxContext, (v) => v.setAudioPlayingChatId); const setAudioPlayingChatId = useContextSelector(ChatBoxContext, (v) => v.setAudioPlayingChatId);
@@ -166,7 +164,9 @@ const ChatBox = ({
}); });
const { setValue, watch } = chatForm; const { setValue, watch } = chatForm;
const chatStartedWatch = watch('chatStarted'); const chatStartedWatch = watch('chatStarted');
const chatStarted = chatStartedWatch || chatRecords.length > 0 || variableList.length === 0; const chatStarted =
chatBoxData?.appId === appId &&
(chatStartedWatch || chatRecords.length > 0 || variableList.length === 0);
// 滚动到底部 // 滚动到底部
const scrollToBottom = useMemoizedFn((behavior: 'smooth' | 'auto' = 'smooth', delay = 0) => { const scrollToBottom = useMemoizedFn((behavior: 'smooth' | 'auto' = 'smooth', delay = 0) => {
@@ -802,9 +802,9 @@ const ChatBox = ({
setQuestionGuide([]); setQuestionGuide([]);
setValue('chatStarted', false); setValue('chatStarted', false);
abortRequest('leave'); abortRequest('leave');
}, [router.query, setValue, chatId]); }, [abortRequest, setValue]);
// add listener // Add listener
useEffect(() => { useEffect(() => {
const windowMessage = ({ data }: MessageEvent<{ type: 'sendPrompt'; text: string }>) => { const windowMessage = ({ data }: MessageEvent<{ type: 'sendPrompt'; text: string }>) => {
if (data?.type === 'sendPrompt' && data?.text) { if (data?.type === 'sendPrompt' && data?.text) {
@@ -829,30 +829,27 @@ const ChatBox = ({
eventBus.off(EventNameEnum.sendQuestion); eventBus.off(EventNameEnum.sendQuestion);
eventBus.off(EventNameEnum.editQuestion); eventBus.off(EventNameEnum.editQuestion);
}; };
}, [isReady, resetInputVal, sendPrompt]); }, [chatBoxData, resetInputVal, sendPrompt]);
// Auto send prompt // Auto send prompt
useEffect(() => { useEffect(() => {
if ( if (
isReady && chatBoxData?.app?.chatConfig?.autoExecute?.open &&
autoExecute.open &&
chatStarted && chatStarted &&
chatRecords.length === 0 && chatRecords.length === 0 &&
isChatRecordsLoaded isChatRecordsLoaded
) { ) {
sendPrompt({ sendPrompt({
text: autoExecute.defaultPrompt || 'AUTO_EXECUTE', text: chatBoxData?.app?.chatConfig?.autoExecute?.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true hideInUI: true
}); });
} }
}, [ }, [
chatStarted, chatStarted,
chatRecords, chatRecords.length,
isChatRecordsLoaded, isChatRecordsLoaded,
sendPrompt, sendPrompt,
isReady, chatBoxData?.app?.chatConfig?.autoExecute
autoExecute.open,
autoExecute.defaultPrompt
]); ]);
// output data // output data

View File

@@ -1,5 +1,5 @@
import React, { useState, useCallback } from 'react'; import React, { useState, useCallback } from 'react';
import { Flex, useTheme, Box, useDisclosure } from '@chakra-ui/react'; import { Flex, Box, useDisclosure } from '@chakra-ui/react';
import MyIcon from '@fastgpt/web/components/common/Icon'; import MyIcon from '@fastgpt/web/components/common/Icon';
import Avatar from '@fastgpt/web/components/common/Avatar'; import Avatar from '@fastgpt/web/components/common/Avatar';
import ToolMenu from './ToolMenu'; import ToolMenu from './ToolMenu';
@@ -10,7 +10,6 @@ import MyTag from '@fastgpt/web/components/common/Tag/index';
import { useContextSelector } from 'use-context-selector'; import { useContextSelector } from 'use-context-selector';
import { ChatContext } from '@/web/core/chat/context/chatContext'; import { ChatContext } from '@/web/core/chat/context/chatContext';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import { InitChatResponse } from '@/global/core/chat/api';
import { AppFolderTypeList, AppTypeEnum } from '@fastgpt/global/core/app/constants'; import { AppFolderTypeList, AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { useSystem } from '@fastgpt/web/hooks/useSystem';
import LightRowTabs from '@fastgpt/web/components/common/Tabs/LightRowTabs'; import LightRowTabs from '@fastgpt/web/components/common/Tabs/LightRowTabs';
@@ -22,9 +21,9 @@ import {
} from '@fastgpt/global/common/parentFolder/type'; } from '@fastgpt/global/common/parentFolder/type';
import { getMyApps } from '@/web/core/app/api'; import { getMyApps } from '@/web/core/app/api';
import SelectOneResource from '@/components/common/folder/SelectOneResource'; import SelectOneResource from '@/components/common/folder/SelectOneResource';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
const ChatHeader = ({ const ChatHeader = ({
chatData,
history, history,
showHistory, showHistory,
apps, apps,
@@ -33,15 +32,16 @@ const ChatHeader = ({
}: { }: {
history: ChatItemType[]; history: ChatItemType[];
showHistory?: boolean; showHistory?: boolean;
chatData: InitChatResponse;
apps?: AppListItemType[]; apps?: AppListItemType[];
onRouteToAppDetail?: () => void; onRouteToAppDetail?: () => void;
totalRecordsCount: number; totalRecordsCount: number;
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const isPlugin = chatData.app.type === AppTypeEnum.plugin;
const { isPc } = useSystem(); const { isPc } = useSystem();
const chatData = useContextSelector(ChatItemContext, (v) => v.chatBoxData);
const isPlugin = chatData.app.type === AppTypeEnum.plugin;
return isPc && isPlugin ? null : ( return isPc && isPlugin ? null : (
<Flex <Flex
alignItems={'center'} alignItems={'center'}

View File

@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'; import React, { useCallback, useEffect, useMemo } from 'react';
import NextHead from '@/components/common/NextHead'; import NextHead from '@/components/common/NextHead';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { getInitChatInfo } from '@/web/core/chat/api'; import { getInitChatInfo } from '@/web/core/chat/api';
@@ -24,7 +24,7 @@ import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { useMount } from 'ahooks'; import { useMount } from 'ahooks';
import { getNanoid } from '@fastgpt/global/common/string/tools'; import { getNanoid } from '@fastgpt/global/common/string/tools';
import { defaultChatData, GetChatTypeEnum } from '@/global/core/chat/constants'; import { GetChatTypeEnum } from '@/global/core/chat/constants';
import ChatContextProvider, { ChatContext } from '@/web/core/chat/context/chatContext'; import ChatContextProvider, { ChatContext } from '@/web/core/chat/context/chatContext';
import { AppListItemType } from '@fastgpt/global/core/app/type'; import { AppListItemType } from '@fastgpt/global/core/app/type';
import { useContextSelector } from 'use-context-selector'; import { useContextSelector } from 'use-context-selector';
@@ -36,7 +36,6 @@ import ChatItemContextProvider, { ChatItemContext } from '@/web/core/chat/contex
import ChatRecordContextProvider, { import ChatRecordContextProvider, {
ChatRecordContext ChatRecordContext
} from '@/web/core/chat/context/chatRecordContext'; } from '@/web/core/chat/context/chatRecordContext';
import { InitChatResponse } from '@/global/core/chat/api';
const CustomPluginRunBox = dynamic(() => import('./components/CustomPluginRunBox')); const CustomPluginRunBox = dynamic(() => import('./components/CustomPluginRunBox'));
@@ -56,13 +55,13 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
const resetVariables = useContextSelector(ChatItemContext, (v) => v.resetVariables); const resetVariables = useContextSelector(ChatItemContext, (v) => v.resetVariables);
const isPlugin = useContextSelector(ChatItemContext, (v) => v.isPlugin); const isPlugin = useContextSelector(ChatItemContext, (v) => v.isPlugin);
const chatBoxData = useContextSelector(ChatItemContext, (v) => v.chatBoxData);
const setChatBoxData = useContextSelector(ChatItemContext, (v) => v.setChatBoxData); const setChatBoxData = useContextSelector(ChatItemContext, (v) => v.setChatBoxData);
const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords); const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
const totalRecordsCount = useContextSelector(ChatRecordContext, (v) => v.totalRecordsCount); const totalRecordsCount = useContextSelector(ChatRecordContext, (v) => v.totalRecordsCount);
// Load chat init data // Load chat init data
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { loading } = useRequest2( const { loading } = useRequest2(
async () => { async () => {
if (!appId || forbidLoadChat.current) return; if (!appId || forbidLoadChat.current) return;
@@ -71,11 +70,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
res.userAvatar = userInfo?.avatar; res.userAvatar = userInfo?.avatar;
// Wait for state update to complete // Wait for state update to complete
await new Promise((resolve) => { setChatBoxData(res);
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
// reset chat variables // reset chat variables
resetVariables({ resetVariables({
@@ -132,14 +127,14 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
// new chat // new chat
onUpdateHistoryTitle({ chatId, newTitle }); onUpdateHistoryTitle({ chatId, newTitle });
// update chat window // update chat window
setChatData((state) => ({ setChatBoxData((state) => ({
...state, ...state,
title: newTitle title: newTitle
})); }));
return { responseText, responseData, isNewChat: forbidLoadChat.current }; return { responseText, responseData, isNewChat: forbidLoadChat.current };
}, },
[chatId, appId, onUpdateHistoryTitle, forbidLoadChat] [appId, chatId, onUpdateHistoryTitle, setChatBoxData, forbidLoadChat]
); );
const RenderHistorySlider = useMemo(() => { const RenderHistorySlider = useMemo(() => {
const Children = ( const Children = (
@@ -164,7 +159,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
return ( return (
<Flex h={'100%'}> <Flex h={'100%'}>
<NextHead title={chatData.app.name} icon={chatData.app.avatar}></NextHead> <NextHead title={chatBoxData.app.name} icon={chatBoxData.app.avatar}></NextHead>
{/* pc show myself apps */} {/* pc show myself apps */}
{isPc && ( {isPc && (
<Box borderRight={theme.borders.base} w={'220px'} flexShrink={0}> <Box borderRight={theme.borders.base} w={'220px'} flexShrink={0}>
@@ -188,7 +183,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
<ChatHeader <ChatHeader
totalRecordsCount={totalRecordsCount} totalRecordsCount={totalRecordsCount}
apps={myApps} apps={myApps}
chatData={chatData}
history={chatRecords} history={chatRecords}
showHistory showHistory
onRouteToAppDetail={() => router.push(`/app/detail?appId=${appId}`)} onRouteToAppDetail={() => router.push(`/app/detail?appId=${appId}`)}
@@ -213,7 +207,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType={'user'} feedbackType={'user'}
onStartChat={onStartChat} onStartChat={onStartChat}
chatType={'chat'} chatType={'chat'}
isReady={!loading}
showRawSource showRawSource
showNodeStatus showNodeStatus
/> />

View File

@@ -87,7 +87,6 @@ const OutLink = (props: Props) => {
const isChatRecordsLoaded = useContextSelector(ChatRecordContext, (v) => v.isChatRecordsLoaded); const isChatRecordsLoaded = useContextSelector(ChatRecordContext, (v) => v.isChatRecordsLoaded);
const initSign = useRef(false); const initSign = useRef(false);
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { data, loading } = useRequest2( const { data, loading } = useRequest2(
async () => { async () => {
const shareId = outLinkAuthData.shareId; const shareId = outLinkAuthData.shareId;
@@ -100,11 +99,7 @@ const OutLink = (props: Props) => {
outLinkUid outLinkUid
}); });
await new Promise((resolve) => { setChatBoxData(res);
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
resetVariables({ resetVariables({
variables: res.variables variables: res.variables
@@ -180,7 +175,7 @@ const OutLink = (props: Props) => {
onUpdateHistoryTitle({ chatId: completionChatId, newTitle }); onUpdateHistoryTitle({ chatId: completionChatId, newTitle });
// update chat window // update chat window
setChatData((state) => ({ setChatBoxData((state) => ({
...state, ...state,
title: newTitle title: newTitle
})); }));
@@ -199,7 +194,15 @@ const OutLink = (props: Props) => {
return { responseText, responseData, isNewChat: forbidLoadChat.current }; return { responseText, responseData, isNewChat: forbidLoadChat.current };
}, },
[chatId, customVariables, outLinkAuthData, onUpdateHistoryTitle, forbidLoadChat, onChangeChatId] [
chatId,
customVariables,
outLinkAuthData,
onUpdateHistoryTitle,
setChatBoxData,
forbidLoadChat,
onChangeChatId
]
); );
// window init // window init
@@ -258,7 +261,6 @@ const OutLink = (props: Props) => {
{/* header */} {/* header */}
{showHead === '1' ? ( {showHead === '1' ? (
<ChatHeader <ChatHeader
chatData={chatData}
history={chatRecords} history={chatRecords}
totalRecordsCount={totalRecordsCount} totalRecordsCount={totalRecordsCount}
showHistory={showHistory === '1'} showHistory={showHistory === '1'}
@@ -282,7 +284,6 @@ const OutLink = (props: Props) => {
feedbackType={'user'} feedbackType={'user'}
onStartChat={startChat} onStartChat={startChat}
chatType="share" chatType="share"
isReady={!loading}
showRawSource={showRawSource} showRawSource={showRawSource}
showNodeStatus={showNodeStatus} showNodeStatus={showNodeStatus}
/> />

View File

@@ -62,24 +62,21 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
const onUpdateHistoryTitle = useContextSelector(ChatContext, (v) => v.onUpdateHistoryTitle); const onUpdateHistoryTitle = useContextSelector(ChatContext, (v) => v.onUpdateHistoryTitle);
const resetVariables = useContextSelector(ChatItemContext, (v) => v.resetVariables); const resetVariables = useContextSelector(ChatItemContext, (v) => v.resetVariables);
const chatBoxData = useContextSelector(ChatItemContext, (v) => v.chatBoxData);
const setChatBoxData = useContextSelector(ChatItemContext, (v) => v.setChatBoxData); const setChatBoxData = useContextSelector(ChatItemContext, (v) => v.setChatBoxData);
const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords); const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
const totalRecordsCount = useContextSelector(ChatRecordContext, (v) => v.totalRecordsCount); const totalRecordsCount = useContextSelector(ChatRecordContext, (v) => v.totalRecordsCount);
// get chat app info // get chat app info
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { loading } = useRequest2( const { loading } = useRequest2(
async () => { async () => {
if (!appId || forbidLoadChat.current) return; if (!appId || forbidLoadChat.current) return;
const res = await getTeamChatInfo({ teamId, appId, chatId, teamToken }); const res = await getTeamChatInfo({ teamId, appId, chatId, teamToken });
await new Promise((resolve) => { setChatBoxData(res);
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
// reset chat records // reset chat records
resetVariables({ resetVariables({
variables: res.variables variables: res.variables
@@ -124,7 +121,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
teamId, teamId,
teamToken, teamToken,
chatId: completionChatId, chatId: completionChatId,
appType: chatData.app.type appType: chatBoxData.app.type
}, },
onMessage: generatingMessage, onMessage: generatingMessage,
abortCtrl: controller abortCtrl: controller
@@ -139,7 +136,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
onUpdateHistoryTitle({ chatId: completionChatId, newTitle }); onUpdateHistoryTitle({ chatId: completionChatId, newTitle });
// update chat window // update chat window
setChatData((state) => ({ setChatBoxData((state) => ({
...state, ...state,
title: newTitle title: newTitle
})); }));
@@ -152,8 +149,9 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
appId, appId,
teamId, teamId,
teamToken, teamToken,
chatData.app.type, chatBoxData.app.type,
onUpdateHistoryTitle, onUpdateHistoryTitle,
setChatBoxData,
forbidLoadChat, forbidLoadChat,
onChangeChatId onChangeChatId
] ]
@@ -182,7 +180,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
return ( return (
<Flex h={'100%'}> <Flex h={'100%'}>
<NextHead title={chatData.app.name} icon={chatData.app.avatar}></NextHead> <NextHead title={chatBoxData.app.name} icon={chatBoxData.app.avatar}></NextHead>
{/* pc show myself apps */} {/* pc show myself apps */}
{isPc && ( {isPc && (
<Box borderRight={theme.borders.base} w={'220px'} flexShrink={0}> <Box borderRight={theme.borders.base} w={'220px'} flexShrink={0}>
@@ -205,13 +203,12 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
<ChatHeader <ChatHeader
totalRecordsCount={totalRecordsCount} totalRecordsCount={totalRecordsCount}
apps={myApps} apps={myApps}
chatData={chatData}
history={chatRecords} history={chatRecords}
showHistory showHistory
/> />
{/* chat box */} {/* chat box */}
<Box flex={1}> <Box flex={1}>
{chatData.app.type === AppTypeEnum.plugin ? ( {chatBoxData.app.type === AppTypeEnum.plugin ? (
<CustomPluginRunBox <CustomPluginRunBox
appId={appId} appId={appId}
chatId={chatId} chatId={chatId}
@@ -227,7 +224,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType={'user'} feedbackType={'user'}
onStartChat={startChat} onStartChat={startChat}
chatType="team" chatType="team"
isReady={!loading}
showRawSource showRawSource
showNodeStatus showNodeStatus
/> />

View File

@@ -10,13 +10,17 @@ import { AppChatConfigType } from '@fastgpt/global/core/app/type';
import { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io'; import { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io';
type ChatBoxDataType = { type ChatBoxDataType = {
appId: string;
title?: string;
userAvatar?: string; userAvatar?: string;
app: { app: {
chatConfig?: AppChatConfigType; chatConfig?: AppChatConfigType;
name: string; name: string;
avatar: string; avatar: string;
type: `${AppTypeEnum}`; type: `${AppTypeEnum}`;
pluginInputs: FlowNodeInputItemType[]; pluginInputs: FlowNodeInputItemType[];
chatModels?: string[];
}; };
}; };
@@ -55,7 +59,9 @@ const ChatItemContextProvider = ({ children }: { children: ReactNode }) => {
const ChatBoxRef = useRef<ChatComponentRef>(null); const ChatBoxRef = useRef<ChatComponentRef>(null);
const variablesForm = useForm<ChatBoxInputFormType>(); const variablesForm = useForm<ChatBoxInputFormType>();
const [chatBoxData, setChatBoxData] = useState<ChatBoxDataType>(defaultChatData); const [chatBoxData, setChatBoxData] = useState<ChatBoxDataType>({
...defaultChatData
});
const isPlugin = chatBoxData.app.type === AppTypeEnum.plugin; const isPlugin = chatBoxData.app.type === AppTypeEnum.plugin;

View File

@@ -56,10 +56,6 @@ const ChatRecordContextProvider = ({
const ChatBoxRef = useContextSelector(ChatItemContext, (v) => v.ChatBoxRef); const ChatBoxRef = useContextSelector(ChatItemContext, (v) => v.ChatBoxRef);
const [isChatRecordsLoaded, setIsChatRecordsLoaded] = useState(false); const [isChatRecordsLoaded, setIsChatRecordsLoaded] = useState(false);
useEffect(() => {
setIsChatRecordsLoaded(false);
}, [params]);
const { const {
data: chatRecords, data: chatRecords,
ScrollData, ScrollData,
@@ -67,6 +63,8 @@ const ChatRecordContextProvider = ({
total: totalRecordsCount total: totalRecordsCount
} = useScrollPagination( } = useScrollPagination(
async (data: getPaginationRecordsBody): Promise<PaginationResponse<ChatSiteItemType>> => { async (data: getPaginationRecordsBody): Promise<PaginationResponse<ChatSiteItemType>> => {
setIsChatRecordsLoaded(false);
const res = await getChatRecords(data); const res = await getChatRecords(data);
// First load scroll to bottom // First load scroll to bottom