Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

refactor(swarms): simplify swarm summarization and improve error handling refactor(css): update card field layout to use CSS Grid for better responsiveness

fudjia4c2648af58ab
diff --git a/api/_lib/swarms.js b/api/_lib/swarms.js
index 5e455d0d7..67ded0d7a 100644
--- a/api/_lib/swarms.js
+++ b/api/_lib/swarms.js
@@ -741,9 +741,7 @@ export async function listSwarms({ network = 'mainnet', status = null, limit = 3
select s.* from swarms s
where s.network = ${net} and s.status in ('open','active','paused')
order by (s.status = 'active') desc, s.created_at desc limit ${limit} offset ${offset}`;
- const out = [];
- for (const s of rows) out.push(await summarizeSwarm(s));
- return out;
+ return summarizeSwarms(rows);
}
/** Every swarm the user owns or is (or was) a member of, any status — for "My swarms". */
@@ -755,25 +753,57 @@ export async function listSwarmsForUser(userId) {
order by s.created_at desc
limit 100
`;
+ return summarizeSwarms(rows);
+}
+
+/**
+ * Summarize a batch of swarm rows for a directory listing. Aggregate stats for
+ * every swarm are fetched in two grouped queries (not two-per-swarm) so a long
+ * directory stays a fixed cost. A single member/position sub-query failure
+ * degrades to zeroed stats for the whole batch rather than 500-ing the endpoint,
+ * and a malformed individual row is skipped — a public directory must never die
+ * on one bad record.
+ */
+async function summarizeSwarms(rows) {
+ if (!rows.length) return [];
+ const swarmIds = rows.map((s) => s.id);
+ const treasuryIds = [...new Set(rows.map((s) => s.treasury_agent_id).filter(Boolean))];
+
+ const [memberRows, tradeRows] = await Promise.all([
+ sql`
+ select swarm_id,
+ count(*) filter (where status = 'active')::int as members,
+ coalesce(sum(contribution_lamports) filter (where status = 'active'),0)::numeric as contributed,
+ coalesce(sum(withdrawn_lamports),0)::numeric as withdrawn
+ from swarm_members where swarm_id = any(${swarmIds}) group by swarm_id
+ `.catch(() => []),
+ treasuryIds.length
+ ? sql`
+ select agent_id, network,
+ count(*)::int as closed,
+ coalesce(sum(realized_pnl_lamports),0)::numeric as pnl,
+ count(*) filter (where realized_pnl_lamports > 0)::int as wins,
+ count(*) filter (where status in ('open','opening','closing'))::int as open
+ from agent_sniper_positions where agent_id = any(${treasuryIds}) group by agent_id, network
+ `.catch(() => [])
+ : Promise.resolve([]),
+ ]);
+
+ const memberBy = new Map(memberRows.map((r) => [r.swarm_id, r]));
+ const tradeBy = new Map(tradeRows.map((r) => [`${r.agent_id}|${r.network}`, r]));
+
const out = [];
- for (const s of rows) out.push(await summarizeSwarm(s));
+ for (const s of rows) {
+ try {
+ out.push(summarizeSwarmRow(s, memberBy.get(s.id), tradeBy.get(`${s.treasury_agent_id}|${s.network}`)));
+ } catch {
+ // A malformed row (e.g. unparseable policy) must not sink the whole list.
+ }
+ }
return out;
}
-async function summarizeSwarm(swarm) {
- const [agg] = await sql`
- select count(*) filter (where status = 'active')::int as members,
- coalesce(sum(contribution_lamports) filter (where status = 'active'),0)::numeric as contributed,
- coalesce(sum(withdrawn_lamports),0)::numeric as withdrawn
- from swarm_members where swarm_id = ${swarm.id}
- `;
- const [trades] = await sql`
- select count(*)::int as closed,
- coalesce(sum(realized_pnl_lamports),0)::numeric as pnl,
- count(*) filter (where realized_pnl_lamports > 0)::int as wins,
- count(*) filter (where status in ('open','opening','closing'))::int as open
- from agent_sniper_positions where agent_id = ${swarm.treasury_agent_id} and network = ${swarm.network}
- `;
+function summarizeSwarmRow(swarm, agg, trades) {
const lamports = (v) => (v == null ? 0 : Number(String(v).split('.')[0]) / LAMPORTS_PER_SOL);
const closed = Number(trades?.closed || 0);
return {
diff --git a/src/agent-detail.css b/src/agent-detail.css
index 159a9ae1a..5592e58fe 100644
--- a/src/agent-detail.css
+++ b/src/agent-detail.css
@@ -114,24 +114,31 @@ a {
min-width: 0;
}
-/* Masonry card field — tile the stacked cards across the full width.
- column-width auto-fits as many columns as the viewport allows; tall
- and short cards balance into even columns. The hero stays full-width
- above this grid; the footer stays below it. */
+/* Card field — tile the stacked cards across the full width. This is a
+ CSS Grid, not a CSS multi-column context, on purpose: multi-column
+ (`column-width`) strands every card into the leftmost column and lets the
+ page overflow straight down whenever its content can't balance — the
+ "single narrow column beside a huge dead gutter, page runs off the bottom"
+ failure this page used to hit. `repeat(auto-fit, minmax(min(100%, 360px),
+ 1fr))` can't do that: it packs as many ~360px tracks as fit and STRETCHES
+ them to fill the row, collapsing empty tracks so a short field (few cards)
+ still spans the full width instead of hugging the left edge. `min(100%,
+ 360px)` keeps a lone card full-width instead of overflowing on sub-360px
+ viewports. The hero stays full-width above this grid; the footer below. */
.ad-cards {
- /* 380px tiles let a second column form as soon as the content field
- clears ~800px, so tablet / split-screen / collapsed-sidebar widths
- get a balanced two-up grid instead of one stretched column. */
- column-width: 380px;
- column-gap: 16px;
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
+ align-items: start;
+ gap: 16px;
padding: 4px 24px 0;
}
.ad-cards > .ad-card,
.ad-cards > details {
- margin: 0 0 16px;
- width: 100%;
- break-inside: avoid;
- -webkit-column-break-inside: avoid;
+ margin: 0;
+ /* Let a grid track shrink below its content's min-content width so a wide
+ child (mono address, live canvas, embed) can't blow a column out and
+ force the whole field wider than the viewport. */
+ min-width: 0;
}
.ad-banner {
@@ -784,10 +791,9 @@ div.ad-hero-avatar canvas {
color: var(--ad-text);
}
-/* Below 1024px the 220px sidebar would leave too little room for the card
- field to form two columns, stranding a single narrow column beside dead
- space. Drop the sidebar (its links live in the global nav too) and give
- the content the full width so the masonry can tile properly. */
+/* Below 1024px the 220px sidebar leaves too little room for the card field
+ to form two columns. Drop the sidebar (its links live in the global nav
+ too) and give the content the full width so the grid can tile two-up. */
@media (max-width: 1024px) {
.ad-shell {
grid-template-columns: 1fr;