Fix: handle paginated responses (items wrapper) for dms/automation/agents/ai hooks

This commit is contained in:
Agent Zero
2026-07-26 01:35:03 +02:00
parent 15a6c9b6c6
commit 6d484ed747
3 changed files with 17 additions and 5 deletions
+12 -3
View File
@@ -22,7 +22,10 @@ import type {
export function useAutomations() {
return useQuery({
queryKey: ['automations'],
queryFn: () => apiGet<AutomationDefinition[]>('/automation'),
queryFn: async () => {
const res = await apiGet<AutomationDefinition[] | { items: AutomationDefinition[] }>('/automation');
return Array.isArray(res) ? res : res.items ?? [];
},
});
}
@@ -136,7 +139,10 @@ export function useUpdateAutomationSettings() {
export function useAgents() {
return useQuery({
queryKey: ['agents'],
queryFn: () => apiGet<AgentDefinition[]>('/agents'),
queryFn: async () => {
const res = await apiGet<AgentDefinition[] | { items: AgentDefinition[] }>('/agents');
return Array.isArray(res) ? res : res.items ?? [];
},
});
}
@@ -230,7 +236,10 @@ export function useRestoreAgentVersion() {
export function useAgentTools() {
return useQuery({
queryKey: ['agentTools'],
queryFn: () => apiGet<AgentTool[]>('/agents/tools'),
queryFn: async () => {
const res = await apiGet<AgentTool[] | { items: AgentTool[] }>('/agents/tools');
return Array.isArray(res) ? res : res.items ?? [];
},
});
}