|
17 | 17 | UiPathRuntimeResult, |
18 | 18 | UiPathRuntimeStatus, |
19 | 19 | ) |
| 20 | +from uipath.runtime.resumable.trigger import UiPathResumeTriggerType |
20 | 21 | from uipath.runtime.schema import UiPathRuntimeSchema |
21 | 22 |
|
22 | 23 | logger = logging.getLogger(__name__) |
@@ -65,12 +66,44 @@ async def stream( |
65 | 66 | """Stream execution events with chat support.""" |
66 | 67 | await self.chat_bridge.connect() |
67 | 68 |
|
68 | | - async for event in self.delegate.stream(input, options=options): |
69 | | - if isinstance(event, UiPathRuntimeMessageEvent): |
70 | | - if event.payload: |
71 | | - await self.chat_bridge.emit_message_event(event.payload) |
| 69 | + execution_completed = False |
| 70 | + current_input = input |
| 71 | + current_options = UiPathStreamOptions( |
| 72 | + resume=options.resume if options else False, |
| 73 | + breakpoints=options.breakpoints if options else None, |
| 74 | + ) |
| 75 | + |
| 76 | + while not execution_completed: |
| 77 | + async for event in self.delegate.stream( |
| 78 | + current_input, options=current_options |
| 79 | + ): |
| 80 | + if isinstance(event, UiPathRuntimeMessageEvent): |
| 81 | + if event.payload: |
| 82 | + await self.chat_bridge.emit_message_event(event.payload) |
| 83 | + |
| 84 | + if isinstance(event, UiPathRuntimeResult): |
| 85 | + runtime_result = event |
| 86 | + |
| 87 | + if ( |
| 88 | + runtime_result.status == UiPathRuntimeStatus.SUSPENDED |
| 89 | + and runtime_result.trigger |
| 90 | + and runtime_result.trigger.trigger_type |
| 91 | + == UiPathResumeTriggerType.API |
| 92 | + ): |
| 93 | + await self.chat_bridge.emit_interrupt_event(runtime_result) |
| 94 | + resume_data = await self.chat_bridge.wait_for_resume() |
| 95 | + |
| 96 | + # Continue with resumed execution |
| 97 | + current_input = resume_data |
| 98 | + current_options.resume = True |
| 99 | + break |
| 100 | + else: |
| 101 | + yield event |
| 102 | + execution_completed = True |
| 103 | + else: |
| 104 | + yield event |
72 | 105 |
|
73 | | - yield event |
| 106 | + await self.chat_bridge.emit_exchange_end_event() |
74 | 107 |
|
75 | 108 | async def get_schema(self) -> UiPathRuntimeSchema: |
76 | 109 | """Get schema from the delegate runtime.""" |
|
0 commit comments