UNPKG

@bonginkan/maria

Version:

MARIA OS v5.9.5 – Self-Evolving Organizational Intelligence OS | Speed Improvement Phase 3: LLM Optimization + Command Refactoring | Performance Measurement + Run Evidence System | Zero ESLint/TypeScript Errors | 人とAIが役割を持ち、学び、進化し続けるための仕事のOS | GraphRAG ×

96 lines (95 loc) 2.7 kB
/** * Safe Expression Evaluator with Sandboxing * * Provides secure expression evaluation for conditional logic * without exposing dangerous JavaScript execution */ import { EventEmitter } from "node:events"; export interface ExpressionContext { variables: Record<string, unknown>; functions: Record<string, (...args: unknown[]) => unknown>; metadata: { userId: string; correlationId: string; timestamp: number; }; } export interface EvaluationResult { success: boolean; result?: unknown; error?: string; executionTime: number; expressionComplexity: number; } export interface ExpressionAnalysis { complexity: number; usedVariables: string[]; usedFunctions: string[]; hasUnsafePatterns: boolean; estimatedExecutionTime: number; } export declare class SafeExpressionEvaluator extends EventEmitter { private readonly maxComplexity; private readonly maxExecutionTime; private readonly maxDepth; private readonly allowedOperators; private readonly safeBuiltins; constructor(); /** * Evaluate expression safely */ evaluate(expression: string, context: ExpressionContext): Promise<EvaluationResult>; /** * Analyze expression for complexity and safety */ analyzeExpression(expression: string): ExpressionAnalysis; /** * Calculate expression complexity */ private calculateComplexity; /** * Extract variable names from expression */ private extractVariables; /** * Extract function names from expression */ private extractFunctions; /** * Check if identifier is a keyword or built-in */ private isKeywordOrBuiltin; /** * Create sandboxed execution environment */ private createSandbox; /** * Execute expression with timeout protection */ private executeWithTimeout; /** * Mask sensitive data in expressions for logging */ private maskSensitiveData; /** * Batch evaluate multiple expressions */ evaluateMultiple(expressions: Array<{ id: string; expression: string; }>, context: ExpressionContext): Promise<Array<{ id: string; result: EvaluationResult; }>>; /** * Create a new context with additional variables */ createContext(variables: Record<string, unknown>, functions?: Record<string, (...args: unknown[]) => unknown>, metadata?: Partial<ExpressionContext["metadata"]>): ExpressionContext; /** * Get evaluator health status */ getHealthStatus(): { status: "healthy" | "degraded" | "unhealthy"; details: unknown; }; }