From dbe6b22cddb91688b978510960df9cb60975c4f4 Mon Sep 17 00:00:00 2001 From: kicer Date: Sun, 27 Sep 2026 23:45:57 +0800 Subject: [PATCH] =?UTF-8?q?channel=20=E5=91=BD=E4=BB=A4=E8=BE=93=E5=87=BA?= =?UTF-8?q?=20markdown=20=E5=8C=96=EF=BC=88/help=20/status=EF=BC=9Bmarkdow?= =?UTF-8?q?n=20=E4=B8=BA=20channel=20=E5=B1=82=E8=A7=84=E8=8C=83=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=89=EF=BC=9Bwxbot=20=E5=87=BA=E5=8F=A3=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=20stripMarkdown=20=E9=99=8D=E7=BA=A7=E7=BA=AF?= =?UTF-8?q?=E6=96=87=E6=9C=AC=EF=BC=88=E5=BE=AE=E4=BF=A1=E4=B8=8D=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=20markdown=EF=BC=8CAI=20=E5=9B=9E=E5=A4=8D=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=B8=A6=E8=A3=B8=E6=98=9F=E5=8F=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/routes/channel.js | 27 +++++++++++++++------------ wxbot/app/src/server.js | 7 ++++--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/server/routes/channel.js b/app/server/routes/channel.js index 5cfc71e..acbd270 100644 --- a/app/server/routes/channel.js +++ b/app/server/routes/channel.js @@ -82,14 +82,16 @@ function parseCommand(text) { return { cmd: head, rest }; } +// 命令输出统一用 markdown(channel 层的规范格式):支持渲染的接入端直接用, +// 微信这类纯文本端由 wxbot 发送前 stripMarkdown 降级——格式信息留在生产方,渲染适配在消费方。 const HELP_TEXT = [ - '可用命令:', - '/new [文本] 新建会话并切换(带文本则作为首条消息直接开跑;不打断旧会话正在跑的回合)', - '/stop 终止当前回合', - '/compact 压缩上下文(摘要稍后作为一条回复出现在会话里)', - '/clear 清空当前会话(回到顾问模式,会话继续用)', - '/status 查看当前会话状态', - '/help 显示本帮助', + '**可用命令**', + '- `/new [文本]` 新建会话并切换(带文本则作为首条消息直接开跑;不打断旧会话正在跑的回合)', + '- `/stop` 终止当前回合', + '- `/compact` 压缩上下文(摘要稍后作为一条回复出现在会话里)', + '- `/clear` 清空当前会话(回到顾问模式,会话继续用)', + '- `/status` 查看当前会话状态', + '- `/help` 显示本帮助', ].join('\n'); const STATUS_TEXT = { active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' }; @@ -106,15 +108,16 @@ function statusReply(db, s) { const run = engine.getRun(s.id); const looping = !!(run && run.looping); const lines = [ - '会话 ' + s.id + '「' + (s.title || '未命名') + '」', - '状态:' + (looping ? '回合进行中' : (STATUS_TEXT[s.status] || s.status)) + '**会话状态**', + '- 会话:`' + s.id + '`「' + (s.title || '未命名') + '」', + '- 状态:' + (looping ? '回合进行中' : (STATUS_TEXT[s.status] || s.status)) + '|阶段:' + (PHASE_TEXT[s.phase] || s.phase || '-'), - '模型:' + (s.model_id || '未绑定'), + '- 模型:`' + (s.model_id || '未绑定') + '`', ]; const t = db.prepare('SELECT cron_expr, next_run_at, last_run_at, last_status FROM scheduled_tasks WHERE session_id = ?').get(s.id); lines.push(t - ? '定时任务:cron「' + t.cron_expr + '」下次 ' + fmtTime(t.next_run_at) + '(上次 ' + fmtTime(t.last_run_at) + ' ' + (t.last_status || '-') + ')' - : '定时任务:无'); + ? '- 定时任务:cron `' + t.cron_expr + '`,下次 ' + fmtTime(t.next_run_at) + '(上次 ' + fmtTime(t.last_run_at) + ' ' + (t.last_status || '-') + ')' + : '- 定时任务:无'); return lines.join('\n'); } diff --git a/wxbot/app/src/server.js b/wxbot/app/src/server.js index b1fe99a..8424326 100644 --- a/wxbot/app/src/server.js +++ b/wxbot/app/src/server.js @@ -16,7 +16,7 @@ import fs from "node:fs"; import path from "node:path"; import yaml from "js-yaml"; import QRCode from "qrcode"; -import { WeChatBot } from "@wechatbot/wechatbot"; +import { WeChatBot, stripMarkdown } from "@wechatbot/wechatbot"; // ── 配置加载(含 ${ENV_VAR} 展开)──────────────────────────────────────────── const DEFAULTS = { @@ -251,7 +251,8 @@ async function onIncoming(inst, msg) { } try { const r = await corePost("/wxhook/inbox", { id: inst.id, from: userId, text: text || undefined, media: media || undefined }, 30000); - if (r && r.kind === "command" && r.reply) await inst.bot.send(userId, r.reply); + // 命令回执可能是 markdown(channel 层规范格式);微信不渲染 markdown,出口统一 stripMarkdown 降级。 + if (r && r.kind === "command" && r.reply) await inst.bot.send(userId, stripMarkdown(r.reply)); } catch (e) { if (e.status === 404) { // core 侧绑定已删(解绑通知丢失的孤儿实例):告知用户并自毁(连凭证一起清,避免复活再骚扰) @@ -322,7 +323,7 @@ app.post("/api/deliver", requireAuth, async (req, res) => { if (!inst) return res.status(404).json({ error: "实例不存在" }); if (!to || !String(text || "").trim()) return res.status(400).json({ error: "to/text 不能为空" }); try { - await inst.bot.send(String(to), String(text)); + await inst.bot.send(String(to), stripMarkdown(String(text))); res.json({ ok: true }); } catch (e) { res.status(502).json({ error: "发送失败:" + String(e?.message || e).slice(0, 200) });