From 6d484ed747019099d68ce86eae61f4e078a3ee91 Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Sun, 26 Jul 2026 01:35:03 +0200 Subject: [PATCH] Fix: handle paginated responses (items wrapper) for dms/automation/agents/ai hooks --- frontend/src/api/ai.ts | 5 ++++- frontend/src/api/automation.ts | 15 ++++++++++++--- frontend/src/api/dms.ts | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/api/ai.ts b/frontend/src/api/ai.ts index ab333d5..19b14c6 100644 --- a/frontend/src/api/ai.ts +++ b/frontend/src/api/ai.ts @@ -142,7 +142,10 @@ export const deleteAgent = (id: string) => apiDelete(`/ai/agents/${id}`); // ─── Tools ─── -export const fetchTools = () => apiGet('/ai/tools'); +export const fetchTools = async () => { + const res = await apiGet('/ai/tools'); + return Array.isArray(res) ? res : res.items ?? []; +}; // ─── Folders ─── diff --git a/frontend/src/api/automation.ts b/frontend/src/api/automation.ts index 04ee62d..1f05089 100644 --- a/frontend/src/api/automation.ts +++ b/frontend/src/api/automation.ts @@ -22,7 +22,10 @@ import type { export function useAutomations() { return useQuery({ queryKey: ['automations'], - queryFn: () => apiGet('/automation'), + queryFn: async () => { + const res = await apiGet('/automation'); + return Array.isArray(res) ? res : res.items ?? []; + }, }); } @@ -136,7 +139,10 @@ export function useUpdateAutomationSettings() { export function useAgents() { return useQuery({ queryKey: ['agents'], - queryFn: () => apiGet('/agents'), + queryFn: async () => { + const res = await apiGet('/agents'); + return Array.isArray(res) ? res : res.items ?? []; + }, }); } @@ -230,7 +236,10 @@ export function useRestoreAgentVersion() { export function useAgentTools() { return useQuery({ queryKey: ['agentTools'], - queryFn: () => apiGet('/agents/tools'), + queryFn: async () => { + const res = await apiGet('/agents/tools'); + return Array.isArray(res) ? res : res.items ?? []; + }, }); } diff --git a/frontend/src/api/dms.ts b/frontend/src/api/dms.ts index ecbd90f..80ad49c 100644 --- a/frontend/src/api/dms.ts +++ b/frontend/src/api/dms.ts @@ -191,7 +191,7 @@ export function searchFiles(query: string): Promise { } export function getSharedWithMe(): Promise { - return apiGet('/dms/shared-with-me'); + return apiGet('/dms/shared-with-me').then(r => Array.isArray(r) ? r : r.items ?? []); } export function fetchSharedWithMe(): Promise {