From e023e5bc441965396732092fc3f55b710e2c7259 Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 15:10:15 -1000 Subject: [PATCH 01/17] change default theme to light --- ui/components/theme/Provider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/components/theme/Provider.tsx b/ui/components/theme/Provider.tsx index 43e2714..a02f08d 100644 --- a/ui/components/theme/Provider.tsx +++ b/ui/components/theme/Provider.tsx @@ -7,7 +7,7 @@ const ThemeProviderComponent = ({ children: React.ReactNode; }) => { return ( - + {children} ); From ee659d9e13fa193f8ec8b52ef5bccefddaef57bf Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 15:13:27 -1000 Subject: [PATCH 02/17] add mcId --- ui/components/ChatWindow.tsx | 63 +++++++++++++++++++++++++++--------- ui/lib/mcid.ts | 38 ++++++++++++++++++++++ 2 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 ui/lib/mcid.ts diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index b26573f..f37375c 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -1,17 +1,18 @@ 'use client'; -import { useEffect, useRef, useState } from 'react'; -import { Document } from '@langchain/core/documents'; +import {useEffect, useRef, useState} from 'react'; +import {Document} from '@langchain/core/documents'; import Navbar from './Navbar'; import Chat from './Chat'; import EmptyChat from './EmptyChat'; import crypto from 'crypto'; -import { toast } from 'sonner'; -import { useSearchParams } from 'next/navigation'; -import { getSuggestions } from '@/lib/actions'; -import { Settings } from 'lucide-react'; +import {toast} from 'sonner'; +import {useSearchParams} from 'next/navigation'; +import {getSuggestions} from '@/lib/actions'; +import {Settings} from 'lucide-react'; import SettingsDialog from './SettingsDialog'; import NextError from 'next/error'; +import {Mcid} from "@/lib/mcid"; export type Message = { messageId: string; @@ -140,7 +141,7 @@ const useSocket = ( if ( Object.keys(chatModelProviders).length > 0 && (((!openAIBaseURL || !openAIPIKey) && - chatModelProvider === 'custom_openai') || + chatModelProvider === 'custom_openai') || !chatModelProviders[chatModelProvider]) ) { const chatModelProvidersKeys = Object.keys(chatModelProviders); @@ -173,7 +174,7 @@ const useSocket = ( Object.keys(chatModelProviders[chatModelProvider]).length > 0 ? chatModelProvider : Object.keys(chatModelProviders)[0] - ], + ], )[0]; localStorage.setItem('chatModel', chatModel); } @@ -382,10 +383,10 @@ const loadMessages = async ( setIsMessagesLoaded(true); }; -const ChatWindow = ({ id }: { id?: string }) => { +const ChatWindow = ({id}: { id?: string }) => { const searchParams = useSearchParams(); const initialMessage = searchParams.get('q'); - + const [userId, setUserId] = useState(); const [chatId, setChatId] = useState(id); const [newChatCreated, setNewChatCreated] = useState(false); @@ -417,6 +418,36 @@ const ChatWindow = ({ id }: { id?: string }) => { const [isSettingsOpen, setIsSettingsOpen] = useState(false); + useEffect(() => { + const initializeUserId = () => { + try { + // 从 localStorage 读取现有用户 ID + const storedUserId = localStorage.getItem('userId'); + + if (storedUserId) { + setUserId(storedUserId); + console.debug('Using existing user ID:', storedUserId); + } else { + // 生成新的 MCID + const newUserId = new Mcid().generate().toString(); // 转换为字符串 + + // 存储到 localStorage + localStorage.setItem('userId', newUserId); + setUserId(newUserId); + console.debug('Generated new user ID:', newUserId); + } + } catch (error) { + console.error('Error initializing user ID:', error); + // 生成随机 ID 作为 fallback + const fallbackId = crypto.randomBytes(20).toString('hex'); + localStorage.setItem('userId', fallbackId); + setUserId(fallbackId); + } + }; + + initializeUserId(); + }, []); // 空依赖数组确保只运行一次 + useEffect(() => { if ( chatId && @@ -465,7 +496,7 @@ const ChatWindow = ({ id }: { id?: string }) => { } else { setIsReady(false); } - }, [isMessagesLoaded, isWSReady]); + }, [isMessagesLoaded, isWSReady, userId]); const sendMessage = async (message: string, messageId?: string) => { if (loading) return; @@ -556,7 +587,7 @@ const ChatWindow = ({ id }: { id?: string }) => { setMessages((prev) => prev.map((message) => { if (message.messageId === data.messageId) { - return { ...message, content: message.content + data.data }; + return {...message, content: message.content + data.data}; } return message; @@ -589,7 +620,7 @@ const ChatWindow = ({ id }: { id?: string }) => { setMessages((prev) => prev.map((msg) => { if (msg.messageId === lastMsg.messageId) { - return { ...msg, suggestions: suggestions }; + return {...msg, suggestions: suggestions}; } return msg; }), @@ -639,19 +670,19 @@ const ChatWindow = ({ id }: { id?: string }) => { Failed to connect to the server. Please try again later.

- + ); } return isReady ? ( notFound ? ( - + ) : (
{messages.length > 0 ? ( <> - + 255) { + throw new Error('Machine ID must be between 0 and 255'); + } + } + + generate(): number { + let now = Date.now(); + + if (now < this.lastTimestamp) { + throw new Error('Clock moved backwards'); + } + + if (now === this.lastTimestamp) { + this.sequence = (this.sequence + 1) & 0xf; + if (this.sequence === 0) { + while (now <= this.lastTimestamp) { + now = Date.now(); + } + } + } else { + this.sequence = 0; + } + + this.lastTimestamp = now; + + return ( + (now * 0x1000) + // 时间戳左移 12 位 + (this.machineId * 16) + // 机器 ID 左移 4 位 + this.sequence // 序列号 + ); + } +} From 1a8f59e92b4b0d20806e9aae3f4f8c934608ecbd Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 15:38:24 -1000 Subject: [PATCH 03/17] add userId --- ui/components/ChatWindow.tsx | 8 ++++++-- ui/components/EmptyChat.tsx | 6 ++++++ ui/components/EmptyChatMessageInput.tsx | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index f37375c..2e0505c 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -411,6 +411,7 @@ const ChatWindow = ({id}: { id?: string }) => { const [focusMode, setFocusMode] = useState('webSearch'); const [optimizationMode, setOptimizationMode] = useState('speed'); + const [copilotEnabled, setCopilotEnabled] = useState(true); const [isMessagesLoaded, setIsMessagesLoaded] = useState(false); @@ -468,7 +469,7 @@ const ChatWindow = ({id}: { id?: string }) => { } else if (!chatId) { setNewChatCreated(true); setIsMessagesLoaded(true); - setChatId(crypto.randomBytes(20).toString('hex')); + setChatId(new Mcid().generate().toString()); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -512,11 +513,12 @@ const ChatWindow = ({id}: { id?: string }) => { let recievedMessage = ''; let added = false; - messageId = messageId ?? crypto.randomBytes(7).toString('hex'); + messageId = messageId ?? new Mcid().generate().toString(); ws.send( JSON.stringify({ type: 'message', + useerId:userId, message: { messageId: messageId, chatId: chatId!, @@ -699,6 +701,8 @@ const ChatWindow = ({id}: { id?: string }) => { void; focusMode: string; setFocusMode: (mode: string) => void; + copilotEnabled: boolean; + setCopilotEnabled: (enabled: boolean) => void; optimizationMode: string; setOptimizationMode: (mode: string) => void; fileIds: string[]; @@ -44,6 +48,8 @@ const EmptyChat = ({ sendMessage={sendMessage} focusMode={focusMode} setFocusMode={setFocusMode} + copilotEnabled={copilotEnabled} + setCopilotEnabled={setCopilotEnabled} optimizationMode={optimizationMode} setOptimizationMode={setOptimizationMode} fileIds={fileIds} diff --git a/ui/components/EmptyChatMessageInput.tsx b/ui/components/EmptyChatMessageInput.tsx index 43d1e28..195b8d3 100644 --- a/ui/components/EmptyChatMessageInput.tsx +++ b/ui/components/EmptyChatMessageInput.tsx @@ -11,6 +11,8 @@ const EmptyChatMessageInput = ({ sendMessage, focusMode, setFocusMode, + copilotEnabled, + setCopilotEnabled, optimizationMode, setOptimizationMode, fileIds, @@ -23,12 +25,13 @@ const EmptyChatMessageInput = ({ setFocusMode: (mode: string) => void; optimizationMode: string; setOptimizationMode: (mode: string) => void; + copilotEnabled:boolean + setCopilotEnabled:(mode: boolean) => void; fileIds: string[]; setFileIds: (fileIds: string[]) => void; files: File[]; setFiles: (files: File[]) => void; }) => { - const [copilotEnabled, setCopilotEnabled] = useState(false); const [message, setMessage] = useState(''); const inputRef = useRef(null); @@ -94,6 +97,7 @@ const EmptyChatMessageInput = ({ />
+ Date: Sun, 2 Feb 2025 15:42:08 -1000 Subject: [PATCH 04/17] update fallbackId --- ui/components/ChatWindow.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 2e0505c..1be4ec5 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -429,25 +429,22 @@ const ChatWindow = ({id}: { id?: string }) => { setUserId(storedUserId); console.debug('Using existing user ID:', storedUserId); } else { - // 生成新的 MCID const newUserId = new Mcid().generate().toString(); // 转换为字符串 - // 存储到 localStorage localStorage.setItem('userId', newUserId); setUserId(newUserId); console.debug('Generated new user ID:', newUserId); } } catch (error) { console.error('Error initializing user ID:', error); - // 生成随机 ID 作为 fallback - const fallbackId = crypto.randomBytes(20).toString('hex'); + const fallbackId = "1234567890"; localStorage.setItem('userId', fallbackId); setUserId(fallbackId); } }; initializeUserId(); - }, []); // 空依赖数组确保只运行一次 + }, []); useEffect(() => { if ( From 969f01e2757527a650a5c75a828726b5f91ec3c5 Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 16:04:59 -1000 Subject: [PATCH 05/17] crrect userId --- ui/components/ChatWindow.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 1be4ec5..8e18b03 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -515,7 +515,7 @@ const ChatWindow = ({id}: { id?: string }) => { ws.send( JSON.stringify({ type: 'message', - useerId:userId, + userId:userId, message: { messageId: messageId, chatId: chatId!, @@ -523,6 +523,7 @@ const ChatWindow = ({id}: { id?: string }) => { }, files: fileIds, focusMode: focusMode, + copilotEnabled: copilotEnabled, optimizationMode: optimizationMode, history: [...chatHistory, ['human', message]], }), From 5f672eaa66f006dd903823c82c1758399391af72 Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 16:09:59 -1000 Subject: [PATCH 06/17] remove userId --- ui/components/ChatWindow.tsx | 2 +- ui/lib/mcid.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 8e18b03..95a81e8 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -429,7 +429,7 @@ const ChatWindow = ({id}: { id?: string }) => { setUserId(storedUserId); console.debug('Using existing user ID:', storedUserId); } else { - const newUserId = new Mcid().generate().toString(); // 转换为字符串 + const newUserId = new Mcid().generate().toString(); localStorage.setItem('userId', newUserId); setUserId(newUserId); diff --git a/ui/lib/mcid.ts b/ui/lib/mcid.ts index 1a0d0d3..77d7f65 100644 --- a/ui/lib/mcid.ts +++ b/ui/lib/mcid.ts @@ -30,9 +30,7 @@ export class Mcid { this.lastTimestamp = now; return ( - (now * 0x1000) + // 时间戳左移 12 位 - (this.machineId * 16) + // 机器 ID 左移 4 位 - this.sequence // 序列号 + (now * 0x1000) + (this.machineId * 16) + this.sequence ); } } From 7733b663d437a3ec478a94813afdf75a8434f1bc Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 16:38:57 -1000 Subject: [PATCH 07/17] add math and translator --- ui/components/EmptyChatMessageInput.tsx | 4 +-- ui/components/MessageInputActions/Focus.tsx | 31 +++++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ui/components/EmptyChatMessageInput.tsx b/ui/components/EmptyChatMessageInput.tsx index 195b8d3..efa0fd8 100644 --- a/ui/components/EmptyChatMessageInput.tsx +++ b/ui/components/EmptyChatMessageInput.tsx @@ -11,8 +11,8 @@ const EmptyChatMessageInput = ({ sendMessage, focusMode, setFocusMode, - copilotEnabled, - setCopilotEnabled, + copilotEnabled, + setCopilotEnabled, optimizationMode, setOptimizationMode, fileIds, diff --git a/ui/components/MessageInputActions/Focus.tsx b/ui/components/MessageInputActions/Focus.tsx index 613078b..b72e19f 100644 --- a/ui/components/MessageInputActions/Focus.tsx +++ b/ui/components/MessageInputActions/Focus.tsx @@ -1,5 +1,5 @@ import { - BadgePercent, + BadgePercent, Calculator, ChevronDown, Globe, Pencil, @@ -13,7 +13,7 @@ import { PopoverPanel, Transition, } from '@headlessui/react'; -import { SiReddit, SiYoutube } from '@icons-pack/react-simple-icons'; +import {SiGoogletranslate, SiReddit, SiYoutube} from '@icons-pack/react-simple-icons'; import { Fragment } from 'react'; const focusModes = [ @@ -29,6 +29,12 @@ const focusModes = [ description: 'Search in published academic papers', icon: , }, + { + key: 'wolframAlphaSearch', + title: 'Wolfram Alpha', + description: 'Computational knowledge engine', + icon: , + }, { key: 'writingAssistant', title: 'Writing', @@ -36,11 +42,24 @@ const focusModes = [ icon: , }, { - key: 'wolframAlphaSearch', - title: 'Wolfram Alpha', - description: 'Computational knowledge engine', - icon: , + key: 'mathAssistant', + title: 'Math', + description: 'Chat without searching the web', + icon: , }, + { + key: 'translator', + title: 'Trasnlator', + description: 'Chat without searching the web', + icon: ( + + ), + }, + { key: 'youtubeSearch', title: 'Youtube', From 144bf81533cb20569f2d5e1f351eb6cdfb81fe18 Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 16:53:40 -1000 Subject: [PATCH 08/17] add DeepSeek --- ui/assets/DeepSeekIcon.tsx | 20 ++++++++++++++++++++ ui/assets/deepseek.svg | 1 + ui/components/MessageInputActions/Focus.tsx | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 ui/assets/DeepSeekIcon.tsx create mode 100644 ui/assets/deepseek.svg diff --git a/ui/assets/DeepSeekIcon.tsx b/ui/assets/DeepSeekIcon.tsx new file mode 100644 index 0000000..0c761db --- /dev/null +++ b/ui/assets/DeepSeekIcon.tsx @@ -0,0 +1,20 @@ +import React from 'react'; + +const DeepSeekIcon = (props: React.JSX.IntrinsicAttributes & React.SVGProps) => ( + + + +); + +export default DeepSeekIcon; diff --git a/ui/assets/deepseek.svg b/ui/assets/deepseek.svg new file mode 100644 index 0000000..3dcf249 --- /dev/null +++ b/ui/assets/deepseek.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ui/components/MessageInputActions/Focus.tsx b/ui/components/MessageInputActions/Focus.tsx index b72e19f..49f7641 100644 --- a/ui/components/MessageInputActions/Focus.tsx +++ b/ui/components/MessageInputActions/Focus.tsx @@ -15,6 +15,7 @@ import { } from '@headlessui/react'; import {SiGoogletranslate, SiReddit, SiYoutube} from '@icons-pack/react-simple-icons'; import { Fragment } from 'react'; +import DeepSeekIcon from "@/assets/DeepSeekIcon"; const focusModes = [ { @@ -84,6 +85,14 @@ const focusModes = [ /> ), }, + { + key: 'deepSeek', + title: 'DeepSeek', + description: 'Chat with DeepSeek', + icon: ( + + ), + }, ]; const Focus = ({ From 66b48146a345008d7fca29ed1b7f74aaaaa6a4cd Mon Sep 17 00:00:00 2001 From: litongjava Date: Sun, 2 Feb 2025 16:54:31 -1000 Subject: [PATCH 09/17] change to search --- ui/components/MessageInputActions/Focus.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/components/MessageInputActions/Focus.tsx b/ui/components/MessageInputActions/Focus.tsx index 49f7641..31c0f2f 100644 --- a/ui/components/MessageInputActions/Focus.tsx +++ b/ui/components/MessageInputActions/Focus.tsx @@ -20,7 +20,7 @@ import DeepSeekIcon from "@/assets/DeepSeekIcon"; const focusModes = [ { key: 'webSearch', - title: 'All', + title: 'Search', description: 'Searches across all of the internet', icon: , }, From 3558dc2ed28268e86f5e1fe549c039be3f321075 Mon Sep 17 00:00:00 2001 From: litongjava Date: Mon, 3 Feb 2025 00:17:55 -1000 Subject: [PATCH 10/17] fetch chats with userid --- ui/app/library/page.tsx | 20 ++++++++++---------- ui/components/ChatWindow.tsx | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/app/library/page.tsx b/ui/app/library/page.tsx index 379596c..76652c5 100644 --- a/ui/app/library/page.tsx +++ b/ui/app/library/page.tsx @@ -1,10 +1,10 @@ 'use client'; import DeleteChat from '@/components/DeleteChat'; -import { cn, formatTimeDifference } from '@/lib/utils'; -import { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react'; +import {cn, formatTimeDifference} from '@/lib/utils'; +import {BookOpenText, ClockIcon, Delete, ScanEye} from 'lucide-react'; import Link from 'next/link'; -import { useEffect, useState } from 'react'; +import {useEffect, useState} from 'react'; export interface Chat { id: string; @@ -20,8 +20,8 @@ const Page = () => { useEffect(() => { const fetchChats = async () => { setLoading(true); - - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chats`, { + let userId = localStorage.getItem("userId"); + const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chats?userId=` + userId, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -60,19 +60,19 @@ const Page = () => {
- +

Library

-
+
- {chats.length === 0 && ( + {chats && chats.length === 0 && (

No chats found.

)} - {chats.length > 0 && ( + {chats && chats.length > 0 && (
{chats.map((chat, i) => (
{
- +

{formatTimeDifference(new Date(), chat.createdAt)} Ago

diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 95a81e8..c4c4bd8 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -525,7 +525,7 @@ const ChatWindow = ({id}: { id?: string }) => { focusMode: focusMode, copilotEnabled: copilotEnabled, optimizationMode: optimizationMode, - history: [...chatHistory, ['human', message]], + history: [], }), ); From 311f0e08798ab85da836eb343ff6176f79eecf7f Mon Sep 17 00:00:00 2001 From: litongjava Date: Mon, 3 Feb 2025 01:27:27 -1000 Subject: [PATCH 11/17] fix bug: file --- ui/components/ChatWindow.tsx | 4 ++-- ui/components/MessageInputActions/AttachSmall.tsx | 2 +- ui/components/MessageInputActions/Focus.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index c4c4bd8..0707457 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -367,7 +367,7 @@ const loadMessages = async ( document.title = messages[0].content; - const files = data.chat.files.map((file: any) => { + const files = data.chat.files && data.chat.files.map((file: any) => { return { fileName: file.name, fileExtension: file.name.split('.').pop(), @@ -376,7 +376,7 @@ const loadMessages = async ( }); setFiles(files); - setFileIds(files.map((file: File) => file.fileId)); + setFileIds(files && files.map((file: File) => file.fileId)); setChatHistory(history); setFocusMode(data.chat.focusMode); diff --git a/ui/components/MessageInputActions/AttachSmall.tsx b/ui/components/MessageInputActions/AttachSmall.tsx index 3514a58..1bce1b9 100644 --- a/ui/components/MessageInputActions/AttachSmall.tsx +++ b/ui/components/MessageInputActions/AttachSmall.tsx @@ -55,7 +55,7 @@ const AttachSmall = ({
- ) : files.length > 0 ? ( + ) : files && files.length > 0 ? ( Date: Mon, 3 Feb 2025 08:48:19 -1000 Subject: [PATCH 12/17] feat: remove speed and show focus mode --- ui/app/page.tsx | 4 ++-- ui/components/EmptyChatMessageInput.tsx | 13 +++++++------ ui/components/MessageInputActions/Focus.tsx | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ui/app/page.tsx b/ui/app/page.tsx index e18aca9..9666183 100644 --- a/ui/app/page.tsx +++ b/ui/app/page.tsx @@ -3,8 +3,8 @@ import { Metadata } from 'next'; import { Suspense } from 'react'; export const metadata: Metadata = { - title: 'Chat - Perplexica', - description: 'Chat with the internet, chat with Perplexica.', + title: 'MyCounsellor Ai Serach Eengine - Searching Thking with Gemini', + description: 'Chat with the internet, chat with MyCounsellor.', }; const Home = () => { diff --git a/ui/components/EmptyChatMessageInput.tsx b/ui/components/EmptyChatMessageInput.tsx index efa0fd8..36be1c3 100644 --- a/ui/components/EmptyChatMessageInput.tsx +++ b/ui/components/EmptyChatMessageInput.tsx @@ -88,6 +88,8 @@ const EmptyChatMessageInput = ({
+
+
-
-
+ - + {/**/}
-
-

+
+

Research begins here.

Date: Mon, 3 Feb 2025 14:45:45 -1000 Subject: [PATCH 15/17] feat: show deepseek --- ui/components/MessageInputActions/Focus.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/components/MessageInputActions/Focus.tsx b/ui/components/MessageInputActions/Focus.tsx index 3ec0226..de4cece 100644 --- a/ui/components/MessageInputActions/Focus.tsx +++ b/ui/components/MessageInputActions/Focus.tsx @@ -133,7 +133,7 @@ const Focus = ({ leaveTo="opacity-0 translate-y-1" > -
+
{focusModes.map((mode, i) => ( setFocusMode(mode.key)} From 4dc5857b17fd0d1c0e4b3d622594e610ddc58495 Mon Sep 17 00:00:00 2001 From: litongjava Date: Mon, 3 Feb 2025 15:00:06 -1000 Subject: [PATCH 16/17] feat: add copilotEnabled and setCopilotEnabled to MesageInput --- ui/components/Chat.tsx | 6 ++++++ ui/components/ChatWindow.tsx | 2 ++ ui/components/MessageInput.tsx | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/components/Chat.tsx b/ui/components/Chat.tsx index 81aa32f..a3caf8a 100644 --- a/ui/components/Chat.tsx +++ b/ui/components/Chat.tsx @@ -16,6 +16,8 @@ const Chat = ({ setFileIds, files, setFiles, + copilotEnabled, + setCopilotEnabled, }: { messages: Message[]; sendMessage: (message: string) => void; @@ -26,6 +28,8 @@ const Chat = ({ setFileIds: (fileIds: string[]) => void; files: File[]; setFiles: (files: File[]) => void; + copilotEnabled:boolean + setCopilotEnabled:(mode: boolean) => void; }) => { const [dividerWidth, setDividerWidth] = useState(0); const dividerRef = useRef(null); @@ -93,6 +97,8 @@ const Chat = ({ setFileIds={setFileIds} files={files} setFiles={setFiles} + copilotEnabled={copilotEnabled} + setCopilotEnabled={setCopilotEnabled} />
)} diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index ec8e3e6..4808f49 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -704,6 +704,8 @@ const ChatWindow = ({id}: { id?: string }) => { setFileIds={setFileIds} files={files} setFiles={setFiles} + copilotEnabled={copilotEnabled} + setCopilotEnabled={setCopilotEnabled} /> ) : ( diff --git a/ui/components/MessageInput.tsx b/ui/components/MessageInput.tsx index b6b1d96..f1888c5 100644 --- a/ui/components/MessageInput.tsx +++ b/ui/components/MessageInput.tsx @@ -14,6 +14,8 @@ const MessageInput = ({ setFileIds, files, setFiles, + copilotEnabled, + setCopilotEnabled, }: { sendMessage: (message: string) => void; loading: boolean; @@ -21,8 +23,10 @@ const MessageInput = ({ setFileIds: (fileIds: string[]) => void; files: File[]; setFiles: (files: File[]) => void; + copilotEnabled:boolean + setCopilotEnabled:(mode: boolean) => void; + }) => { - const [copilotEnabled, setCopilotEnabled] = useState(false); const [message, setMessage] = useState(''); const [textareaRows, setTextareaRows] = useState(1); const [mode, setMode] = useState<'multi' | 'single'>('single'); From 3afa826fb96e969279a2036401ef9a7e9767bd7f Mon Sep 17 00:00:00 2001 From: litongjava Date: Tue, 4 Feb 2025 19:15:54 -1000 Subject: [PATCH 17/17] feat: add sources of user --- ui/components/ChatWindow.tsx | 2 +- ui/components/MessageBox.tsx | 69 +++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 4808f49..54c4b49 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -352,7 +352,7 @@ const loadMessages = async ( const messages = data.messages.map((msg: any) => { return { ...msg, - ...JSON.parse(msg.metadata), + // ...JSON.parse(msg.metadata), }; }) as Message[]; diff --git a/ui/components/MessageBox.tsx b/ui/components/MessageBox.tsx index f23127c..64cbe2a 100644 --- a/ui/components/MessageBox.tsx +++ b/ui/components/MessageBox.tsx @@ -1,9 +1,9 @@ 'use client'; /* eslint-disable @next/next/no-img-element */ -import React, { MutableRefObject, useEffect, useState } from 'react'; -import { Message } from './ChatWindow'; -import { cn } from '@/lib/utils'; +import React, {MutableRefObject, useEffect, useState} from 'react'; +import {Message} from './ChatWindow'; +import {cn} from '@/lib/utils'; import { BookCopy, Disc3, @@ -18,18 +18,18 @@ import Rewrite from './MessageActions/Rewrite'; import MessageSources from './MessageSources'; import SearchImages from './SearchImages'; import SearchVideos from './SearchVideos'; -import { useSpeech } from 'react-text-to-speech'; +import {useSpeech} from 'react-text-to-speech'; const MessageBox = ({ - message, - messageIndex, - history, - loading, - dividerRef, - isLast, - rewrite, - sendMessage, -}: { + message, + messageIndex, + history, + loading, + dividerRef, + isLast, + rewrite, + sendMessage, + }: { message: Message; messageIndex: number; history: Message[]; @@ -63,7 +63,7 @@ const MessageBox = ({ setParsedMessage(message.content); }, [message.content, message.sources, message.role]); - const { speechStatus, start, stop } = useSpeech({ text: speechMessage }); + const {speechStatus, start, stop} = useSpeech({text: speechMessage}); return (
@@ -72,6 +72,23 @@ const MessageBox = ({

{message.content}

+
+ + {message.sources && message.sources.length > 0 && ( +
+
+ +

+ Sources +

+
+ +
+ )} +
)} @@ -84,12 +101,12 @@ const MessageBox = ({ {message.sources && message.sources.length > 0 && (
- +

Sources

- +
)}
@@ -114,15 +131,16 @@ const MessageBox = ({ {parsedMessage} {loading && isLast ? null : ( -
+
{/* */} - +
- +
@@ -148,10 +166,10 @@ const MessageBox = ({ message.role === 'assistant' && !loading && ( <> -
+
- +

Related

@@ -160,7 +178,7 @@ const MessageBox = ({ className="flex flex-col space-y-3 text-sm" key={i} > -
+
{ sendMessage(suggestion); @@ -183,7 +201,8 @@ const MessageBox = ({ )}
-
+