diff --git a/datacenter/app/chat/page.tsx b/datacenter/app/chat/page.tsx
index 1734d0727..de94b13a9 100644
--- a/datacenter/app/chat/page.tsx
+++ b/datacenter/app/chat/page.tsx
@@ -1,14 +1,49 @@
"use client"
-import dynamic from 'next/dynamic'
+import { useRequest } from 'ahooks';
+import { sendGetRequest, sendPostRequest } from '@/utils/request';
+import useAgentChat from '@/hooks/useAgentChat';
+import ChatBoxComp from '@/components/chatBoxTemp';
+import { useDialogueContext } from '@/app/context/dialogue';
+import { useSearchParams } from 'next/navigation';
+const AgentPage = () => {
+ const searchParams = useSearchParams();
+ const { refreshDialogList } = useDialogueContext();
+ const id = searchParams.get('id');
+ const scene = searchParams.get('scene');
-const DynamicWrapper = dynamic(() => import ('@/components/agentPage'), {
- loading: () =>
Loading...
,
- ssr: false,
-});
+ const { data: historyList } = useRequest(async () => await sendGetRequest('/v1/chat/dialogue/messages/history', {
+ con_uid: id
+ }), {
+ ready: !!id,
+ refreshDeps: [id]
+ });
+
+ const { data: paramsList } = useRequest(async () => await sendPostRequest(`/v1/chat/mode/params/list?chat_mode=${scene}`), {
+ ready: !!scene,
+ refreshDeps: [scene]
+ });
+
+ const { history, handleChatSubmit } = useAgentChat({
+ queryAgentURL: `/v1/chat/completions`,
+ queryBody: {
+ conv_uid: id,
+ chat_mode: scene || 'chat_normal',
+ },
+ initHistory: historyList?.data
+ });
-const DynamicAgentPage = (props: any) => {
return (
-
+ <>
+ {
+ await refreshDialogList();
+ }}
+ messages={history || []}
+ onSubmit={handleChatSubmit}
+ paramsList={paramsList?.data}
+ />
+ >
)
}
-export default DynamicAgentPage;
\ No newline at end of file
+
+export default AgentPage;
\ No newline at end of file
diff --git a/datacenter/components/agentPage.tsx b/datacenter/components/agentPage.tsx
deleted file mode 100644
index ac2541e58..000000000
--- a/datacenter/components/agentPage.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-"use client"
-import { useRequest } from 'ahooks';
-import { sendGetRequest, sendPostRequest } from '@/utils/request';
-import useAgentChat from '@/hooks/useAgentChat';
-import ChatBoxComp from '@/components/chatBoxTemp';
-import { useDialogueContext } from '@/app/context/dialogue';
-
-const AgentPage = (props: {
- searchParams: {
- id?: string;
- scene?: string;
- initMessage?: string;
- }
-}) => {
- const { refreshDialogList } = useDialogueContext();
-
- const { data: historyList } = useRequest(async () => await sendGetRequest('/v1/chat/dialogue/messages/history', {
- con_uid: props.searchParams?.id
- }), {
- ready: !!props.searchParams?.id,
- refreshDeps: [props.searchParams?.id]
- });
-
- const { data: paramsList } = useRequest(async () => await sendPostRequest(`/v1/chat/mode/params/list?chat_mode=${props.searchParams?.scene}`), {
- ready: !!props.searchParams?.scene,
- refreshDeps: [props.searchParams?.scene]
- });
-
- const { history, handleChatSubmit } = useAgentChat({
- queryAgentURL: `/v1/chat/completions`,
- queryBody: {
- conv_uid: props.searchParams?.id,
- chat_mode: props.searchParams?.scene || 'chat_normal',
- },
- initHistory: historyList?.data
- });
-
- return (
- <>
- {
- await refreshDialogList();
- }}
- messages={history || []}
- onSubmit={handleChatSubmit}
- paramsList={paramsList?.data}
- />
- >
- )
-}
-
-export default AgentPage;
\ No newline at end of file
diff --git a/datacenter/components/chatBoxTemp.tsx b/datacenter/components/chatBoxTemp.tsx
index 56f4762a7..9364c4e35 100644
--- a/datacenter/components/chatBoxTemp.tsx
+++ b/datacenter/components/chatBoxTemp.tsx
@@ -10,11 +10,11 @@ import SmartToyOutlinedIcon from '@mui/icons-material/SmartToyOutlined';
import Markdown from 'markdown-to-jsx';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { okaidia } from 'react-syntax-highlighter/dist/esm/styles/prism';
+import { useSearchParams } from 'next/navigation';
type Props = {
messages: Message[];
onSubmit: (message: string, otherQueryBody?: any) => Promise;
- initialMessage?: string;
readOnly?: boolean;
paramsList?: { [key: string]: string };
clearIntialMessage?: () => void;
@@ -25,12 +25,13 @@ const Schema = z.object({ query: z.string().min(1) });
const ChatBoxComp = ({
messages,
onSubmit,
- initialMessage,
readOnly,
paramsList,
clearIntialMessage
}: Props) => {
const { mode } = useColorScheme();
+ const searchParams = useSearchParams();
+ const initMessage = searchParams.get('initMessage');
const scrollableRef = React.useRef(null);
const [isLoading, setIsLoading] = useState(false);
const [currentParam, setCurrentParam] = useState();
@@ -42,6 +43,7 @@ const ChatBoxComp = ({
const submit = async ({ query }: z.infer) => {
try {
+ console.log('submit');
setIsLoading(true);
methods.reset();
await onSubmit(query, {
@@ -55,10 +57,11 @@ const ChatBoxComp = ({
const handleInitMessage = async () => {
try {
- const searchParams = new URLSearchParams(window.location.search);
- searchParams.delete('initMessage');
- window.history.replaceState(null, null, `?${searchParams.toString()}`);
- await submit({ query: (initialMessage as string) });
+ const searchParamsTemp = new URLSearchParams(window.location.search);
+ const initMessage = searchParamsTemp.get('initMessage');
+ searchParamsTemp.delete('initMessage');
+ window.history.replaceState(null, null, `?${searchParamsTemp.toString()}`);
+ await submit({ query: (initMessage as string) });
} catch (err) {
console.log(err);
} finally {
@@ -83,12 +86,12 @@ const ChatBoxComp = ({
scrollableRef.current.scrollTo(0, scrollableRef.current.scrollHeight);
}, [messages?.length]);
-
+
React.useEffect(() => {
- if (initialMessage && messages.length <= 0) {
+ if (initMessage && messages.length <= 0) {
handleInitMessage();
}
- }, [initialMessage]);
+ }, [initMessage, messages.length]);
React.useEffect(() => {
if (paramsList && Object.keys(paramsList || {})?.length > 0) {
diff --git a/datacenter/hooks/useAgentChat.ts b/datacenter/hooks/useAgentChat.ts
index 50204a720..d9c734e20 100644
--- a/datacenter/hooks/useAgentChat.ts
+++ b/datacenter/hooks/useAgentChat.ts
@@ -49,7 +49,7 @@ import { useDialogueContext } from '@/app/context/dialogue';
const ctrl = new AbortController();
let buffer = '';
- await fetchEventSource(`${process.env.API_BASE_URL + queryAgentURL}`, {
+ await fetchEventSource(`${process.env.API_BASE_URL + "/api" + queryAgentURL}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',