Fix: handle paginated responses (items wrapper) for dms/automation/agents/ai hooks
This commit is contained in:
@@ -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 ?? [];
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user