2026-08-26 21:14:36 +08:00
|
|
|
import {
|
2026-08-28 15:27:10 +08:00
|
|
|
CURSOR_EXECUTOR_CHANNEL,
|
|
|
|
|
isChannelAllowedByCursorPolicy,
|
2026-08-31 09:40:52 +08:00
|
|
|
isCursorFeatureEnabled,
|
2026-08-26 21:14:36 +08:00
|
|
|
isIntentAllowedByWechatCursorPolicy,
|
|
|
|
|
isUserAllowedByWechatCursorPolicy,
|
|
|
|
|
} from './wechat-cursor-executor-admin-config.mjs';
|
2026-08-31 09:40:52 +08:00
|
|
|
import { CURSOR_CHANNEL_FEATURES } from './cursor-channel-features.mjs';
|
2026-08-26 21:14:36 +08:00
|
|
|
|
2026-08-31 09:40:52 +08:00
|
|
|
export { CURSOR_EXECUTOR_CHANNEL, CURSOR_CHANNEL_FEATURES };
|
2026-08-28 15:27:10 +08:00
|
|
|
|
|
|
|
|
export function resolveCursorChannelEligible({
|
2026-08-26 21:14:36 +08:00
|
|
|
user = null,
|
|
|
|
|
userId = null,
|
2026-08-28 15:27:10 +08:00
|
|
|
channel = '',
|
2026-08-26 21:14:36 +08:00
|
|
|
intentKind = '',
|
|
|
|
|
policy = null,
|
|
|
|
|
} = {}) {
|
|
|
|
|
if (!policy?.enabled) return false;
|
|
|
|
|
const subject = user ?? { userId };
|
|
|
|
|
if (!isUserAllowedByWechatCursorPolicy(subject, policy)) return false;
|
2026-08-28 15:27:10 +08:00
|
|
|
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;
|
|
|
|
|
}
|
2026-08-26 21:14:36 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2026-08-28 15:27:10 +08:00
|
|
|
|
2026-08-31 09:40:52 +08:00
|
|
|
export function resolveCursorChatBridgeEligible({
|
|
|
|
|
user = null,
|
|
|
|
|
userId = null,
|
2026-08-31 10:16:03 +08:00
|
|
|
channel = '',
|
|
|
|
|
intentKind = '',
|
2026-08-31 09:40:52 +08:00
|
|
|
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;
|
2026-08-31 10:16:03 +08:00
|
|
|
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;
|
2026-09-04 14:33:55 +08:00
|
|
|
// Bridge is text-only: only explicit direct-chat intents; agent / rain / empty → DeepSeek.
|
|
|
|
|
if (String(intentKind ?? '').trim() !== 'chat.general') return false;
|
2026-08-31 10:16:03 +08:00
|
|
|
if (!isChannelAllowedByCursorPolicy(normalizedChannel || CURSOR_EXECUTOR_CHANNEL.H5, policy)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-08-31 09:40:52 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-28 15:27:10 +08:00
|
|
|
export function resolveWechatCursorExecutorEligible({
|
|
|
|
|
user = null,
|
|
|
|
|
userId = null,
|
|
|
|
|
intentKind = '',
|
|
|
|
|
policy = null,
|
|
|
|
|
} = {}) {
|
|
|
|
|
return resolveCursorChannelEligible({
|
|
|
|
|
user,
|
|
|
|
|
userId,
|
|
|
|
|
channel: CURSOR_EXECUTOR_CHANNEL.WECHAT_MP,
|
|
|
|
|
intentKind,
|
|
|
|
|
policy,
|
|
|
|
|
});
|
|
|
|
|
}
|