@@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | from __future__ import annotations |
| 4 | 4 | |
| 5 | +import inspect |
| 5 | 6 | from collections.abc import Awaitable, Callable |
| 6 | 7 | from dataclasses import dataclass |
| 7 | 8 | from enum import StrEnum |
@@ -394,7 +395,8 @@ class ToolExecutor: |
| 394 | 395 | preview, |
| 395 | 396 | ) |
| 396 | 397 | if on_confirmation: |
| 397 | | - confirmed = await on_confirmation( |
| 398 | + confirmed = await self._invoke_confirmation_handler( |
| 399 | + on_confirmation, |
| 398 | 400 | confirmation.tool_name, |
| 399 | 401 | confirmation.message, |
| 400 | 402 | confirmation.details, |
@@ -445,9 +447,35 @@ class ToolExecutor: |
| 445 | 447 | if emit_confirmation: |
| 446 | 448 | await emit_confirmation(tool_call.name, message, details, preview) |
| 447 | 449 | if on_confirmation: |
| 448 | | - return await on_confirmation(tool_call.name, message, details, preview) |
| 450 | + return await self._invoke_confirmation_handler( |
| 451 | + on_confirmation, |
| 452 | + tool_call.name, |
| 453 | + message, |
| 454 | + details, |
| 455 | + preview, |
| 456 | + ) |
| 449 | 457 | return False |
| 450 | 458 | |
| 459 | + @staticmethod |
| 460 | + async def _invoke_confirmation_handler( |
| 461 | + handler: BrowserConfirmation, |
| 462 | + tool_name: str, |
| 463 | + message: str, |
| 464 | + details: str, |
| 465 | + preview: dict[str, Any] | None, |
| 466 | + ) -> bool: |
| 467 | + if handler is None: |
| 468 | + return True |
| 469 | + |
| 470 | + try: |
| 471 | + parameter_count = len(inspect.signature(handler).parameters) |
| 472 | + except (TypeError, ValueError): |
| 473 | + parameter_count = 4 |
| 474 | + |
| 475 | + if parameter_count >= 4: |
| 476 | + return await handler(tool_name, message, details, preview) |
| 477 | + return await handler(tool_name, message, details) |
| 478 | + |
| 451 | 479 | @staticmethod |
| 452 | 480 | def _merge_messages(primary: str, extra_messages: list[str]) -> str: |
| 453 | 481 | parts = [message for message in extra_messages if message] |