| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import Indicator from '@/app/components/header/indicator' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import StatusContainer from '@/app/components/workflow/run/status-container' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type ResultProps = { | 
					
						
							|  |  |  |   status: string | 
					
						
							|  |  |  |   time?: number | 
					
						
							|  |  |  |   tokens?: number | 
					
						
							|  |  |  |   error?: string | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |   exceptionCounts?: number | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const StatusPanel: FC<ResultProps> = ({ | 
					
						
							|  |  |  |   status, | 
					
						
							|  |  |  |   time, | 
					
						
							|  |  |  |   tokens, | 
					
						
							|  |  |  |   error, | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |   exceptionCounts, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |     <StatusContainer status={status}> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       <div className='flex'> | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |         <div className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           'max-w-[120px] flex-[33%]', | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |           status === 'partial-succeeded' && 'min-w-[140px]', | 
					
						
							|  |  |  |         )}> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <div className='system-2xs-medium-uppercase mb-1 text-text-tertiary'>{t('runLog.resultPanel.status')}</div> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           <div | 
					
						
							|  |  |  |             className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               'system-xs-semibold-uppercase flex items-center gap-1', | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               status === 'succeeded' && 'text-util-colors-green-green-600', | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |               status === 'partial-succeeded' && 'text-util-colors-green-green-600', | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               status === 'failed' && 'text-util-colors-red-red-600', | 
					
						
							|  |  |  |               status === 'stopped' && 'text-util-colors-warning-warning-600', | 
					
						
							|  |  |  |               status === 'running' && 'text-util-colors-blue-light-blue-light-600', | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             )} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             {status === 'running' && ( | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'blue'} /> | 
					
						
							|  |  |  |                 <span>Running</span> | 
					
						
							|  |  |  |               </> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             )} | 
					
						
							|  |  |  |             {status === 'succeeded' && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'green'} /> | 
					
						
							|  |  |  |                 <span>SUCCESS</span> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             )} | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |             {status === 'partial-succeeded' && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'green'} /> | 
					
						
							|  |  |  |                 <span>PARTIAL SUCCESS</span> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |             {status === 'exception' && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'yellow'} /> | 
					
						
							|  |  |  |                 <span>EXCEPTION</span> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             )} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             {status === 'failed' && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'red'} /> | 
					
						
							|  |  |  |                 <span>FAIL</span> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |             {status === 'stopped' && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <Indicator color={'yellow'} /> | 
					
						
							|  |  |  |                 <span>STOP</span> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className='max-w-[152px] flex-[33%]'> | 
					
						
							|  |  |  |           <div className='system-2xs-medium-uppercase mb-1 text-text-tertiary'>{t('runLog.resultPanel.time')}</div> | 
					
						
							|  |  |  |           <div className='system-sm-medium flex items-center gap-1 text-text-secondary'> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             {status === 'running' && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <div className='h-2 w-16 rounded-sm bg-text-quaternary' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             )} | 
					
						
							|  |  |  |             {status !== 'running' && ( | 
					
						
							| 
									
										
										
										
											2024-09-11 18:24:18 +08:00
										 |  |  |               <span>{time ? `${time?.toFixed(3)}s` : '-'}</span> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             )} | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <div className='flex-[33%]'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <div className='system-2xs-medium-uppercase mb-1 text-text-tertiary'>{t('runLog.resultPanel.tokens')}</div> | 
					
						
							|  |  |  |           <div className='system-sm-medium flex items-center gap-1 text-text-secondary'> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             {status === 'running' && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <div className='h-2 w-20 rounded-sm bg-text-quaternary' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             )} | 
					
						
							|  |  |  |             {status !== 'running' && ( | 
					
						
							|  |  |  |               <span>{`${tokens || 0} Tokens`}</span> | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       {status === 'failed' && error && ( | 
					
						
							|  |  |  |         <> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |           <div className='my-2 h-[0.5px] bg-divider-subtle'/> | 
					
						
							|  |  |  |           <div className='system-xs-regular text-text-destructive'>{error}</div> | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |           { | 
					
						
							|  |  |  |             !!exceptionCounts && ( | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 <div className='my-2 h-[0.5px] bg-divider-subtle'/> | 
					
						
							|  |  |  |                 <div className='system-xs-regular text-text-destructive'> | 
					
						
							|  |  |  |                   {t('workflow.nodes.common.errorHandle.partialSucceeded.tip', { num: exceptionCounts })} | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         </> | 
					
						
							|  |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         status === 'partial-succeeded' && !!exceptionCounts && ( | 
					
						
							|  |  |  |           <> | 
					
						
							|  |  |  |             <div className='my-2 h-[0.5px] bg-divider-deep'/> | 
					
						
							|  |  |  |             <div className='system-xs-medium text-text-warning'> | 
					
						
							|  |  |  |               {t('workflow.nodes.common.errorHandle.partialSucceeded.tip', { num: exceptionCounts })} | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         status === 'exception' && ( | 
					
						
							|  |  |  |           <> | 
					
						
							|  |  |  |             <div className='my-2 h-[0.5px] bg-divider-deep'/> | 
					
						
							|  |  |  |             <div className='system-xs-medium text-text-warning'> | 
					
						
							|  |  |  |               {error} | 
					
						
							|  |  |  |               <a | 
					
						
							| 
									
										
										
										
											2024-12-11 18:03:41 +08:00
										 |  |  |                 href='https://docs.dify.ai/guides/workflow/error-handling/error-type' | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |                 target='_blank' | 
					
						
							|  |  |  |                 className='text-text-accent' | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 {t('workflow.common.learnMore')} | 
					
						
							|  |  |  |               </a> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |     </StatusContainer> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default StatusPanel |