| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  | import { memo } from 'react' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { useNodes } from 'reactflow' | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  | import { useShallow } from 'zustand/react/shallow' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import type { CommonNodeType } from '../types' | 
					
						
							|  |  |  | import { Panel as NodePanel } from '../nodes' | 
					
						
							|  |  |  | import { useStore } from '../store' | 
					
						
							| 
									
										
										
										
											2024-04-25 14:02:06 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   useIsChatMode, | 
					
						
							|  |  |  | } from '../hooks' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import DebugAndPreview from './debug-and-preview' | 
					
						
							|  |  |  | import Record from './record' | 
					
						
							|  |  |  | import WorkflowPreview from './workflow-preview' | 
					
						
							|  |  |  | import ChatRecord from './chat-record' | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  | import ChatVariablePanel from './chat-variable-panel' | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | import EnvPanel from './env-panel' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import GlobalVariablePanel from './global-variable-panel' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { useStore as useAppStore } from '@/app/components/app/store' | 
					
						
							|  |  |  | import MessageLogModal from '@/app/components/base/message-log-modal' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Panel: FC = () => { | 
					
						
							|  |  |  |   const nodes = useNodes<CommonNodeType>() | 
					
						
							|  |  |  |   const isChatMode = useIsChatMode() | 
					
						
							|  |  |  |   const selectedNode = nodes.find(node => node.data.selected) | 
					
						
							|  |  |  |   const historyWorkflowData = useStore(s => s.historyWorkflowData) | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |   const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |   const showEnvPanel = useStore(s => s.showEnvPanel) | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  |   const showChatVariablePanel = useStore(s => s.showChatVariablePanel) | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   const showGlobalVariablePanel = useStore(s => s.showGlobalVariablePanel) | 
					
						
							| 
									
										
										
										
											2024-04-24 13:05:33 +08:00
										 |  |  |   const isRestoring = useStore(s => s.isRestoring) | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({ | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |     currentLogItem: state.currentLogItem, | 
					
						
							|  |  |  |     setCurrentLogItem: state.setCurrentLogItem, | 
					
						
							|  |  |  |     showMessageLogModal: state.showMessageLogModal, | 
					
						
							|  |  |  |     setShowMessageLogModal: state.setShowMessageLogModal, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     currentLogModalActiveTab: state.currentLogModalActiveTab, | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |   }))) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2024-04-25 14:02:06 +08:00
										 |  |  |     <div | 
					
						
							|  |  |  |       tabIndex={-1} | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |       className={cn('absolute top-14 right-0 bottom-2 flex z-10 outline-none')} | 
					
						
							| 
									
										
										
										
											2024-04-25 14:02:06 +08:00
										 |  |  |       key={`${isRestoring}`} | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         showMessageLogModal && ( | 
					
						
							|  |  |  |           <MessageLogModal | 
					
						
							|  |  |  |             fixedWidth | 
					
						
							|  |  |  |             width={400} | 
					
						
							|  |  |  |             currentLogItem={currentLogItem} | 
					
						
							|  |  |  |             onCancel={() => { | 
					
						
							|  |  |  |               setCurrentLogItem() | 
					
						
							|  |  |  |               setShowMessageLogModal(false) | 
					
						
							|  |  |  |             }} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             defaultTab={currentLogModalActiveTab} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         !!selectedNode && ( | 
					
						
							|  |  |  |           <NodePanel {...selectedNode!} /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         historyWorkflowData && !isChatMode && ( | 
					
						
							|  |  |  |           <Record /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         historyWorkflowData && isChatMode && ( | 
					
						
							|  |  |  |           <ChatRecord /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |         showDebugAndPreviewPanel && isChatMode && ( | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           <DebugAndPreview /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |         showDebugAndPreviewPanel && !isChatMode && ( | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           <WorkflowPreview /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         showEnvPanel && ( | 
					
						
							|  |  |  |           <EnvPanel /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         showChatVariablePanel && ( | 
					
						
							|  |  |  |           <ChatVariablePanel /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         showGlobalVariablePanel && ( | 
					
						
							|  |  |  |           <GlobalVariablePanel /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default memo(Panel) |