Prevent location matching in bot messages
This commit is contained in:
1 parent
c21932389e
commit
d5ebdec076
8 files changed
+112
-2
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { isSafeOutboundMessage } from './outbound-message-safety.js';
|
||||
|
||||
export interface ConversationMessage {
|
||||
sender: string;
|
||||
@@ -201,6 +202,7 @@ export function isSafeConversationReply(message: string): boolean {
|
||||
const trimmed = message.trim();
|
||||
if (!trimmed || trimmed.length > 600) return false;
|
||||
if (/\b(as an ai|system prompt|begin untrusted|end untrusted|ignore (all|previous) instructions)\b/i.test(trimmed)) return false;
|
||||
if (!isSafeOutboundMessage(trimmed)) return false;
|
||||
const sentences = trimmed.match(/[^.!?]+[.!?]+/g) ?? [];
|
||||
return sentences.length <= 3;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const SHARED_LOCATION_PATTERNS: readonly RegExp[] = [
|
||||
/\b(?:i(?:'m| am)|i live|i(?:'m| am) based)\s+(?:also\s+)?(?:in|near|around)\b[^.!?\n]{0,60}\b(?:too|as well)\b/i,
|
||||
/\b(?:i(?:'m| am)|i live|i(?:'m| am) based)\s+also\s+(?:in|near|around)\b/i,
|
||||
/\bwe(?:'re| are)\s+(?:both\s+)?(?:in|from|based in|near)\b/i,
|
||||
/\b(?:same|nearby|local)\s+(?:area|city|town|county|country|location)\b/i,
|
||||
/\b(?:not (?:too )?far|close|close by|nearby|local)\s+(?:from|to)\s+you\b/i,
|
||||
/\byou(?:'re| are)\s+(?:so\s+)?(?:close|close by|nearby|local)\b/i,
|
||||
/\b(?:near me|close to me|in my area|down the road|my neck of the woods|practically (?:my )?neighbou?rs?)\b/i,
|
||||
/\b(?:that's|that is|you(?:'re| are))\s+not (?:too )?far away\b/i,
|
||||
/\b(?:only|just)\s+\d+\s*(?:miles?|minutes?|hours?)\s+away\b/i,
|
||||
/\b(?:another|fellow)\s+(?:brit|briton|british|english|scottish|welsh|irish|londoner)\b/i,
|
||||
/\b(?:uk|england|scotland|wales|ireland|london)\s+(?:too|as well)\b/i,
|
||||
];
|
||||
|
||||
const IN_PERSON_INVITATION_PATTERNS: readonly RegExp[] = [
|
||||
/\b(?:meet|meet up|get together)\s+(?:in person|irl|sometime|tonight|today|tomorrow|this week|this weekend)\b/i,
|
||||
/\b(?:we should|we could|want to|wanna|fancy|let's|shall we)\s+(?:meet|meet up|get together|grab (?:a )?(?:drink|coffee))\b/i,
|
||||
/\b(?:come over|come round|visit me|see you in person)\b/i,
|
||||
];
|
||||
|
||||
/**
|
||||
* Prevent generated messages from implying physical proximity or inviting an
|
||||
* in-person meeting. Stating the configured persona location by itself remains
|
||||
* valid; relating it to the recipient's location does not. Prompts separately
|
||||
* prohibit mentioning the recipient's location at all.
|
||||
*/
|
||||
export function isSafeOutboundMessage(message: string): boolean {
|
||||
return !SHARED_LOCATION_PATTERNS.some((pattern) => pattern.test(message))
|
||||
&& !IN_PERSON_INVITATION_PATTERNS.some((pattern) => pattern.test(message));
|
||||
}
|
||||
Reference in new issue
Block a user