/** * Fuzzy Enum Matching Utilities * * TIER 1 Token Efficiency Optimization * * Provides 3-tier fuzzy matching for action enums: * 1. Exact match (case-insensitive) * 2. Alias match (synonym mapping) * 3. Levenshtein distance (auto-correct typos) * * Returns guiding errors with suggestions when no match found. * * Philosophy: "Trust but verify through schema" + "Guiding errors teach the solution" */ export interface MatchResult { matched: T; exact: boolean; similarity: number; } export interface GuidingError { error: 'invalid_action' | 'invalid_identifier' | 'validation_error'; input: string; suggestions: Array<{ value: string; similarity: number; }>; message: string; } export type MatchOutcome = MatchResult | GuidingError; export declare function isGuidingError(result: unknown): result is GuidingError; /** * Calculate Levenshtein distance between two strings * Used for fuzzy matching tier 3 */ export declare function levenshtein(a: string, b: string): number; /** * Calculate similarity score (0-1) between two strings */ export declare function similarity(a: string, b: string): number; /** * Normalize input for matching: * - Lowercase * - Trim whitespace * - Replace hyphens/spaces with underscores */ export declare function normalizeInput(input: string): string; /** * Match an input against valid actions with 3-tier fuzzy matching * * @param input - User input to match * @param validActions - Array of valid action strings * @param aliases - Optional map of alias -> canonical action * @param threshold - Minimum similarity for fuzzy match (default: 0.6) * @returns MatchResult on success, GuidingError on failure * * @example * const actions = ['create', 'get', 'update', 'delete', 'list'] as const; * const aliases = { 'new': 'create', 'fetch': 'get', 'modify': 'update' }; * * matchAction('new', actions, aliases); // { matched: 'create', exact: false, similarity: 0.95 } * matchAction('creat', actions, aliases); // { matched: 'create', exact: false, similarity: 0.83 } * matchAction('xyz', actions, aliases); // GuidingError with suggestions */ export declare function matchAction(input: string, validActions: readonly T[], aliases?: Record, threshold?: number): MatchOutcome; /** * Resolve an identifier that could be UUID or name * * @param identifier - UUID or name to resolve * @param findById - Function to find by ID * @param findByName - Function to find by name * @param listAll - Optional function to list all for suggestions * @returns Entity on success, GuidingError on failure * * @example * const result = await resolveIdentifier( * 'Valeros', * id => charRepo.findById(id), * name => charRepo.findByName(name), * () => charRepo.listAll() * ); */ export declare function resolveIdentifier(identifier: string, findById: (id: string) => T | null, findByName: (name: string) => T | null, listAll?: () => T[]): T | GuidingError; /** * Standard CRUD action aliases * These cover common synonyms for CRUD operations */ export declare const CRUD_ALIASES: Record; /** * Extend base aliases with domain-specific ones */ export declare function extendAliases(base: Record, extensions: Record): Record; /** * Format a guiding error as an MCP tool response */ export declare function formatGuidingError(error: GuidingError): { content: Array<{ type: 'text'; text: string; }>; }; import { z } from 'zod'; /** * Create a Zod schema that accepts fuzzy-matched actions * * @example * const ActionSchema = createFuzzyActionSchema( * ['create', 'get', 'update', 'delete', 'list'], * CRUD_ALIASES * ); * * ActionSchema.parse('new'); // Returns 'create' * ActionSchema.parse('creat'); // Returns 'create' (fuzzy) * ActionSchema.parse('xyz'); // Throws with suggestions */ export declare function createFuzzyActionSchema(validActions: readonly T[], aliases?: Record, threshold?: number): z.ZodEffects; /** * Create a Zod schema that accepts flexible identifiers (UUID or name) * Note: This creates a passthrough schema - actual resolution happens at runtime */ export declare const FlexibleIdentifierSchema: z.ZodString; //# sourceMappingURL=fuzzy-enum.d.ts.map