export class ContentSafetyError extends Error { public readonly isSafetyRejection = true; constructor(message: string) { super(message); this.name = "ContentSafetyError"; Object.setPrototypeOf(this, ContentSafetyError.prototype); } } export function isContentSafetyError(err: any): boolean { if (!err) return false; if (err.isSafetyRejection || err.name === "ContentSafetyError") return true; const msg = String(err.message || err.error || err || "").toLowerCase(); return ( msg.includes("safety filter") || msg.includes("prohibited_content") || msg.includes("harm_category") || msg.includes("safe-for-work") || msg.includes("finishreason: safety") || msg.includes("finishreason: blocklist") || msg.includes("blockreason") || msg.includes("content safety") || msg.includes("safety policy") || msg.includes("violates safety") ); }