Use userSessionId for chat history
This commit is contained in:
parent
27e6f5b9e1
commit
1eee511aac
5 changed files with 30 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import crypto from 'crypto';
|
||||
import DeleteChat from '@/components/DeleteChat';
|
||||
import { formatTimeDifference } from '@/lib/utils';
|
||||
import { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react';
|
||||
|
|
@ -21,10 +22,17 @@ const Page = () => {
|
|||
const fetchChats = async () => {
|
||||
setLoading(true);
|
||||
|
||||
let userSessionId = localStorage.getItem('userSessionId');
|
||||
if (!userSessionId) {
|
||||
userSessionId = crypto.randomBytes(20).toString('hex');
|
||||
localStorage.setItem('userSessionId', userSessionId)
|
||||
}
|
||||
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chats`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'user-session-id': userSessionId!,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ const useSocket = (
|
|||
'embeddingModelProvider',
|
||||
);
|
||||
|
||||
let userSessionId = localStorage.getItem('userSessionId');
|
||||
if (!userSessionId) {
|
||||
userSessionId = crypto.randomBytes(20).toString('hex');
|
||||
localStorage.setItem('userSessionId', userSessionId!)
|
||||
}
|
||||
|
||||
if (
|
||||
!chatModel ||
|
||||
!chatModelProvider ||
|
||||
|
|
@ -324,6 +330,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||
let added = false;
|
||||
|
||||
const messageId = crypto.randomBytes(7).toString('hex');
|
||||
let userSessionId = localStorage.getItem('userSessionId');
|
||||
|
||||
ws?.send(
|
||||
JSON.stringify({
|
||||
|
|
@ -331,6 +338,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||
message: {
|
||||
chatId: chatId!,
|
||||
content: message,
|
||||
userSessionId: userSessionId,
|
||||
},
|
||||
focusMode: focusMode,
|
||||
history: [...chatHistory, ['human', message]],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue