feat: integrate skills.sh search for discovering skills from public registry

Add skills.sh API integration allowing users to search and install from
a catalog of 91K+ agent skills directly within CC Switch. The search
results are converted to DiscoverableSkill objects and reuse the existing
install pipeline. Includes fallback directory search for repos where
skills are nested in subdirectories, and filters out non-GitHub sources.
This commit is contained in:
Jason
2026-04-05 22:16:10 +08:00
parent 33f5d56afd
commit d51e774b20
11 changed files with 583 additions and 57 deletions
+16
View File
@@ -0,0 +1,16 @@
import { useState, useEffect } from "react";
/**
* 返回一个延迟更新的值,在指定时间内无新变化后才更新。
* 用于搜索输入等场景,避免每次按键都触发请求。
*/
export function useDebouncedValue<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value);
useEffect(() => {
const timer = setTimeout(() => setDebouncedValue(value), delay);
return () => clearTimeout(timer);
}, [value, delay]);
return debouncedValue;
}
+22
View File
@@ -11,6 +11,7 @@ import {
type ImportSkillSelection,
type InstalledSkill,
type SkillUpdateInfo,
type SkillsShSearchResult,
} from "@/lib/api/skills";
import type { AppId } from "@/lib/api/types";
@@ -326,6 +327,26 @@ export function useUpdateSkill() {
});
}
// ========== skills.sh 搜索 ==========
/**
* 搜索 skills.sh 公共目录
* 使用 300ms staleTime 和 keepPreviousData 实现平滑搜索体验
*/
export function useSearchSkillsSh(
query: string,
limit: number,
offset: number,
) {
return useQuery({
queryKey: ["skills", "skillssh", query, limit, offset],
queryFn: () => skillsApi.searchSkillsSh(query, limit, offset),
enabled: query.length >= 2,
staleTime: 5 * 60 * 1000,
placeholderData: keepPreviousData,
});
}
// ========== 辅助类型 ==========
export type {
@@ -334,5 +355,6 @@ export type {
ImportSkillSelection,
SkillBackupEntry,
SkillUpdateInfo,
SkillsShSearchResult,
AppId,
};