sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
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 {
|
||||
Alert,
|
||||
Button,
|
||||
Empty,
|
||||
Modal,
|
||||
Spin,
|
||||
Switch,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { showError, showSuccess } from '../../helpers';
|
||||
import { getConsents, updateConsent } from './api';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const kindText = (t, kind) =>
|
||||
({
|
||||
judge: {
|
||||
title: t('智能判定'),
|
||||
desc: t(
|
||||
'把脱敏、截断后的请求片段发送给境外判定服务(Jev),用于选择合适的模型。',
|
||||
),
|
||||
},
|
||||
eval: {
|
||||
title: t('质量打分'),
|
||||
desc: t(
|
||||
'把脱敏、截断后的请求与回答片段发送给境外判定服务,用于质量评估。',
|
||||
),
|
||||
},
|
||||
shadow: {
|
||||
title: t('影子评审'),
|
||||
desc: t('把正式脱敏后的请求发送给基线模型和评审模型,用于对比质量。'),
|
||||
},
|
||||
replay: {
|
||||
title: t('回放留存'),
|
||||
desc: t('把脱敏后的请求加密留存最多 90 天,用于离线评估。'),
|
||||
},
|
||||
})[kind] || { title: kind, desc: '' };
|
||||
|
||||
// 同意记录(§9.5)。企业同意只能由真实的企业所有者操作。
|
||||
// onChange:授权状态变化后回调最新列表(企业中心"仅授权模式"据此刷新入口)
|
||||
const ConsentPanel = ({ mode, orgId, canWrite = true, onChange }) => {
|
||||
const { t } = useTranslation();
|
||||
const [rows, setRows] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
setRows((await getConsents(mode, orgId)) || []);
|
||||
} catch (e) {
|
||||
setError(e?.message || t('加载失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [mode, orgId, t]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const toggle = (row, granted) => {
|
||||
const text = kindText(t, row.kind);
|
||||
const doIt = async () => {
|
||||
try {
|
||||
const next = await updateConsent(mode, orgId, row.kind, granted);
|
||||
setRows(next);
|
||||
onChange?.(next);
|
||||
showSuccess(granted ? t('已授权') : t('已撤回'));
|
||||
} catch (e) {
|
||||
if (e?.message) showError(e.message);
|
||||
load(); // 写入可能已成功、只是回读失败:重新拉取,避免开关停在旧状态
|
||||
}
|
||||
};
|
||||
if (!granted) return doIt();
|
||||
Modal.confirm({
|
||||
title: `${t('确认授权')} · ${text.title}`,
|
||||
content: (
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Text>{text.desc}</Text>
|
||||
{row.overseas && (
|
||||
<Alert
|
||||
type='warning'
|
||||
showIcon
|
||||
title={t(
|
||||
'该项涉及数据出境(发送到境外服务),可随时撤回,撤回后立即生效。',
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{mode === 'org' && (
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{t('授权后会覆盖企业「数据安全」「不用于训练」功能的默认保护。')}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
onOk: doIt,
|
||||
});
|
||||
};
|
||||
|
||||
if (loading)
|
||||
return (
|
||||
<div className='smart-router-state'>
|
||||
<Spin />
|
||||
</div>
|
||||
);
|
||||
if (error)
|
||||
return (
|
||||
<Alert
|
||||
type='error'
|
||||
showIcon
|
||||
title={error}
|
||||
action={
|
||||
<Button size='small' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
const available = rows.filter((r) => r.available);
|
||||
if (available.length === 0)
|
||||
return (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('平台暂未开放需要授权的智能路由功能')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='smart-router-stack'>
|
||||
{!canWrite && (
|
||||
<Alert
|
||||
type='info'
|
||||
showIcon
|
||||
title={t('企业出境同意只能由企业所有者操作。')}
|
||||
/>
|
||||
)}
|
||||
{available.map((r) => {
|
||||
const text = kindText(t, r.kind);
|
||||
return (
|
||||
<div key={r.kind} className='smart-router-consent-row'>
|
||||
<div className='min-w-0'>
|
||||
<div className='smart-router-consent-head'>
|
||||
<Text strong>{text.title}</Text>
|
||||
{r.overseas && (
|
||||
<Tag color='warning' variant='filled'>
|
||||
{t('境外处理')}
|
||||
</Tag>
|
||||
)}
|
||||
{r.valid ? (
|
||||
<Tag color='success' variant='filled'>
|
||||
{t('已生效')}
|
||||
</Tag>
|
||||
) : r.granted ? (
|
||||
<Tag color='default' variant='filled'>
|
||||
{t('文案已更新,需要重新授权')}
|
||||
</Tag>
|
||||
) : null}
|
||||
</div>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{text.desc}
|
||||
</Text>
|
||||
</div>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={r.valid}
|
||||
disabled={!canWrite}
|
||||
onChange={(v) => toggle(r, v)}
|
||||
aria-label={text.title}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ConsentPanel;
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
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 { Alert, Button, Empty, Table, Tag } from 'antd';
|
||||
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 [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: 20 })) || {
|
||||
items: [],
|
||||
total: 0,
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
setError(e?.message || t('加载失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [mode, orgId, page, 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' }}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由请求')}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
pagination={{
|
||||
// 接口固定 page_size=20,不提供每页条数切换
|
||||
current: page,
|
||||
pageSize: 20,
|
||||
total: data.total || 0,
|
||||
size: 'small',
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
onChange: setPage,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default DecisionTable;
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
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, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Switch,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { showError, showSuccess } from '../../helpers';
|
||||
import { getAdminStatus, loadOptions, saveOption, setJevKey } from './api';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { TextArea } = Input;
|
||||
const PREFIX = 'smart_router_setting.';
|
||||
|
||||
// 字段定义:type 决定编辑控件;compliance=true 的是合规相关(只有 root 能改,后端 rootOnlyOptionKeys)
|
||||
const FIELDS = [
|
||||
{ key: 'enabled', type: 'bool', label: '总开关', section: 'main' },
|
||||
{
|
||||
key: 'rollout_percent',
|
||||
type: 'int',
|
||||
label: '灰度比例(%)',
|
||||
min: 0,
|
||||
max: 100,
|
||||
section: 'main',
|
||||
},
|
||||
{
|
||||
key: 'single_node_ack',
|
||||
type: 'bool',
|
||||
label: '确认为单节点部署(Redis 未启用时必填)',
|
||||
section: 'main',
|
||||
compliance: true,
|
||||
},
|
||||
{
|
||||
key: 'max_profiles_per_user',
|
||||
type: 'int',
|
||||
label: '每人最多个人集合数',
|
||||
min: 0,
|
||||
max: 100,
|
||||
section: 'main',
|
||||
},
|
||||
{
|
||||
key: 'jev_egress_allowed',
|
||||
type: 'bool',
|
||||
label: '允许调用 Jev(数据出境,合规评估通过后开启)',
|
||||
section: 'jev',
|
||||
compliance: true,
|
||||
},
|
||||
{
|
||||
key: 'jev_primary',
|
||||
type: 'select',
|
||||
label: '主通道',
|
||||
options: ['typesafe', 'openrouter'],
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'jev_model_typesafe',
|
||||
type: 'str',
|
||||
label: 'TypeSafe 模型版本',
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'jev_model_openrouter',
|
||||
type: 'str',
|
||||
label: 'OpenRouter 模型版本',
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'judge_budget_ms',
|
||||
type: 'int',
|
||||
label: '判定总预算(毫秒,以国内压测 P95 为准)',
|
||||
min: 20,
|
||||
max: 5000,
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'judge_hedge_enabled',
|
||||
type: 'bool',
|
||||
label: '主备对冲',
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'judge_hedge_after_ms',
|
||||
type: 'int',
|
||||
label: '对冲触发(毫秒,取压测 P80)',
|
||||
min: 1,
|
||||
max: 5000,
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'state_max_bytes',
|
||||
type: 'int',
|
||||
label: '发给 Jev 的内容上限(字节)',
|
||||
min: 1000,
|
||||
max: 30000,
|
||||
section: 'jev',
|
||||
},
|
||||
{
|
||||
key: 'default_tau_quality',
|
||||
type: 'str',
|
||||
label: '质量优先 τ1,τ2,τ3',
|
||||
section: 'judge',
|
||||
},
|
||||
{
|
||||
key: 'default_tau_balanced',
|
||||
type: 'str',
|
||||
label: '平衡 τ1,τ2,τ3',
|
||||
section: 'judge',
|
||||
},
|
||||
{
|
||||
key: 'default_tau_cost',
|
||||
type: 'str',
|
||||
label: '成本优先 τ1,τ2,τ3',
|
||||
section: 'judge',
|
||||
},
|
||||
{
|
||||
key: 'skill_injection_token_reserve',
|
||||
type: 'int',
|
||||
label: 'skill 注入预留 token',
|
||||
min: 0,
|
||||
max: 100000,
|
||||
section: 'judge',
|
||||
},
|
||||
{
|
||||
key: 'strip_incompatible_channel_types',
|
||||
type: 'str',
|
||||
label: '未通过剥离兼容性验证的渠道类型(逗号分隔)',
|
||||
section: 'judge',
|
||||
compliance: true,
|
||||
},
|
||||
{
|
||||
key: 'rules_judge_config',
|
||||
type: 'json',
|
||||
label: '规则判定器关键词与分数(JSON,留空使用内置)',
|
||||
section: 'judge',
|
||||
},
|
||||
{
|
||||
key: 'consent_text_versions',
|
||||
type: 'json',
|
||||
label: '同意文案版本(JSON,如 {"judge":{"v":1,"overseas":true}})',
|
||||
section: 'consent',
|
||||
compliance: true,
|
||||
},
|
||||
{
|
||||
key: 'router_eval_retention_days',
|
||||
type: 'int',
|
||||
label: '判定明细保留天数',
|
||||
min: 1,
|
||||
max: 365,
|
||||
section: 'retention',
|
||||
},
|
||||
{
|
||||
key: 'simulate_daily_cap_per_user',
|
||||
type: 'int',
|
||||
label: '试路由每人每日上限',
|
||||
min: 0,
|
||||
max: 100000,
|
||||
section: 'retention',
|
||||
},
|
||||
{
|
||||
key: 'simulate_daily_cap_per_org',
|
||||
type: 'int',
|
||||
label: '试路由每企业每日上限',
|
||||
min: 0,
|
||||
max: 1000000,
|
||||
section: 'retention',
|
||||
},
|
||||
{
|
||||
key: 'max_profiles_per_org',
|
||||
type: 'int',
|
||||
label: '每个企业最多集合数',
|
||||
min: 0,
|
||||
max: 1000,
|
||||
section: 'retention',
|
||||
},
|
||||
{
|
||||
key: 'jev_daily_cap_per_user',
|
||||
type: 'int',
|
||||
label: 'Jev 判定每人每日上限(0 不限)',
|
||||
min: 0,
|
||||
max: 10000000,
|
||||
section: 'retention',
|
||||
},
|
||||
{
|
||||
key: 'jev_daily_cap_per_org',
|
||||
type: 'int',
|
||||
label: 'Jev 判定每企业每日上限(0 不限)',
|
||||
min: 0,
|
||||
max: 100000000,
|
||||
section: 'retention',
|
||||
},
|
||||
];
|
||||
|
||||
const SECTIONS = [
|
||||
['main', '总控'],
|
||||
['jev', 'Jev 判定'],
|
||||
['judge', '判定参数'],
|
||||
['consent', '同意文案'],
|
||||
['retention', '保留与限流'],
|
||||
];
|
||||
|
||||
// 保存顺序:前置条件(single_node_ack)必须先于依赖它的总开关保存
|
||||
const SAVE_ORDER = ['single_node_ack', 'consent_text_versions'];
|
||||
|
||||
const GlobalSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const [values, setValues] = useState({});
|
||||
const [original, setOriginal] = useState({});
|
||||
const [status, setStatus] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [keys, setKeys] = useState({ typesafe: '', openrouter: '' });
|
||||
const tRef = useRef(t);
|
||||
tRef.current = t;
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setLoadError('');
|
||||
try {
|
||||
const data = await loadOptions();
|
||||
const v = {};
|
||||
(data || []).forEach((item) => {
|
||||
if (item.key.startsWith(PREFIX))
|
||||
v[item.key.slice(PREFIX.length)] = item.value;
|
||||
});
|
||||
setValues(v);
|
||||
setOriginal(v);
|
||||
setStatus(await getAdminStatus());
|
||||
} catch (e) {
|
||||
setLoadError(e?.message || tRef.current('加载失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []); // 不依赖 t:切换语言不能重新加载并丢掉未保存的编辑
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const save = async () => {
|
||||
const changed = FIELDS.filter(
|
||||
(f) => String(values[f.key] ?? '') !== String(original[f.key] ?? ''),
|
||||
).sort((a, b) => {
|
||||
const ia = SAVE_ORDER.indexOf(a.key);
|
||||
const ib = SAVE_ORDER.indexOf(b.key);
|
||||
return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib);
|
||||
});
|
||||
if (changed.length === 0) {
|
||||
showSuccess(t('配置未修改'));
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
const saved = {};
|
||||
try {
|
||||
for (const f of changed) {
|
||||
try {
|
||||
await saveOption(PREFIX + f.key, String(values[f.key] ?? ''));
|
||||
saved[f.key] = values[f.key];
|
||||
} catch (e) {
|
||||
showError(`${t(f.label)} · ${e?.message || ''}`);
|
||||
// 已保存的项更新基线,未保存的编辑保留在表单里,便于修改后重试
|
||||
setOriginal((o) => ({ ...o, ...saved }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
showSuccess(t('已保存'));
|
||||
await load();
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveKey = async (provider, clear = false) => {
|
||||
const run = async () => {
|
||||
try {
|
||||
await setJevKey(provider, keys[provider], clear);
|
||||
setKeys((k) => ({ ...k, [provider]: '' }));
|
||||
showSuccess(clear ? t('已清除') : t('已保存'));
|
||||
setStatus(await getAdminStatus());
|
||||
} catch (e) {
|
||||
showError(e?.message || t('保存失败,请稍后重试'));
|
||||
}
|
||||
};
|
||||
if (!clear) return run();
|
||||
Modal.confirm({
|
||||
title: t('确认清除密钥?'),
|
||||
content: t('清除后该通道无法调用 Jev,判定会降级为规则判定。'),
|
||||
okButtonProps: { danger: true },
|
||||
onOk: run,
|
||||
});
|
||||
};
|
||||
|
||||
const renderField = (f) => {
|
||||
const v = values[f.key];
|
||||
const set = (nv) => setValues((s) => ({ ...s, [f.key]: nv }));
|
||||
switch (f.type) {
|
||||
case 'bool':
|
||||
return (
|
||||
<Switch
|
||||
checked={v === 'true'}
|
||||
onChange={(c) => set(c ? 'true' : 'false')}
|
||||
aria-label={t(f.label)}
|
||||
/>
|
||||
);
|
||||
case 'int':
|
||||
return (
|
||||
<InputNumber
|
||||
style={{ width: 200 }}
|
||||
min={f.min}
|
||||
max={f.max}
|
||||
value={Number(v) || 0}
|
||||
onChange={(raw) => {
|
||||
// antd 清空时回调 null,按原 Semi 的空串语义回落到最小值
|
||||
const n = raw ?? '';
|
||||
set(
|
||||
String(
|
||||
Number.isFinite(Number(n)) && n !== ''
|
||||
? Number(n)
|
||||
: (f.min ?? 0),
|
||||
),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
case 'select':
|
||||
return (
|
||||
<Select
|
||||
style={{ width: 200 }}
|
||||
value={v}
|
||||
options={f.options.map((o) => ({ label: o, value: o }))}
|
||||
onChange={set}
|
||||
/>
|
||||
);
|
||||
case 'json':
|
||||
return (
|
||||
<TextArea
|
||||
className='smart-router-mono'
|
||||
autoSize={{ minRows: 2, maxRows: 10 }}
|
||||
value={v}
|
||||
onChange={(e) => set(e.target.value)}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
return (
|
||||
<Input
|
||||
style={{ maxWidth: 360 }}
|
||||
value={v}
|
||||
onChange={(e) => set(e.target.value)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading)
|
||||
return (
|
||||
<div className='smart-router-state'>
|
||||
<Spin />
|
||||
</div>
|
||||
);
|
||||
if (loadError)
|
||||
return (
|
||||
<Alert
|
||||
type='error'
|
||||
showIcon
|
||||
title={loadError}
|
||||
action={
|
||||
<Button size='small' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='smart-router-stack'>
|
||||
{status && (
|
||||
<div className='smart-router-card'>
|
||||
<div className='smart-router-card-title'>{t('运行状态')}</div>
|
||||
<Space size={8} wrap>
|
||||
<Tag color={status.session_store_ready ? 'success' : 'error'}>
|
||||
{status.session_store_ready
|
||||
? t('共享会话存储就绪')
|
||||
: t('共享会话存储未就绪')}
|
||||
</Tag>
|
||||
<Tag color={status.redis_enabled ? 'success' : 'default'}>
|
||||
Redis {status.redis_enabled ? t('已启用') : t('未启用')}
|
||||
</Tag>
|
||||
<Tag color={status.typesafe_key_set ? 'success' : 'default'}>
|
||||
TypeSafe{' '}
|
||||
{status.typesafe_key_set ? t('密钥已设置') : t('未设置密钥')}
|
||||
</Tag>
|
||||
<Tag color={status.openrouter_key_set ? 'success' : 'default'}>
|
||||
OpenRouter{' '}
|
||||
{status.openrouter_key_set ? t('密钥已设置') : t('未设置密钥')}
|
||||
</Tag>
|
||||
{status.typesafe_breaker && (
|
||||
<Tag color='error'>{t('TypeSafe 熔断中')}</Tag>
|
||||
)}
|
||||
{status.openrouter_breaker && (
|
||||
<Tag color='error'>{t('OpenRouter 熔断中')}</Tag>
|
||||
)}
|
||||
<Tag>
|
||||
{t('会话写入失败')}{' '}
|
||||
<span className='smart-router-num'>
|
||||
{status.session_write_fail}
|
||||
</span>
|
||||
</Tag>
|
||||
<Tag>
|
||||
{t('评估记录丢弃')}{' '}
|
||||
<span className='smart-router-num'>{status.eval_dropped}</span>
|
||||
</Tag>
|
||||
<Tag>
|
||||
{t('会话读取失败')}{' '}
|
||||
<span className='smart-router-num'>
|
||||
{status.session_read_fail}
|
||||
</span>
|
||||
</Tag>
|
||||
<Tag>
|
||||
{t('Jev 降级次数')}{' '}
|
||||
<span className='smart-router-num'>{status.jev_fallback}</span>
|
||||
</Tag>
|
||||
<Tag color={status.not_ready ? 'warning' : 'default'}>
|
||||
{t('存储未就绪拒绝')}{' '}
|
||||
<span className='smart-router-num'>{status.not_ready}</span>
|
||||
</Tag>
|
||||
</Space>
|
||||
<div className='smart-router-section'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{t('以上计数为当前节点进程内累计值,进程重启后清零')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Alert
|
||||
type='warning'
|
||||
showIcon
|
||||
title={t(
|
||||
'标注「合规」的配置项只有超级管理员可以修改。开启 Jev 出境前须完成合规评估。',
|
||||
)}
|
||||
/>
|
||||
{SECTIONS.map(([sec, title]) => (
|
||||
<div key={sec} className='smart-router-card'>
|
||||
<div className='smart-router-card-title'>{t(title)}</div>
|
||||
{/* 受控字段沿用 values 状态,Form 只提供竖排标签布局,不接管取值与提交 */}
|
||||
<Form layout='vertical' component='div' requiredMark={false}>
|
||||
{FIELDS.filter((f) => f.section === sec).map((f) => (
|
||||
<Form.Item
|
||||
key={f.key}
|
||||
label={
|
||||
<span className='smart-router-field-label'>
|
||||
{t(f.label)}
|
||||
{f.compliance && (
|
||||
<Tag color='warning' variant='filled'>
|
||||
{t('合规')}
|
||||
</Tag>
|
||||
)}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
{renderField(f)}
|
||||
</Form.Item>
|
||||
))}
|
||||
{sec === 'jev' &&
|
||||
['typesafe', 'openrouter'].map((p) => (
|
||||
<Form.Item
|
||||
key={p}
|
||||
label={
|
||||
<span className='smart-router-field-label'>
|
||||
{p === 'typesafe'
|
||||
? t('TypeSafe 密钥')
|
||||
: t('OpenRouter 密钥')}
|
||||
({t('加密存储,只有超级管理员可修改')})
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Space size={8} wrap>
|
||||
<Input.Password
|
||||
style={{ width: 320 }}
|
||||
placeholder={t('输入新密钥;留空表示不修改')}
|
||||
value={keys[p]}
|
||||
onChange={(e) =>
|
||||
setKeys((k) => ({ ...k, [p]: e.target.value }))
|
||||
}
|
||||
/>
|
||||
<Button onClick={() => saveKey(p)} disabled={!keys[p]}>
|
||||
{t('保存密钥')}
|
||||
</Button>
|
||||
<Button
|
||||
danger
|
||||
disabled={
|
||||
!(p === 'typesafe'
|
||||
? status?.typesafe_key_set
|
||||
: status?.openrouter_key_set)
|
||||
}
|
||||
onClick={() => saveKey(p, true)}
|
||||
>
|
||||
{t('清除')}
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
))}
|
||||
</Form>
|
||||
</div>
|
||||
))}
|
||||
<div>
|
||||
<Button type='primary' loading={saving} onClick={save}>
|
||||
{t('保存设置')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSettings;
|
||||
@@ -0,0 +1,954 @@
|
||||
/*
|
||||
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, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
Collapse,
|
||||
Drawer,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Modal,
|
||||
Select,
|
||||
Switch,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { Plus, Trash2 } from '../common/icons/ActionIcons';
|
||||
import { showError, showSuccess } from '../../helpers';
|
||||
import { saveProfile } from './api';
|
||||
|
||||
const { TextArea } = Input;
|
||||
|
||||
// 等价 Semi Select 的 filter + allowCreate:可搜索,输入的新模型名作为临时选项出现,
|
||||
// 只有选中后才回调 onChange(与原行为一致,不在每次键入时写值)。
|
||||
const CreatableSelect = ({ options, value, onChange, ...props }) => {
|
||||
const [search, setSearch] = useState('');
|
||||
const keyword = search.trim();
|
||||
const merged =
|
||||
keyword && !options.some((o) => o.value === keyword)
|
||||
? [...options, { label: keyword, value: keyword }]
|
||||
: options;
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
showSearch
|
||||
optionFilterProp='label'
|
||||
value={value}
|
||||
options={merged}
|
||||
onSearch={setSearch}
|
||||
onChange={(v) => {
|
||||
setSearch('');
|
||||
onChange(v);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const RULES_LABELS = [
|
||||
'coding',
|
||||
'math',
|
||||
'translate',
|
||||
'extract',
|
||||
'analysis',
|
||||
'writing',
|
||||
'chat',
|
||||
'general',
|
||||
];
|
||||
|
||||
const LABEL_PATTERN = /^[a-z0-9_]{1,32}$/;
|
||||
|
||||
let uidSeq = 0;
|
||||
const uid = () => `l${Date.now().toString(36)}${(uidSeq += 1)}`;
|
||||
|
||||
const defaultLabels = (t) =>
|
||||
[
|
||||
['coding', '编写、修改、调试、解释代码'],
|
||||
['math', '数学计算、推导、证明'],
|
||||
['writing', '创作、改写、润色长文本'],
|
||||
['analysis', '数据分析、方案对比、专业问答'],
|
||||
['extract', '信息抽取、格式转换、分类'],
|
||||
['translate', '翻译'],
|
||||
['chat', '闲聊、简单查询'],
|
||||
['general', '无法归入以上类别的请求'],
|
||||
].map(([name, desc]) => ({
|
||||
id: uid(),
|
||||
name,
|
||||
desc: t(desc),
|
||||
rules_label: '',
|
||||
}));
|
||||
|
||||
const emptyCaps = {
|
||||
vision: false,
|
||||
tools: false,
|
||||
json_mode: false,
|
||||
reasoning: false,
|
||||
max_context: 0,
|
||||
};
|
||||
|
||||
const parseCaps = (raw) => {
|
||||
if (!raw) return { ...emptyCaps };
|
||||
try {
|
||||
return {
|
||||
...emptyCaps,
|
||||
...(typeof raw === 'string' ? JSON.parse(raw) : raw),
|
||||
};
|
||||
} catch (e) {
|
||||
return { ...emptyCaps };
|
||||
}
|
||||
};
|
||||
|
||||
const emptyRow = () => ['', '', '', ''];
|
||||
|
||||
// 矩阵按标签的稳定 id 存储:改名时不搬动行,保存时再按名字重建(避免改名到已有名字时覆盖别的行)
|
||||
const toState = (profile, t) => {
|
||||
if (!profile) {
|
||||
const labels = defaultLabels(t);
|
||||
return {
|
||||
slug: '',
|
||||
name: '',
|
||||
description: '',
|
||||
strategy: 'balanced',
|
||||
tier_thresholds: '',
|
||||
min_task_conf: 0,
|
||||
reasoning_threshold: 0,
|
||||
reasoning_model: '',
|
||||
default_model: '',
|
||||
baseline_model: '',
|
||||
sticky_enabled: true,
|
||||
sticky_ttl_sec: 1800,
|
||||
jev_allowed: false,
|
||||
status: 1,
|
||||
labels,
|
||||
matrix: Object.fromEntries(labels.map((l) => [l.id, emptyRow()])),
|
||||
rules: '[]',
|
||||
models: [],
|
||||
};
|
||||
}
|
||||
const labels = (profile.task_labels_obj || []).map((l) => ({
|
||||
id: uid(),
|
||||
name: l.name,
|
||||
desc: l.desc || '',
|
||||
rules_label: l.rules_label || '',
|
||||
}));
|
||||
const matrix = {};
|
||||
labels.forEach((l) => {
|
||||
const row = (profile.matrix_obj || {})[l.name] || [];
|
||||
matrix[l.id] = [0, 1, 2, 3].map((i) => row[i] || '');
|
||||
});
|
||||
return {
|
||||
id: profile.id,
|
||||
slug: profile.slug,
|
||||
name: profile.name,
|
||||
description: profile.description,
|
||||
strategy: profile.strategy,
|
||||
tier_thresholds: profile.tier_thresholds || '',
|
||||
min_task_conf: profile.min_task_conf || 0,
|
||||
reasoning_threshold: profile.reasoning_threshold || 0,
|
||||
reasoning_model: profile.reasoning_model || '',
|
||||
default_model: profile.default_model,
|
||||
baseline_model: profile.baseline_model,
|
||||
sticky_enabled: profile.sticky_enabled,
|
||||
sticky_ttl_sec: profile.sticky_ttl_sec || 1800,
|
||||
jev_allowed: profile.jev_allowed,
|
||||
status: profile.status,
|
||||
labels,
|
||||
matrix,
|
||||
rules: JSON.stringify(profile.rules_obj || [], null, 2),
|
||||
models: (profile.models || []).map((m) => ({
|
||||
model_name: m.model_name,
|
||||
model_tier: m.model_tier,
|
||||
description: m.description || '',
|
||||
enabled: m.enabled,
|
||||
caps: parseCaps(m.capabilities),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
// 一键生成:按能力档把候选分配到 4 列(只作为初始值,§8.6)
|
||||
const autoMatrix = (labels, models) => {
|
||||
const enabled = models.filter((m) => m.model_name && m.enabled);
|
||||
if (enabled.length === 0) return null;
|
||||
const sorted = [...enabled].sort((a, b) => a.model_tier - b.model_tier);
|
||||
const col = (k) => {
|
||||
const hit = sorted.find((m) => m.model_tier >= k);
|
||||
return (hit || sorted[sorted.length - 1]).model_name;
|
||||
};
|
||||
const row = [col(0), col(1), col(2), col(3)];
|
||||
return Object.fromEntries(labels.map((l) => [l.id, [...row]]));
|
||||
};
|
||||
|
||||
// 替换矩阵与角色字段中对某个候选名的引用
|
||||
const replaceModelRefs = (s, from, to) => {
|
||||
if (!from) return s;
|
||||
const matrix = {};
|
||||
Object.entries(s.matrix).forEach(([k, row]) => {
|
||||
matrix[k] = row.map((c) => (c === from ? to : c));
|
||||
});
|
||||
const swap = (v) => (v === from ? to : v);
|
||||
return {
|
||||
...s,
|
||||
matrix,
|
||||
default_model: swap(s.default_model),
|
||||
baseline_model: swap(s.baseline_model),
|
||||
reasoning_model: swap(s.reasoning_model),
|
||||
};
|
||||
};
|
||||
|
||||
const ProfileEditor = ({
|
||||
visible,
|
||||
mode,
|
||||
orgId,
|
||||
profile,
|
||||
candidateModels,
|
||||
onClose,
|
||||
onSaved,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [state, setState] = useState(() => toState(profile, t));
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [activePanels, setActivePanels] = useState([
|
||||
'basic',
|
||||
'models',
|
||||
'matrix',
|
||||
'roles',
|
||||
]);
|
||||
// 进入编辑时 general 行的标签 id:只锁定这一行,避免改名成 general 后整行被锁死
|
||||
const generalIdRef = useRef(null);
|
||||
|
||||
// 只在打开抽屉(或换了要编辑的集合)时重置;切换语言不能清掉未保存的编辑
|
||||
const tRef = useRef(t);
|
||||
tRef.current = t;
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
const next = toState(profile, tRef.current);
|
||||
generalIdRef.current =
|
||||
next.labels.find((l) => l.name === 'general')?.id || null;
|
||||
setState(next);
|
||||
setActivePanels(['basic', 'models', 'matrix', 'roles']);
|
||||
}
|
||||
}, [visible, profile]);
|
||||
|
||||
const set = (k, v) => setState((s) => ({ ...s, [k]: v }));
|
||||
const candidateNames = useMemo(
|
||||
() => state.models.map((m) => m.model_name).filter(Boolean),
|
||||
[state.models],
|
||||
);
|
||||
const candidateOptions = candidateNames.map((m) => ({ label: m, value: m }));
|
||||
const modelOptions = useMemo(
|
||||
() => (candidateModels || []).map((m) => ({ label: m, value: m })),
|
||||
[candidateModels],
|
||||
);
|
||||
const duplicateLabels = useMemo(() => {
|
||||
const seen = new Set();
|
||||
const dup = new Set();
|
||||
state.labels.forEach((l) => {
|
||||
if (seen.has(l.name)) dup.add(l.name);
|
||||
seen.add(l.name);
|
||||
});
|
||||
return dup;
|
||||
}, [state.labels]);
|
||||
|
||||
const updateModel = (idx, patch) =>
|
||||
setState((s) => {
|
||||
let next = s;
|
||||
if (patch.model_name !== undefined) {
|
||||
const from = s.models[idx].model_name;
|
||||
const usedElsewhere = (name) =>
|
||||
s.models.some((m, i) => i !== idx && m.model_name === name);
|
||||
// 改名时同步替换矩阵与角色字段中的引用;新旧名字被其他行占用时不级联,避免误改别的候选的引用
|
||||
if (from && !usedElsewhere(from) && !usedElsewhere(patch.model_name)) {
|
||||
next = replaceModelRefs(s, from, patch.model_name);
|
||||
}
|
||||
}
|
||||
const models = next.models.map((m, i) =>
|
||||
i === idx ? { ...m, ...patch } : m,
|
||||
);
|
||||
return { ...next, models };
|
||||
});
|
||||
const updateCaps = (idx, patch) =>
|
||||
setState((s) => ({
|
||||
...s,
|
||||
models: s.models.map((m, i) =>
|
||||
i === idx ? { ...m, caps: { ...m.caps, ...patch } } : m,
|
||||
),
|
||||
}));
|
||||
const removeModel = (idx) => {
|
||||
const removed = state.models[idx]?.model_name;
|
||||
const general = state.matrix[generalIdRef.current] || [];
|
||||
if (removed && general.includes(removed)) {
|
||||
showError(t('该模型在 general 行中被引用,请先替换 general 行的单元格'));
|
||||
return;
|
||||
}
|
||||
setState((s) => {
|
||||
const stillUsed = s.models.some(
|
||||
(m, i) => i !== idx && m.model_name === removed,
|
||||
);
|
||||
const next = stillUsed ? s : replaceModelRefs(s, removed, '');
|
||||
return { ...next, models: next.models.filter((_, i) => i !== idx) };
|
||||
});
|
||||
};
|
||||
|
||||
const updateLabel = (id, patch) =>
|
||||
setState((s) => ({
|
||||
...s,
|
||||
labels: s.labels.map((l) => (l.id === id ? { ...l, ...patch } : l)),
|
||||
}));
|
||||
const removeLabel = (id) =>
|
||||
setState((s) => {
|
||||
const matrix = { ...s.matrix };
|
||||
delete matrix[id];
|
||||
return { ...s, labels: s.labels.filter((l) => l.id !== id), matrix };
|
||||
});
|
||||
const addLabel = () =>
|
||||
setState((s) => {
|
||||
const names = new Set(s.labels.map((l) => l.name));
|
||||
let n = s.labels.length + 1;
|
||||
while (names.has(`label_${n}`)) n += 1;
|
||||
const id = uid();
|
||||
return {
|
||||
...s,
|
||||
labels: [
|
||||
...s.labels,
|
||||
{ id, name: `label_${n}`, desc: '', rules_label: '' },
|
||||
],
|
||||
matrix: { ...s.matrix, [id]: emptyRow() },
|
||||
};
|
||||
});
|
||||
|
||||
const setCell = (id, col, value) =>
|
||||
setState((s) => {
|
||||
const row = [...(s.matrix[id] || emptyRow())];
|
||||
row[col] = value || '';
|
||||
return { ...s, matrix: { ...s.matrix, [id]: row } };
|
||||
});
|
||||
|
||||
const applyAutoMatrix = () => {
|
||||
const next = autoMatrix(state.labels, state.models);
|
||||
if (!next) {
|
||||
showError(t('请先添加并启用候选模型'));
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: t('一键生成(仅作为初始值)'),
|
||||
content: t('会覆盖当前矩阵中的全部单元格,是否继续?'),
|
||||
onOk: () => set('matrix', next),
|
||||
});
|
||||
};
|
||||
|
||||
// 保存前的客户端检查:把必填项问题指向对应面板,避免只看到后端报错
|
||||
const precheck = () => {
|
||||
if (!state.id && !/^[a-z0-9][a-z0-9-]{0,47}$/.test(state.slug.trim())) {
|
||||
return ['basic', t('短名只允许小写字母、数字和连字符,最长 48 个字符')];
|
||||
}
|
||||
if (state.models.some((m) => !m.model_name)) {
|
||||
return ['models', t('有候选模型还没有选择模型名')];
|
||||
}
|
||||
if (candidateNames.length === 0)
|
||||
return ['models', t('至少需要一个候选模型')];
|
||||
if (new Set(candidateNames).size !== candidateNames.length) {
|
||||
return ['models', t('候选模型不能重复')];
|
||||
}
|
||||
for (const l of state.labels) {
|
||||
if (!LABEL_PATTERN.test(l.name)) {
|
||||
return [
|
||||
'labels',
|
||||
t('任务标签只允许小写字母、数字和下划线,最长 32 个字符'),
|
||||
];
|
||||
}
|
||||
}
|
||||
if (duplicateLabels.size > 0) return ['labels', t('任务标签不能重名')];
|
||||
if (!state.labels.some((l) => l.name === 'general')) {
|
||||
return ['labels', t('任务标签必须包含 general')];
|
||||
}
|
||||
const general = state.labels.find((l) => l.name === 'general');
|
||||
if ((state.matrix[general.id] || []).some((c) => !c)) {
|
||||
return ['matrix', t('general 行的 4 个单元格必须全部填写')];
|
||||
}
|
||||
if (!state.default_model) return ['roles', t('请选择默认模型')];
|
||||
if (!state.baseline_model) return ['roles', t('请选择基线模型')];
|
||||
// 自定义规则引用的模型 / 行必须仍然存在(改名、删除后容易遗漏)
|
||||
try {
|
||||
const rules = JSON.parse(state.rules || '[]');
|
||||
const labelNames = new Set(state.labels.map((l) => l.name));
|
||||
for (let i = 0; i < (Array.isArray(rules) ? rules.length : 0); i += 1) {
|
||||
const th = rules[i]?.then || {};
|
||||
if (
|
||||
(th.model && !candidateNames.includes(th.model)) ||
|
||||
(th.row && !labelNames.has(th.row))
|
||||
) {
|
||||
return [
|
||||
'rules',
|
||||
`${t('自定义规则引用了不存在的模型或行')} #${i + 1}`,
|
||||
];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// JSON 格式错误在保存时单独提示
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
const problem = precheck();
|
||||
if (problem) {
|
||||
setActivePanels((p) => (p.includes(problem[0]) ? p : [...p, problem[0]]));
|
||||
showError(problem[1]);
|
||||
return;
|
||||
}
|
||||
let rules;
|
||||
try {
|
||||
rules = JSON.parse(state.rules || '[]');
|
||||
if (!Array.isArray(rules)) throw new Error('not array');
|
||||
} catch (e) {
|
||||
setActivePanels((p) => (p.includes('rules') ? p : [...p, 'rules']));
|
||||
showError(t('自定义规则必须是合法的 JSON 数组'));
|
||||
return;
|
||||
}
|
||||
const matrix = {};
|
||||
state.labels.forEach((l) => {
|
||||
matrix[l.name] = [...(state.matrix[l.id] || emptyRow())].slice(0, 4);
|
||||
});
|
||||
const payload = {
|
||||
id: state.id,
|
||||
slug: state.slug.trim(),
|
||||
name: state.name,
|
||||
description: state.description,
|
||||
mode: 'matrix',
|
||||
strategy: state.strategy,
|
||||
tier_thresholds: state.tier_thresholds,
|
||||
min_task_conf: Number(state.min_task_conf) || 0,
|
||||
reasoning_threshold: Number(state.reasoning_threshold) || 0,
|
||||
reasoning_model: state.reasoning_model || '',
|
||||
default_model: state.default_model || '',
|
||||
baseline_model: state.baseline_model || '',
|
||||
sticky_enabled: state.sticky_enabled,
|
||||
sticky_ttl_sec: Number(state.sticky_ttl_sec) || 1800,
|
||||
jev_allowed: state.jev_allowed,
|
||||
status: state.status,
|
||||
task_labels: state.labels.map((l) => ({
|
||||
name: l.name.trim(),
|
||||
desc: l.desc,
|
||||
...(l.rules_label ? { rules_label: l.rules_label } : {}),
|
||||
})),
|
||||
difficulty_levels: profile?.difficulty_levels_obj || undefined,
|
||||
matrix,
|
||||
rules,
|
||||
models: state.models.map((m) => ({
|
||||
model_name: m.model_name,
|
||||
model_tier: Number(m.model_tier) || 0,
|
||||
description: m.description,
|
||||
enabled: m.enabled,
|
||||
capabilities: {
|
||||
...m.caps,
|
||||
max_context: Number(m.caps.max_context) || 0,
|
||||
},
|
||||
})),
|
||||
};
|
||||
setSaving(true);
|
||||
try {
|
||||
await saveProfile(mode, orgId, payload);
|
||||
showSuccess(t('已保存'));
|
||||
onSaved?.();
|
||||
} catch (e) {
|
||||
showError(e?.message || t('保存失败,请稍后重试'));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const tierOptions = [0, 1, 2, 3, 4].map((v) => ({
|
||||
label: `${t('能力档')} ${v}`,
|
||||
value: v,
|
||||
}));
|
||||
const strategyOptions = [
|
||||
{ label: t('质量优先'), value: 'quality' },
|
||||
{ label: t('平衡'), value: 'balanced' },
|
||||
{ label: t('成本优先'), value: 'cost' },
|
||||
];
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
rootClassName='smart-router-sheet'
|
||||
open={visible}
|
||||
onClose={onClose}
|
||||
size={Math.min(
|
||||
820,
|
||||
typeof window !== 'undefined' ? window.innerWidth : 820,
|
||||
)}
|
||||
title={profile ? t('编辑智能路由集合') : t('新建智能路由集合')}
|
||||
footer={
|
||||
<div className='smart-router-sheet-footer'>
|
||||
<Button onClick={onClose}>{t('取消')}</Button>
|
||||
<Button type='primary' loading={saving} onClick={handleSave}>
|
||||
{t('保存')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{/* 字段均为受控 state;Form 只提供竖排标签与间距,不接管取值、校验与提交 */}
|
||||
<Form layout='vertical' component='div' requiredMark={false}>
|
||||
<Collapse
|
||||
activeKey={activePanels}
|
||||
onChange={(keys) => setActivePanels(keys || [])}
|
||||
items={[
|
||||
{
|
||||
key: 'basic',
|
||||
label: t('基本信息'),
|
||||
children: (
|
||||
<div className='smart-router-grid'>
|
||||
<Form.Item
|
||||
label={t(
|
||||
'短名(虚拟模型名为 router/短名,创建后不可修改)',
|
||||
)}
|
||||
>
|
||||
<Input
|
||||
value={state.slug}
|
||||
disabled={!!state.id}
|
||||
prefix='router/'
|
||||
onChange={(e) =>
|
||||
set('slug', e.target.value.toLowerCase())
|
||||
}
|
||||
placeholder='coding'
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('名称')}>
|
||||
<Input
|
||||
value={state.name}
|
||||
onChange={(e) => set('name', e.target.value)}
|
||||
maxLength={64}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
className='smart-router-grid-full'
|
||||
label={t('说明')}
|
||||
>
|
||||
<Input
|
||||
value={state.description}
|
||||
onChange={(e) => set('description', e.target.value)}
|
||||
maxLength={255}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('策略')}>
|
||||
<Select
|
||||
value={state.strategy}
|
||||
options={strategyOptions}
|
||||
onChange={(v) => set('strategy', v)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t('高级:难度档阈值 τ1,τ2,τ3(留空使用策略默认值)')}
|
||||
>
|
||||
<Input
|
||||
value={state.tier_thresholds}
|
||||
onChange={(e) => set('tier_thresholds', e.target.value)}
|
||||
placeholder='0.45,0.50,0.55'
|
||||
/>
|
||||
</Form.Item>
|
||||
<div className='smart-router-inline'>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={state.status === 1}
|
||||
onChange={(v) => set('status', v ? 1 : 2)}
|
||||
aria-label={t('启用')}
|
||||
/>
|
||||
<Text>{t('启用')}</Text>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'models',
|
||||
label: t('候选模型'),
|
||||
children: (
|
||||
<div className='smart-router-stack'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{t(
|
||||
'能力档 0~4:数值越大能力越强;推理模型通常配为 4。能力标签用于按请求过滤候选。',
|
||||
)}
|
||||
</Text>
|
||||
{state.models.map((m, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className='smart-router-card smart-router-card--compact'
|
||||
>
|
||||
<div className='smart-router-inline'>
|
||||
<CreatableSelect
|
||||
className='smart-router-model-select'
|
||||
value={m.model_name || undefined}
|
||||
options={modelOptions.filter(
|
||||
(o) =>
|
||||
o.value === m.model_name ||
|
||||
!state.models.some(
|
||||
(x, i) => i !== idx && x.model_name === o.value,
|
||||
),
|
||||
)}
|
||||
placeholder={t('选择模型')}
|
||||
aria-label={t('选择模型')}
|
||||
onChange={(v) =>
|
||||
updateModel(idx, { model_name: v || '' })
|
||||
}
|
||||
/>
|
||||
<Select
|
||||
style={{ width: 150 }}
|
||||
value={m.model_tier}
|
||||
options={tierOptions}
|
||||
aria-label={t('能力档')}
|
||||
onChange={(v) => updateModel(idx, { model_tier: v })}
|
||||
/>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={m.enabled}
|
||||
onChange={(v) => updateModel(idx, { enabled: v })}
|
||||
aria-label={t('启用')}
|
||||
/>
|
||||
<Button
|
||||
type='text'
|
||||
danger
|
||||
icon={<Trash2 size={16} />}
|
||||
aria-label={t('删除')}
|
||||
onClick={() => removeModel(idx)}
|
||||
/>
|
||||
</div>
|
||||
<div className='smart-router-inline smart-router-section'>
|
||||
<Checkbox
|
||||
checked={m.caps.vision}
|
||||
onChange={(e) =>
|
||||
updateCaps(idx, { vision: e.target.checked })
|
||||
}
|
||||
>
|
||||
{t('图片输入')}
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={m.caps.tools}
|
||||
onChange={(e) =>
|
||||
updateCaps(idx, { tools: e.target.checked })
|
||||
}
|
||||
>
|
||||
{t('工具调用')}
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={m.caps.json_mode}
|
||||
onChange={(e) =>
|
||||
updateCaps(idx, { json_mode: e.target.checked })
|
||||
}
|
||||
>
|
||||
{t('JSON 输出')}
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={m.caps.reasoning}
|
||||
onChange={(e) =>
|
||||
updateCaps(idx, { reasoning: e.target.checked })
|
||||
}
|
||||
>
|
||||
{t('推理模型')}
|
||||
</Checkbox>
|
||||
<InputNumber
|
||||
style={{ width: 200 }}
|
||||
prefix={t('上下文')}
|
||||
min={0}
|
||||
value={m.caps.max_context}
|
||||
onChange={(v) =>
|
||||
updateCaps(idx, { max_context: Number(v) || 0 })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div>
|
||||
<Button
|
||||
icon={<Plus size={16} />}
|
||||
onClick={() =>
|
||||
set('models', [
|
||||
...state.models,
|
||||
{
|
||||
model_name: '',
|
||||
model_tier: 1,
|
||||
description: '',
|
||||
enabled: true,
|
||||
caps: { ...emptyCaps },
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
{t('添加候选模型')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'labels',
|
||||
label: t('任务标签'),
|
||||
children: (
|
||||
<div className='smart-router-stack'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{t(
|
||||
'标签修改后,任务置信度阈值建议观察 7 天后再调整。必须包含 general。',
|
||||
)}
|
||||
</Text>
|
||||
{state.labels.map((l) => {
|
||||
const locked = l.id === generalIdRef.current;
|
||||
const invalid =
|
||||
duplicateLabels.has(l.name) ||
|
||||
!LABEL_PATTERN.test(l.name);
|
||||
return (
|
||||
<div key={l.id} className='smart-router-inline'>
|
||||
<Input
|
||||
style={{ width: 160 }}
|
||||
value={l.name}
|
||||
disabled={locked}
|
||||
status={invalid ? 'error' : undefined}
|
||||
aria-label={t('任务类型')}
|
||||
onChange={(e) =>
|
||||
updateLabel(l.id, {
|
||||
name: e.target.value.toLowerCase(),
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
style={{ flex: 1, minWidth: 200 }}
|
||||
value={l.desc}
|
||||
aria-label={t('说明')}
|
||||
onChange={(e) =>
|
||||
updateLabel(l.id, { desc: e.target.value })
|
||||
}
|
||||
/>
|
||||
<Select
|
||||
style={{ width: 170 }}
|
||||
placeholder={t('对应规则判定器标签')}
|
||||
allowClear
|
||||
value={l.rules_label || undefined}
|
||||
options={RULES_LABELS.map((x) => ({
|
||||
label: x,
|
||||
value: x,
|
||||
}))}
|
||||
onChange={(v) =>
|
||||
updateLabel(l.id, { rules_label: v || '' })
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
type='text'
|
||||
danger
|
||||
icon={<Trash2 size={16} />}
|
||||
disabled={locked}
|
||||
aria-label={t('删除')}
|
||||
onClick={() => removeLabel(l.id)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{duplicateLabels.size > 0 && (
|
||||
<Text type='danger' className='smart-router-sub'>
|
||||
{t('任务标签不能重名')}
|
||||
</Text>
|
||||
)}
|
||||
<div>
|
||||
<Button
|
||||
icon={<Plus size={16} />}
|
||||
disabled={state.labels.length >= 32}
|
||||
onClick={addLabel}
|
||||
>
|
||||
{t('添加标签')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'matrix',
|
||||
label: t('路由矩阵'),
|
||||
children: (
|
||||
<div className='smart-router-stack'>
|
||||
<div className='smart-router-toolbar'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{t('行是任务类型,列是难度档;general 行必须全部填写。')}
|
||||
</Text>
|
||||
<Button onClick={applyAutoMatrix}>
|
||||
{t('一键生成(仅作为初始值)')}
|
||||
</Button>
|
||||
</div>
|
||||
<div className='smart-router-matrix'>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t('任务类型')}</th>
|
||||
<th>{t('0 简单')}</th>
|
||||
<th>{t('1 常规')}</th>
|
||||
<th>{t('2 较难')}</th>
|
||||
<th>{t('3 困难')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{state.labels.map((l) => (
|
||||
<tr key={l.id}>
|
||||
<td className='smart-router-mono smart-router-sub'>
|
||||
{l.name}
|
||||
</td>
|
||||
{[0, 1, 2, 3].map((col) => (
|
||||
<td key={col}>
|
||||
<Select
|
||||
style={{ width: 150 }}
|
||||
size='small'
|
||||
allowClear={l.name !== 'general'}
|
||||
value={
|
||||
(state.matrix[l.id] || [])[col] || undefined
|
||||
}
|
||||
options={candidateOptions}
|
||||
aria-label={`${l.name} · ${col}`}
|
||||
onChange={(v) => setCell(l.id, col, v)}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'roles',
|
||||
label: t('模型角色与阈值'),
|
||||
children: (
|
||||
<div className='smart-router-grid'>
|
||||
<Form.Item label={t('默认模型(判定失败时使用)')}>
|
||||
<Select
|
||||
value={state.default_model || undefined}
|
||||
options={candidateOptions}
|
||||
onChange={(v) => set('default_model', v || '')}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t('基线模型(用于节省率,必须出现在矩阵中)')}
|
||||
>
|
||||
<Select
|
||||
value={state.baseline_model || undefined}
|
||||
options={candidateOptions}
|
||||
onChange={(v) => set('baseline_model', v || '')}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('推理模型(可选)')}>
|
||||
<Select
|
||||
allowClear
|
||||
value={state.reasoning_model || undefined}
|
||||
options={candidateOptions}
|
||||
onChange={(v) => set('reasoning_model', v || '')}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('推理阈值(0 表示默认 0.7)')}>
|
||||
<InputNumber
|
||||
className='w-full'
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={state.reasoning_threshold}
|
||||
onChange={(v) =>
|
||||
set('reasoning_threshold', Number(v) || 0)
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label={t('任务置信度下限(0 表示默认)')}>
|
||||
<InputNumber
|
||||
className='w-full'
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={state.min_task_conf}
|
||||
onChange={(v) => set('min_task_conf', Number(v) || 0)}
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'session',
|
||||
label: t('会话与判定'),
|
||||
children: (
|
||||
<div className='smart-router-stack'>
|
||||
<div className='smart-router-inline'>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={state.sticky_enabled}
|
||||
onChange={(v) => set('sticky_enabled', v)}
|
||||
aria-label={t('会话粘性(只升档不降档)')}
|
||||
/>
|
||||
<Text>{t('会话粘性(只升档不降档)')}</Text>
|
||||
<InputNumber
|
||||
style={{ width: 220 }}
|
||||
prefix={t('有效期(秒)')}
|
||||
min={60}
|
||||
max={86400}
|
||||
value={state.sticky_ttl_sec}
|
||||
onChange={(v) => set('sticky_ttl_sec', Number(v) || 1800)}
|
||||
/>
|
||||
</div>
|
||||
<div className='smart-router-inline'>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={state.jev_allowed}
|
||||
onChange={(v) => set('jev_allowed', v)}
|
||||
aria-label={t(
|
||||
'允许使用 Jev 判定(还需平台开启与出境同意)',
|
||||
)}
|
||||
/>
|
||||
<Text>
|
||||
{t('允许使用 Jev 判定(还需平台开启与出境同意)')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'rules',
|
||||
label: t('自定义规则(高级)'),
|
||||
children: (
|
||||
<div className='smart-router-stack'>
|
||||
<Alert
|
||||
type='info'
|
||||
showIcon
|
||||
title={t(
|
||||
'JSON 数组,按顺序第一条命中即生效。动作:model 直接指定模型;tier(可带 row)强制难度档;tier_min / tier_max 约束区间。',
|
||||
)}
|
||||
/>
|
||||
<TextArea
|
||||
className='smart-router-mono'
|
||||
autoSize={{ minRows: 6, maxRows: 16 }}
|
||||
value={state.rules}
|
||||
aria-label={t('自定义规则(高级)')}
|
||||
onChange={(e) => set('rules', e.target.value)}
|
||||
placeholder='[{"if":{"user_contains":"review"},"then":{"tier":3,"row":"coding"}}]'
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Form>
|
||||
</Drawer>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProfileEditor;
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
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 {
|
||||
Alert,
|
||||
Button,
|
||||
Empty,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
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) => (
|
||||
<div className='min-w-0'>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
className='smart-router-mono smart-router-copy'
|
||||
aria-label={`${t('复制')} ${v}`}
|
||||
onClick={async () => {
|
||||
if (await copy(v)) showSuccess(t('已复制'));
|
||||
}}
|
||||
>
|
||||
{v}
|
||||
</Button>
|
||||
<div>
|
||||
<Text
|
||||
type='secondary'
|
||||
className='smart-router-sub smart-router-name'
|
||||
ellipsis={{ tooltip: r.name }}
|
||||
>
|
||||
{r.name}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('策略'),
|
||||
dataIndex: 'strategy',
|
||||
width: 110,
|
||||
render: strategyText,
|
||||
},
|
||||
{
|
||||
title: t('候选模型'),
|
||||
dataIndex: 'models',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (ms) => (
|
||||
<span className='smart-router-num'>
|
||||
{(ms || []).filter((m) => m.enabled).length}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('默认模型'),
|
||||
dataIndex: 'default_model',
|
||||
width: 220,
|
||||
render: (v) => <span className='smart-router-mono'>{v}</span>,
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 140,
|
||||
render: (v, r) => (
|
||||
<Space size={8}>
|
||||
{v === 1 ? (
|
||||
<Tag color='success' variant='filled'>
|
||||
{t('启用')}
|
||||
</Tag>
|
||||
) : (
|
||||
<Tag color='default' variant='filled'>
|
||||
{t('停用')}
|
||||
</Tag>
|
||||
)}
|
||||
{r.jev_allowed && (
|
||||
<Tag color='blue' variant='filled'>
|
||||
Jev
|
||||
</Tag>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
key: 'actions',
|
||||
fixed: 'right',
|
||||
width: 180,
|
||||
render: (_, r) => (
|
||||
<Space size={8} wrap>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => setSimulating(r)}
|
||||
disabled={!canWrite}
|
||||
>
|
||||
{t('试路由')}
|
||||
</Button>
|
||||
{canWrite && (
|
||||
<>
|
||||
<Button type='link' size='small' onClick={() => setEditing(r)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title={t('确认删除该集合?')}
|
||||
description={t('使用该虚拟模型名的请求将返回"模型不存在"。')}
|
||||
okButtonProps={{ danger: true }}
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
await deleteProfile(mode, orgId, r.id);
|
||||
showSuccess(t('已删除'));
|
||||
load();
|
||||
} catch (e) {
|
||||
if (e?.message) showError(e.message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='smart-router-stack'>
|
||||
<div className='smart-router-toolbar'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{emptyHint}
|
||||
</Text>
|
||||
{canWrite && (
|
||||
<Button
|
||||
type='primary'
|
||||
icon={<Plus size={16} />}
|
||||
onClick={() => setEditing({})}
|
||||
>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{error ? (
|
||||
<Alert
|
||||
type='error'
|
||||
showIcon
|
||||
title={error}
|
||||
action={
|
||||
<Button size='small' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Table
|
||||
rowKey='id'
|
||||
size='middle'
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
pagination={false}
|
||||
scroll={{ x: 'max-content' }}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由集合')}
|
||||
>
|
||||
{canWrite && (
|
||||
<Button type='primary' onClick={() => setEditing({})}>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</Empty>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<ProfileEditor
|
||||
visible={editing !== null}
|
||||
mode={mode}
|
||||
orgId={orgId}
|
||||
profile={editing && editing.id ? editing : null}
|
||||
candidateModels={models}
|
||||
onClose={() => setEditing(null)}
|
||||
onSaved={() => {
|
||||
setEditing(null);
|
||||
load();
|
||||
}}
|
||||
/>
|
||||
<SimulateModal
|
||||
visible={!!simulating}
|
||||
mode={mode}
|
||||
orgId={orgId}
|
||||
profile={simulating}
|
||||
onClose={() => setSimulating(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProfileTable;
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
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, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Alert, Button, Input, Modal, Progress, Tag, Typography } from 'antd';
|
||||
import { simulateProfile } from './api';
|
||||
import { gateText, reasonText, srcText } from './labels';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { TextArea } = Input;
|
||||
|
||||
const ProbBars = ({ probs }) => {
|
||||
if (!probs) return null;
|
||||
const entries = Array.isArray(probs)
|
||||
? probs.map((v, i) => [String(i), v])
|
||||
: Object.entries(probs).sort((a, b) => b[1] - a[1]);
|
||||
return (
|
||||
<div className='smart-router-prob-list'>
|
||||
{entries.map(([k, v]) => (
|
||||
<div key={k} className='smart-router-prob'>
|
||||
<span className='smart-router-mono smart-router-prob-label'>{k}</span>
|
||||
<Progress
|
||||
className='smart-router-prob-bar'
|
||||
percent={Math.round((v || 0) * 100)}
|
||||
showInfo={false}
|
||||
size='small'
|
||||
/>
|
||||
<span className='smart-router-num smart-router-prob-value'>
|
||||
{Math.round((v || 0) * 100)}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const SimulateModal = ({ visible, mode, orgId, profile, onClose }) => {
|
||||
const { t } = useTranslation();
|
||||
const [prompt, setPrompt] = useState('');
|
||||
const [system, setSystem] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [result, setResult] = useState(null);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setResult(null);
|
||||
setError('');
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
// 换了集合就清空上一次的输入
|
||||
useEffect(() => {
|
||||
setPrompt('');
|
||||
setSystem('');
|
||||
}, [profile?.id]);
|
||||
|
||||
const run = async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
setResult(
|
||||
await simulateProfile(mode, orgId, profile.id, { prompt, system }),
|
||||
);
|
||||
} catch (e) {
|
||||
setError(e?.message || t('试路由失败,请稍后重试'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
rootClassName='smart-router-sheet'
|
||||
open={visible}
|
||||
title={`${t('试路由')} · router/${profile?.slug || ''}`}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
width={760}
|
||||
>
|
||||
<div className='smart-router-stack'>
|
||||
<TextArea
|
||||
autoSize={{ minRows: 2, maxRows: 4 }}
|
||||
placeholder={t('可选:system 提示词')}
|
||||
aria-label={t('可选:system 提示词')}
|
||||
value={system}
|
||||
onChange={(e) => setSystem(e.target.value)}
|
||||
/>
|
||||
<TextArea
|
||||
autoSize={{ minRows: 4, maxRows: 10 }}
|
||||
placeholder={t('粘贴一段要路由的用户请求')}
|
||||
aria-label={t('粘贴一段要路由的用户请求')}
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
/>
|
||||
<div>
|
||||
<Button
|
||||
type='primary'
|
||||
loading={loading}
|
||||
disabled={!prompt.trim()}
|
||||
onClick={run}
|
||||
>
|
||||
{t('试路由')}
|
||||
</Button>
|
||||
</div>
|
||||
{error && <Alert type='error' showIcon title={error} />}
|
||||
{result && (
|
||||
<div className='smart-router-card'>
|
||||
{result.error ? (
|
||||
<Alert type='warning' showIcon title={result.error} />
|
||||
) : (
|
||||
<dl className='smart-router-kv'>
|
||||
<dt>{t('实际模型')}</dt>
|
||||
<dd>
|
||||
<span className='smart-router-mono'>{result.model}</span>{' '}
|
||||
<Tag variant='filled'>
|
||||
{t('能力档')} {result.model_tier}
|
||||
</Tag>
|
||||
</dd>
|
||||
<dt>{t('判定来源')}</dt>
|
||||
<dd>
|
||||
<Tag variant='filled' color='blue'>
|
||||
{srcText(t, result.src)}
|
||||
</Tag>{' '}
|
||||
<span className='smart-router-mono'>{result.why}</span>
|
||||
</dd>
|
||||
<dt>{t('合规闸门')}</dt>
|
||||
<dd>{gateText(t, result.gate)}</dd>
|
||||
<dt>{t('任务 / 难度档')}</dt>
|
||||
<dd>
|
||||
{result.task} /{' '}
|
||||
<span className='smart-router-num'>
|
||||
{result.difficulty_tier}
|
||||
</span>
|
||||
</dd>
|
||||
<dt>{t('规则判定器')}</dt>
|
||||
<dd>
|
||||
{result.rules_task} /{' '}
|
||||
<span className='smart-router-num'>{result.rules_tier}</span>
|
||||
</dd>
|
||||
{result.judge_ms > 0 && (
|
||||
<>
|
||||
<dt>{t('判定耗时')}</dt>
|
||||
<dd className='smart-router-num'>{result.judge_ms} ms</dd>
|
||||
</>
|
||||
)}
|
||||
<dt>{t('基线模型')}</dt>
|
||||
<dd className='smart-router-mono'>{result.baseline_model}</dd>
|
||||
{result.features && (
|
||||
<>
|
||||
<dt>{t('请求特征')}</dt>
|
||||
<dd className='smart-router-num'>
|
||||
{t('预估 token')} {result.features.est_tokens} ·{' '}
|
||||
{t('对话 token')} {result.features.conv_tokens} ·{' '}
|
||||
{t('用户轮次')} {result.features.user_turns}
|
||||
</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
)}
|
||||
{result.task_probs && Object.keys(result.task_probs).length > 0 && (
|
||||
<div className='smart-router-section'>
|
||||
<Text strong>{t('任务类型概率')}</Text>
|
||||
<ProbBars probs={result.task_probs} />
|
||||
</div>
|
||||
)}
|
||||
{result.difficulty_probs && result.difficulty_probs.length > 0 && (
|
||||
<div className='smart-router-section'>
|
||||
<Text strong>{t('难度概率')}</Text>
|
||||
<ProbBars probs={result.difficulty_probs} />
|
||||
</div>
|
||||
)}
|
||||
{result.filtered && Object.keys(result.filtered).length > 0 && (
|
||||
<div className='smart-router-section'>
|
||||
<Text strong>{t('被过滤的候选')}</Text>
|
||||
<div className='smart-router-tags'>
|
||||
{Object.entries(result.filtered).map(([m, r]) => (
|
||||
<Tag key={m} variant='filled' color='default'>
|
||||
{m} · {reasonText(t, r)}
|
||||
</Tag>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SimulateModal;
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
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 { API, showError } from '../../helpers';
|
||||
import i18n from '../../i18n/i18n';
|
||||
|
||||
// 智能模型路由接口(后端 router/smart-router.go)。
|
||||
// mode: personal(个人)/ admin(平台 system 集合)/ org(企业,X-Org-Id 由 API 拦截器注入)
|
||||
// 所有请求都跳过全局错误提示(skipErrorHandler),由调用方只弹一次业务文案,避免英文报错与重复提示。
|
||||
export const routerBase = (mode) => {
|
||||
if (mode === 'admin') return '/api/router/admin';
|
||||
if (mode === 'org') return '/api/org/router';
|
||||
return '/api/router';
|
||||
};
|
||||
|
||||
const opts = (orgId, extra = {}) => ({
|
||||
skipErrorHandler: true,
|
||||
...(orgId ? { headers: { 'X-Org-Id': String(orgId) } } : {}),
|
||||
...extra,
|
||||
});
|
||||
|
||||
const friendly = (e) => {
|
||||
const msg = e?.response?.data?.message;
|
||||
if (msg) return msg;
|
||||
const status = e?.response?.status;
|
||||
if (status === 429) return i18n.t('操作过于频繁,请稍后再试');
|
||||
if (status === 401 || status === 403) return i18n.t('没有权限执行该操作');
|
||||
return i18n.t('请求失败,请稍后重试');
|
||||
};
|
||||
|
||||
const call = async (fn) => {
|
||||
let res;
|
||||
try {
|
||||
res = await fn();
|
||||
} catch (e) {
|
||||
// 401 交给全局处理:清理登录态并跳转登录页(skipErrorHandler 会跳过它)。
|
||||
// 之后不再抛出,调用方也就不会再弹一次"没有权限"——页面马上会跳走
|
||||
if (e?.response?.status === 401) {
|
||||
showError(e);
|
||||
return new Promise(() => {});
|
||||
}
|
||||
throw new Error(friendly(e));
|
||||
}
|
||||
const { success, message, data } = res?.data || {};
|
||||
if (!success) throw new Error(message || i18n.t('请求失败,请稍后重试'));
|
||||
return data;
|
||||
};
|
||||
|
||||
export const listProfiles = (mode, orgId) =>
|
||||
call(() => API.get(`${routerBase(mode)}/profiles`, opts(orgId)));
|
||||
|
||||
export const saveProfile = (mode, orgId, profile) => {
|
||||
const base = routerBase(mode);
|
||||
return call(() =>
|
||||
profile.id
|
||||
? API.put(`${base}/profiles/${profile.id}`, profile, opts(orgId))
|
||||
: API.post(`${base}/profiles`, profile, opts(orgId)),
|
||||
);
|
||||
};
|
||||
|
||||
export const deleteProfile = (mode, orgId, id) =>
|
||||
call(() => API.delete(`${routerBase(mode)}/profiles/${id}`, opts(orgId)));
|
||||
|
||||
export const simulateProfile = (mode, orgId, id, payload) =>
|
||||
call(() =>
|
||||
API.post(
|
||||
`${routerBase(mode)}/profiles/${id}/simulate`,
|
||||
payload,
|
||||
opts(orgId),
|
||||
),
|
||||
);
|
||||
|
||||
export const listDecisions = (mode, orgId, params) =>
|
||||
call(() => API.get(`${routerBase(mode)}/decisions`, opts(orgId, { params })));
|
||||
|
||||
export const getConsents = (mode, orgId) =>
|
||||
call(() => API.get(`${routerBase(mode)}/consents`, opts(orgId)));
|
||||
|
||||
// 个人是否仍有生效中的出境同意:平台关闭智能路由后,侧边栏据此保留入口供撤回(会话内缓存,避免每次进页面都请求)
|
||||
const CONSENT_CACHE_KEY = 'smart_router_personal_consent_granted';
|
||||
|
||||
export const readPersonalConsentCache = () => {
|
||||
try {
|
||||
return sessionStorage.getItem(CONSENT_CACHE_KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const writePersonalConsentCache = (rows) => {
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
CONSENT_CACHE_KEY,
|
||||
(rows || []).some((x) => x && x.granted === true) ? '1' : '0',
|
||||
);
|
||||
} catch {
|
||||
// 无痕模式等场景下 sessionStorage 不可用:不缓存即可
|
||||
}
|
||||
};
|
||||
|
||||
export const loadPersonalConsentGranted = async () => {
|
||||
const rows = await getConsents('personal');
|
||||
writePersonalConsentCache(rows);
|
||||
return (rows || []).some((x) => x && x.granted === true);
|
||||
};
|
||||
|
||||
export const updateConsent = async (mode, orgId, kind, granted) => {
|
||||
const rows = await call(() =>
|
||||
API.put(`${routerBase(mode)}/consents`, { kind, granted }, opts(orgId)),
|
||||
);
|
||||
if (mode !== 'org' && mode !== 'admin') writePersonalConsentCache(rows);
|
||||
return rows;
|
||||
};
|
||||
|
||||
// 候选模型下拉的数据来源:个人=自己分组可用模型;平台=全部启用模型;企业=企业可用模型
|
||||
export const listCandidateModels = async (mode, orgId) => {
|
||||
let url = '/api/user/models';
|
||||
if (mode === 'admin') url = '/api/channel/models_enabled';
|
||||
if (mode === 'org') url = '/api/org/models';
|
||||
const data = await call(() => API.get(url, opts(orgId)));
|
||||
return (data || []).filter(
|
||||
(m) => typeof m === 'string' && !m.startsWith('router/'),
|
||||
);
|
||||
};
|
||||
|
||||
export const getAdminStatus = () =>
|
||||
call(() => API.get('/api/router/admin/status', opts()));
|
||||
|
||||
export const setJevKey = (provider, key, clear = false) =>
|
||||
call(() =>
|
||||
API.put('/api/router/admin/jev-key', { provider, key, clear }, opts()),
|
||||
);
|
||||
|
||||
export const loadOptions = () => call(() => API.get('/api/option/', opts()));
|
||||
|
||||
export const saveOption = (key, value) =>
|
||||
call(() => API.put('/api/option/', { key, value }, opts()));
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
// 判定来源 / 闸门 / 过滤原因的展示文案(与后端 decide.go、gate.go、filter.go 的代码一一对应)
|
||||
export const reasonText = (t, code) =>
|
||||
({
|
||||
disabled: t('已停用'),
|
||||
level: t('等级不可用'),
|
||||
scope: t('不在企业作用域白名单'),
|
||||
experience_center: t('不在体验中心白名单'),
|
||||
no_channel: t('分组内没有可用渠道'),
|
||||
channel_query_failed: t('渠道查询失败'),
|
||||
protocol: t('渠道不支持该入口格式'),
|
||||
vision: t('不支持图片输入'),
|
||||
tools: t('不支持工具调用'),
|
||||
json_mode: t('不支持 JSON 输出'),
|
||||
context: t('超出上下文长度'),
|
||||
tool_id_format: t('工具调用 ID 格式不兼容'),
|
||||
strip_incompatible: t('不兼容历史剥离'),
|
||||
reasoning: t('不支持推理 / 思考'),
|
||||
})[code] || code;
|
||||
|
||||
// Jev 调用失败原因(jev.FailureReason);http_xxx 为上游状态码
|
||||
export const jevReasonText = (t, code) => {
|
||||
if (!code) return '';
|
||||
if (/^http_\d+$/.test(code))
|
||||
return t('上游返回 {{code}}', { code: code.slice(5) });
|
||||
return (
|
||||
{
|
||||
timeout: t('判定超时'),
|
||||
breaker: t('通道熔断中'),
|
||||
no_key: t('未配置密钥'),
|
||||
parse: t('返回格式异常'),
|
||||
error: t('调用失败'),
|
||||
}[code] || code
|
||||
);
|
||||
};
|
||||
|
||||
export const gateText = (t, code) =>
|
||||
({
|
||||
jev: t('已调用 Jev'),
|
||||
platform_off: t('平台未开启 Jev 出境'),
|
||||
sensitive: t('命中敏感词'),
|
||||
desens_off: t('脱敏未启用'),
|
||||
desens_block: t('脱敏策略会拦截'),
|
||||
guard_input: t('内容审核输入审查生效'),
|
||||
org_no_consent: t('企业未授权'),
|
||||
user_no_consent: t('个人未授权'),
|
||||
profile_off: t('集合未允许使用 Jev'),
|
||||
no_quota: t('余额不足,未调用 Jev'),
|
||||
jev_cap: t('今日 Jev 判定次数已达上限'),
|
||||
desens_residual: t('脱敏后仍有敏感信息'),
|
||||
'n/a': t('未经过闸门'),
|
||||
})[code] ||
|
||||
(code && code.startsWith('rules:') ? gateText(t, code.slice(6)) : code) ||
|
||||
'-';
|
||||
|
||||
export const srcText = (t, code) =>
|
||||
({
|
||||
jev: t('Jev 判定'),
|
||||
cache: t('判定缓存'),
|
||||
rules: t('规则判定器'),
|
||||
rules_fallback: t('Jev 失败,规则判定'),
|
||||
rule: t('自定义规则'),
|
||||
rule_tier: t('自定义规则强制档位'),
|
||||
forced: t('请求指定档位'),
|
||||
single: t('唯一候选'),
|
||||
sticky: t('会话粘性'),
|
||||
continuation: t('工具调用续写'),
|
||||
default: t('默认模型'),
|
||||
cheapest: t('最便宜的候选'),
|
||||
disabled: t('未启用,使用默认模型'),
|
||||
error: t('路由失败'),
|
||||
})[code] || code;
|
||||
@@ -0,0 +1,271 @@
|
||||
/* 智能模型路由:配色只引用语义变量(tokens.css),同时用于控制台与企业中心,保持中性 */
|
||||
.smart-router-page,
|
||||
.smart-router-scope,
|
||||
.smart-router-sheet {
|
||||
--sr-ink: var(--text-primary);
|
||||
--sr-muted: var(--text-secondary);
|
||||
--sr-line: var(--border-subtle);
|
||||
--sr-accent: var(--brand-primary);
|
||||
}
|
||||
|
||||
.smart-router-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
color: var(--sr-ink);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.smart-router-alert {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
/* 控制台介绍区:无图标、无渐变的说明块;标题与内边距由公共页头 / 容器统一 */
|
||||
.smart-router-hero {
|
||||
padding: 16px 24px;
|
||||
border: 1px solid var(--sr-line);
|
||||
border-radius: 10px;
|
||||
background: var(--surface-card);
|
||||
}
|
||||
|
||||
.smart-router-eyebrow {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--sr-accent);
|
||||
}
|
||||
|
||||
.smart-router-hero h1 {
|
||||
margin: 4px 0 0;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 24px;
|
||||
color: var(--sr-ink);
|
||||
}
|
||||
|
||||
.smart-router-hero p {
|
||||
margin: 4px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 22px;
|
||||
color: var(--sr-muted);
|
||||
}
|
||||
|
||||
/* 区块卡:控制台 / 企业中心页内的子卡与弹层内结果卡 */
|
||||
.smart-router-card {
|
||||
border: 1px solid var(--sr-line);
|
||||
border-radius: 10px;
|
||||
background: var(--surface-card);
|
||||
padding: 16px 24px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.smart-router-card--compact {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
.smart-router-card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
.smart-router-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.smart-router-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.smart-router-inline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 16px;
|
||||
}
|
||||
|
||||
.smart-router-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.smart-router-state {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 24px 0;
|
||||
}
|
||||
|
||||
.smart-router-sub {
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.smart-router-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* 数据出境授权行 */
|
||||
.smart-router-consent-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 16px 24px;
|
||||
border: 1px solid var(--sr-line);
|
||||
border-radius: 10px;
|
||||
background: var(--surface-card);
|
||||
}
|
||||
|
||||
.smart-router-consent-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.smart-router-consent-head .ant-tag {
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
|
||||
/* 集合表:可点击复制的虚拟模型名 */
|
||||
.smart-router-copy.ant-btn {
|
||||
height: auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.smart-router-name {
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
.smart-router-field-label {
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.smart-router-field-label .ant-tag {
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
|
||||
/* 编辑抽屉 */
|
||||
.smart-router-sheet-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.smart-router-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 16px;
|
||||
}
|
||||
|
||||
.smart-router-grid-full {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.smart-router-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.smart-router-model-select {
|
||||
flex: 1;
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.smart-router-mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.smart-router-num {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.smart-router-matrix {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.smart-router-matrix table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 8px 8px;
|
||||
min-width: 640px;
|
||||
}
|
||||
|
||||
.smart-router-matrix th {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--sr-muted);
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 试路由概率条:antd Progress,颜色沿用主题主色 */
|
||||
.smart-router-prob-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.smart-router-prob {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.smart-router-prob-label {
|
||||
width: 80px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.smart-router-prob-bar.ant-progress {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.smart-router-prob-value {
|
||||
width: 40px;
|
||||
flex: none;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.smart-router-kv {
|
||||
display: grid;
|
||||
grid-template-columns: max-content 1fr;
|
||||
gap: 8px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.smart-router-kv dt {
|
||||
color: var(--sr-muted);
|
||||
}
|
||||
|
||||
.smart-router-kv dd {
|
||||
margin: 0;
|
||||
min-width: 0;
|
||||
word-break: break-all;
|
||||
}
|
||||
Reference in New Issue
Block a user