mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02: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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue