Files
memind/chat-task-intent-config.mjs
T
John a30b62b987
Memind CI / Test, build, and release guards (push) Has been cancelled
feat(chat-intent): observe routing, keep discuss-first on chat, and escalate short follow-ups
Close the chat-session dead zone without flipping production flags: record 0.72 fallbacks, stop C-2 from treating「先聊聊」as execute, and promote「不对你去执行」after a completed direct turn on both h5direct and date sessions.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-19 13:13:17 +08:00

77 lines
2.5 KiB
JavaScript

function envFlag(value, fallback = false) {
const raw = String(value ?? '').trim().toLowerCase();
if (!raw) return fallback;
return ['1', 'true', 'yes', 'on'].includes(raw);
}
function parseUserIdSet(raw) {
return new Set(
String(raw ?? '')
.split(/[,;\s]+/)
.map((item) => item.trim())
.filter(Boolean),
);
}
function boundedNumber(value, fallback, { min = 0, max = Number.MAX_SAFE_INTEGER } = {}) {
const parsed = Number(value);
if (!Number.isFinite(parsed)) return fallback;
return Math.min(max, Math.max(min, parsed));
}
export function resolveDirectEscalationContextPolicy(env = process.env) {
return {
enabled: envFlag(env?.MEMIND_DIRECT_ESCALATION_CONTEXT_ENABLED, false),
canaryUserIds: parseUserIdSet(env?.MEMIND_DIRECT_ESCALATION_CONTEXT_CANARY_USER_IDS),
};
}
export function isDirectEscalationContextEnabledForUser(userId, policy) {
if (!policy?.enabled) return false;
if (!policy.canaryUserIds?.size) return true;
return policy.canaryUserIds.has(String(userId ?? '').trim());
}
export function resolveChatSessionDeferPolicy(env = process.env) {
return {
enabled: envFlag(env?.MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_ENABLED, false),
canaryUserIds: parseUserIdSet(env?.MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_CANARY_USER_IDS),
minTextLength: Math.round(boundedNumber(
env?.MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_MIN_TEXT_LENGTH,
12,
{ min: 4, max: 200 },
)),
};
}
export function isChatSessionDeferEnabledForUser(userId, policy) {
if (!policy?.enabled) return false;
if (!policy.canaryUserIds?.size) return true;
return policy.canaryUserIds.has(String(userId ?? '').trim());
}
export function resolveDirectFollowupEscalatePolicy(env = process.env) {
return {
enabled: envFlag(env?.MEMIND_CHAT_ROUTER_DIRECT_FOLLOWUP_ESCALATE_ENABLED, false),
canaryUserIds: parseUserIdSet(env?.MEMIND_CHAT_ROUTER_DIRECT_FOLLOWUP_ESCALATE_CANARY_USER_IDS),
};
}
export function isDirectFollowupEscalateEnabledForUser(userId, policy) {
if (!policy?.enabled) return false;
if (!policy.canaryUserIds?.size) return true;
return policy.canaryUserIds.has(String(userId ?? '').trim());
}
export function shouldDeferChatSessionRoutingToLlm({
enabled = false,
text = '',
minTextLength = 12,
isExplicitDirectChatOnlyText = () => false,
} = {}) {
if (!enabled) return false;
const normalized = String(text ?? '').trim();
if (!normalized || isExplicitDirectChatOnlyText(normalized)) return false;
return normalized.length >= Math.max(1, Number(minTextLength) || 12);
}