mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-02 02:29:08 +00:00
Replacing researcher chat components with new chat page and components
This commit is contained in:
parent
96d9ee68a3
commit
1dd373a700
12 changed files with 10 additions and 2658 deletions
|
@ -4,11 +4,11 @@ import { type CreateMessage, type Message, useChat } from "@ai-sdk/react";
|
|||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import type { ResearchMode } from "@/components/chat";
|
||||
import ChatInterface from "@/components/chat_v2/ChatInterface";
|
||||
import ChatInterface from "@/components/chat/ChatInterface";
|
||||
import type { Document } from "@/hooks/use-documents";
|
||||
import { useChatAPI, useChatState } from "@/hooks/useChat";
|
||||
|
||||
export default function ResearchChatPageV2() {
|
||||
export default function ResearcherPage() {
|
||||
const { search_space_id, chat_id } = useParams();
|
||||
const router = useRouter();
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,80 +0,0 @@
|
|||
"use client";
|
||||
import React, { useEffect } from 'react';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
|
||||
const ResearcherPage = () => {
|
||||
const router = useRouter();
|
||||
const { search_space_id } = useParams();
|
||||
const [isCreating, setIsCreating] = React.useState(true);
|
||||
const [error, setError] = React.useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const createChat = async () => {
|
||||
try {
|
||||
// Get token from localStorage
|
||||
const token = localStorage.getItem('surfsense_bearer_token');
|
||||
|
||||
if (!token) {
|
||||
setError('Authentication token not found');
|
||||
setIsCreating(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new chat
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: "QNA",
|
||||
title: "Untitled Chat", // Empty title initially
|
||||
initial_connectors: [], // No default connectors
|
||||
messages: [],
|
||||
search_space_id: Number(search_space_id)
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to create chat: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Redirect to the new chat page
|
||||
router.push(`/dashboard/${search_space_id}/researcher/${data.id}`);
|
||||
} catch (err) {
|
||||
console.error('Error creating chat:', err);
|
||||
setError(err instanceof Error ? err.message : 'Failed to create chat');
|
||||
setIsCreating(false);
|
||||
}
|
||||
};
|
||||
|
||||
createChat();
|
||||
}, [search_space_id, router]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[calc(100vh-4rem)]">
|
||||
<div className="text-red-500 mb-4">Error: {error}</div>
|
||||
<button
|
||||
onClick={() => location.reload()}
|
||||
className="px-4 py-2 bg-primary text-white rounded-md"
|
||||
>
|
||||
Try Again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[calc(100vh-4rem)]">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-primary mb-4" />
|
||||
<p className="text-muted-foreground">Creating new research chat...</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ResearcherPage;
|
|
@ -22,7 +22,7 @@ import { Badge } from "@/components/ui/badge";
|
|||
import { Suspense, useState, useCallback } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useDocuments, Document } from "@/hooks/use-documents";
|
||||
import { DocumentsDataTable } from "@/components/chat_v2/DocumentsDataTable";
|
||||
import { DocumentsDataTable } from "@/components/chat/DocumentsDataTable";
|
||||
import { useSearchSourceConnectors } from "@/hooks/useSearchSourceConnectors";
|
||||
import {
|
||||
getConnectorIcon,
|
|
@ -6,9 +6,9 @@ import {
|
|||
ChatHandler,
|
||||
} from "@llamaindex/chat-ui";
|
||||
import { Document } from "@/hooks/use-documents";
|
||||
import { ChatInputUI } from "@/components/chat_v2/ChatInputGroup";
|
||||
import { ChatInputUI } from "@/components/chat/ChatInputGroup";
|
||||
import { ResearchMode } from "@/components/chat";
|
||||
import { ChatMessagesUI } from "@/components/chat_v2/ChatMessages";
|
||||
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
|
||||
|
||||
interface ChatInterfaceProps {
|
||||
handler: ChatHandler;
|
|
@ -7,16 +7,17 @@ import {
|
|||
Message,
|
||||
useChatUI,
|
||||
} from "@llamaindex/chat-ui";
|
||||
import TerminalDisplay from "@/components/chat_v2/ChatTerminal";
|
||||
import ChatSourcesDisplay from "@/components/chat_v2/ChatSources";
|
||||
import { CitationDisplay } from "@/components/chat_v2/ChatCitation";
|
||||
import { ChatFurtherQuestions } from "@/components/chat_v2/ChatFurtherQuestions";
|
||||
import TerminalDisplay from "@/components/chat/ChatTerminal";
|
||||
import ChatSourcesDisplay from "@/components/chat/ChatSources";
|
||||
import { CitationDisplay } from "@/components/chat/ChatCitation";
|
||||
import { ChatFurtherQuestions } from "@/components/chat/ChatFurtherQuestions";
|
||||
|
||||
export function ChatMessagesUI() {
|
||||
const { messages } = useChatUI();
|
||||
|
||||
return (
|
||||
<LlamaIndexChatMessages className="flex-1">
|
||||
<LlamaIndexChatMessages.Empty heading="Welcome to Surfsense!" subheading="Ask me anything from your documents" />
|
||||
<LlamaIndexChatMessages.List className="p-4">
|
||||
{messages.map((message, index) => (
|
||||
<ChatMessageUI
|
|
@ -1,23 +0,0 @@
|
|||
// Connector sources
|
||||
export const connectorSourcesMenu = [
|
||||
{
|
||||
id: 1,
|
||||
name: "Crawled URL",
|
||||
type: "CRAWLED_URL",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "File",
|
||||
type: "FILE",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Extension",
|
||||
type: "EXTENSION",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "Youtube Video",
|
||||
type: "YOUTUBE_VIDEO",
|
||||
}
|
||||
];
|
Loading…
Add table
Reference in a new issue