/** * ConversationGuard * * Detects and prevents multi-turn manipulation attacks by: * - Tracking conversation history patterns * - Detecting gradual privilege escalation attempts * - Identifying context manipulation across turns * - Blocking suspicious conversation trajectories */ import { GuardLogger } from "../types"; export interface ConversationGuardConfig { maxConversationLength?: number; conversationTTLMinutes?: number; escalationThreshold?: number; manipulationPatterns?: ManipulationPattern[]; detectToneShifts?: boolean; detectRoleConfusion?: boolean; detectInstructionOverride?: boolean; logger?: GuardLogger; } export interface ManipulationPattern { name: string; pattern: RegExp; weight: number; category: "escalation" | "confusion" | "override" | "extraction"; } export interface ConversationGuardResult { allowed: boolean; reason?: string; violations: string[]; risk_score: number; risk_factors: RiskFactor[]; conversation_analysis: { turn_count: number; escalation_attempts: number; manipulation_indicators: number; suspicious_patterns: string[]; }; } export interface RiskFactor { factor: string; weight: number; details: string; } export declare class ConversationGuard { private config; private logger; private sessions; private defaultManipulationPatterns; constructor(config?: ConversationGuardConfig); /** * Analyze a new user message in context of the conversation */ check(sessionId: string, userMessage: string, toolCalls?: string[], claimedRole?: string, requestId?: string): ConversationGuardResult; /** * Record assistant response (for complete conversation tracking) */ recordResponse(sessionId: string, response: string, toolCalls?: string[]): void; /** * Get session analysis */ getSessionAnalysis(sessionId: string): { turn_count: number; escalation_attempts: number; manipulation_indicators: number; claimed_roles: string[]; session_age_minutes: number; } | null; /** * Reset a session */ resetSession(sessionId: string): void; /** * Destroy guard and release resources */ destroy(): void; private preprocessMessage; private getOrCreateSession; private lastCleanup; private lazyCleanup; }