From f24969d28230f6e7d98d1029e8afd397e3723c0a Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 7 Oct 2026 21:28:53 +0800 Subject: [PATCH] feat(webui): add catalog loading skeletons (#6092) * feat(webui): add catalog loading skeletons * feat(webui): add MCP tool loading skeleton * fix(webui): make skill discovery skeletons visible * refactor(webui): share skeleton status markup --- webui/src/App.tsx | 4 +- .../src/components/settings/SettingsPage.tsx | 6 +- .../src/components/settings/SettingsView.tsx | 6 + .../settings/SkillsCatalogSettings.tsx | 26 +++- .../components/settings/SkillsMarketplace.tsx | 57 ++++---- .../settings/shared/CatalogSkeleton.tsx | 40 ++++++ .../settings/shared/SkeletonStatus.tsx | 18 +++ .../settings/system/AppsSettings.tsx | 24 ++-- .../settings/system/ChannelsSettings.tsx | 14 +- .../settings/system/McpManagementDialog.tsx | 68 ++++++---- webui/src/hooks/useSkills.ts | 25 +++- webui/src/i18n/locales/en/common.json | 4 + webui/src/i18n/locales/es/common.json | 4 + webui/src/i18n/locales/fr/common.json | 4 + webui/src/i18n/locales/id/common.json | 4 + webui/src/i18n/locales/ja/common.json | 4 + webui/src/i18n/locales/ko/common.json | 4 + webui/src/i18n/locales/pt-BR/common.json | 4 + webui/src/i18n/locales/vi/common.json | 4 + webui/src/i18n/locales/zh-CN/common.json | 4 + webui/src/i18n/locales/zh-TW/common.json | 4 + webui/src/tests/app-layout.test.tsx | 2 +- webui/src/tests/catalog-loading.test.tsx | 124 ++++++++++++++++++ .../src/tests/mcp-management-dialog.test.tsx | 64 ++++++++- webui/src/tests/skills-marketplace.test.tsx | 119 +++++++++++++++-- 25 files changed, 538 insertions(+), 99 deletions(-) create mode 100644 webui/src/components/settings/shared/CatalogSkeleton.tsx create mode 100644 webui/src/components/settings/shared/SkeletonStatus.tsx create mode 100644 webui/src/tests/catalog-loading.test.tsx diff --git a/webui/src/App.tsx b/webui/src/App.tsx index ab0ec0059..a881d1f3a 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -1232,7 +1232,7 @@ function Shell({ const [runningChatIds, setRunningChatIds] = useState>(() => new Set()); const [updatedChatIds, setUpdatedChatIds] = useState>(readSessionUpdateChatIds); const [workspaces, setWorkspaces] = useState(null); - const skills = useSkills(getToken); + const { skills, loading: skillsLoading, error: skillsError } = useSkills(getToken); const pageVisible = usePageVisibility(); const [settingsSnapshot, setSettingsSnapshot] = useState(null); const [settingsLoading, setSettingsLoading] = useState(true); @@ -3092,6 +3092,8 @@ function Shell({ onModelNameChange={onModelNameChange} onSettingsChange={setSettingsSnapshot} skills={skills} + skillsLoading={skillsLoading} + skillsError={skillsError} onStartAutomationChat={onStartAutomationChat} titleOverrides={sidebarState.title_overrides} sessions={topicSessions} diff --git a/webui/src/components/settings/SettingsPage.tsx b/webui/src/components/settings/SettingsPage.tsx index bafdb76ab..7771cf2c0 100644 --- a/webui/src/components/settings/SettingsPage.tsx +++ b/webui/src/components/settings/SettingsPage.tsx @@ -53,6 +53,8 @@ interface SettingsPageProps { onToggleTheme: () => void; onBackToChat: () => void; skills: SkillSummary[]; + skillsLoading: boolean; + skillsError: boolean; onStartAutomationChat?: ( content: string, images?: SendAttachment[], @@ -75,6 +77,8 @@ export function SettingsPage({ onToggleTheme, onBackToChat, skills, + skillsLoading, + skillsError, onStartAutomationChat, titleOverrides, sessions, @@ -608,7 +612,7 @@ export function SettingsPage({ ); case "skills": - return ; + return ; case "runtime": return (
diff --git a/webui/src/components/settings/SettingsView.tsx b/webui/src/components/settings/SettingsView.tsx index 675df6181..0b5e2f6b3 100644 --- a/webui/src/components/settings/SettingsView.tsx +++ b/webui/src/components/settings/SettingsView.tsx @@ -18,6 +18,8 @@ interface SettingsViewProps { onModelNameChange: (modelName: string | null) => void; onSettingsChange?: (payload: SettingsPayload) => void; skills?: SkillSummary[]; + skillsLoading?: boolean; + skillsError?: boolean; onStartAutomationChat?: ( content: string, images?: SendAttachment[], @@ -46,6 +48,8 @@ export function SettingsView({ onModelNameChange, onSettingsChange, skills = [], + skillsLoading = false, + skillsError = false, onStartAutomationChat, titleOverrides, sessions, @@ -76,6 +80,8 @@ export function SettingsView({ onToggleTheme={onToggleTheme} onBackToChat={onBackToChat} skills={skills} + skillsLoading={skillsLoading} + skillsError={skillsError} onStartAutomationChat={onStartAutomationChat} titleOverrides={titleOverrides} sessions={sessions} diff --git a/webui/src/components/settings/SkillsCatalogSettings.tsx b/webui/src/components/settings/SkillsCatalogSettings.tsx index c4380fb01..5904b0364 100644 --- a/webui/src/components/settings/SkillsCatalogSettings.tsx +++ b/webui/src/components/settings/SkillsCatalogSettings.tsx @@ -31,14 +31,19 @@ import { Input } from "@/components/ui/input"; import { SegmentedControl } from "@/components/ui/segmented-control"; import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet"; import { SkillsMarketplace } from "@/components/settings/SkillsMarketplace"; +import { CatalogSkeleton } from "@/components/settings/shared/CatalogSkeleton"; import { ToggleButton } from "@/components/settings/ToggleButton"; import { deleteSkill, fetchSkillDetail, updateSkillEnabled } from "@/lib/api"; -import { notifySkillsChanged } from "@/lib/skill-events"; +import { notifySkillsChanged, requestSkillsRefresh } from "@/lib/skill-events"; import type { SkillDetail, SkillSummary } from "@/lib/types"; import { cn } from "@/lib/utils"; import { useClient } from "@/providers/ClientProvider"; -export function SkillsCatalogSettings({ skills }: { skills: SkillSummary[] }) { +export function SkillsCatalogSettings({ skills, loading = false, error = false }: { + skills: SkillSummary[]; + loading?: boolean; + error?: boolean; +}) { const { t } = useTranslation(); const [selectedSkill, setSelectedSkill] = useState(null); const [view, setView] = useState<"installed" | "discover">("installed"); @@ -140,14 +145,23 @@ export function SkillsCatalogSettings({ skills }: { skills: SkillSummary[] }) { value, label: ( <> - {label} {count} + {label} {loading || error ? "—" : count} ), }))} onChange={setInstalledFilter} />
- {groupedSkills.length ? ( + {loading ? ( + + ) : error ? ( +
+

{t("settings.skills.catalogLoadFailed")}

+ +
+ ) : groupedSkills.length ? (
{groupedSkills.map((group) => (
@@ -173,9 +187,7 @@ export function SkillsCatalogSettings({ skills }: { skills: SkillSummary[] }) {
) : (
- {t("settings.skills.noMatching", { - defaultValue: "No matching skills.", - })} + {t(skills.length ? "settings.skills.noMatching" : "settings.skills.empty")}
)} diff --git a/webui/src/components/settings/SkillsMarketplace.tsx b/webui/src/components/settings/SkillsMarketplace.tsx index 86d66951f..c1d1c9399 100644 --- a/webui/src/components/settings/SkillsMarketplace.tsx +++ b/webui/src/components/settings/SkillsMarketplace.tsx @@ -9,6 +9,7 @@ import { } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus"; import { AlertDialog, AlertDialogAction, @@ -125,9 +126,9 @@ export function SkillsMarketplace({ } let cancelled = false; + setLoading(true); + setError(""); const timer = window.setTimeout(() => { - setLoading(true); - setError(""); searchMarketplaceSkills(getToken(), normalized) .then((payload) => { if (cancelled) return; @@ -218,7 +219,7 @@ export function SkillsMarketplace({ defaultValue: "Searching", })} > - + ) : null} @@ -252,7 +253,7 @@ export function SkillsMarketplace({ ) : null} {trendingLoading ? ( - + ) : visibleTrending.length ? ( ) : (
- + {loading && !visibleResults.length ? ( + + ) : ( + + )}
)} @@ -566,7 +571,7 @@ function MarketplaceSkillRow({ } > {isInstalling ? ( - + ) : installed ? ( ) : ( @@ -669,19 +674,27 @@ function TrendSparkline({ values }: { values?: number[] }) { ); } -function TrendingSkeleton() { +function MarketplaceSkeleton({ ranked = false }: { ranked?: boolean }) { + const { t } = useTranslation(); return ( -
+ {Array.from({ length: 5 }, (_, index) => ( -
-
-
-
-
+
+ {ranked ?
: null} +
+
+
+
+
+
+
-
+
))} -
+ ); } diff --git a/webui/src/components/settings/shared/CatalogSkeleton.tsx b/webui/src/components/settings/shared/CatalogSkeleton.tsx new file mode 100644 index 000000000..0591ccd4b --- /dev/null +++ b/webui/src/components/settings/shared/CatalogSkeleton.tsx @@ -0,0 +1,40 @@ +import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus"; +import { cn } from "@/lib/utils"; + +export function CatalogSkeleton({ label, layout }: { + label: string; + layout: "apps" | "channels" | "skills"; +}) { + const channels = layout === "channels"; + const skills = layout === "skills"; + const block = "rounded bg-muted-foreground/20"; + + return ( + + {Array.from({ length: 6 }, (_, index) => ( +
+
+
+
+ {!channels ?
: null} +
+
+
+
+
+ ))} + + ); +} diff --git a/webui/src/components/settings/shared/SkeletonStatus.tsx b/webui/src/components/settings/shared/SkeletonStatus.tsx new file mode 100644 index 000000000..c4224e220 --- /dev/null +++ b/webui/src/components/settings/shared/SkeletonStatus.tsx @@ -0,0 +1,18 @@ +import type { ReactNode } from "react"; + +import { cn } from "@/lib/utils"; + +export function SkeletonStatus({ label, className, children }: { + label: string; + className: string; + children: ReactNode; +}) { + return ( +
+ {label} +
+ {children} +
+
+ ); +} diff --git a/webui/src/components/settings/system/AppsSettings.tsx b/webui/src/components/settings/system/AppsSettings.tsx index 84babcec0..c77093328 100644 --- a/webui/src/components/settings/system/AppsSettings.tsx +++ b/webui/src/components/settings/system/AppsSettings.tsx @@ -31,6 +31,8 @@ import { } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { CatalogSkeleton } from "@/components/settings/shared/CatalogSkeleton"; + import { DismissibleStatusMessage, RestartRequiredNotice, @@ -218,10 +220,8 @@ export function AppsCatalogSettings({ const focusedApp = cliFocusName ? (cliApps?.apps ?? []).find((app) => app.name === cliFocusName && app.installed) : null; - const loading = - (cliAppsLoading || mcpPresetsLoading) && - !cliApps && - !mcpPresets; + const loading = (mcpPresetsLoading && !mcpPresets) + || ((filter !== "mcp" || Boolean(normalizedQuery)) && cliAppsLoading && !cliApps); const cliAppCount = cliApps?.apps.length ?? 0; const emptyTitle = normalizedQuery ? tx("settings.apps.empty", "No tools match your search.") @@ -305,15 +305,10 @@ export function AppsCatalogSettings({ : tx("settings.apps.featured", "Tools")} - {items.length} + {loading ? "—" : items.length}
- {loading ? ( -
- - {tx("settings.apps.loading", "Loading apps…")} -
- ) : items.length ? ( + {items.length ? (
{items.map((item) => item.kind === "cli" ? ( @@ -351,7 +346,10 @@ export function AppsCatalogSettings({ ), )}
- ) : ( + ) : null} + {loading ? ( + + ) : !items.length && !statusIsError ? (

{emptyTitle}

{normalizedQuery ? ( @@ -383,7 +381,7 @@ export function AppsCatalogSettings({

)}
- )} + ) : null} {filter === "mcp" ? ( diff --git a/webui/src/components/settings/system/ChannelsSettings.tsx b/webui/src/components/settings/system/ChannelsSettings.tsx index b1e517e83..43fef789c 100644 --- a/webui/src/components/settings/system/ChannelsSettings.tsx +++ b/webui/src/components/settings/system/ChannelsSettings.tsx @@ -1,10 +1,11 @@ import { useCallback, useLayoutEffect, useRef, useState } from "react"; -import { Loader2, Search, X } from "lucide-react"; +import { Search, X } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Input } from "@/components/ui/input"; import { SegmentedControl } from "@/components/ui/segmented-control"; import { SETTINGS_SEARCH_INPUT_CLASS } from "@/components/settings/shared/SettingsControls"; +import { CatalogSkeleton } from "@/components/settings/shared/CatalogSkeleton"; import type { ChannelFeatureAction } from "@/channel-plugins/types"; import { ChannelCatalogRow } from "@/components/settings/channels/ChannelCatalogRow"; import { localizedChannelDisplayName } from "@/components/settings/channels/ChannelIdentity"; @@ -120,10 +121,9 @@ export function ChannelsSettings({ onRestart={onRestart} isRestarting={isRestarting} /> ) : null} {loading && !nanobotFeatures ? ( -
- - {t("settings.channels.loading")} -
+ + + ) : visibleChannels.length ? ( channelGroups.map((group) => (
)) - ) : ( + ) : !error ? (
{t(channels.length ? "settings.channels.noResults" : "settings.channels.empty")}
- )} + ) : null} { if (!open) requestChannelClose(); }}> { diff --git a/webui/src/components/settings/system/McpManagementDialog.tsx b/webui/src/components/settings/system/McpManagementDialog.tsx index fbec79814..84857c116 100644 --- a/webui/src/components/settings/system/McpManagementDialog.tsx +++ b/webui/src/components/settings/system/McpManagementDialog.tsx @@ -5,6 +5,7 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { Check, ExternalLink, Loader2, RotateCcw, Search, Server, Trash2, X } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus"; import { Button } from "@/components/ui/button"; import { Dialog, @@ -363,6 +364,29 @@ function ToolsPanel({ }) { const { t } = useTranslation(); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); + if (!toolNames.length && testBusy) { + return ( + +
+
+
+
+
+
+
+
+
+ {Array.from({ length: 6 }, (_, index) => ( +
+
+
+
+ ))} +
+ + ); + } + if (!toolNames.length) { return (
- {testBusy ? ( - - ) : ( - - )} +

- {testBusy - ? tx("common.loading", "Loading…") - : preset.error || tx("settings.mcp.noToolsAvailable", "No tools available")} + {preset.error || tx("settings.mcp.noToolsAvailable", "No tools available")}

- {!testBusy ? ( - - ) : null} +
); } diff --git a/webui/src/hooks/useSkills.ts b/webui/src/hooks/useSkills.ts index 3db5cdd5e..8704bc343 100644 --- a/webui/src/hooks/useSkills.ts +++ b/webui/src/hooks/useSkills.ts @@ -4,8 +4,14 @@ import { fetchSkills } from "@/lib/api"; import { isSkillsPayload, SKILLS_CHANGED_EVENT, SKILLS_REFRESH_EVENT } from "@/lib/skill-events"; import type { SkillSummary } from "@/lib/types"; -export function useSkills(getToken: () => string): SkillSummary[] { - const [skills, setSkills] = useState([]); +type SkillsState = + | { status: "loading" | "error"; skills: null } + | { status: "ready"; skills: SkillSummary[] }; + +const EMPTY_SKILLS: SkillSummary[] = []; + +export function useSkills(getToken: () => string) { + const [state, setState] = useState({ status: "loading", skills: null }); useEffect(() => { let cancelled = false; @@ -21,13 +27,16 @@ export function useSkills(getToken: () => string): SkillSummary[] { } refreshing = true; refreshQueued = false; + setState((current) => current.skills === null ? { status: "loading", skills: null } : current); const version = payloadVersion; fetchSkills(getToken()) .then(({ skills: nextSkills }) => { - if (!cancelled && version === payloadVersion) setSkills(nextSkills); + if (!cancelled && version === payloadVersion) setState({ status: "ready", skills: nextSkills }); }) .catch(() => { - // Keep the last known list usable during transient refresh failures. + if (!cancelled && version === payloadVersion) { + setState((current) => current.skills === null ? { status: "error", skills: null } : current); + } }) .finally(() => { refreshing = false; @@ -38,7 +47,7 @@ export function useSkills(getToken: () => string): SkillSummary[] { const payload = (event as CustomEvent).detail; if (!cancelled && isSkillsPayload(payload)) { payloadVersion += 1; - setSkills(payload.skills); + setState({ status: "ready", skills: payload.skills }); } }; @@ -52,5 +61,9 @@ export function useSkills(getToken: () => string): SkillSummary[] { }; }, [getToken]); - return skills; + return { + skills: state.skills ?? EMPTY_SKILLS, + loading: state.status === "loading", + error: state.status === "error", + }; } diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.json index 52d96c473..bd686becc 100644 --- a/webui/src/i18n/locales/en/common.json +++ b/webui/src/i18n/locales/en/common.json @@ -980,6 +980,7 @@ "endpointLabel": "Endpoint", "toolPreview": "Tools", "noToolsAvailable": "No tools available", + "loadingTools": "Loading tools…", "searchTools": "Search tools", "searchToolsPlaceholder": "Search tools", "selectedCount": "{{count}} enabled", @@ -1627,6 +1628,9 @@ "filterEnabled": "Enabled", "filterDisabled": "Disabled", "noMatching": "No matching skills.", + "loading": "Loading skills…", + "catalogLoadFailed": "Could not load skills.", + "retry": "Retry", "statusDisabled": "Disabled", "statusEnabled": "Enabled", "statusNeedsSetup": "Needs setup", diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.json index eff2b84f6..426f87c88 100644 --- a/webui/src/i18n/locales/es/common.json +++ b/webui/src/i18n/locales/es/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "URL", "toolPreview": "Herramientas", "noToolsAvailable": "No hay herramientas disponibles", + "loadingTools": "Cargando herramientas…", "searchTools": "Buscar herramientas", "searchToolsPlaceholder": "Buscar herramientas", "selectedCount": "{{count}} activadas", @@ -1428,6 +1429,9 @@ "filterEnabled": "Activadas", "filterDisabled": "Desactivadas", "noMatching": "No hay habilidades coincidentes.", + "loading": "Cargando habilidades…", + "catalogLoadFailed": "No se pudieron cargar las habilidades.", + "retry": "Reintentar", "statusDisabled": "Desactivada", "statusEnabled": "Activada", "statusNeedsSetup": "Requiere configuración", diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.json index 0c64c7c50..10536ec46 100644 --- a/webui/src/i18n/locales/fr/common.json +++ b/webui/src/i18n/locales/fr/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "URL", "toolPreview": "Outils", "noToolsAvailable": "Aucun outil disponible", + "loadingTools": "Chargement des outils…", "searchTools": "Rechercher des outils", "searchToolsPlaceholder": "Rechercher des outils", "selectedCount": "{{count}} activés", @@ -1427,6 +1428,9 @@ "filterEnabled": "Activées", "filterDisabled": "Désactivées", "noMatching": "Aucune compétence correspondante.", + "loading": "Chargement des compétences…", + "catalogLoadFailed": "Impossible de charger les compétences.", + "retry": "Réessayer", "statusDisabled": "Désactivée", "statusEnabled": "Activée", "statusNeedsSetup": "Configuration requise", diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.json index be92a916a..1ec787d36 100644 --- a/webui/src/i18n/locales/id/common.json +++ b/webui/src/i18n/locales/id/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "Endpoint", "toolPreview": "Alat", "noToolsAvailable": "Tidak ada alat yang tersedia", + "loadingTools": "Memuat alat…", "searchTools": "Cari alat", "searchToolsPlaceholder": "Cari alat", "selectedCount": "{{count}} aktif", @@ -1427,6 +1428,9 @@ "filterEnabled": "Aktif", "filterDisabled": "Nonaktif", "noMatching": "Tidak ada keterampilan yang cocok.", + "loading": "Memuat keterampilan…", + "catalogLoadFailed": "Tidak dapat memuat keterampilan.", + "retry": "Coba lagi", "statusDisabled": "Nonaktif", "statusEnabled": "Aktif", "statusNeedsSetup": "Perlu penyiapan", diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.json index 13a43c167..ff45b8d5d 100644 --- a/webui/src/i18n/locales/ja/common.json +++ b/webui/src/i18n/locales/ja/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "エンドポイント", "toolPreview": "ツール", "noToolsAvailable": "利用可能なツールはありません", + "loadingTools": "ツールを読み込み中…", "searchTools": "ツールを検索", "searchToolsPlaceholder": "ツールを検索", "selectedCount": "{{count}} 件有効", @@ -1427,6 +1428,9 @@ "filterEnabled": "有効", "filterDisabled": "無効", "noMatching": "一致するスキルがありません。", + "loading": "スキルを読み込み中…", + "catalogLoadFailed": "スキルを読み込めませんでした。", + "retry": "再試行", "statusDisabled": "無効", "statusEnabled": "有効", "statusNeedsSetup": "セットアップが必要", diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.json index 763162590..4647449ae 100644 --- a/webui/src/i18n/locales/ko/common.json +++ b/webui/src/i18n/locales/ko/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "엔드포인트", "toolPreview": "도구", "noToolsAvailable": "사용 가능한 도구가 없습니다", + "loadingTools": "도구 로딩 중…", "searchTools": "도구 검색", "searchToolsPlaceholder": "도구 검색", "selectedCount": "{{count}}개 활성화", @@ -1427,6 +1428,9 @@ "filterEnabled": "활성화됨", "filterDisabled": "비활성화됨", "noMatching": "일치하는 스킬이 없습니다.", + "loading": "스킬 불러오는 중…", + "catalogLoadFailed": "스킬을 불러올 수 없습니다.", + "retry": "다시 시도", "statusDisabled": "비활성화됨", "statusEnabled": "활성화됨", "statusNeedsSetup": "설정 필요", diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.json index ddea5e8cd..60e72db57 100644 --- a/webui/src/i18n/locales/pt-BR/common.json +++ b/webui/src/i18n/locales/pt-BR/common.json @@ -796,6 +796,7 @@ "endpointLabel": "Endpoint", "toolPreview": "Ferramentas", "noToolsAvailable": "Nenhuma ferramenta disponível", + "loadingTools": "Carregando ferramentas…", "searchTools": "Buscar ferramentas", "searchToolsPlaceholder": "Buscar ferramentas", "selectedCount": "{{count}} ativadas", @@ -1441,6 +1442,9 @@ "filterEnabled": "Ativadas", "filterDisabled": "Desativadas", "noMatching": "Nenhuma habilidade correspondente.", + "loading": "Carregando habilidades…", + "catalogLoadFailed": "Não foi possível carregar as habilidades.", + "retry": "Tentar novamente", "statusDisabled": "Desativada", "statusEnabled": "Ativada", "statusNeedsSetup": "Requer configuração", diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.json index c7c5ee4b0..d40e3f5b9 100644 --- a/webui/src/i18n/locales/vi/common.json +++ b/webui/src/i18n/locales/vi/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "URL kết nối", "toolPreview": "Công cụ", "noToolsAvailable": "Không có công cụ khả dụng", + "loadingTools": "Đang tải công cụ…", "searchTools": "Tìm công cụ", "searchToolsPlaceholder": "Tìm công cụ", "selectedCount": "Đã bật {{count}}", @@ -1427,6 +1428,9 @@ "filterEnabled": "Đã bật", "filterDisabled": "Đã tắt", "noMatching": "Không có kỹ năng phù hợp.", + "loading": "Đang tải kỹ năng…", + "catalogLoadFailed": "Không thể tải kỹ năng.", + "retry": "Thử lại", "statusDisabled": "Đã tắt", "statusEnabled": "Đã bật", "statusNeedsSetup": "Cần thiết lập", diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.json index 6e1091725..1031c8e22 100644 --- a/webui/src/i18n/locales/zh-CN/common.json +++ b/webui/src/i18n/locales/zh-CN/common.json @@ -982,6 +982,7 @@ "endpointLabel": "连接地址", "toolPreview": "工具", "noToolsAvailable": "没有可用工具", + "loadingTools": "正在加载工具…", "searchTools": "搜索工具", "searchToolsPlaceholder": "搜索工具", "selectedCount": "已启用 {{count}} 个", @@ -1627,6 +1628,9 @@ "filterEnabled": "已启用", "filterDisabled": "已停用", "noMatching": "没有匹配的技能。", + "loading": "技能加载中…", + "catalogLoadFailed": "无法加载技能。", + "retry": "重试", "statusDisabled": "已停用", "statusEnabled": "已启用", "statusNeedsSetup": "需要设置", diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.json index d7dac81da..ddbc47bf6 100644 --- a/webui/src/i18n/locales/zh-TW/common.json +++ b/webui/src/i18n/locales/zh-TW/common.json @@ -1005,6 +1005,7 @@ "endpointLabel": "端點", "toolPreview": "工具", "noToolsAvailable": "沒有可用工具", + "loadingTools": "正在載入工具…", "searchTools": "搜尋工具", "searchToolsPlaceholder": "搜尋工具", "selectedCount": "已啟用 {{count}} 個", @@ -1427,6 +1428,9 @@ "filterEnabled": "已啟用", "filterDisabled": "已停用", "noMatching": "沒有相符的技能。", + "loading": "正在載入技能…", + "catalogLoadFailed": "無法載入技能。", + "retry": "重試", "statusDisabled": "已停用", "statusEnabled": "已啟用", "statusNeedsSetup": "需要設定", diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx index e8fc59874..9fc39cff6 100644 --- a/webui/src/tests/app-layout.test.tsx +++ b/webui/src/tests/app-layout.test.tsx @@ -1490,7 +1490,7 @@ describe("App layout", () => { screen.queryByRole("button", { name: "Open details for custom-skill" }), ).not.toBeInTheDocument(); }); - expect(screen.getByText("No matching skills.")).toBeInTheDocument(); + expect(screen.getByText("No skills are available.")).toBeInTheDocument(); }); it("discovers and installs a skill from skills.sh", async () => { diff --git a/webui/src/tests/catalog-loading.test.tsx b/webui/src/tests/catalog-loading.test.tsx new file mode 100644 index 000000000..3d2a89076 --- /dev/null +++ b/webui/src/tests/catalog-loading.test.tsx @@ -0,0 +1,124 @@ +import { act, fireEvent, screen } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; + +import type { CliAppInfo, McpPresetInfo, NanobotFeatureInfo } from "@/lib/types"; +import { + installSettingsViewTestHooks, + jsonResponse, + renderSettingsView, + settingsPayload, +} from "@/tests/settings-test-utils"; + +function deferred() { + let resolve!: (value: T) => void; + const promise = new Promise((res) => { resolve = res; }); + return { promise, resolve }; +} + +const app: CliAppInfo = { + name: "anygen", display_name: "AnyGen", category: "generation", + description: "Generate documents.", requires: "ANYGEN_API_KEY", source: "harness", + entry_point: "cli-anything-anygen", install_supported: true, installed: true, + available: true, status: "installed", skill_installed: true, +}; +const plugin: McpPresetInfo = { + name: "plugin-computer-use", display_name: "Computer Use", category: "Plugin", + description: "Control the desktop.", requires: "accessibility", transport: "stdio", + install_supported: false, installed: true, configured: true, enabled: false, + available: false, status: "disabled", required_fields: [], source: "agent-plugin", + docs_url: "", note: "", connection_summary: "", +}; +const channel: NanobotFeatureInfo = { + name: "discord", display_name: "Discord", type: "channel", installed: true, + configured: false, enabled: false, ready: false, status: "not_enabled", + install_supported: true, requires_restart: false, +}; + +describe("catalog loading", () => { + installSettingsViewTestHooks(); + + it("keeps loaded Apps rows visible while waiting for Agent Plugins", async () => { + const cli = deferred(); + const mcp = deferred(); + vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings/cli-apps") return cli.promise; + if (url === "/api/settings/mcp-presets") return mcp.promise; + return Promise.resolve(jsonResponse(settingsPayload())); + })); + renderSettingsView({ initialSettings: settingsPayload() }); + expect(screen.getByRole("status", { name: "Loading apps…" })).toHaveAttribute("aria-busy", "true"); + + await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); }); + expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); + expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); + await act(async () => { mcp.resolve(jsonResponse({ presets: [plugin], installed_count: 1 })); }); + expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); + }); + + it("finishes an empty MCP category independently but waits for Apps when searching", async () => { + const cli = deferred(); + vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings/cli-apps") return cli.promise; + if (url === "/api/settings/mcp-presets") { + return Promise.resolve(jsonResponse({ presets: [], installed_count: 0 })); + } + return Promise.resolve(jsonResponse(settingsPayload())); + })); + renderSettingsView({ initialSettings: settingsPayload() }); + await act(async () => {}); + expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); + expect(screen.queryByText("No apps available.")).not.toBeInTheDocument(); + + fireEvent.click(screen.getByRole("button", { name: "MCP" })); + expect(screen.getByText("No MCP tools available.")).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); + fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "AnyGen" } }); + expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); + expect(screen.queryByText("No tools match your search.")).not.toBeInTheDocument(); + await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); }); + expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); + }); + + it.each(["apps", "channels"] as const)("reports a failed %s read without claiming an empty catalog", async (section) => { + vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings") return jsonResponse(settingsPayload()); + if (url === "/api/settings/mcp-presets") return jsonResponse({ presets: [], installed_count: 0 }); + throw new Error("Catalog offline"); + })); + renderSettingsView({ initialSection: section, initialSettings: settingsPayload() }); + expect(await screen.findByText("Catalog offline")).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: /Loading (apps|channels)/ })).not.toBeInTheDocument(); + expect(screen.queryByText("No apps available.")).not.toBeInTheDocument(); + expect(screen.queryByText("No channels match this filter.")).not.toBeInTheDocument(); + }); + + it("shows Channels placeholders until the first response and preserves rows on a focus refresh", async () => { + const initial = deferred(); + const refresh = deferred(); + const fetchFeatures = vi.fn().mockReturnValueOnce(initial.promise).mockReturnValue(refresh.promise); + vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => ( + String(input) === "/api/settings/nanobot-features" + ? fetchFeatures() : Promise.resolve(jsonResponse(settingsPayload())) + ))); + renderSettingsView({ initialSection: "channels", initialSettings: settingsPayload() }); + expect(screen.getByRole("status", { name: "Loading channels…" })).toHaveAttribute("aria-busy", "true"); + fireEvent.change(screen.getByRole("searchbox", { name: "Search channels" }), { + target: { value: "discord" }, + }); + await act(async () => { initial.resolve(jsonResponse({ features: [channel], enabled_count: 0 })); }); + expect(screen.getByRole("button", { name: "View Discord settings" })).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading channels…" })).not.toBeInTheDocument(); + + act(() => { window.dispatchEvent(new Event("focus")); }); + expect(fetchFeatures).toHaveBeenCalledTimes(2); + expect(screen.getByRole("button", { name: "View Discord settings" })).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading channels…" })).not.toBeInTheDocument(); + await act(async () => { refresh.resolve(jsonResponse({ features: [], enabled_count: 0 })); }); + expect(screen.getByText("No channels match this filter.")).toBeInTheDocument(); + }); +}); diff --git a/webui/src/tests/mcp-management-dialog.test.tsx b/webui/src/tests/mcp-management-dialog.test.tsx index a45ebae25..412690619 100644 --- a/webui/src/tests/mcp-management-dialog.test.tsx +++ b/webui/src/tests/mcp-management-dialog.test.tsx @@ -98,6 +98,56 @@ describe("McpManagementDialog", () => { fireEvent.click(within(dialog).getByRole("button", { name: "Reload tools" })); expect(onAction).toHaveBeenCalledTimes(2); }); + + it("shows a skeleton for the first inspection and keeps tools and draft selections during reinspection", () => { + const emptyPreset = { ...connectedPreset, tool_count: 0, tool_names: [] }; + const { updateDialog } = renderDialog({ + initialTab: "tools", + preset: emptyPreset, + actionKey: "test:docs", + }); + + const dialog = screen.getByRole("dialog", { name: "Docs MCP" }); + expect(within(dialog).getByRole("status", { name: "Loading tools…" })).toHaveAttribute("aria-busy", "true"); + expect(within(dialog).queryByRole("textbox", { name: "Search tools" })).not.toBeInTheDocument(); + expect(within(dialog).queryByText("No tools available")).not.toBeInTheDocument(); + + updateDialog(connectedPreset); + expect(within(dialog).queryByRole("status", { name: "Loading tools…" })).not.toBeInTheDocument(); + const searchDocs = within(dialog).getByRole("checkbox", { name: /search_docs/ }); + fireEvent.click(searchDocs); + expect(searchDocs).not.toBeChecked(); + + updateDialog({ ...connectedPreset, tool_names: [] }, "test:docs"); + expect(within(dialog).queryByRole("status", { name: "Loading tools…" })).not.toBeInTheDocument(); + expect(within(dialog).getByRole("checkbox", { name: /search_docs/ })).not.toBeChecked(); + expect(within(dialog).getByRole("checkbox", { name: /write_note/ })).toBeChecked(); + expect(within(dialog).getByText("2 enabled")).toBeInTheDocument(); + expect(within(dialog).getByRole("button", { name: "Save changes" })).toBeEnabled(); + }); + + it.each([ + { error: undefined, message: "No tools available" }, + { error: "Inspection failed", message: "Inspection failed" }, + ])("offers recovery when inspection finishes with $message", ({ error, message }) => { + const onAction = vi.fn(); + const emptyPreset = { ...connectedPreset, tool_count: 0, tool_names: [], error }; + const { updateDialog } = renderDialog({ + initialTab: "tools", + preset: emptyPreset, + actionKey: "test:docs", + onAction, + }); + + const dialog = screen.getByRole("dialog", { name: "Docs MCP" }); + expect(within(dialog).getByRole("status", { name: "Loading tools…" })).toBeInTheDocument(); + updateDialog(emptyPreset); + expect(within(dialog).queryByRole("status", { name: "Loading tools…" })).not.toBeInTheDocument(); + expect(within(dialog).getByText(message)).toBeInTheDocument(); + if (error) expect(within(dialog).getByRole("alert")).toHaveTextContent(error); + fireEvent.click(within(dialog).getByRole("button", { name: "Reload tools" })); + expect(onAction).toHaveBeenLastCalledWith("test", "docs"); + }); }); function renderDialog({ @@ -105,19 +155,21 @@ function renderDialog({ onAction = vi.fn(), onToolsChange = vi.fn(), preset = connectedPreset, + actionKey = null, }: { initialTab: McpManagementTab; onAction?: ReturnType; onToolsChange?: ReturnType; preset?: McpPresetInfo; + actionKey?: string | null; }) { - function Harness() { + function Harness({ preset, actionKey }: { preset: McpPresetInfo; actionKey: string | null }) { const [tab, setTab] = useState(initialTab); return ( ); } - return render(); + const view = render(); + return { + ...view, + updateDialog: (nextPreset: McpPresetInfo, nextActionKey: string | null = null) => { + view.rerender(); + }, + }; } diff --git a/webui/src/tests/skills-marketplace.test.tsx b/webui/src/tests/skills-marketplace.test.tsx index 329404e33..ed3358386 100644 --- a/webui/src/tests/skills-marketplace.test.tsx +++ b/webui/src/tests/skills-marketplace.test.tsx @@ -2,6 +2,7 @@ import { act, fireEvent, render, renderHook, screen } from "@testing-library/rea import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { SkillsMarketplace } from "@/components/settings/SkillsMarketplace"; +import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings"; import { ThreadComposer } from "@/components/thread/ThreadComposer"; import { fetchSkills, @@ -38,6 +39,52 @@ function marketplace(token: string) { } describe("useSkills", () => { + it("shows loading, retries a failed first read, and preserves an empty catalog during refresh", async () => { + let rejectInitial!: (error: Error) => void; + let resolveRetry!: (value: Awaited>) => void; + let resolveRefresh!: (value: Awaited>) => void; + vi.mocked(fetchSkills).mockReset() + .mockImplementationOnce(() => new Promise((_resolve, reject) => { rejectInitial = reject; })) + .mockImplementationOnce(() => new Promise((resolve) => { resolveRetry = resolve; })) + .mockImplementationOnce(() => new Promise((resolve) => { resolveRefresh = resolve; })); + const getToken = () => "tok"; + function Catalog() { + const state = useSkills(getToken); + return ; + } + render(); + + expect(screen.getByRole("status", { name: "Loading skills…" })).toHaveAttribute("aria-busy", "true"); + fireEvent.change(screen.getByRole("textbox", { name: "Search installed skills" }), { + target: { value: "cron" }, + }); + await act(async () => { rejectInitial(new Error("Offline")); }); + expect(screen.getByRole("alert")).toHaveTextContent("Could not load skills."); + expect(screen.queryByText("No skills are available.")).not.toBeInTheDocument(); + + fireEvent.click(screen.getByRole("button", { name: "Retry" })); + expect(screen.getByRole("status", { name: "Loading skills…" })).toBeInTheDocument(); + expect(screen.queryByRole("alert")).not.toBeInTheDocument(); + await act(async () => { resolveRetry({ skills: [] }); }); + expect(screen.getByText("No skills are available.")).toBeInTheDocument(); + expect(screen.getByRole("button", { name: "All 0" })).toBeInTheDocument(); + + act(() => { requestSkillsRefresh(); }); + expect(screen.getByText("No skills are available.")).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading skills…" })).not.toBeInTheDocument(); + await act(async () => { + resolveRefresh({ skills: [{ + name: "weather", description: "Get the weather.", source: "builtin", available: true, + }] }); + }); + expect(screen.getByText("No matching skills.")).toBeInTheDocument(); + fireEvent.change(screen.getByRole("textbox", { name: "Search installed skills" }), { + target: { value: "" }, + }); + expect(screen.getByRole("button", { name: "Open details for weather" })).toBeInTheDocument(); + expect(fetchSkills).toHaveBeenCalledTimes(3); + }); + it("discovers skills added after page load when opening the $ menu, not on each keystroke", async () => { const installed = { name: "simple-pr-review", @@ -50,7 +97,7 @@ describe("useSkills", () => { .mockResolvedValue({ skills: [installed] }); const getToken = () => "tok"; function Composer() { - const skills = useSkills(getToken); + const { skills } = useSkills(getToken); return ; } render(); @@ -105,7 +152,7 @@ describe("useSkills", () => { }); // The old response was captured before installation; it cannot satisfy the new opens. expect(fetchSkills).toHaveBeenCalledTimes(2); - expect(result.current).toEqual([installed]); + expect(result.current.skills).toEqual([installed]); unmount(); requestSkillsRefresh(); @@ -126,19 +173,19 @@ describe("useSkills", () => { const getToken = () => "tok"; const { result } = renderHook(() => useSkills(getToken)); await act(async () => {}); - expect(result.current).toEqual([installed]); + expect(result.current.skills).toEqual([installed]); await act(async () => { requestSkillsRefresh(); }); expect(fetchSkills).toHaveBeenCalledTimes(2); - expect(result.current).toEqual([installed]); + expect(result.current).toEqual({ skills: [installed], loading: false, error: false }); await act(async () => { requestSkillsRefresh(); }); expect(fetchSkills).toHaveBeenCalledTimes(3); - expect(result.current).toEqual([]); + expect(result.current).toEqual({ skills: [], loading: false, error: false }); }); it.each([false, true])("does not start a queued refresh after unmount (failure: %s)", async (fails) => { @@ -162,11 +209,11 @@ describe("useSkills", () => { expect(fetchSkills).toHaveBeenCalledTimes(1); }); - it("does not let an older request overwrite a newer skill event", async () => { - let resolveSkills!: (value: Awaited>) => void; + it.each([false, true])("does not let an older request overwrite a newer skill event (failure: %s)", async (fails) => { + let settle!: () => void; vi.mocked(fetchSkills).mockReset().mockImplementationOnce( - () => new Promise((resolve) => { - resolveSkills = resolve; + () => new Promise((resolve, reject) => { + settle = () => fails ? reject(new Error("Offline")) : resolve({ skills: [] }); }), ); const installed = { @@ -184,13 +231,13 @@ describe("useSkills", () => { detail: { skills: [installed] }, })); }); - expect(result.current).toEqual([installed]); + expect(result.current).toEqual({ skills: [installed], loading: false, error: false }); await act(async () => { - resolveSkills({ skills: [] }); + settle(); }); - expect(result.current).toEqual([installed]); + expect(result.current).toEqual({ skills: [installed], loading: false, error: false }); }); }); @@ -217,6 +264,54 @@ describe("SkillsMarketplace", () => { vi.useRealTimers(); }); + it("shows discovery skeletons while trending or the first search is pending and keeps loaded search results", async () => { + const skill = { + id: "skillhub:react-testing", skill_id: "react-testing", name: "React Testing", + source: "react-testing", provider: "skillhub" as const, installs: 42, + url: "https://skillhub.cn/react-testing", installed: false, install_supported: true, + metric: "installs_total" as const, rank: 1, + }; + let resolveTrending!: (value: Awaited>) => void; + let resolveSearch!: (value: Awaited>) => void; + let resolveNextSearch!: (value: Awaited>) => void; + vi.mocked(fetchTrendingMarketplaceSkills).mockImplementationOnce( + () => new Promise((resolve) => { resolveTrending = resolve; }), + ); + vi.mocked(searchMarketplaceSkills) + .mockImplementationOnce(() => new Promise((resolve) => { resolveSearch = resolve; })) + .mockImplementationOnce(() => new Promise((resolve) => { resolveNextSearch = resolve; })); + render(marketplace("tok")); + + expect(screen.getByRole("status", { name: "Loading skills…" })).toHaveAttribute("aria-busy", "true"); + await act(async () => { + resolveTrending({ period: "mixed", provider: "all", install_supported: true, skills: [skill] }); + }); + expect(screen.getByRole("button", { name: "Install React Testing" })).toBeInTheDocument(); + + fireEvent.change(screen.getByRole("textbox", { name: "Search skills" }), { + target: { value: "React" }, + }); + expect(screen.getByRole("status", { name: "Loading skills…" })).toHaveAttribute("aria-busy", "true"); + expect(searchMarketplaceSkills).not.toHaveBeenCalled(); + await act(async () => { await vi.advanceTimersByTimeAsync(300); }); + expect(searchMarketplaceSkills).toHaveBeenCalledWith("tok", "React"); + expect(screen.getByRole("status", { name: "Loading skills…" })).toBeInTheDocument(); + await act(async () => { + resolveSearch({ query: "React", provider: "all", install_supported: true, skills: [skill] }); + }); + + fireEvent.change(screen.getByRole("textbox", { name: "Search skills" }), { + target: { value: "Vue" }, + }); + await act(async () => { await vi.advanceTimersByTimeAsync(300); }); + expect(screen.getByRole("button", { name: "Install React Testing" })).toBeInTheDocument(); + expect(screen.queryByRole("status", { name: "Loading skills…" })).not.toBeInTheDocument(); + await act(async () => { + resolveNextSearch({ query: "Vue", provider: "all", install_supported: true, skills: [] }); + }); + expect(screen.getByText("No skills found for “Vue”.")).toBeInTheDocument(); + }); + it("keeps loaded marketplace data stable when the auth token rotates", async () => { const { rerender } = render(marketplace("tok-old"));