mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-11 08:42:39 +02:00
clean up
This commit is contained in:
parent
776660f5e3
commit
62df67b93b
4 changed files with 5 additions and 179 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
import { atomWithMutation } from "jotai-tanstack-query";
|
import { atomWithMutation } from "jotai-tanstack-query";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import type { Chat } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
import type { Chat } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||||
import { deleteChat } from "@/lib/apis/chats.api";
|
|
||||||
import { chatApiService } from "@/lib/apis/chats-api.service";
|
import { chatApiService } from "@/lib/apis/chats-api.service";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { queryClient } from "@/lib/query-client/client";
|
import { queryClient } from "@/lib/query-client/client";
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { atomWithQuery } from "jotai-tanstack-query";
|
||||||
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
||||||
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
|
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
|
||||||
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/seach-space-queries.atom";
|
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/seach-space-queries.atom";
|
||||||
import { fetchChatDetails, fetchChatsBySearchSpace } from "@/lib/apis/chats.api";
|
|
||||||
import { chatApiService } from "@/lib/apis/chats-api.service";
|
import { chatApiService } from "@/lib/apis/chats-api.service";
|
||||||
import { getPodcastByChatId } from "@/lib/apis/podcasts.api";
|
import { getPodcastByChatId } from "@/lib/apis/podcasts.api";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect } from "react";
|
||||||
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
import { activeChatAtom, activeChatIdAtom } from "@/atoms/chats/chat-querie.atoms";
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
BreadcrumbItem,
|
BreadcrumbItem,
|
||||||
|
|
@ -13,7 +14,6 @@ import {
|
||||||
BreadcrumbSeparator,
|
BreadcrumbSeparator,
|
||||||
} from "@/components/ui/breadcrumb";
|
} from "@/components/ui/breadcrumb";
|
||||||
import { useSearchSpace } from "@/hooks/use-search-space";
|
import { useSearchSpace } from "@/hooks/use-search-space";
|
||||||
import { fetchChatDetails } from "@/lib/apis/chats.api";
|
|
||||||
|
|
||||||
interface BreadcrumbItemInterface {
|
interface BreadcrumbItemInterface {
|
||||||
label: string;
|
label: string;
|
||||||
|
|
@ -23,13 +23,10 @@ interface BreadcrumbItemInterface {
|
||||||
export function DashboardBreadcrumb() {
|
export function DashboardBreadcrumb() {
|
||||||
const t = useTranslations("breadcrumb");
|
const t = useTranslations("breadcrumb");
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [chatDetails, setChatDetails] = useState<ChatDetails | null>(null);
|
const { data: activeChatState } = useAtomValue(activeChatAtom);
|
||||||
|
|
||||||
// Extract search space ID and chat ID from pathname
|
// Extract search space ID and chat ID from pathname
|
||||||
const segments = pathname.split("/").filter(Boolean);
|
const segments = pathname.split("/").filter(Boolean);
|
||||||
const searchSpaceId = segments[0] === "dashboard" && segments[1] ? segments[1] : null;
|
const searchSpaceId = segments[0] === "dashboard" && segments[1] ? segments[1] : null;
|
||||||
const chatId =
|
|
||||||
segments[0] === "dashboard" && segments[2] === "researcher" && segments[3] ? segments[3] : null;
|
|
||||||
|
|
||||||
// Fetch search space details if we have an ID
|
// Fetch search space details if we have an ID
|
||||||
const { searchSpace } = useSearchSpace({
|
const { searchSpace } = useSearchSpace({
|
||||||
|
|
@ -37,18 +34,6 @@ export function DashboardBreadcrumb() {
|
||||||
autoFetch: !!searchSpaceId,
|
autoFetch: !!searchSpaceId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch chat details if we have a chat ID
|
|
||||||
useEffect(() => {
|
|
||||||
if (chatId) {
|
|
||||||
const token = localStorage.getItem("surfsense_bearer_token");
|
|
||||||
if (token) {
|
|
||||||
fetchChatDetails(chatId, token).then(setChatDetails);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setChatDetails(null);
|
|
||||||
}
|
|
||||||
}, [chatId]);
|
|
||||||
|
|
||||||
// Parse the pathname to create breadcrumb items
|
// Parse the pathname to create breadcrumb items
|
||||||
const generateBreadcrumbs = (path: string): BreadcrumbItemInterface[] => {
|
const generateBreadcrumbs = (path: string): BreadcrumbItemInterface[] => {
|
||||||
const segments = path.split("/").filter(Boolean);
|
const segments = path.split("/").filter(Boolean);
|
||||||
|
|
@ -125,7 +110,7 @@ export function DashboardBreadcrumb() {
|
||||||
// Handle researcher sub-sections (chat IDs)
|
// Handle researcher sub-sections (chat IDs)
|
||||||
if (section === "researcher") {
|
if (section === "researcher") {
|
||||||
// Use the actual chat title if available, otherwise fall back to the ID
|
// Use the actual chat title if available, otherwise fall back to the ID
|
||||||
const chatLabel = chatDetails?.title || subSection;
|
const chatLabel = activeChatState?.chatDetails?.title || subSection;
|
||||||
breadcrumbs.push({
|
breadcrumbs.push({
|
||||||
label: t("researcher"),
|
label: t("researcher"),
|
||||||
href: `/dashboard/${segments[1]}/researcher`,
|
href: `/dashboard/${segments[1]}/researcher`,
|
||||||
|
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
import type { Message } from "@ai-sdk/react";
|
|
||||||
import type { Chat, ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
|
|
||||||
import type { ResearchMode } from "@/components/chat/types";
|
|
||||||
|
|
||||||
export const fetchChatDetails = async (
|
|
||||||
chatId: string,
|
|
||||||
authToken: string
|
|
||||||
): Promise<ChatDetails | null> => {
|
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const fetchChatsBySearchSpace = async (
|
|
||||||
searchSpaceId: string,
|
|
||||||
authToken: string
|
|
||||||
): Promise<ChatDetails[] | null> => {
|
|
||||||
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();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteChat = async (chatId: number, authToken: string) => {
|
|
||||||
const response = await fetch(
|
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${chatId}`,
|
|
||||||
{
|
|
||||||
method: "DELETE",
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to delete chat: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createChat = async (
|
|
||||||
initialMessage: string,
|
|
||||||
researchMode: ResearchMode,
|
|
||||||
selectedConnectors: string[],
|
|
||||||
authToken: string,
|
|
||||||
searchSpaceId: number
|
|
||||||
): Promise<Chat | null> => {
|
|
||||||
const response = await fetch(`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
type: researchMode,
|
|
||||||
title: "Untitled Chat",
|
|
||||||
initial_connectors: selectedConnectors,
|
|
||||||
messages: [
|
|
||||||
{
|
|
||||||
role: "user",
|
|
||||||
content: initialMessage,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
search_space_id: searchSpaceId,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to create chat: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateChat = async (
|
|
||||||
chatId: string,
|
|
||||||
messages: Message[],
|
|
||||||
researchMode: ResearchMode,
|
|
||||||
selectedConnectors: string[],
|
|
||||||
authToken: string,
|
|
||||||
searchSpaceId: number
|
|
||||||
) => {
|
|
||||||
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 ${authToken}`,
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
type: researchMode,
|
|
||||||
title: title,
|
|
||||||
initial_connectors: selectedConnectors,
|
|
||||||
messages: messages,
|
|
||||||
search_space_id: searchSpaceId,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to update chat: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const fetchChats = async (
|
|
||||||
searchSpaceId: string,
|
|
||||||
limit: number,
|
|
||||||
skip: number,
|
|
||||||
authToken: string
|
|
||||||
) => {
|
|
||||||
const response = await fetch(
|
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats?limit=${limit}&skip=${skip}&search_space_id=${searchSpaceId}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
method: "GET",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch chats: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
};
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue