tenseleyflow/loader / 36eb700

Browse files

Preserve legacy confirmation callbacks

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
36eb70042029f2b7274667248fd14f50e474331b
Parents
e995221
Tree
807cf40

1 changed file

StatusFile+-
M src/loader/runtime/executor.py 30 2
src/loader/runtime/executor.pymodified
@@ -2,6 +2,7 @@
22
 
33
 from __future__ import annotations
44
 
5
+import inspect
56
 from collections.abc import Awaitable, Callable
67
 from dataclasses import dataclass
78
 from enum import StrEnum
@@ -394,7 +395,8 @@ class ToolExecutor:
394395
                     preview,
395396
                 )
396397
             if on_confirmation:
397
-                confirmed = await on_confirmation(
398
+                confirmed = await self._invoke_confirmation_handler(
399
+                    on_confirmation,
398400
                     confirmation.tool_name,
399401
                     confirmation.message,
400402
                     confirmation.details,
@@ -445,9 +447,35 @@ class ToolExecutor:
445447
         if emit_confirmation:
446448
             await emit_confirmation(tool_call.name, message, details, preview)
447449
         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
+            )
449457
         return False
450458
 
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
+
451479
     @staticmethod
452480
     def _merge_messages(primary: str, extra_messages: list[str]) -> str:
453481
         parts = [message for message in extra_messages if message]