UNPKG

semantic-prompt-mcp

Version:

MCP server for semantic prompt framework - NLP-inspired adaptive reasoning engine for LLM orchestration

73 lines 2.96 kB
/** * Validation utilities for semantic-prompt-mcp */ import { parameterNormalizer } from './parameterNormalizer.js'; import { VALIDATION_PATTERNS } from '../constants/index.js'; export class ValidationUtils { static validateThoughtData(input, prompts) { const normalized = parameterNormalizer.normalizeChainOfThoughtParams(input); const data = normalized; if (!data.thought || typeof data.thought !== 'string') { throw new Error(prompts.errors.invalidThought); } if (!data.thoughtNumber || typeof data.thoughtNumber !== 'number') { throw new Error(prompts.errors.invalidThoughtNumber); } if (!data.totalThoughts || typeof data.totalThoughts !== 'number') { throw new Error(prompts.errors.invalidTotalThoughts); } if (typeof data.nextThoughtNeeded !== 'boolean') { data.nextThoughtNeeded = true; } return { thought: data.thought, thoughtNumber: data.thoughtNumber, totalThoughts: data.totalThoughts, nextThoughtNeeded: Boolean(data.nextThoughtNeeded), commandSelection: data.commandSelection, agentSelection: data.agentSelection, isRevision: data.isRevision, revisesThought: data.revisesThought, branchFromThought: data.branchFromThought, branchId: data.branchId, needsMoreThoughts: data.needsMoreThoughts, }; } static validateCommandName(command, availableCommands) { const normalizedCommand = command.toLowerCase(); if (availableCommands && availableCommands.length > 0) { const commandExists = availableCommands.includes(normalizedCommand); if (!commandExists) { throw new Error(`Command '${command}' not found. Available commands: ${availableCommands.join(', ')}`); } } else { if (!VALIDATION_PATTERNS.SAFE_NAME.test(normalizedCommand)) { throw new Error(`Invalid command name '${command}'. Use lowercase letters, numbers, and hyphens only.`); } } } static validateAgents(agents, availableAgents) { const available = new Set(availableAgents); const invalid = agents .map(a => a.toLowerCase()) .filter(a => !available.has(a)); if (invalid.length > 0) { throw new Error(`Invalid agents: ${invalid.join(', ')}`); } return agents.map(a => a.toLowerCase()); } static extractInputData(input) { try { const inputData = input; return { thoughtNumber: inputData?.thoughtNumber || 1, totalThoughts: inputData?.totalThoughts || 4 }; } catch { return { thoughtNumber: 1, totalThoughts: 4 }; } } } //# sourceMappingURL=validation.js.map