Files
monkey-ai-web/src/components/smart-router/DecisionTable.jsx
T

174 lines
4.5 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
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, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Empty, Tag } from 'antd';
import { Table } from '@/components/ui';
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
import { listDecisions } from './api';
import { gateText, jevReasonText, srcText } from './labels';
// 判定明细:只读 router_eval_records(§12.3)
const DecisionTable = ({ mode, orgId }) => {
const { t } = useTranslation();
const [data, setData] = useState({ items: [], total: 0 });
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(20);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const load = useCallback(async () => {
setLoading(true);
setError('');
try {
setData(
(await listDecisions(mode, orgId, {
p: page,
page_size: pageSize,
})) || {
items: [],
total: 0,
},
);
} catch (e) {
setError(e?.message || t('加载失败'));
} finally {
setLoading(false);
}
}, [mode, orgId, page, pageSize, t]);
useEffect(() => {
load();
}, [load]);
const columns = [
{
title: t('时间'),
dataIndex: 'created_at',
width: 180,
render: (v) => (
<span className='smart-router-num'>
{new Date(v * 1000).toLocaleString()}
</span>
),
},
{
title: t('虚拟模型'),
dataIndex: 'virtual_model',
width: 180,
render: (v) => <span className='smart-router-mono'>{v}</span>,
},
{
title: t('实际模型'),
dataIndex: 'actual_model',
width: 200,
render: (v) => <span className='smart-router-mono'>{v || '-'}</span>,
},
{
title: t('判定来源'),
dataIndex: 'src',
width: 200,
render: (v, r) => (
<Tag variant='filled' color={v === 'error' ? 'error' : 'blue'}>
{srcText(t, v)}
{r.reason ? ` · ${jevReasonText(t, r.reason)}` : ''}
</Tag>
),
},
{
title: t('任务 / 难度档'),
key: 'task',
width: 140,
render: (_, r) => `${r.task || '-'} / ${r.difficulty_tier}`,
},
{
title: t('合规闸门'),
dataIndex: 'gate',
width: 140,
render: (v) => gateText(t, v),
},
{
title: t('状态码'),
dataIndex: 'status_code',
width: 90,
align: 'right',
render: (v) => <span className='smart-router-num'>{v}</span>,
},
{
title: t('判定耗时'),
dataIndex: 'judge_ms',
width: 110,
align: 'right',
render: (v) => (
<span className='smart-router-num'>{v ? `${v} ms` : '-'}</span>
),
},
];
if (error)
return (
<Alert
type='error'
showIcon
title={error}
action={
<Button size='small' onClick={load}>
{t('重试')}
</Button>
}
/>
);
return (
<Table
rowKey='id'
size='middle'
loading={loading}
columns={columns}
dataSource={data.items || []}
scroll={{ x: 'max-content' }}
empty={
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={t('还没有智能路由请求')}
/>
}
pagination={{
current: page,
pageSize,
total: data.total || 0,
size: 'small',
showSizeChanger: mode === 'org',
onPageSizeChange:
mode === 'org'
? (size) => {
setPage(1);
setPageSize(size);
}
: undefined,
showTotal: (total) => t('共 {{total}} 条', { total }),
onChange: setPage,
}}
/>
);
};
export default DecisionTable;