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.
This commit is contained in:
Lukas May
2026-02-04 22:00:34 +01:00
parent c93b3aaa4c
commit 049810ffae

View File

@@ -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<PendingQuestions | null> => {
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');
}),