mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
add update chat mutation atom
This commit is contained in:
parent
684589fc19
commit
373bd668f7
2 changed files with 23 additions and 22 deletions
|
|
@ -4,7 +4,7 @@ import { type CreateMessage, type Message, useChat } from "@ai-sdk/react";
|
|||
import { useAtomValue } from "jotai";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import { createChatMutationAtom } from "@/atoms/chats/chat-mutation.atoms";
|
||||
import { createChatMutationAtom, updateChatMutationAtom } from "@/atoms/chats/chat-mutation.atoms";
|
||||
import { activeChatAtom } from "@/atoms/chats/chat-query.atoms";
|
||||
import { activeChatIdAtom } from "@/atoms/chats/ui.atoms";
|
||||
import ChatInterface from "@/components/chat/ChatInterface";
|
||||
|
|
@ -19,11 +19,8 @@ export default function ResearcherPage() {
|
|||
const hasSetInitialConnectors = useRef(false);
|
||||
const activeChatId = useAtomValue(activeChatIdAtom);
|
||||
const { data: activeChatState, isFetching: isChatLoading } = useAtomValue(activeChatAtom);
|
||||
const {
|
||||
mutateAsync: createChat,
|
||||
isPending: isCreatingChat,
|
||||
error: createChatError,
|
||||
} = useAtomValue(createChatMutationAtom);
|
||||
const { mutateAsync: createChat } = useAtomValue(createChatMutationAtom);
|
||||
const { mutateAsync: updateChat } = useAtomValue(updateChatMutationAtom);
|
||||
const isNewChat = !activeChatId;
|
||||
|
||||
// Reset the flag when chat ID changes
|
||||
|
|
@ -47,10 +44,10 @@ export default function ResearcherPage() {
|
|||
chat_id: activeChatId ?? undefined,
|
||||
});
|
||||
|
||||
const { updateChat } = useChatAPI({
|
||||
token,
|
||||
search_space_id: search_space_id as string,
|
||||
});
|
||||
// const { updateChat } = useChatAPI({
|
||||
// token,
|
||||
// search_space_id: search_space_id as string,
|
||||
// });
|
||||
|
||||
// Fetch all available sources (document types + live search connectors)
|
||||
const { documentTypes } = useDocumentTypes(Number(search_space_id));
|
||||
|
|
@ -245,7 +242,18 @@ export default function ResearcherPage() {
|
|||
handler.messages.length > 0 &&
|
||||
handler.messages[handler.messages.length - 1]?.role === "assistant"
|
||||
) {
|
||||
updateChat(activeChatId, handler.messages, researchMode, selectedConnectors);
|
||||
const userMessages = handler.messages.filter((msg) => msg.role === "user");
|
||||
if (userMessages.length === 0) return;
|
||||
const title = userMessages[0].content;
|
||||
|
||||
updateChat({
|
||||
type: researchMode,
|
||||
title: title,
|
||||
initial_connectors: selectedConnectors,
|
||||
messages: handler.messages,
|
||||
search_space_id: Number(search_space_id),
|
||||
id: Number(activeChatId),
|
||||
});
|
||||
}
|
||||
}, [handler.messages, handler.status, activeChatId, isNewChat, isChatLoading]);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,17 +34,10 @@ export const deleteChatResponse = z.object({
|
|||
|
||||
export const deleteChatRequest = chatSummary.pick({ id: true });
|
||||
|
||||
export const createChatRequest = z.object({
|
||||
type: chatTypeEnum,
|
||||
title: z.string(),
|
||||
initial_connectors: z.array(z.string()),
|
||||
messages: z.array(
|
||||
z.object({
|
||||
role: z.enum(["user", "assistant"]),
|
||||
content: z.string(),
|
||||
})
|
||||
),
|
||||
search_space_id: z.number(),
|
||||
export const createChatRequest = chatDetails.omit({
|
||||
created_at: true,
|
||||
id: true,
|
||||
state_version: true,
|
||||
});
|
||||
|
||||
export const updateChatRequest = chatDetails.omit({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue