result.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import StatusPanel from '@/app/components/workflow/run/status'
  5. import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
  6. import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
  7. import useTimestamp from '@/hooks/use-timestamp'
  8. type ResultPanelProps = {
  9. status: string
  10. elapsed_time?: number
  11. total_tokens?: number
  12. error?: string
  13. inputs?: any
  14. outputs?: any
  15. created_by?: string
  16. created_at: string
  17. agentMode?: string
  18. tools?: string[]
  19. iterations?: number
  20. }
  21. const ResultPanel: FC<ResultPanelProps> = ({
  22. elapsed_time,
  23. total_tokens,
  24. error,
  25. inputs,
  26. outputs,
  27. created_by,
  28. created_at,
  29. agentMode,
  30. tools,
  31. iterations,
  32. }) => {
  33. const { t } = useTranslation()
  34. const { formatTime } = useTimestamp()
  35. return (
  36. <div className='bg-white py-2'>
  37. <div className='px-4 py-2'>
  38. <StatusPanel
  39. status='succeeded'
  40. time={elapsed_time}
  41. tokens={total_tokens}
  42. error={error}
  43. />
  44. </div>
  45. <div className='px-4 py-2 flex flex-col gap-2'>
  46. <CodeEditor
  47. readOnly
  48. title={<div>INPUT</div>}
  49. language={CodeLanguage.json}
  50. value={inputs}
  51. isJSONStringifyBeauty
  52. />
  53. <CodeEditor
  54. readOnly
  55. title={<div>OUTPUT</div>}
  56. language={CodeLanguage.json}
  57. value={outputs}
  58. isJSONStringifyBeauty
  59. />
  60. </div>
  61. <div className='px-4 py-2'>
  62. <div className='h-[0.5px] bg-black opacity-5' />
  63. </div>
  64. <div className='px-4 py-2'>
  65. <div className='relative'>
  66. <div className='h-6 leading-6 text-gray-500 text-xs font-medium'>{t('runLog.meta.title')}</div>
  67. <div className='py-1'>
  68. <div className='flex'>
  69. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('runLog.meta.status')}</div>
  70. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  71. <span>SUCCESS</span>
  72. </div>
  73. </div>
  74. <div className='flex'>
  75. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('runLog.meta.executor')}</div>
  76. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  77. <span>{created_by || 'N/A'}</span>
  78. </div>
  79. </div>
  80. <div className='flex'>
  81. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('runLog.meta.startTime')}</div>
  82. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  83. <span>{formatTime(Date.parse(created_at) / 1000, t('appLog.dateTimeFormat') as string)}</span>
  84. </div>
  85. </div>
  86. <div className='flex'>
  87. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('runLog.meta.time')}</div>
  88. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  89. <span>{`${elapsed_time?.toFixed(3)}s`}</span>
  90. </div>
  91. </div>
  92. <div className='flex'>
  93. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('runLog.meta.tokens')}</div>
  94. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  95. <span>{`${total_tokens || 0} Tokens`}</span>
  96. </div>
  97. </div>
  98. <div className='flex'>
  99. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('appLog.agentLogDetail.agentMode')}</div>
  100. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  101. <span>{agentMode === 'function_call' ? t('appDebug.agent.agentModeType.functionCall') : t('appDebug.agent.agentModeType.ReACT')}</span>
  102. </div>
  103. </div>
  104. <div className='flex'>
  105. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('appLog.agentLogDetail.toolUsed')}</div>
  106. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  107. <span>{tools?.length ? tools?.join(', ') : 'Null'}</span>
  108. </div>
  109. </div>
  110. <div className='flex'>
  111. <div className='shrink-0 w-[104px] px-2 py-[5px] text-gray-500 text-xs leading-[18px] truncate'>{t('appLog.agentLogDetail.iterations')}</div>
  112. <div className='grow px-2 py-[5px] text-gray-900 text-xs leading-[18px]'>
  113. <span>{iterations}</span>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. )
  121. }
  122. export default ResultPanel