Spaces:
Sleeping
Sleeping
| """ | |
| Agent 2: Website Inspector | |
| Captures screenshots from live website. | |
| """ | |
| from typing import Dict, Any | |
| import sys | |
| import os | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from utils.website_capturer import capture_website_screenshots | |
| def agent_2_node(state: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Capture screenshots from live website. | |
| This agent: | |
| 1. Opens website in headless browser | |
| 2. Captures full-page screenshots at desktop and mobile viewports | |
| 3. Stores paths and dimensions in state | |
| """ | |
| print("\n" + "="*60) | |
| print("π Agent 2: Website Inspector - Capturing Website Screenshots") | |
| print("="*60) | |
| website_url = state.get("website_url", "") | |
| execution_id = state.get("execution_id", "") | |
| logs = state.get("logs", []) | |
| try: | |
| # Capture screenshots | |
| screenshots, dimensions = capture_website_screenshots( | |
| website_url=website_url, | |
| output_dir="data/website", | |
| execution_id=execution_id, | |
| desktop_width=1440, | |
| mobile_width=375 | |
| ) | |
| if not screenshots: | |
| raise ValueError("Failed to capture any website screenshots") | |
| print(f"\n β Captured {len(screenshots)} website screenshots") | |
| for viewport, path in screenshots.items(): | |
| dims = dimensions.get(viewport, {}) | |
| print(f" β’ {viewport}: {dims.get('width', '?')}x{dims.get('height', '?')}px") | |
| logs.append(f"πΈ Website {viewport}: {dims.get('width', '?')}x{dims.get('height', '?')}px") | |
| return { | |
| "website_screenshots": screenshots, | |
| "website_dimensions": dimensions, | |
| "status": "website_captured", | |
| "logs": logs | |
| } | |
| except Exception as e: | |
| error_msg = f"Failed to capture website screenshots: {str(e)}" | |
| print(f"\n β {error_msg}") | |
| logs.append(f"β {error_msg}") | |
| return { | |
| "status": "website_capture_failed", | |
| "error_message": error_msg, | |
| "logs": logs | |
| } | |