result-panel.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. type ResultPanelProps = {
  9. inputs?: string
  10. process_data?: string
  11. outputs?: string
  12. status: string
  13. error?: string
  14. elapsed_time?: number
  15. total_tokens?: number
  16. created_at?: number
  17. created_by?: string
  18. finished_at?: number
  19. steps?: number
  20. showSteps?: boolean
  21. }
  22. const ResultPanel: FC<ResultPanelProps> = ({
  23. inputs,
  24. process_data,
  25. outputs,
  26. status,
  27. error,
  28. elapsed_time,
  29. total_tokens,
  30. created_at,
  31. created_by,
  32. steps,
  33. showSteps,
  34. }) => {
  35. const { t } = useTranslation()
  36. return (
  37. <div className='bg-components-panel-bg py-2'>
  38. <div className='px-4 py-2'>
  39. <StatusPanel
  40. status={status}
  41. time={elapsed_time}
  42. tokens={total_tokens}
  43. error={error}
  44. />
  45. </div>
  46. <div className='px-4 py-2 flex flex-col gap-2'>
  47. <CodeEditor
  48. readOnly
  49. title={<div>{t('workflow.common.input').toLocaleUpperCase()}</div>}
  50. language={CodeLanguage.json}
  51. value={inputs}
  52. isJSONStringifyBeauty
  53. />
  54. {process_data && (
  55. <CodeEditor
  56. readOnly
  57. title={<div>{t('workflow.common.processData').toLocaleUpperCase()}</div>}
  58. language={CodeLanguage.json}
  59. value={process_data}
  60. isJSONStringifyBeauty
  61. />
  62. )}
  63. {(outputs || status === 'running') && (
  64. <CodeEditor
  65. readOnly
  66. title={<div>{t('workflow.common.output').toLocaleUpperCase()}</div>}
  67. language={CodeLanguage.json}
  68. value={outputs}
  69. isJSONStringifyBeauty
  70. />
  71. )}
  72. </div>
  73. <div className='px-4 py-2'>
  74. <div className='h-[0.5px] divider-subtle' />
  75. </div>
  76. <div className='px-4 py-2'>
  77. <MetaData
  78. status={status}
  79. executor={created_by}
  80. startTime={created_at}
  81. time={elapsed_time}
  82. tokens={total_tokens}
  83. steps={steps}
  84. showSteps={showSteps}
  85. />
  86. </div>
  87. </div>
  88. )
  89. }
  90. export default ResultPanel