channel 命令输出 markdown 化(/help /status;markdown 为 channel 层规范格式);wxbot 出口统一 stripMarkdown 降级纯文本(微信不渲染 markdown,AI 回复不再带裸星号)

This commit is contained in:
2026-09-27 23:45:57 +08:00
parent d1f4b354c1
commit dbe6b22cdd
2 changed files with 19 additions and 15 deletions
+15 -12
View File
@@ -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');
}
+4 -3
View File
@@ -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) });