Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(skill): 企业版技能面板修复——企业卸载接口/安装态唯一键/展示名与来源/页签切换容错

huben2cb9fb5cb658
diff --git a/jiuwenswarm/channels/web/frontend/src/components/SkillPanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/SkillPanel/index.tsx
index 792d2e7d7b..cab7811dd3 100644
--- a/jiuwenswarm/channels/web/frontend/src/components/SkillPanel/index.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/components/SkillPanel/index.tsx
@@ -160,7 +160,8 @@ function getSourceLabel(source: string, t: (key: string) => string, isBuiltinSou
if (source === "builtin") return t('skills.source.builtin');
if (source === "clawhub") return t('skills.source.clawhub');
if (source === "skillnet") return t('skills.source.skillnet');
- if (source === "teamskillshub" || source === "swarmskillhub") return t('skills.source.teamskillshub');
+ if (source === "teamskillshub") return t('skills.source.teamskillshub');
+ if (source === "swarmskillhub") return t('skills.source.swarmskillhub');
return source || t('skills.source.unknown');
}
@@ -617,6 +618,8 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
const [debouncedSearch, setDebouncedSearch] = useState("");
const searchDebounceRef = useRef<number | null>(null);
const prevIsActiveRef = useRef(isActive);
+ /** 首次列表加载成功后置 true:刷新失败(如瞬态 SCOPE_FULL_TIMEOUT)保留旧列表,不清空页面 */
+ const skillsLoadedRef = useRef(false);
const [selectedSkill, setSelectedSkill] = useState<SkillDetail | null>(null);
const [listState, setListState] = useState<LoadState>("idle");
const [detailState, setDetailState] = useState<LoadState>("idle");
@@ -844,6 +847,7 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
);
setSkills((data.skills || []).map(normalizeSkillItem));
setPlugins(data.plugins || []);
+ skillsLoadedRef.current = true;
setListState("success");
if (!readOnly) {
@@ -851,7 +855,8 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
}
} catch (error) {
console.error(error);
- setListState("error");
+ // 已有成功数据时保留旧列表(stale-while-error),避免页签切换期间瞬态失败清空整个页面
+ setListState(skillsLoadedRef.current ? "success" : "error");
}
}, [fetchMarketplaces, readOnly, withSession]);
@@ -1265,17 +1270,19 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
setMessage(null);
setMessageType(null);
try {
+ // 企业版 skills.uninstall 被网关拦截,卸载用户自装技能须走 skills.enterprise.uninstall
const data = await webRequest<{
success: boolean;
detail?: string;
message?: string;
- }>("skills.uninstall", withSession({
+ error_message?: string;
+ }>(readOnly ? "skills.enterprise.uninstall" : "skills.uninstall", withSession({
name: pluginName,
// 传 origin 让后端按来源精确定位目录与记录,避免重名技能误删另一个
...(origin ? { origin } : {}),
}));
if (!data.success) {
- throw new Error(data.detail || data.message || t('skills.errors.uninstallFailed'));
+ throw new Error(data.detail || data.message || data.error_message || t('skills.errors.uninstallFailed'));
}
showMessage("success", t('skills.messages.uninstalled', { pluginName }));
await fetchSkills();
@@ -1288,7 +1295,7 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
setActionTarget(null);
}
},
- [fetchSkills, handleBackToList, t, withSession]
+ [fetchSkills, handleBackToList, readOnly, t, withSession]
);
const renderActionButton = (skill: SkillItem) => {
@@ -1442,9 +1449,11 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
};
const renderStatus = (skill: SkillItem) => {
- if (skill.installed === true) return t('skills.status.installed');
- if (installedSkillMap.has(skill.name)) return t('skills.status.installed');
- if (skill.source === "local") return t('skills.status.installed');
+ const installed =
+ skill.installed === true || installedSkillMap.has(skill.name) || skill.source === "local";
+ // 「全部」页签里的条目均已安装,「已安装」徽章冗余,不再展示
+ if (installed && mySkillsSubTab === "all") return "";
+ if (installed) return t('skills.status.installed');
if (skill.is_builtin) {
return "";
}
@@ -2122,7 +2131,7 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
{listState === "success" && builtinSkills.length > 0 && (
builtinSkills.map((skill) => {
const avatar = getSkillAvatar(skill.name);
- const displayName = skill.display_name || skill.name;
+ const displayName = skill.market_display_name || skill.display_name || skill.name;
const isDisabled = skill.enabled === false;
const isToggling = actionTarget === `toggle:${skill.name}`;
const isInstalled = skill.installed === true || installedSkillMap.has(skill.name) || skill.source === "local";
@@ -2283,7 +2292,7 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
</div>
<div>
<div className="text-lg font-semibold text-text-strong">
- {selectedSkill.display_name || selectedSkill.name}
+ {selectedSkill.market_display_name || selectedSkill.display_name || selectedSkill.name}
</div>
<div className="text-sm text-text-muted mt-1">
{skillDisplayDesc(selectedSkill, t('skills.noDescription'))}
@@ -2467,7 +2476,7 @@ export function SkillPanel({ sessionId, onNavigateToConfig, isActive = false }:
{listState === "success" &&
pagedMySkills.map((skill) => {
const avatar = getSkillAvatar(skill.name);
- const displayName = skill.display_name || skill.name;
+ const displayName = skill.market_display_name || skill.display_name || skill.name;
const isDisabled = skill.enabled === false;
const isToggling = actionTarget === `toggle:${skill.origin || skill.name}`;
return (
diff --git a/jiuwenswarm/channels/web/frontend/src/features/EnterpriseSkillSourcePanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/features/EnterpriseSkillSourcePanel/index.tsx
index cee8847c3d..cc978f6753 100644
--- a/jiuwenswarm/channels/web/frontend/src/features/EnterpriseSkillSourcePanel/index.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/features/EnterpriseSkillSourcePanel/index.tsx
@@ -82,6 +82,29 @@ function labelText(label: { name?: string } | string | undefined): string {
return label.name || '';
}
+/** 安装/更新中状态按产物唯一键判定:name 在 Hub 侧可重复或为空,直接用会让所有按钮一起转 */
+function itemKey(item: SkillCandidate, fallbackSourceId: string): string {
+ return `${item.source_id || fallbackSourceId}:${item.skill_id || item.name}:${item.version_id}`;
+}
+
+/**
+ * 页签来回切换会卸载并重挂面板,挂载时的自动加载(providers/updates/search)
+ * 用短 TTL 模块级缓存兜底:避免重复请求打满后端 scope 队列(SCOPE_FULL_TIMEOUT),
+ * 也让瞬态失败时可回退到缓存快照而不是清空列表。用户主动操作(搜索/翻页/安装/更新)始终走实时请求。
+ */
+const MOUNT_CACHE_TTL_MS = 60_000;
+const providersCache = new Map<string, { at: number; sources: SourceDescriptor[] }>();
+const updatesCache = new Map<string, { at: number; items: UpdateStatus[] }>();
+const searchCache = new Map<string, { at: number; items: SkillCandidate[]; total: number }>();
+
+function isFresh(at: number): boolean {
+ return Date.now() - at < MOUNT_CACHE_TTL_MS;
+}
+
+function searchCacheKey(sessionId: string, sourceId: string, q: string, page: number): string {
+ return `${sessionId}|${sourceId}|${q}|${page}`;
+}
+
export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', externalSearchQuery, onInstalled }: EnterpriseSkillSourcePanelProps) {
const { t } = useTranslation();
const [sources, setSources] = useState<SourceDescriptor[]>([]);
@@ -100,9 +123,22 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
const withSession = useCallback((params?: Record<string, unknown>) => ({ ...(params || {}), session_id: sessionId }), [sessionId]);
- // 1) 拉取可用技能源,默认选中第一个可搜索的来源
+ // 1) 拉取可用技能源,默认选中第一个可搜索的来源(挂载时优先用缓存,避免页签切换重复请求)
useEffect(() => {
let cancelled = false;
+ const applySources = (enabled: SourceDescriptor[]) => {
+ if (cancelled) return;
+ setSources(enabled);
+ if (enabled.length > 0) setSourceId(enabled[0].source_id);
+ else setLoadState('error');
+ };
+ const cached = providersCache.get(sessionId);
+ if (cached && isFresh(cached.at)) {
+ applySources(cached.sources);
+ return () => {
+ cancelled = true;
+ };
+ }
void (async () => {
try {
const data = await webRequest<{
@@ -112,12 +148,15 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
}>('skills.source.providers', withSession());
if (!data.success) throw new Error(data.error_message || t('skills.source.errors.loadFailed'));
const enabled = (data.providers || []).filter(item => item.enabled !== false && (item.capabilities || []).includes('search'));
- if (cancelled) return;
- setSources(enabled);
- if (enabled.length > 0) setSourceId(enabled[0].source_id);
- else setLoadState('error');
+ providersCache.set(sessionId, { at: Date.now(), sources: enabled });
+ applySources(enabled);
} catch (error) {
if (cancelled) return;
+ const fallback = providersCache.get(sessionId);
+ if (fallback) {
+ applySources(fallback.sources);
+ return;
+ }
setLoadState('error');
showToast('error', error instanceof Error ? error.message : t('skills.source.errors.loadFailed'));
}
@@ -125,34 +164,58 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
return () => {
cancelled = true;
};
- }, [showToast, t, withSession]);
+ }, [sessionId, showToast, t, withSession]);
- // 2) 已安装技能的更新状态(按 source_id:name 作为已装判定)
- useEffect(() => {
- if (!sourceId) return;
- let cancelled = false;
- void (async () => {
+ // 2) 已安装技能的更新状态(按 source_id:name 作为已装判定;挂载走缓存,安装/更新后强制刷新)
+ const loadUpdates = useCallback(
+ async (targetSourceId: string, force = false) => {
+ if (!targetSourceId) return;
+ const cacheKey = `${sessionId}|${targetSourceId}`;
+ const applyItems = (items: UpdateStatus[]) => {
+ setUpdateStatuses(new Map(items.map(item => [`${item.source_id}:${item.name}`, item])));
+ };
+ const cached = updatesCache.get(cacheKey);
+ if (!force && cached && isFresh(cached.at)) {
+ applyItems(cached.items);
+ return;
+ }
try {
const data = await webRequest<{
success: boolean;
items?: UpdateStatus[];
- }>('skills.updates.check', withSession({ source_id: sourceId }));
- if (!cancelled && data.success) {
- setUpdateStatuses(new Map((data.items || []).map(item => [`${item.source_id}:${item.name}`, item])));
- }
+ }>('skills.updates.check', withSession({ source_id: targetSourceId }));
+ if (!data.success) return;
+ const items = data.items || [];
+ updatesCache.set(cacheKey, { at: Date.now(), items });
+ applyItems(items);
} catch {
// 更新状态查询失败不阻断搜索展示
}
- })();
- return () => {
- cancelled = true;
- };
- }, [sourceId, withSession]);
+ },
+ [sessionId, withSession],
+ );
+
+ useEffect(() => {
+ if (!sourceId) return;
+ void loadUpdates(sourceId);
+ }, [sourceId, loadUpdates]);
- // 3) 搜索
+ // 3) 搜索(preferCache 仅用于挂载/来源切换的自动加载;失败时回退缓存快照不清空列表)
const runSearch = useCallback(
- async (targetPage: number) => {
+ async (targetPage: number, options?: { preferCache?: boolean }) => {
if (!sourceId) return;
+ const q = query.trim();
+ const cacheKey = searchCacheKey(sessionId, sourceId, q, targetPage);
+ if (options?.preferCache) {
+ const cached = searchCache.get(cacheKey);
+ if (cached && isFresh(cached.at)) {
+ setResults(cached.items);
+ setTotal(cached.total);
+ setPage(targetPage);
+ setLoadState('success');
+ return;
+ }
+ }
setLoadState('loading');
clearToast();
try {
@@ -165,30 +228,41 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
'skills.source.search',
withSession({
source_id: sourceId,
- q: query.trim(),
+ q,
page: targetPage,
page_size: PAGE_SIZE,
}),
);
if (!data.success) throw new Error(data.error_message || t('skills.source.errors.searchFailed'));
- setResults(data.items || []);
- setTotal(data.total ?? (data.items || []).length);
+ const items = data.items || [];
+ const newTotal = data.total ?? items.length;
+ searchCache.set(cacheKey, { at: Date.now(), items, total: newTotal });
+ setResults(items);
+ setTotal(newTotal);
setPage(targetPage);
setLoadState('success');
} catch (error) {
- setResults([]);
- setTotal(0);
- setLoadState('error');
+ const cached = searchCache.get(cacheKey);
+ if (cached) {
+ setResults(cached.items);
+ setTotal(cached.total);
+ setPage(targetPage);
+ setLoadState('success');
+ } else {
+ setResults([]);
+ setTotal(0);
+ setLoadState('error');
+ }
showToast('error', error instanceof Error ? error.message : t('skills.source.errors.searchFailed'));
}
},
- [query, showToast, sourceId, t, withSession],
+ [query, sessionId, showToast, sourceId, t, withSession],
);
useEffect(() => {
if (sourceId) {
setPage(1);
- void runSearch(1);
+ void runSearch(1, { preferCache: true });
}
// sourceId 变化时触发;内部模式 query 变化由搜索按钮/回车触发,外部模式由下面 query effect 触发
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -212,7 +286,7 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
const handleInstall = useCallback(
async (item: SkillCandidate, force = false) => {
if (installingId) return;
- setInstallingId(item.name);
+ setInstallingId(itemKey(item, sourceId));
clearToast();
try {
const data = await webRequest<{
@@ -226,6 +300,8 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
source_id: item.source_id || sourceId,
skill_id: item.skill_id,
version_id: item.version_id,
+ // 市场展示名透传落盘,安装后「我的技能」与技能广场同名显示
+ ...(item.display_name ? { display_name: item.display_name } : {}),
force,
}),
);
@@ -240,6 +316,8 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
const skillName = data.skill?.name || item.name;
showToast('success', t('skills.source.messages.installed', { name: skillName }));
await onInstalled?.(skillName);
+ // 安装后刷新已装状态缓存,保证卡片徽章与下次挂载读取的缓存一致
+ void loadUpdates(item.source_id || sourceId, true);
void runSearch(page);
} catch (error) {
showToast('error', error instanceof Error ? error.message : t('skills.source.errors.installFailed'));
@@ -247,7 +325,7 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
setInstallingId(null);
}
},
- [installingId, onInstalled, page, runSearch, showToast, sourceId, t, withSession],
+ [installingId, loadUpdates, onInstalled, page, runSearch, showToast, sourceId, t, withSession],
);
const handleConfirmInstall = useCallback(() => {
@@ -260,7 +338,7 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
async (item: SkillCandidate, status: UpdateStatus) => {
if (installingId) return;
const targetVersionId = status.latest_version_id || item.version_id;
- setInstallingId(item.name);
+ setInstallingId(itemKey(item, sourceId));
clearToast();
try {
const data = await webRequest<{
@@ -287,6 +365,8 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
});
return next;
});
+ // 同步缓存,避免下次挂载读到更新前的旧状态
+ void loadUpdates(item.source_id || sourceId, true);
showToast('success', t('skills.source.messages.updated', { name: data.skill?.name || item.name }));
await onInstalled?.(data.skill?.name || item.name);
} catch (error) {
@@ -295,13 +375,13 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
setInstallingId(null);
}
},
- [installingId, onInstalled, showToast, sourceId, t, withSession],
+ [installingId, loadUpdates, onInstalled, showToast, sourceId, t, withSession],
);
const renderAction = (item: SkillCandidate) => {
const status = updateStatuses.get(`${item.source_id}:${item.name}`);
const isInstalled = Boolean(status);
- const isInstalling = installingId === item.name;
+ const isInstalling = installingId === itemKey(item, sourceId);
if (isInstalled && status?.has_update) {
return (
<button
@@ -469,7 +549,7 @@ export function EnterpriseSkillSourcePanel({ sessionId, viewMode = 'list', exter
message={t('skills.source.replaceConfirm', { name: pendingConfirm.name })}
onConfirm={handleConfirmInstall}
onCancel={() => setPendingConfirm(null)}
- loading={installingId === pendingConfirm.name}
+ loading={installingId === itemKey(pendingConfirm, sourceId)}
/>
)}
</div>
diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json
index b6a0a1eb96..198561d651 100644
--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json
+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json
@@ -1705,6 +1705,7 @@
"clawhub": "ClawHub",
"skillnet": "SkillNet",
"teamskillshub": "TeamSkillsHub",
+ "swarmskillhub": "SwarmSkillHub",
"unknown": "Unknown",
"author": "Author",
"rating": "Rating",
diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json
index 6e325aa737..fc05c2e99f 100644
--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json
+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json
@@ -1695,6 +1695,7 @@
"clawhub": "ClawHub",
"skillnet": "SkillNet",
"teamskillshub": "TeamSkillsHub",
+ "swarmskillhub": "SwarmSkillHub",
"unknown": "未知",
"author": "作者",
"rating": "评分",
diff --git a/jiuwenswarm/server/runtime/skill/skill_manager.py b/jiuwenswarm/server/runtime/skill/skill_manager.py
index d78a35fca6..ac1e04ad2b 100644
--- a/jiuwenswarm/server/runtime/skill/skill_manager.py
+++ b/jiuwenswarm/server/runtime/skill/skill_manager.py
@@ -547,15 +547,17 @@ class SkillManager:
os.getenv("TEAM_SKILLS_HUB_HMAC_SECRET_ENV")
or "SKILL_DOWNLOAD_HMAC_SECRET"
).strip()
+ # 默认 if-present:Hub 未下发签名时仅记 verified=false 不拦截安装;
+ # 需要强验签的环境通过 TEAM_SKILLS_HUB_HMAC_VERIFICATION=required 显式开启
verification = str(
- os.getenv("TEAM_SKILLS_HUB_HMAC_VERIFICATION") or "required"
+ os.getenv("TEAM_SKILLS_HUB_HMAC_VERIFICATION") or "if-present"
).strip().lower()
if verification not in {"required", "if-present"}:
logger.warning(
- "Invalid TEAM_SKILLS_HUB_HMAC_VERIFICATION=%s; using required",
+ "Invalid TEAM_SKILLS_HUB_HMAC_VERIFICATION=%s; using if-present",
verification,
)
- verification = "required"
+ verification = "if-present"
return SourceConfig(
source_id=SWARM_SKILL_HUB_SOURCE_ID,
provider_type="swarmskillhub",
@@ -2409,6 +2411,7 @@ class SkillManager:
force: bool,
fingerprint: str | None = None,
verification: dict[str, Any] | None = None,
+ market_display_name: str = "",
) -> dict[str, Any]:
"""Atomically replace the entity, then commit the JSON installation record."""
existing_ref = self._find_installation_by_skill_ref(source_id, skill_id)
@@ -2458,6 +2461,7 @@ class SkillManager:
fingerprint=fingerprint,
verification=verification,
entity_dir=entity_dir,
+ market_display_name=market_display_name,
)
except Exception:
if dest.exists():
@@ -2483,6 +2487,8 @@ class SkillManager:
"missing_params", "source_id, skill_id and version_id are required"
)
force = bool(params.get("force", False))
+ # 市场展示名(技能广场卡片名)透传落盘,让「我的技能」与技能广场同名显示
+ market_display_name = str(params.get("display_name") or "").strip()[:200]
try:
descriptor, body, verification = await self._fetch_verified_source_artifact(
source_id=source_id,
@@ -2520,6 +2526,7 @@ class SkillManager:
force=force,
fingerprint=descriptor.fingerprint,
verification=verification,
+ market_display_name=market_display_name,
)
skill_payload: dict[str, Any] = {}
for key in (
@@ -5791,6 +5798,7 @@ class SkillManager:
"removable",
"sync_status",
"consistency",
+ "market_display_name",
):
if key in dto:
payload[key] = dto[key]
@@ -5834,6 +5842,7 @@ class SkillManager:
fingerprint: str | None = None,
verification: dict[str, Any] | None = None,
entity_dir: str | None = None,
+ market_display_name: str | None = None,
replace_by_name: bool = False,
) -> dict[str, Any]:
"""Create or update one managed installation in workspace JSON."""
@@ -5903,6 +5912,7 @@ class SkillManager:
("skill_id", skill_id),
("version_id", version_id),
("fingerprint", fingerprint),
+ ("market_display_name", market_display_name),
):
normalized = str(value or "").strip()
if normalized: