From 93d116a9d0b816131cb9f60d028c8ef69e58e6cc Mon Sep 17 00:00:00 2001 From: JzoNg Date: Sat, 2 Mar 2024 14:05:05 +0800 Subject: [PATCH] add tracing panel --- .../components/app/workflow-log/detail.tsx | 2 +- web/app/components/workflow/run/node.tsx | 90 +++++++++++++++++++ web/app/components/workflow/run/tracing.tsx | 24 +++-- 3 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 web/app/components/workflow/run/node.tsx diff --git a/web/app/components/app/workflow-log/detail.tsx b/web/app/components/app/workflow-log/detail.tsx index 3b2d7ff269..ee0677e876 100644 --- a/web/app/components/app/workflow-log/detail.tsx +++ b/web/app/components/app/workflow-log/detail.tsx @@ -19,7 +19,7 @@ const DetailPanel: FC = ({ appDetail, onClose }) => {

{t('appLog.runDetail.workflowTitle')}

- + ) } diff --git a/web/app/components/workflow/run/node.tsx b/web/app/components/workflow/run/node.tsx new file mode 100644 index 0000000000..79b1dda0f5 --- /dev/null +++ b/web/app/components/workflow/run/node.tsx @@ -0,0 +1,90 @@ +'use client' +import type { FC } from 'react' +import cn from 'classnames' +import BlockIcon from '../block-icon' +import type { BlockEnum } from '../types' +import { 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' + +export type NodeInfo = { + type: BlockEnum + title: string + time: number + tokens: number + status: string + error?: string +} + +type Props = { + nodeInfo: NodeInfo + collapsed: boolean + collapseHandle: () => void +} + +const NodePanel: FC = ({ nodeInfo, collapsed, collapseHandle }) => { + const getTime = (time: number) => { + if (time < 1) + return `${time * 1000} ms` + if (time > 60) + return `${parseInt(Math.round(time / 60).toString())} m ${(time % 60).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` + } + return ( +
+
+
+ + +
{nodeInfo.title}
+
{`${getTime(nodeInfo.time)} ยท ${getTokenCount(nodeInfo.tokens)} tokens`}
+ {nodeInfo.status === 'succeeded' && ( + + )} + {nodeInfo.status === 'failed' && ( + + )} + {nodeInfo.status === 'stopped' && ( + + )} + {nodeInfo.status === 'running' && ( +
+ + Running +
+ )} +
+ {!collapsed && ( +
+ {/* TODO */} +
+
INPUT
+
+
+
OUPUT
+
+
+ )} +
+
+ ) +} + +export default NodePanel diff --git a/web/app/components/workflow/run/tracing.tsx b/web/app/components/workflow/run/tracing.tsx index 51f54b33aa..adfcc8563a 100644 --- a/web/app/components/workflow/run/tracing.tsx +++ b/web/app/components/workflow/run/tracing.tsx @@ -1,22 +1,34 @@ 'use client' import type { FC } from 'react' -// import React, { useState } from 'react' +import React, { useState } from 'react' import { useTranslation } from 'react-i18next' // import cn from 'classnames' -// import Loading from '@/app/components/base/loading' -// import Indicator from '@/app/components/header/indicator' +import { BlockEnum } from '../types' +import NodePanel from './node' type TracingProps = { appId: string } +const nodeInfoFake = { + type: BlockEnum.Start, + title: 'START', + time: 67.349, + tokens: 2708, + status: 'succeeded', +} + const Tracing: FC = ({ appId }) => { const { t } = useTranslation() - // const [currentTab, setCurrentTab] = useState(activeTab) + const [nodeCollapsed, setCurrentTab] = useState(false) + + const collapseStateChange = () => { + setCurrentTab(!nodeCollapsed) + } return ( -
- Tracing panel = TODO +
+
) }