'use client' import { useTranslation } from 'react-i18next' import type { FC } from 'react' import { useCallback, useEffect, useState } from 'react' import cn from 'classnames' import BlockIcon from '../block-icon' import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { AlertCircle, AlertTriangle } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' import { CheckCircle, Loading02 } from '@/app/components/base/icons/src/vender/line/general' import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows' import type { NodeTracing } from '@/types/workflow' type Props = { nodeInfo: NodeTracing hideInfo?: boolean hideProcessDetail?: boolean } const NodePanel: FC = ({ nodeInfo, hideInfo = false, hideProcessDetail, }) => { const [collapseState, doSetCollapseState] = useState(true) const setCollapseState = useCallback((state: boolean) => { if (hideProcessDetail) return doSetCollapseState(state) }, [hideProcessDetail]) const { t } = useTranslation() const getTime = (time: number) => { if (time < 1) return `${(time * 1000).toFixed(3)} ms` if (time > 60) return `${parseInt(Math.round(time / 60).toString())} m ${(time % 60).toFixed(3)} s` return `${time.toFixed(3)} s` } const getTokenCount = (tokens: number) => { if (tokens < 1000) return tokens if (tokens >= 1000 && tokens < 1000000) return `${parseFloat((tokens / 1000).toFixed(3))}K` if (tokens >= 1000000) return `${parseFloat((tokens / 1000000).toFixed(3))}M` } useEffect(() => { setCollapseState(!nodeInfo.expand) }, [nodeInfo.expand, setCollapseState]) return (
setCollapseState(!collapseState)} > {!hideProcessDetail && ( )}
{nodeInfo.title}
{nodeInfo.status !== 'running' && !hideInfo && (
{`${getTime(nodeInfo.elapsed_time || 0)} ยท ${getTokenCount(nodeInfo.execution_metadata?.total_tokens || 0)} tokens`}
)} {nodeInfo.status === 'succeeded' && ( )} {nodeInfo.status === 'failed' && ( )} {nodeInfo.status === 'stopped' && ( )} {nodeInfo.status === 'running' && (
Running
)}
{!collapseState && !hideProcessDetail && (
{nodeInfo.status === 'stopped' && (
{t('workflow.tracing.stopBy', { user: nodeInfo.created_by ? nodeInfo.created_by.name : 'N/A' })}
)} {nodeInfo.status === 'failed' && (
{nodeInfo.error}
)}
{nodeInfo.inputs && (
{t('workflow.common.input').toLocaleUpperCase()}
} language={CodeLanguage.json} value={nodeInfo.inputs} isJSONStringifyBeauty />
)} {nodeInfo.process_data && (
{t('workflow.common.processData').toLocaleUpperCase()}
} language={CodeLanguage.json} value={nodeInfo.process_data} isJSONStringifyBeauty />
)} {nodeInfo.outputs && (
{t('workflow.common.output').toLocaleUpperCase()}
} language={CodeLanguage.json} value={nodeInfo.outputs} isJSONStringifyBeauty />
)} )} ) } export default NodePanel