Files
monkey-ai-web/src/components/smart-router/ProfileEditor.jsx
T
2026-11-18 19:09:00 +08:00

955 lines
34 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, { useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Alert,
Button,
Checkbox,
Collapse,
Form,
Input,
InputNumber,
Modal,
Select,
Switch,
Typography,
} from 'antd';
import { ConsoleDrawer as Drawer } from '../console/ConsolePrimitives';
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;