UNPKG

mcp-decisive

Version:

MCP server for WRAP decision-making framework with structured output

74 lines 3.79 kB
import { ok, err } from 'neverthrow'; import { OptionListModel } from '../term/option.js'; // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Implementation Section // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Business rule: Validate request const validateRegisterRequest = (request) => { if (!request.options || request.options.length === 0) { return err({ type: 'ValidationFailed', reason: 'Options list cannot be empty' }); } return ok(request); }; // Business rule: Register options directly using term models const registerOptionList = (request) => { // Use term model to create properly validated OptionList const requestedOptionList = { options: request.options }; return OptionListModel.create(requestedOptionList) .mapErr(errors => ({ type: 'OptionListCreationFailed', details: errors })); }; // Command implementation using functional composition const registerOptionsCommand = (request) => validateRegisterRequest(request) .andThen(validRequest => registerOptionList(validRequest) .andThen(optionList => { const event = { type: 'OptionsGenerated', optionList }; return ok(event); })); // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Error Handling Utilities // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ const OptionSelectionErrorHandler = { // Smart constructor for validation errors validationFailed: (reason) => ({ type: 'ValidationFailed', reason }), // Convert errors to user-friendly messages toString: (error) => { switch (error.type) { case 'ValidationFailed': return `Validation failed: ${error.reason}`; case 'OptionListCreationFailed': return `Option list creation failed: ${error.details.map(d => d.message).join(', ')}`; default: // Exhaustive check - TypeScript will error if we miss a case const _exhaustive = error; throw new Error(`Unhandled error type: ${_exhaustive}`); } } }; // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Public API - Expose only what's needed // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ /** * Option Selection Aggregate - The public interface for option selection commands * * @command registerOptions - Register 3-5 options directly * @utility toErrorMessage - Convert errors to user-friendly strings */ export const OptionSelectionAggregate = { registerOptions: registerOptionsCommand, toErrorMessage: OptionSelectionErrorHandler.toString, }; //# sourceMappingURL=option-selection.js.map