Spaces:
Sleeping
Sleeping
| """ | |
| Agent 1: Design Inspector | |
| Captures screenshots from Figma design file. | |
| """ | |
| 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.figma_client import FigmaClient | |
| def agent_1_node(state: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Capture screenshots from Figma design. | |
| This agent: | |
| 1. Connects to Figma API | |
| 2. Finds Desktop and Mobile frames | |
| 3. Exports screenshots at proper scale | |
| 4. Stores paths and dimensions in state | |
| """ | |
| print("\n" + "="*60) | |
| print("π¨ Agent 1: Design Inspector - Capturing Figma Screenshots") | |
| print("="*60) | |
| figma_key = state.get("figma_access_token", "") | |
| figma_file = state.get("figma_file_key", "") | |
| execution_id = state.get("execution_id", "") | |
| logs = state.get("logs", []) | |
| try: | |
| # Initialize Figma client | |
| client = FigmaClient(figma_key) | |
| # Export frames | |
| screenshots, dimensions = client.export_frames_for_comparison( | |
| file_key=figma_file, | |
| output_dir="data/figma", | |
| execution_id=execution_id | |
| ) | |
| if not screenshots: | |
| raise ValueError("No frames found in Figma file. Ensure frames are named with 'Desktop' or 'Mobile'.") | |
| print(f"\n β Captured {len(screenshots)} Figma 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"πΈ Figma {viewport}: {dims.get('width', '?')}x{dims.get('height', '?')}px") | |
| return { | |
| "figma_screenshots": screenshots, | |
| "figma_dimensions": dimensions, | |
| "status": "figma_captured", | |
| "logs": logs | |
| } | |
| except Exception as e: | |
| error_msg = f"Failed to capture Figma screenshots: {str(e)}" | |
| print(f"\n β {error_msg}") | |
| logs.append(f"β {error_msg}") | |
| return { | |
| "status": "figma_capture_failed", | |
| "error_message": error_msg, | |
| "logs": logs | |
| } | |