import { useQuery } from '@tanstack/react-query'; import { api } from '../client'; import type { SearchRequest } from '../schema'; export function useSearchExecutions(filters: SearchRequest) { return useQuery({ queryKey: ['executions', 'search', filters], queryFn: async () => { const { data, error } = await api.POST('/search/executions', { body: filters, }); if (error) throw new Error('Search failed'); return data!; }, placeholderData: (prev) => prev, }); } export function useExecutionDetail(executionId: string | null) { return useQuery({ queryKey: ['executions', 'detail', executionId], queryFn: async () => { const { data, error } = await api.GET('/executions/{executionId}', { params: { path: { executionId: executionId! } }, }); if (error) throw new Error('Failed to load execution detail'); return data!; }, enabled: !!executionId, }); } export function useProcessorSnapshot( executionId: string | null, index: number | null, ) { return useQuery({ queryKey: ['executions', 'snapshot', executionId, index], queryFn: async () => { const { data, error } = await api.GET( '/executions/{executionId}/processors/{index}/snapshot', { params: { path: { executionId: executionId!, index: index! }, }, }, ); if (error) throw new Error('Failed to load snapshot'); return data!; }, enabled: !!executionId && index !== null, }); }