UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

44 lines (43 loc) • 1.85 kB
//#region src/channels/mention-gating.ts function implicitMentionKindWhen(e, t) { return t ? [e] : []; } function resolveBotThreadMentionPolicy(e) { if (!e.isBotOwnedThread || e.requireMentionInBotThreads === void 0) return { requireMention: e.requireMention, implicitMentionKinds: e.implicitMentionKinds }; return { requireMention: e.requireMentionInBotThreads, implicitMentionKinds: e.requireMentionInBotThreads ? e.implicitMentionKinds?.filter((e) => e === "native") : e.implicitMentionKinds }; } /** Translates positive implicit-mention policy into the evaluator's kind allowlist. */ function allowedImplicitMentionKindsFromConfig(e) { return [ ...implicitMentionKindWhen("reply_to_bot", e.replyToBot !== false), ...implicitMentionKindWhen("quoted_bot", e.quotedBot !== false), ...implicitMentionKindWhen("bot_thread_participant", e.threadParticipation !== false), "native" ]; } function resolveInboundMentionDecision(e) { const { facts: t, policy: n } = "facts" in e && "policy" in e ? e : { facts: e, policy: e }; const r = n.allowedImplicitMentionKinds ?? (n.implicitMentions ? allowedImplicitMentionKindsFromConfig(n.implicitMentions) : void 0); const i = n.isGroup && n.requireMention && !t.wasMentioned && !(t.hasAnyMention ?? false) && n.allowTextCommands && n.commandAuthorized && n.hasControlCommand; const a = [...new Set(t.implicitMentionKinds ?? [])].filter((e) => !r || r.includes(e)); const o = a.length > 0; const s = t.wasMentioned || o || i; return { implicitMention: o, matchedImplicitMentionKinds: a, effectiveWasMentioned: s, shouldBypassMention: i, shouldSkip: n.requireMention && t.canDetectMention && !s }; } //#endregion export { resolveInboundMentionDecision as i, implicitMentionKindWhen as n, resolveBotThreadMentionPolicy as r, allowedImplicitMentionKindsFromConfig as t };