"use client"; import { useCallback, useState } from "react"; import { listChatSessions, type ChatSessionOut } from "@/lib/api/chatHistory"; import { listLocalChatSessions } from "./local-chat-history"; export function useChatSessions() { const [chatSessions, setChatSessions] = useState([]); const [isHistoryLoading, setIsHistoryLoading] = useState(false); const [activeSessionId, setActiveSessionId] = useState(null); const refreshChatHistory = useCallback(async () => { setIsHistoryLoading(true); try { const sessions = await listChatSessions(); setChatSessions(sessions); } catch { setChatSessions(listLocalChatSessions()); } finally { setIsHistoryLoading(false); } }, []); return { chatSessions, setChatSessions, isHistoryLoading, activeSessionId, setActiveSessionId, refreshChatHistory, }; }