Building a configurator
Define parameters, formulas and rules so a custom product prices itself from a structured form.
A configurator is an engine definition: a set of parameters, derived values, rules and outputs. The same engine and test bench drive Servicing and Configure, so the semantics are identical across both.
Parameters
Each parameter has a key, a label and a kind: number, dimension, select, boolean or text. Dimension parameters carry a canonical unit such as mm, um or deg, and inputs are normalised to that unit before any formula runs. Selects can attach numeric meta to each option, which formulas read with lookup_meta.
- min, max and step constrain numeric and dimension inputs.
- required marks a parameter that must be supplied before a run.
- default seeds the form and help explains the field inline.
Formulas
Derived values are expressions evaluated in order, each able to reference parameters and earlier derived values. Outputs produce price, cost, leadtime_days and any custom keys. Expressions use a restricted mathjs parser with a function whitelist: round, ceil, floor, abs, min, max, sqrt, pow, clamp, if, tiered and lookup_meta among them. There is no assignment and no loops.
// derived
grind_minutes = 18 + flutes * 6 + if(neck, 8, 0)
// outputs
price = round(cost * 2.2, 2)
leadtime_days = if(coating_strip, 7, 4)Units and tiers
Because dimension parameters are normalised first, a formula always sees the same unit regardless of how the value was entered. The tiered function returns the value of the highest threshold less than or equal to its input, which is the usual way to express banded base rates.
base = tiered(diameter_mm, [[0, 8.50], [6, 10.00], [12, 14.00], [20, 22.00]])Conditions and rules
Rules run after derived values and before outputs. Each rule has a when condition and an effect. A block effect stops the run and returns its message, so use it for work you cannot take. A warn effect attaches to the result and lets the run continue, so use it for work that needs review.
Block what you cannot make. Warn on what needs a human to look. A block aborts the run and explains why, a warn is advisory and still prices.
Money is calculated with decimal precision and converted to integer minor units with round half-up only at the final step. Evaluation is deterministic: the same definition version and the same inputs always give the same outputs.