Files
msh-system/docs/Testing/test-0325-1.md
panchengyong 35052d655f chore: 更新测试文档 test-0325-1 与 IDEA 配置
- docs/Testing:标题行微调
- .idea:compiler.xml、jarRepositories.xml

Made-with: Cursor
2026-03-30 12:50:38 +08:00

42 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 手动测试问题
## 页面pages/tool/ai-nutritionist
- 1. 请求后页面显示:"未能获取到有效回复。"
fetch("http://127.0.0.1:20822/api/front/coze/chat/stream", {
"headers": {
"accept": "*/*",
"authori-zation": "6f6767b2edc64949b0e4888c199ac0bb",
"content-type": "application/json",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site"
},
"referrer": "https://servicewechat.com/wx7ecf3e3699353c69/devtools/page-frame.html",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "{\"botId\":\"7591133240535449654\",\"userId\":11,\"additionalMessages\":[{\"role\":\"user\",\"content\":\"透析患者可以喝牛奶吗?\",\"content_type\":\"text\"}],\"stream\":true,\"autoSaveHistory\":true}",
"method": "POST",
"mode": "cors",
"credentials": "omit"
});
## 修复记录
### 问题 1 修复:流式对话显示"未能获取到有效回复"
**根因分析**:两个问题导致前端无法正确接收流式数据:
1. **Delta 事件过滤条件过严**`ai-nutritionist.vue``sendToAIStream()``conversation.message.delta` 事件要求 `evt.role === 'assistant' && evt.type === 'answer'`。但 Coze SDK 在流式增量事件中可能不返回 `role``type` 字段(后端发送的精简 JSON 仅在字段非 null 时才包含),导致所有增量内容被静默丢弃。
2. **未处理非分块响应降级**`cozeChatStream()``success` 回调未处理响应体。在微信开发者工具或某些不支持 `onChunkReceived` 的环境下,流式数据仅在 `res.data` 中一次性返回,但被完全忽略。
**修复内容**
- `ai-nutritionist.vue`:将 delta 过滤改为 `const role = evt.role || 'assistant'`,缺失字段时默认为预期值。
- `models-api.js`:增加 `_gotChunks` 标记,当 `onChunkReceived` 未触发时,在 `success` 回调中解析 `res.data` 作为降级处理;增加 `responseType: 'text'` 确保响应体为字符串。
# 参考文档
- 3. /Users/a123/msh-system/.cursor/plans/optimize_ai_nutritionist_speed_b6e9a618.plan.md
- 1. /Users/a123/msh-system/docs/测试问题分析报告_2026-03-22.md
- 2. /Users/a123/msh-system/docs/功能开发详细设计_2026-03-25.md