Files
memind/wechat-cursor-executor-policy.mjs
T
john 7cc3fb7f8a
Memind CI / Test, build, and release guards (push) Failing after 13m25s
fix(rain): keep Goose agent turns on DeepSeek, not Cursor chat bridge.
Cursor bridge PoC rejects tool calls; Rain and other agent sessions must not
apply it during session provider selection.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 14:33:55 +08:00

81 lines
2.7 KiB
JavaScript

import {
CURSOR_EXECUTOR_CHANNEL,
isChannelAllowedByCursorPolicy,
isCursorFeatureEnabled,
isIntentAllowedByWechatCursorPolicy,
isUserAllowedByWechatCursorPolicy,
} from './wechat-cursor-executor-admin-config.mjs';
import { CURSOR_CHANNEL_FEATURES } from './cursor-channel-features.mjs';
export { CURSOR_EXECUTOR_CHANNEL, CURSOR_CHANNEL_FEATURES };
export function resolveCursorChannelEligible({
user = null,
userId = null,
channel = '',
intentKind = '',
policy = null,
} = {}) {
if (!policy?.enabled) return false;
const subject = user ?? { userId };
if (!isUserAllowedByWechatCursorPolicy(subject, policy)) return false;
if (!isChannelAllowedByCursorPolicy(channel, policy)) return false;
const normalizedChannel = String(channel ?? '').trim().toLowerCase();
if (normalizedChannel === CURSOR_EXECUTOR_CHANNEL.WECHAT_MP) {
if (!isIntentAllowedByWechatCursorPolicy(intentKind, policy)) return false;
}
return true;
}
export function resolveCursorChatBridgeEligible({
user = null,
userId = null,
channel = '',
intentKind = '',
policy = null,
env = process.env,
} = {}) {
if (!policy?.enabled) return false;
const subject = user ?? { userId };
if (!isUserAllowedByWechatCursorPolicy(subject, policy)) return false;
if (!isCursorFeatureEnabled(policy, CURSOR_CHANNEL_FEATURES.CHAT_BRIDGE)) return false;
const normalizedChannel = String(channel ?? '').trim().toLowerCase();
// WeChat Goose sessions always carry tools; the bridge PoC rejects tool calls.
if (normalizedChannel === CURSOR_EXECUTOR_CHANNEL.WECHAT_MP) return false;
if (String(intentKind ?? '').trim() === 'page.generate') return false;
// Bridge is text-only: only explicit direct-chat intents; agent / rain / empty → DeepSeek.
if (String(intentKind ?? '').trim() !== 'chat.general') return false;
if (!isChannelAllowedByCursorPolicy(normalizedChannel || CURSOR_EXECUTOR_CHANNEL.H5, policy)) {
return false;
}
const bridgeEnvEnabled = String(env?.MEMIND_CURSOR_CHAT_BRIDGE_ENABLED ?? '').trim();
if (!['1', 'true', 'yes', 'on'].includes(bridgeEnvEnabled.toLowerCase())) return false;
return true;
}
export function resolveCursorScheduledTaskEligible({
user = null,
userId = null,
policy = null,
} = {}) {
if (!policy?.enabled) return false;
const subject = user ?? { userId };
if (!isUserAllowedByWechatCursorPolicy(subject, policy)) return false;
return isCursorFeatureEnabled(policy, CURSOR_CHANNEL_FEATURES.SCHEDULED_TASKS);
}
export function resolveWechatCursorExecutorEligible({
user = null,
userId = null,
intentKind = '',
policy = null,
} = {}) {
return resolveCursorChannelEligible({
user,
userId,
channel: CURSOR_EXECUTOR_CHANNEL.WECHAT_MP,
intentKind,
policy,
});
}