微信工具心跳:tool_call/tool_result 事件向 wxbot /api/typing 发 sendTyping(每绑定 2s 冷却、失败静默),长工具回合微信端持续显示「正在输入」

This commit is contained in:
2026-09-28 00:33:44 +08:00
parent 27a71d182d
commit 910d90cc40
4 changed files with 35 additions and 3 deletions
+1
View File
@@ -66,6 +66,7 @@ docker compose up -d agent-core # core 带 WXBOT_URL/WXBOT_TOKEN 重建(
| DELETE | `/api/instances/:id` | 销毁实例并删登录凭证(解绑) |
| GET | `/api/instances/:id/qr.svg` | 当前登录二维码(core 设置页代理渲染) |
| POST | `/api/deliver {id,to,text}` | 文本投递(core 已分段;出口统一 stripMarkdown,微信不渲染 markdown) |
| POST | `/api/typing {id,to}` | 「正在输入」心跳(core 在工具调用/结果时触发,每绑定 2s 冷却;typing 自然过期无需 stopTyping) |
| POST | `/api/deliver_media {id,to,filename,b64}` | 附件投递(core 已把正文里的 /p/ 链接换成本地字节并做归属/大小校验;SDK 按扩展名自动路由 image/video/file 卡片) |
## 本地调试
+14
View File
@@ -333,6 +333,20 @@ app.post("/api/deliver", requireAuth, async (req, res) => {
}
});
// core → wxbot「正在输入」心跳(工具调用/回执节奏触发;typing 由微信侧自动过期,无需 stopTyping)
app.post("/api/typing", requireAuth, async (req, res) => {
const { id, to } = req.body || {};
const inst = instances.get(String(id || ""));
if (!inst) return res.status(404).json({ error: "实例不存在" });
if (!to) return res.status(400).json({ error: "to 不能为空" });
try {
await inst.bot.sendTyping(String(to));
res.json({ ok: true });
} catch (e) {
res.status(502).json({ error: "typing 失败:" + String(e?.message || e).slice(0, 200) });
}
});
// core → wxbot 附件投递(链接→卡片):core 已把正文里的 /p/ 链接换成本地读好的字节并做
// 归属/大小/数量校验;这里只转发 SDK——bot.send 的 file 按扩展名自动路由 image/video/file 卡片,
// CDN 上传 + 加密全在 SDK 内。