Skip to content

Commit 2ba3ee3

Browse files
fix: duplication
1 parent 47b1e15 commit 2ba3ee3

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

gui/src/components/BackgroundMode/AgentsList.tsx

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ArrowPathIcon, PlayIcon } from "@heroicons/react/24/outline";
22
import { useContext, useEffect, useState } from "react";
3+
import { normalizeRepoUrl } from "core/util/repoUrl";
34
import { useAuth } from "../../context/Auth";
45
import { IdeMessengerContext } from "../../context/IdeMessenger";
56
import { useAppSelector } from "../../redux/hooks";
@@ -21,48 +22,6 @@ interface AgentsListProps {
2122
isCreatingAgent?: boolean;
2223
}
2324

24-
// Robust URL normalization function
25-
const normalizeRepoUrl = (url: string | undefined | null): string => {
26-
if (!url) return "";
27-
28-
let normalized = url.trim();
29-
30-
// Convert SSH to HTTPS: git@github.com:owner/repo.git -> https://github.com/owner/repo
31-
if (normalized.startsWith("git@github.com:")) {
32-
normalized = normalized.replace("git@github.com:", "https://github.com/");
33-
}
34-
35-
// Convert SSH protocol to HTTPS: ssh://git@github.com/owner/repo.git -> https://github.com/owner/repo
36-
// Also handles: ssh://git@github.com:owner/repo.git (less common)
37-
if (normalized.startsWith("ssh://git@github.com")) {
38-
normalized = normalized
39-
.replace("ssh://git@github.com/", "https://github.com/")
40-
.replace("ssh://git@github.com:", "https://github.com/");
41-
}
42-
43-
// Convert shorthand owner/repo to full URL
44-
if (
45-
normalized.includes("/") &&
46-
!normalized.startsWith("http") &&
47-
!normalized.startsWith("git@")
48-
) {
49-
normalized = `https://github.com/${normalized}`;
50-
}
51-
52-
// Remove .git suffix
53-
if (normalized.endsWith(".git")) {
54-
normalized = normalized.slice(0, -4);
55-
}
56-
57-
// Remove trailing slash
58-
if (normalized.endsWith("/")) {
59-
normalized = normalized.slice(0, -1);
60-
}
61-
62-
// Normalize to lowercase
63-
return normalized.toLowerCase();
64-
};
65-
6625
export function AgentsList({ isCreatingAgent = false }: AgentsListProps) {
6726
const { session } = useAuth();
6827
const ideMessenger = useContext(IdeMessengerContext);
@@ -156,7 +115,7 @@ export function AgentsList({ isCreatingAgent = false }: AgentsListProps) {
156115
const isAgentInCurrentWorkspace = (agent: Agent): boolean => {
157116
// Get all possible agent repo URLs (both repoUrl and metadata.github_repo)
158117
const agentUrls = [agent.repoUrl, agent.metadata?.github_repo]
159-
.filter(Boolean)
118+
.filter((url): url is string => Boolean(url))
160119
.map(normalizeRepoUrl)
161120
.filter((url) => url !== "");
162121

0 commit comments

Comments
 (0)