From 049810ffae9a280def953029bc98c9cd19e7046c Mon Sep 17 00:00:00 2001 From: Lukas May Date: Wed, 4 Feb 2026 22:00:34 +0100 Subject: [PATCH] fix(19): gracefully handle missing agentManager in read-only agent procedures listWaitingAgents, listAgents, and getAgentQuestions now return empty results instead of throwing when agentManager is not wired into the tRPC context. Mutation procedures (spawn, stop, resume) still throw. --- src/trpc/router.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/trpc/router.ts b/src/trpc/router.ts index 699cfd0..3edf19c 100644 --- a/src/trpc/router.ts +++ b/src/trpc/router.ts @@ -408,8 +408,8 @@ export const appRouter = router({ */ listAgents: publicProcedure .query(async ({ ctx }) => { - const agentManager = requireAgentManager(ctx); - return agentManager.list(); + if (!ctx.agentManager) return []; + return ctx.agentManager.list(); }), /** @@ -463,9 +463,9 @@ export const appRouter = router({ getAgentQuestions: publicProcedure .input(agentIdentifierSchema) .query(async ({ ctx, input }): Promise => { - const agentManager = requireAgentManager(ctx); + if (!ctx.agentManager) return null; const agent = await resolveAgent(ctx, input); - return agentManager.getPendingQuestions(agent.id); + return ctx.agentManager.getPendingQuestions(agent.id); }), /** @@ -474,8 +474,8 @@ export const appRouter = router({ */ listWaitingAgents: publicProcedure .query(async ({ ctx }) => { - const agentManager = requireAgentManager(ctx); - const allAgents = await agentManager.list(); + if (!ctx.agentManager) return []; + const allAgents = await ctx.agentManager.list(); return allAgents.filter(agent => agent.status === 'waiting_for_input'); }),