import IconFont from '../components/IconFont'; import { CaretRightOutlined, CloseOutlined } from '@ant-design/icons'; import classNames from 'classnames'; import { ForwardRefRenderFunction, forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react'; import Chat from '../Chat'; import { AgentType } from '../Chat/type'; import { setToken } from '../utils/utils'; import { SendMsgParamsType } from '../common/type'; import styles from './style.module.less'; import { copilotTitle } from '../common/env'; type Props = { token?: string; agentIds?: number[]; noInput?: boolean; isDeveloper?: boolean; integrateSystem?: string; apiUrl?: string; onReportMsgEvent?: (msg: string, valid: boolean) => void; onOpenChatPage?: (agentId?: number) => void; }; const Copilot: ForwardRefRenderFunction = ( { token, agentIds, noInput, isDeveloper, integrateSystem, apiUrl, onReportMsgEvent, onOpenChatPage, }, ref ) => { const [chatVisible, setChatVisible] = useState(false); const [copilotMinimized, setCopilotMinimized] = useState(false); const [currentAgent, setCurrentAgent] = useState(); const chatRef = useRef(); useImperativeHandle(ref, () => ({ sendCopilotMsg, })); useEffect(() => { if (token) { setToken(token); } }, [token]); useEffect(() => { if (apiUrl) { localStorage.setItem('SUPERSONIC_CHAT_API_URL', apiUrl); } }, [apiUrl]); const sendCopilotMsg = (params: SendMsgParamsType) => { chatRef?.current?.sendCopilotMsg(params); updateChatVisible(true); }; const updateChatVisible = (visible: boolean) => { setChatVisible(visible); }; const onToggleChatVisible = () => { updateChatVisible(!chatVisible); }; const onCloseChat = () => { updateChatVisible(false); }; const onTransferChat = () => { onOpenChatPage?.(currentAgent?.id); }; const onMinimizeCopilot = (e: any) => { e.stopPropagation(); updateChatVisible(false); setCopilotMinimized(true); }; const copilotClass = classNames(styles.copilot, { [styles.copilotMinimized]: copilotMinimized, }); const chatPopoverClass = classNames(styles.chatPopover, { [styles.c2System]: integrateSystem === 'c2', }); return ( <>
{ setCopilotMinimized(false); }} onClick={onToggleChatVisible} >
-
{onOpenChatPage && ( )}
{copilotTitle}
); }; export default forwardRef(Copilot);