11"""Debug runtime implementation."""
22
33import logging
4- from typing import Any , Generic , TypeVar
4+ from typing import Any , Generic , Optional , TypeVar
55
66from uipath .runtime import (
77 UiPathBaseRuntime ,
88 UiPathBreakpointResult ,
9- UiPathRuntimeContext ,
9+ UiPathExecutionOptions ,
1010 UiPathRuntimeResult ,
1111 UiPathRuntimeStatus ,
1212 UiPathStreamNotSupportedError ,
@@ -26,53 +26,48 @@ class UiPathDebugRuntime(UiPathBaseRuntime, Generic[T]):
2626
2727 def __init__ (
2828 self ,
29- context : UiPathRuntimeContext ,
3029 delegate : T ,
3130 debug_bridge : UiPathDebugBridge ,
3231 ):
3332 """Initialize the UiPathDebugRuntime."""
34- super ().__init__ (context )
35- self .context : UiPathRuntimeContext = context
33+ super ().__init__ ()
3634 self .delegate : T = delegate
3735 self .debug_bridge : UiPathDebugBridge = debug_bridge
3836
39- async def execute (self , input : dict [str , Any ]) -> UiPathRuntimeResult :
37+ async def execute (
38+ self , input : dict [str , Any ], options : Optional [UiPathExecutionOptions ] = None
39+ ) -> UiPathRuntimeResult :
4040 """Execute the workflow with debug support."""
4141 try :
4242 await self .debug_bridge .connect ()
4343
4444 await self .debug_bridge .emit_execution_started ()
4545
4646 result : UiPathRuntimeResult
47+
4748 # Try to stream events from inner runtime
4849 try :
49- result = await self ._stream_and_debug (self . delegate , input )
50+ result = await self ._stream_and_debug (input , options = options )
5051 except UiPathStreamNotSupportedError :
5152 # Fallback to regular execute if streaming not supported
5253 logger .debug (
5354 f"Runtime { self .delegate .__class__ .__name__ } does not support "
5455 "streaming, falling back to execute()"
5556 )
56- result = await self .delegate .execute (input )
57+ result = await self .delegate .execute (input , options = options )
5758
5859 await self .debug_bridge .emit_execution_completed (result )
5960
60- self .context .result = result
61-
6261 return result
6362
6463 except Exception as e :
65- # Emit execution error
66- self .context .result = UiPathRuntimeResult (
67- status = UiPathRuntimeStatus .FAULTED ,
68- )
6964 await self .debug_bridge .emit_execution_error (
7065 error = str (e ),
7166 )
7267 raise
7368
7469 async def _stream_and_debug (
75- self , inner_runtime : T , input : dict [str , Any ]
70+ self , input : dict [str , Any ], options : Optional [ UiPathExecutionOptions ] = None
7671 ) -> UiPathRuntimeResult :
7772 """Stream events from inner runtime and handle debug interactions."""
7873 final_result : UiPathRuntimeResult
@@ -81,13 +76,17 @@ async def _stream_and_debug(
8176 # Starting in paused state - wait for breakpoints and resume
8277 await self .debug_bridge .wait_for_resume ()
8378
79+ debug_options = UiPathExecutionOptions (
80+ resume = options .resume if options else False ,
81+ breakpoints = options .breakpoints if options else None ,
82+ )
83+
8484 # Keep streaming until execution completes (not just paused at breakpoint)
8585 while not execution_completed :
8686 # Update breakpoints from debug bridge
87- if inner_runtime .context is not None :
88- inner_runtime .context .breakpoints = self .debug_bridge .get_breakpoints ()
87+ debug_options .breakpoints = self .debug_bridge .get_breakpoints ()
8988 # Stream events from inner runtime
90- async for event in inner_runtime . stream (input ):
89+ async for event in self . delegate . stream (input , options = debug_options ):
9190 # Handle final result
9291 if isinstance (event , UiPathRuntimeResult ):
9392 final_result = event
@@ -99,8 +98,8 @@ async def _stream_and_debug(
9998 await self .debug_bridge .emit_breakpoint_hit (event )
10099 await self .debug_bridge .wait_for_resume ()
101100
102- if inner_runtime . context is not None :
103- inner_runtime . context .resume = True
101+ # Tell inner runtime we're resuming
102+ debug_options .resume = True
104103
105104 except UiPathDebugQuitError :
106105 final_result = UiPathRuntimeResult (
@@ -122,9 +121,6 @@ async def _stream_and_debug(
122121 async def cleanup (self ) -> None :
123122 """Cleanup runtime resources."""
124123 try :
125- await self .delegate .cleanup ()
126- finally :
127- try :
128- await self .debug_bridge .disconnect ()
129- except Exception as e :
130- logger .warning (f"Error disconnecting debug bridge: { e } " )
124+ await self .debug_bridge .disconnect ()
125+ except Exception as e :
126+ logger .warning (f"Error disconnecting debug bridge: { e } " )
0 commit comments