result-panel.tsx 4.5 KB

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