| 19 | type_key = "switch" |
| 20 | |
| 21 | def execute(self, config: dict[str, Any], context: StepContext) -> StepResult: |
| 22 | expression = config.get("expression", "") |
| 23 | value = evaluate_expression(expression, context) |
| 24 | |
| 25 | # String-coerce for matching |
| 26 | str_value = str(value) if value is not None else "" |
| 27 | |
| 28 | cases = config.get("cases", {}) |
| 29 | for case_key, case_steps in cases.items(): |
| 30 | if str(case_key) == str_value: |
| 31 | return StepResult( |
| 32 | status=StepStatus.COMPLETED, |
| 33 | output={"matched_case": str(case_key), "expression_value": value}, |
| 34 | next_steps=case_steps, |
| 35 | ) |
| 36 | |
| 37 | # Default fallback |
| 38 | default_steps = config.get("default", []) |
| 39 | return StepResult( |
| 40 | status=StepStatus.COMPLETED, |
| 41 | output={"matched_case": "__default__", "expression_value": value}, |
| 42 | next_steps=default_steps, |
| 43 | ) |
| 44 | |
| 45 | def validate(self, config: dict[str, Any]) -> list[str]: |
| 46 | errors = super().validate(config) |