| 2521 | return None |
| 2522 | |
| 2523 | def _extract_flow_entity_id(self, entity_payload: Dict[str, Any]) -> Optional[str]: |
| 2524 | if not isinstance(entity_payload, dict): |
| 2525 | return None |
| 2526 | |
| 2527 | candidates = [entity_payload] |
| 2528 | result = entity_payload.get("result") |
| 2529 | if isinstance(result, dict): |
| 2530 | candidates.append(result) |
| 2531 | data = result.get("data") |
| 2532 | if isinstance(data, dict): |
| 2533 | candidates.append(data) |
| 2534 | json_node = data.get("json") |
| 2535 | if isinstance(json_node, dict): |
| 2536 | candidates.append(json_node) |
| 2537 | nested_result = json_node.get("result") |
| 2538 | if isinstance(nested_result, dict): |
| 2539 | candidates.append(nested_result) |
| 2540 | |
| 2541 | for candidate in candidates: |
| 2542 | if not isinstance(candidate, dict): |
| 2543 | continue |
| 2544 | for key in ("entityId", "id", "parentEntityId"): |
| 2545 | entity_id = str(candidate.get(key) or "").strip() |
| 2546 | if entity_id: |
| 2547 | return entity_id |
| 2548 | |
| 2549 | return None |
| 2550 | |
| 2551 | def _extract_turn_count(self, session_detail: Dict[str, Any]) -> int: |
| 2552 | if not isinstance(session_detail, dict): |