mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-10 20:35:17 +02:00
add active search space chats atom with query
This commit is contained in:
parent
9567a3ce23
commit
93f6056a91
10 changed files with 81 additions and 29 deletions
|
|
@ -17,8 +17,8 @@ import { Separator } from "@/components/ui/separator";
|
|||
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
|
||||
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { activeChatIdAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chat/chat-ui.atom";
|
||||
import { activeChatIdAtom } from "@/stores/chats/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
||||
|
||||
export function DashboardClientLayout({
|
||||
children,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { useEffect } from "react";
|
|||
import { ChatInputUI } from "@/components/chat/ChatInputGroup";
|
||||
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
|
||||
import type { Document } from "@/hooks/use-documents";
|
||||
import { activeChatIdAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { activeChatIdAtom } from "@/stores/chats/active-chat.atom";
|
||||
import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer";
|
||||
|
||||
interface ChatInterfaceProps {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import { LoaderIcon, PanelRight, TriangleAlert } from "lucide-react";
|
|||
import { toast } from "sonner";
|
||||
import { generatePodcast } from "@/lib/apis/podcast-apis";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { activeChatAtom, activeChatIdAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chat/chat-ui.atom";
|
||||
import { activeChatAtom, activeChatIdAtom } from "@/stores/chats/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
||||
import { ChatPanelView } from "./ChatPanelView";
|
||||
|
||||
export interface GeneratePodcastRequest {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import { AlertCircle, Play, RefreshCw, Sparkles } from "lucide-react";
|
|||
import { motion } from "motion/react";
|
||||
import { useCallback } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { activeChatAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chat/chat-ui.atom";
|
||||
import { activeChatAtom } from "@/stores/chats/active-chat.atom";
|
||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
||||
import { getPodcastStalenessMessage, isPodcastStale } from "../PodcastUtils";
|
||||
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||
import { ConfigModal } from "./ConfigModal";
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { useAtomValue } from "jotai";
|
|||
import { Pencil } from "lucide-react";
|
||||
import { useCallback, useContext, useState } from "react";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { activeChatAtom } from "@/stores/chat/active-chat.atom";
|
||||
import { activeChatAtom } from "@/stores/chats/active-chat.atom";
|
||||
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||
|
||||
interface ConfigModalProps {
|
||||
|
|
|
|||
|
|
@ -1,28 +1,56 @@
|
|||
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||
|
||||
export const fetchChatDetails = async (
|
||||
chatId: string,
|
||||
authToken: string
|
||||
chatId: string,
|
||||
authToken: string
|
||||
): Promise<ChatDetails | null> => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${Number(chatId)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${Number(
|
||||
chatId
|
||||
)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch chat details: ${response.statusText}`);
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch chat details: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error("Error fetching chat details:", err);
|
||||
return null;
|
||||
}
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error("Error fetching chat details:", err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchChatsBySearchSpace = async (
|
||||
searchSpaceId: string,
|
||||
authToken: string
|
||||
): Promise<ChatDetails[] | null> => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats?search_space_id=${searchSpaceId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch chats: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error("Error fetching chats:", err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export const cacheKeys = {
|
||||
activeChat: (chatId: string) => ["activeChat", chatId],
|
||||
activeSearchSpaceChats: (searchSpaceId: string) => ["activeSearchSpaceChats", searchSpaceId],
|
||||
};
|
||||
|
|
|
|||
23
surfsense_web/stores/chats/active-search-space-chats.atom.ts
Normal file
23
surfsense_web/stores/chats/active-search-space-chats.atom.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import { fetchChatsBySearchSpace } from "@/lib/apis/chat-apis";
|
||||
import { activeSearchSpaceIdAtom } from "../seach-space/active-seach-space.atom";
|
||||
|
||||
export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
const authToken = localStorage.getItem("surfsense_bearer_token");
|
||||
|
||||
return {
|
||||
queryKey: ["chatsBySearchSpace", searchSpaceId],
|
||||
enabled: !!searchSpaceId && !!authToken,
|
||||
queryFn: async () => {
|
||||
if (!authToken) {
|
||||
throw new Error("No authentication token found");
|
||||
}
|
||||
if (!searchSpaceId) {
|
||||
throw new Error("No search space id found");
|
||||
}
|
||||
|
||||
return fetchChatsBySearchSpace(searchSpaceId, authToken);
|
||||
},
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue