import { memo, useRef, useState, } from 'react' import { useKeyPress } from 'ahooks' import { RiCloseLine, RiEqualizer2Line } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { useNodes } from 'reactflow' import { useEdgesInteractions, useNodesInteractions, useWorkflowInteractions, } from '../../hooks' import { BlockEnum } from '../../types' import type { StartNodeType } from '../../nodes/start/types' import ChatWrapper from './chat-wrapper' import cn from '@/utils/classnames' import { RefreshCcw01 } from '@/app/components/base/icons/src/vender/line/arrows' import { BubbleX } from '@/app/components/base/icons/src/vender/line/others' import Tooltip from '@/app/components/base/tooltip' import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' import { useStore } from '@/app/components/workflow/store' export type ChatWrapperRefType = { handleRestart: () => void } const DebugAndPreview = () => { const { t } = useTranslation() const chatRef = useRef({ handleRestart: () => { } }) const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions() const { handleNodeCancelRunningStatus } = useNodesInteractions() const { handleEdgeCancelRunningStatus } = useEdgesInteractions() const varList = useStore(s => s.conversationVariables) const [expanded, setExpanded] = useState(true) const nodes = useNodes() const startNode = nodes.find(node => node.data.type === BlockEnum.Start) const variables = startNode?.data.variables || [] const [showConversationVariableModal, setShowConversationVariableModal] = useState(false) const handleRestartChat = () => { handleNodeCancelRunningStatus() handleEdgeCancelRunningStatus() chatRef.current.handleRestart() } useKeyPress('shift.r', () => { handleRestartChat() }, { exactMatch: true, }) return (
{t('workflow.common.debugAndPreview').toLocaleUpperCase()}
handleRestartChat()}> {varList.length > 0 && ( setShowConversationVariableModal(true)}> )} {variables.length > 0 && (
setExpanded(!expanded)}> {expanded &&
}
)}
setShowConversationVariableModal(false)} showInputsFieldsPanel={expanded} onHide={() => setExpanded(false)} />
) } export default memo(DebugAndPreview)