UNPKG

@openguardrails/moltguard

Version:

AI agent security plugin for OpenClaw: prompt injection detection, PII sanitization, and monitoring dashboard

87 lines 2.8 kB
/** * EventReporter - Handles batched event reporting to Core. * * Responsibilities: * 1. Queue non-blocking events and flush them in batches (100ms window) * 2. Send blocking events synchronously and return block decisions * 3. Handle network failures gracefully (fail-open) * 4. Truncate large content to avoid timeouts */ import type { CoreCredentials } from "./config.js"; import type { Logger } from "./types.js"; import type { HookType, HookEventData } from "./hook-types.js"; export type BlockDecision = { block: true; reason: string; findings?: Array<{ riskLevel: string; riskType: string; reason: string; }>; }; export type EventReporterConfig = { coreUrl: string; pluginVersion: string; /** Timeout for API calls in ms */ timeoutMs?: number; /** Whether to enable batching (default: true) */ enableBatching?: boolean; }; export declare class EventReporter { private config; private log; private credentials; /** Sequence counter per session */ private sessionSeq; /** Run ID per session */ private sessionRunId; /** Event queue for batching */ private queue; /** Flush timer */ private flushTimer; /** Whether we're currently flushing */ private flushing; constructor(config: EventReporterConfig, log: Logger); /** Set Core credentials for authenticated API calls */ setCredentials(credentials: CoreCredentials | null): void; /** Set or get run ID for a session */ setRunId(sessionKey: string, runId: string): void; getRunId(sessionKey: string): string | undefined; /** Clear session state */ clearSession(sessionKey: string): void; /** * Report an event. For blocking hooks, this is synchronous and may return * a block decision. For non-blocking hooks, this queues the event for batching. */ report(sessionKey: string, hookType: HookType, data: HookEventData, blocking?: boolean): Promise<BlockDecision | undefined>; /** * Send a single event synchronously (for blocking hooks). * Returns a block decision if Core says to block, undefined otherwise. */ private reportSync; /** * Queue an event for batched sending. */ private queueEvent; /** * Flush all queued events to Core. */ flush(): Promise<void>; /** * Send a batch of events for a single session. */ private sendBatch; /** * Get next sequence number for a session. */ private getNextSeq; /** * Sanitize event data: truncate large content, remove secrets. */ private sanitizeEventData; /** * Stop the reporter and flush remaining events. */ stop(): Promise<void>; } //# sourceMappingURL=event-reporter.d.ts.map