diff --git a/src/app/MainArea/Antechamber/index.tsx b/src/app/MainArea/Antechamber/index.tsx
index d1481dd..e1084b8 100644
--- a/src/app/MainArea/Antechamber/index.tsx
+++ b/src/app/MainArea/Antechamber/index.tsx
@@ -99,8 +99,8 @@ export default function Antechamber() {
};
return (
-
-
+
+
diff --git a/src/components/AntechamberHeader/index.tsx b/src/components/AntechamberHeader/index.tsx
index 3873d63..9fe0661 100644
--- a/src/components/AntechamberHeader/index.tsx
+++ b/src/components/AntechamberHeader/index.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from "react";
+import { useState, useEffect, useContext } from "react";
import HelloGIF from "/icons/hello.gif";
import WhatsThing from "/icons/whatsThing.png";
@@ -7,16 +7,16 @@ import RightIcon from "/icons/right.png";
import styles from "./index.module.css";
import { fetchQuestions } from "@/apis/questions";
import { useAbortController } from "@/hooks/useAbortController";
+import { RealtimeClientContext } from "../Provider/RealtimeClientProvider";
-type Props = {
- toRoom: ({initMessage,fileUrl}:{initMessage?:string,fileUrl?:string}) =>void;
-};
-export default function HeaderGroup({ toRoom }: Props) {
+export default function HeaderGroup() {
const [isRotating, setIsRotating] = useState(false);
const [displayQuestions, setDisplayQuestions] = useState
([]);
const [allQuestions, setAllQuestions] = useState([]);
+ const { handleConnect } = useContext(RealtimeClientContext);
+
const { getSignal } = useAbortController();
// 随机获取4个问题的函数
@@ -64,7 +64,7 @@ export default function HeaderGroup({ toRoom }: Props) {
};
const handleQuestion = async (question: string) => {
- toRoom({initMessage:question});
+ handleConnect({initMessage:question});
};
return (
diff --git a/src/components/AntechamberScore/index.tsx b/src/components/AntechamberScore/index.tsx
index 83baa9d..ff54558 100644
--- a/src/components/AntechamberScore/index.tsx
+++ b/src/components/AntechamberScore/index.tsx
@@ -4,12 +4,11 @@ import { useSearchParams } from 'react-router-dom';
import MyInputIcon from '/icons/myInput.png';
import RightBlueIcon from '/icons/rightBlue.png';
import style from './index.module.css';
+import { RealtimeClientContext } from '../Provider/RealtimeClientProvider';
+import { useContext } from 'react';
-type Props = {
- toRoom: ({initMessage,fileUrl}:{initMessage?:string,fileUrl?:string}) => void;
-};
-export default function MyInput({ toRoom }: Props) {
+export default function MyInput() {
const [searchParams] = useSearchParams()
@@ -17,9 +16,11 @@ export default function MyInput({ toRoom }: Props) {
const subjectGroup = searchParams.get('subjectGroup') || '物/化/史'
const expectedScore = searchParams.get('expectedScore') || 500
+ const { handleConnect } = useContext(RealtimeClientContext);
+
const handleQuestion = async () => {
- toRoom({initMessage:`我的高考地点在${provinceName},我选择的科目是${subjectGroup},我的高考分数为${expectedScore}分。帮我出一个科学的参考志愿表`});
+ handleConnect({initMessage:`我的高考地点在${provinceName},我选择的科目是${subjectGroup},我的高考分数为${expectedScore}分。帮我出一个科学的参考志愿表`});
};
return (
diff --git a/src/components/Provider/RealtimeClientProvider.tsx b/src/components/Provider/RealtimeClientProvider.tsx
index 3a0698a..2a81649 100644
--- a/src/components/Provider/RealtimeClientProvider.tsx
+++ b/src/components/Provider/RealtimeClientProvider.tsx
@@ -168,16 +168,13 @@ export const RealtimeClientProvider = ({
try {
if (!clientRef.current) {
await initClient({ initMessage, fileInfo });
- } else {
- await handleDisconnect();
- await initClient({ initMessage, fileInfo });
}
await clientRef.current?.connect();
await clientRef.current?.setAudioEnable(false);
setAudioEnabled(false);
} catch (error) {
- console.error(error);
+ // console.error(error);
if (error instanceof RealtimeAPIError) {
switch (error.code) {
case RealtimeError.CREATE_ROOM_ERROR:
@@ -275,7 +272,7 @@ export const RealtimeClientProvider = ({
content: JSON.stringify([
{
type: "text",
- text: "帮我解读这个文件,结合当下的专业行情以及对该专业未来的发展趋势,简介的给出大学建议",
+ text: "帮我解读这个文件,结合当下的专业行情以及对该专业未来的发展趋势,简介的给出志愿建议",
},
{ type: "image", file_url: fileInfo.url },
]),
@@ -294,6 +291,12 @@ export const RealtimeClientProvider = ({
client.on(EventNames.ALL, (_eventName, event: any) => {
// AI智能体设置
+ if(_eventName === 'server.error'){
+ // 长期不活动,服务端终结了
+ handleDisconnect();
+ }
+
+
if (
event.event_type !== ChatEventType.CONVERSATION_MESSAGE_DELTA &&
event.event_type !== ChatEventType.CONVERSATION_MESSAGE_COMPLETED &&
@@ -362,9 +365,7 @@ export const RealtimeClientProvider = ({
event.data.role !== RoleType.Assistant)
) {
// lastEvent = event;
- if(event.event_type === ChatEventType.CONVERSATION_MESSAGE_DELTA && fileParseStatusRef.current === 2){
- console.log("重置了");
-
+ if(event.event_type === ChatEventType.CONVERSATION_MESSAGE_DELTA && fileParseStatusRef.current === 2){
fileParseStatusRef.current = -1;
}
return [
@@ -454,9 +455,6 @@ export const RealtimeClientProvider = ({
setIsConnected(true);
});
- client.on(EventNames.ERROR, (_error: any) => {
- setIsConnected(false);
- });
},
[clientRef.current]
);
diff --git a/src/components/RoomConversation/index.tsx b/src/components/RoomConversation/index.tsx
index cd9e983..64000bd 100644
--- a/src/components/RoomConversation/index.tsx
+++ b/src/components/RoomConversation/index.tsx
@@ -31,7 +31,7 @@ export default function RoomConversation() {
Hey,我是您的六纬AI填报师
@@ -54,7 +54,7 @@ export default function RoomConversation() {
: "bg-blue-500 text-white rounded-tr-none"
}`}
>
- {typeof message.fileParseStatus === "undefined" ? (
+ {typeof message.fileParseStatus === "undefined" && typeof message.fileInfo === 'undefined' ? (