feat: add semantic WeChat session actions

This commit is contained in:
john
2026-07-23 17:18:25 +08:00
parent baa383548c
commit 7e20ec14f1
8 changed files with 235 additions and 2 deletions
+30
View File
@@ -4,6 +4,7 @@ import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { classifyWechatIntent, isPageGenerateIntent } from './intent/classifier.mjs';
import { resolveWechatSessionAction } from './intent/session-action.mjs';
import {
filterSendableHtmlArtifacts,
isStubPublicHtmlContent,
@@ -37,6 +38,26 @@ test('classifyWechatIntent detects session.reset', () => {
assert.equal(classifyWechatIntent({ msgType: 'text', agentText: '换新会话' }).kind, 'session.reset');
});
test('resolveWechatSessionAction recognizes natural new-session expressions', async () => {
for (const text of ['换新会话', '新开一个会话', '我们重新开始吧', '从头来']) {
const result = await resolveWechatSessionAction(text);
assert.equal(result.action, 'reset', text);
}
});
test('resolveWechatSessionAction separates ignore-context from reset', async () => {
assert.equal((await resolveWechatSessionAction('不要参考刚才关于医联体的内容')).action, 'ignore_previous');
assert.equal((await resolveWechatSessionAction('继续刚才的话题')).action, 'continue');
});
test('resolveWechatSessionAction uses an injected semantic classifier for unclear text', async () => {
const result = await resolveWechatSessionAction('我们换个思路聊', {
semanticClassifier: async () => ({ action: 'reset', confidence: 0.88, reason: '新对话意图' }),
});
assert.equal(result.action, 'reset');
assert.equal(result.source, 'semantic_model');
});
test('selectSendableHtmlArtifacts never returns stub html', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-stub-'));
const stubPath = path.join(dir, 'tang-poem.html');
@@ -85,6 +106,15 @@ test('buildWechatAgentPrompt lives in wechat prompts package', () => {
assert.match(prompt, /schedule-assistant/);
});
test('buildWechatAgentPrompt carries ignore-previous context boundary', () => {
const prompt = buildWechatAgentPrompt({
msgType: 'text',
agentText: '请分析这段新内容',
sessionAction: 'ignore_previous',
});
assert.match(prompt, /忽略此前相关内容/);
});
test('schedule confirmation guard blocks false positives', async () => {
assert.equal(looksLikeScheduleConfirmation('已经帮你设置好了待办提醒'), true);
const guarded = await guardScheduleConfirmationReply({