mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
replace imperative fetch with tanstak
This commit is contained in:
parent
373bd668f7
commit
ff73272da5
2 changed files with 1 additions and 60 deletions
|
|
@ -8,7 +8,7 @@ import { createChatMutationAtom, updateChatMutationAtom } from "@/atoms/chats/ch
|
||||||
import { activeChatAtom } from "@/atoms/chats/chat-query.atoms";
|
import { activeChatAtom } from "@/atoms/chats/chat-query.atoms";
|
||||||
import { activeChatIdAtom } from "@/atoms/chats/ui.atoms";
|
import { activeChatIdAtom } from "@/atoms/chats/ui.atoms";
|
||||||
import ChatInterface from "@/components/chat/ChatInterface";
|
import ChatInterface from "@/components/chat/ChatInterface";
|
||||||
import { useChatAPI, useChatState } from "@/hooks/use-chat";
|
import { useChatState } from "@/hooks/use-chat";
|
||||||
import { useDocumentTypes } from "@/hooks/use-document-types";
|
import { useDocumentTypes } from "@/hooks/use-document-types";
|
||||||
import type { Document } from "@/hooks/use-documents";
|
import type { Document } from "@/hooks/use-documents";
|
||||||
import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors";
|
import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors";
|
||||||
|
|
@ -44,11 +44,6 @@ export default function ResearcherPage() {
|
||||||
chat_id: activeChatId ?? undefined,
|
chat_id: activeChatId ?? undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// const { updateChat } = useChatAPI({
|
|
||||||
// token,
|
|
||||||
// search_space_id: search_space_id as string,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Fetch all available sources (document types + live search connectors)
|
// Fetch all available sources (document types + live search connectors)
|
||||||
const { documentTypes } = useDocumentTypes(Number(search_space_id));
|
const { documentTypes } = useDocumentTypes(Number(search_space_id));
|
||||||
const { connectors: searchConnectors } = useSearchSourceConnectors(
|
const { connectors: searchConnectors } = useSearchSourceConnectors(
|
||||||
|
|
|
||||||
|
|
@ -45,57 +45,3 @@ export function useChatState({ chat_id }: UseChatStateProps) {
|
||||||
setTopK,
|
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue