replace imperative fetch with tanstak

This commit is contained in:
thierryverse 2025-11-19 09:32:20 +02:00
parent 373bd668f7
commit ff73272da5
2 changed files with 1 additions and 60 deletions

View file

@ -45,57 +45,3 @@ export function useChatState({ chat_id }: UseChatStateProps) {
setTopK,
};
}
interface UseChatAPIProps {
token: string | null;
search_space_id: string;
}
export function useChatAPI({ token, search_space_id }: UseChatAPIProps) {
const updateChat = useCallback(
async (
chatId: string,
messages: Message[],
researchMode: ResearchMode,
selectedConnectors: string[]
) => {
if (!token) return;
try {
const userMessages = messages.filter((msg) => msg.role === "user");
if (userMessages.length === 0) return;
const title = userMessages[0].content;
const response = await fetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${Number(chatId)}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
type: researchMode,
title: title,
initial_connectors: selectedConnectors,
messages: messages,
search_space_id: Number(search_space_id),
}),
}
);
if (!response.ok) {
throw new Error(`Failed to update chat: ${response.statusText}`);
}
} catch (err) {
console.error("Error updating chat:", err);
}
},
[token, search_space_id]
);
return {
updateChat,
};
}