feat: implement Radar backend tRPC procedures with repository extensions
Add five new tRPC query procedures powering the Radar page's per-agent behavioral metrics (questions asked, subagent spawns, compaction events, inter-agent messages) plus the batch repository methods they require. Repository changes: - LogChunkRepository: add findByAgentIds() for batch fetching without N+1 - ConversationRepository: add countByFromAgentIds() and findByFromAgentId() - Drizzle adapters: implement all three new methods using inArray() - InMemoryConversationRepository (integration test): implement new methods tRPC procedures added: - agent.listForRadar: filtered agent list with per-agent metrics computed from log chunks (questionsCount, subagentsCount, compactionsCount) and conversation counts (messagesCount); supports timeRange/status/mode/initiative filters - agent.getCompactionEvents: compact system init chunks for one agent (cap 200) - agent.getSubagentSpawns: Agent tool_use entries with prompt preview (cap 200) - agent.getQuestionsAsked: AskUserQuestion tool calls with questions array (cap 200) - conversation.getByFromAgent: conversations by fromAgentId with toAgentName resolved All 13 new unit tests pass; existing test suite unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,24 @@ class InMemoryConversationRepository implements ConversationRepository {
|
||||
return updated;
|
||||
}
|
||||
|
||||
async countByFromAgentIds(agentIds: string[]): Promise<{ agentId: string; count: number }[]> {
|
||||
if (agentIds.length === 0) return [];
|
||||
const counts = new Map<string, number>();
|
||||
for (const conv of this.store.values()) {
|
||||
if (agentIds.includes(conv.fromAgentId)) {
|
||||
counts.set(conv.fromAgentId, (counts.get(conv.fromAgentId) ?? 0) + 1);
|
||||
}
|
||||
}
|
||||
return [...counts.entries()].map(([agentId, count]) => ({ agentId, count }));
|
||||
}
|
||||
|
||||
async findByFromAgentId(agentId: string): Promise<Conversation[]> {
|
||||
return [...this.store.values()]
|
||||
.filter((c) => c.fromAgentId === agentId)
|
||||
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime())
|
||||
.slice(0, 200);
|
||||
}
|
||||
|
||||
/** Test helper — return all conversations */
|
||||
getAll(): Conversation[] {
|
||||
return [...this.store.values()];
|
||||
|
||||
Reference in New Issue
Block a user