index.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useNodes } from 'reactflow'
  4. import { useShallow } from 'zustand/react/shallow'
  5. import type { CommonNodeType } from '../types'
  6. import { Panel as NodePanel } from '../nodes'
  7. import { useStore } from '../store'
  8. import {
  9. useIsChatMode,
  10. } from '../hooks'
  11. import DebugAndPreview from './debug-and-preview'
  12. import Record from './record'
  13. import WorkflowPreview from './workflow-preview'
  14. import ChatRecord from './chat-record'
  15. import ChatVariablePanel from './chat-variable-panel'
  16. import EnvPanel from './env-panel'
  17. import cn from '@/utils/classnames'
  18. import { useStore as useAppStore } from '@/app/components/app/store'
  19. import MessageLogModal from '@/app/components/base/message-log-modal'
  20. const Panel: FC = () => {
  21. const nodes = useNodes<CommonNodeType>()
  22. const isChatMode = useIsChatMode()
  23. const selectedNode = nodes.find(node => node.data.selected)
  24. const historyWorkflowData = useStore(s => s.historyWorkflowData)
  25. const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel)
  26. const showEnvPanel = useStore(s => s.showEnvPanel)
  27. const showChatVariablePanel = useStore(s => s.showChatVariablePanel)
  28. const isRestoring = useStore(s => s.isRestoring)
  29. const { currentLogItem, setCurrentLogItem, showMessageLogModal, setShowMessageLogModal, currentLogModalActiveTab } = useAppStore(useShallow(state => ({
  30. currentLogItem: state.currentLogItem,
  31. setCurrentLogItem: state.setCurrentLogItem,
  32. showMessageLogModal: state.showMessageLogModal,
  33. setShowMessageLogModal: state.setShowMessageLogModal,
  34. currentLogModalActiveTab: state.currentLogModalActiveTab,
  35. })))
  36. return (
  37. <div
  38. tabIndex={-1}
  39. className={cn('absolute top-14 right-0 bottom-2 flex z-10 outline-none')}
  40. key={`${isRestoring}`}
  41. >
  42. {
  43. showMessageLogModal && (
  44. <MessageLogModal
  45. fixedWidth
  46. width={400}
  47. currentLogItem={currentLogItem}
  48. onCancel={() => {
  49. setCurrentLogItem()
  50. setShowMessageLogModal(false)
  51. }}
  52. defaultTab={currentLogModalActiveTab}
  53. />
  54. )
  55. }
  56. {
  57. !!selectedNode && (
  58. <NodePanel {...selectedNode!} />
  59. )
  60. }
  61. {
  62. historyWorkflowData && !isChatMode && (
  63. <Record />
  64. )
  65. }
  66. {
  67. historyWorkflowData && isChatMode && (
  68. <ChatRecord />
  69. )
  70. }
  71. {
  72. showDebugAndPreviewPanel && isChatMode && (
  73. <DebugAndPreview />
  74. )
  75. }
  76. {
  77. showDebugAndPreviewPanel && !isChatMode && (
  78. <WorkflowPreview />
  79. )
  80. }
  81. {
  82. showEnvPanel && (
  83. <EnvPanel />
  84. )
  85. }
  86. {
  87. showChatVariablePanel && (
  88. <ChatVariablePanel />
  89. )
  90. }
  91. </div>
  92. )
  93. }
  94. export default memo(Panel)