/* 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 . For commercial licensing, please contact support@quantumnous.com */ import React, { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Empty, Modal, Space, Tag, Typography } from 'antd'; import { TableRowActions } from '@/components/common/table/TableToolbar'; import { Table } from '@/components/ui'; import { ConsoleAlert as Alert } from '../console/ConsolePrimitives'; import { Plus } from '../common/icons/ActionIcons'; import { copy, showError, showSuccess } from '../../helpers'; import { deleteProfile, listCandidateModels, listProfiles } from './api'; import ProfileEditor from './ProfileEditor'; import SimulateModal from './SimulateModal'; const { Text } = Typography; const ProfileTable = ({ mode, orgId, canWrite = true, emptyHint }) => { const { t } = useTranslation(); const [list, setList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [editing, setEditing] = useState(null); // null 关闭;{} 新建;profile 编辑 const [simulating, setSimulating] = useState(null); const [models, setModels] = useState([]); const load = useCallback(async () => { setLoading(true); setError(''); try { setList((await listProfiles(mode, orgId)) || []); } catch (e) { setError(e?.message || t('加载失败')); } finally { setLoading(false); } }, [mode, orgId, t]); useEffect(() => { load(); }, [load]); useEffect(() => { if (!canWrite) return; listCandidateModels(mode, orgId) .then(setModels) .catch(() => setModels([])); }, [mode, orgId, canWrite]); const strategyText = (s) => ({ quality: t('质量优先'), balanced: t('平衡'), cost: t('成本优先') })[s] || s; const columns = [ { title: t('虚拟模型'), dataIndex: 'virtual_model', width: 280, render: (v, r) => (
{r.name}
), }, { title: t('策略'), dataIndex: 'strategy', width: 110, render: strategyText, }, { title: t('候选模型'), dataIndex: 'models', width: 100, align: 'right', render: (ms) => ( {(ms || []).filter((m) => m.enabled).length} ), }, { title: t('默认模型'), dataIndex: 'default_model', width: 220, render: (v) => {v}, }, { title: t('状态'), dataIndex: 'status', width: 140, render: (v, r) => ( {v === 1 ? ( {t('启用')} ) : ( {t('停用')} )} {r.jev_allowed && ( Jev )} ), }, { title: t('操作'), key: 'actions', fixed: 'right', width: 180, render: (_, r) => ( setEditing(r), }, canWrite && { key: 'delete', label: t('删除'), danger: true, onClick: () => Modal.confirm({ title: t('确认删除该集合?'), content: t('使用该虚拟模型名的请求将返回"模型不存在"。'), okText: t('确认'), cancelText: t('取消'), okButtonProps: { danger: true }, onOk: async () => { try { await deleteProfile(mode, orgId, r.id); showSuccess(t('已删除')); load(); } catch (e) { if (e?.message) showError(e.message); } }, }), }, ]} > ), }, ]; return (
{emptyHint} {canWrite && ( )}
{error ? ( {t('重试')} } /> ) : ( {canWrite && ( )} } /> )} setEditing(null)} onSaved={() => { setEditing(null); load(); }} /> setSimulating(null)} /> ); }; export default ProfileTable;