|
5 | 5 | import json |
6 | 6 | import traceback |
7 | 7 | from datetime import datetime |
8 | | -from typing import Any, Callable, cast |
| 8 | +from typing import Any, Callable, Literal, Protocol, cast |
9 | 9 |
|
10 | 10 | from pydantic import BaseModel |
11 | 11 | from uipath.core.tracing import UiPathTraceManager |
|
18 | 18 | UiPathRuntimeStatus, |
19 | 19 | UiPathStreamOptions, |
20 | 20 | ) |
21 | | -from uipath.runtime.debug import UiPathDebugProtocol, UiPathDebugRuntime |
| 21 | +from uipath.runtime.debug import ( |
| 22 | + UiPathBreakpointResult, |
| 23 | + UiPathDebugProtocol, |
| 24 | + UiPathDebugRuntime, |
| 25 | +) |
22 | 26 | from uipath.runtime.errors import UiPathErrorContract, UiPathRuntimeError |
23 | 27 | from uipath.runtime.events import UiPathRuntimeMessageEvent, UiPathRuntimeStateEvent |
24 | 28 |
|
|
30 | 34 | LogCallback = Callable[[LogData], None] |
31 | 35 | TraceCallback = Callable[[TraceData], None] |
32 | 36 | ChatCallback = Callable[[ChatData], None] |
33 | | -DebugBridgeFactory = Callable[[ExecutionMode], UiPathDebugProtocol] |
| 37 | + |
| 38 | + |
| 39 | +class DebugBridgeProtocol(UiPathDebugProtocol, Protocol): |
| 40 | + """Extended debug bridge protocol with control methods and callbacks.""" |
| 41 | + |
| 42 | + on_execution_started: Callable[[], None] | None |
| 43 | + on_state_update: Callable[[UiPathRuntimeStateEvent], None] | None |
| 44 | + on_breakpoint_hit: Callable[[UiPathBreakpointResult], None] | None |
| 45 | + on_execution_completed: Callable[[UiPathRuntimeResult], None] | None |
| 46 | + on_execution_error: Callable[[str], None] | None |
| 47 | + |
| 48 | + def resume(self, resume_data: Any) -> None: ... |
| 49 | + def quit(self) -> None: ... |
| 50 | + def set_breakpoints(self, breakpoints: list[str] | Literal["*"]) -> None: ... |
| 51 | + |
| 52 | + |
| 53 | +DebugBridgeFactory = Callable[[ExecutionMode], DebugBridgeProtocol] |
34 | 54 |
|
35 | 55 |
|
36 | 56 | class RunService: |
@@ -71,7 +91,7 @@ def __init__( |
71 | 91 | batch=False, |
72 | 92 | ) |
73 | 93 |
|
74 | | - self.debug_bridges: dict[str, UiPathDebugProtocol] = {} |
| 94 | + self.debug_bridges: dict[str, DebugBridgeProtocol] = {} |
75 | 95 |
|
76 | 96 | def register_run(self, run: ExecutionRun) -> None: |
77 | 97 | """Register a new run and emit an initial update.""" |
@@ -276,7 +296,7 @@ def handle_trace(self, trace_data: TraceData) -> None: |
276 | 296 | if self.on_trace is not None: |
277 | 297 | self.on_trace(trace_data) |
278 | 298 |
|
279 | | - def get_debug_bridge(self, run_id: str) -> UiPathDebugProtocol | None: |
| 299 | + def get_debug_bridge(self, run_id: str) -> DebugBridgeProtocol | None: |
280 | 300 | """Get the debug bridge for a run.""" |
281 | 301 | return self.debug_bridges.get(run_id) |
282 | 302 |
|
|
0 commit comments