diff --git a/desktop/src/features/agents/ui/UnifiedAgentsSection.tsx b/desktop/src/features/agents/ui/UnifiedAgentsSection.tsx index 93ab5509d7..22d6b0d180 100644 --- a/desktop/src/features/agents/ui/UnifiedAgentsSection.tsx +++ b/desktop/src/features/agents/ui/UnifiedAgentsSection.tsx @@ -40,6 +40,7 @@ import { AgentIdentityCard } from "./AgentIdentityCard"; import { CreateIdentityCard } from "./CreateIdentityCard"; import { EditAgentDialog } from "./EditAgentDialog"; import { ManagedAgentLogPanel } from "./ManagedAgentLogPanel"; +import { buildUnifiedGroups, pickProfileAgent } from "./unifiedAgentGroups"; type UnifiedAgentsSectionProps = { actionErrorMessage: string | null; @@ -84,39 +85,9 @@ type UnifiedAgentsSectionProps = { onImportPersonaFile: (fileBytes: number[], fileName: string) => void; }; -type PersonaGroup = { persona: AgentPersona; agents: ManagedAgent[] }; - const AGENT_CARD_COLUMN_CLASS = "w-full"; const AGENT_CARD_GRID_CLASS = `${AGENT_CARD_COLUMN_CLASS} grid grid-cols-[repeat(auto-fill,minmax(220px,240px))] justify-start gap-3`; -function buildUnifiedGroups(personas: AgentPersona[], agents: ManagedAgent[]) { - const byPersonaId = new Map(); - const ungrouped: ManagedAgent[] = []; - - for (const agent of agents) { - if (!agent.personaId) { - ungrouped.push(agent); - } else { - const list = byPersonaId.get(agent.personaId) ?? []; - list.push(agent); - byPersonaId.set(agent.personaId, list); - } - } - - const matched = new Set(); - const groups: PersonaGroup[] = personas.map((p) => { - matched.add(p.id); - return { persona: p, agents: byPersonaId.get(p.id) ?? [] }; - }); - - const unknown: ManagedAgent[] = []; - for (const [id, list] of byPersonaId) { - if (!matched.has(id)) unknown.push(...list); - } - - return { groups, ungrouped, unknown }; -} - export function UnifiedAgentsSection(props: UnifiedAgentsSectionProps) { const { actionErrorMessage, @@ -376,15 +347,6 @@ export function UnifiedAgentsSection(props: UnifiedAgentsSectionProps) { ); } -function pickProfileAgent(agents: ManagedAgent[]) { - return [...agents].sort((left, right) => { - const activeDiff = - Number(isManagedAgentActive(right)) - Number(isManagedAgentActive(left)); - if (activeDiff !== 0) return activeDiff; - return left.name.localeCompare(right.name); - })[0]; -} - type AgentMenuProps = { isActionPending: boolean; onAddToChannel: (agent: ManagedAgent) => void; diff --git a/desktop/src/features/agents/ui/unifiedAgentGroups.ts b/desktop/src/features/agents/ui/unifiedAgentGroups.ts new file mode 100644 index 0000000000..a2d1b987f3 --- /dev/null +++ b/desktop/src/features/agents/ui/unifiedAgentGroups.ts @@ -0,0 +1,44 @@ +import { isManagedAgentActive } from "@/features/agents/lib/managedAgentControlActions"; +import type { AgentPersona, ManagedAgent } from "@/shared/api/types"; + +type PersonaGroup = { persona: AgentPersona; agents: ManagedAgent[] }; + +export function buildUnifiedGroups( + personas: AgentPersona[], + agents: ManagedAgent[], +) { + const byPersonaId = new Map(); + const ungrouped: ManagedAgent[] = []; + + for (const agent of agents) { + if (!agent.personaId) { + ungrouped.push(agent); + } else { + const list = byPersonaId.get(agent.personaId) ?? []; + list.push(agent); + byPersonaId.set(agent.personaId, list); + } + } + + const matched = new Set(); + const groups: PersonaGroup[] = personas.map((persona) => { + matched.add(persona.id); + return { persona, agents: byPersonaId.get(persona.id) ?? [] }; + }); + + const unknown: ManagedAgent[] = []; + for (const [id, list] of byPersonaId) { + if (!matched.has(id)) unknown.push(...list); + } + + return { groups, ungrouped, unknown }; +} + +export function pickProfileAgent(agents: ManagedAgent[]) { + return [...agents].sort((left, right) => { + const activeDiff = + Number(isManagedAgentActive(right)) - Number(isManagedAgentActive(left)); + if (activeDiff !== 0) return activeDiff; + return left.name.localeCompare(right.name); + })[0]; +}