swarm ui: select several agents on the agents page and broadcast to them
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.
This commit is contained in:
parent
7bdaea7954
commit
56ed2e07da
1 changed files with 793 additions and 88 deletions
30
frontend/packages/swarm-ui/src/pages/agents/selection.ts
Normal file
30
frontend/packages/swarm-ui/src/pages/agents/selection.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// 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;
|
||||
}
|
||||
Loading…
Reference in a new issue