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.

105 lines 3.88 kB
/** * TriggerValidationService - Centralized trigger validation for all element types * * Eliminates duplicate trigger validation code across PersonaManager, SkillManager, * MemoryManager, TemplateManager, AgentManager, and EnsembleManager. * * Key Features: * - Unified validation rules for all element types (max 20 triggers, max 50 chars) * - Consistent validation algorithm across all element types * - Comprehensive error reporting and logging * - Full TypeScript type safety * * @example * ```typescript * import { triggerValidationService } from './services/TriggerValidationService'; * * const result = triggerValidationService.validateTriggers( * ['create', 'build', 'invalid!@#'], * ElementType.SKILL, * 'my-skill' * ); * * console.log(result.validTriggers); // ['create', 'build'] * console.log(result.rejectedTriggers); // [{ original: 'invalid!@#', reason: '...' }] * ``` */ import { ElementType } from '../../portfolio/types.js'; /** * Details about a rejected trigger */ export interface RejectedTrigger { /** Original trigger value before sanitization */ original: string; /** Human-readable reason why this trigger was rejected */ reason: string; } /** * Result of trigger validation operation */ export interface TriggerValidationResult { /** Successfully validated triggers (sanitized and validated) */ validTriggers: string[]; /** Triggers that failed validation with reasons */ rejectedTriggers: RejectedTrigger[]; /** Whether any triggers were rejected during validation */ hasRejections: boolean; /** Total count of input triggers (before validation) */ totalInput: number; /** Warnings about truncation, limit exceeded, etc. */ warnings: string[]; } /** * Service for validating and processing trigger arrays across all element types * * This service provides centralized trigger validation to eliminate code duplication * across element managers. All element types use the same validation rules: * - Maximum 20 triggers * - Maximum 50 characters per trigger * - Only alphanumeric, hyphens, underscores, @, and . allowed */ export declare class TriggerValidationService { constructor(); /** * Validate an array of triggers for a specific element type * * Validation process: * 1. Limit input array to MAX_TRIGGERS (20) * 2. For each trigger: * a. Convert to string * b. Sanitize (remove dangerous characters, trim, limit length to 50) * c. Check if empty after sanitization * d. Validate against regex pattern (/^[a-zA-Z0-9\-_@.]+$/) * 3. Collect valid and rejected triggers * 4. Log warnings if truncation or rejections occurred * * @param triggers - Raw trigger array from user input or metadata * @param elementType - Type of element being validated (used for logging context) * @param elementName - Name of element (used for logging context) * @returns Validation result with valid/rejected triggers and warnings * * @example * ```typescript * const result = service.validateTriggers( * ['create', 'build', 'test!@#', ''], * ElementType.SKILL, * 'code-generator' * ); * // result.validTriggers: ['create', 'build'] * // result.rejectedTriggers: [ * // { original: 'test!@#', reason: '(invalid format ...)' }, * // { original: '', reason: '(empty)' } * // ] * ``` */ validateTriggers(triggers: string[], elementType: ElementType, elementName: string): TriggerValidationResult; /** * Create an empty validation result * * @param totalInput - Total count of input triggers * @returns Empty result with no valid or rejected triggers * @private */ private createEmptyResult; } //# sourceMappingURL=TriggerValidationService.d.ts.map