(case: dict[str, Any], state: DifyRuntimeState)
| 236 | |
| 237 | |
| 238 | def evaluate_case(case: dict[str, Any], state: DifyRuntimeState) -> bool: |
| 239 | conditions = case.get("conditions") or [] |
| 240 | if not conditions: |
| 241 | return False |
| 242 | logical = str(case.get("logical_operator") or "and").lower() |
| 243 | results: list[bool] = [] |
| 244 | for cond in conditions: |
| 245 | if not isinstance(cond, dict): |
| 246 | continue |
| 247 | selector = cond.get("variable_selector") or [] |
| 248 | left = state.resolve_selector(selector) |
| 249 | results.append( |
| 250 | _compare( |
| 251 | left, |
| 252 | str(cond.get("comparison_operator") or "="), |
| 253 | cond.get("value"), |
| 254 | str(cond.get("varType")) if cond.get("varType") is not None else None, |
| 255 | ) |
| 256 | ) |
| 257 | if not results: |
| 258 | return False |
| 259 | if logical == "or": |
| 260 | return any(results) |
| 261 | return all(results) |
| 262 | |
| 263 | |
| 264 | def evaluate_handle(handle: str, cases: list[dict[str, Any]], state: DifyRuntimeState) -> bool: |
no test coverage detected