Instead of calling refetch() with stale time params, the refresh buttons now set a toOverride state to new Date().toISOString(). This flows into the query key, triggering a fresh fetch with the current time as the upper bound. Both useApplicationLogs and useAgentEvents hooks accept an optional toOverride parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { api } from '../client';
|
|
import { config } from '../../config';
|
|
import { useAuthStore } from '../../auth/auth-store';
|
|
import { useRefreshInterval } from './use-refresh-interval';
|
|
|
|
export function useAgents(status?: string, application?: string) {
|
|
const refetchInterval = useRefreshInterval(10_000);
|
|
return useQuery({
|
|
queryKey: ['agents', status, application],
|
|
queryFn: async () => {
|
|
const { data, error } = await api.GET('/agents', {
|
|
params: { query: { ...(status ? { status } : {}), ...(application ? { application } : {}) } },
|
|
});
|
|
if (error) throw new Error('Failed to load agents');
|
|
return data!;
|
|
},
|
|
refetchInterval,
|
|
});
|
|
}
|
|
|
|
export function useAgentEvents(appId?: string, agentId?: string, limit = 50, toOverride?: string) {
|
|
const refetchInterval = useRefreshInterval(15_000);
|
|
return useQuery({
|
|
queryKey: ['agents', 'events', appId, agentId, limit, toOverride],
|
|
queryFn: async () => {
|
|
const token = useAuthStore.getState().accessToken;
|
|
const params = new URLSearchParams();
|
|
if (appId) params.set('appId', appId);
|
|
if (agentId) params.set('agentId', agentId);
|
|
if (toOverride) params.set('to', toOverride);
|
|
params.set('limit', String(limit));
|
|
const res = await fetch(`${config.apiBaseUrl}/agents/events-log?${params}`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-Cameleer-Protocol-Version': '1',
|
|
},
|
|
});
|
|
if (!res.ok) throw new Error('Failed to load agent events');
|
|
return res.json();
|
|
},
|
|
refetchInterval,
|
|
});
|
|
}
|