import EmbedDialog from '@/components/embed-dialog'; import { useShowEmbedModal } from '@/components/embed-dialog/use-show-embed-dialog'; import { PageHeader } from '@/components/page-header'; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from '@/components/ui/breadcrumb'; import { Button, ButtonLoading } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import message from '@/components/ui/message'; import { SharedFrom } from '@/constants/chat'; import { useSetModalState } from '@/hooks/common-hooks'; import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks'; import { ReactFlowProvider } from '@xyflow/react'; import { ChevronDown, CirclePlay, History, LaptopMinimalCheck, Logs, MessageSquareCode, ScreenShare, Settings, Upload, } from 'lucide-react'; import { ComponentPropsWithoutRef, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { useParams } from 'umi'; import AgentCanvas from './canvas'; import { DropdownProvider } from './canvas/context'; import { Operator } from './constant'; import { GlobalParamSheet } from './gobal-variable-sheet'; import { useCancelCurrentDataflow } from './hooks/use-cancel-dataflow'; import { useHandleExportJsonFile } from './hooks/use-export-json'; import { useFetchDataOnMount } from './hooks/use-fetch-data'; import { useFetchPipelineLog } from './hooks/use-fetch-pipeline-log'; import { useGetBeginNodeDataInputs } from './hooks/use-get-begin-query'; import { useIsPipeline } from './hooks/use-is-pipeline'; import { useIsWebhookMode } from './hooks/use-is-webhook'; import { useRunDataflow } from './hooks/use-run-dataflow'; import { useSaveGraph, useSaveGraphBeforeOpeningDebugDrawer, useWatchAgentChange, } from './hooks/use-save-graph'; import { PipelineLogSheet } from './pipeline-log-sheet'; import PipelineRunSheet from './pipeline-run-sheet'; import { SettingDialog } from './setting-dialog'; import useGraphStore from './store'; import { useAgentHistoryManager } from './use-agent-history-manager'; import { VersionDialog } from './version-dialog'; import WebhookSheet from './webhook-sheet'; function AgentDropdownMenuItem({ children, ...props }: ComponentPropsWithoutRef) { return ( {children} ); } export default function Agent() { const { id } = useParams(); const isPipeline = useIsPipeline(); const { navigateToAgents } = useNavigatePage(); const { visible: chatDrawerVisible, hideModal: hideChatDrawer, showModal: showChatDrawer, } = useSetModalState(); const { t } = useTranslation(); useAgentHistoryManager(); const { handleExportJson } = useHandleExportJsonFile(); const { saveGraph, loading } = useSaveGraph(); const { flowDetail: agentDetail } = useFetchDataOnMount(); const inputs = useGetBeginNodeDataInputs(); const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer); const handleRunAgent = useCallback(() => { if (inputs.length > 0) { showChatDrawer(); } else { handleRun(); } }, [handleRun, inputs, showChatDrawer]); const { visible: versionDialogVisible, hideModal: hideVersionDialog, showModal: showVersionDialog, } = useSetModalState(); const { visible: settingDialogVisible, hideModal: hideSettingDialog, showModal: showSettingDialog, } = useSetModalState(); const { showEmbedModal, hideEmbedModal, embedVisible, beta } = useShowEmbedModal(); const { navigateToAgentLogs } = useNavigatePage(); const time = useWatchAgentChange(chatDrawerVisible); const isWebhookMode = useIsWebhookMode(); // pipeline const { visible: pipelineRunSheetVisible, hideModal: hidePipelineRunSheet, showModal: showPipelineRunSheet, } = useSetModalState(); const { visible: webhookTestSheetVisible, hideModal: hideWebhookTestSheet, showModal: showWebhookTestSheet, } = useSetModalState(); const { visible: pipelineLogSheetVisible, showModal: showPipelineLogSheet, hideModal: hidePipelineLogSheet, } = useSetModalState(); const { visible: globalParamSheetVisible, showModal: showGlobalParamSheet, hideModal: hideGlobalParamSheet, } = useSetModalState(); const { isParsing, logs, messageId, setMessageId, isCompleted, stopFetchTrace, isLogEmpty, } = useFetchPipelineLog(pipelineLogSheetVisible); const findNodeByName = useGraphStore((state) => state.findNodeByName); const handleRunPipeline = useCallback(() => { if (!findNodeByName(Operator.Tokenizer)) { message.warning(t('flow.tokenizerRequired')); return; } if (isParsing) { // show log sheet showPipelineLogSheet(); } else { hidePipelineLogSheet(); // handleRun(); showPipelineRunSheet(); } }, [ findNodeByName, hidePipelineLogSheet, isParsing, showPipelineLogSheet, showPipelineRunSheet, t, ]); const { handleCancel } = useCancelCurrentDataflow({ messageId, stopFetchTrace, }); const handleButtonRunClick = useCallback(() => { if (isWebhookMode) { showWebhookTestSheet(); } else if (isPipeline) { handleRunPipeline(); } else { handleRunAgent(); } }, [ handleRunAgent, handleRunPipeline, isPipeline, isWebhookMode, showWebhookTestSheet, ]); const { run: runPipeline, loading: pipelineRunning, uploadedFileData, } = useRunDataflow({ showLogSheet: showPipelineLogSheet, setMessageId }); return (
{t('header.flow')} {agentDetail.title}
{t('flow.autosaved')} {time}
saveGraph()} loading={loading} > {t('flow.save')} showGlobalParamSheet()} loading={loading} > {t('flow.conversationVariable')} {isPipeline || ( )} {t('flow.export')} {t('flow.setting')} {isPipeline || (location.hostname !== 'demo.ragflow.io' && ( <> {t('common.embedIntoSite')} ))}
{embedVisible && ( )} {versionDialogVisible && ( )} {settingDialogVisible && ( )} {pipelineLogSheetVisible && ( )} {pipelineRunSheetVisible && ( )} {globalParamSheetVisible && ( )} {webhookTestSheetVisible && ( )}
); }