Select mode picks agents from the list: the select button in the filter card, a press on an agent's icon, or a long press on a card starts it. In it a card toggles a tick instead of opening its details, and the card's own controls stop answering. A bar at the foot of the list has select all shown, clear, broadcast and done; Escape leaves the mode. Broadcast opens a dialog with the picked agents and a message box, sending through the existing broadcast endpoint; the composer's send and result parts are now shared with the swarm page's broadcast card. A full send shows a toast and ends select mode; a partial one keeps the result with a retry for the agents that failed.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
// The agents page's picks for select mode. Plain functions with no imports, so
|
|
// `npm test` runs them; `useAgentSelection` holds the state.
|
|
|
|
/** `picked` without the agents the roster no longer has (one destroyed meanwhile). */
|
|
export function stillThere(picked: string[], roster: string[]): string[] {
|
|
const known = new Set(roster);
|
|
return picked.filter((name) => known.has(name));
|
|
}
|
|
|
|
/** Starting select mode on `name`: it is picked, and any earlier picks stay. */
|
|
export function startedOn(picked: string[], name: string | null): string[] {
|
|
if (name === null || picked.includes(name)) return picked;
|
|
return [...picked, name];
|
|
}
|
|
|
|
/** `picked` with `name` flipped. */
|
|
export function toggled(picked: string[], name: string): string[] {
|
|
return picked.includes(name)
|
|
? picked.filter((n) => n !== name)
|
|
: [...picked, name];
|
|
}
|
|
|
|
/** `picked` plus every shown agent, without repeating a name. */
|
|
export function pickedAll(picked: string[], shown: string[]): string[] {
|
|
const out = [...picked];
|
|
for (const name of shown) {
|
|
if (!out.includes(name)) out.push(name);
|
|
}
|
|
return out;
|
|
}
|