Fix NCalc case sensitivity and add formula validation

- Normalize IF/Abs/Pow/etc. to lowercase before evaluation so AI-generated
  or manually typed uppercase function names no longer cause "Function not
  found" errors
- Add NormalizeAndValidate() which normalizes then does a parse-only check
  on save — invalid formulas are rejected with a clear error before storing
- Update AI system prompt to list all functions in lowercase and explicitly
  call out case-sensitivity; add if() to the supported function list
- Add collapsible NCalc quick-reference panel in the formula editor showing
  all operators, functions (lowercase), built-in variables, and an example

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 22:09:43 -04:00
parent ca7e905832
commit efc4e9dadf
4 changed files with 97 additions and 3 deletions
@@ -19,4 +19,12 @@ public interface ICustomFormulaAiService
/// Safe server-side only — no user-controlled code execution.
/// </summary>
EvaluateFormulaResponse EvaluateFormula(EvaluateFormulaRequest request);
/// <summary>
/// Normalizes NCalc built-in function names to lowercase (IF→if, Abs→abs, etc.) then
/// attempts a parse-only evaluation to catch syntax errors before the formula is saved.
/// Returns the normalized formula string and a null error on success, or the original
/// formula and an error message on failure.
/// </summary>
(string NormalizedFormula, string? Error) NormalizeAndValidate(string formula);
}