Skip to content

Commit

Permalink
app auto exec
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Nov 18, 2024
1 parent 59d8181 commit d9bda4f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from '@fastgpt/global/core/chat/type.d';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { Box, Flex, Checkbox } from '@chakra-ui/react';
import { Box, Checkbox } from '@chakra-ui/react';
import { EventNameEnum, eventBus } from '@/web/common/utils/eventbus';
import { chats2GPTMessages } from '@fastgpt/global/core/chat/adapt';
import { useForm } from 'react-hook-form';
Expand Down Expand Up @@ -144,6 +144,7 @@ const ChatBox = ({
const variableList = useContextSelector(ChatBoxContext, (v) => v.variableList);
const allVariableList = useContextSelector(ChatBoxContext, (v) => v.allVariableList);
const questionGuide = useContextSelector(ChatBoxContext, (v) => v.questionGuide);
const autoExecute = useContextSelector(ChatBoxContext, (v) => v.autoExecute);
const startSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.startSegmentedAudio);
const finishSegmentedAudio = useContextSelector(ChatBoxContext, (v) => v.finishSegmentedAudio);
const setAudioPlayingChatId = useContextSelector(ChatBoxContext, (v) => v.setAudioPlayingChatId);
Expand Down Expand Up @@ -885,8 +886,8 @@ const ChatBox = ({
new Date(item.time).getTime() - new Date(chatRecords[index - 1].time!).getTime() >
10 * 60 * 1000 && <TimeBox time={item.time} />}

<Box py={6}>
{item.obj === ChatRoleEnum.Human && (
<Box py={item.hideInUI ? 0 : 6}>
{item.obj === ChatRoleEnum.Human && !item.hideInUI && (
<ChatItem
type={item.obj}
avatar={userAvatar}
Expand Down Expand Up @@ -999,14 +1000,14 @@ const ChatBox = ({
welcomeText
]);

// useEffect(() => {
// if (isAutoExecute && chatStarted && autoExecute.open) {
// sendPrompt({
// text: autoExecute.defaultPrompt || 'AUTO_EXECUTE',
// hideInUI: true
// });
// }
// }, [isAutoExecute, sendPrompt, chatStarted, autoExecute, chatHistories.length]);
useEffect(() => {
if (autoExecute.open && chatStarted && chatRecords.length === 0) {
sendPrompt({
text: autoExecute.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true
});
}
}, [sendPrompt, chatStarted, autoExecute, chatRecords.length, chatRecords]);

return (
<MyBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { PluginRunBoxTabEnum } from '@/components/core/chat/ChatContainer/Plugin
import CloseIcon from '@fastgpt/web/components/common/Icon/close';
import ChatBox from '@/components/core/chat/ChatContainer/ChatBox';
import { useSystem } from '@fastgpt/web/hooks/useSystem';
import { useQuery } from '@tanstack/react-query';
import { PcHeader } from '@/pages/chat/components/ChatHeader';
import { GetChatTypeEnum } from '@/global/core/chat/constants';
import ChatItemContextProvider, { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
Expand Down
7 changes: 0 additions & 7 deletions projects/app/src/pages/app/detail/components/useChatTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { getInitChatInfo } from '@/web/core/chat/api';
import { useTranslation } from 'next-i18next';
import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';

const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/PluginRunBox'));

Expand Down Expand Up @@ -73,12 +72,6 @@ export const useChatTest = ({
const resetVariables = useContextSelector(ChatItemContext, (v) => v.resetVariables);
const clearChatRecords = useContextSelector(ChatItemContext, (v) => v.clearChatRecords);

const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);

const isAutoExecute = useMemo(() => {
return chatRecords.length === 0 && chatConfig?.autoExecute?.open && nodes.length > 0;
}, [chatConfig?.autoExecute?.open, chatRecords.length, nodes.length]);

const pluginInputs = useMemo(() => {
return nodes.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput)?.inputs || [];
}, [nodes]);
Expand Down
7 changes: 0 additions & 7 deletions projects/app/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
}
);

// const isAutoExecute = useMemo(
// () =>
// !isRecordsLoading && chatRecords.length === 0 && !isLoading && chatConfig?.autoExecute?.open,
// [isRecordsLoading, chatRecords.length, isLoading, chatConfig?.autoExecute?.open]
// );

const onStartChat = useCallback(
async ({
messages,
Expand Down Expand Up @@ -213,7 +207,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
chatType={'chat'}
showRawSource
showNodeStatus
// isAutoExecute={isAutoExecute}
/>
)}
</Box>
Expand Down
23 changes: 2 additions & 21 deletions projects/app/src/pages/chat/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ChatHeader from './components/ChatHeader';
import ChatHistorySlider from './components/ChatHistorySlider';
import { serviceSideProps } from '@/web/common/utils/i18n';
import { useTranslation } from 'next-i18next';
import { delChatRecordById, getInitOutLinkChatInfo } from '@/web/core/chat/api';
import { getInitOutLinkChatInfo } from '@/web/core/chat/api';
import { getChatTitleFromChatMessage } from '@fastgpt/global/core/chat/utils';
import { MongoOutLink } from '@fastgpt/service/support/outLink/schema';
import { OutLinkWithAppType } from '@fastgpt/global/support/outLink/type';
Expand All @@ -26,7 +26,6 @@ import { InitChatResponse } from '@/global/core/chat/api';
import { defaultChatData, GetChatTypeEnum } from '@/global/core/chat/constants';
import { useMount } from 'ahooks';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { getNanoid } from '@fastgpt/global/common/string/tools';

import dynamic from 'next/dynamic';
Expand Down Expand Up @@ -196,23 +195,6 @@ const OutLink = (props: Props) => {
[chatId, customVariables, outLinkAuthData, onUpdateHistoryTitle, forbidLoadChat, onChangeChatId]
);

const loadingCountRef = useRef(0);
// const isAutoExecute = useMemo(() => {
// // 记录非加载状态的次数,用于判断是否真正加载完成
// if (!isRecordsLoading) {
// loadingCountRef.current++;
// }

// // 非加载状态计数超过3次,确保完全加载
// return (
// loadingCountRef.current > 3 &&
// !isRecordsLoading &&
// chatRecords.length === 0 &&
// !isLoading &&
// chatConfig?.autoExecute?.open
// );
// }, [chatConfig?.autoExecute?.open, chatRecords.length, isLoading, isRecordsLoading]);

// window init
const [isEmbed, setIdEmbed] = useState(true);
useMount(() => {
Expand Down Expand Up @@ -291,7 +273,6 @@ const OutLink = (props: Props) => {
chatType="share"
showRawSource={showRawSource}
showNodeStatus={showNodeStatus}
// isAutoExecute={isAutoExecute}
/>
)}
</Box>
Expand Down Expand Up @@ -387,7 +368,7 @@ export async function getServerSideProps(context: any) {

return {
props: {
appId: app?.appId?._id ?? '',
appId: app?.appId?._id?.toString() ?? '',
appName: app?.appId?.name ?? 'AI',
appAvatar: app?.appId?.avatar ?? '',
appIntro: app?.appId?.intro ?? 'AI',
Expand Down
3 changes: 0 additions & 3 deletions projects/app/src/pages/chat/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import NextHead from '@/components/common/NextHead';
import { getTeamChatInfo } from '@/web/core/chat/api';
import { useRouter } from 'next/router';
import { Box, Flex, Drawer, DrawerOverlay, DrawerContent, useTheme } from '@chakra-ui/react';
import { useToast } from '@fastgpt/web/hooks/useToast';
import SideBar from '@/components/SideBar';
import PageContainer from '@/components/PageContainer';
import { getMyTokensApps } from '@/web/core/chat/api';
Expand Down Expand Up @@ -51,7 +50,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
[key: string]: string;
};

const { toast } = useToast();
const theme = useTheme();
const { isPc } = useSystem();

Expand Down Expand Up @@ -222,7 +220,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
chatType="team"
showRawSource
showNodeStatus
// isAutoExecute={isAutoExecute}
/>
)}
</Box>
Expand Down

0 comments on commit d9bda4f

Please sign in to comment.