/** * Dynamic Extract Helper Functions * * Utility functions for parsing next_prompt configurations, * resolving dynamic values, and evaluating conditional branches. */ import type { Logger, NextPromptConfig, NextPromptBranch, NextPromptCondition } from './types.js'; /** * Result of resolving next_prompt configuration */ export interface ResolvedNextPrompt { /** Resolved prompt area */ prompt_area: string; /** Resolved prompt key */ prompt_key: string; /** Which resolution method was used */ resolution_type: 'simple' | 'branch' | 'default'; /** Branch index if a branch was matched */ branch_index?: number; } /** * Result of multi-value next_prompt resolution (for wildcard [*] JSONPaths) */ export interface ResolvedNextPromptMulti { /** Array of resolved next prompts (one for each matched value) */ resolutions: ResolvedNextPrompt[]; /** Whether this was a multi-value resolution (true if wildcards were used) */ is_multi: boolean; /** The source JSONPath that contained wildcards (if any) */ source_jsonpath?: string; /** Whether max_branches limit was reached */ truncated?: boolean; } /** * Parse the next_prompt JSON string from database into NextPromptConfig * * @param json_string - JSON string from database next_prompt field * @param logger - Logger instance * @returns Parsed NextPromptConfig or null if invalid/empty * * @example * ```typescript * const config = parse_next_prompt_config('{"static_prompt_area": "doc"}', logger); * // Returns: { static_prompt_area: 'doc' } * * const empty = parse_next_prompt_config(null, logger); * // Returns: null * ``` */ export declare function parse_next_prompt_config(json_string: string | null, logger: Logger): NextPromptConfig | null; /** * Evaluate a single condition against LLM output * * @param condition - The condition to evaluate * @param llm_output - Parsed JSON output from LLM * @param logger - Logger instance * @returns true if condition matches * * @example * ```typescript * const condition = { field: '$.total', operator: '>', value: 1000 }; * const output = { total: 1500 }; * * evaluate_condition(condition, output, logger); * // Returns: true * ``` */ export declare function evaluate_condition(condition: NextPromptCondition, llm_output: Record, logger: Logger): boolean; /** * Evaluate all conditions in a branch (AND logic) * All conditions must match for the branch to match * * @param branch - The branch to evaluate * @param llm_output - Parsed JSON output from LLM * @param logger - Logger instance * @returns true if all conditions match (or no conditions defined) */ export declare function evaluate_branch(branch: NextPromptBranch, llm_output: Record, logger: Logger): boolean; /** * Find the first matching branch and resolve its values * * @param config - The NextPromptConfig * @param llm_output - Parsed JSON output from LLM * @param logger - Logger instance * @returns Resolved next prompt info or null */ export declare function find_matching_branch(config: NextPromptConfig, llm_output: Record, logger: Logger): ResolvedNextPrompt | null; /** * Resolve next_prompt configuration to actual prompt_area and prompt_key * * Resolution priority: * 1. If branches defined: evaluate each branch in order, use first match * 2. If no branch matches and default_branch defined: use default_branch * 3. If no branches: use simple mode (static/dynamic values at root level) * * Within each branch/simple mode: * - static_prompt_area/key takes precedence over dynamic * - dynamic values are extracted from LLM output using JSONPath * * @param config - The NextPromptConfig * @param llm_output - Parsed JSON output from LLM * @param logger - Logger instance * @returns Resolved next prompt info or null if resolution failed * * @example * ```typescript * // Simple mode * const config = { * static_prompt_area: 'doc', * dynamic_prompt_key: '$.document_type' * }; * const output = { document_type: 'invoice' }; * * resolve_next_prompt(config, output, logger); * // Returns: { prompt_area: 'doc', prompt_key: 'invoice', resolution_type: 'simple' } * * // Conditional branching * const config2 = { * branches: [ * { * conditions: [{ field: '$.total', operator: '>', value: 1000 }], * static_prompt_area: 'doc', * static_prompt_key: 'high_value' * } * ], * default_branch: { * static_prompt_area: 'doc', * dynamic_prompt_key: '$.document_type' * } * }; * ``` */ export declare function resolve_next_prompt(config: NextPromptConfig, llm_output: Record, logger: Logger): ResolvedNextPrompt | null; /** * Validate that a NextPromptConfig has at least one valid configuration * At minimum, must have either: * - Both static_prompt_area and static_prompt_key (or dynamic equivalents) * - At least one branch with valid area/key configuration * - A default_branch with valid area/key configuration * * @param config - The NextPromptConfig to validate * @returns true if config is valid */ export declare function validate_next_prompt_config(config: NextPromptConfig): boolean; /** * Resolve next_prompt configuration with multi-value wildcard support * * When the dynamic_prompt_key or dynamic_prompt_area contains wildcards [*], * this function extracts ALL matching values and returns multiple resolutions. * * @param config - The NextPromptConfig * @param llm_output - Parsed JSON output from LLM * @param logger - Logger instance * @param max_branches - Maximum number of branches to return (default: 10) * @returns Multi-resolution result with array of resolved prompts * * @example * ```typescript * // LLM returns: { document_types: [{ name: 'invoice' }, { name: 'receipt' }] } * const config = { * static_prompt_area: 'doc', * dynamic_prompt_key: '$.document_types[*].name' * }; * * resolve_next_prompt_multi(config, output, logger); * // Returns: { * // resolutions: [ * // { prompt_area: 'doc', prompt_key: 'invoice', resolution_type: 'simple' }, * // { prompt_area: 'doc', prompt_key: 'receipt', resolution_type: 'simple' } * // ], * // is_multi: true, * // source_jsonpath: '$.document_types[*].name' * // } * ``` */ export declare function resolve_next_prompt_multi(config: NextPromptConfig, llm_output: Record, logger: Logger, max_branches?: number): ResolvedNextPromptMulti; //# sourceMappingURL=dynamic_extract_helpers.d.ts.map