/** * Safety Engine — 四层风控引擎 * * 1. 内容安全审核(敏感词 + AI 审核) * 2. 频率限制(滑动窗口限速) * 3. 平台合规校验 * 4. 反封策略(随机延迟 + 活跃时段 + 冷却机制) */ import type { SafetyEngineConfig, SafetyCheckResult, ViolationType, SafetyLevel, RateLimit, RateLimitResult, PlatformRule, PlatformCheckResult } from "./types.js"; export declare class SafetyEngine { private config; private sensitiveWords; private whitelistWords; private platformRules; private rateLimits; private antiBlock; /** 频率计数器: key → { timestamps } */ private rateCounters; /** 每日发布计数 */ private dailyPublishCount; private lastResetDate; /** 连续失败计数器 */ private consecutiveFailures; constructor(config?: Partial); /** * 全面内容安全检查 * 包括敏感词、违规内容、个人信息等 */ checkContent(content: string, title?: string): SafetyCheckResult; /** * 过滤/替换内容中的违规部分 * 返回清理后的内容 */ sanitizeContent(content: string): { cleaned: string; replacements: number; }; /** * 检查频率是否允许 */ checkRateLimit(platform: string, action: RateLimit["action"]): RateLimitResult; /** 记录一次操作(用于频率计数) */ recordAction(platform: string, action: RateLimit["action"]): void; /** * 校验内容是否符合平台规则 */ checkPlatformRules(platform: string, data: { title?: string; content?: string; tags?: string[]; images?: string[]; }): PlatformCheckResult; /** 获取平台规则 */ getPlatformRule(platform: string): PlatformRule | undefined; /** 列出所有平台规则 */ listPlatformRules(): PlatformRule[]; /** * 获取发布前需要等待的随机延迟(毫秒) */ getRandomDelay(): number; /** * 检查当前时间是否在活跃时段 */ isActiveHour(): boolean; /** * 检查是否超过每日发布上限 */ checkDailyLimit(): { allowed: boolean; remaining: number; }; /** * 记录失败并检查是否需要冷却 */ recordFailure(platform: string): { needsCooldown: boolean; cooldownMs: number; }; /** 重置失败计数 */ resetFailure(platform: string): void; /** * 综合预发布检查 * 集成所有安全层,返回最终决策 */ prePublishCheck(platform: string, data: { title?: string; content?: string; tags?: string[]; images?: string[]; }): Promise<{ allowed: boolean; reasons: string[]; delayMs: number; contentCheck: SafetyCheckResult; platformCheck: PlatformCheckResult; rateCheck: RateLimitResult; dailyCheck: { allowed: boolean; remaining: number; }; }>; /** 获取风控状态摘要 */ getStatus(): { level: SafetyLevel; sensitiveWordCount: number; platformRuleCount: number; rateLimitCount: number; dailyPublishCount: number; dailyPublishLimit: number; activeHours: [number, number]; }; /** 添加自定义敏感词 */ addSensitiveWord(word: string, type?: ViolationType): void; /** 添加白名单词 */ addWhitelistWord(word: string): void; private getSeverity; private getTypeName; private calculateRiskScore; private determineAction; private generateSuggestions; private escapeRegex; } //# sourceMappingURL=engine.d.ts.map