mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-22 23:53:08 +00:00
feat(ui): add React Query hooks for data fetching
- Add useFeatures, useFeature, useAgentOutput for feature data - Add useGitHubIssues, useGitHubPRs, useGitHubValidations, useGitHubIssueComments - Add useClaudeUsage, useCodexUsage with polling intervals - Add useRunningAgents, useRunningAgentsCount - Add useWorktrees, useWorktreeInfo, useWorktreeStatus, useWorktreeDiffs - Add useGlobalSettings, useProjectSettings, useCredentials - Add useAvailableModels, useCodexModels, useOpencodeModels - Add useSessions, useSessionHistory, useSessionQueue - Add useIdeationPrompts, useIdeas - Add CLI status queries (claude, cursor, codex, opencode, github) - Add useCursorPermissionsQuery, useWorkspaceDirectories - Add usePipelineConfig, useSpecFile, useSpecRegenerationStatus Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
61
apps/ui/src/hooks/queries/use-running-agents.ts
Normal file
61
apps/ui/src/hooks/queries/use-running-agents.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Running Agents Query Hook
|
||||
*
|
||||
* React Query hook for fetching currently running agents.
|
||||
* This data is invalidated by WebSocket events when agents start/stop.
|
||||
*/
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getElectronAPI, type RunningAgent } from '@/lib/electron';
|
||||
import { queryKeys } from '@/lib/query-keys';
|
||||
import { STALE_TIMES } from '@/lib/query-client';
|
||||
|
||||
interface RunningAgentsResult {
|
||||
agents: RunningAgent[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all currently running agents
|
||||
*
|
||||
* @returns Query result with running agents and total count
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { data, isLoading } = useRunningAgents();
|
||||
* const { agents, count } = data ?? { agents: [], count: 0 };
|
||||
* ```
|
||||
*/
|
||||
export function useRunningAgents() {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.runningAgents.all(),
|
||||
queryFn: async (): Promise<RunningAgentsResult> => {
|
||||
const api = getElectronAPI();
|
||||
const result = await api.runningAgents.getAll();
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || 'Failed to fetch running agents');
|
||||
}
|
||||
return {
|
||||
agents: result.runningAgents ?? [],
|
||||
count: result.totalCount ?? 0,
|
||||
};
|
||||
},
|
||||
staleTime: STALE_TIMES.RUNNING_AGENTS,
|
||||
// Note: Don't use refetchInterval here - rely on WebSocket invalidation
|
||||
// for real-time updates instead of polling
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get running agents count
|
||||
* This is a selector that derives count from the main query
|
||||
*
|
||||
* @returns Query result with just the count
|
||||
*/
|
||||
export function useRunningAgentsCount() {
|
||||
const query = useRunningAgents();
|
||||
return {
|
||||
...query,
|
||||
data: query.data?.count ?? 0,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user