UNPKG

modsure

Version:

Check user content against your site rules using Jev.

42 lines (41 loc) • 1.25 kB
export interface Rule { id: string; /** The site's rule in plain language, e.g. "No unsolicited advertising." */ description: string; /** User-facing rejection message. Defaults to description. */ message?: string; /** Reject when the violation probability is >= this value (0–1). */ threshold?: number; } export interface RuleCheck { id: string; description: string; message: string; threshold: number; probability: number; violated: boolean; } export interface ModerationResult { allowed: boolean; violations: RuleCheck[]; checks: RuleCheck[]; model: string; } export interface ModeratorOptions { apiKey: string; rules: readonly Rule[]; threshold?: number; model?: string; timeoutMs?: number; fetch?: typeof globalThis.fetch; } export interface Moderator { moderate(content: string, options?: { signal?: AbortSignal }): Promise<ModerationResult>; } export type ModerationErrorCode = 'HTTP_ERROR' | 'INVALID_RESPONSE' | 'ABORTED' | 'TIMEOUT' | 'NETWORK_ERROR'; export class ModerationError extends Error { constructor(message: string, code: ModerationErrorCode, status?: number); code: ModerationErrorCode; status?: number; } export function createModerator(options: ModeratorOptions): Moderator;