'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.'> yMaxWhenEmpty: number } const hasChartData = (rows: AgentMonitoringChartRow[], valueKey: string) => { return rows.some(row => Number(row[valueKey] ?? 0) !== 0) } export function AgentMonitoringChart({ titleKey, explanationKey, summaryValue, rows, chartType, valueKey, unitKey, yMaxWhenEmpty, }: AgentMonitoringChartProps) { const { t } = useTranslation('agentV2') const yField = getChartValueField(rows, valueKey) const tokenSummary = getTokenSummary(rows) const shouldUseEmptyYAxis = !hasChartData(rows, yField) const options = buildChartOptions({ rows, chartType, valueKey: yField, yMax: shouldUseEmptyYAxis ? yMaxWhenEmpty : undefined, }) const isEmptySummary = Number.parseFloat(summaryValue.replace(/,/g, '')) === 0 return (

{t(titleKey)}

{t(explanationKey)}
{summaryValue}
{chartType !== 'tokenUsage' && unitKey && (
{t(unitKey)}
)} {chartType === 'tokenUsage' && (
{t('agentDetail.monitoring.tokenUsageConsumed')} {' '} (~ {tokenSummary} )
)}
) }