2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
131 lines
3.4 KiB
React
131 lines
3.4 KiB
React
import { useMemo } from 'react';
|
|
import { Wallet, Activity, Gauge, Cpu } from 'lucide-react';
|
|
import {
|
|
IconMoneyExchangeStroked,
|
|
IconHistogram,
|
|
IconPulse,
|
|
IconStopwatchStroked,
|
|
IconTypograph,
|
|
IconSend,
|
|
} from '@/components/ui/icons';
|
|
import { renderNumber, renderQuota } from '../../helpers';
|
|
import { createSectionTitle } from '../../helpers/dashboard';
|
|
|
|
export const useDashboardStats = (
|
|
userState,
|
|
consumeQuota,
|
|
consumeTokens,
|
|
times,
|
|
performanceMetrics,
|
|
navigate,
|
|
t,
|
|
tokenUsage = null,
|
|
) => {
|
|
const groupedStatsData = useMemo(
|
|
() => [
|
|
{
|
|
title: createSectionTitle(Wallet, t('钱包概况')),
|
|
color: 'bg-blue-50',
|
|
items: [
|
|
{
|
|
title: t('可用余额'),
|
|
value: renderQuota(userState?.user?.quota),
|
|
icon: <IconMoneyExchangeStroked />,
|
|
avatarColor: 'blue',
|
|
},
|
|
{
|
|
title: t('累计支出'),
|
|
value: renderQuota(userState?.user?.used_quota),
|
|
icon: <IconHistogram />,
|
|
avatarColor: 'purple',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: createSectionTitle(Activity, t('调用活跃度')),
|
|
color: 'bg-green-50',
|
|
items: [
|
|
{
|
|
title: t('总调用次数'),
|
|
value: userState.user?.request_count,
|
|
icon: <IconSend />,
|
|
avatarColor: 'green',
|
|
},
|
|
{
|
|
title: t('有效记录'),
|
|
value: times,
|
|
icon: <IconPulse />,
|
|
avatarColor: 'cyan',
|
|
},
|
|
],
|
|
},
|
|
...(tokenUsage
|
|
? [
|
|
{
|
|
title: createSectionTitle(Cpu, t('Token 流量')),
|
|
color: 'bg-amber-50',
|
|
layout: 'two-column',
|
|
items: [
|
|
{
|
|
title: t('输入 Token'),
|
|
value: renderNumber(tokenUsage.input_tokens || 0),
|
|
icon: <IconTypograph />,
|
|
avatarColor: 'blue',
|
|
},
|
|
{
|
|
title: t('输出 Token'),
|
|
value: renderNumber(tokenUsage.output_tokens || 0),
|
|
icon: <IconSend />,
|
|
avatarColor: 'green',
|
|
},
|
|
{
|
|
title: t('缓存命中'),
|
|
value: renderNumber(tokenUsage.cache_tokens || 0),
|
|
icon: <IconPulse />,
|
|
avatarColor: 'cyan',
|
|
},
|
|
{
|
|
title: t('缓存写入'),
|
|
value: renderNumber(tokenUsage.cache_creation_tokens || 0),
|
|
icon: <IconHistogram />,
|
|
avatarColor: 'orange',
|
|
},
|
|
],
|
|
},
|
|
]
|
|
: []),
|
|
{
|
|
title: createSectionTitle(Gauge, t('实时速率')),
|
|
color: 'bg-brand/5',
|
|
items: [
|
|
{
|
|
title: t('请求速率'),
|
|
value: performanceMetrics.avgRPM,
|
|
icon: <IconStopwatchStroked />,
|
|
avatarColor: 'indigo',
|
|
},
|
|
{
|
|
title: t('Token 速率'),
|
|
value: performanceMetrics.avgTPM,
|
|
icon: <IconTypograph />,
|
|
avatarColor: 'orange',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
[
|
|
userState?.user?.quota,
|
|
userState?.user?.used_quota,
|
|
userState?.user?.request_count,
|
|
times,
|
|
performanceMetrics,
|
|
tokenUsage,
|
|
t,
|
|
],
|
|
);
|
|
|
|
return {
|
|
groupedStatsData,
|
|
};
|
|
};
|