Browse Source

fix: random

Carson 2 tháng trước cách đây
mục cha
commit
aad0b8f91d
2 tập tin đã thay đổi với 16 bổ sung13 xóa
  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);