import type { Message } from '@agforge/core'; /** * 校验违规信息 */ export type SanitizeViolation = { /** 触发该违规的规则 ID */ ruleId: string; /** 人类可读的违规描述 */ message: string; }; /** * 规则处理结果 */ export type SanitizeResult = { /** 发现的违规列表。空数组表示消息合法。 */ violations: Array; /** 修复后的消息列表(单次遍历同时产出) */ fixed: Array; }; /** * 消息校验规则接口。 * * 每条规则负责检测一种非法消息模式,并提供对应的修复逻辑。 * process() 在单次遍历中同时完成检测和修复,避免重复遍历消息列表。 * 管道执行器根据模式决定使用 violations(warn)还是 fixed(fix)。 */ export type SanitizeRule = { /** 规则唯一标识,用于日志和配置 */ readonly id: string; /** * 在单次遍历中同时检测违规并生成修复后的消息列表。 * * - 'warn' 模式:管道执行器仅使用 violations,忽略 fixed * - 'fix' 模式:管道执行器使用 violations 记录日志,并将 fixed 传递给下一规则 * * @returns 包含违规列表和修复后消息的结果对象 */ process(messages: ReadonlyArray): SanitizeResult; };