You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

result-panel.tsx 5.5KB

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