微信语音修复:iLink 已自动转写 voice(msg.text 即识别文字),按文本类转发

This commit is contained in:
2026-09-28 07:05:43 +08:00
parent d1e97ba9f9
commit cc66badee8
2 changed files with 12 additions and 10 deletions
+7 -7
View File
@@ -86,10 +86,10 @@ function parseCommand(text) {
// 微信这类纯文本端由 wxbot 发送前 stripMarkdown 降级——格式信息留在生产方,渲染适配在消费方。
const HELP_TEXT = [
'**可用命令**',
'- `/new [文本]` 新建会话并切换(带文本则作为首条消息直接开跑;不打断旧会话正在跑的回合)',
'- `/new [msg]` 新建会话并切换)',
'- `/stop` 终止当前回合',
'- `/compact` 压缩上下文(摘要稍后作为一条回复出现在会话里)',
'- `/clear` 清空当前会话(回到顾问模式,会话继续用)',
'- `/compact` 压缩上下文',
'- `/clear` 清空当前会话',
'- `/status` 查看当前会话状态',
'- `/help` 显示本帮助',
].join('\n');
@@ -174,14 +174,14 @@ function handleSend(db, opts) {
// 其余命令都作用于当前会话;无绑定时不隐式新建(那不是用户点这条命令的意图)
const s = boundSession(db, user, channel);
if (!s) {
return { kind: 'command', reply: '当前没有会话(先 /new,或直接发一条普通消息自动新建)', session_id: null };
return { kind: 'command', reply: '当前没有会话,请直接发送消息', session_id: null };
}
if (cmd === 'stop') {
// 与 Web 按钮语义对齐:只有回合真在跑才停,idle 不误伤(stop 会把 held 刷成 cancelled)
const run = engine.getRun(s.id);
if (!(run && run.looping)) {
return { kind: 'command', reply: '当前没有进行中的回合(无需终止)', session_id: s.id };
return { kind: 'command', reply: '当前没有进行中的回合,无需终止', session_id: s.id };
}
engine.stop(s.id);
log.info('msg', tag + ' channel /stop ' + s.id);
@@ -191,13 +191,13 @@ function handleSend(db, opts) {
if (cmd === 'compact') {
engine.summarizeContext(s.id); // 回合进行中 engine 抛 409(请先终止),冒给调用方
log.info('msg', tag + ' channel /compact ' + s.id);
return { kind: 'command', reply: '已发起上下文压缩,摘要稍后会作为一条回复出现在会话里', session_id: s.id };
return { kind: 'command', reply: '已发起上下文压缩,摘要稍后回复', session_id: s.id };
}
if (cmd === 'clear') {
engine.clearSessionMessages(s.id); // 同上,回合进行中 409
log.info('msg', tag + ' channel /clear ' + s.id);
return { kind: 'command', reply: '已清空当前会话(回到顾问模式),继续发消息即从零开始', session_id: s.id };
return { kind: 'command', reply: '已清空当前会话,现在从零开始', session_id: s.id };
}
// cmd === 'status'
+5 -3
View File
@@ -215,12 +215,14 @@ function createInstance(id) {
// 收信 → 转发 core inbox。命令回执(kind=command)同步回文本;
// 普通消息(kind=message)不回执——最终回复稍后由 core 经 /api/deliver 推过来。
// 媒体消息(image/video/file):SDK 下好字节随 inbox 转发(core 落任务目录 + 拼「用户上传了文件」
// 告知行,同 web 附件模式)。msg.text 对媒体消息是 SDK 占位描述(如 "[image]"),不能当真正文,
// 故只认 type==='text';voice 等未接入类型回占位提示。
// 告知行,同 web 附件模式)。msg.text 对媒体消息是 SDK 占位描述(如 "[image]"),不能当真正文;
// voice 特殊:iLink 服务端已自动转写,msg.text 即识别出的文字,按文本处理(silk 原始音频不下载)。
const MEDIA_KINDS = new Set(["image", "video", "file"]);
const TEXT_LIKE_KINDS = new Set(["text", "voice"]);
async function onIncoming(inst, msg) {
const type = String(msg?.type || "text");
const text = type === "text" ? String(msg?.text ?? "").trim() : "";
const text = TEXT_LIKE_KINDS.has(type) ? String(msg?.text ?? "").trim() : "";
const userId = String(msg?.userId ?? "");
const isMedia = MEDIA_KINDS.has(type);
if (!text && !isMedia) {