Split unified agent grouping helpers

This commit is contained in:
klopez4212
2026-06-25 14:12:03 +01:00
parent ae2f3a2e3b
commit a4588ca00d
2 changed files with 45 additions and 39 deletions

View File

@@ -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<string, ManagedAgent[]>();
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<string>();
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;

View File

@@ -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<string, ManagedAgent[]>();
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<string>();
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];
}