Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 3x 3x 1x 3x 3x 8x 8x 8x 3x 8x 8x 8x 2x 8x 8x 2x 18x 4x 8x 8x 8x 8x 8x 1x 8x 1x 7x 2x 2x 1x 1x | import GeneratedMark from "@/components/badge/GeneratedMark";
import {
collectionSection,
CreateButton,
ResourceCollection,
useCollectionFilters,
} from "@/components/collection";
import { formatUsd } from "@/components/cost";
import { OriginBadge } from "@/components/owner";
import { type Swarm, type SwarmThread, type Topology } from "@/objects/Swarm";
import { APP_ROUTES } from "@/routes/const";
import { swarmHref } from "@/routes/resourceHref";
import type { TopologyCatalogue } from "@/services/api/routers/SwarmRouter";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useQuery } from "@tanstack/react-query";
import { ChevronRight, Network, PlayCircle, Users } from "lucide-react";
import React, { useMemo } from "react";
import { Link } from "react-router-dom";
import { formatDuration, shapeLabel } from "./swarmDisplay";
import ThreadRow from "./ThreadRow";
/**
* The Swarms tab: the workspace's swarms, and the caller's runs of them —
* those going first. A swarm is a team of agents in a shape; a run is one
* dispatch of it on a task, under a budget and a time cap.
*/
const POLL_MS = 5000;
const SwarmCard: React.FC<{ swarm: Swarm; shape: string }> = ({ swarm, shape }) => (
<Link
to={swarmHref(swarm.id)}
className="group flex flex-col gap-3 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-5 shadow-sm hover:shadow-md hover:border-gray-300 dark:hover:border-gray-500 transition-all"
>
<div className="flex items-center gap-3 min-w-0">
<GeneratedMark generated={swarm.is_ai_generated} label="AI generated swarm">
<div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
<Network className="size-5 text-gray-600 dark:text-gray-300" />
</div>
</GeneratedMark>
<div className="min-w-0">
<div className="flex items-center gap-1.5 min-w-0">
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100 truncate">
{swarm.name}
</span>
<OriginBadge resource={swarm} />
</div>
<div className="text-xs text-gray-400 dark:text-gray-500">{shape}</div>
</div>
</div>
{swarm.description ? (
<p className="text-xs text-gray-500 dark:text-gray-400 line-clamp-2">{swarm.description}</p>
) : (
<p className="text-xs italic text-gray-300 dark:text-gray-600">No description.</p>
)}
<div className="flex flex-wrap items-center gap-3 text-xs text-gray-500 dark:text-gray-400">
<span className="flex items-center gap-1">
<Users className="size-3" />
{swarm.roster.length} agent{swarm.roster.length === 1 ? "" : "s"}
</span>
{swarm.defaults.budget_usd != null && (
<span>{formatUsd(swarm.defaults.budget_usd)} a run</span>
)}
{swarm.defaults.time_cap_s != null && (
<span>{formatDuration(swarm.defaults.time_cap_s)} at most</span>
)}
</div>
</Link>
);
const SwarmRow: React.FC<{ swarm: Swarm; shape: string }> = ({ swarm, shape }) => (
<Link
to={swarmHref(swarm.id)}
className="flex items-center gap-3 px-4 py-3 border-b border-gray-100 dark:border-gray-700 last:border-0 hover:bg-gray-50 dark:hover:bg-gray-700/40 group"
>
<Network className="size-4 text-gray-500 shrink-0" />
<div className="flex-1 min-w-0">
<div className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">
{swarm.name}
</div>
<div className="text-xs text-gray-400 dark:text-gray-500 truncate">
{shape} · {swarm.roster.length} agent{swarm.roster.length === 1 ? "" : "s"}
</div>
</div>
<ChevronRight className="size-3.5 text-gray-300 dark:text-gray-600 opacity-0 group-hover:opacity-100" />
</Link>
);
export const SwarmsContent: React.FC = () => {
const { getApiHandler } = useApiHandler();
const collection = useCollectionFilters();
const { data: catalogue } = useQuery<TopologyCatalogue>({
queryKey: [QUERY_KEYS.GET.SWARM_TOPOLOGIES],
queryFn: () => getApiHandler().swarm_router.topologies(),
});
const off = catalogue?.unavailable === "off";
// Asked for once the catalogue says swarms are on here, never before.
const on = catalogue?.unavailable === null;
const { data: swarms = [], isLoading: listLoading } = useQuery<Swarm[]>({
queryKey: [QUERY_KEYS.GET.SWARMS],
queryFn: () => getApiHandler().swarm_router.list(),
enabled: on,
});
const isLoading = !catalogue || listLoading;
// A run and its follow-ups are one item.
const { data: threads = [] } = useQuery<SwarmThread[]>({
queryKey: [QUERY_KEYS.GET.SWARM_THREADS, "mine"],
queryFn: () => getApiHandler().swarm_router.myThreads(),
enabled: on,
refetchInterval: (query) =>
((query.state.data as SwarmThread[] | undefined) ?? []).some((t) => t.open)
? POLL_MS
: false,
});
const topologies: Topology[] = catalogue?.topologies ?? [];
const going = threads.filter((t: SwarmThread) => t.open);
const { matches } = collection;
const shown = useMemo(
() =>
swarms.filter((s: Swarm) =>
matches(s.name, s.description, shapeLabel(topologies, s.topology)),
),
[swarms, matches, topologies],
);
if (off) {
return (
<div className="rounded-xl border border-dashed border-gray-200 dark:border-gray-700 p-8 text-center">
<Network className="mx-auto size-6 text-gray-300 dark:text-gray-600" />
<p className="mt-2 text-sm font-medium text-gray-600 dark:text-gray-300">
Swarms are switched off on this deployment
</p>
<p className="mt-1 text-xs text-gray-400 dark:text-gray-500">
A swarm sends a team of your agents on a long task under a budget and a
time cap.
</p>
</div>
);
}
return (
<ResourceCollection
description="A swarm is a team of your agents in a shape — a lead and workers, say. Send it on a long task with a budget and a time cap: the lead plans, the team does the pieces in parallel, the lead checks each piece and writes the answer. Every step is one of your agents, governed by its rules."
stats={[
{ label: "Swarms", value: swarms.length, loading: isLoading },
{ label: "Going now", value: going.length },
]}
shown={shown.length}
search={{
value: collection.search,
onChange: collection.setSearch,
placeholder: "Search swarms…",
}}
{...collection.toolbarProps}
actions={
<CreateButton label="New Swarm" to={APP_ROUTES.USER.INFERENCE.SWARMS.new} />
}
sections={[
collectionSection<SwarmThread>({
label: "Your runs",
hint: "newest first; a run and its follow-ups are one row",
items: threads,
itemKey: (thread) => thread.thread_id,
renderRow: (thread) => <ThreadRow thread={thread} />,
renderCard: (thread) => <ThreadRow thread={thread} />,
hideWhenEmpty: true,
empty: { Icon: PlayCircle, title: "No runs yet." },
}),
collectionSection<Swarm>({
label: "Swarms",
items: shown,
itemKey: (swarm) => swarm.id,
renderCard: (swarm) => (
<SwarmCard swarm={swarm} shape={shapeLabel(topologies, swarm.topology)} />
),
renderRow: (swarm) => (
<SwarmRow swarm={swarm} shape={shapeLabel(topologies, swarm.topology)} />
),
loading: isLoading,
skeletonCount: 2,
empty: {
Icon: Network,
title: "No swarms yet.",
hint: "Put a few of your agents into a shape — a lead and its workers — and send them on a task.",
dashed: true,
},
emptyFilteredTitle: "No swarms match your search.",
}),
]}
/>
);
};
export default SwarmsContent;
|