@@ -164,7 +164,26 @@ async def execute(self, run: ExecutionRun) -> None:
164164 runtime_id = run .id ,
165165 )
166166
167- runtime : UiPathRuntimeProtocol
167+ runtime : UiPathRuntimeProtocol = new_runtime
168+
169+ if run .mode == ExecutionMode .CHAT :
170+ chat_bridge = WebChatBridge ()
171+ chat_bridge .on_message = lambda evt : self ._handle_chat_message_event (
172+ run , evt
173+ )
174+ chat_bridge .on_interrupt = lambda trigger : self ._handle_interrupt (
175+ run , trigger
176+ )
177+ self .chat_bridges [run .id ] = chat_bridge
178+
179+ # ChatRuntime handles suspend/resume internally
180+ runtime = cast (
181+ UiPathRuntimeProtocol ,
182+ UiPathChatRuntime (
183+ delegate = runtime ,
184+ chat_bridge = chat_bridge ,
185+ ),
186+ )
168187
169188 if self ._debug_bridge_factory :
170189 debug_bridge = self ._debug_bridge_factory (run .mode )
@@ -188,31 +207,15 @@ async def execute(self, run: ExecutionRun) -> None:
188207 self .debug_bridges [run .id ] = debug_bridge
189208
190209 runtime = UiPathDebugRuntime (
191- delegate = new_runtime ,
210+ delegate = runtime ,
192211 debug_bridge = debug_bridge ,
193212 )
194- else :
195- runtime = new_runtime
196213
197214 if run .mode == ExecutionMode .CHAT :
198- chat_bridge = WebChatBridge ()
199- chat_bridge .on_message = lambda evt : self ._handle_chat_message_event (
200- run , evt
201- )
202- chat_bridge .on_interrupt = lambda trigger : self ._handle_interrupt (
203- run , trigger
204- )
205- self .chat_bridges [run .id ] = chat_bridge
206-
207- # Wrap: ExecutionRuntime(ChatRuntime(runtime))
208- # ChatRuntime handles suspend/resume internally,
215+ # Wrap: ExecutionRuntime(Debug(Chat(base)))
209216 # ExecutionRuntime's OTel span wraps the entire session.
210- chat_runtime = UiPathChatRuntime (
211- delegate = runtime ,
212- chat_bridge = chat_bridge ,
213- )
214217 execution_runtime = UiPathExecutionRuntime (
215- delegate = cast ( UiPathRuntimeProtocol , chat_runtime ) ,
218+ delegate = runtime ,
216219 trace_manager = self .trace_manager ,
217220 log_handler = log_handler ,
218221 execution_id = run .id ,
0 commit comments