Fallback function call detection using DOM parsing. This is used when the network interceptor doesn't capture function calls (e.g., due to timing issues or format changes). Args: page: Playwright page instance. req_id: Request ID for logging. logger: Logger inst
(
page: Any,
req_id: str,
logger: Any,
)
| 488 | |
| 489 | |
| 490 | async def detect_function_calls_from_dom( |
| 491 | page: Any, |
| 492 | req_id: str, |
| 493 | logger: Any, |
| 494 | ) -> Tuple[List[dict], str]: |
| 495 | """Fallback function call detection using DOM parsing. |
| 496 | |
| 497 | This is used when the network interceptor doesn't capture function calls |
| 498 | (e.g., due to timing issues or format changes). |
| 499 | |
| 500 | Args: |
| 501 | page: Playwright page instance. |
| 502 | req_id: Request ID for logging. |
| 503 | logger: Logger instance. |
| 504 | |
| 505 | Returns: |
| 506 | Tuple of (List of function call dicts, text content). |
| 507 | """ |
| 508 | if not page: |
| 509 | return [], "" |
| 510 | |
| 511 | try: |
| 512 | from api_utils.utils_ext.function_call_response_parser import ( |
| 513 | FunctionCallResponseParser, |
| 514 | ) |
| 515 | |
| 516 | parser = FunctionCallResponseParser(page, logger, req_id) |
| 517 | result = await parser.parse_function_calls() |
| 518 | |
| 519 | function_calls: List[dict] = [] |
| 520 | if result.has_function_calls and result.function_calls: |
| 521 | # Convert ParsedFunctionCall objects to dict format expected by stream |
| 522 | for fc in result.function_calls: |
| 523 | function_calls.append({"name": fc.name, "params": fc.arguments}) |
| 524 | |
| 525 | if FUNCTION_CALLING_DEBUG: |
| 526 | logger.info( |
| 527 | f"[{req_id}] DOM fallback detected {len(function_calls)} function call(s)" |
| 528 | ) |
| 529 | |
| 530 | return function_calls, result.text_content |
| 531 | |
| 532 | except Exception as e: |
| 533 | if FUNCTION_CALLING_DEBUG: |
| 534 | logger.debug(f"[{req_id}] DOM function call detection failed: {e}") |
| 535 | |
| 536 | return [], "" |
no test coverage detected