842 lines
31 KiB
React
842 lines
31 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 React, {
|
||
useCallback,
|
||
useContext,
|
||
useEffect,
|
||
useMemo,
|
||
useState,
|
||
} from 'react';
|
||
import {
|
||
Button,
|
||
Empty,
|
||
Input,
|
||
InputNumber,
|
||
Modal,
|
||
Select,
|
||
SideSheet,
|
||
Switch,
|
||
Tag,
|
||
TextArea,
|
||
Toast,
|
||
Typography,
|
||
} from '@/components/ui';
|
||
import { Search } from 'lucide-react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { useNavigate } from 'react-router-dom';
|
||
import { API } from '../../helpers';
|
||
import {
|
||
LicenseBadge,
|
||
RiskBadge,
|
||
SkillEmptyGuide,
|
||
SkillStatusTag,
|
||
} from '../../components/skill';
|
||
import {
|
||
usePageGuide,
|
||
PageGuideDrawer,
|
||
PageGuideTrigger,
|
||
} from '../../components/common/PageGuide';
|
||
import OrgPanel from './components/OrgPanel';
|
||
import { StatusContext } from '../../context/Status';
|
||
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
|
||
import './org-skills.css';
|
||
import OrgBreadcrumb from './components/OrgBreadcrumb';
|
||
|
||
const { Title, Text, Paragraph } = Typography;
|
||
|
||
const jsonList = (value) => {
|
||
try {
|
||
const parsed = JSON.parse(value || '[]');
|
||
return Array.isArray(parsed) ? parsed : [];
|
||
} catch {
|
||
return [];
|
||
}
|
||
};
|
||
|
||
const OrgSkillLibrary = ({ orgId, orgRole, canAssignSkills = false }) => {
|
||
const { t } = useTranslation();
|
||
const navigate = useNavigate();
|
||
const [statusState] = useContext(StatusContext);
|
||
// 平台超管(查看企业时 org_role=super_admin、无成员身份)拿不到 /api/org/list
|
||
// 里的这个企业,所以在平台超市页 activeOrg 解析不出来、没有启用面。他们的
|
||
// 企业上下文只有在 /org 内才明确(current_org_id),因此页内引入抽屉是超管
|
||
// 唯一可用的"代客开通"入口。
|
||
const isPlatformSuperAdmin = orgRole === 'super_admin';
|
||
// 与技能超市页同一开关:站点关闭「技能超市 · 为企业启用」后,超市页不再有
|
||
// 启用按钮,跳过去的入口必须同步收起,否则就是一条通向空手而归的路。
|
||
// 超管不受此开关约束——该开关的语义正是"仅平台可代为启用"。
|
||
const selfEnableAllowed = useMemo(() => {
|
||
const orgCenter = normalizeSidebarModulesAdmin(
|
||
statusState?.status?.SidebarModulesAdmin,
|
||
).orgCenter;
|
||
return orgCenter?.enabled !== false && orgCenter?.skillMarket !== false;
|
||
}, [statusState?.status?.SidebarModulesAdmin]);
|
||
const canImport = selfEnableAllowed || isPlatformSuperAdmin;
|
||
const headers = useMemo(() => ({ 'X-Org-Id': String(orgId) }), [orgId]);
|
||
const [items, setItems] = useState([]);
|
||
const [catalog, setCatalog] = useState(new Map());
|
||
const [selected, setSelected] = useState(null);
|
||
const [derivePolicy, setDerivePolicy] = useState(null);
|
||
const [derivedVersions, setDerivedVersions] = useState([]);
|
||
const [evidenceVersion, setEvidenceVersion] = useState(null);
|
||
const [evidence, setEvidence] = useState({
|
||
model: '',
|
||
input: '',
|
||
});
|
||
// 页内引入:直接复用 load() 已经取回的 catalog(/api/org/skills/market),
|
||
// 不额外发请求。主要服务平台超管——超市页对其解析不出企业上下文;对普通
|
||
// 管理员它是"就地快速添加",与超市页的分页/分类/需求热度视图互补。
|
||
const [importOpen, setImportOpen] = useState(false);
|
||
const [importKeyword, setImportKeyword] = useState('');
|
||
const [importingId, setImportingId] = useState(0);
|
||
// 三态分离:首次加载完成前不渲染空态(否则闪一下"技能库为空"),
|
||
// 加载失败要说人话且与"确实为空"区分开。
|
||
const [loaded, setLoaded] = useState(false);
|
||
const [loadError, setLoadError] = useState({ library: '', catalog: '' });
|
||
const [form, setForm] = useState({
|
||
display_name: '',
|
||
description_zh: '',
|
||
applicable_roles: '[]',
|
||
usage_boundary: '',
|
||
default_activation: 'manual',
|
||
derived_version_id: 0,
|
||
});
|
||
const load = useCallback(async () => {
|
||
// allSettled 而非 all:任一端点失败都会让两个 setState 都不执行,于是主
|
||
// 列表显示"企业技能库为空"、抽屉显示"平台目录暂无可用技能"——把硬故障
|
||
// 说成"平台还没上架技能",安抚性文案盖住真实错误。分别降级并记录错误态。
|
||
const [libraryOutcome, marketOutcome] = await Promise.allSettled([
|
||
API.get('/api/org/skills/library', { headers, skipErrorHandler: true }),
|
||
API.get('/api/org/skills/market', { headers, skipErrorHandler: true }),
|
||
]);
|
||
const pick = (outcome) =>
|
||
outcome.status === 'fulfilled' ? outcome.value : null;
|
||
const libraryRes = pick(libraryOutcome);
|
||
const marketRes = pick(marketOutcome);
|
||
const readError = (outcome, res) =>
|
||
outcome.status === 'rejected'
|
||
? outcome.reason?.response?.data?.message ||
|
||
outcome.reason?.message ||
|
||
t('加载失败')
|
||
: res?.data?.success
|
||
? ''
|
||
: res?.data?.message || t('加载失败');
|
||
if (libraryRes?.data?.success) setItems(libraryRes.data.data || []);
|
||
if (marketRes?.data?.success)
|
||
setCatalog(
|
||
new Map(
|
||
(marketRes.data.data || []).map((item) => [item.definition.id, item]),
|
||
),
|
||
);
|
||
setLoadError({
|
||
library: readError(libraryOutcome, libraryRes),
|
||
catalog: readError(marketOutcome, marketRes),
|
||
});
|
||
setLoaded(true);
|
||
}, [headers, t]);
|
||
useEffect(() => {
|
||
void load();
|
||
}, [load]);
|
||
// 库里已有的技能(无论启停)不重复出现在引入列表里——它们的启停归本页主列表管。
|
||
const libraryIds = useMemo(
|
||
() => new Set(items.map((policy) => policy.skill_id)),
|
||
[items],
|
||
);
|
||
const catalogName = useCallback(
|
||
(item) =>
|
||
item?.locales?.find((locale) => locale.locale === 'zh')?.name ||
|
||
item?.locales?.[0]?.name ||
|
||
item?.definition?.canonical_id ||
|
||
`Skill #${item?.definition?.id}`,
|
||
[],
|
||
);
|
||
const importCandidates = useMemo(() => {
|
||
const keyword = importKeyword.trim().toLowerCase();
|
||
return [...catalog.values()]
|
||
.filter((item) => !libraryIds.has(item.definition.id))
|
||
.filter((item) => {
|
||
if (!keyword) return true;
|
||
return (
|
||
catalogName(item).toLowerCase().includes(keyword) ||
|
||
String(item.definition?.canonical_id || '')
|
||
.toLowerCase()
|
||
.includes(keyword)
|
||
);
|
||
});
|
||
}, [catalog, libraryIds, importKeyword, catalogName]);
|
||
const importSkill = async (skillId) => {
|
||
// 有请求在飞时不接受新点击:单值 importingId 无法表达多个并发,
|
||
// 先完成的那个会把 loading 清掉,让仍在飞行的按钮看起来可再点。
|
||
if (importingId) return;
|
||
setImportingId(skillId);
|
||
let enabled = false;
|
||
try {
|
||
// 与技能超市页同一端点。失败分两路:controller 的 brainError 走 400/422
|
||
// (axios reject,故需 skipErrorHandler 避免双 Toast),中间件 abortOrg
|
||
// 走 200+success:false(axios 不 reject,只有 !success 分支能兜住)。
|
||
const response = await API.put(
|
||
`/api/org/skills/library/${skillId}/enabled`,
|
||
{ enabled: true },
|
||
{ headers, skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success) {
|
||
throw new Error(response.data?.message || t('操作失败'));
|
||
}
|
||
enabled = true;
|
||
// 平台超管的 can_assign_skills 后端恒 false(无成员身份,分发路由的
|
||
// RequireOrgMemberActor 必拒),菜单里也没有该入口。把他们指向"分发与
|
||
// 锁定"等于指向一个进不去的页面——代客开通的收尾必须由企业管理员完成。
|
||
Toast.success({
|
||
content: canAssignSkills
|
||
? t('已加入企业技能库;还需在「分发与锁定」建策略,成员才可用')
|
||
: t(
|
||
'已加入企业技能库;还需由企业管理员在「分发与锁定」建策略,成员才可用',
|
||
),
|
||
duration: 6,
|
||
});
|
||
} catch (error) {
|
||
Toast.error(
|
||
error?.response?.data?.message || error?.message || t('操作失败'),
|
||
);
|
||
} finally {
|
||
setImportingId(0);
|
||
}
|
||
if (!enabled) return;
|
||
// 启用即视为采纳该技能下的员工诉求(与技能超市页同口径);处置失败静默,
|
||
// 下次进页面还会看到该诉求。不做的话超市页的「N 人想要」永不消失。
|
||
try {
|
||
await API.put(
|
||
`/api/org/skills/demand/${skillId}`,
|
||
{ status: 'accepted' },
|
||
{ headers, skipErrorHandler: true },
|
||
);
|
||
} catch (_error) {
|
||
/* 见上:静默 */
|
||
}
|
||
// 刷新放在 try 之外:load() 内部的 GET 未跳过全局拦截器,放在同一个 try 里
|
||
// 会在刷新失败时叠加一条"失败"Toast(且是 axios 英文原文),而启用其实已
|
||
// 经成功。失败时保持旧列表即可,用户再操作一次会自然重拉。
|
||
await load().catch(() => {});
|
||
};
|
||
const openCustomization = (policy, derivedVersionId) => {
|
||
const customization = policy.customization || {};
|
||
setForm({
|
||
display_name: customization.display_name || '',
|
||
description_zh: customization.description_zh || '',
|
||
applicable_roles: customization.applicable_roles || '[]',
|
||
usage_boundary: customization.usage_boundary || '',
|
||
default_activation: customization.default_activation || 'manual',
|
||
derived_version_id:
|
||
derivedVersionId ?? customization.derived_version_id ?? 0,
|
||
});
|
||
setSelected(policy);
|
||
};
|
||
const configure = async (policy, patch) => {
|
||
const payload = {
|
||
enabled: policy.enabled,
|
||
emergency_stopped: policy.emergency_stopped,
|
||
version_policy: policy.version_policy || 'follow',
|
||
locked_version_id: policy.locked_version_id || 0,
|
||
...patch,
|
||
};
|
||
const response = await API.put(
|
||
`/api/org/skills/library/${policy.skill_id}/policy`,
|
||
payload,
|
||
{ headers },
|
||
);
|
||
if (!response.data?.success) {
|
||
Toast.error(response.data?.message || t('操作失败'));
|
||
return;
|
||
}
|
||
await load();
|
||
};
|
||
const saveCustomization = async () => {
|
||
const payload = {
|
||
...form,
|
||
applicable_roles_json: form.applicable_roles || '[]',
|
||
};
|
||
const response = await API.put(
|
||
`/api/org/skills/library/${selected.skill_id}/customization`,
|
||
payload,
|
||
{ headers },
|
||
);
|
||
if (!response.data?.success) {
|
||
Toast.error(response.data?.message || t('操作失败'));
|
||
return;
|
||
}
|
||
Toast.success(t('企业定制已保存'));
|
||
setSelected(null);
|
||
await load();
|
||
};
|
||
const [deriveForm, setDeriveForm] = useState({
|
||
body: '',
|
||
name_zh: '',
|
||
name_en: '',
|
||
description_zh: '',
|
||
description_en: '',
|
||
triggers_zh: '',
|
||
triggers_en: '',
|
||
scenarios_zh: '',
|
||
scenarios_en: '',
|
||
compact_constraint_zh: '',
|
||
compact_constraint_en: '',
|
||
change_statement: '',
|
||
default_output_language: 'auto',
|
||
capabilities: ['prompt_only'],
|
||
tags: [],
|
||
});
|
||
const saveDerived = async () => {
|
||
const list = (value) =>
|
||
String(value || '')
|
||
.split(',')
|
||
.map((item) => item.trim())
|
||
.filter(Boolean);
|
||
const parentVersion = catalog.get(derivePolicy.skill_id)?.version;
|
||
if (!parentVersion) {
|
||
Toast.error(t('平台当前版本不可用,无法创建派生版本'));
|
||
return;
|
||
}
|
||
if (!String(deriveForm.body || '').trim()) {
|
||
Toast.warning(t('请先填写派生版本正文(body)'));
|
||
return;
|
||
}
|
||
const response = await API.post(
|
||
`/api/org/skills/versions/${parentVersion.id}/derive`,
|
||
{
|
||
...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),
|
||
},
|
||
{ headers },
|
||
);
|
||
if (!response.data?.success) {
|
||
Toast.error(response.data?.message || t('操作失败'));
|
||
return;
|
||
}
|
||
Toast.success(t('企业派生版本已创建,请完成模型实测和审核后再激活'));
|
||
await loadDerivedVersions(derivePolicy.skill_id);
|
||
await load();
|
||
};
|
||
const loadDerivedVersions = async (skillId) => {
|
||
const response = await API.get(
|
||
`/api/org/skills/library/${skillId}/derived-versions`,
|
||
{ headers },
|
||
);
|
||
if (!response.data?.success) {
|
||
Toast.error(response.data?.message || t('派生版本加载失败'));
|
||
return;
|
||
}
|
||
setDerivedVersions(response.data.data || []);
|
||
};
|
||
const openDerived = async (policy) => {
|
||
const catalogItem = catalog.get(policy.skill_id);
|
||
const version = catalogItem?.version;
|
||
const zh = catalogItem?.locales?.find((item) => item.locale === 'zh') || {};
|
||
const en = catalogItem?.locales?.find((item) => item.locale === 'en') || {};
|
||
setDeriveForm({
|
||
// The platform never serializes version bodies to organizations, so a
|
||
// derived version's full body must be authored here from scratch.
|
||
body: '',
|
||
name_zh: zh.name || '',
|
||
name_en: en.name || '',
|
||
description_zh: zh.description || '',
|
||
description_en: en.description || '',
|
||
triggers_zh: jsonList(zh.triggers).join(', '),
|
||
triggers_en: jsonList(en.triggers).join(', '),
|
||
scenarios_zh: jsonList(zh.scenarios).join(', '),
|
||
scenarios_en: jsonList(en.scenarios).join(', '),
|
||
compact_constraint_zh: zh.compact_constraint || '',
|
||
compact_constraint_en: en.compact_constraint || '',
|
||
change_statement: '',
|
||
default_output_language: version?.default_output_language || 'auto',
|
||
capabilities: jsonList(version?.capabilities),
|
||
tags: jsonList(version?.tags),
|
||
});
|
||
setDerivePolicy(policy);
|
||
setDerivedVersions([]);
|
||
await loadDerivedVersions(policy.skill_id);
|
||
};
|
||
const derivedAction = async (versionId, suffix, body = {}) => {
|
||
const response = await API.post(
|
||
`/api/org/skills/versions/${versionId}/${suffix}`,
|
||
body,
|
||
{ headers },
|
||
);
|
||
if (!response.data?.success) {
|
||
Toast.error(response.data?.message || t('操作失败'));
|
||
return false;
|
||
}
|
||
await loadDerivedVersions(derivePolicy.skill_id);
|
||
return true;
|
||
};
|
||
const recordDerivedEvidence = async () => {
|
||
if (!evidence.model.trim() || !evidence.input.trim()) {
|
||
Toast.error(t('模型名称与测试输入不能为空'));
|
||
return;
|
||
}
|
||
if (
|
||
await derivedAction(evidenceVersion, 'test', {
|
||
model: evidence.model,
|
||
input: evidence.input,
|
||
})
|
||
) {
|
||
Toast.success(t('模型实测完成,证据已落库'));
|
||
setEvidenceVersion(null);
|
||
}
|
||
};
|
||
// 使用指引:技能库四项治理动作的阅读式说明(无上手流程,不出进度胶囊)。
|
||
const guide = usePageGuide({
|
||
guideKey: 'org-skill-library',
|
||
title: t('企业技能库 · 使用指引'),
|
||
intro: t('已启用技能的治理中心:启停、版本、止血与企业化定制'),
|
||
steps: [
|
||
{
|
||
title: t('启用状态与版本策略'),
|
||
detail: t('每行开关控制启用;版本策略决定是否跟随平台升级'),
|
||
points: [
|
||
t('「跟随平台升级」自动使用平台最新审核版本'),
|
||
t('「锁定版本」把当前版本固定下来,平台升级不影响企业在用版本'),
|
||
],
|
||
},
|
||
{
|
||
title: t('紧急停用'),
|
||
detail: t('发现质量或安全问题时的止血开关'),
|
||
points: [t('点「紧急停用」该技能立即对全企业失效,点「恢复」重新生效')],
|
||
},
|
||
{
|
||
title: t('企业展示定制'),
|
||
detail: t('把平台技能翻译成员工看得懂的说法'),
|
||
points: [
|
||
t('可设置企业内展示名称、中文说明与使用边界'),
|
||
t('成员在「我的技能」里看到的就是这里配置的内容'),
|
||
],
|
||
},
|
||
{
|
||
title: t('内容派生'),
|
||
detail: t('基于平台版本创建带企业知识的派生版本'),
|
||
points: [
|
||
t('派生版本的正文需要自行撰写——平台不会下发原始正文'),
|
||
t(
|
||
'流程:创建派生 → 执行模型实测 → 领取审核 → 审核通过 → 设为企业版本',
|
||
),
|
||
t('模型实测会真实调用所选模型,响应自动留档为审核证据'),
|
||
],
|
||
},
|
||
],
|
||
faq: [
|
||
{
|
||
q: t('技能库为空?'),
|
||
a: t('点页面右上角「引入技能」,从平台目录中为企业启用'),
|
||
},
|
||
{
|
||
q: t('已启用但成员看不到?'),
|
||
a: t('还需要在「分发与锁定」创建分发策略覆盖到目标成员'),
|
||
},
|
||
],
|
||
});
|
||
return (
|
||
<main className='org-skills-page'>
|
||
<header className='org-skills-hero'>
|
||
<div>
|
||
<OrgBreadcrumb current={t('企业技能库')} />
|
||
<Title heading={3}>{t('企业技能库')}</Title>
|
||
<Paragraph>
|
||
{t('控制启用状态、版本锁定、紧急停用和企业展示定制。')}
|
||
</Paragraph>
|
||
</div>
|
||
<div className='org-skills-hero-actions'>
|
||
{/* 页内引入:对平台超管这是唯一可用入口(超市页解析不出其企业上下文);
|
||
对普通管理员是就地快速添加。数据复用已加载的 catalog,不额外发请求。 */}
|
||
{canImport ? (
|
||
<Button theme='solid' onClick={() => setImportOpen(true)}>
|
||
{t('引入技能')}
|
||
</Button>
|
||
) : null}
|
||
{/* 浏览完整平台目录(分页/搜索/分类)仍去超市页;超管在那里没有企业
|
||
上下文,故不对其展示,避免点过去发现无法启用。 */}
|
||
{selfEnableAllowed && !isPlatformSuperAdmin ? (
|
||
<Button
|
||
theme='borderless'
|
||
onClick={() => navigate('/skill-market')}
|
||
>
|
||
{t('浏览技能超市')}
|
||
</Button>
|
||
) : null}
|
||
<PageGuideTrigger guide={guide} />
|
||
</div>
|
||
</header>
|
||
<PageGuideDrawer guide={guide} />
|
||
{!loaded ? (
|
||
<SkillEmptyGuide title={t('正在加载企业技能库')} />
|
||
) : loadError.library ? (
|
||
// 错误态必须与"确实为空"分开:否则接口 5xx 会被渲染成
|
||
// "企业技能库为空 / 点引入技能",把硬故障说成正常状态。
|
||
<SkillEmptyGuide
|
||
title={t('企业技能库加载失败')}
|
||
description={loadError.library}
|
||
actionLabel={t('重试')}
|
||
onAction={() => void load()}
|
||
/>
|
||
) : items.length === 0 ? (
|
||
<SkillEmptyGuide
|
||
title={t('企业技能库为空')}
|
||
description={
|
||
canImport
|
||
? t('点「引入技能」从平台目录中为企业启用 Skill。')
|
||
: t('平台已关闭自助启用,请联系平台管理员为企业启用 Skill。')
|
||
}
|
||
actionLabel={canImport ? t('引入技能') : undefined}
|
||
onAction={canImport ? () => setImportOpen(true) : undefined}
|
||
/>
|
||
) : (
|
||
<section className='org-skill-library-list'>
|
||
{items.map((policy) => (
|
||
<OrgPanel
|
||
key={policy.id}
|
||
title={
|
||
catalog
|
||
.get(policy.skill_id)
|
||
?.locales?.find((item) => item.locale === 'zh')?.name ||
|
||
`Skill #${policy.skill_id}`
|
||
}
|
||
actions={
|
||
<SkillStatusTag
|
||
status={
|
||
policy.emergency_stopped
|
||
? 'quarantined'
|
||
: policy.enabled
|
||
? 'published'
|
||
: 'withdrawn'
|
||
}
|
||
/>
|
||
}
|
||
>
|
||
<div className='org-skill-policy-row'>
|
||
<label>
|
||
<Text>{t('启用')}</Text>
|
||
<Switch
|
||
checked={policy.enabled}
|
||
onChange={(enabled) => configure(policy, { enabled })}
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('版本策略')}</Text>
|
||
<Select
|
||
value={policy.version_policy || 'follow'}
|
||
onChange={(version_policy) =>
|
||
configure(policy, {
|
||
version_policy,
|
||
locked_version_id:
|
||
version_policy === 'locked'
|
||
? catalog.get(policy.skill_id)?.version?.id || 0
|
||
: 0,
|
||
})
|
||
}
|
||
>
|
||
<Select.Option value='follow'>
|
||
{t('跟随平台升级')}
|
||
</Select.Option>
|
||
<Select.Option value='locked'>
|
||
{t('锁定版本')}
|
||
</Select.Option>
|
||
</Select>
|
||
</label>
|
||
<Button
|
||
type='danger'
|
||
onClick={() =>
|
||
configure(policy, {
|
||
emergency_stopped: !policy.emergency_stopped,
|
||
})
|
||
}
|
||
>
|
||
{policy.emergency_stopped ? t('恢复') : t('紧急停用')}
|
||
</Button>
|
||
<Button onClick={() => openCustomization(policy)}>
|
||
{t('企业定制')}
|
||
</Button>
|
||
<Button onClick={() => void openDerived(policy)}>
|
||
{t('内容派生')}
|
||
</Button>
|
||
</div>
|
||
</OrgPanel>
|
||
))}
|
||
</section>
|
||
)}
|
||
<Modal
|
||
title={t('企业展示定制')}
|
||
visible={!!selected}
|
||
onCancel={() => setSelected(null)}
|
||
onOk={saveCustomization}
|
||
>
|
||
<div className='org-skill-form'>
|
||
<label>
|
||
<Text>{t('展示名称')}</Text>
|
||
<TextArea
|
||
value={form.display_name}
|
||
onChange={(value) =>
|
||
setForm((old) => ({ ...old, display_name: value }))
|
||
}
|
||
autosize
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('中文说明')}</Text>
|
||
<TextArea
|
||
value={form.description_zh}
|
||
onChange={(value) =>
|
||
setForm((old) => ({ ...old, description_zh: value }))
|
||
}
|
||
autosize
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('使用边界')}</Text>
|
||
<TextArea
|
||
value={form.usage_boundary}
|
||
onChange={(value) =>
|
||
setForm((old) => ({ ...old, usage_boundary: value }))
|
||
}
|
||
autosize
|
||
/>
|
||
</label>
|
||
<label>
|
||
<Text>{t('已审核派生版本 ID')}</Text>
|
||
<InputNumber
|
||
min={0}
|
||
value={form.derived_version_id}
|
||
onChange={(derived_version_id) =>
|
||
setForm((old) => ({ ...old, derived_version_id }))
|
||
}
|
||
/>
|
||
</label>
|
||
</div>
|
||
</Modal>
|
||
<Modal
|
||
title={t('创建企业派生版本')}
|
||
visible={!!derivePolicy}
|
||
onCancel={() => setDerivePolicy(null)}
|
||
onOk={saveDerived}
|
||
width={760}
|
||
>
|
||
<div className='org-skill-form'>
|
||
{derivedVersions.map((item) => (
|
||
<div key={item.version.id} className='org-skill-policy-row'>
|
||
<Text>v{item.version.version_no}</Text>
|
||
<Tag>{item.runtime?.conclusion || 'scan_pending'}</Tag>
|
||
<Tag>{item.review?.status || 'pending'}</Tag>
|
||
<Button
|
||
size='small'
|
||
onClick={() => {
|
||
// Reset the captured inputs on every open: the Form fields
|
||
// remount empty, so stale state from a previous version's
|
||
// test must never be silently submitted for this one.
|
||
setEvidence({ model: '', input: '' });
|
||
setEvidenceVersion(item.version.id);
|
||
}}
|
||
>
|
||
{t('执行模型实测')}
|
||
</Button>
|
||
<Button
|
||
size='small'
|
||
disabled={item.review?.status !== 'pending'}
|
||
onClick={() =>
|
||
void derivedAction(item.version.id, 'review/start')
|
||
}
|
||
>
|
||
{t('领取审核')}
|
||
</Button>
|
||
<Button
|
||
size='small'
|
||
disabled={item.review?.status !== 'reviewing'}
|
||
onClick={() =>
|
||
void derivedAction(item.version.id, 'review/decision', {
|
||
approved: true,
|
||
conclusion: { decision: 'approved' },
|
||
})
|
||
}
|
||
>
|
||
{t('审核通过')}
|
||
</Button>
|
||
<Button
|
||
size='small'
|
||
disabled={item.review?.status !== 'approved'}
|
||
onClick={() => {
|
||
openCustomization(derivePolicy, item.version.id);
|
||
setDerivePolicy(null);
|
||
}}
|
||
>
|
||
{t('设为企业版本')}
|
||
</Button>
|
||
</div>
|
||
))}
|
||
{[
|
||
'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>
|
||
<Text>body</Text>
|
||
<TextArea
|
||
value={deriveForm.body}
|
||
onChange={(value) =>
|
||
setDeriveForm((old) => ({ ...old, body: value }))
|
||
}
|
||
placeholder={t(
|
||
'平台正文不会同步到企业侧,请在此完整撰写派生版本的正文内容',
|
||
)}
|
||
autosize={{ minRows: 10 }}
|
||
/>
|
||
</label>
|
||
</div>
|
||
</Modal>
|
||
<Modal
|
||
title={t('执行真实模型测试')}
|
||
visible={!!evidenceVersion}
|
||
onCancel={() => setEvidenceVersion(null)}
|
||
onOk={recordDerivedEvidence}
|
||
>
|
||
{/* Plain controlled inputs: Semi Form fields keep their own state and
|
||
ignore the value prop, which previously let stale state diverge
|
||
from what the user saw on screen. */}
|
||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||
<Input
|
||
placeholder={t('模型')}
|
||
value={evidence.model}
|
||
onChange={(model) => setEvidence((old) => ({ ...old, model }))}
|
||
/>
|
||
<TextArea
|
||
placeholder={t('测试输入')}
|
||
value={evidence.input}
|
||
onChange={(input) => setEvidence((old) => ({ ...old, input }))}
|
||
/>
|
||
<Paragraph type='tertiary'>
|
||
{t(
|
||
'提交后将实际调用所选模型执行该版本正文,真实响应自动落库为审核证据。',
|
||
)}
|
||
</Paragraph>
|
||
</div>
|
||
</Modal>
|
||
<SideSheet
|
||
title={t('引入技能')}
|
||
visible={importOpen}
|
||
onCancel={() => {
|
||
setImportOpen(false);
|
||
setImportKeyword('');
|
||
}}
|
||
width={560}
|
||
className='org-sidesheet'
|
||
>
|
||
<div className='org-skill-import'>
|
||
<Paragraph type='tertiary'>
|
||
{t(
|
||
'从平台已审核的技能目录中为本企业启用。启用后还需在「分发与锁定」建策略,成员才可用。',
|
||
)}
|
||
</Paragraph>
|
||
<Input
|
||
value={importKeyword}
|
||
onChange={setImportKeyword}
|
||
prefix={<Search size={15} />}
|
||
placeholder={t('搜索技能名称或标识')}
|
||
showClear
|
||
/>
|
||
{!loaded ? (
|
||
<Empty title={t('正在加载平台目录')} />
|
||
) : loadError.catalog ? (
|
||
// 同上:目录接口失败不能显示成"平台暂无可用技能"。
|
||
<Empty
|
||
title={t('平台目录加载失败')}
|
||
description={loadError.catalog}
|
||
/>
|
||
) : importCandidates.length === 0 ? (
|
||
<Empty
|
||
title={
|
||
catalog.size === 0
|
||
? t('平台目录暂无可用技能')
|
||
: importKeyword.trim()
|
||
? t('没有匹配的技能')
|
||
: t('平台目录中的技能都已在企业技能库中')
|
||
}
|
||
description={
|
||
catalog.size === 0
|
||
? t('平台审核通过的技能会出现在这里,稍后再来看看。')
|
||
: undefined
|
||
}
|
||
/>
|
||
) : (
|
||
<ul className='org-skill-import-list'>
|
||
{importCandidates.map((item) => (
|
||
<li key={item.definition.id}>
|
||
<div className='org-skill-import-main'>
|
||
<Text strong>{catalogName(item)}</Text>
|
||
<Text type='tertiary' size='small'>
|
||
{item.definition?.canonical_id} · v
|
||
{item.version?.version_no}
|
||
</Text>
|
||
</div>
|
||
{/* 合规徽章与启用按钮同排:启用是留审计的治理写入,
|
||
许可证决策与运行时安全结论必须在决策点可见。 */}
|
||
<div className='org-skill-import-actions'>
|
||
<LicenseBadge
|
||
expression={item.license?.expression}
|
||
decision={item.license?.decision}
|
||
/>
|
||
<RiskBadge conclusion={item.runtime?.conclusion} />
|
||
<Button
|
||
size='small'
|
||
theme='solid'
|
||
loading={importingId === item.definition.id}
|
||
onClick={() => void importSkill(item.definition.id)}
|
||
>
|
||
{t('启用')}
|
||
</Button>
|
||
</div>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</div>
|
||
</SideSheet>
|
||
</main>
|
||
);
|
||
};
|
||
|
||
export default OrgSkillLibrary;
|