diff --git a/README.md b/README.md index 73d268e..61a4f0f 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,13 @@ console.log(result.confidence) // 0.89 console.log(result.risk_score) // 0.85 console.log(result.rationale) // "Multiple grooming indicators..." console.log(result.recommended_action) // 'immediate_intervention' + +// Per-message breakdown (optional, returned on conversation-aware endpoints) +if (result.message_analysis) { + for (const m of result.message_analysis) { + console.log(`Message ${m.message_index}: risk=${m.risk_score}, flags=${m.flags}, summary=${m.summary}`) + } +} ``` #### `detectUnsafe(input)` diff --git a/src/types/detection.ts b/src/types/detection.ts index 4492884..47ceb5f 100644 --- a/src/types/detection.ts +++ b/src/types/detection.ts @@ -35,6 +35,20 @@ export interface DetectionCategory { confidence: number; } +/** + * Per-message analysis from conversation-aware detection. + */ +export interface MessageAnalysis { + /** Index of the message in the input array */ + message_index: number; + /** Risk score for this specific message (0-1) */ + risk_score: number; + /** Flags identified in this message */ + flags: string[]; + /** Brief summary of the message analysis */ + summary: string; +} + /** * Evidence excerpt from the analyzed content. */ @@ -85,6 +99,8 @@ export interface DetectionResult { recommended_action: string; /** Explanation of the analysis */ rationale: string; + /** Per-message analysis (conversation-aware endpoints) */ + message_analysis?: MessageAnalysis[]; /** Language code used for analysis */ language: string; /** Language support maturity */ diff --git a/src/types/safety.ts b/src/types/safety.ts index 138b2e8..65756c6 100644 --- a/src/types/safety.ts +++ b/src/types/safety.ts @@ -3,6 +3,7 @@ import { GroomingRisk, } from '../constants.js'; import { TrackingFields } from './index.js'; +import { MessageAnalysis } from './detection.js'; // Re-export enums for convenience export { Severity, GroomingRisk }; @@ -96,6 +97,8 @@ export interface GroomingResult { risk_score: number; /** Recommended action to take */ recommended_action: string; + /** Per-message analysis (conversation-aware endpoints) */ + message_analysis?: MessageAnalysis[]; /** Language code used for analysis */ language?: string; /** Language support maturity */