/** * Guardian - Main runtime protection class * * Provides a unified interface for all guardian features: * - Interceptor for LLM client wrapping * - Action validation for tool/function calls * - Intent classification * - Input/output guardrails * - Policy-based configuration * - Circuit breaker protection * - Metrics collection */ import type { ModelClient } from '@artemiskit/core'; import { RateLimiter } from './circuit-breaker'; import { type GuardrailsConfig } from './guardrails'; import { GuardianBlockedError, GuardianInterceptor, type GuardrailFn } from './interceptor'; import type { ActionDefinition, ContentValidationConfig, GuardianEventHandler, GuardianMetrics, GuardianMode, GuardianModeCanonical, GuardianPolicy, MultiTurnConfig, Violation } from './types'; /** * Normalize Guardian mode to canonical form with deprecation warning * @param mode - The mode to normalize * @returns The canonical mode */ export declare function normalizeGuardianMode(mode: GuardianMode): GuardianModeCanonical; /** * Guardian configuration options */ export interface GuardianConfig { /** * Operating mode * * Canonical modes (recommended): * - 'observe': Log only, never block (for monitoring) * - 'selective': Block high-confidence threats (threshold-based) * - 'strict': Block all detected violations (maximum protection) * * Legacy modes (deprecated): * - 'testing' → 'observe' * - 'guardian' → 'strict' * - 'hybrid' → 'selective' */ mode?: GuardianMode; /** Policy file path or policy object */ policy?: string | GuardianPolicy; /** LLM client for semantic validation and intent classification */ llmClient?: ModelClient; /** Enable input validation */ validateInput?: boolean; /** Enable output validation */ validateOutput?: boolean; /** Block on validation failure */ blockOnFailure?: boolean; /** * Content validation strategy configuration * * @default { strategy: 'semantic', semanticThreshold: 0.9 } */ contentValidation?: ContentValidationConfig; /** Custom guardrails configuration (pattern-based) */ guardrails?: GuardrailsConfig; /** * Multi-turn detection configuration * * Enable to detect attacks that span multiple messages: * - Trust-building before sensitive requests * - Escalating risk patterns * - Context manipulation claims * - Split payload attacks */ multiTurn?: MultiTurnConfig; /** Custom action definitions */ allowedActions?: ActionDefinition[]; /** Event handler */ onEvent?: GuardianEventHandler; /** Enable metrics collection */ collectMetrics?: boolean; /** Enable logging */ enableLogging?: boolean; } /** * Guardian class - main runtime protection API */ export declare class Guardian { private config; private policy; private circuitBreaker; private rateLimiter?; private metricsCollector; private actionValidator; private intentClassifier; private semanticValidator?; private inputGuardrails; private outputGuardrails; private eventHandlers; /** The normalized (canonical) mode after processing legacy modes */ private normalizedMode; constructor(config?: GuardianConfig); /** * Wrap a model client with guardian protection * * Note: Checks circuit breaker on each LLM request via the shouldAllow callback. * When the circuit is open due to detected attack patterns, all LLM requests are blocked. */ protect(client: ModelClient): GuardianInterceptor; /** * Validate a tool/function call */ validateAction(toolName: string, args: Record, agentId?: string): Promise<{ valid: boolean; violations: Violation[]; sanitizedArguments?: Record; requiresApproval?: boolean; }>; /** * Classify intent of a message */ classifyIntent(text: string): Promise; /** * Validate input content */ validateInput(content: string): Promise<{ valid: boolean; violations: Violation[]; transformedContent?: string; }>; /** * Validate output content */ validateOutput(content: string): Promise<{ valid: boolean; violations: Violation[]; transformedContent?: string; }>; /** * Get current metrics */ getMetrics(): GuardianMetrics; /** * Get circuit breaker state */ getCircuitBreakerState(): { state: string; violationCount: number; timeUntilReset: number; }; /** * Get rate limit status */ getRateLimitStatus(): ReturnType | undefined; /** * Get the current policy */ getPolicy(): GuardianPolicy; /** * Get the normalized (canonical) operating mode * * This returns the canonical mode even if a legacy mode was configured. */ getMode(): GuardianModeCanonical; /** * Check if Guardian should block based on mode and violation severity * * - observe: Never blocks * - selective: Blocks high-confidence/high-severity only * - strict: Blocks all violations */ shouldBlock(violation: Violation): boolean; /** * Get the content validation configuration */ getContentValidationConfig(): ContentValidationConfig; /** * Update policy at runtime */ updatePolicy(policy: GuardianPolicy): void; /** * Register an allowed action */ registerAction(action: ActionDefinition): void; /** * Add a custom guardrail */ addInputGuardrail(guardrail: GuardrailFn): void; /** * Add a custom output guardrail */ addOutputGuardrail(guardrail: GuardrailFn): void; /** * Register an event handler */ onEvent(handler: GuardianEventHandler): void; /** * Remove an event handler */ offEvent(handler: GuardianEventHandler): void; /** * Reset all metrics and state */ reset(): void; /** * Load or create policy */ private loadOrCreatePolicy; /** * Emit an event to all handlers */ private emit; } /** * Create a guardian instance */ export declare function createGuardian(config?: GuardianConfig): Guardian; export { GuardianBlockedError }; //# sourceMappingURL=guardian.d.ts.map