1359 lines
48 KiB
React
1359 lines
48 KiB
React
/*
|
||
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 { ConsolePageActions } from '../../components/console/ConsolePageContainer';
|
||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||
import {
|
||
Button,
|
||
Checkbox,
|
||
Input,
|
||
Modal,
|
||
Select,
|
||
TabPane,
|
||
Tabs,
|
||
Tag,
|
||
TextArea,
|
||
Toast,
|
||
Typography,
|
||
} from '@/components/ui';
|
||
import { IconPlus, IconRefresh, IconSearch } from '@/components/ui/icons';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { API } from '../../helpers';
|
||
import { skillTagLabel } from '../../constants/skillCategories';
|
||
import {
|
||
CapabilityTags,
|
||
GrayscaleProgress,
|
||
LicenseBadge,
|
||
RiskBadge,
|
||
SkillCard,
|
||
SkillDetailSideSheet,
|
||
SkillEmptyGuide,
|
||
SkillStatusTag,
|
||
VersionTimeline,
|
||
} from '../../components/skill';
|
||
import './skill-platform.css';
|
||
|
||
const { Text, Paragraph } = Typography;
|
||
|
||
const IMPORT_TERMINAL = ['succeeded', 'completed_with_errors', 'failed'];
|
||
|
||
const parseJSONList = (value) => {
|
||
try {
|
||
const parsed = JSON.parse(value || '[]');
|
||
return Array.isArray(parsed) ? parsed : [];
|
||
} catch {
|
||
return [];
|
||
}
|
||
};
|
||
|
||
const SkillPlatform = () => {
|
||
const { t, i18n } = useTranslation();
|
||
// 分类标签的展示语言:数据层是英文 slug,仅中文界面映射为中文名(映射表见
|
||
// constants/skillCategories.js),其余语言(en/fr/ru/ja/vi)一律展示原始
|
||
// slug——slug 本身是英文,比中文兜底更贴近这些界面。过滤请求仍携带原始 slug。
|
||
const tagLanguage = i18n.language?.startsWith('zh') ? 'zh' : 'en';
|
||
const [loading, setLoading] = useState(true);
|
||
const [skills, setSkills] = useState([]);
|
||
const [status, setStatus] = useState('');
|
||
const [page, setPage] = useState(1);
|
||
const [total, setTotal] = useState(0);
|
||
const pageSize = 50;
|
||
const [selected, setSelected] = useState(null);
|
||
const [detailTab, setDetailTab] = useState('review');
|
||
const [detail, setDetail] = useState(null);
|
||
const [importVisible, setImportVisible] = useState(false);
|
||
const [importing, setImporting] = useState(false);
|
||
const [importingBundled, setImportingBundled] = useState(false);
|
||
// One entry per running import job. The manual snapshot import contributes a
|
||
// single job; the bundled one-click import contributes one job per pack.
|
||
const [importJobs, setImportJobs] = useState([]);
|
||
// Ids we have already counted as finished, so completion only refreshes the
|
||
// catalog once per job instead of on every poll tick.
|
||
const completedImportIds = useRef(new Set());
|
||
const [importForm, setImportForm] = useState({
|
||
source_key: '',
|
||
source_name: '',
|
||
source_type: 'upstream-original',
|
||
repository: '',
|
||
snapshot_path: '',
|
||
commit_sha: '',
|
||
package_version: '',
|
||
});
|
||
const [deriveVisible, setDeriveVisible] = useState(false);
|
||
const [deriveForm, setDeriveForm] = useState({});
|
||
const [modelTestVisible, setModelTestVisible] = useState(false);
|
||
const [modelTestForm, setModelTestForm] = useState({
|
||
channel_id: 0,
|
||
model: '',
|
||
input: '',
|
||
});
|
||
// 渠道下拉的数据源与实测结果面板。渠道列表只在第一次打开实测弹窗时拉取。
|
||
const [testChannels, setTestChannels] = useState([]);
|
||
const [testChannelsLoading, setTestChannelsLoading] = useState(false);
|
||
const [modelTesting, setModelTesting] = useState(false);
|
||
const [modelTestResult, setModelTestResult] = useState(null);
|
||
const [emergencyStopVisible, setEmergencyStopVisible] = useState(false);
|
||
const [emergencyStopReason, setEmergencyStopReason] = useState('');
|
||
const [withdrawVisible, setWithdrawVisible] = useState(false);
|
||
const [withdrawReason, setWithdrawReason] = useState('');
|
||
// 批量补扫(扫描规则升级后的漂移消除入口)。
|
||
const [rescanningOutdated, setRescanningOutdated] = useState(false);
|
||
// 审核结论逐项勾选(替代一键 hardcode 通过):null=关闭,
|
||
// {approved:true}=通过确认弹窗,{approved:false}=驳回原因弹窗。
|
||
const [reviewDecision, setReviewDecision] = useState(null);
|
||
const [reviewChecklist, setReviewChecklist] = useState({
|
||
value: false,
|
||
localization: false,
|
||
safety: false,
|
||
quality: false,
|
||
});
|
||
const [reviewReason, setReviewReason] = useState('');
|
||
// 当前扫描规则版本,由列表接口下发;用于标记"已发布但扫描停留在旧规则、
|
||
// 注入静默不生效"的技能(方案 §11 P0-4)。
|
||
const [scanRuleVersion, setScanRuleVersion] = useState('');
|
||
// 行业分类 facet:tag 参数下推到服务端过滤,分页与计数才是全量口径。
|
||
const [tagFacets, setTagFacets] = useState([]);
|
||
const [activeTag, setActiveTag] = useState('');
|
||
// 关键字搜索:keyword 是输入框即时值,searchTerm 是回车/清空后真正下推
|
||
// 到服务端的值(与技能超市同一交互,避免每敲一个字符打一次全量查询)。
|
||
const [keyword, setKeyword] = useState('');
|
||
const [searchTerm, setSearchTerm] = useState('');
|
||
|
||
// 请求序号:快速切换 tag/状态时,慢的旧响应可能晚于新响应返回,
|
||
// 不带序号就会用旧过滤结果覆盖新选中态(列表与高亮不一致)。
|
||
const skillsRequestSeq = useRef(0);
|
||
const loadSkills = useCallback(async () => {
|
||
const seq = ++skillsRequestSeq.current;
|
||
setLoading(true);
|
||
try {
|
||
const response = await API.get('/api/skill-platform/skills', {
|
||
params: {
|
||
status,
|
||
tag: activeTag || undefined,
|
||
keyword: searchTerm || undefined,
|
||
page,
|
||
page_size: pageSize,
|
||
},
|
||
skipErrorHandler: true,
|
||
});
|
||
if (seq !== skillsRequestSeq.current) return;
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('加载失败'));
|
||
setSkills(response.data.data || []);
|
||
setTotal(response.data.total || (response.data.data || []).length);
|
||
setScanRuleVersion(response.data.scan_rule_version || '');
|
||
} catch (error) {
|
||
if (seq !== skillsRequestSeq.current) return;
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('加载失败'),
|
||
);
|
||
} finally {
|
||
if (seq === skillsRequestSeq.current) setLoading(false);
|
||
}
|
||
}, [page, status, activeTag, searchTerm, t]);
|
||
|
||
useEffect(() => {
|
||
void loadSkills();
|
||
}, [loadSkills]);
|
||
|
||
const loadTagFacets = useCallback(async () => {
|
||
try {
|
||
const response = await API.get('/api/skill-platform/skill-tags', {
|
||
skipErrorHandler: true,
|
||
});
|
||
if (response.data?.success) setTagFacets(response.data.data || []);
|
||
} catch {
|
||
// Facet 是辅助导航,失败时保留旧值即可,不打断页面。
|
||
}
|
||
}, []);
|
||
useEffect(() => {
|
||
void loadTagFacets();
|
||
}, [loadTagFacets]);
|
||
|
||
// Counted from backend totals, not the currently loaded page — with
|
||
// pagination the page slice would make these numbers jump on every page
|
||
// turn and contradict the pager's total.
|
||
const [metrics, setMetrics] = useState({
|
||
供应链总数: 0,
|
||
待审核: 0,
|
||
已发布: 0,
|
||
已隔离: 0,
|
||
});
|
||
const loadMetrics = useCallback(async () => {
|
||
try {
|
||
const [all, pending, published, quarantined] = await Promise.all(
|
||
['', 'review_pending', 'published', 'quarantined'].map((value) =>
|
||
API.get('/api/skill-platform/skills', {
|
||
params: { status: value, page: 1, page_size: 1 },
|
||
skipErrorHandler: true,
|
||
}),
|
||
),
|
||
);
|
||
setMetrics({
|
||
供应链总数: all.data?.total || 0,
|
||
待审核: pending.data?.total || 0,
|
||
已发布: published.data?.total || 0,
|
||
已隔离: quarantined.data?.total || 0,
|
||
});
|
||
} catch {
|
||
// Metric tiles are advisory; keep the last known values on failure.
|
||
}
|
||
}, []);
|
||
useEffect(() => {
|
||
void loadMetrics();
|
||
}, [loadMetrics]);
|
||
|
||
// Poll only the still-running jobs. Keyed on the id list of pending jobs (not
|
||
// the whole job objects) so a progress tick doesn't tear down and recreate the
|
||
// interval, which would make the real cadence the response RTT instead of 1s.
|
||
const pendingImportIds = importJobs
|
||
.filter((job) => !IMPORT_TERMINAL.includes(job.status))
|
||
.map((job) => job.id);
|
||
const pendingImportSignature = pendingImportIds.join(',');
|
||
useEffect(() => {
|
||
if (!pendingImportSignature) return undefined;
|
||
let active = true;
|
||
const ids = pendingImportSignature.split(',');
|
||
const poll = async () => {
|
||
const results = await Promise.all(
|
||
ids.map((id) =>
|
||
API.get(`/api/skill-platform/imports/${id}`)
|
||
.then((response) =>
|
||
response.data?.success ? response.data.data : null,
|
||
)
|
||
.catch(() => null),
|
||
),
|
||
);
|
||
if (!active) return;
|
||
const byId = new Map(results.filter(Boolean).map((job) => [job.id, job]));
|
||
setImportJobs((previous) =>
|
||
previous.map((job) => byId.get(job.id) || job),
|
||
);
|
||
// Refresh the catalog once per job as it finishes, so imported skills
|
||
// appear without waiting for the whole batch (awesome-curated-v1 is large).
|
||
const newlyDone = results.some(
|
||
(job) =>
|
||
job &&
|
||
IMPORT_TERMINAL.includes(job.status) &&
|
||
!completedImportIds.current.has(job.id),
|
||
);
|
||
results.forEach((job) => {
|
||
if (job && IMPORT_TERMINAL.includes(job.status))
|
||
completedImportIds.current.add(job.id);
|
||
});
|
||
if (newlyDone)
|
||
await Promise.all([loadSkills(), loadMetrics(), loadTagFacets()]);
|
||
};
|
||
const timer = window.setInterval(() => void poll(), 1000);
|
||
void poll();
|
||
return () => {
|
||
active = false;
|
||
window.clearInterval(timer);
|
||
};
|
||
}, [pendingImportSignature, loadMetrics, loadSkills, loadTagFacets]);
|
||
|
||
const loadDetail = useCallback(
|
||
async (skill) => {
|
||
setDetailTab('review');
|
||
setSelected(skill);
|
||
try {
|
||
const response = await API.get(
|
||
`/api/skill-platform/skills/${skill.definition.id}`,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('加载失败'));
|
||
setDetail(response.data.data);
|
||
} catch (error) {
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('加载失败'),
|
||
);
|
||
}
|
||
},
|
||
[t],
|
||
);
|
||
|
||
const currentVersion =
|
||
detail?.versions?.find(
|
||
(version) => version.id === detail?.definition?.current_version_id,
|
||
) || detail?.versions?.[0];
|
||
|
||
const execute = async (path, payload = {}) => {
|
||
try {
|
||
const response = await API.post(path, payload, {
|
||
skipErrorHandler: true,
|
||
});
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('操作失败'));
|
||
Toast.success(t('操作成功'));
|
||
// 回滚/发布可能改变展示版本的 tags,facet 也要一起刷新。
|
||
await Promise.all([loadSkills(), loadMetrics(), loadTagFacets()]);
|
||
// 刷新目标以 detail(用户所见、操作所指)为准而非 selected:两者在
|
||
// loadDetail 失败时可能分叉(R29 发现项)。
|
||
if (detail) await loadDetail({ definition: detail.definition });
|
||
return true;
|
||
} catch (error) {
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('操作失败'),
|
||
);
|
||
return false;
|
||
}
|
||
};
|
||
|
||
const submitImport = async () => {
|
||
setImporting(true);
|
||
try {
|
||
const response = await API.post(
|
||
'/api/skill-platform/imports',
|
||
importForm,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('导入失败'));
|
||
setImportVisible(false);
|
||
// Merge instead of replace: a manual import must not drop tracking of
|
||
// still-running bundled-pack jobs (they keep running server-side).
|
||
setImportJobs((previous) => [
|
||
...previous.filter((job) => !IMPORT_TERMINAL.includes(job.status)),
|
||
response.data.data,
|
||
]);
|
||
Toast.success(t('导入任务已创建'));
|
||
} catch (error) {
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('导入失败'),
|
||
);
|
||
} finally {
|
||
setImporting(false);
|
||
}
|
||
};
|
||
|
||
// One-click import of every bundled pack (platform-default-v1 +
|
||
// awesome-curated-v1 + any future pack): the server resolves the on-disk paths
|
||
// and returns one job per pack. They reuse the aggregated progress bar and
|
||
// polling effect.
|
||
const importBundledPacks = async () => {
|
||
setImportingBundled(true);
|
||
try {
|
||
const response = await API.post(
|
||
'/api/skill-platform/imports/bundled-packs',
|
||
{},
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('导入失败'));
|
||
const jobs = response.data.data || [];
|
||
setImportJobs((previous) => [
|
||
...previous.filter((job) => !IMPORT_TERMINAL.includes(job.status)),
|
||
...jobs,
|
||
]);
|
||
Toast.success(
|
||
t('已开始导入内置技能包({{count}} 个)', { count: jobs.length }),
|
||
);
|
||
} catch (error) {
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('导入失败'),
|
||
);
|
||
} finally {
|
||
setImportingBundled(false);
|
||
}
|
||
};
|
||
|
||
const openDerive = () => {
|
||
if (!currentVersion) return;
|
||
const zh =
|
||
currentVersion.locales?.find((item) => item.locale === 'zh') || {};
|
||
const en =
|
||
currentVersion.locales?.find((item) => item.locale === 'en') || {};
|
||
setDeriveForm({
|
||
body: currentVersion.body || '',
|
||
name_zh: zh.name || '',
|
||
name_en: en.name || '',
|
||
description_zh: zh.description || '',
|
||
description_en: en.description || '',
|
||
compact_constraint_zh: zh.compact_constraint || '',
|
||
compact_constraint_en: en.compact_constraint || '',
|
||
triggers_zh: parseJSONList(zh.triggers).join(', '),
|
||
triggers_en: parseJSONList(en.triggers).join(', '),
|
||
scenarios_zh: parseJSONList(zh.scenarios).join(', '),
|
||
scenarios_en: parseJSONList(en.scenarios).join(', '),
|
||
capabilities: parseJSONList(currentVersion.capabilities),
|
||
tags: parseJSONList(currentVersion.tags),
|
||
default_output_language: currentVersion.default_output_language || 'auto',
|
||
change_statement: '',
|
||
});
|
||
setDeriveVisible(true);
|
||
};
|
||
|
||
const submitDerived = async () => {
|
||
const list = (value) =>
|
||
String(value || '')
|
||
.split(',')
|
||
.map((item) => item.trim())
|
||
.filter(Boolean);
|
||
const payload = {
|
||
...deriveForm,
|
||
triggers_zh: list(deriveForm.triggers_zh),
|
||
triggers_en: list(deriveForm.triggers_en),
|
||
scenarios_zh: list(deriveForm.scenarios_zh),
|
||
scenarios_en: list(deriveForm.scenarios_en),
|
||
};
|
||
if (
|
||
await execute(
|
||
`/api/skill-platform/versions/${currentVersion.id}/derive`,
|
||
payload,
|
||
)
|
||
)
|
||
setDeriveVisible(false);
|
||
};
|
||
|
||
// ===== 模型实测(复用渠道管理的渠道/模型数据源) =====
|
||
|
||
const loadTestChannels = useCallback(async () => {
|
||
setTestChannelsLoading(true);
|
||
try {
|
||
// status=1 让服务端只返回已启用渠道(Distribute 对禁用渠道会直接拒绝)。
|
||
// GetPageQuery 把 page_size 硬钳制在 ≤100,单页必然截断大型部署,
|
||
// 必须按 total 翻页拉全(上限 50 页 = 5000 渠道,足够任何现实部署)。
|
||
const collected = [];
|
||
for (let pageNo = 1; pageNo <= 50; pageNo += 1) {
|
||
const response = await API.get(
|
||
`/api/channel/?p=${pageNo}&page_size=100&id_sort=true&status=1`,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success) break;
|
||
const items = response.data.data?.items || [];
|
||
collected.push(...items);
|
||
const totalCount = response.data.data?.total || 0;
|
||
if (items.length === 0 || collected.length >= totalCount) break;
|
||
}
|
||
setTestChannels(collected.filter((channel) => channel.status === 1));
|
||
} catch {
|
||
// 渠道列表拉取失败时保留"自动路由",实测仍可用。
|
||
} finally {
|
||
setTestChannelsLoading(false);
|
||
}
|
||
}, []);
|
||
|
||
const openModelTest = () => {
|
||
// Reset on every open: stale values from a previous version must never be
|
||
// silently submitted as this version's review evidence.
|
||
setModelTestForm({ channel_id: 0, model: '', input: '' });
|
||
setModelTestResult(null);
|
||
setModelTestVisible(true);
|
||
if (testChannels.length === 0) void loadTestChannels();
|
||
};
|
||
|
||
const selectedTestChannel = testChannels.find(
|
||
(channel) => channel.id === modelTestForm.channel_id,
|
||
);
|
||
const testModelOptions = (() => {
|
||
const source = selectedTestChannel
|
||
? String(selectedTestChannel.models || '').split(',')
|
||
: testChannels.flatMap((channel) =>
|
||
String(channel.models || '').split(','),
|
||
);
|
||
return Array.from(
|
||
new Set(source.map((name) => name.trim()).filter(Boolean)),
|
||
).sort();
|
||
})();
|
||
// Semi Select 在 allowCreate + 受控 value 下有坑:optionList 变化时
|
||
// componentDidUpdate 先用新列表刷新 state.options,紧接着 handleValueChange
|
||
// 又用本次 commit 尚未落盘的旧 state.options 覆盖回去(foundation.js
|
||
// handleValueChange 的 `allowCreate && 受控` 分支直接读 getState('options'),
|
||
// 不重新收集 optionList),后写的赢,options 永远滞后一拍。弹窗是先打开再异步
|
||
// 拉渠道的,挂载时 optionList 为空数组,于是第一次更新就把 options 钉死在空,
|
||
// 之后切渠道也只是"用上一次的空数组"覆盖——占位符能报出 12 个模型(直接读
|
||
// testModelOptions.length,不经过 Select 内部 state),下拉却始终是空的。
|
||
// 用列表指纹当 key 强制重挂载,让 init() 走 _collectOptions 拿到当前列表。
|
||
const testModelSelectKey = testModelOptions.join('|');
|
||
|
||
// 扫描漂移 badge:已发布但注入门禁(要求当前规则 PASS)不放行的两种形态
|
||
// 要分开说——"需重扫"是缺当前规则记录(点批量补扫可消除);"扫描未通过"
|
||
// 是当前规则已扫非 PASS(同规则重扫结论不变,需要改写或下架,补扫按钮
|
||
// 对它无效,混用文案会让管理员反复点按钮而 badge 永不消失)。
|
||
const scanDriftBadge = (skill) => {
|
||
if (!scanRuleVersion || skill?.definition?.status !== 'published')
|
||
return null;
|
||
const runtime = skill?.runtime;
|
||
if (runtime && runtime.rule_version === scanRuleVersion) {
|
||
return runtime.conclusion === 'pass'
|
||
? null
|
||
: { text: t('扫描未通过'), color: 'red' };
|
||
}
|
||
return { text: t('需重扫'), color: 'orange' };
|
||
};
|
||
|
||
const runOutdatedRescan = async () => {
|
||
setRescanningOutdated(true);
|
||
try {
|
||
const response = await API.post(
|
||
'/api/skill-platform/rescan-outdated',
|
||
{},
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('操作失败'));
|
||
const {
|
||
checked = 0,
|
||
rescanned = 0,
|
||
passed = 0,
|
||
failed = 0,
|
||
} = response.data.data || {};
|
||
const summary = t(
|
||
'已检查 {{checked}} 个已发布技能,补扫 {{rescanned}} 个,通过 {{passed}} 个',
|
||
{ checked, rescanned, passed },
|
||
);
|
||
// 失败绝不并入成功提示:"补扫 0"与"无需补扫"同形正是要消灭的静默漂移。
|
||
if (failed > 0) {
|
||
Toast.warning(
|
||
`${summary} · ${t('失败 {{failed}} 个,详见服务端日志', { failed })}`,
|
||
);
|
||
} else {
|
||
Toast.success(summary);
|
||
}
|
||
await Promise.all([loadSkills(), loadMetrics()]);
|
||
if (detail) await loadDetail({ definition: detail.definition });
|
||
} catch (error) {
|
||
Toast.error(
|
||
error.response?.data?.message || error.message || t('操作失败'),
|
||
);
|
||
} finally {
|
||
setRescanningOutdated(false);
|
||
}
|
||
};
|
||
|
||
const submitReviewDecision = async () => {
|
||
if (!reviewDecision || !currentVersion) return;
|
||
let payload;
|
||
if (reviewDecision.approved) {
|
||
payload = { approved: true, conclusion: { ...reviewChecklist } };
|
||
} else {
|
||
if (reviewReason.trim().length < 4) {
|
||
Toast.warning(t('请输入至少 4 个字符的驳回原因'));
|
||
return;
|
||
}
|
||
payload = {
|
||
approved: false,
|
||
conclusion: { reason: reviewReason.trim() },
|
||
};
|
||
}
|
||
if (
|
||
await execute(
|
||
`/api/skill-platform/versions/${currentVersion.id}/review/decision`,
|
||
payload,
|
||
)
|
||
)
|
||
setReviewDecision(null);
|
||
};
|
||
|
||
const runModelTest = async () => {
|
||
if (!modelTestForm.model.trim() || !modelTestForm.input.trim()) {
|
||
Toast.warning(t('请填写模型与测试输入'));
|
||
return;
|
||
}
|
||
setModelTesting(true);
|
||
setModelTestResult(null);
|
||
const startedAt = Date.now();
|
||
try {
|
||
const response = await API.post(
|
||
`/api/skill-platform/versions/${currentVersion.id}/model-test`,
|
||
modelTestForm,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success)
|
||
throw new Error(response.data?.message || t('模型实测失败'));
|
||
const raw = response.data.data || {};
|
||
setModelTestResult({
|
||
ok: true,
|
||
content:
|
||
raw.choices?.[0]?.message?.content || JSON.stringify(raw, null, 2),
|
||
usage: raw.usage,
|
||
elapsed: (Date.now() - startedAt) / 1000,
|
||
});
|
||
Toast.success(t('模型实测完成,证据已落库'));
|
||
// 实测记录是审核证据,详情里的 review 状态要跟着刷新(以 detail 为准)。
|
||
if (detail) void loadDetail({ definition: detail.definition });
|
||
} catch (error) {
|
||
setModelTestResult({
|
||
ok: false,
|
||
error:
|
||
error.response?.data?.message || error.message || t('模型实测失败'),
|
||
elapsed: (Date.now() - startedAt) / 1000,
|
||
});
|
||
} finally {
|
||
setModelTesting(false);
|
||
}
|
||
};
|
||
|
||
return (
|
||
<section className='skill-platform-page'>
|
||
<ConsolePageActions>
|
||
<Button
|
||
onClick={() => window.location.assign('/console/expert-platform')}
|
||
>
|
||
{t('专家与模型能力')}
|
||
</Button>
|
||
<Button icon={<IconRefresh />} onClick={loadSkills}>
|
||
{t('刷新')}
|
||
</Button>
|
||
<Button
|
||
loading={importingBundled}
|
||
disabled={pendingImportIds.length > 0}
|
||
onClick={importBundledPacks}
|
||
>
|
||
{t('一键导入内置技能包')}
|
||
</Button>
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
icon={<IconPlus />}
|
||
onClick={() => setImportVisible(true)}
|
||
>
|
||
{t('导入快照')}
|
||
</Button>
|
||
</ConsolePageActions>
|
||
|
||
<section className='skill-platform-metrics'>
|
||
{Object.entries(metrics).map(([key, value]) => (
|
||
<article key={key}>
|
||
<Text type='tertiary'>{t(key)}</Text>
|
||
<strong>{value}</strong>
|
||
</article>
|
||
))}
|
||
</section>
|
||
|
||
{importJobs.length > 0 &&
|
||
(() => {
|
||
const done = importJobs.filter((job) =>
|
||
IMPORT_TERMINAL.includes(job.status),
|
||
).length;
|
||
const sum = importJobs.reduce(
|
||
(acc, job) => ({
|
||
percent: acc.percent + Number(job.progress || 0),
|
||
imported: acc.imported + (job.imported || 0),
|
||
skipped: acc.skipped + (job.skipped || 0),
|
||
failed: acc.failed + (job.failed || 0),
|
||
}),
|
||
{ percent: 0, imported: 0, skipped: 0, failed: 0 },
|
||
);
|
||
return (
|
||
<GrayscaleProgress
|
||
percent={Math.round(sum.percent / importJobs.length)}
|
||
label={t(
|
||
'快照导入 · 技能包 {{done}}/{{total}} · 成功 {{imported}} / 跳过 {{skipped}} / 失败 {{failed}}',
|
||
{
|
||
done,
|
||
total: importJobs.length,
|
||
imported: sum.imported,
|
||
skipped: sum.skipped,
|
||
failed: sum.failed,
|
||
},
|
||
)}
|
||
/>
|
||
);
|
||
})()}
|
||
|
||
<section className='skill-platform-toolbar'>
|
||
<div className='skill-platform-filters'>
|
||
<Input
|
||
value={keyword}
|
||
onChange={setKeyword}
|
||
onEnterPress={() => {
|
||
setPage(1);
|
||
setSearchTerm(keyword.trim());
|
||
}}
|
||
prefix={<IconSearch />}
|
||
placeholder={t('搜索技能名称、描述或标识')}
|
||
showClear
|
||
onClear={() => {
|
||
setKeyword('');
|
||
setSearchTerm('');
|
||
setPage(1);
|
||
}}
|
||
style={{ width: 260 }}
|
||
/>
|
||
<Select
|
||
value={status}
|
||
onChange={(value) => {
|
||
setPage(1);
|
||
setStatus(value);
|
||
}}
|
||
style={{ width: 200 }}
|
||
>
|
||
<Select.Option value=''>{t('全部状态')}</Select.Option>
|
||
{[
|
||
'pending_import',
|
||
'license_pending',
|
||
'scan_pending',
|
||
'review_pending',
|
||
'published',
|
||
'withdrawn',
|
||
'quarantined',
|
||
'deprecated',
|
||
].map((value) => (
|
||
<Select.Option key={value} value={value}>
|
||
<SkillStatusTag status={value} />
|
||
</Select.Option>
|
||
))}
|
||
</Select>
|
||
<Select
|
||
value={activeTag}
|
||
onChange={(value) => {
|
||
setPage(1);
|
||
setActiveTag(value || '');
|
||
}}
|
||
// 自定义过滤同时匹配中文名(label)与原始 slug(value):
|
||
// 管理员从导入日志/数据里记住的常是英文 slug,label 中文化后
|
||
// 默认的按 label 匹配会让 slug 搜索一无所获。
|
||
filter={(input, option) => {
|
||
const needle = String(input || '').toLowerCase();
|
||
return (
|
||
String(option.value || '')
|
||
.toLowerCase()
|
||
.includes(needle) ||
|
||
String(option.label || '')
|
||
.toLowerCase()
|
||
.includes(needle)
|
||
);
|
||
}}
|
||
showClear
|
||
placeholder={t('全部分类')}
|
||
style={{ width: 240 }}
|
||
optionList={[
|
||
{ value: '', label: t('全部分类') },
|
||
...tagFacets.map((facet) => ({
|
||
value: facet.tag,
|
||
label: `${skillTagLabel(facet.tag, tagLanguage)}(${facet.count})`,
|
||
})),
|
||
]}
|
||
/>
|
||
</div>
|
||
<div className='skill-platform-toolbar-actions'>
|
||
<Button loading={rescanningOutdated} onClick={runOutdatedRescan}>
|
||
{t('补扫过期扫描')}
|
||
</Button>
|
||
<Button
|
||
onClick={() =>
|
||
execute('/api/skill-platform/candidates/curate', { limit: 15 })
|
||
}
|
||
>
|
||
{t('圈选首批候选')}
|
||
</Button>
|
||
</div>
|
||
</section>
|
||
|
||
{/* 分类速览:高频行业标签一排 chips,点选即过滤,比下拉更贴近云市场的浏览习惯 */}
|
||
{tagFacets.length > 0 && (
|
||
<section className='skill-platform-tag-chips'>
|
||
<button
|
||
type='button'
|
||
className={`skill-platform-tag-chip${activeTag === '' ? ' is-active' : ''}`}
|
||
onClick={() => {
|
||
setPage(1);
|
||
setActiveTag('');
|
||
}}
|
||
>
|
||
{t('全部')}
|
||
</button>
|
||
{tagFacets.slice(0, 16).map((facet) => (
|
||
<button
|
||
key={facet.tag}
|
||
type='button'
|
||
className={`skill-platform-tag-chip${activeTag === facet.tag ? ' is-active' : ''}`}
|
||
onClick={() => {
|
||
setPage(1);
|
||
setActiveTag((current) =>
|
||
current === facet.tag ? '' : facet.tag,
|
||
);
|
||
}}
|
||
>
|
||
{skillTagLabel(facet.tag, tagLanguage)}
|
||
<span className='skill-platform-tag-chip-count'>
|
||
{facet.count}
|
||
</span>
|
||
</button>
|
||
))}
|
||
</section>
|
||
)}
|
||
|
||
{loading ? (
|
||
<GrayscaleProgress percent={38} label={t('正在核对供应链记录')} />
|
||
) : skills.length === 0 ? (
|
||
searchTerm || activeTag || status ? (
|
||
// 有筛选条件时空列表是"没搜到",不是"没数据"——引导导入会误导。
|
||
<SkillEmptyGuide
|
||
title={t('没有匹配的技能')}
|
||
description={t('换个关键词、状态或分类试试。')}
|
||
actionLabel={t('清空筛选')}
|
||
onAction={() => {
|
||
setKeyword('');
|
||
setSearchTerm('');
|
||
setActiveTag('');
|
||
setStatus('');
|
||
setPage(1);
|
||
}}
|
||
/>
|
||
) : (
|
||
<SkillEmptyGuide
|
||
title={t('还没有 Skill 供应链记录')}
|
||
description={t('从经过授权的固定 Commit 快照开始导入。')}
|
||
actionLabel={t('导入第一个快照')}
|
||
onAction={() => setImportVisible(true)}
|
||
/>
|
||
)
|
||
) : (
|
||
<>
|
||
<section className='skill-platform-grid'>
|
||
{skills.map((skill) => (
|
||
<SkillCard
|
||
key={skill.definition.id}
|
||
skill={skill}
|
||
selected={selected?.definition?.id === skill.definition.id}
|
||
onClick={() => loadDetail(skill)}
|
||
actions={
|
||
<>
|
||
<LicenseBadge
|
||
expression={skill.license?.expression}
|
||
decision={skill.license?.decision}
|
||
/>
|
||
<RiskBadge conclusion={skill.runtime?.conclusion} />
|
||
{(() => {
|
||
const badge = scanDriftBadge(skill);
|
||
return badge ? (
|
||
<Tag size='small' color={badge.color}>
|
||
{badge.text}
|
||
</Tag>
|
||
) : null;
|
||
})()}
|
||
</>
|
||
}
|
||
/>
|
||
))}
|
||
</section>
|
||
{total > pageSize && (
|
||
<div className='skill-platform-pagination'>
|
||
<Button
|
||
disabled={page <= 1}
|
||
onClick={() => setPage((old) => Math.max(1, old - 1))}
|
||
>
|
||
{t('上一页')}
|
||
</Button>
|
||
<Text type='tertiary'>
|
||
{page} / {Math.max(1, Math.ceil(total / pageSize))} · {total}
|
||
</Text>
|
||
<Button
|
||
disabled={page >= Math.ceil(total / pageSize)}
|
||
onClick={() => setPage((old) => old + 1)}
|
||
>
|
||
{t('下一页')}
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</>
|
||
)}
|
||
|
||
<SkillDetailSideSheet
|
||
visible={!!selected}
|
||
className='skill-platform-review-drawer'
|
||
onCancel={() => {
|
||
setSelected(null);
|
||
setDetail(null);
|
||
}}
|
||
title={detail?.definition?.canonical_id || t('Skill 详情')}
|
||
footer={
|
||
detail && currentVersion && detailTab === 'review' ? (
|
||
<div className='skill-review-actions'>
|
||
<Button
|
||
onClick={() =>
|
||
execute(
|
||
`/api/skill-platform/versions/${currentVersion.id}/rescan`,
|
||
)
|
||
}
|
||
>
|
||
{t('重新扫描')}
|
||
</Button>
|
||
<Button onClick={openModelTest}>{t('模型实测')}</Button>
|
||
{currentVersion.reviews?.[0]?.status === 'pending' && (
|
||
<Button
|
||
onClick={() =>
|
||
execute(
|
||
`/api/skill-platform/versions/${currentVersion.id}/review/start`,
|
||
)
|
||
}
|
||
>
|
||
{t('开始审核')}
|
||
</Button>
|
||
)}
|
||
{currentVersion.reviews?.[0]?.status === 'reviewing' && (
|
||
<>
|
||
<Button
|
||
type='primary'
|
||
onClick={() => {
|
||
// 逐项勾选替代一键 hardcode:默认全不勾,
|
||
// 强制审核人对四个维度逐项作出确认。
|
||
setReviewChecklist({
|
||
value: false,
|
||
localization: false,
|
||
safety: false,
|
||
quality: false,
|
||
});
|
||
setReviewDecision({ approved: true });
|
||
}}
|
||
>
|
||
{t('审核通过')}
|
||
</Button>
|
||
<Button
|
||
type='danger'
|
||
onClick={() => {
|
||
setReviewReason('');
|
||
setReviewDecision({ approved: false });
|
||
}}
|
||
>
|
||
{t('驳回')}
|
||
</Button>
|
||
</>
|
||
)}
|
||
{currentVersion.reviews?.[0]?.status === 'approved' && (
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
onClick={() =>
|
||
execute(
|
||
`/api/skill-platform/versions/${currentVersion.id}/publish`,
|
||
)
|
||
}
|
||
>
|
||
{t('发布此版本')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
) : null
|
||
}
|
||
>
|
||
{detail && (
|
||
<div className='skill-platform-detail'>
|
||
<div className='skill-detail-status'>
|
||
<SkillStatusTag status={detail.definition.status} />
|
||
<Button onClick={openDerive}>{t('创建衍生版本')}</Button>
|
||
{detail.definition.status === 'published' && (
|
||
<Button
|
||
type='warning'
|
||
onClick={() => {
|
||
setWithdrawReason('');
|
||
setWithdrawVisible(true);
|
||
}}
|
||
>
|
||
{t('下架')}
|
||
</Button>
|
||
)}
|
||
<Button
|
||
type='danger'
|
||
onClick={() => {
|
||
setEmergencyStopReason('');
|
||
setEmergencyStopVisible(true);
|
||
}}
|
||
>
|
||
{t('紧急停用')}
|
||
</Button>
|
||
</div>
|
||
<Tabs type='line' activeKey={detailTab} onChange={setDetailTab}>
|
||
<TabPane tab={t('审核工作台')} itemKey='review'>
|
||
{currentVersion && (
|
||
<div className='skill-review-workbench'>
|
||
<section>
|
||
<Text type='tertiary'>{t('许可证')}</Text>
|
||
<LicenseBadge
|
||
expression={currentVersion.licenses?.[0]?.expression}
|
||
decision={currentVersion.licenses?.[0]?.decision}
|
||
/>
|
||
</section>
|
||
<section>
|
||
<Text type='tertiary'>{t('安全扫描')}</Text>
|
||
<RiskBadge
|
||
conclusion={currentVersion.scans?.[0]?.conclusion}
|
||
/>
|
||
</section>
|
||
<section>
|
||
<Text type='tertiary'>{t('运行能力')}</Text>
|
||
<CapabilityTags
|
||
capabilities={parseJSONList(
|
||
currentVersion.capabilities,
|
||
)}
|
||
/>
|
||
</section>
|
||
<pre>{currentVersion.body}</pre>
|
||
</div>
|
||
)}
|
||
</TabPane>
|
||
<TabPane tab={t('版本与溯源')} itemKey='versions'>
|
||
<VersionTimeline
|
||
versions={detail.versions}
|
||
renderActions={(version) =>
|
||
version.id !== detail.definition.current_version_id && (
|
||
<Button
|
||
size='small'
|
||
onClick={() =>
|
||
execute(
|
||
`/api/skill-platform/skills/${detail.definition.id}/rollback/${version.id}`,
|
||
)
|
||
}
|
||
>
|
||
{t('回滚到此版本')}
|
||
</Button>
|
||
)
|
||
}
|
||
/>
|
||
</TabPane>
|
||
</Tabs>
|
||
</div>
|
||
)}
|
||
</SkillDetailSideSheet>
|
||
|
||
<Modal
|
||
title={t('导入固定快照')}
|
||
visible={importVisible}
|
||
onCancel={() => setImportVisible(false)}
|
||
onOk={submitImport}
|
||
confirmLoading={importing}
|
||
>
|
||
{/* Controlled inputs: Semi Form fields keep their own state and
|
||
ignore the value prop, which desyncs the visible fields from the
|
||
submitted payload after the modal remounts. */}
|
||
<div className='skill-import-form'>
|
||
{[
|
||
['source_key', t('来源标识')],
|
||
['source_name', t('来源名称')],
|
||
['snapshot_path', t('服务器快照目录')],
|
||
['commit_sha', 'Commit SHA'],
|
||
['repository', t('来源仓库')],
|
||
].map(([field, label]) => (
|
||
<label key={field}>
|
||
<Text>{label}</Text>
|
||
<Input
|
||
value={importForm[field]}
|
||
onChange={(value) =>
|
||
setImportForm((old) => ({ ...old, [field]: value }))
|
||
}
|
||
/>
|
||
</label>
|
||
))}
|
||
</div>
|
||
</Modal>
|
||
|
||
<Modal
|
||
title={t('紧急停用')}
|
||
visible={emergencyStopVisible}
|
||
onCancel={() => setEmergencyStopVisible(false)}
|
||
okButtonProps={{ type: 'danger' }}
|
||
onOk={async () => {
|
||
if (emergencyStopReason.trim().length < 4) {
|
||
Toast.warning(t('请输入至少 4 个字符的停用原因'));
|
||
return;
|
||
}
|
||
if (
|
||
await execute(
|
||
`/api/skill-platform/skills/${detail?.definition?.id}/emergency-stop`,
|
||
{ reason: emergencyStopReason.trim() },
|
||
)
|
||
) {
|
||
setEmergencyStopVisible(false);
|
||
}
|
||
}}
|
||
>
|
||
<Paragraph>
|
||
{t(
|
||
'紧急停用会立即下线当前版本并回滚所有企业灰度实验,恢复必须通过带原因的显式回滚。',
|
||
)}
|
||
</Paragraph>
|
||
<TextArea
|
||
value={emergencyStopReason}
|
||
onChange={setEmergencyStopReason}
|
||
placeholder={t('请输入停用原因(至少 4 个字符)')}
|
||
autosize={{ minRows: 3 }}
|
||
/>
|
||
</Modal>
|
||
|
||
<Modal
|
||
title={t('下架技能')}
|
||
visible={withdrawVisible}
|
||
onCancel={() => setWithdrawVisible(false)}
|
||
okButtonProps={{ type: 'warning' }}
|
||
onOk={async () => {
|
||
if (withdrawReason.trim().length < 4) {
|
||
Toast.warning(t('请输入至少 4 个字符的下架原因'));
|
||
return;
|
||
}
|
||
if (
|
||
await execute(
|
||
`/api/skill-platform/skills/${detail?.definition?.id}/withdraw`,
|
||
{ reason: withdrawReason.trim() },
|
||
)
|
||
) {
|
||
setWithdrawVisible(false);
|
||
}
|
||
}}
|
||
>
|
||
<Paragraph>
|
||
{t(
|
||
'下架后技能将从技能超市与注入解析中移除;审核与扫描记录保留,可随时在审核工作台重新发布恢复。',
|
||
)}
|
||
</Paragraph>
|
||
<TextArea
|
||
value={withdrawReason}
|
||
onChange={setWithdrawReason}
|
||
placeholder={t('请输入下架原因(至少 4 个字符)')}
|
||
autosize={{ minRows: 3 }}
|
||
/>
|
||
</Modal>
|
||
|
||
<Modal
|
||
title={reviewDecision?.approved ? t('审核结论确认') : t('驳回原因')}
|
||
visible={!!reviewDecision}
|
||
// 关闭动画期间 reviewDecision 已为 null,正文会闪成驳回分支——
|
||
// 该弹窗内容轻量,直接关动画(R29 发现项)。
|
||
motion={false}
|
||
onCancel={() => setReviewDecision(null)}
|
||
okButtonProps={
|
||
reviewDecision?.approved
|
||
? {
|
||
disabled: !Object.values(reviewChecklist).every(Boolean),
|
||
}
|
||
: { type: 'danger' }
|
||
}
|
||
okText={reviewDecision?.approved ? t('确认通过') : t('提交驳回')}
|
||
onOk={submitReviewDecision}
|
||
>
|
||
{reviewDecision?.approved ? (
|
||
<div className='skill-review-checklist'>
|
||
<Paragraph type='tertiary'>
|
||
{t('请逐项确认以下审核结论后提交:')}
|
||
</Paragraph>
|
||
{[
|
||
['value', t('价值有效:解决真实业务场景')],
|
||
['localization', t('本地化完整:中英文名称、描述与触发词齐备')],
|
||
['safety', t('安全合规:无越权指令与敏感内容')],
|
||
['quality', t('质量达标:约束清晰、可稳定执行')],
|
||
].map(([key, label]) => (
|
||
<Checkbox
|
||
key={key}
|
||
checked={reviewChecklist[key]}
|
||
onChange={(event) =>
|
||
setReviewChecklist((old) => ({
|
||
...old,
|
||
[key]: event.target.checked,
|
||
}))
|
||
}
|
||
>
|
||
{label}
|
||
</Checkbox>
|
||
))}
|
||
</div>
|
||
) : (
|
||
<TextArea
|
||
value={reviewReason}
|
||
onChange={setReviewReason}
|
||
placeholder={t('请输入驳回原因(至少 4 个字符)')}
|
||
autosize={{ minRows: 3 }}
|
||
/>
|
||
)}
|
||
</Modal>
|
||
|
||
<SkillDetailSideSheet
|
||
visible={deriveVisible}
|
||
onCancel={() => setDeriveVisible(false)}
|
||
title={t('中文化与云端化改写')}
|
||
footer={
|
||
<Button theme='solid' type='primary' onClick={submitDerived}>
|
||
{t('保存为新版本')}
|
||
</Button>
|
||
}
|
||
>
|
||
<div className='skill-derive-grid'>
|
||
{[
|
||
'name_zh',
|
||
'name_en',
|
||
'description_zh',
|
||
'description_en',
|
||
'triggers_zh',
|
||
'triggers_en',
|
||
'scenarios_zh',
|
||
'scenarios_en',
|
||
'compact_constraint_zh',
|
||
'compact_constraint_en',
|
||
'change_statement',
|
||
].map((field) => (
|
||
<label key={field}>
|
||
<Text>{field}</Text>
|
||
<TextArea
|
||
value={deriveForm[field] || ''}
|
||
onChange={(value) =>
|
||
setDeriveForm((old) => ({ ...old, [field]: value }))
|
||
}
|
||
autosize
|
||
/>
|
||
</label>
|
||
))}
|
||
<label className='skill-derive-body'>
|
||
<Text>body</Text>
|
||
<TextArea
|
||
value={deriveForm.body || ''}
|
||
onChange={(value) =>
|
||
setDeriveForm((old) => ({ ...old, body: value }))
|
||
}
|
||
autosize={{ minRows: 14 }}
|
||
/>
|
||
</label>
|
||
</div>
|
||
</SkillDetailSideSheet>
|
||
<Modal
|
||
title={t('模型实测')}
|
||
visible={modelTestVisible}
|
||
onCancel={() => !modelTesting && setModelTestVisible(false)}
|
||
maskClosable={!modelTesting}
|
||
width={640}
|
||
footer={
|
||
<div className='skill-model-test-footer'>
|
||
<Button
|
||
type='tertiary'
|
||
disabled={modelTesting}
|
||
onClick={() => setModelTestVisible(false)}
|
||
>
|
||
{t('关闭')}
|
||
</Button>
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
loading={modelTesting}
|
||
onClick={runModelTest}
|
||
>
|
||
{modelTesting ? t('测试中...') : t('开始测试')}
|
||
</Button>
|
||
</div>
|
||
}
|
||
>
|
||
<div className='skill-import-form'>
|
||
<Paragraph type='tertiary'>
|
||
{t(
|
||
'将以当前版本的 Skill 全文作为 system prompt 发起一次真实调用,结果自动作为审核证据落库。',
|
||
)}
|
||
</Paragraph>
|
||
<label>
|
||
<Text>{t('渠道')}</Text>
|
||
<Select
|
||
value={modelTestForm.channel_id}
|
||
loading={testChannelsLoading}
|
||
filter
|
||
style={{ width: '100%' }}
|
||
onChange={(value) =>
|
||
setModelTestForm((old) => {
|
||
const channel = testChannels.find(
|
||
(item) => item.id === value,
|
||
);
|
||
const models = channel
|
||
? String(channel.models || '')
|
||
.split(',')
|
||
.map((name) => name.trim())
|
||
: [];
|
||
return {
|
||
...old,
|
||
channel_id: value,
|
||
// 切换渠道后旧模型可能不在新渠道里,静默保留会让测试
|
||
// 打到"渠道不支持该模型"的必败请求上。
|
||
model:
|
||
value === 0 || models.includes(old.model)
|
||
? old.model
|
||
: '',
|
||
};
|
||
})
|
||
}
|
||
optionList={[
|
||
{ value: 0, label: t('自动路由(按模型自动选择渠道)') },
|
||
...testChannels.map((channel) => ({
|
||
value: channel.id,
|
||
label: `#${channel.id} ${channel.name}`,
|
||
})),
|
||
]}
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('模型')}</Text>
|
||
<Select
|
||
key={testModelSelectKey}
|
||
value={modelTestForm.model || undefined}
|
||
filter
|
||
allowCreate
|
||
showClear
|
||
style={{ width: '100%' }}
|
||
placeholder={
|
||
selectedTestChannel
|
||
? t('从该渠道的 {{count}} 个模型中选择', {
|
||
count: testModelOptions.length,
|
||
})
|
||
: t('选择或输入模型名称')
|
||
}
|
||
onChange={(value) =>
|
||
setModelTestForm((old) => ({ ...old, model: value || '' }))
|
||
}
|
||
optionList={testModelOptions.map((name) => ({
|
||
value: name,
|
||
label: name,
|
||
}))}
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('测试输入')}</Text>
|
||
<TextArea
|
||
value={modelTestForm.input}
|
||
onChange={(value) =>
|
||
setModelTestForm((old) => ({ ...old, input: value }))
|
||
}
|
||
placeholder={t('输入一段能触发该技能行为的任务描述')}
|
||
autosize={{ minRows: 4 }}
|
||
/>
|
||
</label>
|
||
{modelTestResult && (
|
||
<div
|
||
className={`skill-model-test-result ${modelTestResult.ok ? 'is-ok' : 'is-error'}`}
|
||
>
|
||
<div className='skill-model-test-result-meta'>
|
||
<Text strong>
|
||
{modelTestResult.ok ? t('测试成功') : t('测试失败')}
|
||
</Text>
|
||
<Text type='tertiary' size='small'>
|
||
{t('耗时')} {modelTestResult.elapsed.toFixed(2)}s
|
||
{modelTestResult.usage?.total_tokens
|
||
? ` · ${modelTestResult.usage.total_tokens} tokens`
|
||
: ''}
|
||
</Text>
|
||
</div>
|
||
<pre>
|
||
{modelTestResult.ok
|
||
? modelTestResult.content
|
||
: modelTestResult.error}
|
||
</pre>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</Modal>
|
||
</section>
|
||
);
|
||
};
|
||
|
||
export default SkillPlatform;
|