UNPKG

@openguardrails/moltguard

Version:

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

114 lines 3.9 kB
/** * BusinessReporter - Reports telemetry data to Core's Business Dashboard. * * Only active when the agent's account is on the "business" plan. * Accumulates events and agentic hours locally, then flushes to Core * every 60 seconds via POST /api/v1/business/telemetry. */ import type { CoreCredentials } from "./config.js"; import type { Logger } from "./types.js"; export type BusinessEvent = { type: string; toolName?: string; category?: string; riskLevel?: string; blocked?: boolean; durationMs?: number; summary?: string; metadata?: Record<string, unknown>; }; export type AgenticHoursAccum = { toolCallDurationMs: number; llmDurationMs: number; totalDurationMs: number; toolCallCount: number; llmCallCount: number; sessionCount: number; blockCount: number; riskEventCount: number; }; export type ScanSummaryAccum = { scanType: string; totalScans: number; riskyScans: number; categoryCounts: Record<string, number>; }; export type GatewaySummaryAccum = { totalRequests: number; totalRedactions: number; typeCounts: Record<string, number>; }; export type SecretSummaryAccum = { totalDetections: number; typeCounts: Record<string, number>; }; export type BusinessReporterConfig = { coreUrl: string; pluginVersion: string; }; export declare class BusinessReporter { private enabled; private config; private log; private credentials; private ownerName; private machineName; private machineId; private agentName; private provider; private model; /** Buffered events waiting to be flushed */ private pendingEvents; /** Accumulated agentic hours since last flush */ private hoursAccum; /** Accumulated scan summaries since last flush */ private scanAccum; /** Accumulated gateway activity since last flush */ private gatewayAccum; /** Accumulated secret detections since last flush */ private secretAccum; /** Periodic flush timer */ private flushInterval; /** Whether we're currently flushing */ private flushing; constructor(config: BusinessReporterConfig, log: Logger); /** * Initialize the reporter. Only enables if the account plan is "business". * Call this after fetching the account info from Core. */ initialize(plan: string): void; /** Set Core credentials */ setCredentials(credentials: CoreCredentials | null): void; /** Update agent profile info (called when profile changes) */ setProfile(profile: { ownerName?: string; agentName?: string; provider?: string; model?: string; }): void; /** Whether the reporter is active */ isEnabled(): boolean; /** Stop the reporter and flush remaining data */ stop(): Promise<void>; /** Record a tool call */ recordToolCall(toolName: string, category: string, durationMs: number, blocked: boolean): void; /** Record an LLM call */ recordLlmCall(durationMs: number, model?: string): void; /** Record a detection event */ recordDetection(riskLevel: string, blocked: boolean, summary?: string): void; /** Record a session start/end */ recordSession(type: "start" | "end", durationMs?: number): void; /** Record a scan result (static or dynamic) */ recordScanResult(scanType: "static" | "dynamic", categories: string[], risky: boolean): void; /** Record gateway sanitization activity */ recordGatewayActivity(redactionCount: number, typeCounts: Record<string, number>): void; /** Record secret detection */ recordSecretDetection(typeCounts: Record<string, number>): void; private startPeriodicFlush; private maybeFlush; flush(): Promise<void>; private emptyAccum; private emptyGatewayAccum; private emptySecretAccum; } //# sourceMappingURL=business-reporter.d.ts.map