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
+4 -1
View File
@@ -142,7 +142,10 @@ export const deleteAgent = (id: string) => apiDelete(`/ai/agents/${id}`);
// ─── Tools ───
export const fetchTools = () => apiGet<AITool[]>('/ai/tools');
export const fetchTools = async () => {
const res = await apiGet<AITool[] | { items: AITool[] }>('/ai/tools');
return Array.isArray(res) ? res : res.items ?? [];
};
// ─── Folders ───
+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 ?? [];
},
});
}
+1 -1
View File
@@ -191,7 +191,7 @@ export function searchFiles(query: string): Promise<SearchResult> {
}
export function getSharedWithMe(): Promise<DmsFile[]> {
return apiGet<DmsFile[]>('/dms/shared-with-me');
return apiGet<DmsFile[] | { items: DmsFile[] }>('/dms/shared-with-me').then(r => Array.isArray(r) ? r : r.items ?? []);
}
export function fetchSharedWithMe(): Promise<DmsFile[]> {