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:
Shirone
2026-01-15 16:20:24 +01:00
parent e57549c06e
commit 2bc931a8b0
16 changed files with 1646 additions and 0 deletions

View 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,
};
}