feat: add system disclosure policy gate
Memind CI / Test, build, and release guards (pull_request) Successful in 3m14s

This commit is contained in:
john
2026-07-23 22:53:15 +08:00
parent ba6cc10f08
commit 205b5fd8be
20 changed files with 1585 additions and 2 deletions
+43
View File
@@ -1580,6 +1580,7 @@ export function createWechatMpService({
wechatScheduleLlmConfigService = null,
llmProviderService = null,
chatIntentRouter = null,
systemDisclosurePolicyService = null,
onPageGenerated = null,
applySessionLlmProvider = null,
refreshSessionSnapshot = null,
@@ -3177,6 +3178,48 @@ export function createWechatMpService({
await persistIntentDetail({ intent, userId: boundUser.userId, rawXmlHash });
let disclosureDecision = null;
try {
disclosureDecision = systemDisclosurePolicyService?.evaluate?.({
text: intent.agentText,
channel: 'wechat_mp',
userId: boundUser.userId,
sessionId: null,
}) ?? null;
} catch (err) {
logger.warn?.(
'WeChat MP system disclosure policy evaluation failed open:',
err instanceof Error ? err.message : err,
);
}
if (disclosureDecision?.enforced) {
if (inbound.msgId && typeof userAuth.finishWechatMpMessage === 'function') {
await userAuth.finishWechatMpMessage({
appId: config.appId,
openid: inbound.fromUserName,
msgId: inbound.msgId,
status: 'done',
agentSessionId: null,
});
}
logger.info?.('[system-disclosure-policy] blocked WeChat request', {
userId: boundUser.userId,
policyVersion: disclosureDecision.policyVersion,
reasonCode: disclosureDecision.reasonCode,
categories: disclosureDecision.categories,
});
return {
ok: true,
status: 200,
contentType: 'application/xml; charset=utf-8',
body: buildWechatTextReply({
toUserName: inbound.fromUserName,
fromUserName: inbound.toUserName,
content: disclosureDecision.responseText,
}),
};
}
const scheduleReply =
intent.msgType === 'text' || intent.msgType === 'voice'
? await handleWechatScheduleIntent({