feat: add semantic WeChat session actions
This commit is contained in:
+24
-1
@@ -29,6 +29,10 @@ import {
|
||||
shouldHandleSyncReply,
|
||||
} from './wechat/handlers/sync-replies.mjs';
|
||||
import { classifyWechatIntent } from './wechat/intent/classifier.mjs';
|
||||
import {
|
||||
isWechatSessionResetAction,
|
||||
resolveWechatSessionAction,
|
||||
} from './wechat/intent/session-action.mjs';
|
||||
import { isPageGenerateText, isTopicResetText } from './wechat/intent/patterns.mjs';
|
||||
import { isPageDataIntent } from './chat-skills.mjs';
|
||||
import { resolvePageGenerateOutcome } from './wechat/handlers/page-generate.mjs';
|
||||
@@ -1086,6 +1090,7 @@ function isTopicResetIntent(text) {
|
||||
export function shouldForceNewWechatAgentSession(wechatIntent, resetCandidate) {
|
||||
return (
|
||||
wechatIntent?.kind === 'session.reset' ||
|
||||
isWechatSessionResetAction(wechatIntent?.sessionActionResult) ||
|
||||
isTopicResetIntent(resetCandidate) ||
|
||||
isPageDataIntent(resetCandidate)
|
||||
);
|
||||
@@ -1578,6 +1583,7 @@ export function createWechatMpService({
|
||||
onPageGenerated = null,
|
||||
applySessionLlmProvider = null,
|
||||
refreshSessionSnapshot = null,
|
||||
sessionIntentClassifier = null,
|
||||
pageDataFinishGuard = null,
|
||||
wechatFetch = undiciFetch,
|
||||
linkExists = defaultPublicHtmlLinkExists,
|
||||
@@ -2354,7 +2360,7 @@ export function createWechatMpService({
|
||||
};
|
||||
|
||||
const runIntentMessage = async ({ inbound, intent, user }) => {
|
||||
const wechatIntent = classifyWechatIntent(intent);
|
||||
const wechatIntent = await resolveWechatIntent(intent);
|
||||
const mediaAnalysisEnabled = isWechatMediaGrayUser(user, config.mediaAnalysisGrayUsers);
|
||||
const reliabilityEnabled = isWechatMediaGrayUser(user, config.reliabilityGrayUsers);
|
||||
const agentReplyTimeoutMs = reliabilityEnabled ? config.agentReplyTimeoutMs : 0;
|
||||
@@ -2810,6 +2816,23 @@ export function createWechatMpService({
|
||||
}
|
||||
};
|
||||
|
||||
const resolveWechatIntent = async (intent) => {
|
||||
const wechatIntent = classifyWechatIntent(intent);
|
||||
if (intent.msgType !== 'text' && intent.msgType !== 'voice') return wechatIntent;
|
||||
const sessionActionResult = await resolveWechatSessionAction(intent.agentText, {
|
||||
semanticClassifier: sessionIntentClassifier,
|
||||
logger,
|
||||
});
|
||||
if (isWechatSessionResetAction(sessionActionResult)) {
|
||||
intent.sessionAction = sessionActionResult.action;
|
||||
return { ...wechatIntent, kind: 'session.reset', sessionActionResult };
|
||||
}
|
||||
if (sessionActionResult.action === 'ignore_previous') {
|
||||
intent.sessionAction = sessionActionResult.action;
|
||||
}
|
||||
return { ...wechatIntent, sessionActionResult };
|
||||
};
|
||||
|
||||
const handleInboundMessage = async (bodyText, query = {}) => {
|
||||
if (!verifyRequest(query)) {
|
||||
return { ok: false, status: 403, body: 'invalid signature' };
|
||||
|
||||
Reference in New Issue
Block a user