Handles execution of actions from AI model output for iOS devices. Args: wda_url: WebDriverAgent URL. session_id: Optional WDA session ID. confirmation_callback: Optional callback for sensitive action confirmation. Should return True to proceed, False to
| 27 | |
| 28 | |
| 29 | class IOSActionHandler: |
| 30 | """ |
| 31 | Handles execution of actions from AI model output for iOS devices. |
| 32 | |
| 33 | Args: |
| 34 | wda_url: WebDriverAgent URL. |
| 35 | session_id: Optional WDA session ID. |
| 36 | confirmation_callback: Optional callback for sensitive action confirmation. |
| 37 | Should return True to proceed, False to cancel. |
| 38 | takeover_callback: Optional callback for takeover requests (login, captcha). |
| 39 | """ |
| 40 | |
| 41 | def __init__( |
| 42 | self, |
| 43 | wda_url: str = "http://localhost:8100", |
| 44 | session_id: str | None = None, |
| 45 | confirmation_callback: Callable[[str], bool] | None = None, |
| 46 | takeover_callback: Callable[[str], None] | None = None, |
| 47 | ): |
| 48 | self.wda_url = wda_url |
| 49 | self.session_id = session_id |
| 50 | self.confirmation_callback = confirmation_callback or self._default_confirmation |
| 51 | self.takeover_callback = takeover_callback or self._default_takeover |
| 52 | |
| 53 | def execute( |
| 54 | self, action: dict[str, Any], screen_width: int, screen_height: int |
| 55 | ) -> ActionResult: |
| 56 | """ |
| 57 | Execute an action from the AI model. |
| 58 | |
| 59 | Args: |
| 60 | action: The action dictionary from the model. |
| 61 | screen_width: Current screen width in pixels. |
| 62 | screen_height: Current screen height in pixels. |
| 63 | |
| 64 | Returns: |
| 65 | ActionResult indicating success and whether to finish. |
| 66 | """ |
| 67 | action_type = action.get("_metadata") |
| 68 | |
| 69 | if action_type == "finish": |
| 70 | return ActionResult( |
| 71 | success=True, should_finish=True, message=action.get("message") |
| 72 | ) |
| 73 | |
| 74 | if action_type != "do": |
| 75 | return ActionResult( |
| 76 | success=False, |
| 77 | should_finish=True, |
| 78 | message=f"Unknown action type: {action_type}", |
| 79 | ) |
| 80 | |
| 81 | action_name = action.get("action") |
| 82 | handler_method = self._get_handler(action_name) |
| 83 | |
| 84 | if handler_method is None: |
| 85 | return ActionResult( |
| 86 | success=False, |