mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
chore: historical message corresponding assistant (#462)
* chore: historical message corresponding assistant * chore: addjust code
This commit is contained in:
@@ -96,8 +96,6 @@ const ChatAI = memo(
|
||||
|
||||
const [Question, setQuestion] = useState<string>("");
|
||||
|
||||
const [showPrevSuggestion, setShowPrevSuggestion] = useState(true);
|
||||
|
||||
const [websocketSessionId, setWebsocketSessionId] = useState("");
|
||||
|
||||
const onWebsocketSessionId = useCallback((sessionId: string) => {
|
||||
@@ -212,7 +210,6 @@ const ChatAI = memo(
|
||||
addError("Please wait for the current conversation to complete");
|
||||
return;
|
||||
}
|
||||
setShowPrevSuggestion(false);
|
||||
if (!activeChat?._id) {
|
||||
await createNewChat(value, activeChat, websocketSessionId);
|
||||
} else {
|
||||
@@ -408,7 +405,7 @@ const ChatAI = memo(
|
||||
<ConnectPrompt />
|
||||
)}
|
||||
|
||||
{showPrevSuggestion && !visibleStartPage && (
|
||||
{!activeChat?._id && !visibleStartPage && (
|
||||
<PrevSuggestion sendMessage={init} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface ISource {
|
||||
title?: string;
|
||||
question?: string;
|
||||
details?: any[];
|
||||
assistant_id?: string;
|
||||
}
|
||||
export interface Chat {
|
||||
_id: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { memo, useState } from "react";
|
||||
import { memo, useState, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import clsx from "clsx";
|
||||
|
||||
@@ -47,8 +47,23 @@ export const ChatMessage = memo(function ChatMessage({
|
||||
const { t } = useTranslation();
|
||||
|
||||
const currentAssistant = useConnectStore((state) => state.currentAssistant);
|
||||
const assistantList = useConnectStore((state) => state.assistantList);
|
||||
const [assistant, setAssistant] = useState<any>({});
|
||||
|
||||
const isAssistant = message?._source?.type === "assistant";
|
||||
const assistant_id = message?._source?.assistant_id;
|
||||
|
||||
useEffect(() => {
|
||||
let target = currentAssistant;
|
||||
if (isAssistant && assistant_id && Array.isArray(assistantList)) {
|
||||
const found = assistantList.find((item) => item._id === assistant_id);
|
||||
if (found) {
|
||||
target = found;
|
||||
}
|
||||
}
|
||||
setAssistant(target);
|
||||
}, [isAssistant, assistant_id, assistantList, currentAssistant]);
|
||||
|
||||
const messageContent = message?._source?.message || "";
|
||||
const details = message?._source?.details || [];
|
||||
const question = message?._source?.question || "";
|
||||
@@ -82,7 +97,7 @@ export const ChatMessage = memo(function ChatMessage({
|
||||
ChunkData={tools}
|
||||
loading={loadingStep?.tools}
|
||||
/>
|
||||
|
||||
|
||||
<FetchSource
|
||||
Detail={details.find((item) => item.type === "fetch_source")}
|
||||
ChunkData={fetch_source}
|
||||
@@ -154,11 +169,8 @@ export const ChatMessage = memo(function ChatMessage({
|
||||
<div className="w-full flex items-center gap-1 font-semibold text-sm text-[#333] dark:text-[#d8d8d8]">
|
||||
{isAssistant ? (
|
||||
<div className="w-6 h-6 flex justify-center items-center rounded-full bg-white border border-[#E6E6E6]">
|
||||
{currentAssistant?._source?.icon?.startsWith("font_") ? (
|
||||
<FontIcon
|
||||
name={currentAssistant._source.icon}
|
||||
className="w-4 h-4"
|
||||
/>
|
||||
{assistant?._source?.icon?.startsWith("font_") ? (
|
||||
<FontIcon name={assistant._source.icon} className="w-4 h-4" />
|
||||
) : (
|
||||
<img
|
||||
src={logoImg}
|
||||
@@ -168,7 +180,7 @@ export const ChatMessage = memo(function ChatMessage({
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
{isAssistant ? currentAssistant?._source?.name || "Coco AI" : ""}
|
||||
{isAssistant ? assistant?._source?.name || "Coco AI" : ""}
|
||||
</div>
|
||||
<div className="w-full prose dark:prose-invert prose-sm max-w-none">
|
||||
<div className="w-full pl-7 text-[#333] dark:text-[#d8d8d8] leading-relaxed">
|
||||
|
||||
@@ -335,6 +335,7 @@ export function useChatActions(
|
||||
const openSessionChat = useCallback(
|
||||
async (chat: Chat) => {
|
||||
if (!chat?._id) return;
|
||||
setVisibleStartPage(false);
|
||||
try {
|
||||
let response: any;
|
||||
if (isTauri) {
|
||||
@@ -359,7 +360,6 @@ export function useChatActions(
|
||||
console.error("open_session_chat:", error);
|
||||
return null;
|
||||
}
|
||||
setVisibleStartPage(false);
|
||||
},
|
||||
[currentServiceId]
|
||||
);
|
||||
|
||||
@@ -36,6 +36,9 @@ interface ChatProps {}
|
||||
export default function Chat({}: ChatProps) {
|
||||
const currentService = useConnectStore((state) => state.currentService);
|
||||
const currentAssistant = useConnectStore((state) => state.currentAssistant);
|
||||
const setVisibleStartPage = useConnectStore((state) => {
|
||||
return state.setVisibleStartPage;
|
||||
});
|
||||
|
||||
const chatAIRef = useRef<ChatAIRef>(null);
|
||||
|
||||
@@ -145,6 +148,7 @@ export default function Chat({}: ChatProps) {
|
||||
response = response ? JSON.parse(response) : null;
|
||||
console.log("_open", response);
|
||||
chatHistory(response);
|
||||
setVisibleStartPage(false);
|
||||
} catch (error) {
|
||||
console.error("open_session_chat:", error);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback } from "react";
|
||||
import { useCallback, useEffect } from "react";
|
||||
|
||||
import SearchChat from "@/components/SearchChat";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
@@ -7,7 +7,9 @@ import { useSyncStore } from "@/hooks/useSyncStore";
|
||||
|
||||
function MainApp() {
|
||||
const setIsTauri = useAppStore((state) => state.setIsTauri);
|
||||
setIsTauri(true);
|
||||
useEffect(() => {
|
||||
setIsTauri(true);
|
||||
}, []);
|
||||
|
||||
const hideCoco = useCallback(() => {
|
||||
return platformAdapter.hideWindow();
|
||||
|
||||
@@ -67,7 +67,7 @@ export default defineConfig({
|
||||
|
||||
const packageJson = {
|
||||
name: "@infinilabs/search-chat",
|
||||
version: "1.1.14",
|
||||
version: "1.1.15",
|
||||
main: "index.js",
|
||||
module: "index.js",
|
||||
type: "module",
|
||||
|
||||
Reference in New Issue
Block a user