浏览代码

修复 AI 助手 404 问题

将 AI chat 接口从 POST 改为 GET 方法,
适配 EventSource 只能发送 GET 请求的限制。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
tanlie 3 周之前
父节点
当前提交
de80fdea6e
共有 1 个文件被更改,包括 5 次插入9 次删除
  1. 5 9
      src/mock/index.ts

+ 5 - 9
src/mock/index.ts

@@ -153,18 +153,14 @@ export default [
     },
   },
 
-  // AI 对话接口 (SSE 流式输出)
+  // AI 对话接口 (SSE 流式输出) - 支持 GET/POST
   {
     url: "/api/upms/ai/chat",
-    method: "post",
+    method: "get",
     rawResponse: async (req, res) => {
-      const body = await new Promise<string>((resolve) => {
-        let data = '';
-        req.on('data', (chunk) => data += chunk);
-        req.on('end', () => resolve(data));
-      });
-
-      const { question } = JSON.parse(body);
+      // 从 query 参数获取问题
+      const url = new URL(req.url || '', `http://${req.headers.host}`);
+      const question = url.searchParams.get('question') || '';
 
       // AI 回复知识库
       const knowledgeBase: Record<string, string> = {