/** * RulesManager - Agent rules management system * * Enables agents to follow configurable rules and policies. * * @example * ```typescript * import { RulesManager, Agent } from 'praisonai'; * * const rules = new RulesManager({ * rules: [ * { id: 'safety', pattern: /harmful/i, action: 'block' }, * { id: 'format', pattern: /json/i, action: 'transform' } * ] * }); * * const agent = new Agent({ rules }); * ``` */ /** * Rule action types */ export type RuleAction = 'allow' | 'block' | 'warn' | 'transform' | 'log'; /** * Rule priority levels */ export type RulePriority = 'low' | 'medium' | 'high' | 'critical'; /** * Rule definition */ export interface Rule { /** Unique rule identifier */ id: string; /** Human-readable name */ name?: string; /** Rule description */ description?: string; /** Pattern to match (string or regex) */ pattern?: string | RegExp; /** Custom matcher function */ matcher?: (content: string, context?: RuleContext) => boolean; /** Action to take when matched */ action: RuleAction; /** Priority level */ priority?: RulePriority; /** Transformation function (for action='transform') */ transform?: (content: string) => string; /** Custom handler */ handler?: (content: string, context?: RuleContext) => RuleResult; /** Whether rule is enabled */ enabled?: boolean; /** Tags for categorization */ tags?: string[]; } /** * Context passed to rule evaluation */ export interface RuleContext { /** Source of content (user, agent, tool) */ source?: 'user' | 'agent' | 'tool' | 'system'; /** Agent ID if applicable */ agentId?: string; /** Session ID if applicable */ sessionId?: string; /** Additional metadata */ metadata?: Record; } /** * Result of rule evaluation */ export interface RuleResult { /** Whether rule matched */ matched: boolean; /** Rule ID that matched */ ruleId: string; /** Action taken */ action: RuleAction; /** Original content */ original: string; /** Transformed content (if applicable) */ transformed?: string; /** Warning/error message */ message?: string; } /** * Rules evaluation summary */ export interface RulesEvaluation { /** Whether content passed all rules */ passed: boolean; /** All rule results */ results: RuleResult[]; /** Blocked by rules */ blocked: RuleResult[]; /** Warnings generated */ warnings: RuleResult[]; /** Transformations applied */ transformations: RuleResult[]; /** Final content after transformations */ content: string; } /** * RulesManager configuration */ export interface RulesManagerConfig { /** Initial rules */ rules?: Rule[]; /** Default action for unmatched content */ defaultAction?: RuleAction; /** Whether to continue after first match */ continueOnMatch?: boolean; /** Enable logging */ logging?: boolean; } /** * RulesManager - Manages agent rules and policies */ export declare class RulesManager { readonly id: string; private rules; private defaultAction; private continueOnMatch; private logging; constructor(config?: RulesManagerConfig); /** * Add a rule */ addRule(rule: Rule): void; /** * Remove a rule */ removeRule(id: string): boolean; /** * Get a rule by ID */ getRule(id: string): Rule | undefined; /** * Get all rules */ getAllRules(): Rule[]; /** * Enable/disable a rule */ setRuleEnabled(id: string, enabled: boolean): boolean; /** * Evaluate content against a single rule */ private evaluateRule; /** * Evaluate content against all rules */ evaluate(content: string, context?: RuleContext): RulesEvaluation; /** * Quick check if content passes rules */ check(content: string, context?: RuleContext): boolean; /** * Apply rules and get transformed content */ apply(content: string, context?: RuleContext): string; /** * Get rules by tag */ getRulesByTag(tag: string): Rule[]; /** * Clear all rules */ clear(): void; /** * Export rules to JSON */ toJSON(): Rule[]; } /** * Create a rules manager */ export declare function createRulesManager(config?: RulesManagerConfig): RulesManager; /** * Create common safety rules */ export declare function createSafetyRules(): Rule[]; export default RulesManager;