pub struct SessionAnalyzer { /* private fields */ }Expand description
Session-aware multi-turn security analyzer.
Implementations§
Source§impl SessionAnalyzer
impl SessionAnalyzer
Sourcepub fn new(config: SessionAnalyzerConfig) -> Self
pub fn new(config: SessionAnalyzerConfig) -> Self
Create an analyzer with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create an analyzer with default thresholds.
Sourcepub fn record_event(
&mut self,
session_id: &str,
request_text: &str,
response_text: Option<&str>,
risk_score: f64,
finding_types: Vec<String>,
) -> SessionAnalysisResult
pub fn record_event( &mut self, session_id: &str, request_text: &str, response_text: Option<&str>, risk_score: f64, finding_types: Vec<String>, ) -> SessionAnalysisResult
Record a new event and return the updated analysis for its session.
Sourcepub fn analyze_session(&self, session_id: &str) -> SessionAnalysisResult
pub fn analyze_session(&self, session_id: &str) -> SessionAnalysisResult
Analyse an existing session without recording a new event.
Sourcepub fn detect_escalation(
&self,
session: &SessionState,
) -> Option<EscalationAlert>
pub fn detect_escalation( &self, session: &SessionState, ) -> Option<EscalationAlert>
Detect whether the session shows progressive risk escalation.
Sourcepub fn detect_extraction_probing(
&self,
session: &SessionState,
) -> Vec<ExtractionIndicator>
pub fn detect_extraction_probing( &self, session: &SessionState, ) -> Vec<ExtractionIndicator>
Scan all turns for extraction-probe regex matches.
Sourcepub fn detect_topic_shifting(
&self,
session: &SessionState,
) -> Option<TopicShiftAlert>
pub fn detect_topic_shifting( &self, session: &SessionState, ) -> Option<TopicShiftAlert>
Detect a suspicious topic shift using Jaccard similarity on token sets.
A shift is flagged when similarity drops below topic_shift_sensitivity
AND the risk score of the second turn is non-zero (indicating the shift
accompanies suspicious content).
Sourcepub fn compute_cumulative_risk(&self, session: &SessionState) -> f64
pub fn compute_cumulative_risk(&self, session: &SessionState) -> f64
Return the cumulative risk for a session.
Sourcepub fn cleanup_expired_sessions(&mut self)
pub fn cleanup_expired_sessions(&mut self)
Remove sessions that have been inactive longer than max_session_age.
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Number of active sessions being tracked.
Sourcepub fn to_security_findings(
result: &SessionAnalysisResult,
) -> Vec<SecurityFinding>
pub fn to_security_findings( result: &SessionAnalysisResult, ) -> Vec<SecurityFinding>
Convert a session analysis result into security findings for pipeline integration.