mirror of
https://github.com/block/buzz.git
synced 2026-11-03 07:51:22 +00:00
Split unified agent grouping helpers
This commit is contained in:
@@ -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;
|
||||
|
||||
44
desktop/src/features/agents/ui/unifiedAgentGroups.ts
Normal file
44
desktop/src/features/agents/ui/unifiedAgentGroups.ts
Normal 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];
|
||||
}
|
||||
Reference in New Issue
Block a user