Fix: handle paginated responses (items wrapper) for dms/automation/agents/ai hooks
This commit is contained in:
@@ -142,7 +142,10 @@ export const deleteAgent = (id: string) => apiDelete(`/ai/agents/${id}`);
|
|||||||
|
|
||||||
// ─── Tools ───
|
// ─── 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 ───
|
// ─── Folders ───
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ import type {
|
|||||||
export function useAutomations() {
|
export function useAutomations() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['automations'],
|
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() {
|
export function useAgents() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['agents'],
|
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() {
|
export function useAgentTools() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['agentTools'],
|
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 ?? [];
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export function searchFiles(query: string): Promise<SearchResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSharedWithMe(): Promise<DmsFile[]> {
|
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[]> {
|
export function fetchSharedWithMe(): Promise<DmsFile[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user