/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useCallback, useEffect, useMemo, useRef, useState, } from 'react'; import { Banner, Button, Collapse, Input, InputNumber, Modal, Select, Skeleton, Switch, TabPane, Tabs, Tag, TextArea, Toast, Typography, } from '@/components/ui'; import { Activity, BadgeCheck, Bot, Cpu, Plus, RefreshCw, Scale, ShieldCheck, Sparkles, } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { API, isRoot, showError } from '../../helpers'; import PageBackground from '../../components/common/PageBackground'; import './expert-platform.css'; const { Text } = Typography; // 与后端 expertKeyPattern 逐字一致:必须以小写字母开头(专家标识与步骤 // 标识共用同一正则) const keyPattern = /^[a-z][a-z0-9_-]{2,63}$/; const csvList = (value) => String(value || '') .split(/[,,]/) .map((item) => item.trim()) .filter(Boolean); // 傻瓜式核心:英文文案留空时自动复用中文(后端要求双语非空) const orZh = (en, zh) => (String(en || '').trim() ? String(en).trim() : zh); // 专家自检的检查项标签与阻断结论。detail 里带数字的两项(技能数、候选模型数) // 由前端自己拼,后端只给计数——否则英文用户会看到后端拼好的中文句子。 const diagnoseCheckLabels = { version_status: '版本状态', output_contract: '输出契约', step_plan: '步骤计划', skills: '审核技能', model_sequence: '模型候选', }; const diagnoseBlockingHints = { no_available_model: '没有任何候选模型可派发:请在「模型能力」里登记满足该专家输出上限的渠道。', not_published: '该版本尚未发布,成员在专家广场看不到它。', invalid_output_contract: '输出契约不是合法 JSON,任务会以 invalid_snapshot 失败。', }; const diagnoseCheckDetail = (check, diagnosis, t) => { if (check.key === 'skills') return t('已绑定 {{count}} 个已发布技能', { count: diagnosis.skill_count || 0, }); if (check.key === 'model_sequence') return t('分组 {{group}} 下有 {{count}} 个候选模型', { group: diagnosis.group || 'default', count: diagnosis.candidate_count || 0, }); return check.detail ? t(check.detail) : ''; }; // 版本按号倒序:最新版本永远排在最前(列表与「编辑」取基线共用一套顺序) const sortVersionsDesc = (list) => [...(list || [])].sort((a, b) => (b.version || 0) - (a.version || 0)); // 后端只允许发布 draft/pending_review,被取代的版本会 422 const publishableVersions = (list) => sortVersionsDesc(list).filter( (item) => item.status === 'draft' || item.status === 'pending_review', ); const publishedVersions = (list) => sortVersionsDesc(list).filter((item) => item.status === 'published'); // 版本历史条:只读徽章,不再带行内按钮——所有动作统一收到卡片底部的 // 单行动作区,否则「编辑」与「紧急停用」会被拆成上下两行。 const VersionStrip = ({ versions, labelOf, max = 6 }) => { const sorted = sortVersionsDesc(versions); if (sorted.length === 0) return null; const rest = sorted.length - max; return (
{sorted.slice(0, max).map((version) => (