import { FC } from 'hono/jsx'; import { TopbarNav } from '../components/TopbarNav.js'; import type { ProviderConfig, ModelLimit } from '../../config.js'; interface LimitWithUsage extends ModelLimit { currentUsage: number; periodDesc: string; } interface Props { model: ProviderConfig; limits: LimitWithUsage[]; error?: string; success?: string; } const LIMIT_TYPE_LABELS: Record = { requests: '按请求次数', input_tokens: '按 Token 数', cost: '按金额', }; const PERIOD_LABELS: Record = { hours: '小时', day: '天', week: '周', month: '月', }; export const ModelLimitsPage: FC = (props) => { const { model, limits } = props; return ( 限制规则管理 - {model.customModel}

限制规则管理

模型:{model.customModel} {' '}({model.realModel})

{props.error && (
错误: {props.error}
)} {props.success && (
成功: {props.success}
)} {/* 现有规则列表 */}

现有规则

{limits.length === 0 ? (

暂无限制规则

) : ( {limits.map((limit, index) => ( ))}
类型 周期 数值 使用情况 操作
{LIMIT_TYPE_LABELS[limit.type] || limit.type} {limit.period === 'hours' && limit.periodValue ? `${limit.periodValue} 小时` : PERIOD_LABELS[limit.period] || limit.period} {limit.type === 'cost' ? `$${limit.max}` : `${limit.max}次`}
{limit.type === 'cost' ? `$${limit.currentUsage.toFixed(4)} / $${limit.max}` : `${Math.round(limit.currentUsage)} / ${limit.max}次`}
{limit.period === 'hours' ? `过去 ${limit.periodValue || 24} 小时` : limit.period === 'day' ? '今日' : limit.period === 'week' ? '本周' : '本月'}
)} {/* 添加新规则表单 */}

添加规则