mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
* fix: 截断器丢失唯一 user 消息导致 API 400 修复 #6196 当对话只有一条 user 消息(长 tool chain 场景:system → user → assistant → tool → assistant → tool → ...),三个截断方法都会把这条 user 消息丢掉, 导致智谱、Gemini 等要求 user 消息的 provider 返回 400。 改动: - 提取 `_split_system_rest()` 去掉三个方法里重复的 system/non-system 拆分 - 新增 `_ensure_user_message()`:截断后如果没有 user 了,从原始消息里补回 第一条 user,避免违反 API 格式要求 - 删掉 `truncate_by_dropping_oldest_turns` 里把没有 user 就清空全部消息的逻辑 - 5 个新测试覆盖单 user + 长 tool chain 场景,3 个旧测试更新断言 * style: format code --------- Co-authored-by: Yufeng He <40085740+universeplayer@users.noreply.github.com> Co-authored-by: RC-CHN <1051989940@qq.com>