UNPKG

@dollhousemcp/mcp-server

Version:

DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.

231 lines 9.11 kB
/** * Constants for Ensemble elements * * Defines limits, defaults, and security constants following patterns from other elements * * CONFIGURABILITY (Issue #368): * Limits can be configured via: * 1. Environment variables (e.g., ENSEMBLE_MAX_ELEMENTS=100) * 2. Global configuration object (setGlobalEnsembleLimits()) * 3. Per-ensemble overrides via metadata.resourceLimits * * Priority: Per-ensemble > Global config > Environment variables > Defaults * * @example * // 1. Environment variables (set before server starts) * // ENSEMBLE_MAX_ELEMENTS=100 * // ENSEMBLE_MAX_NESTING_DEPTH=3 * // ENSEMBLE_MAX_ACTIVATION_TIME=60000 * * @example * // 2. Global configuration (programmatic) * import { setGlobalEnsembleLimits } from './constants.js'; * setGlobalEnsembleLimits({ * maxElements: 75, * maxNestingDepth: 4, * maxActivationTime: 45000 * }); * * @example * // 3. Per-ensemble override (in ensemble metadata) * const ensemble = new Ensemble({ * name: 'my-ensemble', * resourceLimits: { * maxActiveElements: 25, // Maps to MAX_ELEMENTS * maxExecutionTimeMs: 10000 // Maps to MAX_ACTIVATION_TIME * } * }, elements, metadataService); */ /** * Absolute maximum values for security - cannot be exceeded even with configuration * These prevent resource exhaustion and DoS attacks */ export declare const ENSEMBLE_HARD_LIMITS: { readonly MAX_ELEMENTS: 500; readonly MAX_NESTING_DEPTH: 10; readonly MAX_ACTIVATION_TIME: 300000; readonly MAX_CONTEXT_SIZE: 10000; readonly MAX_CONTEXT_VALUE_SIZE: 1048576; readonly MAX_DEPENDENCIES: 50; readonly MAX_CONDITION_LENGTH: 1000; }; /** * Minimum values for safety - configured values cannot go below these */ export declare const ENSEMBLE_MIN_LIMITS: { readonly MAX_ELEMENTS: 1; readonly MAX_NESTING_DEPTH: 0; readonly MAX_ACTIVATION_TIME: 1000; readonly MAX_CONTEXT_SIZE: 10; readonly MAX_CONTEXT_VALUE_SIZE: 100; readonly MAX_DEPENDENCIES: 1; readonly MAX_CONDITION_LENGTH: 10; }; /** * Interface for configurable ensemble limits * All properties are optional - unset properties use defaults */ export interface EnsembleLimitsConfig { /** Maximum elements in an ensemble (default: 50, max: 500) */ maxElements?: number; /** Maximum depth of nested ensembles (default: 5, max: 10) */ maxNestingDepth?: number; /** Maximum activation time in ms (default: 30000, max: 300000) */ maxActivationTime?: number; /** Maximum keys in shared context (default: 1000, max: 10000) */ maxContextSize?: number; /** Maximum size of a context value in bytes (default: 10000, max: 1048576) */ maxContextValueSize?: number; /** Maximum dependencies per element (default: 10, max: 50) */ maxDependencies?: number; /** Maximum length of activation condition (default: 200, max: 1000) */ maxConditionLength?: number; } /** * Set global ensemble limits configuration * Values are validated against hard limits * * @param config - Configuration object with desired limits * @example * setGlobalEnsembleLimits({ * maxElements: 100, * maxNestingDepth: 3, * maxActivationTime: 60000 * }); */ export declare function setGlobalEnsembleLimits(config: EnsembleLimitsConfig): void; /** * Get current global ensemble limits configuration * @returns Copy of current global config */ export declare function getGlobalEnsembleLimits(): Readonly<EnsembleLimitsConfig>; /** * Reset global ensemble limits to defaults (clears all overrides) */ export declare function resetGlobalEnsembleLimits(): void; /** * Resolved ensemble limits structure * Uses number type (not literal types) since values are computed at runtime */ export interface ResolvedEnsembleLimits { readonly MAX_ELEMENTS: number; readonly MAX_NESTING_DEPTH: number; readonly MAX_ACTIVATION_TIME: number; readonly MAX_CONTEXT_SIZE: number; readonly MAX_CONTEXT_VALUE_SIZE: number; readonly MAX_DEPENDENCIES: number; readonly MAX_CONDITION_LENGTH: number; } /** * Get effective limits with proper priority: * Per-ensemble override > Global config > Environment variable > Default * * @param perEnsembleOverrides - Optional per-ensemble limit overrides * @returns Resolved limits object */ export declare function getEffectiveLimits(perEnsembleOverrides?: Partial<EnsembleLimitsConfig>): ResolvedEnsembleLimits; /** * Resource limits to prevent DoS attacks and ensure system stability * * Note: Rate limiting is not implemented at the Ensemble level because: * 1. The activationInProgress flag already prevents concurrent activations * 2. Rate limiting should be handled at the handler/API level, not in the domain model * 3. Different deployment scenarios may have different rate limiting requirements * * CONFIGURABILITY: Use getEffectiveLimits() to get limits that respect * environment variables, global config, and per-ensemble overrides. * This constant provides the base defaults for backwards compatibility. */ export declare const ENSEMBLE_LIMITS: { readonly MAX_ELEMENTS: 50; readonly MAX_NESTING_DEPTH: 5; readonly MAX_ACTIVATION_TIME: 30000; readonly MAX_CONTEXT_SIZE: 1000; readonly MAX_CONTEXT_VALUE_SIZE: 10000; readonly MAX_DEPENDENCIES: 10; readonly MAX_CONDITION_LENGTH: 200; }; /** * Default values for ensemble configuration */ export declare const ENSEMBLE_DEFAULTS: { readonly ACTIVATION_STRATEGY: "sequential"; readonly CONFLICT_RESOLUTION: "last-write"; readonly ELEMENT_ROLE: "support"; readonly PRIORITY: 50; readonly ALLOW_NESTED: true; readonly ACTIVATION_TIMEOUT: 5000; readonly MAX_NESTING_DEPTH: 5; readonly CONTEXT_SHARING: "selective"; }; /** * Supported activation strategies * Must match ActivationStrategy type in types.ts */ export declare const ACTIVATION_STRATEGIES: readonly ["all", "sequential", "lazy", "conditional", "priority"]; /** * Supported conflict resolution strategies */ export declare const CONFLICT_STRATEGIES: readonly ["last-write", "first-write", "priority", "merge", "error"]; /** * Element roles within an ensemble */ export declare const ELEMENT_ROLES: readonly ["primary", "support", "override", "monitor", "core"]; /** * Activation modes for elements */ export declare const ACTIVATION_MODES: readonly ["always", "on-demand", "conditional"]; /** * Security event types for ensemble operations * These are logged via SecurityMonitor for audit trails */ export declare const ENSEMBLE_SECURITY_EVENTS: { readonly CIRCULAR_DEPENDENCY: "ENSEMBLE_CIRCULAR_DEPENDENCY"; readonly RESOURCE_LIMIT_EXCEEDED: "ENSEMBLE_RESOURCE_LIMIT_EXCEEDED"; readonly ACTIVATION_TIMEOUT: "ENSEMBLE_ACTIVATION_TIMEOUT"; readonly ACTIVATION_FAILED: "ENSEMBLE_ACTIVATION_FAILED"; readonly SUSPICIOUS_CONDITION: "ENSEMBLE_SUSPICIOUS_CONDITION"; readonly CONDITION_EVALUATION_FAILED: "ENSEMBLE_CONDITION_EVALUATION_FAILED"; readonly NESTED_DEPTH_EXCEEDED: "ENSEMBLE_NESTED_DEPTH_EXCEEDED"; readonly CONTEXT_SIZE_EXCEEDED: "ENSEMBLE_CONTEXT_SIZE_EXCEEDED"; readonly CONTEXT_VALUE_TOO_LARGE: "ENSEMBLE_CONTEXT_VALUE_TOO_LARGE"; readonly SAVED: "ENSEMBLE_SAVED"; readonly IMPORTED: "ENSEMBLE_IMPORTED"; readonly DELETED: "ENSEMBLE_DELETED"; readonly ACTIVATED: "ENSEMBLE_ACTIVATED"; readonly DEACTIVATED: "ENSEMBLE_DEACTIVATED"; }; /** * Error messages for validation */ export declare const ENSEMBLE_ERRORS: { readonly TOO_MANY_ELEMENTS: "Ensemble cannot contain more than 50 elements"; readonly NESTING_TOO_DEEP: "Ensemble nesting depth cannot exceed 5"; readonly CIRCULAR_DEPENDENCY: "Circular dependency detected in ensemble"; readonly INVALID_STRATEGY: "Invalid activation strategy"; readonly INVALID_CONFLICT_RESOLUTION: "Invalid conflict resolution strategy"; readonly INVALID_ELEMENT_ROLE: "Invalid element role"; readonly INVALID_ACTIVATION_MODE: "Invalid activation mode"; readonly ELEMENT_NOT_FOUND: "Element not found in ensemble"; readonly ACTIVATION_TIMEOUT: "Ensemble activation timed out"; readonly CONTEXT_OVERFLOW: "Shared context size exceeded limits"; readonly ELEMENT_LOAD_FAILED: "Failed to load element"; readonly CONDITION_EVALUATION_FAILED: "Failed to evaluate activation condition"; }; /** * Regex patterns for validation */ export declare const ENSEMBLE_PATTERNS: { readonly CONDITION_PATTERN: RegExp; readonly ELEMENT_NAME_PATTERN: RegExp; }; /** * Dangerous keywords that should be rejected in conditions * * These patterns are checked separately from CONDITION_PATTERN for security. * Note: We focus on dangerous code execution patterns rather than unsupported * operators, since condition evaluation isn't implemented yet. When it is * implemented, the evaluator will handle operator support properly. */ export declare const DANGEROUS_CONDITION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]; //# sourceMappingURL=constants.d.ts.map