From cd55f097bf39096c7ebba1bb82e1f45f0c2342fb Mon Sep 17 00:00:00 2001 From: a7m-1st Date: Thu, 13 Nov 2025 01:53:55 +0300 Subject: [PATCH] enhance: update history api with backwards compat --- src/service/historyApi.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/service/historyApi.ts b/src/service/historyApi.ts index d12fc0ced..7f0a39210 100644 --- a/src/service/historyApi.ts +++ b/src/service/historyApi.ts @@ -18,7 +18,8 @@ const groupTasksByProject = (tasks: HistoryTask[]): ProjectGroup[] => { tasks: [], total_completed_tasks: 0, total_failed_tasks: 0, - average_tokens_per_task: 0 + average_tokens_per_task: 0, + last_prompt: task.question || "", }); } @@ -72,8 +73,30 @@ export const fetchHistoryTasks = async (setTasks: React.Dispatch>) => { + try { + const res = await proxyFetchGet(`/api/chat/histories/grouped?include_tasks=true`); + setProjects(res.projects); + } catch (error) { + console.error("Failed to fetch grouped history tasks, using fallback:", error); + fetchGroupedHistoryTasksLegacy(setProjects); + } +}; + +// Function to fetch grouped history summaries only (without individual tasks for better performance) +export const fetchGroupedHistorySummaries = async (setProjects: React.Dispatch>) => { + try { + const res = await proxyFetchGet(`/api/chat/histories/grouped?include_tasks=false`); + setProjects(res.projects); + } catch (error) { + console.error("Failed to fetch grouped history summaries, using fallback:", error); + fetchGroupedHistoryTasksLegacy(setProjects); + } +}; + +// Legacy function for backward compatibility - groups on frontend +export const fetchGroupedHistoryTasksLegacy = async (setProjects: React.Dispatch>) => { try { const res = await proxyFetchGet(`/api/chat/histories`); const groupedProjects = groupTasksByProject(res.items);