mirror of
https://github.com/infinilabs/coco-app.git
synced 2026-08-29 10:09:30 +02:00
fix: current service (#205)
This commit is contained in:
@@ -40,6 +40,7 @@ export const tauriFetch = async <T = any>({
|
||||
|
||||
try {
|
||||
const appStore = JSON.parse(localStorage.getItem("app-store") || "{}");
|
||||
const connectStore = JSON.parse(localStorage.getItem("connect-store") || "{}");
|
||||
console.log("baseURL", appStore.state?.endpoint_http)
|
||||
|
||||
baseURL = appStore.state?.endpoint_http || baseURL;
|
||||
@@ -61,7 +62,7 @@ export const tauriFetch = async <T = any>({
|
||||
headers["Content-Type"] = "application/json";
|
||||
}
|
||||
|
||||
const server_id = appStore.state?.activeServer?.id || "default_coco_server"
|
||||
const server_id = connectStore.state?.currentService?.id || "default_coco_server"
|
||||
const res: any = await invoke("get_server_token", {id: server_id});
|
||||
|
||||
headers["X-API-TOKEN"] = headers["X-API-TOKEN"] || res?.access_token || undefined;
|
||||
|
||||
@@ -19,8 +19,8 @@ import type { Chat } from "./types";
|
||||
import { useChatStore } from "@/stores/chatStore";
|
||||
import { useWindows } from "@/hooks/useWindows";
|
||||
import { ChatHeader } from "./ChatHeader";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { Sidebar } from "@/components/Assistant/Sidebar";
|
||||
import { useConnectStore } from "@/stores/connectStore";
|
||||
|
||||
interface ChatAIProps {
|
||||
isTransitioned: boolean;
|
||||
@@ -80,7 +80,7 @@ const ChatAI = memo(
|
||||
messages,
|
||||
setMessages,
|
||||
} = useChatStore();
|
||||
const activeServer = useAppStore((state) => state.activeServer);
|
||||
const currentService = useConnectStore((state) => state.currentService);
|
||||
|
||||
const [activeChat, setActiveChat] = useState<Chat>();
|
||||
const [isTyping, setIsTyping] = useState(false);
|
||||
@@ -108,9 +108,9 @@ const ChatAI = memo(
|
||||
}, []);
|
||||
|
||||
const reconnect = async () => {
|
||||
if (!activeServer?.id) return;
|
||||
if (!currentService?.id) return;
|
||||
try {
|
||||
await invoke("connect_to_server", { id: activeServer?.id });
|
||||
await invoke("connect_to_server", { id: currentService?.id });
|
||||
setConnected(true);
|
||||
} catch (error) {
|
||||
console.error("Failed to connect:", error);
|
||||
@@ -285,7 +285,7 @@ const ChatAI = memo(
|
||||
chatClose();
|
||||
try {
|
||||
let response: any = await invoke("new_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
message: value,
|
||||
});
|
||||
console.log("_new", response);
|
||||
@@ -314,7 +314,7 @@ const ChatAI = memo(
|
||||
setTimedoutShow(false);
|
||||
try {
|
||||
let response: any = await invoke("send_message", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: newChat?._id,
|
||||
websocketId: websocketIdRef.current,
|
||||
query_params: {
|
||||
@@ -351,7 +351,7 @@ const ChatAI = memo(
|
||||
if (!activeChat?._id) return;
|
||||
try {
|
||||
let response: any = await invoke("close_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: activeChat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
@@ -371,7 +371,7 @@ const ChatAI = memo(
|
||||
if (!activeChat?._id) return;
|
||||
try {
|
||||
let response: any = await invoke("cancel_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: activeChat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
@@ -418,7 +418,7 @@ const ChatAI = memo(
|
||||
const chatHistory = async (chat: Chat) => {
|
||||
try {
|
||||
let response: any = await invoke("session_chat_history", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: chat?._id,
|
||||
from: 0,
|
||||
size: 20,
|
||||
@@ -440,7 +440,7 @@ const ChatAI = memo(
|
||||
chatClose();
|
||||
try {
|
||||
let response: any = await invoke("open_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: chat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
@@ -486,10 +486,10 @@ const ChatAI = memo(
|
||||
}, [isSidebarOpenChat, handleOutsideClick]);
|
||||
|
||||
const getChatHistory = async () => {
|
||||
if (!activeServer?.id) return;
|
||||
if (!currentService?.id) return;
|
||||
try {
|
||||
let response: any = await invoke("chat_history", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
from: 0,
|
||||
size: 20,
|
||||
});
|
||||
@@ -508,8 +508,8 @@ const ChatAI = memo(
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
activeServer && !setIsSidebarOpen && getChatHistory();
|
||||
}, [activeServer]);
|
||||
currentService && !setIsSidebarOpen && getChatHistory();
|
||||
}, [currentService]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -30,6 +30,7 @@ import logoImg from "@/assets/icon.svg";
|
||||
import { useAppStore, IServer } from "@/stores/appStore";
|
||||
import { useChatStore } from "@/stores/chatStore";
|
||||
import type { Chat } from "./types";
|
||||
import { useConnectStore } from "@/stores/connectStore";
|
||||
|
||||
interface ChatHeaderProps {
|
||||
onCreateNewChat: () => void;
|
||||
@@ -56,8 +57,9 @@ export function ChatHeader({
|
||||
|
||||
const [serverList, setServerList] = useState<IServer[]>([]);
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const activeServer = useAppStore((state) => state.activeServer);
|
||||
const setActiveServer = useAppStore((state) => state.setActiveServer);
|
||||
|
||||
const currentService = useConnectStore((state) => state.currentService);
|
||||
const setCurrentService = useConnectStore((state) => state.setCurrentService);
|
||||
|
||||
const fetchServers = async (resetSelection: boolean) => {
|
||||
invoke("list_coco_servers")
|
||||
@@ -67,7 +69,7 @@ export function ChatHeader({
|
||||
);
|
||||
console.log("list_coco_servers", enabledServers);
|
||||
setServerList(enabledServers);
|
||||
if (resetSelection && enabledServers.length > 0 && !activeServer) {
|
||||
if (resetSelection && enabledServers.length > 0 && !currentService) {
|
||||
switchServer(enabledServers[enabledServers.length - 1]);
|
||||
}
|
||||
})
|
||||
@@ -101,7 +103,7 @@ export function ChatHeader({
|
||||
const switchServer = async (server: IServer) => {
|
||||
try {
|
||||
// Switch UI first, then switch server connection
|
||||
setActiveServer(server);
|
||||
setCurrentService(server);
|
||||
setEndpoint(server.endpoint);
|
||||
setMessages(""); // Clear previous messages
|
||||
onCreateNewChat();
|
||||
@@ -255,7 +257,7 @@ export function ChatHeader({
|
||||
key={server.id}
|
||||
onClick={() => switchServer(server)}
|
||||
className={`w-full flex items-center justify-between p-2 rounded-lg transition-colors whitespace-nowrap ${
|
||||
activeServer?.id === server.id
|
||||
currentService?.id === server.id
|
||||
? "bg-gray-100 dark:bg-gray-800"
|
||||
: "hover:bg-gray-50 dark:hover:bg-gray-800/50"
|
||||
}`}
|
||||
@@ -284,7 +286,7 @@ export function ChatHeader({
|
||||
}`}
|
||||
/>
|
||||
<div className="w-4 h-4">
|
||||
{activeServer?.id === server.id && (
|
||||
{currentService?.id === server.id && (
|
||||
<Check className="w-full h-full text-gray-500 dark:text-gray-400" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useRouteError } from "react-router-dom";
|
||||
|
||||
import errorImg from "./assets/error_page.png";
|
||||
import ApiDetails from "@/components/Common/ApiDetails";
|
||||
|
||||
export default function ErrorPage() {
|
||||
const error: any = useRouteError();
|
||||
@@ -23,23 +22,6 @@ export default function ErrorPage() {
|
||||
<i>{error.statusText || error.message}</i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ApiDetails />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div id="error-page">
|
||||
<div className="error-content">
|
||||
<h1 className="error-title">Oops!</h1>
|
||||
<p className="error-message">
|
||||
Sorry, there is an error in your Coco App. Please contact the
|
||||
administrator.
|
||||
</p>
|
||||
<p className="error-details">
|
||||
<i>{error.statusText || error.message}</i>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ export function useFindConnectorIcon(item: any) {
|
||||
const datasourceData = useConnectStore((state) => state.datasourceData);
|
||||
const currentService = useConnectStore((state) => state.currentService);
|
||||
|
||||
// console.log(1111, connector_data, datasourceData, currentService, item?.source);
|
||||
|
||||
const id = item?.source?.id || "";
|
||||
|
||||
const result_source = datasourceData[currentService?.id]?.find(
|
||||
|
||||
@@ -5,14 +5,12 @@ import ChatAI, { ChatAIRef } from "@/components/Assistant/Chat";
|
||||
import { ChatInput } from "@/components/Assistant/ChatInput";
|
||||
import { Sidebar } from "@/components/Assistant/Sidebar";
|
||||
import type { Chat } from "@/components/Assistant/types";
|
||||
import ApiDetails from "@/components/Common/ApiDetails";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { useConnectStore } from "@/stores/connectStore";
|
||||
|
||||
interface ChatProps {}
|
||||
|
||||
export default function Chat({}: ChatProps) {
|
||||
const activeServer = useAppStore((state) => state.activeServer);
|
||||
|
||||
const currentService = useConnectStore((state) => state.currentService);
|
||||
|
||||
const chatAIRef = useRef<ChatAIRef>(null);
|
||||
|
||||
@@ -33,11 +31,11 @@ export default function Chat({}: ChatProps) {
|
||||
const getChatHistory = async () => {
|
||||
try {
|
||||
let response: any = await invoke("chat_history", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
from: 0,
|
||||
size: 20,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
response = JSON.parse(response || "");
|
||||
console.log("_history", response);
|
||||
const hits = response?.hits?.hits || [];
|
||||
setChats(hits);
|
||||
@@ -70,12 +68,12 @@ export default function Chat({}: ChatProps) {
|
||||
const chatHistory = async (chat: Chat) => {
|
||||
try {
|
||||
let response: any = await invoke("session_chat_history", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: chat?._id,
|
||||
from: 0,
|
||||
size: 20,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
response = JSON.parse(response || "");
|
||||
console.log("id_history", response);
|
||||
const hits = response?.hits?.hits || [];
|
||||
const updatedChat: Chat = {
|
||||
@@ -92,10 +90,10 @@ export default function Chat({}: ChatProps) {
|
||||
if (!activeChat?._id) return;
|
||||
try {
|
||||
let response: any = await invoke("close_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: activeChat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
response = JSON.parse(response || "");
|
||||
console.log("_close", response);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch user data:", error);
|
||||
@@ -106,10 +104,10 @@ export default function Chat({}: ChatProps) {
|
||||
chatClose();
|
||||
try {
|
||||
let response: any = await invoke("open_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: chat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
response = JSON.parse(response || "");
|
||||
console.log("_open", response);
|
||||
chatHistory(response);
|
||||
} catch (error) {
|
||||
@@ -121,10 +119,10 @@ export default function Chat({}: ChatProps) {
|
||||
if (!activeChat?._id) return;
|
||||
try {
|
||||
let response: any = await invoke("cancel_session_chat", {
|
||||
serverId: activeServer?.id,
|
||||
serverId: currentService?.id,
|
||||
sessionId: activeChat?._id,
|
||||
});
|
||||
response = JSON.parse(response || "")
|
||||
response = JSON.parse(response || "");
|
||||
console.log("_cancel", response);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch user data:", error);
|
||||
@@ -134,7 +132,7 @@ export default function Chat({}: ChatProps) {
|
||||
const clearChat = () => {
|
||||
chatClose();
|
||||
setActiveChat(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-screen">
|
||||
@@ -160,7 +158,6 @@ export default function Chat({}: ChatProps) {
|
||||
|
||||
{/* Main content */}
|
||||
<div className={`flex-1 flex flex-col bg-white dark:bg-gray-900`}>
|
||||
|
||||
{/* Chat messages */}
|
||||
<ChatAI
|
||||
ref={chatAIRef}
|
||||
@@ -193,8 +190,6 @@ export default function Chat({}: ChatProps) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ApiDetails/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ import { useEffect, useRef, useState } from "react";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { LogicalSize } from "@tauri-apps/api/dpi";
|
||||
import clsx from "clsx";
|
||||
|
||||
import InputBox from "@/components/Search/InputBox";
|
||||
import Search from "@/components/Search/Search";
|
||||
import ChatAI, { ChatAIRef } from "@/components/Assistant/Chat";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { useAuthStore } from "@/stores/authStore";
|
||||
import ApiDetails from "@/components/Common/ApiDetails";
|
||||
import clsx from "clsx";
|
||||
import { isWin } from "@/utils/platform";
|
||||
|
||||
export default function DesktopApp() {
|
||||
@@ -161,8 +160,6 @@ export default function DesktopApp() {
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<ApiDetails />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,25 +6,21 @@ import { useTranslation } from "react-i18next";
|
||||
import SettingsPanel from "@/components/Settings/SettingsPanel";
|
||||
import GeneralSettings from "@/components/Settings/GeneralSettings";
|
||||
import AboutView from "@/components/Settings/AboutView";
|
||||
import Cloud from "@/components/Cloud/Cloud.tsx"
|
||||
import Cloud from "@/components/Cloud/Cloud.tsx";
|
||||
import Footer from "@/components/Footer";
|
||||
import ApiDetails from "@/components/Common/ApiDetails";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
|
||||
|
||||
|
||||
|
||||
function SettingsPage() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const tabs = [
|
||||
{ name: t('settings.tabs.general'), icon: Settings },
|
||||
{ name: t('settings.tabs.extensions'), icon: Puzzle },
|
||||
{ name: t('settings.tabs.connect'), icon: Server },
|
||||
{ name: t('settings.tabs.advanced'), icon: Settings2 },
|
||||
{ name: t('settings.tabs.about'), icon: Info },
|
||||
{ name: t("settings.tabs.general"), icon: Settings },
|
||||
{ name: t("settings.tabs.extensions"), icon: Puzzle },
|
||||
{ name: t("settings.tabs.connect"), icon: Server },
|
||||
{ name: t("settings.tabs.advanced"), icon: Settings2 },
|
||||
{ name: t("settings.tabs.about"), icon: Info },
|
||||
];
|
||||
|
||||
|
||||
const tabIndex = useAppStore((state) => state.tabIndex);
|
||||
const [defaultIndex, setDefaultIndex] = useState<number>(tabIndex);
|
||||
|
||||
@@ -71,7 +67,7 @@ function SettingsPage() {
|
||||
<TabPanel>
|
||||
<SettingsPanel title="">
|
||||
<div className="text-gray-600 dark:text-gray-400">
|
||||
{t('settings.tabs.extensionsContent')}
|
||||
{t("settings.tabs.extensionsContent")}
|
||||
</div>
|
||||
</SettingsPanel>
|
||||
</TabPanel>
|
||||
@@ -81,7 +77,7 @@ function SettingsPage() {
|
||||
<TabPanel>
|
||||
<SettingsPanel title="">
|
||||
<div className="text-gray-600 dark:text-gray-400">
|
||||
{t('settings.tabs.advancedContent')}
|
||||
{t("settings.tabs.advancedContent")}
|
||||
</div>
|
||||
</SettingsPanel>
|
||||
</TabPanel>
|
||||
@@ -95,11 +91,8 @@ function SettingsPage() {
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
|
||||
<ApiDetails />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default SettingsPage;
|
||||
|
||||
@@ -44,8 +44,6 @@ export type IAppStore = {
|
||||
setTabIndex: (tabName: string) => void;
|
||||
isPinned: boolean,
|
||||
setIsPinned: (isPinned: boolean) => void,
|
||||
activeServer: IServer | null,
|
||||
setActiveServer: (activeServer: IServer | null) => void,
|
||||
initializeListeners: () => void;
|
||||
};
|
||||
|
||||
@@ -99,8 +97,6 @@ export const useAppStore = create<IAppStore>()(
|
||||
},
|
||||
isPinned: false,
|
||||
setIsPinned: (isPinned: boolean) => set({ isPinned }),
|
||||
activeServer: null,
|
||||
setActiveServer: (activeServer: IServer | null) => set({ activeServer }),
|
||||
initializeListeners: () => {
|
||||
listen(ENDPOINT_CHANGE_EVENT, (event: any) => {
|
||||
const { endpoint, endpoint_http, endpoint_websocket } = event.payload;
|
||||
@@ -119,7 +115,6 @@ export const useAppStore = create<IAppStore>()(
|
||||
endpoint_http: state.endpoint_http,
|
||||
endpoint_websocket: state.endpoint_websocket,
|
||||
language: state.language,
|
||||
activeServer: state.activeServer,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user