feat(FN-4853): complete Step 2 — aggregate pending approval counts

Fusion-Task-Id: FN-4853
Fusion-Task-Lineage: aaad0ff7-714c-4c82-a1e7-c9a725db90cb
This commit is contained in:
Fusion (runfusion.ai)
2026-05-17 00:48:06 -07:00
committed by gsxdsm
parent 404e202d7e
commit b8b97655b2
2 changed files with 12 additions and 7 deletions

View File

@@ -221,6 +221,17 @@ export class ApprovalRequestStore {
return rows.map((row) => this.rowToRequest(row));
}
getPendingCountsByActor(): Map<string, number> {
const rows = this.db.prepare(`
SELECT requesterActorId AS actorId, COUNT(*) AS requestCount
FROM approval_requests
WHERE status = 'pending'
GROUP BY requesterActorId
`).all() as Array<{ actorId: string; requestCount: number }>;
return new Map(rows.map((row) => [row.actorId, Number(row.requestCount)]));
}
findLatestByDedupeKey(input: { requesterActorId: string; taskId?: string; dedupeKey: string }): ApprovalRequest | null {
const where = ["requesterActorId = ?"];
const params: Array<string> = [input.requesterActorId];

View File

@@ -82,13 +82,7 @@ function isCompatibleDefaultHeartbeatPath(path: string | undefined, agent: Agent
function withPendingApprovalCounts<T extends Agent>(agents: T[], scopedStore: TaskStore): Array<T & { pendingApprovalCount: number }> {
try {
const approvalStore = new ApprovalRequestStore(scopedStore.getDatabase());
const pendingRequests = approvalStore.list({ status: "pending", limit: Number.MAX_SAFE_INTEGER, offset: 0 });
const counts = new Map<string, number>();
for (const request of pendingRequests) {
const agentId = request.requester.actorId;
counts.set(agentId, (counts.get(agentId) ?? 0) + 1);
}
const counts = approvalStore.getPendingCountsByActor();
return agents.map((agent) => ({
...agent,