Files
monkey-ai-web/src/pages/SmartRouter/index.jsx
T
2026-11-18 19:09:00 +08:00

110 lines
3.9 KiB
React

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
ConsoleCard,
ConsoleAlert,
ConsoleTabs,
} from '../../components/console/ConsolePrimitives';
import ProfileTable from '../../components/smart-router/ProfileTable';
import ConsentPanel from '../../components/smart-router/ConsentPanel';
import DecisionTable from '../../components/smart-router/DecisionTable';
import GlobalSettings from '../../components/smart-router/GlobalSettings';
import { isAdmin, isRoot } from '../../helpers';
import '../../components/smart-router/smart-router.css';
// 智能模型路由控制台页(docs/04-渠道与路由/19-智能模型路由方案.md §十二)。
// 页头、顶栏让位与内边距由 ConsolePageContainer 统一(CONSOLE_SPEC §1),页面不再自绘背景。
const SmartRouterPage = () => {
const { t } = useTranslation();
const admin = isAdmin();
const root = isRoot();
const [tab, setTab] = useState(() => {
try {
return localStorage.getItem('smart_router_tab') || 'mine';
} catch (e) {
return 'mine';
}
});
const onTab = (k) => {
setTab(k);
try {
localStorage.setItem('smart_router_tab', k);
} catch (e) {
/* 浏览器存储不可用时忽略 */
}
};
const tabs = useMemo(() => {
const list = [
{ key: 'mine', title: t('我的集合') },
{ key: 'consent', title: t('数据出境授权') },
{ key: 'decisions', title: t('判定明细') },
];
if (admin) {
list.push({ key: 'system', title: t('平台集合') });
list.push({ key: 'all-decisions', title: t('全部判定明细') });
}
if (root) list.push({ key: 'settings', title: t('全局设置') });
return list;
}, [admin, root, t]);
const activeKey = tabs.some((x) => x.key === tab) ? tab : 'mine';
return (
<div className='smart-router-page'>
<ConsoleAlert
className='smart-router-intro'
title={t(
'一个虚拟模型名背后挂多个候选模型,按请求自动选择合适的模型。调用时把模型名写成 router/短名 即可。',
)}
/>
<ConsoleCard className='smart-router-tabs-card'>
<ConsoleTabs
activeKey={activeKey}
onChange={onTab}
items={tabs.map((x) => ({ key: x.key, label: x.title }))}
/>
<div>
{activeKey === 'mine' && (
<ProfileTable
mode='personal'
emptyHint={t('个人集合只对你自己的令牌和 Playground 生效。')}
/>
)}
{activeKey === 'consent' && <ConsentPanel mode='personal' />}
{activeKey === 'decisions' && <DecisionTable mode='personal' />}
{activeKey === 'system' && (
<ProfileTable
mode='admin'
emptyHint={t(
'平台集合对所有用户可用;修改候选会影响所有引用它的令牌,并写入审计日志。',
)}
/>
)}
{activeKey === 'all-decisions' && <DecisionTable mode='admin' />}
{activeKey === 'settings' && <GlobalSettings />}
</div>
</ConsoleCard>
</div>
);
};
export default SmartRouterPage;