mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
Co-authored-by: Jingyi-Dify <jingyi.qi@dify.ai> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: Bond Zhu <783504079@qq.com> Co-authored-by: Yansong Zhang <916125788@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
'use client'
|
|
|
|
import type { AgentMonitoringChartRow, AgentMonitoringChartType } from './chart-utils'
|
|
import type { I18nKeysWithPrefix } from '@/types/i18n'
|
|
import ReactECharts from 'echarts-for-react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { Infotip } from '@/app/components/base/infotip'
|
|
import {
|
|
buildChartOptions,
|
|
getChartValueField,
|
|
getTokenSummary,
|
|
} from './chart-utils'
|
|
|
|
type AgentMonitoringChartProps = {
|
|
titleKey: I18nKeysWithPrefix<'agentV2', 'agentDetail.monitoring.'>
|
|
explanationKey: I18nKeysWithPrefix<'agentV2', 'agentDetail.monitoring.'>
|
|
summaryValue: string
|
|
rows: AgentMonitoringChartRow[]
|
|
chartType: AgentMonitoringChartType
|
|
valueKey?: string
|
|
unitKey?: I18nKeysWithPrefix<'agentV2', 'agentDetail.monitoring.'>
|
|
yMax?: number
|
|
}
|
|
|
|
export function AgentMonitoringChart({
|
|
titleKey,
|
|
explanationKey,
|
|
summaryValue,
|
|
rows,
|
|
chartType,
|
|
valueKey,
|
|
unitKey,
|
|
yMax,
|
|
}: AgentMonitoringChartProps) {
|
|
const { t } = useTranslation('agentV2')
|
|
const yField = getChartValueField(rows, valueKey)
|
|
const tokenSummary = getTokenSummary(rows)
|
|
const options = buildChartOptions({
|
|
rows,
|
|
chartType,
|
|
valueKey: yField,
|
|
yMax,
|
|
})
|
|
const isEmptySummary = summaryValue === '0' || summaryValue.startsWith('0 ')
|
|
|
|
return (
|
|
<article className="flex min-h-79 w-full min-w-0 flex-col rounded-xl border border-components-panel-border bg-components-chart-bg px-6 pt-6 pb-4 shadow-xs">
|
|
<div className="min-w-0">
|
|
<div className="flex min-w-0 items-center gap-1">
|
|
<h3 className="truncate system-xs-semibold-uppercase text-text-secondary">
|
|
{t(titleKey)}
|
|
</h3>
|
|
<Infotip aria-label={t(explanationKey)}>
|
|
{t(explanationKey)}
|
|
</Infotip>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-2 mb-4 flex min-w-0 items-baseline gap-1">
|
|
<div className={`truncate text-2xl leading-8 font-semibold ${isEmptySummary ? 'text-text-quaternary' : 'text-text-primary'}`}>
|
|
{summaryValue}
|
|
</div>
|
|
{chartType !== 'tokenUsage' && unitKey && (
|
|
<div className="truncate system-sm-regular text-text-secondary">
|
|
{t(unitKey)}
|
|
</div>
|
|
)}
|
|
{chartType === 'tokenUsage' && (
|
|
<div className="truncate system-sm-regular text-text-secondary">
|
|
{t('agentDetail.monitoring.tokenUsageConsumed')}
|
|
{' '}
|
|
<span className="text-util-colors-orange-orange-600">
|
|
(~
|
|
{tokenSummary}
|
|
)
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<ReactECharts option={options} style={{ height: 240 }} />
|
|
</article>
|
|
)
|
|
}
|