Carson преди 2 месеца
родител
ревизия
aad0b8f91d
променени са 2 файла, в които са добавени 16 реда и са изтрити 13 реда
  1. 0 1
      app/api/auth/[...nextauth]/route.ts
  2. 16 12
      lib/utils.ts

+ 0 - 1
app/api/auth/[...nextauth]/route.ts

@@ -72,7 +72,6 @@ const authOptions = {
       } catch (e) {
         session.user.name = token.name
       }
-      console.log(session, token);
       return session;
     },
   },

+ 16 - 12
lib/utils.ts

@@ -64,25 +64,29 @@ export function getChatResponse({
 
     // 处理错误事件
     eventSource.onerror = (e) => {
-      error = e
+      error = e;
       resolveQueuePromise();
       eventSource.close(); // 关闭连接
     };
 
-    ctrl.signal.addEventListener("abort", () => {
+    ctrl.signal.addEventListener("abort", (e) => {
+      // FIXME
+      // if (e?.target?.reason?.message) {
+      //   error = e.target.reason
+      // } else {
+      //   done = true
+      // }
+      done = true;
       resolveQueuePromise();
       eventSource.close();
     });
-    fetch(
-      `${process.env.NEXT_PUBLIC_GPT_BASE_URL}/ai_agent_park_chat_new`,
-      {
-        method: "POST",
-        body: JSON.stringify({ ...data, uid }),
-        headers: {
-          "Content-Type": "application/json",
-        },
-      }
-    );
+    fetch(`${process.env.NEXT_PUBLIC_GPT_BASE_URL}/ai_agent_park_chat_new`, {
+      method: "POST",
+      body: JSON.stringify({ ...data, uid }),
+      headers: {
+        "Content-Type": "application/json",
+      },
+    });
 
     while (!done || queue.length > 0) {
       clearTimeout(timer);