diff --git a/ui/src/components/InstallDialog.tsx b/ui/src/components/InstallDialog.tsx
index fc667a6d6..7a20585b4 100644
--- a/ui/src/components/InstallDialog.tsx
+++ b/ui/src/components/InstallDialog.tsx
@@ -74,6 +74,18 @@ function isGitSource(s: string) {
const sameURL = (a: string, b: string) => a.trim().replace(/\/+$/, '') === b.trim().replace(/\/+$/, '');
+function sourceKey(source: string): string {
+ const value = source.trim().replace(/\/+$/, '');
+ const github = value.match(/^(?:(?:https?:\/\/)?(?:www\.)?github\.com\/|git@github\.com:)(.+)$/i)?.[1]
+ ?? (/^[^/:.]+\/[^/]+/.test(value) ? value : null);
+ return github ? `github:${github.replace(/\.git(?=\/|$)/i, '').toLowerCase()}` : value;
+}
+
+function discoveredSource(source: string, path: string): string {
+ if (path === '.') return source;
+ return `${source}${/^(?:git@|ssh:\/\/).+\.git$/i.test(source) ? '//' : '/'}${path}`;
+}
+
function mergeHubs(hubs: HubSavedEntry[]): HubSavedEntry[] {
return [COMMUNITY_HUB, ...hubs.filter((h) => !sameURL(h.url, COMMUNITY_HUB.url)).map((h) => ({ label: h.label, url: h.url }))];
}
@@ -128,8 +140,14 @@ export default function InstallDialog({ kind, initialTab, initialSource, onClose
queryFn: () => api.listSkills(),
staleTime: staleTimes.skills,
});
- const installedKeys = useMemo(() => new Set((skillsData?.resources ?? []).map((r) => `${r.kind}:${r.name}`)), [skillsData]);
- const isInstalled = (k: Kind, n: string) => installedKeys.has(`${k}:${n}`);
+ const installedKeys = useMemo(() => new Set((skillsData?.resources ?? []).filter((r) => r.source).map((r) => `${r.kind}:${sourceKey(r.source!)}`)), [skillsData]);
+ const isInstalled = (k: Kind, source: string) => installedKeys.has(`${k}:${sourceKey(source)}`);
+ const isInstalledResult = (result: SearchResult) => {
+ if (!result.skill) return isInstalled(kind, result.source);
+ const source = sourceKey(result.source);
+ return (skillsData?.resources ?? []).some((item) => item.kind === kind && item.name === result.skill && item.source
+ && (sourceKey(item.source) === source || sourceKey(item.source).startsWith(`${source}/`)));
+ };
const { data: hubConfig } = useQuery({
queryKey: queryKeys.hubConfig,
@@ -268,7 +286,7 @@ export default function InstallDialog({ kind, initialTab, initialSource, onClose
const show = (items: DiscoveredSkill[]) => {
setSource(from);
setFound({ source: from, items });
- setSelected(new Set(items.filter((i) => !isInstalled(i.kind ?? 'skill', i.name)).map((i) => i.path)));
+ setSelected(new Set(items.filter((i) => !isInstalled(i.kind ?? 'skill', discoveredSource(from, i.path))).map((i) => i.path)));
setFilter('');
setExpanded(false);
setTab('url');
@@ -436,7 +454,7 @@ export default function InstallDialog({ kind, initialTab, initialSource, onClose
<>
- {isInstalled(kind, p.name) ? (
+ {isInstalledResult(p) ? (
Installed
) : (