result-panel.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import StatusPanel from './status'
  5. import MetaData from './meta'
  6. import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
  7. import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
  8. import ErrorHandleTip from '@/app/components/workflow/nodes/_base/components/error-handle/error-handle-tip'
  9. import type {
  10. AgentLogItemWithChildren,
  11. NodeTracing,
  12. } from '@/types/workflow'
  13. import { BlockEnum } from '@/app/components/workflow/types'
  14. import { hasRetryNode } from '@/app/components/workflow/utils'
  15. import { IterationLogTrigger } from '@/app/components/workflow/run/iteration-log'
  16. import { LoopLogTrigger } from '@/app/components/workflow/run/loop-log'
  17. import { RetryLogTrigger } from '@/app/components/workflow/run/retry-log'
  18. import { AgentLogTrigger } from '@/app/components/workflow/run/agent-log'
  19. type ResultPanelProps = {
  20. nodeInfo?: NodeTracing
  21. inputs?: string
  22. process_data?: string
  23. outputs?: string
  24. status: string
  25. error?: string
  26. elapsed_time?: number
  27. total_tokens?: number
  28. created_at?: number
  29. created_by?: string
  30. finished_at?: number
  31. steps?: number
  32. showSteps?: boolean
  33. exceptionCounts?: number
  34. execution_metadata?: any
  35. handleShowIterationResultList?: (detail: NodeTracing[][], iterDurationMap: any) => void
  36. handleShowLoopResultList?: (detail: NodeTracing[][], loopDurationMap: any) => void
  37. onShowRetryDetail?: (detail: NodeTracing[]) => void
  38. handleShowAgentOrToolLog?: (detail?: AgentLogItemWithChildren) => void
  39. }
  40. const ResultPanel: FC<ResultPanelProps> = ({
  41. nodeInfo,
  42. inputs,
  43. process_data,
  44. outputs,
  45. status,
  46. error,
  47. elapsed_time,
  48. total_tokens,
  49. created_at,
  50. created_by,
  51. steps,
  52. showSteps,
  53. exceptionCounts,
  54. execution_metadata,
  55. handleShowIterationResultList,
  56. handleShowLoopResultList,
  57. onShowRetryDetail,
  58. handleShowAgentOrToolLog,
  59. }) => {
  60. const { t } = useTranslation()
  61. const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration && !!nodeInfo?.details?.length
  62. const isLoopNode = nodeInfo?.node_type === BlockEnum.Loop && !!nodeInfo?.details?.length
  63. const isRetryNode = hasRetryNode(nodeInfo?.node_type) && !!nodeInfo?.retryDetail?.length
  64. const isAgentNode = nodeInfo?.node_type === BlockEnum.Agent && !!nodeInfo?.agentLog?.length
  65. const isToolNode = nodeInfo?.node_type === BlockEnum.Tool && !!nodeInfo?.agentLog?.length
  66. return (
  67. <div className='bg-components-panel-bg py-2'>
  68. <div className='px-4 py-2'>
  69. <StatusPanel
  70. status={status}
  71. time={elapsed_time}
  72. tokens={total_tokens}
  73. error={error}
  74. exceptionCounts={exceptionCounts}
  75. />
  76. </div>
  77. <div className='px-4'>
  78. {
  79. isIterationNode && handleShowIterationResultList && (
  80. <IterationLogTrigger
  81. nodeInfo={nodeInfo}
  82. onShowIterationResultList={handleShowIterationResultList}
  83. />
  84. )
  85. }
  86. {
  87. isLoopNode && handleShowLoopResultList && (
  88. <LoopLogTrigger
  89. nodeInfo={nodeInfo}
  90. onShowLoopResultList={handleShowLoopResultList}
  91. />
  92. )
  93. }
  94. {
  95. isRetryNode && onShowRetryDetail && (
  96. <RetryLogTrigger
  97. nodeInfo={nodeInfo}
  98. onShowRetryResultList={onShowRetryDetail}
  99. />
  100. )
  101. }
  102. {
  103. (isAgentNode || isToolNode) && handleShowAgentOrToolLog && (
  104. <AgentLogTrigger
  105. nodeInfo={nodeInfo}
  106. onShowAgentOrToolLog={handleShowAgentOrToolLog}
  107. />
  108. )
  109. }
  110. </div>
  111. <div className='flex flex-col gap-2 px-4 py-2'>
  112. <CodeEditor
  113. readOnly
  114. title={<div>{t('workflow.common.input').toLocaleUpperCase()}</div>}
  115. language={CodeLanguage.json}
  116. value={inputs}
  117. isJSONStringifyBeauty
  118. />
  119. {process_data && (
  120. <CodeEditor
  121. readOnly
  122. title={<div>{t('workflow.common.processData').toLocaleUpperCase()}</div>}
  123. language={CodeLanguage.json}
  124. value={process_data}
  125. isJSONStringifyBeauty
  126. />
  127. )}
  128. {(outputs || status === 'running') && (
  129. <CodeEditor
  130. readOnly
  131. title={<div>{t('workflow.common.output').toLocaleUpperCase()}</div>}
  132. language={CodeLanguage.json}
  133. value={outputs}
  134. isJSONStringifyBeauty
  135. tip={<ErrorHandleTip type={execution_metadata?.error_strategy} />}
  136. />
  137. )}
  138. </div>
  139. <div className='px-4 py-2'>
  140. <div className='divider-subtle h-[0.5px]' />
  141. </div>
  142. <div className='px-4 py-2'>
  143. <MetaData
  144. status={status}
  145. executor={created_by}
  146. startTime={created_at}
  147. time={elapsed_time}
  148. tokens={total_tokens}
  149. steps={steps}
  150. showSteps={showSteps}
  151. />
  152. </div>
  153. </div>
  154. )
  155. }
  156. export default ResultPanel